text

source of font::reader

1// Big-endian numbers read out of font data, 0 past its end, so a2// truncated or malformed font reads as zeros rather than faulting.34exp fn u8_at(d: &[u8], at: u64) -> u32 {5    if (at >= d.length()) {6        return 0;7    }8    return d[at] to u32;9}1011exp fn u16_at(d: &[u8], at: u64) -> u32 {12    if (at + 2 > d.length()) {13        return 0;14    }15    return (d[at] to u32 << 8) | d[at + 1] to u32;16}1718exp fn i16_at(d: &[u8], at: u64) -> i32 {19    const v = u16_at(&d, at);20    return if (v >= 0x8000) v to i32 - 0x10000 else v to i32;21}2223exp fn u32_at(d: &[u8], at: u64) -> u32 {24    if (at + 4 > d.length()) {25        return 0;26    }27    return (d[at] to u32 << 24) | (28        d[at + 1] to u32 << 1629    ) | (d[at + 2] to u32 << 8) | d[at + 3] to u32;30}3132// A 2.14 fixed-point number, as composite glyphs' scales are.33exp fn f2dot14_at(d: &[u8], at: u64) -> f32 {34    return i16_at(&d, at) to f32 / 16384.0;35}3637// The four bytes of a tag at `at`, to match against names: none past the38// data's end.39exp fn tag_at(d: &[u8], at: u64) -> &[u8] {40    if (at + 4 > d.length()) {41        return &d[..0];42    }43    return &d[at..at + 4];44}4546// The four bytes as a tag, as `0x6B65726E` for "kern".47exp fn tag(text: &[u8]) -> u32 {48    return (text[0] to u32 << 24) | (text[1] to u32 << 16) | (text[2] to u32 << 8) | text[3] to u32;49}