Runnable SixLabors.Fonts samples that load a real font from assets/fonts and write generated reports and images to output/fonts.
Run the project from the repository root:
dotnet run --project SixLabors.Samples.Fonts\SixLabors.Samples.Fonts.csproj -c ReleaseShows how to load a font file into a FontCollection:
- adds a
.ttffile withFontCollection.Add(...) - reads
FontDescriptionmetadata from the font name table - lists the styles available for the loaded
FontFamily - reports the source path used by the family
Output:
font-loading.txt
Shows how to measure wrapped text before drawing or laying out UI:
- configures
TextOptionswith an origin, wrapping length, and line spacing - calls
TextMeasurer.Measure(...)once to getTextMetrics - compares advance, bounds, and renderable bounds
- reports per-line metrics including baseline, extent, and grapheme count
Output:
text-measurement.txt
Shows how a measured layout can answer editor-style questions:
- uses
TextOptions.TextRunsto apply a different font size to part of the text - reads glyph and grapheme metrics from the measured layout
- uses
HitTest(...),GetCaretPosition(...), andMoveCaret(...) - demonstrates that run indices are grapheme indices
Output:
text-runs-and-interaction.txt
Shows how the measured rectangles for one glyph relate to font metrics:
- calls
TextMeasurer.GetGlyphMetrics(...)for a single laid-out glyph - draws the logical advance cell and rendered glyph bounds
- annotates width, height, side bearings, advance width, and advance height
- writes the diagram as a PNG for visual inspection
Output:
glyph-metrics-visualizer.png
Shows how measured line metrics map to one laid-out line:
- calls
TextMeasurer.Measure(...)once to getTextMetrics.LineMetrics - draws the logical line extent and rendered text bounds
- uses text with descenders so the baseline-to-descender distance is visible
- shows
LineSpacingincreasing the logical line box without scaling glyphs - annotates ascender and descender distances relative to the baseline
- labels the baseline as a position guide rather than a measurement
- annotates
Extent.XandLineHeight
Output:
line-metrics-visualizer.png