swash/internal/
xmtx.rs
1use super::{raw_tag, Bytes, RawTag};
4
5pub const HMTX: RawTag = raw_tag(b"hmtx");
6pub const VMTX: RawTag = raw_tag(b"vmtx");
7
8pub fn advance(data: &[u8], xmtx: u32, long_metric_count: u16, glyph_id: u16) -> u16 {
10 let b = Bytes::new(data);
11 let offset = if glyph_id < long_metric_count {
12 glyph_id as usize * 4
13 } else {
14 (long_metric_count - 1) as usize * 4
15 };
16 b.read_u16(offset + xmtx as usize).unwrap_or(0)
17}
18
19pub fn sb(data: &[u8], xmtx: u32, long_metric_count: u16, glyph_id: u16) -> i16 {
21 let b = Bytes::new(data);
22 let offset = if glyph_id < long_metric_count {
23 glyph_id as usize * 4 + 2
24 } else {
25 long_metric_count as usize * 4 + (glyph_id - long_metric_count) as usize * 2
26 };
27 b.read_i16(offset + xmtx as usize).unwrap_or(0)
28}