write_fonts/generated/
generated_sbix.rs

1// THIS FILE IS AUTOGENERATED.
2// Any changes to this file will be overwritten.
3// For more information about how codegen works, see font-codegen/README.md
4
5#[allow(unused_imports)]
6use crate::codegen_prelude::*;
7
8pub use read_fonts::tables::sbix::HeaderFlags;
9
10impl FontWrite for HeaderFlags {
11    fn write_into(&self, writer: &mut TableWriter) {
12        writer.write_slice(&self.bits().to_be_bytes())
13    }
14}
15
16/// The [sbix (Standard Bitmap Graphics)](https://docs.microsoft.com/en-us/typography/opentype/spec/sbix) table
17#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
18#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
19pub struct Sbix {
20    /// Bit 0: Set to 1.
21    /// Bit 1: Draw outlines.
22    /// Bits 2 to 15: reserved (set to 0).
23    pub flags: HeaderFlags,
24    /// Offsets from the beginning of the 'sbix' table to data for each individual bitmap strike.
25    pub strikes: Vec<OffsetMarker<Strike, WIDTH_32>>,
26}
27
28impl Sbix {
29    /// Construct a new `Sbix`
30    pub fn new(flags: HeaderFlags, strikes: Vec<Strike>) -> Self {
31        Self {
32            flags,
33            strikes: strikes.into_iter().map(Into::into).collect(),
34        }
35    }
36}
37
38impl FontWrite for Sbix {
39    #[allow(clippy::unnecessary_cast)]
40    fn write_into(&self, writer: &mut TableWriter) {
41        (1 as u16).write_into(writer);
42        (self.compile_header_flags()).write_into(writer);
43        (u32::try_from(array_len(&self.strikes)).unwrap()).write_into(writer);
44        self.strikes.write_into(writer);
45    }
46    fn table_type(&self) -> TableType {
47        TableType::TopLevel(Sbix::TAG)
48    }
49}
50
51impl Validate for Sbix {
52    fn validate_impl(&self, ctx: &mut ValidationCtx) {
53        ctx.in_table("Sbix", |ctx| {
54            ctx.in_field("strikes", |ctx| {
55                if self.strikes.len() > (u32::MAX as usize) {
56                    ctx.report("array exceeds max length");
57                }
58                self.strikes.validate_impl(ctx);
59            });
60        })
61    }
62}
63
64impl TopLevelTable for Sbix {
65    const TAG: Tag = Tag::new(b"sbix");
66}
67
68impl<'a> FromObjRef<read_fonts::tables::sbix::Sbix<'a>> for Sbix {
69    fn from_obj_ref(obj: &read_fonts::tables::sbix::Sbix<'a>, _: FontData) -> Self {
70        Sbix {
71            flags: obj.flags(),
72            strikes: obj.strikes().to_owned_table(),
73        }
74    }
75}
76
77#[allow(clippy::needless_lifetimes)]
78impl<'a> FromTableRef<read_fonts::tables::sbix::Sbix<'a>> for Sbix {}
79
80/// [Strike](https://learn.microsoft.com/en-us/typography/opentype/spec/sbix#strikes) header table
81#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
82#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
83pub struct Strike {
84    /// The PPEM size for which this strike was designed.
85    pub ppem: u16,
86    /// The device pixel density (in PPI) for which this strike was designed. (E.g., 96 PPI, 192 PPI.)
87    pub ppi: u16,
88    /// Offset from the beginning of the strike data header to bitmap data for an individual glyph ID.
89    pub glyph_data_offsets: Vec<u32>,
90}
91
92impl Strike {
93    /// Construct a new `Strike`
94    pub fn new(ppem: u16, ppi: u16, glyph_data_offsets: Vec<u32>) -> Self {
95        Self {
96            ppem,
97            ppi,
98            glyph_data_offsets,
99        }
100    }
101}
102
103impl FontWrite for Strike {
104    fn write_into(&self, writer: &mut TableWriter) {
105        self.ppem.write_into(writer);
106        self.ppi.write_into(writer);
107        self.glyph_data_offsets.write_into(writer);
108    }
109    fn table_type(&self) -> TableType {
110        TableType::Named("Strike")
111    }
112}
113
114impl Validate for Strike {
115    fn validate_impl(&self, _ctx: &mut ValidationCtx) {}
116}
117
118impl<'a> FromObjRef<read_fonts::tables::sbix::Strike<'a>> for Strike {
119    fn from_obj_ref(obj: &read_fonts::tables::sbix::Strike<'a>, _: FontData) -> Self {
120        let offset_data = obj.offset_data();
121        Strike {
122            ppem: obj.ppem(),
123            ppi: obj.ppi(),
124            glyph_data_offsets: obj.glyph_data_offsets().to_owned_obj(offset_data),
125        }
126    }
127}
128
129#[allow(clippy::needless_lifetimes)]
130impl<'a> FromTableRef<read_fonts::tables::sbix::Strike<'a>> for Strike {}
131
132/// [Glyph data](https://learn.microsoft.com/en-us/typography/opentype/spec/sbix#glyph-data) table
133#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
134#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
135pub struct GlyphData {
136    /// The horizontal (x-axis) position of the left edge of the bitmap graphic in relation to the glyph design space origin.
137    pub origin_offset_x: i16,
138    /// The vertical (y-axis) position of the bottom edge of the bitmap graphic in relation to the glyph design space origin.
139    pub origin_offset_y: i16,
140    /// Indicates the format of the embedded graphic data: one of 'jpg ', 'png ' or 'tiff', or the special format 'dupe'.
141    pub graphic_type: Tag,
142    /// The actual embedded graphic data. The total length is inferred from sequential entries in the glyphDataOffsets array and the fixed size (8 bytes) of the preceding fields.
143    pub data: Vec<u8>,
144}
145
146impl GlyphData {
147    /// Construct a new `GlyphData`
148    pub fn new(
149        origin_offset_x: i16,
150        origin_offset_y: i16,
151        graphic_type: Tag,
152        data: Vec<u8>,
153    ) -> Self {
154        Self {
155            origin_offset_x,
156            origin_offset_y,
157            graphic_type,
158            data,
159        }
160    }
161}
162
163impl FontWrite for GlyphData {
164    fn write_into(&self, writer: &mut TableWriter) {
165        self.origin_offset_x.write_into(writer);
166        self.origin_offset_y.write_into(writer);
167        self.graphic_type.write_into(writer);
168        self.data.write_into(writer);
169    }
170    fn table_type(&self) -> TableType {
171        TableType::Named("GlyphData")
172    }
173}
174
175impl Validate for GlyphData {
176    fn validate_impl(&self, _ctx: &mut ValidationCtx) {}
177}
178
179impl<'a> FromObjRef<read_fonts::tables::sbix::GlyphData<'a>> for GlyphData {
180    fn from_obj_ref(obj: &read_fonts::tables::sbix::GlyphData<'a>, _: FontData) -> Self {
181        let offset_data = obj.offset_data();
182        GlyphData {
183            origin_offset_x: obj.origin_offset_x(),
184            origin_offset_y: obj.origin_offset_y(),
185            graphic_type: obj.graphic_type(),
186            data: obj.data().to_owned_obj(offset_data),
187        }
188    }
189}
190
191#[allow(clippy::needless_lifetimes)]
192impl<'a> FromTableRef<read_fonts::tables::sbix::GlyphData<'a>> for GlyphData {}
193
194impl<'a> FontRead<'a> for GlyphData {
195    fn read(data: FontData<'a>) -> Result<Self, ReadError> {
196        <read_fonts::tables::sbix::GlyphData as FontRead>::read(data).map(|x| x.to_owned_table())
197    }
198}