Skip to main content

Crate mos_fonts

Crate mos_fonts 

Source
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. WinAnsi natives go out as their canonical byte; the small set of extended Latin glyphs each face carries (Latin Extended-A beyond WinAnsi, the math operators, fi/fl ligatures) goes out through a per-document /Differences remap that mos-pdf plans. 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 with rustybuzz (HarfBuzz Rust port). The PDF backend embeds a subset of the actual TrueType outlines as a Type 0 CID font with a /ToUnicode CMap, 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Β§

EmbeddedFont
A bundled TrueType face: the raw bytes plus the metrics and parsed rustybuzz::Face needed to shape text and emit a PDF FontDescriptor.
FontFamily
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).
ShapedGlyph
One glyph in a shaped run. Cluster values are byte offsets into the source UTF-8 string.
ShapedRun
Output of shape_text: the shaped glyph stream and the total advance width at the requested point size.
WordSubRun
One face’s slice of a per-glyph-fallback shaping result.

EnumsΒ§

Base14Font
One of the 14 standard PDF fonts every conformant PDF reader ships built in (PDF 1.7 Β§9.6.2.2).
EmbeddedFontId
Stable identifier for each bundled embedded cut. Used as the enum payload of Font::Embedded so Font stays Copy/Hash/Eq without 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 font at size points.
descent
Descender depth for font at size points, 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 font at size points.
nfc_text
Return text in Unicode NFC form, borrowing when it is already normalized.
shape
Shape text against font using rustybuzz.
shape_text
Shape text against font.
shape_with_fallback
Shape text against primary with per-glyph fallback.
subset
Subset font to just the glyph IDs in gids (always include GID 0, .notdef, which the PDF spec mandates). Returns the trimmed TTF bytes suitable for embedding as a /FontFile2 stream.
text_width
Advance width of text rendered in font at size points.
winansi_byte
Returns the PDF WinAnsiEncoding byte that encodes ch, or None if ch has no slot in WinAnsi.