1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
//! The index-to-location table.

use {FontHeader, MaximumProfile, Result, Tape, Walue};

/// An index-to-location table.
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum GlyphLocation {
    /// Offsets devided by two.
    HalfOffsets(Vec<u16>),
    /// Offsets.
    Offsets(Vec<u32>),
}

impl<'l> Walue<(&'l FontHeader, &'l MaximumProfile)> for GlyphLocation {
    fn read<T: Tape>(tape: &mut T, (header, profile): (&FontHeader, &MaximumProfile))
                     -> Result<Self> {

        let glyph_count = profile.glyph_count();
        match header.glyph_location_format {
            0 => Ok(GlyphLocation::HalfOffsets(read_walue!(tape, glyph_count + 1))),
            1 => Ok(GlyphLocation::Offsets(read_walue!(tape, glyph_count + 1))),
            _ => raise!("the index-to-location format is unknown"),
        }
    }
}