swash/internal/
vorg.rs

1//! Vertical origin table.
2
3use super::{raw_tag, Bytes, RawTag};
4
5pub const VORG: RawTag = raw_tag(b"VORG");
6
7/// Returns the vertical origin for the specified glyph.
8pub fn origin(data: &[u8], vorg: u32, glyph_id: u16) -> Option<i16> {
9    if vorg == 0 {
10        return None;
11    }
12    let b = Bytes::new(data);
13    let base = vorg as usize;
14    let default = b.read::<i16>(base + 4)?;
15    let count = b.read::<u16>(base + 6)? as usize;
16    let mut l = 0;
17    let mut h = count;
18    while l < h {
19        use core::cmp::Ordering::*;
20        let i = (l + h) / 2;
21        let rec = base + 8 + i * 4;
22        let g = b.read::<u16>(rec)?;
23        match glyph_id.cmp(&g) {
24            Less => h = i,
25            Greater => l = i + 1,
26            Equal => return b.read::<i16>(rec + 2),
27        }
28    }
29    Some(default)
30}