private static Font CreateFont(string fontName, int size) { var fontCollection = new FontCollection(); string fontPath = TestFontUtilities.GetPath(fontName); return(fontCollection.Add(fontPath).CreateFont(size)); }
public void AntialiasingIsAntialiased <TPixel>(TestImageProvider <TPixel> provider) where TPixel : unmanaged, IPixel <TPixel> { Font font36 = TestFontUtilities.GetFont(TestFonts.OpenSans, 20); var textOpt = new TextOptions(font36) { Dpi = 96, Origin = new PointF(0, 0) }; var comparer = ImageComparer.TolerantPercentage(0.001f); provider.RunValidatingProcessorTest( x => x .SetGraphicsOptions(o => o.Antialias = false) .DrawText(textOpt, "Hello, World!", Color.Black), comparer: comparer); }
public void TextBuilder_Bounds_AreCorrect() { Vector2 position = new(5, 5); var options = new TextOptions(TestFontUtilities.GetFont(TestFonts.OpenSans, 16)) { Origin = position }; string text = "Hello World"; IPathCollection glyphs = TextBuilder.GenerateGlyphs(text, options); RectangleF builderBounds = glyphs.Bounds; FontRectangle measuredBounds = TextMeasurer.MeasureBounds(text, options); Assert.Equal(measuredBounds.X, builderBounds.X); Assert.Equal(measuredBounds.Y, builderBounds.Y); Assert.Equal(measuredBounds.Width, builderBounds.Width); Assert.Equal(measuredBounds.Height, builderBounds.Height); }
public void CanRenderCustomFont() { Font font = CreateFont(TestFonts.IcoMoonEvents, 175); TextOptions options = new(font) { VerticalAlignment = VerticalAlignment.Center }; const int imageSize = 300; using var image = new Image <Rgba32>(imageSize, imageSize); string iconText = char.ConvertFromUtf32(int.Parse("e926", NumberStyles.HexNumber)); FontRectangle rect = TextMeasurer.Measure(iconText, options); float textX = ((imageSize - rect.Width) * 0.5F) + rect.Left; float textY = ((imageSize - rect.Height) * 0.5F) + (rect.Top * 0.25F); image.Mutate(x => x.DrawText(iconText, font, Color.Black, new PointF(textX, textY))); image.Save(TestFontUtilities.GetPath("e96.png")); }
public DrawText_Path() { this.FontCollection = new FontCollection(); this.Font = this.FontCollection.Install(TestFontUtilities.GetPath("SixLaborsSampleAB.woff")).CreateFont(12); }
public DrawText_Path() { this.FontCollection = new FontCollection(); this.Font = this.FontCollection.Install(TestFontUtilities.GetPath("SixLaborsSampleAB.woff")); this.img = new ProcessorWatchingImage(10, 10); }
public OutputText() { this.FontCollection = new FontCollection(); this.Font = FontCollection.Install(TestFontUtilities.GetPath("SixLaborsSampleAB.woff")); }