//! Byte offsets, structure sizes, and magic numbers.
//!
//! EOT offsets index into the output prefix. SFNT offsets index into input
//! structures. All values are byte offsets.

/// Offsets within the EOT prefix header (output).
pub mod eot {
    /// Total EOT size, `u32` LE. Patched last.
    pub const LENGTH: usize = 0;
    /// Font payload length, `u32` LE.
    pub const FONT_LENGTH: usize = 4;
    /// EOT version, `u32` LE.
    pub const VERSION: usize = 8;
    /// PANOSE bytes, 10 bytes.
    pub const FONT_PANOSE: usize = 16;
    /// Charset, `u8`.
    pub const CHARSET: usize = 26;
    /// Italic flag, `u8`.
    pub const ITALIC: usize = 27;
    /// Weight, `u32` LE.
    pub const WEIGHT: usize = 28;
    /// Magic number, `u16` LE.
    pub const MAGIC: usize = 34;
    /// Unicode ranges, 4 x `u32` LE.
    pub const UNICODE_RANGE: usize = 36;
    /// Codepage ranges, 2 x `u32` LE.
    pub const CODEPAGE_RANGE: usize = 52;
    /// Checksum adjustment, `u32` LE.
    pub const CHECKSUM_ADJUSTMENT: usize = 60;
}

/// Offsets within SFNT (input) structures.
pub mod sfnt {
    /// Number of tables in the SFNT header.
    pub const NUMTABLES: usize = 4;

    /// Tag, 4 bytes, in a table directory entry.
    pub const TABLE_TAG: usize = 0;
    /// Table offset, `u32` BE, in a table directory entry.
    pub const TABLE_OFFSET: usize = 8;
    /// Table length, `u32` BE, in a table directory entry.
    pub const TABLE_LENGTH: usize = 12;

    /// `usWeightClass`, `u16` BE, in the OS/2 table.
    pub const OS2_WEIGHT: usize = 4;
    /// PANOSE, 10 bytes, in the OS/2 table.
    pub const OS2_FONT_PANOSE: usize = 32;
    /// `ulUnicodeRange1..4`, 4 x `u32` BE, in the OS/2 table.
    pub const OS2_UNICODE_RANGE: usize = 42;
    /// `fsSelection`, `u16` BE, in the OS/2 table.
    pub const OS2_FS_SELECTION: usize = 62;
    /// `ulCodePageRange1..2`, 2 x `u32` BE, in OS/2 version 1 and later.
    pub const OS2_CODEPAGE_RANGE: usize = 78;

    /// `checkSumAdjustment`, `u32` BE, in the head table.
    pub const HEAD_CHECKSUM_ADJUSTMENT: usize = 8;

    /// Name count, `u16` BE, in the name table header.
    pub const NAMETABLE_COUNT: usize = 2;
    /// String storage offset, `u16` BE, in the name table header.
    pub const NAMETABLE_STRING_OFFSET: usize = 4;

    /// Platform ID, `u16` BE, in a name record.
    pub const NAME_PLATFORM_ID: usize = 0;
    /// Encoding ID, `u16` BE, in a name record.
    pub const NAME_ENCODING_ID: usize = 2;
    /// Language ID, `u16` BE, in a name record.
    pub const NAME_LANGUAGE_ID: usize = 4;
    /// Name ID, `u16` BE, in a name record.
    pub const NAME_NAME_ID: usize = 6;
    /// String byte length, `u16` BE, in a name record.
    pub const NAME_LENGTH: usize = 8;
    /// String offset from string storage, `u16` BE, in a name record.
    pub const NAME_OFFSET: usize = 10;
}

/// Sizes of SFNT and EOT structures.
pub mod sizeof {
    /// Size of one table directory entry.
    pub const SFNT_TABLE_ENTRY: usize = 16;
    /// Size of the SFNT header.
    pub const SFNT_HEADER: usize = 12;
    /// Size of the name table header.
    pub const SFNT_NAMETABLE: usize = 6;
    /// Size of one name record.
    pub const SFNT_NAMETABLE_ENTRY: usize = 12;
    /// Size of the EOT prefix header.
    pub const EOT_PREFIX: usize = 82;
}

/// Constants written into the EOT header and used to match name records.
pub mod magic {
    /// EOT version 0x00020001 (uncompressed).
    pub const EOT_VERSION: u32 = 0x0002_0001;
    /// EOT magic 0x504C, ASCII "LP".
    pub const EOT_MAGIC: u16 = 0x504c;
    /// Charset value DEFAULT_CHARSET.
    pub const EOT_CHARSET: u8 = 1;
    /// Microsoft English (US) language ID, 0x0409.
    pub const LANGUAGE_ENGLISH: u16 = 0x0409;
}
