#[allow(unused_imports)]
use crate::codegen_prelude::*;
#[derive(Clone, Debug, Default)]
pub struct TableDirectory {
pub sfnt_version: u32,
pub search_range: u16,
pub entry_selector: u16,
pub range_shift: u16,
pub table_records: Vec<TableRecord>,
}
impl TableDirectory {
pub fn new(
sfnt_version: u32,
search_range: u16,
entry_selector: u16,
range_shift: u16,
table_records: Vec<TableRecord>,
) -> Self {
Self {
sfnt_version,
search_range,
entry_selector,
range_shift,
table_records: table_records.into_iter().map(Into::into).collect(),
}
}
}
impl FontWrite for TableDirectory {
#[allow(clippy::unnecessary_cast)]
fn write_into(&self, writer: &mut TableWriter) {
self.sfnt_version.write_into(writer);
(array_len(&self.table_records).unwrap() as u16).write_into(writer);
self.search_range.write_into(writer);
self.entry_selector.write_into(writer);
self.range_shift.write_into(writer);
self.table_records.write_into(writer);
}
}
impl Validate for TableDirectory {
fn validate_impl(&self, ctx: &mut ValidationCtx) {
ctx.in_table("TableDirectory", |ctx| {
ctx.in_field("table_records", |ctx| {
if self.table_records.len() > (u16::MAX as usize) {
ctx.report("array excedes max length");
}
self.table_records.validate_impl(ctx);
});
})
}
}
#[derive(Clone, Debug, Default)]
pub struct TableRecord {
pub tag: Tag,
pub checksum: u32,
pub offset: u32,
pub length: u32,
}
impl TableRecord {
pub fn new(tag: Tag, checksum: u32, offset: u32, length: u32) -> Self {
Self {
tag,
checksum,
offset,
length,
}
}
}
impl FontWrite for TableRecord {
fn write_into(&self, writer: &mut TableWriter) {
self.tag.write_into(writer);
self.checksum.write_into(writer);
self.offset.write_into(writer);
self.length.write_into(writer);
}
}
impl Validate for TableRecord {
fn validate_impl(&self, _ctx: &mut ValidationCtx) {}
}
#[derive(Clone, Debug, Default)]
pub struct TTCHeader {
pub ttc_tag: Tag,
pub num_fonts: u32,
pub table_directory_offsets: Vec<u32>,
pub dsig_tag: Option<u32>,
pub dsig_length: Option<u32>,
pub dsig_offset: Option<u32>,
}
impl Validate for TTCHeader {
fn validate_impl(&self, ctx: &mut ValidationCtx) {
ctx.in_table("TTCHeader", |ctx| {
let version: MajorMinor = self.compute_version();
ctx.in_field("table_directory_offsets", |ctx| {
if self.table_directory_offsets.len() > (u32::MAX as usize) {
ctx.report("array excedes max length");
}
});
ctx.in_field("dsig_tag", |ctx| {
if version.compatible((2, 0)) && self.dsig_tag.is_none() {
ctx.report(format!("field must be present for version {version}"));
}
});
ctx.in_field("dsig_length", |ctx| {
if version.compatible((2, 0)) && self.dsig_length.is_none() {
ctx.report(format!("field must be present for version {version}"));
}
});
ctx.in_field("dsig_offset", |ctx| {
if version.compatible((2, 0)) && self.dsig_offset.is_none() {
ctx.report(format!("field must be present for version {version}"));
}
});
})
}
}