Expand description
Font discovery, shaping, and metrics (manifest Β§22.1).
Two font-emission paths live behind one Font enum:
Font::Base14; the 14 standard PDF base fonts. No glyph data ships; the PDF reader supplies outlines. Advance widths come from bundled Adobe AFMs, addressed throughpdf_base14_metrics.WinAnsinatives go out as their canonical byte; the small set of extended Latin glyphs each face carries (Latin Extended-A beyondWinAnsi, the math operators,fi/flligatures) goes out through a per-document/Differencesremap thatmos-pdfplans. Characters outside both tiers: Cyrillic, CJK, emoji: silently substitute to?in both the width and emit paths (no warning, no panic; callers that want non-Latin should pick the embedded family).Font::Embedded: a bundled Noto Sans cut shaped withrustybuzz(HarfBuzzRust port). The PDF backend embeds a subset of the actualTrueTypeoutlines as a Type 0 CID font with a/ToUnicodeCMap, so the output is a real Unicode-aware document: copy/paste round-trips through Cyrillic, Greek, accented Latin, and anything else Noto Sans covers.
Six cuts ship in this crateβs data/ directory: four Noto Sans
style cuts (Regular, Bold, Italic, BoldItalic) for proportional
body text, one Noto Sans Mono Regular cut for `raw` runs, and
one Noto Sans Math cut for per-glyph fallback (see SOURCES.md
under the crate root). Style selection happens through FontFamily,
which the layout engine receives from the eval lowerer.
ModulesΒ§
- embedded π
- Embedded TrueType faces + shaping.
- family π
- font π
- metrics π
- normalize π
- resources π
- shape π
StructsΒ§
- Embedded
Font - A bundled
TrueTypeface: the raw bytes plus the metrics and parsedrustybuzz::Faceneeded to shape text and emit a PDFFontDescriptor. - Font
Family - A four-cut family: Regular, Bold, Italic,
BoldItalic. The layout engine picks one slot per styled run (*emphasis*β italic,**strong**β bold, raw β fixed-width family, body β regular). - Shaped
Glyph - One glyph in a shaped run. Cluster values are byte offsets into the source UTF-8 string.
- Shaped
Run - Output of
shape_text: the shaped glyph stream and the total advance width at the requested point size. - Word
SubRun - One faceβs slice of a per-glyph-fallback shaping result.
EnumsΒ§
- Base14
Font - One of the 14 standard PDF fonts every conformant PDF reader ships built in (PDF 1.7 Β§9.6.2.2).
- Embedded
Font Id - Stable identifier for each bundled embedded cut. Used as the enum
payload of
Font::EmbeddedsoFontstaysCopy/Hash/Eqwithout resorting to pointer identity. - Font
- A renderable font β either one of the Adobe Core 14 (no data embedded; outlines from the PDF reader) or a bundled TrueType cut (data embedded, subset per-document).
FunctionsΒ§
- advance_
units_ to_ pt - Convert a font-unit advance to PDF user-space points.
- ascent
- Ascender height for
fontatsizepoints. - descent
- Descender depth for
fontatsizepoints, as a positive number (the AFM/TTF storage convention is negative; both backends normalise on the way out). - extended_
glyph_ name - Returns the extended-tier PostScript glyph name for
ch. - glyph_
width - Width of a single glyph in
fontatsizepoints. - nfc_
text - Return
textin Unicode NFC form, borrowing when it is already normalized. - shape
- Shape
textagainstfontusingrustybuzz. - shape_
text - Shape
textagainstfont. - shape_
with_ fallback - Shape
textagainstprimarywith per-glyph fallback. - subset
- Subset
fontto just the glyph IDs ingids(always include GID 0,.notdef, which the PDF spec mandates). Returns the trimmed TTF bytes suitable for embedding as a/FontFile2stream. - text_
width - Advance width of
textrendered infontatsizepoints. - winansi_
byte - Returns the PDF
WinAnsiEncodingbyte that encodesch, orNoneifchhas no slot inWinAnsi.