#![cfg_attr(docsrs, feature(doc_cfg))]
#![forbid(unsafe_code)]
pub mod font_patch;
pub mod glyph_keyed;
pub mod patch_group;
pub mod patchmap;
pub mod table_keyed;
pub mod url_templates;
#[cfg(test)]
mod testdata {
use std::{collections::HashMap, iter};
use font_test_data::bebuffer::BeBuffer;
use skrifa::Tag;
use write_fonts::{
tables::{head::Head, loca::Loca, maxp::Maxp},
FontBuilder,
};
pub fn test_font_for_patching_with_loca_mod<F>(
short_loca: bool,
loca_mod: F,
additional_tables: HashMap<Tag, &[u8]>,
) -> Vec<u8>
where
F: Fn(&mut Vec<u32>),
{
let mut font_builder = FontBuilder::new();
for (tag, data) in additional_tables {
font_builder.add_raw(tag, data);
}
let maxp = Maxp {
num_glyphs: 15,
..Default::default()
};
font_builder.add_table(&maxp).unwrap();
let head = Head {
index_to_loc_format: if short_loca { 0 } else { 1 },
..Default::default()
};
font_builder.add_table(&head).unwrap();
let glyf = if !short_loca {
BeBuffer::new().extend(iter::repeat_n(0, 140000))
} else {
BeBuffer::new()
};
let glyf = glyf
.push_with_tag(1u8, "gid_0")
.extend([2, 3, 4, 5u8, 0u8])
.push_with_tag(6u8, "gid_1")
.extend([7, 8u8, 0u8])
.push_with_tag(9u8, "gid_8")
.extend([10, 11, 12u8]);
let gid_0 = glyf.offset_for("gid_0") as u32;
let gid_1 = glyf.offset_for("gid_1") as u32;
let gid_8 = glyf.offset_for("gid_8") as u32;
let end = gid_8 + 4;
let mut loca = vec![
gid_0, gid_1, gid_8, gid_8, gid_8, gid_8, gid_8, gid_8, gid_8, end, end, end, end, end, end, end, ];
loca_mod(&mut loca);
let loca = Loca::new(loca);
font_builder.add_table(&loca).unwrap();
let glyf: &[u8] = &glyf;
font_builder.add_raw(Tag::new(b"glyf"), glyf);
font_builder.build()
}
pub fn test_font_for_patching() -> Vec<u8> {
test_font_for_patching_with_loca_mod(
true,
|_| {},
HashMap::from([(Tag::new(b"IFT "), vec![0, 0, 0, 0].as_slice())]),
)
}
}