pub mod cmap;
pub mod embed;
pub mod subset;
use std::collections::BTreeMap;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum FontKind {
TrueType,
Cff,
}
impl FontKind {
pub fn detect(data: &[u8]) -> Option<FontKind> {
if data.len() < 4 {
return None;
}
match &data[..4] {
[0x00, 0x01, 0x00, 0x00] | b"true" | b"ttcf" => Some(FontKind::TrueType),
b"OTTO" => Some(FontKind::Cff),
_ => None,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct FontHandle(pub(crate) u32);
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn detect_truetype_magic() {
assert_eq!(FontKind::detect(&[0x00, 0x01, 0x00, 0x00, 0x00]), Some(FontKind::TrueType));
assert_eq!(FontKind::detect(b"true\x00"), Some(FontKind::TrueType));
}
#[test]
fn detect_ttc_magic() {
assert_eq!(FontKind::detect(b"ttcf\x00\x01\x00\x00"), Some(FontKind::TrueType));
}
#[test]
fn detect_cff_magic() {
assert_eq!(FontKind::detect(b"OTTO\x00"), Some(FontKind::Cff));
}
#[test]
fn detect_unknown_returns_none() {
assert_eq!(FontKind::detect(b"WOFF"), None);
assert_eq!(FontKind::detect(b"wOFF"), None);
assert_eq!(FontKind::detect(b"\x00\x00"), None); }
}
#[derive(Debug)]
#[allow(dead_code)]
pub struct EmbeddedFont {
pub type0_id: lopdf::ObjectId,
pub pdf_name: Vec<u8>,
pub gid_to_char: BTreeMap<u16, char>,
pub gid_to_advance: BTreeMap<u16, u16>,
pub units_per_em: u16,
}