pub struct Kerning { /* private fields */ }Expand description
Parsed GPOS kern-feature pair positioning for a font.
Built once via Font::gpos_kerning; Kerning::pair is a cheap,
allocation-free lookup. An empty Kerning (no GPOS / no kern feature /
malformed) makes every pair() return 0.
Implementations§
Source§impl Kerning
impl Kerning
Sourcepub fn pair(&self, left: u16, right: u16) -> i16
pub fn pair(&self, left: u16, right: u16) -> i16
x-advance adjustment (font design units) applied between left and
right glyph ids; 0 if no kern pair applies. First matching subtable
wins.
Sourcepub fn for_each_ascii_pair(
&self,
glyph_of: impl Fn(u8) -> u16,
emit: impl FnMut(u8, u8, i16),
)
pub fn for_each_ascii_pair( &self, glyph_of: impl Fn(u8) -> u16, emit: impl FnMut(u8, u8, i16), )
Enumerates the ASCII byte pairs this kerning adjusts, replacing the
16,384-pair brute force over Kerning::pair.
For every byte pair (l, r) with pair(glyph_of(l), glyph_of(r)) != 0
— where glyph_of maps the 128 ASCII bytes to glyph ids, possibly
several bytes to one glyph — calls emit(l, r, v) with v exactly
equal to that pair result (first matching subtable wins, defined
zeros shadow later subtables just like pair). Pairs resolving to 0
are never emitted: a zero-initialized matrix already holds their value,
so emit fires once per nonzero cell. The order of emit calls across
distinct pairs is unspecified (format-1 pair maps hash-scatter), so
emit must be order-independent.
Cost is proportional to what the tables actually contain — format-1 pair-map entries and format-2 coverage glyphs — instead of the full 128x128 cross product.