/// <summary> /// Generates the shapes corresponding the glyphs described by the font and with the setting ing withing the FontSpan /// </summary> /// <param name="text">The text to generate glyphs for</param> /// <param name="options">The style and settings to use while rendering the glyphs</param> /// <returns>The paths, boxes, and text box.</returns> private static (IPathCollection Paths, IPathCollection Boxes) GenerateGlyphsWithBox(string text, TextOptions options) { var glyphBuilder = new CustomGlyphBuilder(Vector2.Zero); var renderer = new TextRenderer(glyphBuilder); renderer.RenderText(text, options); return(glyphBuilder.Paths, glyphBuilder.Boxes); }
public static void Draw(Image <Rgba32> img, Font font, VerticalAlignment vert, HorizontalAlignment horiz, float wrappingWidth) { Vector2 location = Vector2.Zero; switch (vert) { case VerticalAlignment.Top: location.Y = 0; break; case VerticalAlignment.Center: location.Y = img.Height / 2F; break; case VerticalAlignment.Bottom: location.Y = img.Height; break; default: break; } switch (horiz) { case HorizontalAlignment.Left: location.X = 0; break; case HorizontalAlignment.Right: location.X = img.Width; break; case HorizontalAlignment.Center: location.X = img.Width / 2F; break; default: break; } var glyphBuilder = new CustomGlyphBuilder(); var renderer = new TextRenderer(glyphBuilder); TextOptions textOptions = new(font) { TabWidth = 4, WrappingLength = wrappingWidth, HorizontalAlignment = horiz, VerticalAlignment = vert, Origin = location }; string text = $" {horiz} {vert} {horiz} {vert} {horiz} {vert} "; renderer.RenderText(text, textOptions); IEnumerable <IPath> shapesToDraw = glyphBuilder.Paths; img.Mutate(x => x.Fill(Color.Black, glyphBuilder.Paths)); Rgba32 f = Color.Fuchsia; f.A = 128; img.Mutate(x => x.Fill(Color.Black, glyphBuilder.Paths)); img.Mutate(x => x.Draw(f, 1, glyphBuilder.Boxes)); img.Mutate(x => x.Draw(Color.Lime, 1, glyphBuilder.TextBox)); } }