PeachDrawing.Core
PeachDrawing.Core
TypefaceFont Class
A Font built directly from a Typeface and a size, with no backend-specific wrapper (a PDF font resource, a platform font handle, ...) underneath - every member below reads only Typeface/TypefaceMetrics data, scaled by Size. This is what a Canvas backend with no host-specific font representation of its own (a standalone raster canvas; any future backend in the same position) uses directly, and it is also the shape every backend’s own metric computation reduces to once its host-specific extras (PDF font-resource identity, a platform handle, ...) are set aside.
public sealed class TypefaceFont : PeachDrawing.Core.Font
Inheritance System.Object → Font → TypefaceFont
Remarks
Every metric here is the *unscaled* value in the same unit as Size itself - no rounding, no host-specific unit conversion (a PDF backend’s internal-layout-unit scaling, an HTML renderer’s CSS-pixel-grid rounding for `line-height: normal`, etc.). A backend that needs either of those applies it on top of these raw numbers, rather than this type guessing at a host it doesn’t know about.
| Constructors | |
|---|---|
| TypefaceFont(Typeface, double, SyntheticStyle, Nullable<double>) | Builds a font directly from typeface at size, with no backend-specific wrapper underneath. |
| Properties | |
|---|---|
| Ascent | Get the ascent, in pixels, of the font — the distance from the top of the font’s line box down to its baseline. |
| CapHeightEm | The font’s cap height as a fraction of the em, or null when unknown. |
| FaceKey | A stable identity for the concrete face this font renders with, used only to coalesce adjacent per-codepoint fragments that resolve to the same face into one word rather than splitting every character. Two Fonts with the same key at the same size/style render identically. |
| FontUnitsPerEm | This font’s design-units-per-em (e.g. 1000 or 2048) - MathTable’s design-unit values need scaling by Size / FontUnitsPerEm to become points. 0 when this font has no MathTable (nothing to scale). |
| HasMathTable | Whether this font carries a MATH table. |
| HasVerticalMetrics | Whether this font carries real OpenType vertical metrics (vhea + vmtx) to consult. |
| HasVerticalOrigin | Whether this font carries a real OpenType VORG table this reader trusts (see OpenTypeDescriptor.HasVerticalOrigin for the CFF-only restriction that gates this). |
| Height | The distance from one baseline to the next when lines are set solid (the typeface’s own cell, not a CSS line-height approximation). |
| LeftPadding | Get the left padding, in pixels, of the font. |
| MathTable | This font’s parsed MATH table, or null if it has none. |
| NormalLineHeight | The font’s own real ascent + descent + line-gap (CSS 2.1 §10.8.1’s `line-height: normal`), unrounded. |
| ObliqueSkewSinus | The sine of a declared CSS Fonts Level 4 oblique <angle> (e.g. oblique 10deg) - a purely rendering-side hint for a backend’s own faux-italic shear when this font’s SyntheticStyle needs to simulate italic, with no bearing on face selection. Null (the common case: italic, bare oblique, or no synthesis needed) leaves the backend to fall back to its own fixed default skew. |
| PaletteCount | The number of CPAL palettes this font carries (0 for a non-color font). |
| PaletteEntryCount | The number of color entries in each CPAL palette (0 for a non-color font). |
| Size | Gets the em-size of this Font measured in the units specified by the Unit property. |
| SyntheticStyle | Which of this font’s style attributes (bold/italic) are faked rather than real, because no matching face was found - what the caller/backend must simulate (e.g. a synthetic oblique shear) rather than get from the typeface’s own glyph outlines. None when every requested attribute matched a real face. |
| Typeface | The matched typeface this font instance is built from - PeachDrawing.Text’s own public glyph/shaping/outline surface, reachable here without a backend needing to downcast to a concrete Font to reach it (as raster’s glyph painting used to, ((FontAdapter)font).Font.Typeface). Null only for a font stub with no real typeface behind it (a test double). |
| UnderlineOffset | Get the vertical offset of the font underline location from the top of the font. |
| UnderlinePosition | The font’s own real preferred underline offset (OpenType post.underlinePosition, scaled to this font’s size the same way UnderlineThickness is), consulted only when CSS text-underline-position: from-font is used ([css-text-decor-4 |
§2.5](https://www.w3.org/TR/css-text-decor-4/#text-underline-position-property ‘https://www.w3.org/TR/css-text-decor-4/#text-underline-position-property’) - from-font does not exist in css-text-decor-3 at all) - a negative value moves the line below the baseline, matching post.underlinePosition’s own sign convention. Defaults to 0 (at the baseline) for every Font except the OpenType-descriptor-backed adapter, which overrides it with the font’s real metric - the same plain-default pattern UnderlineThickness uses. |
|
| UnderlineThickness | The font’s own real underline-stroke thickness (OpenType post.underlineThickness, scaled to this font’s size the same way UnderlineOffset is), consulted only when CSS text-decoration-thickness: from-font is used (CSS Text Decoration 4 §3.3) - the property’s initial value (auto) deliberately does not read this, to preserve this engine’s pre-existing fixed decoration-line thickness exactly. Defaults to 1 (this engine’s own pre-existing hardcoded decoration thickness), mirroring NormalLineHeight’s pattern of a plain default for every Font except the OpenType-descriptor-backed adapter, which overrides it with the font’s real metric. |
| XHeightEm | The font’s real x-height as a fraction of the em, or null when it doesn’t carry one. |
| Methods | |
|---|---|
| FirstDarkPalette() | The index of the first palette flagged usable with a dark background, or null when none. |
| FirstLightPalette() | The index of the first palette flagged usable with a light background, or null when none. |
| GetGlyphAdvanceWidthDesignUnits(int) | This glyph’s real horizontal advance width, in font design units (see FontUnitsPerEm for the scale) - the font’s own hmtx table, as opposed to a MathTableMathVariants entry’s AdvanceMeasurement (the vertical growth-direction extent only, not width). Needed because a stretched glyph - a pre-sized size variant, or an assembled shape’s parts - is a different, wider glyph than the base character MathTable was looked up by, so its own hmtx advance is the only source for the actual space it needs when drawn. 0 when this font can’t resolve one (no descriptor). |
| GetGlyphIndex(Rune) | This rune’s glyph index in this font (0/.notdef if unmapped) - needed to look a glyph up in MathTable’s per-glyph tables (italics correction, top-accent attachment, stretchy variants) by id rather than by character. |
| GetSubSuperscriptMetrics(bool) | This font’s own recommended geometry for a synthesized superscript (or subscript), as fractions of the em: the glyph scale factor, and how far the synthesized baseline sits from the main one, always positive. Null when the font states nothing usable, leaving the caller to fall back to representative ratios. |
| GetVerticalAdvance(Rune) | This rune’s real vmtx advance height, in the same pixel units as Height. Only meaningful when HasVerticalMetrics is true; the default reproduces the flat per-character line-height step used when it’s false. |
| GetVerticalOriginY(Rune) | This rune’s real VORG vertical-origin Y, in the same pixel units as Ascent (baseline-relative, same convention). Only meaningful when HasVerticalOrigin is true; the default reproduces the plain top-of-cell anchor used when it’s false (see FragmentPainter.Text.cs’s PaintUprightVerticalRun remarks for the derivation). |
| GetWhitespaceWidth(Canvas) | The advance width of a single space character, in this font’s own size. |
| HasGlyph(Rune) | Whether this font actually contains a glyph for rune (as opposed to resolving to the missing-glyph box). Drives per-codepoint font fallback: a run whose resolved font lacks a character is re-resolved against the rest of the font-family stack. |
| MatchesEmojiPresentation(Rune, EmojiPresentation) | Whether this font is one to prefer for baseCodepoint when it must be drawn in presentation (CSS font-variant-emoji): its own variation-sequence data says so, or it is a colour font for emoji / an outline font for text. Every font accepts NoPreference; the default answers true for every request so a font with no such data never loses a match it could not judge. |
| SupportsFontVariantCaps(CapsMode) | Whether this font’s GSUB table defines an active lookup for every OpenType feature tag feature needs (e.g. both smcp and c2sc for AllSmallCaps - see GetFeatureTags(CapsMode)). A host calls this when deciding whether to synthesize the feature, which can happen during document parsing - before any Canvas exists - so this lives on Font itself rather than the graphics abstraction, mirroring HasGlyph(Rune). |
| SupportsFontVariantPosition(SubSuperMode) | Whether this font’s GSUB table defines an active lookup for the OpenType feature tag feature needs (subs or sups - see GetFeatureTags(SubSuperMode)). Answering false is what makes a run take the synthesized sub/superscript path instead, which CSS Fonts 4 requires as the fallback; like SupportsFontVariantCaps(CapsMode) this is asked during box-tree parsing, before any Canvas exists. |
| TryGetPaletteColor(int, int, PaintColor) | Resolves a CPAL palette entry to its color. Returns false when the font has no palette data or the indices are out of range. |