text/font.rs#
Source: lib/text/font.rs
font -- embedded SGF1 fonts (tools/ttf2bin.py, ASMLIB/docs/FONTS.md), the font header and
FONTMETRICS records shared by every font kind [src/text/font.s]
Font::parse(data) the 64-byte header, the fast codepoint table (None: not SGF1)
glyph(cp) -> id fallback glyph when unmapped lookup(cp) -> Option<id>
adv(g), kern(g1, g2) font units glyph_box(g) -> [xmin, ymin, xmax, ymax]
path(g, gp, path) append the outline (TrueType quadratics, composites)
outline(g, dx, dy, ol) the outline into the outline buffer (sgf_outline, outline.s)
FAST_CP: u32 = 384
SGF1_MAGIC: u32 = 0x3146_4753
// SGF1 header flags (SG_FLAGS)
SGH_ICON: u16 = 1
SGH_KERN: u16 = 2
SGH_RUNTIME: u16 = 0x100
SGH_COLR: u16 = 0x200 // COLR layers (text runs draw them layer by layer)
SGH_CBDT: u16 = 0x400 // CBDT bitmaps (PARGB glyph cache entries)
// font_style flags
FS_SYN_BOLD: u32 = 1
FS_SYN_ITALIC: u32 = 2
FS_SHARP: u32 = 4
/// Classic screen typography: round kerning and advances to whole device pixels.
FS_CLASSIC: u32 = 8
FS_MASK: u32 = 15
// text_decor flags
TD_UNDERLINE: u32 = 1
TD_STRIKEOUT: u32 = 2
// font_name ids (OpenType name IDs)
FN_FAMILY: u32 = 1
FN_STYLE: u32 = 2
FN_FULL: u32 = 4
FN_TYPO_FAMILY: u32 = 16
FN_TYPO_STYLE: u32 = 17
// FONTMETRICS byte offsets (font_metric)
FM_UPEM: u32 = 0
FM_ASC: u32 = 4
FM_DESC: u32 = 8
FM_GAP: u32 = 12
FM_TYPO_ASC: u32 = 16
FM_TYPO_DESC: u32 = 20
FM_TYPO_GAP: u32 = 24
FM_WIN_ASC: u32 = 28
FM_WIN_DESC: u32 = 32
FM_XH: u32 = 36
FM_CAPH: u32 = 40
FM_UL_POS: u32 = 44
FM_UL_THICK: u32 = 48
FM_ST_POS: u32 = 52
FM_ST_THICK: u32 = 56
FM_WEIGHT: u32 = 60
FM_FLAGS: u32 = 64
FM_NGLYPHS: u32 = 68
FM_ADVMAX: u32 = 72
FM_WIDTH: u32 = 76
FM_SIZE: u32 = 80
// FONTMETRICS flags
FMF_ITALIC: i32 = 1
FMF_BOLD: i32 = 2
FMF_OBLIQUE: i32 = 4
FMF_COLOR: i32 = 8
FMF_CFF: i32 = 16
FMF_VAR: i32 = 32
FMF_SYMBOL: i32 = 64
FMF_MONO: i32 = 128
FMF_TYPO: i32 = 256
FMF_EMBED: i32 = 512
FMF_SYN: i32 = 1024
FMF_BITMAP: i32 = 2048
FMF_KERN: i32 = 4096
struct Hdrthe SGF1-compatible header every font kind has (font_data): what gc_scale and the text metrics read. i16 fields sign-extended, upem / nglyphs zero-extended.flags: u16upem: i32asc: i32desc: i32gap: i32caph: i32xh: i32ulpos: i32ulthick: i32nglyphs: u32baseid: u32-- derived fonts: base font id + 1 (0 = none)
struct MetricsFONTMETRICS (font.inc): all values in font units (y up)upem: i32asc: i32desc: i32gap: i32typo_asc: i32typo_desc: i32typo_gap: i32win_asc: i32win_desc: i32xh: i32caph: i32ul_pos: i32ul_thick: i32st_pos: i32st_thick: i32weight: i32flags: i32nglyphs: i32advmax: i32width: i32
impl Metrics
fn field(&self, off: u32) -> i32the field at byte offset FM_* (0 for an invalid field) [font_metric]fn as_array(&self) -> [i32; 20]struct Gpthe glyph transform (font.s g_gp): origin in float pixels, pixels per font unit, composite offset in font unitsx: f32y: f32sx: f32sy: f32dx: i32dy: i32
struct Fontflags: u16upem: i32asc: i32desc: i32gap: i32caph: i32xh: i32ulpos: i32ulthick: i32nglyphs: u32fallback: u32
impl Font
fn parse(data: &'static [u8]) -> Option<Font>font_register's parse: None when the data is not SGF1fn new(data: &'static [u8]) -> Fontfn hdr(&self) -> Hdrfn lookup(&self, cp: u32) -> Option<u32>binary search over the ranges {u32 firstCp, u16 count, u16 firstGlyph} [font_lookup]fn glyph(&self, cp: u32) -> u32fn adv(&self, g: u32) -> i32fn kern(&self, g1: u32, g2: u32) -> i32kern(l, r) = matrix[lclass[l] * kernR + rclass[r]] * 4 font unitsfn glyph_box(&self, g: u32) -> Option<[i32; 4]>fn path(&self, g: u32, gp: &mut Gp, path: &mut Path, depth: u32)glyph_path: append the outline transformed by gp (implied on-curve midpoints, composites recursively)fn outline(&self, g: u32, dx: i32, dy: i32, depth: u32, ol: &mut Outline)append glyph g (composites resolved) to the outline buffer: points in font units + (dx, dy), one contour per SGF1 contour [sgf_outline]