/src/fontations/write-fonts/generated/generated_sbix.rs
Line | Count | Source |
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)] |
6 | | use crate::codegen_prelude::*; |
7 | | |
8 | | pub use read_fonts::tables::sbix::HeaderFlags; |
9 | | |
10 | | impl FontWrite for HeaderFlags { |
11 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
12 | 0 | writer.write_slice(&self.bits().to_be_bytes()) |
13 | 0 | } |
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))] |
19 | | pub 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 | | |
28 | | impl Sbix { |
29 | | /// Construct a new `Sbix` |
30 | 0 | pub fn new(flags: HeaderFlags, strikes: Vec<Strike>) -> Self { |
31 | 0 | Self { |
32 | 0 | flags, |
33 | 0 | strikes: strikes.into_iter().map(Into::into).collect(), |
34 | 0 | } |
35 | 0 | } |
36 | | } |
37 | | |
38 | | impl FontWrite for Sbix { |
39 | | #[allow(clippy::unnecessary_cast)] |
40 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
41 | 0 | (1 as u16).write_into(writer); |
42 | 0 | (self.compile_header_flags()).write_into(writer); |
43 | 0 | (u32::try_from(array_len(&self.strikes)).unwrap()).write_into(writer); |
44 | 0 | self.strikes.write_into(writer); |
45 | 0 | } |
46 | 0 | fn table_type(&self) -> TableType { |
47 | 0 | TableType::TopLevel(Sbix::TAG) |
48 | 0 | } |
49 | | } |
50 | | |
51 | | impl Validate for Sbix { |
52 | 0 | fn validate_impl(&self, ctx: &mut ValidationCtx) { |
53 | 0 | ctx.in_table("Sbix", |ctx| { |
54 | 0 | ctx.in_field("strikes", |ctx| { |
55 | 0 | if self.strikes.len() > (u32::MAX as usize) { |
56 | 0 | ctx.report("array exceeds max length"); |
57 | 0 | } |
58 | 0 | self.strikes.validate_impl(ctx); |
59 | 0 | }); |
60 | 0 | }) |
61 | 0 | } |
62 | | } |
63 | | |
64 | | impl TopLevelTable for Sbix { |
65 | | const TAG: Tag = Tag::new(b"sbix"); |
66 | | } |
67 | | |
68 | | impl<'a> FromObjRef<read_fonts::tables::sbix::Sbix<'a>> for Sbix { |
69 | 0 | fn from_obj_ref(obj: &read_fonts::tables::sbix::Sbix<'a>, _: FontData) -> Self { |
70 | 0 | Sbix { |
71 | 0 | flags: obj.flags(), |
72 | 0 | strikes: obj.strikes().to_owned_table(), |
73 | 0 | } |
74 | 0 | } |
75 | | } |
76 | | |
77 | | #[allow(clippy::needless_lifetimes)] |
78 | | impl<'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))] |
83 | | pub 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 | | |
92 | | impl Strike { |
93 | | /// Construct a new `Strike` |
94 | 0 | pub fn new(ppem: u16, ppi: u16, glyph_data_offsets: Vec<u32>) -> Self { |
95 | 0 | Self { |
96 | 0 | ppem, |
97 | 0 | ppi, |
98 | 0 | glyph_data_offsets, |
99 | 0 | } |
100 | 0 | } |
101 | | } |
102 | | |
103 | | impl FontWrite for Strike { |
104 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
105 | 0 | self.ppem.write_into(writer); |
106 | 0 | self.ppi.write_into(writer); |
107 | 0 | self.glyph_data_offsets.write_into(writer); |
108 | 0 | } |
109 | 0 | fn table_type(&self) -> TableType { |
110 | 0 | TableType::Named("Strike") |
111 | 0 | } |
112 | | } |
113 | | |
114 | | impl Validate for Strike { |
115 | 0 | fn validate_impl(&self, _ctx: &mut ValidationCtx) {} |
116 | | } |
117 | | |
118 | | impl<'a> FromObjRef<read_fonts::tables::sbix::Strike<'a>> for Strike { |
119 | 0 | fn from_obj_ref(obj: &read_fonts::tables::sbix::Strike<'a>, _: FontData) -> Self { |
120 | 0 | let offset_data = obj.offset_data(); |
121 | 0 | Strike { |
122 | 0 | ppem: obj.ppem(), |
123 | 0 | ppi: obj.ppi(), |
124 | 0 | glyph_data_offsets: obj.glyph_data_offsets().to_owned_obj(offset_data), |
125 | 0 | } |
126 | 0 | } |
127 | | } |
128 | | |
129 | | #[allow(clippy::needless_lifetimes)] |
130 | | impl<'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))] |
135 | | pub 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 | | |
146 | | impl GlyphData { |
147 | | /// Construct a new `GlyphData` |
148 | 0 | pub fn new( |
149 | 0 | origin_offset_x: i16, |
150 | 0 | origin_offset_y: i16, |
151 | 0 | graphic_type: Tag, |
152 | 0 | data: Vec<u8>, |
153 | 0 | ) -> Self { |
154 | 0 | Self { |
155 | 0 | origin_offset_x, |
156 | 0 | origin_offset_y, |
157 | 0 | graphic_type, |
158 | 0 | data, |
159 | 0 | } |
160 | 0 | } |
161 | | } |
162 | | |
163 | | impl FontWrite for GlyphData { |
164 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
165 | 0 | self.origin_offset_x.write_into(writer); |
166 | 0 | self.origin_offset_y.write_into(writer); |
167 | 0 | self.graphic_type.write_into(writer); |
168 | 0 | self.data.write_into(writer); |
169 | 0 | } |
170 | 0 | fn table_type(&self) -> TableType { |
171 | 0 | TableType::Named("GlyphData") |
172 | 0 | } |
173 | | } |
174 | | |
175 | | impl Validate for GlyphData { |
176 | 0 | fn validate_impl(&self, _ctx: &mut ValidationCtx) {} |
177 | | } |
178 | | |
179 | | impl<'a> FromObjRef<read_fonts::tables::sbix::GlyphData<'a>> for GlyphData { |
180 | 0 | fn from_obj_ref(obj: &read_fonts::tables::sbix::GlyphData<'a>, _: FontData) -> Self { |
181 | 0 | let offset_data = obj.offset_data(); |
182 | 0 | GlyphData { |
183 | 0 | origin_offset_x: obj.origin_offset_x(), |
184 | 0 | origin_offset_y: obj.origin_offset_y(), |
185 | 0 | graphic_type: obj.graphic_type(), |
186 | 0 | data: obj.data().to_owned_obj(offset_data), |
187 | 0 | } |
188 | 0 | } |
189 | | } |
190 | | |
191 | | #[allow(clippy::needless_lifetimes)] |
192 | | impl<'a> FromTableRef<read_fonts::tables::sbix::GlyphData<'a>> for GlyphData {} |
193 | | |
194 | | impl<'a> FontRead<'a> for GlyphData { |
195 | 0 | fn read(data: FontData<'a>) -> Result<Self, ReadError> { |
196 | 0 | <read_fonts::tables::sbix::GlyphData as FontRead>::read(data).map(|x| x.to_owned_table()) |
197 | 0 | } |
198 | | } |