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 through [pdf_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. A word
shaped through
shape_with_fallbackproduces aVec<WordSubRun>; each sub-run is self-contained: itstextis the source UTF-8 slice covered by exactly this sub-run, itsglyphs’clusteroffsets are rebased to the sub-run’s localtext(soplan_embeddedcan build/ToUnicodewithout knowing about the parent word), and itsadvance_ptis the sum of per-glyph advances at the requested point size.
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 at
size_pt, given the face’s units-per-em. Values are carried asi32because shapers use signed advances, but current embedded output normalizes to PDF-emittablehmtxadvances in0..=65535. Preserve sign here anyway so future positioned shaping cannot turn a negative adjustment into a huge positive width. - 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 PostScript glyph name for
chif and only ifchis in the extended tier: i.e. a Core 14 AFM glyph that has noWinAnsibyte and therefore must be reached through a custom/Encoding/Differencesslot. The extended tier covers: - glyph_
width - Width of a single glyph in
fontatsizepoints. For Base14 faces this is one AFM lookup; for embedded faces it shapes the single character. Used by the paragraph engine for character-wise hyphenation of oversized words. - nfc_
text - Return
textin Unicode NFC form, borrowing when it is already normalized. - shape
- Shape
textagainstfontusingrustybuzz. Returns the glyph stream in visual order (LTR for this slice). Glyph IDs, advances, and offsets come fromrustybuzz, so substitutions, kerning, and combining-mark positioning are preserved. An emptytextreturns an emptyVecwithout invoking the shaper. - shape_
text - Shape
textagainstfontand return both the glyph stream and the advance widths in user-space points. Callers that need only the width can usetext_width; callers that will also emit glyphs downstream should use this to avoid shaping twice. - shape_
with_ fallback - Shape
textagainstprimarywith per-glyph fallback. Walks each HarfBuzz cluster in the primary’s shaped output; clusters that contain any.notdef(GID 0) glyph are re-shaped against each embedded face infallbacksin order. The first fallback to produce a glyph stream with no.notdefwins the whole cluster (cluster- granular replacement, never partial: partial replacement would duplicate bases, drop marks, break ligatures). - 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.