PeachDrawing.Core

PeachDrawing.Core

Font Class

Adapter for platform specific font object - used to render text using specific font.

public abstract class Font

Inheritance System.Object → Font

Derived
↳ TypefaceFont

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 line spacing, in pixels, of this font.
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 used value of `line-height: normal` (CSS 2.1 §10.8.1), intended to be in the same pixel units as Height/Ascent. Real browsers resolve this from the font’s own ascent/descent/line-gap metrics rather than a flat multiplier; the default here reproduces the flat 1.2×-font-size approximation used before real per-font metrics were available (issue #956), so only the OpenType-descriptor-backed adapter overrides it - mirroring the vertical- metrics section above. Note this default is only faithful to that unit contract for an Font whose own Size is already in that same space; a font whose Size is a true, unscaled point size cannot just inherit this default and overrides the property instead.
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.
TextBaselineOffset The exact offset from DrawString’s top anchor to the baseline it paints at. Layout uses Ascent, which some adapters round for stable box geometry; paint effects that must sit a precise distance from the rendered glyphs use this unrounded counterpart instead.
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.
GetAdvanceEm(Rune) The advance width of rune’s glyph as a fraction of the em, or null when this font has no glyph for it (or no metrics at all). Built from GetGlyphIndex(Rune)/ GetGlyphAdvanceWidthDesignUnits(int)/FontUnitsPerEm, so it needs no override of its own.
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.