write-fonts 0.49.1

Writing font files.
Documentation
// THIS FILE IS AUTOGENERATED.
// Any changes to this file will be overwritten.
// For more information about how codegen works, see font-codegen/README.md

#[allow(unused_imports)]
use crate::codegen_prelude::*;

/// A generic table parameterized by the type of its subtable offsets.
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct MyLookup<T> {
    /// Determines the concrete type of T
    pub lookup_type: u16,
    /// Offsets to subtables, from beginning of this table
    pub subtables: Vec<OffsetMarker<T>>,
}

impl<T: FontWrite> FontWrite for MyLookup<T> {
    #[allow(clippy::unnecessary_cast)]
    fn write_into(&self, writer: &mut TableWriter) {
        self.lookup_type.write_into(writer);
        (u16::try_from(array_len(&self.subtables)).unwrap()).write_into(writer);
        self.subtables.write_into(writer);
    }
    fn table_type(&self) -> TableType {
        TableType::Named("MyLookup")
    }
}

impl<T: Validate> Validate for MyLookup<T> {
    fn validate_impl(&self, ctx: &mut ValidationCtx) {
        ctx.in_table("MyLookup", |ctx| {
            ctx.in_field("subtables", |ctx| {
                if self.subtables.len() > (u16::MAX as usize) {
                    ctx.report("array exceeds max length");
                }
                self.subtables.validate_impl(ctx);
            });
        })
    }
}

impl<'a, T, U> FromObjRef<read_fonts::codegen_test::generic_group::MyLookup<'a, U>> for MyLookup<T>
where
    U: FontRead<'a>,
    T: FromTableRef<U> + Default + 'static,
{
    fn from_obj_ref(
        obj: &read_fonts::codegen_test::generic_group::MyLookup<'a, U>,
        _: FontData,
    ) -> Self {
        MyLookup {
            lookup_type: obj.lookup_type(),
            subtables: obj.subtables().to_owned_table(),
        }
    }
}

#[allow(clippy::needless_lifetimes)]
impl<'a, T, U> FromTableRef<read_fonts::codegen_test::generic_group::MyLookup<'a, U>>
    for MyLookup<T>
where
    U: FontRead<'a>,
    T: FromTableRef<U> + Default + 'static,
{
}

/// A concrete subtable with a format field (format group)
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum MySubtable {
    Format1(MySubtableFormat1),
    Format2(MySubtableFormat2),
}

impl MySubtable {}

impl Default for MySubtable {
    fn default() -> Self {
        Self::Format1(Default::default())
    }
}

impl FontWrite for MySubtable {
    fn write_into(&self, writer: &mut TableWriter) {
        match self {
            Self::Format1(item) => item.write_into(writer),
            Self::Format2(item) => item.write_into(writer),
        }
    }
    fn table_type(&self) -> TableType {
        match self {
            Self::Format1(item) => item.table_type(),
            Self::Format2(item) => item.table_type(),
        }
    }
}

impl Validate for MySubtable {
    fn validate_impl(&self, ctx: &mut ValidationCtx) {
        match self {
            Self::Format1(item) => item.validate_impl(ctx),
            Self::Format2(item) => item.validate_impl(ctx),
        }
    }
}

impl FromObjRef<read_fonts::codegen_test::generic_group::MySubtable<'_>> for MySubtable {
    fn from_obj_ref(
        obj: &read_fonts::codegen_test::generic_group::MySubtable,
        _: FontData,
    ) -> Self {
        use read_fonts::codegen_test::generic_group::MySubtable as ObjRefType;
        match obj {
            ObjRefType::Format1(item) => MySubtable::Format1(item.to_owned_table()),
            ObjRefType::Format2(item) => MySubtable::Format2(item.to_owned_table()),
        }
    }
}

impl FromTableRef<read_fonts::codegen_test::generic_group::MySubtable<'_>> for MySubtable {}

impl<'a> FontRead<'a> for MySubtable {
    fn read(data: FontData<'a>) -> Result<Self, ReadError> {
        <read_fonts::codegen_test::generic_group::MySubtable as FontRead>::read(data)
            .map(|x| x.to_owned_table())
    }
}

impl From<MySubtableFormat1> for MySubtable {
    fn from(src: MySubtableFormat1) -> MySubtable {
        MySubtable::Format1(src)
    }
}

impl From<MySubtableFormat2> for MySubtable {
    fn from(src: MySubtableFormat2) -> MySubtable {
        MySubtable::Format2(src)
    }
}

#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct MySubtableFormat1 {
    pub value: u16,
}

impl FontWrite for MySubtableFormat1 {
    #[allow(clippy::unnecessary_cast)]
    fn write_into(&self, writer: &mut TableWriter) {
        (1 as u16).write_into(writer);
        self.value.write_into(writer);
    }
    fn table_type(&self) -> TableType {
        TableType::Named("MySubtableFormat1")
    }
}

impl Validate for MySubtableFormat1 {
    fn validate_impl(&self, _ctx: &mut ValidationCtx) {}
}

impl<'a> FromObjRef<read_fonts::codegen_test::generic_group::MySubtableFormat1<'a>>
    for MySubtableFormat1
{
    fn from_obj_ref(
        obj: &read_fonts::codegen_test::generic_group::MySubtableFormat1<'a>,
        _: FontData,
    ) -> Self {
        MySubtableFormat1 { value: obj.value() }
    }
}

#[allow(clippy::needless_lifetimes)]
impl<'a> FromTableRef<read_fonts::codegen_test::generic_group::MySubtableFormat1<'a>>
    for MySubtableFormat1
{
}

impl<'a> FontRead<'a> for MySubtableFormat1 {
    fn read(data: FontData<'a>) -> Result<Self, ReadError> {
        <read_fonts::codegen_test::generic_group::MySubtableFormat1 as FontRead>::read(data)
            .map(|x| x.to_owned_table())
    }
}

#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct MySubtableFormat2 {
    pub values: Vec<u16>,
}

impl FontWrite for MySubtableFormat2 {
    #[allow(clippy::unnecessary_cast)]
    fn write_into(&self, writer: &mut TableWriter) {
        (2 as u16).write_into(writer);
        (u16::try_from(array_len(&self.values)).unwrap()).write_into(writer);
        self.values.write_into(writer);
    }
    fn table_type(&self) -> TableType {
        TableType::Named("MySubtableFormat2")
    }
}

impl Validate for MySubtableFormat2 {
    fn validate_impl(&self, ctx: &mut ValidationCtx) {
        ctx.in_table("MySubtableFormat2", |ctx| {
            ctx.in_field("values", |ctx| {
                if self.values.len() > (u16::MAX as usize) {
                    ctx.report("array exceeds max length");
                }
            });
        })
    }
}

impl<'a> FromObjRef<read_fonts::codegen_test::generic_group::MySubtableFormat2<'a>>
    for MySubtableFormat2
{
    fn from_obj_ref(
        obj: &read_fonts::codegen_test::generic_group::MySubtableFormat2<'a>,
        _: FontData,
    ) -> Self {
        let offset_data = obj.offset_data();
        MySubtableFormat2 {
            values: obj.values().to_owned_obj(offset_data),
        }
    }
}

#[allow(clippy::needless_lifetimes)]
impl<'a> FromTableRef<read_fonts::codegen_test::generic_group::MySubtableFormat2<'a>>
    for MySubtableFormat2
{
}

impl<'a> FontRead<'a> for MySubtableFormat2 {
    fn read(data: FontData<'a>) -> Result<Self, ReadError> {
        <read_fonts::codegen_test::generic_group::MySubtableFormat2 as FontRead>::read(data)
            .map(|x| x.to_owned_table())
    }
}

/// The group enum dispatching on lookup_type.
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum MyLookupGroup {
    TypeOne(MyLookup<MySubtable>),
    TypeTwo(MyLookup<MySubtableFormat1>),
}

impl Default for MyLookupGroup {
    fn default() -> Self {
        Self::TypeOne(Default::default())
    }
}

impl FontWrite for MyLookupGroup {
    fn write_into(&self, writer: &mut TableWriter) {
        match self {
            Self::TypeOne(table) => table.write_into(writer),
            Self::TypeTwo(table) => table.write_into(writer),
        }
    }
    fn table_type(&self) -> TableType {
        match self {
            Self::TypeOne(table) => table.table_type(),
            Self::TypeTwo(table) => table.table_type(),
        }
    }
}

impl Validate for MyLookupGroup {
    fn validate_impl(&self, ctx: &mut ValidationCtx) {
        match self {
            Self::TypeOne(table) => table.validate_impl(ctx),
            Self::TypeTwo(table) => table.validate_impl(ctx),
        }
    }
}

impl FromObjRef<read_fonts::codegen_test::generic_group::MyLookupGroup<'_>> for MyLookupGroup {
    fn from_obj_ref(
        from: &read_fonts::codegen_test::generic_group::MyLookupGroup<'_>,
        data: FontData,
    ) -> Self {
        match from {
            read_fonts::codegen_test::generic_group::MyLookupGroup::TypeOne(table) => {
                Self::TypeOne(table.to_owned_obj(data))
            }
            read_fonts::codegen_test::generic_group::MyLookupGroup::TypeTwo(table) => {
                Self::TypeTwo(table.to_owned_obj(data))
            }
        }
    }
}

impl FromTableRef<read_fonts::codegen_test::generic_group::MyLookupGroup<'_>> for MyLookupGroup {}

impl From<MyLookup<MySubtable>> for MyLookupGroup {
    fn from(src: MyLookup<MySubtable>) -> MyLookupGroup {
        MyLookupGroup::TypeOne(src)
    }
}

impl From<MyLookup<MySubtableFormat1>> for MyLookupGroup {
    fn from(src: MyLookup<MySubtableFormat1>) -> MyLookupGroup {
        MyLookupGroup::TypeTwo(src)
    }
}

#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ContainsLookupGroup {
    pub version: u16,
    pub lookup: OffsetMarker<MyLookupGroup>,
}

impl FontWrite for ContainsLookupGroup {
    fn write_into(&self, writer: &mut TableWriter) {
        self.version.write_into(writer);
        self.lookup.write_into(writer);
    }
    fn table_type(&self) -> TableType {
        TableType::Named("ContainsLookupGroup")
    }
}

impl Validate for ContainsLookupGroup {
    fn validate_impl(&self, ctx: &mut ValidationCtx) {
        ctx.in_table("ContainsLookupGroup", |ctx| {
            ctx.in_field("lookup", |ctx| {
                self.lookup.validate_impl(ctx);
            });
        })
    }
}

impl<'a> FromObjRef<read_fonts::codegen_test::generic_group::ContainsLookupGroup<'a>>
    for ContainsLookupGroup
{
    fn from_obj_ref(
        obj: &read_fonts::codegen_test::generic_group::ContainsLookupGroup<'a>,
        _: FontData,
    ) -> Self {
        ContainsLookupGroup {
            version: obj.version(),
            lookup: obj.lookup().to_owned_table(),
        }
    }
}

#[allow(clippy::needless_lifetimes)]
impl<'a> FromTableRef<read_fonts::codegen_test::generic_group::ContainsLookupGroup<'a>>
    for ContainsLookupGroup
{
}

impl<'a> FontRead<'a> for ContainsLookupGroup {
    fn read(data: FontData<'a>) -> Result<Self, ReadError> {
        <read_fonts::codegen_test::generic_group::ContainsLookupGroup as FontRead>::read(data)
            .map(|x| x.to_owned_table())
    }
}