public void IndexToXyShouldWorkCorrectly() { ITextContext context = new TypographyTextContext("0123456", FontFile, 36, FontStretch.Normal, FontStyle.Normal, FontWeight.Normal, 1000, 100, TextAlignment.Leading); // prepare debug contexts { surface = new Cairo.ImageSurface(Cairo.Format.Argb32, 2000, 2000); g = new Cairo.Context(surface); g.SetSourceRGBA(1, 1, 1, 1); g.Paint(); g.SetSourceRGBA(0, 0, 0, 1); g.LineWidth = 1; } // build path CairoPathBuilder cairoPathBuilder; cairoPathBuilder = new CairoPathBuilder(g, 0, 0, 1); context.Build(Point.Zero, cairoPathBuilder); float x, y, height; context.IndexToXY(0, false, out x, out y, out height); context.IndexToXY(1, false, out x, out y, out height); context.IndexToXY(2, false, out x, out y, out height); context.IndexToXY(3, false, out x, out y, out height); context.IndexToXY(4, false, out x, out y, out height); context.IndexToXY(5, false, out x, out y, out height); }
public void XyToIndexShouldWorkCorrectly() { ITextContext context = new TypographyTextContext("0123456", FontFile, 36, FontStretch.Normal, FontStyle.Normal, FontWeight.Normal, 1000, 100, TextAlignment.Leading); // prepare debug contexts { surface = new Cairo.ImageSurface(Cairo.Format.Argb32, 2000, 2000); g = new Cairo.Context(surface); g.SetSourceRGBA(1, 1, 1, 1); g.Paint(); g.SetSourceRGBA(0, 0, 0, 1); g.LineWidth = 1; } // build path CairoPathBuilder cairoPathBuilder; cairoPathBuilder = new CairoPathBuilder(g, 0, 0, 1); context.Build(Point.Zero, cairoPathBuilder); bool isInside = false; uint charIndex = context.XyToIndex(-1, 0, out isInside); Assert.False(isInside); Assert.Equal(0u, charIndex); charIndex = context.XyToIndex(13, 0, out isInside); Assert.True(isInside); Assert.Equal(0u, charIndex); charIndex = context.XyToIndex(37, 0, out isInside); Assert.True(isInside); Assert.Equal(1u, charIndex); charIndex = context.XyToIndex(64, 0, out isInside); Assert.True(isInside); Assert.Equal(2u, charIndex); charIndex = context.XyToIndex(89, 0, out isInside); Assert.True(isInside); Assert.Equal(3u, charIndex); }
public void ShouldGetCorrectOutline() { ITextContext textContext = new TypographyTextContext( "0123456", FontFile, 36, FontStretch.Normal, FontStyle.Normal, FontWeight.Normal, 1000, 100, TextAlignment.Leading); // prepare debug contexts { surface = new Cairo.ImageSurface(Cairo.Format.Argb32, 2000, 2000); g = new Cairo.Context(surface); g.SetSourceRGBA(1, 1, 1, 1); g.Paint(); g.SetSourceRGBA(0, 0, 0, 1); g.LineWidth = 1; } // build path CairoPathBuilder cairoPathBuilder; { cairoPathBuilder = new CairoPathBuilder(g, 0, 0, 1); textContext.Build(Point.Zero, cairoPathBuilder); } // show debug results // image { surface.WriteToPng(PathImagePath); g.Dispose(); Assert.False(PathImagePath.Contains(" ")); // open the image in Windows Photo Viewer Process.Start(@"C:\WINDOWS\System32\rundll32.exe", @"""C:\Program Files\Windows Photo Viewer\PhotoViewer.dll"", ImageView_Fullscreen " + PathImagePath); } //text { var text = cairoPathBuilder.Result; File.WriteAllText(PathTextPath, text); Process.Start(@"notepad", PathTextPath); } // Now, check if the output text and image shows a right outline of the text. }