// Copyright (c) Six Labors. // Licensed under the Six Labors Split License. using System.Numerics; using SixLabors.Fonts.Rendering; namespace SixLabors.Fonts { /// /// Represents a font-specific glyph at the point size used for layout and rendering. /// public readonly struct Glyph { private readonly float pointSize; internal Glyph(FontGlyphMetrics glyphMetrics, float pointSize) { this.GlyphMetrics = glyphMetrics; this.pointSize = pointSize; } /// /// Gets the font metrics for this glyph. /// public FontGlyphMetrics GlyphMetrics { get; } /// /// Calculates the rendered glyph bounds for the specified layout mode and origin. /// /// The glyph layout mode to measure with. /// The glyph origin to calculate the bounds from. /// The DPI to measure the glyph at. /// The rendered glyph bounds. public FontRectangle BoundingBox(GlyphLayoutMode mode, Vector2 glyphOrigin, float dpi) => this.GlyphMetrics.GetBoundingBox(mode, glyphOrigin, this.pointSize * dpi); /// /// Renders the glyph to the render surface. /// /// The target render surface. /// The index of the grapheme this glyph is part of. /// The origin used to render the glyph outline. /// The origin used to render text decorations. /// The glyph layout mode to render using. /// The options to render using. internal void RenderTo( IGlyphRenderer surface, int graphemeIndex, Vector2 glyphOrigin, Vector2 decorationOrigin, GlyphLayoutMode mode, TextOptions options) => this.GlyphMetrics.RenderTo(surface, graphemeIndex, glyphOrigin, decorationOrigin, mode, options); } }