read_fonts/generated/
generated_post.rs#[allow(unused_imports)]
use crate::codegen_prelude::*;
#[derive(Debug, Clone, Copy)]
#[doc(hidden)]
pub struct PostMarker {
num_glyphs_byte_start: Option<usize>,
glyph_name_index_byte_start: Option<usize>,
glyph_name_index_byte_len: Option<usize>,
string_data_byte_start: Option<usize>,
string_data_byte_len: Option<usize>,
}
impl PostMarker {
pub fn version_byte_range(&self) -> Range<usize> {
let start = 0;
start..start + Version16Dot16::RAW_BYTE_LEN
}
pub fn italic_angle_byte_range(&self) -> Range<usize> {
let start = self.version_byte_range().end;
start..start + Fixed::RAW_BYTE_LEN
}
pub fn underline_position_byte_range(&self) -> Range<usize> {
let start = self.italic_angle_byte_range().end;
start..start + FWord::RAW_BYTE_LEN
}
pub fn underline_thickness_byte_range(&self) -> Range<usize> {
let start = self.underline_position_byte_range().end;
start..start + FWord::RAW_BYTE_LEN
}
pub fn is_fixed_pitch_byte_range(&self) -> Range<usize> {
let start = self.underline_thickness_byte_range().end;
start..start + u32::RAW_BYTE_LEN
}
pub fn min_mem_type42_byte_range(&self) -> Range<usize> {
let start = self.is_fixed_pitch_byte_range().end;
start..start + u32::RAW_BYTE_LEN
}
pub fn max_mem_type42_byte_range(&self) -> Range<usize> {
let start = self.min_mem_type42_byte_range().end;
start..start + u32::RAW_BYTE_LEN
}
pub fn min_mem_type1_byte_range(&self) -> Range<usize> {
let start = self.max_mem_type42_byte_range().end;
start..start + u32::RAW_BYTE_LEN
}
pub fn max_mem_type1_byte_range(&self) -> Range<usize> {
let start = self.min_mem_type1_byte_range().end;
start..start + u32::RAW_BYTE_LEN
}
pub fn num_glyphs_byte_range(&self) -> Option<Range<usize>> {
let start = self.num_glyphs_byte_start?;
Some(start..start + u16::RAW_BYTE_LEN)
}
pub fn glyph_name_index_byte_range(&self) -> Option<Range<usize>> {
let start = self.glyph_name_index_byte_start?;
Some(start..start + self.glyph_name_index_byte_len?)
}
pub fn string_data_byte_range(&self) -> Option<Range<usize>> {
let start = self.string_data_byte_start?;
Some(start..start + self.string_data_byte_len?)
}
}
impl TopLevelTable for Post<'_> {
const TAG: Tag = Tag::new(b"post");
}
impl<'a> FontRead<'a> for Post<'a> {
fn read(data: FontData<'a>) -> Result<Self, ReadError> {
let mut cursor = data.cursor();
let version: Version16Dot16 = cursor.read()?;
cursor.advance::<Fixed>();
cursor.advance::<FWord>();
cursor.advance::<FWord>();
cursor.advance::<u32>();
cursor.advance::<u32>();
cursor.advance::<u32>();
cursor.advance::<u32>();
cursor.advance::<u32>();
let num_glyphs_byte_start = version
.compatible((2u16, 0u16))
.then(|| cursor.position())
.transpose()?;
let num_glyphs = version
.compatible((2u16, 0u16))
.then(|| cursor.read::<u16>())
.transpose()?
.unwrap_or(0);
let glyph_name_index_byte_start = version
.compatible((2u16, 0u16))
.then(|| cursor.position())
.transpose()?;
let glyph_name_index_byte_len = version.compatible((2u16, 0u16)).then_some(
(num_glyphs as usize)
.checked_mul(u16::RAW_BYTE_LEN)
.ok_or(ReadError::OutOfBounds)?,
);
if let Some(value) = glyph_name_index_byte_len {
cursor.advance_by(value);
}
let string_data_byte_start = version
.compatible((2u16, 0u16))
.then(|| cursor.position())
.transpose()?;
let string_data_byte_len = version
.compatible((2u16, 0u16))
.then_some(cursor.remaining_bytes());
if let Some(value) = string_data_byte_len {
cursor.advance_by(value);
}
cursor.finish(PostMarker {
num_glyphs_byte_start,
glyph_name_index_byte_start,
glyph_name_index_byte_len,
string_data_byte_start,
string_data_byte_len,
})
}
}
pub type Post<'a> = TableRef<'a, PostMarker>;
#[allow(clippy::needless_lifetimes)]
impl<'a> Post<'a> {
pub fn version(&self) -> Version16Dot16 {
let range = self.shape.version_byte_range();
self.data.read_at(range.start).unwrap()
}
pub fn italic_angle(&self) -> Fixed {
let range = self.shape.italic_angle_byte_range();
self.data.read_at(range.start).unwrap()
}
pub fn underline_position(&self) -> FWord {
let range = self.shape.underline_position_byte_range();
self.data.read_at(range.start).unwrap()
}
pub fn underline_thickness(&self) -> FWord {
let range = self.shape.underline_thickness_byte_range();
self.data.read_at(range.start).unwrap()
}
pub fn is_fixed_pitch(&self) -> u32 {
let range = self.shape.is_fixed_pitch_byte_range();
self.data.read_at(range.start).unwrap()
}
pub fn min_mem_type42(&self) -> u32 {
let range = self.shape.min_mem_type42_byte_range();
self.data.read_at(range.start).unwrap()
}
pub fn max_mem_type42(&self) -> u32 {
let range = self.shape.max_mem_type42_byte_range();
self.data.read_at(range.start).unwrap()
}
pub fn min_mem_type1(&self) -> u32 {
let range = self.shape.min_mem_type1_byte_range();
self.data.read_at(range.start).unwrap()
}
pub fn max_mem_type1(&self) -> u32 {
let range = self.shape.max_mem_type1_byte_range();
self.data.read_at(range.start).unwrap()
}
pub fn num_glyphs(&self) -> Option<u16> {
let range = self.shape.num_glyphs_byte_range()?;
Some(self.data.read_at(range.start).unwrap())
}
pub fn glyph_name_index(&self) -> Option<&'a [BigEndian<u16>]> {
let range = self.shape.glyph_name_index_byte_range()?;
Some(self.data.read_array(range).unwrap())
}
pub fn string_data(&self) -> Option<VarLenArray<'a, PString<'a>>> {
let range = self.shape.string_data_byte_range()?;
Some(VarLenArray::read(self.data.split_off(range.start).unwrap()).unwrap())
}
}
#[cfg(feature = "experimental_traverse")]
impl<'a> SomeTable<'a> for Post<'a> {
fn type_name(&self) -> &str {
"Post"
}
fn get_field(&self, idx: usize) -> Option<Field<'a>> {
let version = self.version();
match idx {
0usize => Some(Field::new("version", self.version())),
1usize => Some(Field::new("italic_angle", self.italic_angle())),
2usize => Some(Field::new("underline_position", self.underline_position())),
3usize => Some(Field::new(
"underline_thickness",
self.underline_thickness(),
)),
4usize => Some(Field::new("is_fixed_pitch", self.is_fixed_pitch())),
5usize => Some(Field::new("min_mem_type42", self.min_mem_type42())),
6usize => Some(Field::new("max_mem_type42", self.max_mem_type42())),
7usize => Some(Field::new("min_mem_type1", self.min_mem_type1())),
8usize => Some(Field::new("max_mem_type1", self.max_mem_type1())),
9usize if version.compatible((2u16, 0u16)) => {
Some(Field::new("num_glyphs", self.num_glyphs().unwrap()))
}
10usize if version.compatible((2u16, 0u16)) => Some(Field::new(
"glyph_name_index",
self.glyph_name_index().unwrap(),
)),
11usize if version.compatible((2u16, 0u16)) => {
Some(Field::new("string_data", self.traverse_string_data()))
}
_ => None,
}
}
}
#[cfg(feature = "experimental_traverse")]
#[allow(clippy::needless_lifetimes)]
impl<'a> std::fmt::Debug for Post<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
(self as &dyn SomeTable<'a>).fmt(f)
}
}