pub(crate) use super::*;
use crate::vec;
#[cfg(feature = "log")]
pub(crate) use log::*;
impl<'a, T: TagWriter> SerializeEngine<'a, T> {
#[cfg(feature = "tagging")]
pub fn from_layout_and_tags(layout: &'a Layout, tags: T) -> Self {
Self {
bytes: byte::ByteWriter::new(),
layout,
#[cfg(feature = "tagging")]
tags,
#[cfg(feature = "tagging")]
tagging_data: TaggingData::default(),
_phantom: PhantomData,
}
}
#[cfg(feature = "tagging")]
pub fn tagging_engine(&mut self, tags: T) {
self.tags = tags;
}
pub fn data(&self) -> &[u8] {
&self.bytes.bytes
}
pub fn data_owned(self) -> Vec<u8> {
self.bytes.bytes
}
}
impl<'a> SerializeEngine<'a> {
pub fn from_layout(layout: &'a Layout) -> Self {
Self {
bytes: byte::ByteWriter::new(),
layout,
#[cfg(feature = "tagging")]
tags: TagWriterNoOp,
#[cfg(feature = "tagging")]
tagging_data: TaggingData::default(),
_phantom: PhantomData,
}
}
}
pub(crate) fn push_signature<T: TagWriter>(engine: &mut SerializeEngine<T>) {
#[cfg(feature = "tagging")]
let start = engine.bytes.byte_index();
engine.bytes.push(127);
engine.bytes.push(102);
engine.bytes.push(115);
engine.bytes.push(70);
#[cfg(feature = "tagging")]
engine.tags.tag_span(
TagKind::Signature,
Span::new(start, engine.bytes.byte_index()),
);
#[cfg(feature = "log")]
info!("Signed font data");
}
pub(crate) fn push_version<T: TagWriter>(engine: &mut SerializeEngine<T>) {
let version = engine.layout.version as u8;
engine.bytes.push(version);
#[cfg(feature = "tagging")]
engine.tags.tag_byte(
TagKind::Version {
value: engine.layout.version,
},
engine.bytes.byte_index(),
);
#[cfg(feature = "log")]
info!("Pushed version {}", engine.layout.version);
}
pub(crate) fn push_header<T: TagWriter>(engine: &mut SerializeEngine<T>) {
let mut font_properties = 0b00000000;
if engine.layout.compact {
font_properties |= 0b00000001;
}
engine.bytes.push(font_properties);
#[cfg(feature = "tagging")]
engine.tags.tag_bitflag(
TagKind::Header,
vec![TagKind::CompactFlag {
enabled: engine.layout.compact,
}],
engine.bytes.byte_index(),
);
#[cfg(feature = "log")]
info!("Pushed header");
}