/src/fontations/write-fonts/generated/generated_colr.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::colr::{CompositeMode, Extend}; |
9 | | |
10 | | /// [COLR (Color)](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#colr-header) table |
11 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
12 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
13 | | pub struct Colr { |
14 | | /// Number of BaseGlyph records; may be 0 in a version 1 table. |
15 | | pub num_base_glyph_records: u16, |
16 | | /// Offset to baseGlyphRecords array (may be NULL). |
17 | | pub base_glyph_records: NullableOffsetMarker<Vec<BaseGlyph>, WIDTH_32>, |
18 | | /// Offset to layerRecords array (may be NULL). |
19 | | pub layer_records: NullableOffsetMarker<Vec<Layer>, WIDTH_32>, |
20 | | /// Number of Layer records; may be 0 in a version 1 table. |
21 | | pub num_layer_records: u16, |
22 | | /// Offset to BaseGlyphList table. |
23 | | pub base_glyph_list: NullableOffsetMarker<BaseGlyphList, WIDTH_32>, |
24 | | /// Offset to LayerList table (may be NULL). |
25 | | pub layer_list: NullableOffsetMarker<LayerList, WIDTH_32>, |
26 | | /// Offset to ClipList table (may be NULL). |
27 | | pub clip_list: NullableOffsetMarker<ClipList, WIDTH_32>, |
28 | | /// Offset to DeltaSetIndexMap table (may be NULL). |
29 | | pub var_index_map: NullableOffsetMarker<DeltaSetIndexMap, WIDTH_32>, |
30 | | /// Offset to ItemVariationStore (may be NULL). |
31 | | pub item_variation_store: NullableOffsetMarker<ItemVariationStore, WIDTH_32>, |
32 | | } |
33 | | |
34 | | impl Colr { |
35 | | /// Construct a new `Colr` |
36 | 0 | pub fn new( |
37 | 0 | num_base_glyph_records: u16, |
38 | 0 | base_glyph_records: Option<Vec<BaseGlyph>>, |
39 | 0 | layer_records: Option<Vec<Layer>>, |
40 | 0 | num_layer_records: u16, |
41 | 0 | ) -> Self { |
42 | 0 | Self { |
43 | 0 | num_base_glyph_records, |
44 | 0 | base_glyph_records: base_glyph_records.into(), |
45 | 0 | layer_records: layer_records.into(), |
46 | 0 | num_layer_records, |
47 | 0 | ..Default::default() |
48 | 0 | } |
49 | 0 | } |
50 | | } |
51 | | |
52 | | impl FontWrite for Colr { |
53 | | #[allow(clippy::unnecessary_cast)] |
54 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
55 | 0 | let version = self.compute_version() as u16; |
56 | 0 | version.write_into(writer); |
57 | 0 | self.num_base_glyph_records.write_into(writer); |
58 | 0 | self.base_glyph_records.write_into(writer); |
59 | 0 | self.layer_records.write_into(writer); |
60 | 0 | self.num_layer_records.write_into(writer); |
61 | 0 | version |
62 | 0 | .compatible(1u16) |
63 | 0 | .then(|| self.base_glyph_list.write_into(writer)); |
64 | 0 | version |
65 | 0 | .compatible(1u16) |
66 | 0 | .then(|| self.layer_list.write_into(writer)); |
67 | 0 | version |
68 | 0 | .compatible(1u16) |
69 | 0 | .then(|| self.clip_list.write_into(writer)); |
70 | 0 | version |
71 | 0 | .compatible(1u16) |
72 | 0 | .then(|| self.var_index_map.write_into(writer)); |
73 | 0 | version |
74 | 0 | .compatible(1u16) |
75 | 0 | .then(|| self.item_variation_store.write_into(writer)); |
76 | 0 | } |
77 | 0 | fn table_type(&self) -> TableType { |
78 | 0 | TableType::TopLevel(Colr::TAG) |
79 | 0 | } |
80 | | } |
81 | | |
82 | | impl Validate for Colr { |
83 | 0 | fn validate_impl(&self, ctx: &mut ValidationCtx) { |
84 | 0 | ctx.in_table("Colr", |ctx| { |
85 | 0 | ctx.in_field("base_glyph_records", |ctx| { |
86 | 0 | self.base_glyph_records.validate_impl(ctx); |
87 | 0 | }); |
88 | 0 | ctx.in_field("layer_records", |ctx| { |
89 | 0 | self.layer_records.validate_impl(ctx); |
90 | 0 | }); |
91 | 0 | ctx.in_field("base_glyph_list", |ctx| { |
92 | 0 | self.base_glyph_list.validate_impl(ctx); |
93 | 0 | }); |
94 | 0 | ctx.in_field("layer_list", |ctx| { |
95 | 0 | self.layer_list.validate_impl(ctx); |
96 | 0 | }); |
97 | 0 | ctx.in_field("clip_list", |ctx| { |
98 | 0 | self.clip_list.validate_impl(ctx); |
99 | 0 | }); |
100 | 0 | ctx.in_field("var_index_map", |ctx| { |
101 | 0 | self.var_index_map.validate_impl(ctx); |
102 | 0 | }); |
103 | 0 | ctx.in_field("item_variation_store", |ctx| { |
104 | 0 | self.item_variation_store.validate_impl(ctx); |
105 | 0 | }); |
106 | 0 | }) |
107 | 0 | } |
108 | | } |
109 | | |
110 | | impl TopLevelTable for Colr { |
111 | | const TAG: Tag = Tag::new(b"COLR"); |
112 | | } |
113 | | |
114 | | impl<'a> FromObjRef<read_fonts::tables::colr::Colr<'a>> for Colr { |
115 | 0 | fn from_obj_ref(obj: &read_fonts::tables::colr::Colr<'a>, _: FontData) -> Self { |
116 | 0 | let offset_data = obj.offset_data(); |
117 | 0 | Colr { |
118 | 0 | num_base_glyph_records: obj.num_base_glyph_records(), |
119 | 0 | base_glyph_records: obj.base_glyph_records().to_owned_obj(offset_data), |
120 | 0 | layer_records: obj.layer_records().to_owned_obj(offset_data), |
121 | 0 | num_layer_records: obj.num_layer_records(), |
122 | 0 | base_glyph_list: obj.base_glyph_list().to_owned_table(), |
123 | 0 | layer_list: obj.layer_list().to_owned_table(), |
124 | 0 | clip_list: obj.clip_list().to_owned_table(), |
125 | 0 | var_index_map: obj.var_index_map().to_owned_table(), |
126 | 0 | item_variation_store: obj.item_variation_store().to_owned_table(), |
127 | 0 | } |
128 | 0 | } |
129 | | } |
130 | | |
131 | | #[allow(clippy::needless_lifetimes)] |
132 | | impl<'a> FromTableRef<read_fonts::tables::colr::Colr<'a>> for Colr {} |
133 | | |
134 | | impl ReadArgs for Colr { |
135 | | type Args = (); |
136 | | } |
137 | | |
138 | | impl<'a> FontRead<'a> for Colr { |
139 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
140 | 0 | <read_fonts::tables::colr::Colr as FontRead>::read(data).map(|x| x.to_owned_table()) |
141 | 0 | } |
142 | | } |
143 | | |
144 | | /// [BaseGlyph](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#baseglyph-and-layer-records) record |
145 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
146 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
147 | | pub struct BaseGlyph { |
148 | | /// Glyph ID of the base glyph. |
149 | | pub glyph_id: GlyphId16, |
150 | | /// Index (base 0) into the layerRecords array. |
151 | | pub first_layer_index: u16, |
152 | | /// Number of color layers associated with this glyph. |
153 | | pub num_layers: u16, |
154 | | } |
155 | | |
156 | | impl BaseGlyph { |
157 | | /// Construct a new `BaseGlyph` |
158 | 0 | pub fn new(glyph_id: GlyphId16, first_layer_index: u16, num_layers: u16) -> Self { |
159 | 0 | Self { |
160 | 0 | glyph_id, |
161 | 0 | first_layer_index, |
162 | 0 | num_layers, |
163 | 0 | } |
164 | 0 | } |
165 | | } |
166 | | |
167 | | impl FontWrite for BaseGlyph { |
168 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
169 | 0 | self.glyph_id.write_into(writer); |
170 | 0 | self.first_layer_index.write_into(writer); |
171 | 0 | self.num_layers.write_into(writer); |
172 | 0 | } |
173 | 0 | fn table_type(&self) -> TableType { |
174 | 0 | TableType::Named("BaseGlyph") |
175 | 0 | } |
176 | | } |
177 | | |
178 | | impl Validate for BaseGlyph { |
179 | 0 | fn validate_impl(&self, _ctx: &mut ValidationCtx) {} |
180 | | } |
181 | | |
182 | | impl FromObjRef<read_fonts::tables::colr::BaseGlyph> for BaseGlyph { |
183 | 0 | fn from_obj_ref(obj: &read_fonts::tables::colr::BaseGlyph, _: FontData) -> Self { |
184 | 0 | BaseGlyph { |
185 | 0 | glyph_id: obj.glyph_id(), |
186 | 0 | first_layer_index: obj.first_layer_index(), |
187 | 0 | num_layers: obj.num_layers(), |
188 | 0 | } |
189 | 0 | } |
190 | | } |
191 | | |
192 | | /// [Layer](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#baseglyph-and-layer-records) record |
193 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
194 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
195 | | pub struct Layer { |
196 | | /// Glyph ID of the glyph used for a given layer. |
197 | | pub glyph_id: GlyphId16, |
198 | | /// Index (base 0) for a palette entry in the CPAL table. |
199 | | pub palette_index: u16, |
200 | | } |
201 | | |
202 | | impl Layer { |
203 | | /// Construct a new `Layer` |
204 | 0 | pub fn new(glyph_id: GlyphId16, palette_index: u16) -> Self { |
205 | 0 | Self { |
206 | 0 | glyph_id, |
207 | 0 | palette_index, |
208 | 0 | } |
209 | 0 | } |
210 | | } |
211 | | |
212 | | impl FontWrite for Layer { |
213 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
214 | 0 | self.glyph_id.write_into(writer); |
215 | 0 | self.palette_index.write_into(writer); |
216 | 0 | } |
217 | 0 | fn table_type(&self) -> TableType { |
218 | 0 | TableType::Named("Layer") |
219 | 0 | } |
220 | | } |
221 | | |
222 | | impl Validate for Layer { |
223 | 0 | fn validate_impl(&self, _ctx: &mut ValidationCtx) {} |
224 | | } |
225 | | |
226 | | impl FromObjRef<read_fonts::tables::colr::Layer> for Layer { |
227 | 0 | fn from_obj_ref(obj: &read_fonts::tables::colr::Layer, _: FontData) -> Self { |
228 | 0 | Layer { |
229 | 0 | glyph_id: obj.glyph_id(), |
230 | 0 | palette_index: obj.palette_index(), |
231 | 0 | } |
232 | 0 | } |
233 | | } |
234 | | |
235 | | /// [BaseGlyphList](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#baseglyphlist-layerlist-and-cliplist) table |
236 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
237 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
238 | | pub struct BaseGlyphList { |
239 | | pub num_base_glyph_paint_records: u32, |
240 | | pub base_glyph_paint_records: Vec<BaseGlyphPaint>, |
241 | | } |
242 | | |
243 | | impl BaseGlyphList { |
244 | | /// Construct a new `BaseGlyphList` |
245 | 0 | pub fn new( |
246 | 0 | num_base_glyph_paint_records: u32, |
247 | 0 | base_glyph_paint_records: Vec<BaseGlyphPaint>, |
248 | 0 | ) -> Self { |
249 | 0 | Self { |
250 | 0 | num_base_glyph_paint_records, |
251 | 0 | base_glyph_paint_records, |
252 | 0 | } |
253 | 0 | } |
254 | | } |
255 | | |
256 | | impl FontWrite for BaseGlyphList { |
257 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
258 | 0 | self.num_base_glyph_paint_records.write_into(writer); |
259 | 0 | self.base_glyph_paint_records.write_into(writer); |
260 | 0 | } |
261 | 0 | fn table_type(&self) -> TableType { |
262 | 0 | TableType::Named("BaseGlyphList") |
263 | 0 | } |
264 | | } |
265 | | |
266 | | impl Validate for BaseGlyphList { |
267 | 0 | fn validate_impl(&self, ctx: &mut ValidationCtx) { |
268 | 0 | ctx.in_table("BaseGlyphList", |ctx| { |
269 | 0 | ctx.in_field("base_glyph_paint_records", |ctx| { |
270 | 0 | if self.base_glyph_paint_records.len() > to_usize(u32::MAX) { |
271 | 0 | ctx.report("array exceeds max length"); |
272 | 0 | } |
273 | 0 | self.base_glyph_paint_records.validate_impl(ctx); |
274 | 0 | }); |
275 | 0 | }) |
276 | 0 | } |
277 | | } |
278 | | |
279 | | impl<'a> FromObjRef<read_fonts::tables::colr::BaseGlyphList<'a>> for BaseGlyphList { |
280 | 0 | fn from_obj_ref(obj: &read_fonts::tables::colr::BaseGlyphList<'a>, _: FontData) -> Self { |
281 | 0 | let offset_data = obj.offset_data(); |
282 | 0 | BaseGlyphList { |
283 | 0 | num_base_glyph_paint_records: obj.num_base_glyph_paint_records(), |
284 | 0 | base_glyph_paint_records: obj.base_glyph_paint_records().to_owned_obj(offset_data), |
285 | 0 | } |
286 | 0 | } |
287 | | } |
288 | | |
289 | | #[allow(clippy::needless_lifetimes)] |
290 | | impl<'a> FromTableRef<read_fonts::tables::colr::BaseGlyphList<'a>> for BaseGlyphList {} |
291 | | |
292 | | impl ReadArgs for BaseGlyphList { |
293 | | type Args = (); |
294 | | } |
295 | | |
296 | | impl<'a> FontRead<'a> for BaseGlyphList { |
297 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
298 | 0 | <read_fonts::tables::colr::BaseGlyphList as FontRead>::read(data) |
299 | 0 | .map(|x| x.to_owned_table()) |
300 | 0 | } |
301 | | } |
302 | | |
303 | | /// [BaseGlyphPaint](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#baseglyphlist-layerlist-and-cliplist) record |
304 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
305 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
306 | | pub struct BaseGlyphPaint { |
307 | | /// Glyph ID of the base glyph. |
308 | | pub glyph_id: GlyphId16, |
309 | | /// Offset to a Paint table, from the beginning of the [`BaseGlyphList`] table. |
310 | | pub paint: OffsetMarker<Paint, WIDTH_32>, |
311 | | } |
312 | | |
313 | | impl BaseGlyphPaint { |
314 | | /// Construct a new `BaseGlyphPaint` |
315 | 0 | pub fn new(glyph_id: GlyphId16, paint: Paint) -> Self { |
316 | 0 | Self { |
317 | 0 | glyph_id, |
318 | 0 | paint: paint.into(), |
319 | 0 | } |
320 | 0 | } |
321 | | } |
322 | | |
323 | | impl FontWrite for BaseGlyphPaint { |
324 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
325 | 0 | self.glyph_id.write_into(writer); |
326 | 0 | self.paint.write_into(writer); |
327 | 0 | } |
328 | 0 | fn table_type(&self) -> TableType { |
329 | 0 | TableType::Named("BaseGlyphPaint") |
330 | 0 | } |
331 | | } |
332 | | |
333 | | impl Validate for BaseGlyphPaint { |
334 | 0 | fn validate_impl(&self, ctx: &mut ValidationCtx) { |
335 | 0 | ctx.in_table("BaseGlyphPaint", |ctx| { |
336 | 0 | ctx.in_field("paint", |ctx| { |
337 | 0 | self.paint.validate_impl(ctx); |
338 | 0 | }); |
339 | 0 | }) |
340 | 0 | } |
341 | | } |
342 | | |
343 | | impl FromObjRef<read_fonts::tables::colr::BaseGlyphPaint> for BaseGlyphPaint { |
344 | 0 | fn from_obj_ref(obj: &read_fonts::tables::colr::BaseGlyphPaint, offset_data: FontData) -> Self { |
345 | 0 | BaseGlyphPaint { |
346 | 0 | glyph_id: obj.glyph_id(), |
347 | 0 | paint: obj.paint(offset_data).to_owned_table(), |
348 | 0 | } |
349 | 0 | } |
350 | | } |
351 | | |
352 | | /// [LayerList](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#baseglyphlist-layerlist-and-cliplist) table |
353 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
354 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
355 | | pub struct LayerList { |
356 | | pub num_layers: u32, |
357 | | /// Offsets to Paint tables. |
358 | | pub paints: Vec<OffsetMarker<Paint, WIDTH_32>>, |
359 | | } |
360 | | |
361 | | impl LayerList { |
362 | | /// Construct a new `LayerList` |
363 | 0 | pub fn new(num_layers: u32, paints: Vec<Paint>) -> Self { |
364 | 0 | Self { |
365 | 0 | num_layers, |
366 | 0 | paints: paints.into_iter().map(Into::into).collect(), |
367 | 0 | } |
368 | 0 | } |
369 | | } |
370 | | |
371 | | impl FontWrite for LayerList { |
372 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
373 | 0 | self.num_layers.write_into(writer); |
374 | 0 | self.paints.write_into(writer); |
375 | 0 | } |
376 | 0 | fn table_type(&self) -> TableType { |
377 | 0 | TableType::Named("LayerList") |
378 | 0 | } |
379 | | } |
380 | | |
381 | | impl Validate for LayerList { |
382 | 0 | fn validate_impl(&self, ctx: &mut ValidationCtx) { |
383 | 0 | ctx.in_table("LayerList", |ctx| { |
384 | 0 | ctx.in_field("paints", |ctx| { |
385 | 0 | if self.paints.len() > to_usize(u32::MAX) { |
386 | 0 | ctx.report("array exceeds max length"); |
387 | 0 | } |
388 | 0 | self.paints.validate_impl(ctx); |
389 | 0 | }); |
390 | 0 | }) |
391 | 0 | } |
392 | | } |
393 | | |
394 | | impl<'a> FromObjRef<read_fonts::tables::colr::LayerList<'a>> for LayerList { |
395 | 0 | fn from_obj_ref(obj: &read_fonts::tables::colr::LayerList<'a>, _: FontData) -> Self { |
396 | 0 | LayerList { |
397 | 0 | num_layers: obj.num_layers(), |
398 | 0 | paints: obj.paints().to_owned_table(), |
399 | 0 | } |
400 | 0 | } |
401 | | } |
402 | | |
403 | | #[allow(clippy::needless_lifetimes)] |
404 | | impl<'a> FromTableRef<read_fonts::tables::colr::LayerList<'a>> for LayerList {} |
405 | | |
406 | | impl ReadArgs for LayerList { |
407 | | type Args = (); |
408 | | } |
409 | | |
410 | | impl<'a> FontRead<'a> for LayerList { |
411 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
412 | 0 | <read_fonts::tables::colr::LayerList as FontRead>::read(data).map(|x| x.to_owned_table()) |
413 | 0 | } |
414 | | } |
415 | | |
416 | | /// [ClipList](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#baseglyphlist-layerlist-and-cliplist) table |
417 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
418 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
419 | | pub struct ClipList { |
420 | | /// Set to 1. |
421 | | pub format: u8, |
422 | | /// Number of Clip records. |
423 | | pub num_clips: u32, |
424 | | /// Clip records. Sorted by startGlyphID. |
425 | | pub clips: Vec<Clip>, |
426 | | } |
427 | | |
428 | | impl ClipList { |
429 | | /// Construct a new `ClipList` |
430 | 0 | pub fn new(format: u8, num_clips: u32, clips: Vec<Clip>) -> Self { |
431 | 0 | Self { |
432 | 0 | format, |
433 | 0 | num_clips, |
434 | 0 | clips, |
435 | 0 | } |
436 | 0 | } |
437 | | } |
438 | | |
439 | | impl FontWrite for ClipList { |
440 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
441 | 0 | self.format.write_into(writer); |
442 | 0 | self.num_clips.write_into(writer); |
443 | 0 | self.clips.write_into(writer); |
444 | 0 | } |
445 | 0 | fn table_type(&self) -> TableType { |
446 | 0 | TableType::Named("ClipList") |
447 | 0 | } |
448 | | } |
449 | | |
450 | | impl Validate for ClipList { |
451 | 0 | fn validate_impl(&self, ctx: &mut ValidationCtx) { |
452 | 0 | ctx.in_table("ClipList", |ctx| { |
453 | 0 | ctx.in_field("clips", |ctx| { |
454 | 0 | if self.clips.len() > to_usize(u32::MAX) { |
455 | 0 | ctx.report("array exceeds max length"); |
456 | 0 | } |
457 | 0 | self.clips.validate_impl(ctx); |
458 | 0 | }); |
459 | 0 | }) |
460 | 0 | } |
461 | | } |
462 | | |
463 | | impl<'a> FromObjRef<read_fonts::tables::colr::ClipList<'a>> for ClipList { |
464 | 0 | fn from_obj_ref(obj: &read_fonts::tables::colr::ClipList<'a>, _: FontData) -> Self { |
465 | 0 | let offset_data = obj.offset_data(); |
466 | 0 | ClipList { |
467 | 0 | format: obj.format(), |
468 | 0 | num_clips: obj.num_clips(), |
469 | 0 | clips: obj.clips().to_owned_obj(offset_data), |
470 | 0 | } |
471 | 0 | } |
472 | | } |
473 | | |
474 | | #[allow(clippy::needless_lifetimes)] |
475 | | impl<'a> FromTableRef<read_fonts::tables::colr::ClipList<'a>> for ClipList {} |
476 | | |
477 | | impl ReadArgs for ClipList { |
478 | | type Args = (); |
479 | | } |
480 | | |
481 | | impl<'a> FontRead<'a> for ClipList { |
482 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
483 | 0 | <read_fonts::tables::colr::ClipList as FontRead>::read(data).map(|x| x.to_owned_table()) |
484 | 0 | } |
485 | | } |
486 | | |
487 | | /// [Clip](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#baseglyphlist-layerlist-and-cliplist) record |
488 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
489 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
490 | | pub struct Clip { |
491 | | /// First glyph ID in the range. |
492 | | pub start_glyph_id: GlyphId16, |
493 | | /// Last glyph ID in the range. |
494 | | pub end_glyph_id: GlyphId16, |
495 | | /// Offset to a ClipBox table, from the beginning of the [`ClipList`] table. |
496 | | pub clip_box: OffsetMarker<ClipBox, WIDTH_24>, |
497 | | } |
498 | | |
499 | | impl Clip { |
500 | | /// Construct a new `Clip` |
501 | 0 | pub fn new(start_glyph_id: GlyphId16, end_glyph_id: GlyphId16, clip_box: ClipBox) -> Self { |
502 | 0 | Self { |
503 | 0 | start_glyph_id, |
504 | 0 | end_glyph_id, |
505 | 0 | clip_box: clip_box.into(), |
506 | 0 | } |
507 | 0 | } |
508 | | } |
509 | | |
510 | | impl FontWrite for Clip { |
511 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
512 | 0 | self.start_glyph_id.write_into(writer); |
513 | 0 | self.end_glyph_id.write_into(writer); |
514 | 0 | self.clip_box.write_into(writer); |
515 | 0 | } |
516 | 0 | fn table_type(&self) -> TableType { |
517 | 0 | TableType::Named("Clip") |
518 | 0 | } |
519 | | } |
520 | | |
521 | | impl Validate for Clip { |
522 | 0 | fn validate_impl(&self, ctx: &mut ValidationCtx) { |
523 | 0 | ctx.in_table("Clip", |ctx| { |
524 | 0 | ctx.in_field("clip_box", |ctx| { |
525 | 0 | self.clip_box.validate_impl(ctx); |
526 | 0 | }); |
527 | 0 | }) |
528 | 0 | } |
529 | | } |
530 | | |
531 | | impl FromObjRef<read_fonts::tables::colr::Clip> for Clip { |
532 | 0 | fn from_obj_ref(obj: &read_fonts::tables::colr::Clip, offset_data: FontData) -> Self { |
533 | 0 | Clip { |
534 | 0 | start_glyph_id: obj.start_glyph_id(), |
535 | 0 | end_glyph_id: obj.end_glyph_id(), |
536 | 0 | clip_box: obj.clip_box(offset_data).to_owned_table(), |
537 | 0 | } |
538 | 0 | } |
539 | | } |
540 | | |
541 | | /// [ClipBox](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#baseglyphlist-layerlist-and-cliplist) table |
542 | | #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] |
543 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
544 | | pub enum ClipBox { |
545 | | Format1(ClipBoxFormat1), |
546 | | Format2(ClipBoxFormat2), |
547 | | } |
548 | | |
549 | | impl ClipBox { |
550 | | /// Construct a new `ClipBoxFormat1` subtable |
551 | 0 | pub fn format_1(x_min: FWord, y_min: FWord, x_max: FWord, y_max: FWord) -> Self { |
552 | 0 | Self::Format1(ClipBoxFormat1::new(x_min, y_min, x_max, y_max)) |
553 | 0 | } |
554 | | |
555 | | /// Construct a new `ClipBoxFormat2` subtable |
556 | 0 | pub fn format_2( |
557 | 0 | x_min: FWord, |
558 | 0 | y_min: FWord, |
559 | 0 | x_max: FWord, |
560 | 0 | y_max: FWord, |
561 | 0 | var_index_base: u32, |
562 | 0 | ) -> Self { |
563 | 0 | Self::Format2(ClipBoxFormat2::new( |
564 | 0 | x_min, |
565 | 0 | y_min, |
566 | 0 | x_max, |
567 | 0 | y_max, |
568 | 0 | var_index_base, |
569 | 0 | )) |
570 | 0 | } |
571 | | } |
572 | | |
573 | | impl Default for ClipBox { |
574 | 0 | fn default() -> Self { |
575 | 0 | Self::Format1(Default::default()) |
576 | 0 | } |
577 | | } |
578 | | |
579 | | impl FontWrite for ClipBox { |
580 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
581 | 0 | match self { |
582 | 0 | Self::Format1(item) => item.write_into(writer), |
583 | 0 | Self::Format2(item) => item.write_into(writer), |
584 | | } |
585 | 0 | } |
586 | 0 | fn table_type(&self) -> TableType { |
587 | 0 | match self { |
588 | 0 | Self::Format1(item) => item.table_type(), |
589 | 0 | Self::Format2(item) => item.table_type(), |
590 | | } |
591 | 0 | } |
592 | | } |
593 | | |
594 | | impl Validate for ClipBox { |
595 | 0 | fn validate_impl(&self, ctx: &mut ValidationCtx) { |
596 | 0 | match self { |
597 | 0 | Self::Format1(item) => item.validate_impl(ctx), |
598 | 0 | Self::Format2(item) => item.validate_impl(ctx), |
599 | | } |
600 | 0 | } |
601 | | } |
602 | | |
603 | | impl FromObjRef<read_fonts::tables::colr::ClipBox<'_>> for ClipBox { |
604 | 0 | fn from_obj_ref(obj: &read_fonts::tables::colr::ClipBox, _: FontData) -> Self { |
605 | | use read_fonts::tables::colr::ClipBox as ObjRefType; |
606 | 0 | match obj { |
607 | 0 | ObjRefType::Format1(item) => ClipBox::Format1(item.to_owned_table()), |
608 | 0 | ObjRefType::Format2(item) => ClipBox::Format2(item.to_owned_table()), |
609 | | } |
610 | 0 | } |
611 | | } |
612 | | |
613 | | impl FromTableRef<read_fonts::tables::colr::ClipBox<'_>> for ClipBox {} |
614 | | |
615 | | impl ReadArgs for ClipBox { |
616 | | type Args = (); |
617 | | } |
618 | | |
619 | | impl<'a> FontRead<'a> for ClipBox { |
620 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
621 | 0 | <read_fonts::tables::colr::ClipBox as FontRead>::read(data).map(|x| x.to_owned_table()) |
622 | 0 | } |
623 | | } |
624 | | |
625 | | impl From<ClipBoxFormat1> for ClipBox { |
626 | 0 | fn from(src: ClipBoxFormat1) -> ClipBox { |
627 | 0 | ClipBox::Format1(src) |
628 | 0 | } |
629 | | } |
630 | | |
631 | | impl From<ClipBoxFormat2> for ClipBox { |
632 | 0 | fn from(src: ClipBoxFormat2) -> ClipBox { |
633 | 0 | ClipBox::Format2(src) |
634 | 0 | } |
635 | | } |
636 | | |
637 | | /// [ClipBoxFormat1](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#baseglyphlist-layerlist-and-cliplist) record |
638 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
639 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
640 | | pub struct ClipBoxFormat1 { |
641 | | /// Minimum x of clip box. |
642 | | pub x_min: FWord, |
643 | | /// Minimum y of clip box. |
644 | | pub y_min: FWord, |
645 | | /// Maximum x of clip box. |
646 | | pub x_max: FWord, |
647 | | /// Maximum y of clip box. |
648 | | pub y_max: FWord, |
649 | | } |
650 | | |
651 | | impl ClipBoxFormat1 { |
652 | | /// Construct a new `ClipBoxFormat1` |
653 | 0 | pub fn new(x_min: FWord, y_min: FWord, x_max: FWord, y_max: FWord) -> Self { |
654 | 0 | Self { |
655 | 0 | x_min, |
656 | 0 | y_min, |
657 | 0 | x_max, |
658 | 0 | y_max, |
659 | 0 | } |
660 | 0 | } |
661 | | } |
662 | | |
663 | | impl FontWrite for ClipBoxFormat1 { |
664 | | #[allow(clippy::unnecessary_cast)] |
665 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
666 | 0 | (1 as u8).write_into(writer); |
667 | 0 | self.x_min.write_into(writer); |
668 | 0 | self.y_min.write_into(writer); |
669 | 0 | self.x_max.write_into(writer); |
670 | 0 | self.y_max.write_into(writer); |
671 | 0 | } |
672 | 0 | fn table_type(&self) -> TableType { |
673 | 0 | TableType::Named("ClipBoxFormat1") |
674 | 0 | } |
675 | | } |
676 | | |
677 | | impl Validate for ClipBoxFormat1 { |
678 | 0 | fn validate_impl(&self, _ctx: &mut ValidationCtx) {} |
679 | | } |
680 | | |
681 | | impl<'a> FromObjRef<read_fonts::tables::colr::ClipBoxFormat1<'a>> for ClipBoxFormat1 { |
682 | 0 | fn from_obj_ref(obj: &read_fonts::tables::colr::ClipBoxFormat1<'a>, _: FontData) -> Self { |
683 | 0 | ClipBoxFormat1 { |
684 | 0 | x_min: obj.x_min(), |
685 | 0 | y_min: obj.y_min(), |
686 | 0 | x_max: obj.x_max(), |
687 | 0 | y_max: obj.y_max(), |
688 | 0 | } |
689 | 0 | } |
690 | | } |
691 | | |
692 | | #[allow(clippy::needless_lifetimes)] |
693 | | impl<'a> FromTableRef<read_fonts::tables::colr::ClipBoxFormat1<'a>> for ClipBoxFormat1 {} |
694 | | |
695 | | impl ReadArgs for ClipBoxFormat1 { |
696 | | type Args = (); |
697 | | } |
698 | | |
699 | | impl<'a> FontRead<'a> for ClipBoxFormat1 { |
700 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
701 | 0 | <read_fonts::tables::colr::ClipBoxFormat1 as FontRead>::read(data) |
702 | 0 | .map(|x| x.to_owned_table()) |
703 | 0 | } |
704 | | } |
705 | | |
706 | | /// [ClipBoxFormat2](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#baseglyphlist-layerlist-and-cliplist) record |
707 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
708 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
709 | | pub struct ClipBoxFormat2 { |
710 | | /// Minimum x of clip box. For variation, use varIndexBase + 0. |
711 | | pub x_min: FWord, |
712 | | /// Minimum y of clip box. For variation, use varIndexBase + 1. |
713 | | pub y_min: FWord, |
714 | | /// Maximum x of clip box. For variation, use varIndexBase + 2. |
715 | | pub x_max: FWord, |
716 | | /// Maximum y of clip box. For variation, use varIndexBase + 3. |
717 | | pub y_max: FWord, |
718 | | /// Base index into DeltaSetIndexMap. |
719 | | pub var_index_base: u32, |
720 | | } |
721 | | |
722 | | impl ClipBoxFormat2 { |
723 | | /// Construct a new `ClipBoxFormat2` |
724 | 0 | pub fn new( |
725 | 0 | x_min: FWord, |
726 | 0 | y_min: FWord, |
727 | 0 | x_max: FWord, |
728 | 0 | y_max: FWord, |
729 | 0 | var_index_base: u32, |
730 | 0 | ) -> Self { |
731 | 0 | Self { |
732 | 0 | x_min, |
733 | 0 | y_min, |
734 | 0 | x_max, |
735 | 0 | y_max, |
736 | 0 | var_index_base, |
737 | 0 | } |
738 | 0 | } |
739 | | } |
740 | | |
741 | | impl FontWrite for ClipBoxFormat2 { |
742 | | #[allow(clippy::unnecessary_cast)] |
743 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
744 | 0 | (2 as u8).write_into(writer); |
745 | 0 | self.x_min.write_into(writer); |
746 | 0 | self.y_min.write_into(writer); |
747 | 0 | self.x_max.write_into(writer); |
748 | 0 | self.y_max.write_into(writer); |
749 | 0 | self.var_index_base.write_into(writer); |
750 | 0 | } |
751 | 0 | fn table_type(&self) -> TableType { |
752 | 0 | TableType::Named("ClipBoxFormat2") |
753 | 0 | } |
754 | | } |
755 | | |
756 | | impl Validate for ClipBoxFormat2 { |
757 | 0 | fn validate_impl(&self, _ctx: &mut ValidationCtx) {} |
758 | | } |
759 | | |
760 | | impl<'a> FromObjRef<read_fonts::tables::colr::ClipBoxFormat2<'a>> for ClipBoxFormat2 { |
761 | 0 | fn from_obj_ref(obj: &read_fonts::tables::colr::ClipBoxFormat2<'a>, _: FontData) -> Self { |
762 | 0 | ClipBoxFormat2 { |
763 | 0 | x_min: obj.x_min(), |
764 | 0 | y_min: obj.y_min(), |
765 | 0 | x_max: obj.x_max(), |
766 | 0 | y_max: obj.y_max(), |
767 | 0 | var_index_base: obj.var_index_base(), |
768 | 0 | } |
769 | 0 | } |
770 | | } |
771 | | |
772 | | #[allow(clippy::needless_lifetimes)] |
773 | | impl<'a> FromTableRef<read_fonts::tables::colr::ClipBoxFormat2<'a>> for ClipBoxFormat2 {} |
774 | | |
775 | | impl ReadArgs for ClipBoxFormat2 { |
776 | | type Args = (); |
777 | | } |
778 | | |
779 | | impl<'a> FontRead<'a> for ClipBoxFormat2 { |
780 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
781 | 0 | <read_fonts::tables::colr::ClipBoxFormat2 as FontRead>::read(data) |
782 | 0 | .map(|x| x.to_owned_table()) |
783 | 0 | } |
784 | | } |
785 | | |
786 | | /// [ColorIndex](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#color-references-colorstop-and-colorline) record |
787 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
788 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
789 | | pub struct ColorIndex { |
790 | | /// Index for a CPAL palette entry. |
791 | | pub palette_index: u16, |
792 | | /// Alpha value. |
793 | | pub alpha: F2Dot14, |
794 | | } |
795 | | |
796 | | impl ColorIndex { |
797 | | /// Construct a new `ColorIndex` |
798 | 0 | pub fn new(palette_index: u16, alpha: F2Dot14) -> Self { |
799 | 0 | Self { |
800 | 0 | palette_index, |
801 | 0 | alpha, |
802 | 0 | } |
803 | 0 | } |
804 | | } |
805 | | |
806 | | impl FontWrite for ColorIndex { |
807 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
808 | 0 | self.palette_index.write_into(writer); |
809 | 0 | self.alpha.write_into(writer); |
810 | 0 | } |
811 | 0 | fn table_type(&self) -> TableType { |
812 | 0 | TableType::Named("ColorIndex") |
813 | 0 | } |
814 | | } |
815 | | |
816 | | impl Validate for ColorIndex { |
817 | 0 | fn validate_impl(&self, _ctx: &mut ValidationCtx) {} |
818 | | } |
819 | | |
820 | | impl FromObjRef<read_fonts::tables::colr::ColorIndex> for ColorIndex { |
821 | 0 | fn from_obj_ref(obj: &read_fonts::tables::colr::ColorIndex, _: FontData) -> Self { |
822 | 0 | ColorIndex { |
823 | 0 | palette_index: obj.palette_index(), |
824 | 0 | alpha: obj.alpha(), |
825 | 0 | } |
826 | 0 | } |
827 | | } |
828 | | |
829 | | /// [VarColorIndex](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#color-references-colorstop-and-colorline) record |
830 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
831 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
832 | | pub struct VarColorIndex { |
833 | | /// Index for a CPAL palette entry. |
834 | | pub palette_index: u16, |
835 | | /// Alpha value. For variation, use varIndexBase + 0. |
836 | | pub alpha: F2Dot14, |
837 | | /// Base index into DeltaSetIndexMap. |
838 | | pub var_index_base: u32, |
839 | | } |
840 | | |
841 | | impl VarColorIndex { |
842 | | /// Construct a new `VarColorIndex` |
843 | 0 | pub fn new(palette_index: u16, alpha: F2Dot14, var_index_base: u32) -> Self { |
844 | 0 | Self { |
845 | 0 | palette_index, |
846 | 0 | alpha, |
847 | 0 | var_index_base, |
848 | 0 | } |
849 | 0 | } |
850 | | } |
851 | | |
852 | | impl FontWrite for VarColorIndex { |
853 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
854 | 0 | self.palette_index.write_into(writer); |
855 | 0 | self.alpha.write_into(writer); |
856 | 0 | self.var_index_base.write_into(writer); |
857 | 0 | } |
858 | 0 | fn table_type(&self) -> TableType { |
859 | 0 | TableType::Named("VarColorIndex") |
860 | 0 | } |
861 | | } |
862 | | |
863 | | impl Validate for VarColorIndex { |
864 | 0 | fn validate_impl(&self, _ctx: &mut ValidationCtx) {} |
865 | | } |
866 | | |
867 | | impl FromObjRef<read_fonts::tables::colr::VarColorIndex> for VarColorIndex { |
868 | 0 | fn from_obj_ref(obj: &read_fonts::tables::colr::VarColorIndex, _: FontData) -> Self { |
869 | 0 | VarColorIndex { |
870 | 0 | palette_index: obj.palette_index(), |
871 | 0 | alpha: obj.alpha(), |
872 | 0 | var_index_base: obj.var_index_base(), |
873 | 0 | } |
874 | 0 | } |
875 | | } |
876 | | |
877 | | /// [ColorStop](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#color-references-colorstop-and-colorline) record |
878 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
879 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
880 | | pub struct ColorStop { |
881 | | /// Position on a color line. |
882 | | pub stop_offset: F2Dot14, |
883 | | /// Index for a CPAL palette entry. |
884 | | pub palette_index: u16, |
885 | | /// Alpha value. |
886 | | pub alpha: F2Dot14, |
887 | | } |
888 | | |
889 | | impl ColorStop { |
890 | | /// Construct a new `ColorStop` |
891 | 0 | pub fn new(stop_offset: F2Dot14, palette_index: u16, alpha: F2Dot14) -> Self { |
892 | 0 | Self { |
893 | 0 | stop_offset, |
894 | 0 | palette_index, |
895 | 0 | alpha, |
896 | 0 | } |
897 | 0 | } |
898 | | } |
899 | | |
900 | | impl FontWrite for ColorStop { |
901 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
902 | 0 | self.stop_offset.write_into(writer); |
903 | 0 | self.palette_index.write_into(writer); |
904 | 0 | self.alpha.write_into(writer); |
905 | 0 | } |
906 | 0 | fn table_type(&self) -> TableType { |
907 | 0 | TableType::Named("ColorStop") |
908 | 0 | } |
909 | | } |
910 | | |
911 | | impl Validate for ColorStop { |
912 | 0 | fn validate_impl(&self, _ctx: &mut ValidationCtx) {} |
913 | | } |
914 | | |
915 | | impl FromObjRef<read_fonts::tables::colr::ColorStop> for ColorStop { |
916 | 0 | fn from_obj_ref(obj: &read_fonts::tables::colr::ColorStop, _: FontData) -> Self { |
917 | 0 | ColorStop { |
918 | 0 | stop_offset: obj.stop_offset(), |
919 | 0 | palette_index: obj.palette_index(), |
920 | 0 | alpha: obj.alpha(), |
921 | 0 | } |
922 | 0 | } |
923 | | } |
924 | | |
925 | | /// [VarColorStop](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#color-references-colorstop-and-colorline) record |
926 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
927 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
928 | | pub struct VarColorStop { |
929 | | /// Position on a color line. For variation, use varIndexBase + 0. |
930 | | pub stop_offset: F2Dot14, |
931 | | /// Index for a CPAL palette entry. |
932 | | pub palette_index: u16, |
933 | | /// Alpha value. For variation, use varIndexBase + 1. |
934 | | pub alpha: F2Dot14, |
935 | | /// Base index into DeltaSetIndexMap. |
936 | | pub var_index_base: u32, |
937 | | } |
938 | | |
939 | | impl VarColorStop { |
940 | | /// Construct a new `VarColorStop` |
941 | 0 | pub fn new( |
942 | 0 | stop_offset: F2Dot14, |
943 | 0 | palette_index: u16, |
944 | 0 | alpha: F2Dot14, |
945 | 0 | var_index_base: u32, |
946 | 0 | ) -> Self { |
947 | 0 | Self { |
948 | 0 | stop_offset, |
949 | 0 | palette_index, |
950 | 0 | alpha, |
951 | 0 | var_index_base, |
952 | 0 | } |
953 | 0 | } |
954 | | } |
955 | | |
956 | | impl FontWrite for VarColorStop { |
957 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
958 | 0 | self.stop_offset.write_into(writer); |
959 | 0 | self.palette_index.write_into(writer); |
960 | 0 | self.alpha.write_into(writer); |
961 | 0 | self.var_index_base.write_into(writer); |
962 | 0 | } |
963 | 0 | fn table_type(&self) -> TableType { |
964 | 0 | TableType::Named("VarColorStop") |
965 | 0 | } |
966 | | } |
967 | | |
968 | | impl Validate for VarColorStop { |
969 | 0 | fn validate_impl(&self, _ctx: &mut ValidationCtx) {} |
970 | | } |
971 | | |
972 | | impl FromObjRef<read_fonts::tables::colr::VarColorStop> for VarColorStop { |
973 | 0 | fn from_obj_ref(obj: &read_fonts::tables::colr::VarColorStop, _: FontData) -> Self { |
974 | 0 | VarColorStop { |
975 | 0 | stop_offset: obj.stop_offset(), |
976 | 0 | palette_index: obj.palette_index(), |
977 | 0 | alpha: obj.alpha(), |
978 | 0 | var_index_base: obj.var_index_base(), |
979 | 0 | } |
980 | 0 | } |
981 | | } |
982 | | |
983 | | /// [ColorLine](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#color-references-colorstop-and-colorline) table |
984 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
985 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
986 | | pub struct ColorLine { |
987 | | /// An Extend enum value. |
988 | | pub extend: Extend, |
989 | | /// Number of ColorStop records. |
990 | | pub num_stops: u16, |
991 | | pub color_stops: Vec<ColorStop>, |
992 | | } |
993 | | |
994 | | impl ColorLine { |
995 | | /// Construct a new `ColorLine` |
996 | 0 | pub fn new(extend: Extend, num_stops: u16, color_stops: Vec<ColorStop>) -> Self { |
997 | 0 | Self { |
998 | 0 | extend, |
999 | 0 | num_stops, |
1000 | 0 | color_stops, |
1001 | 0 | } |
1002 | 0 | } |
1003 | | } |
1004 | | |
1005 | | impl FontWrite for ColorLine { |
1006 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
1007 | 0 | self.extend.write_into(writer); |
1008 | 0 | self.num_stops.write_into(writer); |
1009 | 0 | self.color_stops.write_into(writer); |
1010 | 0 | } |
1011 | 0 | fn table_type(&self) -> TableType { |
1012 | 0 | TableType::Named("ColorLine") |
1013 | 0 | } |
1014 | | } |
1015 | | |
1016 | | impl Validate for ColorLine { |
1017 | 0 | fn validate_impl(&self, ctx: &mut ValidationCtx) { |
1018 | 0 | ctx.in_table("ColorLine", |ctx| { |
1019 | 0 | ctx.in_field("color_stops", |ctx| { |
1020 | 0 | if self.color_stops.len() > to_usize(u16::MAX) { |
1021 | 0 | ctx.report("array exceeds max length"); |
1022 | 0 | } |
1023 | 0 | self.color_stops.validate_impl(ctx); |
1024 | 0 | }); |
1025 | 0 | }) |
1026 | 0 | } |
1027 | | } |
1028 | | |
1029 | | impl<'a> FromObjRef<read_fonts::tables::colr::ColorLine<'a>> for ColorLine { |
1030 | 0 | fn from_obj_ref(obj: &read_fonts::tables::colr::ColorLine<'a>, _: FontData) -> Self { |
1031 | 0 | let offset_data = obj.offset_data(); |
1032 | 0 | ColorLine { |
1033 | 0 | extend: obj.extend(), |
1034 | 0 | num_stops: obj.num_stops(), |
1035 | 0 | color_stops: obj.color_stops().to_owned_obj(offset_data), |
1036 | 0 | } |
1037 | 0 | } |
1038 | | } |
1039 | | |
1040 | | #[allow(clippy::needless_lifetimes)] |
1041 | | impl<'a> FromTableRef<read_fonts::tables::colr::ColorLine<'a>> for ColorLine {} |
1042 | | |
1043 | | impl ReadArgs for ColorLine { |
1044 | | type Args = (); |
1045 | | } |
1046 | | |
1047 | | impl<'a> FontRead<'a> for ColorLine { |
1048 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
1049 | 0 | <read_fonts::tables::colr::ColorLine as FontRead>::read(data).map(|x| x.to_owned_table()) |
1050 | 0 | } |
1051 | | } |
1052 | | |
1053 | | /// [VarColorLine](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#color-references-colorstop-and-colorline) table |
1054 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
1055 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
1056 | | pub struct VarColorLine { |
1057 | | /// An Extend enum value. |
1058 | | pub extend: Extend, |
1059 | | /// Number of ColorStop records. |
1060 | | pub num_stops: u16, |
1061 | | /// Allows for variations. |
1062 | | pub color_stops: Vec<VarColorStop>, |
1063 | | } |
1064 | | |
1065 | | impl VarColorLine { |
1066 | | /// Construct a new `VarColorLine` |
1067 | 0 | pub fn new(extend: Extend, num_stops: u16, color_stops: Vec<VarColorStop>) -> Self { |
1068 | 0 | Self { |
1069 | 0 | extend, |
1070 | 0 | num_stops, |
1071 | 0 | color_stops, |
1072 | 0 | } |
1073 | 0 | } |
1074 | | } |
1075 | | |
1076 | | impl FontWrite for VarColorLine { |
1077 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
1078 | 0 | self.extend.write_into(writer); |
1079 | 0 | self.num_stops.write_into(writer); |
1080 | 0 | self.color_stops.write_into(writer); |
1081 | 0 | } |
1082 | 0 | fn table_type(&self) -> TableType { |
1083 | 0 | TableType::Named("VarColorLine") |
1084 | 0 | } |
1085 | | } |
1086 | | |
1087 | | impl Validate for VarColorLine { |
1088 | 0 | fn validate_impl(&self, ctx: &mut ValidationCtx) { |
1089 | 0 | ctx.in_table("VarColorLine", |ctx| { |
1090 | 0 | ctx.in_field("color_stops", |ctx| { |
1091 | 0 | if self.color_stops.len() > to_usize(u16::MAX) { |
1092 | 0 | ctx.report("array exceeds max length"); |
1093 | 0 | } |
1094 | 0 | self.color_stops.validate_impl(ctx); |
1095 | 0 | }); |
1096 | 0 | }) |
1097 | 0 | } |
1098 | | } |
1099 | | |
1100 | | impl<'a> FromObjRef<read_fonts::tables::colr::VarColorLine<'a>> for VarColorLine { |
1101 | 0 | fn from_obj_ref(obj: &read_fonts::tables::colr::VarColorLine<'a>, _: FontData) -> Self { |
1102 | 0 | let offset_data = obj.offset_data(); |
1103 | 0 | VarColorLine { |
1104 | 0 | extend: obj.extend(), |
1105 | 0 | num_stops: obj.num_stops(), |
1106 | 0 | color_stops: obj.color_stops().to_owned_obj(offset_data), |
1107 | 0 | } |
1108 | 0 | } |
1109 | | } |
1110 | | |
1111 | | #[allow(clippy::needless_lifetimes)] |
1112 | | impl<'a> FromTableRef<read_fonts::tables::colr::VarColorLine<'a>> for VarColorLine {} |
1113 | | |
1114 | | impl ReadArgs for VarColorLine { |
1115 | | type Args = (); |
1116 | | } |
1117 | | |
1118 | | impl<'a> FontRead<'a> for VarColorLine { |
1119 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
1120 | 0 | <read_fonts::tables::colr::VarColorLine as FontRead>::read(data).map(|x| x.to_owned_table()) |
1121 | 0 | } |
1122 | | } |
1123 | | |
1124 | | impl FontWrite for Extend { |
1125 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
1126 | 0 | let val = *self as u8; |
1127 | 0 | writer.write_slice(&val.to_be_bytes()) |
1128 | 0 | } |
1129 | | } |
1130 | | |
1131 | | /// [Paint](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#paint-tables) tables |
1132 | | #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] |
1133 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
1134 | | pub enum Paint { |
1135 | | ColrLayers(PaintColrLayers), |
1136 | | Solid(PaintSolid), |
1137 | | VarSolid(PaintVarSolid), |
1138 | | LinearGradient(PaintLinearGradient), |
1139 | | VarLinearGradient(PaintVarLinearGradient), |
1140 | | RadialGradient(PaintRadialGradient), |
1141 | | VarRadialGradient(PaintVarRadialGradient), |
1142 | | SweepGradient(PaintSweepGradient), |
1143 | | VarSweepGradient(PaintVarSweepGradient), |
1144 | | Glyph(PaintGlyph), |
1145 | | ColrGlyph(PaintColrGlyph), |
1146 | | Transform(PaintTransform), |
1147 | | VarTransform(PaintVarTransform), |
1148 | | Translate(PaintTranslate), |
1149 | | VarTranslate(PaintVarTranslate), |
1150 | | Scale(PaintScale), |
1151 | | VarScale(PaintVarScale), |
1152 | | ScaleAroundCenter(PaintScaleAroundCenter), |
1153 | | VarScaleAroundCenter(PaintVarScaleAroundCenter), |
1154 | | ScaleUniform(PaintScaleUniform), |
1155 | | VarScaleUniform(PaintVarScaleUniform), |
1156 | | ScaleUniformAroundCenter(PaintScaleUniformAroundCenter), |
1157 | | VarScaleUniformAroundCenter(PaintVarScaleUniformAroundCenter), |
1158 | | Rotate(PaintRotate), |
1159 | | VarRotate(PaintVarRotate), |
1160 | | RotateAroundCenter(PaintRotateAroundCenter), |
1161 | | VarRotateAroundCenter(PaintVarRotateAroundCenter), |
1162 | | Skew(PaintSkew), |
1163 | | VarSkew(PaintVarSkew), |
1164 | | SkewAroundCenter(PaintSkewAroundCenter), |
1165 | | VarSkewAroundCenter(PaintVarSkewAroundCenter), |
1166 | | Composite(PaintComposite), |
1167 | | } |
1168 | | |
1169 | | impl Paint { |
1170 | | /// Construct a new `PaintColrLayers` subtable |
1171 | 0 | pub fn colr_layers(num_layers: u8, first_layer_index: u32) -> Self { |
1172 | 0 | Self::ColrLayers(PaintColrLayers::new(num_layers, first_layer_index)) |
1173 | 0 | } |
1174 | | |
1175 | | /// Construct a new `PaintSolid` subtable |
1176 | 0 | pub fn solid(palette_index: u16, alpha: F2Dot14) -> Self { |
1177 | 0 | Self::Solid(PaintSolid::new(palette_index, alpha)) |
1178 | 0 | } |
1179 | | |
1180 | | /// Construct a new `PaintVarSolid` subtable |
1181 | 0 | pub fn var_solid(palette_index: u16, alpha: F2Dot14, var_index_base: u32) -> Self { |
1182 | 0 | Self::VarSolid(PaintVarSolid::new(palette_index, alpha, var_index_base)) |
1183 | 0 | } |
1184 | | |
1185 | | /// Construct a new `PaintLinearGradient` subtable |
1186 | 0 | pub fn linear_gradient( |
1187 | 0 | color_line: ColorLine, |
1188 | 0 | x0: FWord, |
1189 | 0 | y0: FWord, |
1190 | 0 | x1: FWord, |
1191 | 0 | y1: FWord, |
1192 | 0 | x2: FWord, |
1193 | 0 | y2: FWord, |
1194 | 0 | ) -> Self { |
1195 | 0 | Self::LinearGradient(PaintLinearGradient::new(color_line, x0, y0, x1, y1, x2, y2)) |
1196 | 0 | } |
1197 | | |
1198 | | /// Construct a new `PaintVarLinearGradient` subtable |
1199 | | #[allow(clippy::too_many_arguments)] |
1200 | 0 | pub fn var_linear_gradient( |
1201 | 0 | color_line: VarColorLine, |
1202 | 0 | x0: FWord, |
1203 | 0 | y0: FWord, |
1204 | 0 | x1: FWord, |
1205 | 0 | y1: FWord, |
1206 | 0 | x2: FWord, |
1207 | 0 | y2: FWord, |
1208 | 0 | var_index_base: u32, |
1209 | 0 | ) -> Self { |
1210 | 0 | Self::VarLinearGradient(PaintVarLinearGradient::new( |
1211 | 0 | color_line, |
1212 | 0 | x0, |
1213 | 0 | y0, |
1214 | 0 | x1, |
1215 | 0 | y1, |
1216 | 0 | x2, |
1217 | 0 | y2, |
1218 | 0 | var_index_base, |
1219 | 0 | )) |
1220 | 0 | } |
1221 | | |
1222 | | /// Construct a new `PaintRadialGradient` subtable |
1223 | 0 | pub fn radial_gradient( |
1224 | 0 | color_line: ColorLine, |
1225 | 0 | x0: FWord, |
1226 | 0 | y0: FWord, |
1227 | 0 | radius0: UfWord, |
1228 | 0 | x1: FWord, |
1229 | 0 | y1: FWord, |
1230 | 0 | radius1: UfWord, |
1231 | 0 | ) -> Self { |
1232 | 0 | Self::RadialGradient(PaintRadialGradient::new( |
1233 | 0 | color_line, x0, y0, radius0, x1, y1, radius1, |
1234 | 0 | )) |
1235 | 0 | } |
1236 | | |
1237 | | /// Construct a new `PaintVarRadialGradient` subtable |
1238 | | #[allow(clippy::too_many_arguments)] |
1239 | 0 | pub fn var_radial_gradient( |
1240 | 0 | color_line: VarColorLine, |
1241 | 0 | x0: FWord, |
1242 | 0 | y0: FWord, |
1243 | 0 | radius0: UfWord, |
1244 | 0 | x1: FWord, |
1245 | 0 | y1: FWord, |
1246 | 0 | radius1: UfWord, |
1247 | 0 | var_index_base: u32, |
1248 | 0 | ) -> Self { |
1249 | 0 | Self::VarRadialGradient(PaintVarRadialGradient::new( |
1250 | 0 | color_line, |
1251 | 0 | x0, |
1252 | 0 | y0, |
1253 | 0 | radius0, |
1254 | 0 | x1, |
1255 | 0 | y1, |
1256 | 0 | radius1, |
1257 | 0 | var_index_base, |
1258 | 0 | )) |
1259 | 0 | } |
1260 | | |
1261 | | /// Construct a new `PaintSweepGradient` subtable |
1262 | 0 | pub fn sweep_gradient( |
1263 | 0 | color_line: ColorLine, |
1264 | 0 | center_x: FWord, |
1265 | 0 | center_y: FWord, |
1266 | 0 | start_angle: F2Dot14, |
1267 | 0 | end_angle: F2Dot14, |
1268 | 0 | ) -> Self { |
1269 | 0 | Self::SweepGradient(PaintSweepGradient::new( |
1270 | 0 | color_line, |
1271 | 0 | center_x, |
1272 | 0 | center_y, |
1273 | 0 | start_angle, |
1274 | 0 | end_angle, |
1275 | 0 | )) |
1276 | 0 | } |
1277 | | |
1278 | | /// Construct a new `PaintVarSweepGradient` subtable |
1279 | 0 | pub fn var_sweep_gradient( |
1280 | 0 | color_line: VarColorLine, |
1281 | 0 | center_x: FWord, |
1282 | 0 | center_y: FWord, |
1283 | 0 | start_angle: F2Dot14, |
1284 | 0 | end_angle: F2Dot14, |
1285 | 0 | var_index_base: u32, |
1286 | 0 | ) -> Self { |
1287 | 0 | Self::VarSweepGradient(PaintVarSweepGradient::new( |
1288 | 0 | color_line, |
1289 | 0 | center_x, |
1290 | 0 | center_y, |
1291 | 0 | start_angle, |
1292 | 0 | end_angle, |
1293 | 0 | var_index_base, |
1294 | 0 | )) |
1295 | 0 | } |
1296 | | |
1297 | | /// Construct a new `PaintGlyph` subtable |
1298 | 0 | pub fn glyph(paint: Paint, glyph_id: GlyphId16) -> Self { |
1299 | 0 | Self::Glyph(PaintGlyph::new(paint, glyph_id)) |
1300 | 0 | } |
1301 | | |
1302 | | /// Construct a new `PaintColrGlyph` subtable |
1303 | 0 | pub fn colr_glyph(glyph_id: GlyphId16) -> Self { |
1304 | 0 | Self::ColrGlyph(PaintColrGlyph::new(glyph_id)) |
1305 | 0 | } |
1306 | | |
1307 | | /// Construct a new `PaintTransform` subtable |
1308 | 0 | pub fn transform(paint: Paint, transform: Affine2x3) -> Self { |
1309 | 0 | Self::Transform(PaintTransform::new(paint, transform)) |
1310 | 0 | } |
1311 | | |
1312 | | /// Construct a new `PaintVarTransform` subtable |
1313 | 0 | pub fn var_transform(paint: Paint, transform: VarAffine2x3) -> Self { |
1314 | 0 | Self::VarTransform(PaintVarTransform::new(paint, transform)) |
1315 | 0 | } |
1316 | | |
1317 | | /// Construct a new `PaintTranslate` subtable |
1318 | 0 | pub fn translate(paint: Paint, dx: FWord, dy: FWord) -> Self { |
1319 | 0 | Self::Translate(PaintTranslate::new(paint, dx, dy)) |
1320 | 0 | } |
1321 | | |
1322 | | /// Construct a new `PaintVarTranslate` subtable |
1323 | 0 | pub fn var_translate(paint: Paint, dx: FWord, dy: FWord, var_index_base: u32) -> Self { |
1324 | 0 | Self::VarTranslate(PaintVarTranslate::new(paint, dx, dy, var_index_base)) |
1325 | 0 | } |
1326 | | |
1327 | | /// Construct a new `PaintScale` subtable |
1328 | 0 | pub fn scale(paint: Paint, scale_x: F2Dot14, scale_y: F2Dot14) -> Self { |
1329 | 0 | Self::Scale(PaintScale::new(paint, scale_x, scale_y)) |
1330 | 0 | } |
1331 | | |
1332 | | /// Construct a new `PaintVarScale` subtable |
1333 | 0 | pub fn var_scale( |
1334 | 0 | paint: Paint, |
1335 | 0 | scale_x: F2Dot14, |
1336 | 0 | scale_y: F2Dot14, |
1337 | 0 | var_index_base: u32, |
1338 | 0 | ) -> Self { |
1339 | 0 | Self::VarScale(PaintVarScale::new(paint, scale_x, scale_y, var_index_base)) |
1340 | 0 | } |
1341 | | |
1342 | | /// Construct a new `PaintScaleAroundCenter` subtable |
1343 | 0 | pub fn scale_around_center( |
1344 | 0 | paint: Paint, |
1345 | 0 | scale_x: F2Dot14, |
1346 | 0 | scale_y: F2Dot14, |
1347 | 0 | center_x: FWord, |
1348 | 0 | center_y: FWord, |
1349 | 0 | ) -> Self { |
1350 | 0 | Self::ScaleAroundCenter(PaintScaleAroundCenter::new( |
1351 | 0 | paint, scale_x, scale_y, center_x, center_y, |
1352 | 0 | )) |
1353 | 0 | } |
1354 | | |
1355 | | /// Construct a new `PaintVarScaleAroundCenter` subtable |
1356 | 0 | pub fn var_scale_around_center( |
1357 | 0 | paint: Paint, |
1358 | 0 | scale_x: F2Dot14, |
1359 | 0 | scale_y: F2Dot14, |
1360 | 0 | center_x: FWord, |
1361 | 0 | center_y: FWord, |
1362 | 0 | var_index_base: u32, |
1363 | 0 | ) -> Self { |
1364 | 0 | Self::VarScaleAroundCenter(PaintVarScaleAroundCenter::new( |
1365 | 0 | paint, |
1366 | 0 | scale_x, |
1367 | 0 | scale_y, |
1368 | 0 | center_x, |
1369 | 0 | center_y, |
1370 | 0 | var_index_base, |
1371 | 0 | )) |
1372 | 0 | } |
1373 | | |
1374 | | /// Construct a new `PaintScaleUniform` subtable |
1375 | 0 | pub fn scale_uniform(paint: Paint, scale: F2Dot14) -> Self { |
1376 | 0 | Self::ScaleUniform(PaintScaleUniform::new(paint, scale)) |
1377 | 0 | } |
1378 | | |
1379 | | /// Construct a new `PaintVarScaleUniform` subtable |
1380 | 0 | pub fn var_scale_uniform(paint: Paint, scale: F2Dot14, var_index_base: u32) -> Self { |
1381 | 0 | Self::VarScaleUniform(PaintVarScaleUniform::new(paint, scale, var_index_base)) |
1382 | 0 | } |
1383 | | |
1384 | | /// Construct a new `PaintScaleUniformAroundCenter` subtable |
1385 | 0 | pub fn scale_uniform_around_center( |
1386 | 0 | paint: Paint, |
1387 | 0 | scale: F2Dot14, |
1388 | 0 | center_x: FWord, |
1389 | 0 | center_y: FWord, |
1390 | 0 | ) -> Self { |
1391 | 0 | Self::ScaleUniformAroundCenter(PaintScaleUniformAroundCenter::new( |
1392 | 0 | paint, scale, center_x, center_y, |
1393 | 0 | )) |
1394 | 0 | } |
1395 | | |
1396 | | /// Construct a new `PaintVarScaleUniformAroundCenter` subtable |
1397 | 0 | pub fn var_scale_uniform_around_center( |
1398 | 0 | paint: Paint, |
1399 | 0 | scale: F2Dot14, |
1400 | 0 | center_x: FWord, |
1401 | 0 | center_y: FWord, |
1402 | 0 | var_index_base: u32, |
1403 | 0 | ) -> Self { |
1404 | 0 | Self::VarScaleUniformAroundCenter(PaintVarScaleUniformAroundCenter::new( |
1405 | 0 | paint, |
1406 | 0 | scale, |
1407 | 0 | center_x, |
1408 | 0 | center_y, |
1409 | 0 | var_index_base, |
1410 | 0 | )) |
1411 | 0 | } |
1412 | | |
1413 | | /// Construct a new `PaintRotate` subtable |
1414 | 0 | pub fn rotate(paint: Paint, angle: F2Dot14) -> Self { |
1415 | 0 | Self::Rotate(PaintRotate::new(paint, angle)) |
1416 | 0 | } |
1417 | | |
1418 | | /// Construct a new `PaintVarRotate` subtable |
1419 | 0 | pub fn var_rotate(paint: Paint, angle: F2Dot14, var_index_base: u32) -> Self { |
1420 | 0 | Self::VarRotate(PaintVarRotate::new(paint, angle, var_index_base)) |
1421 | 0 | } |
1422 | | |
1423 | | /// Construct a new `PaintRotateAroundCenter` subtable |
1424 | 0 | pub fn rotate_around_center( |
1425 | 0 | paint: Paint, |
1426 | 0 | angle: F2Dot14, |
1427 | 0 | center_x: FWord, |
1428 | 0 | center_y: FWord, |
1429 | 0 | ) -> Self { |
1430 | 0 | Self::RotateAroundCenter(PaintRotateAroundCenter::new( |
1431 | 0 | paint, angle, center_x, center_y, |
1432 | 0 | )) |
1433 | 0 | } |
1434 | | |
1435 | | /// Construct a new `PaintVarRotateAroundCenter` subtable |
1436 | 0 | pub fn var_rotate_around_center( |
1437 | 0 | paint: Paint, |
1438 | 0 | angle: F2Dot14, |
1439 | 0 | center_x: FWord, |
1440 | 0 | center_y: FWord, |
1441 | 0 | var_index_base: u32, |
1442 | 0 | ) -> Self { |
1443 | 0 | Self::VarRotateAroundCenter(PaintVarRotateAroundCenter::new( |
1444 | 0 | paint, |
1445 | 0 | angle, |
1446 | 0 | center_x, |
1447 | 0 | center_y, |
1448 | 0 | var_index_base, |
1449 | 0 | )) |
1450 | 0 | } |
1451 | | |
1452 | | /// Construct a new `PaintSkew` subtable |
1453 | 0 | pub fn skew(paint: Paint, x_skew_angle: F2Dot14, y_skew_angle: F2Dot14) -> Self { |
1454 | 0 | Self::Skew(PaintSkew::new(paint, x_skew_angle, y_skew_angle)) |
1455 | 0 | } |
1456 | | |
1457 | | /// Construct a new `PaintVarSkew` subtable |
1458 | 0 | pub fn var_skew( |
1459 | 0 | paint: Paint, |
1460 | 0 | x_skew_angle: F2Dot14, |
1461 | 0 | y_skew_angle: F2Dot14, |
1462 | 0 | var_index_base: u32, |
1463 | 0 | ) -> Self { |
1464 | 0 | Self::VarSkew(PaintVarSkew::new( |
1465 | 0 | paint, |
1466 | 0 | x_skew_angle, |
1467 | 0 | y_skew_angle, |
1468 | 0 | var_index_base, |
1469 | 0 | )) |
1470 | 0 | } |
1471 | | |
1472 | | /// Construct a new `PaintSkewAroundCenter` subtable |
1473 | 0 | pub fn skew_around_center( |
1474 | 0 | paint: Paint, |
1475 | 0 | x_skew_angle: F2Dot14, |
1476 | 0 | y_skew_angle: F2Dot14, |
1477 | 0 | center_x: FWord, |
1478 | 0 | center_y: FWord, |
1479 | 0 | ) -> Self { |
1480 | 0 | Self::SkewAroundCenter(PaintSkewAroundCenter::new( |
1481 | 0 | paint, |
1482 | 0 | x_skew_angle, |
1483 | 0 | y_skew_angle, |
1484 | 0 | center_x, |
1485 | 0 | center_y, |
1486 | 0 | )) |
1487 | 0 | } |
1488 | | |
1489 | | /// Construct a new `PaintVarSkewAroundCenter` subtable |
1490 | 0 | pub fn var_skew_around_center( |
1491 | 0 | paint: Paint, |
1492 | 0 | x_skew_angle: F2Dot14, |
1493 | 0 | y_skew_angle: F2Dot14, |
1494 | 0 | center_x: FWord, |
1495 | 0 | center_y: FWord, |
1496 | 0 | var_index_base: u32, |
1497 | 0 | ) -> Self { |
1498 | 0 | Self::VarSkewAroundCenter(PaintVarSkewAroundCenter::new( |
1499 | 0 | paint, |
1500 | 0 | x_skew_angle, |
1501 | 0 | y_skew_angle, |
1502 | 0 | center_x, |
1503 | 0 | center_y, |
1504 | 0 | var_index_base, |
1505 | 0 | )) |
1506 | 0 | } |
1507 | | |
1508 | | /// Construct a new `PaintComposite` subtable |
1509 | 0 | pub fn composite( |
1510 | 0 | source_paint: Paint, |
1511 | 0 | composite_mode: CompositeMode, |
1512 | 0 | backdrop_paint: Paint, |
1513 | 0 | ) -> Self { |
1514 | 0 | Self::Composite(PaintComposite::new( |
1515 | 0 | source_paint, |
1516 | 0 | composite_mode, |
1517 | 0 | backdrop_paint, |
1518 | 0 | )) |
1519 | 0 | } |
1520 | | } |
1521 | | |
1522 | | impl Default for Paint { |
1523 | 0 | fn default() -> Self { |
1524 | 0 | Self::ColrLayers(Default::default()) |
1525 | 0 | } |
1526 | | } |
1527 | | |
1528 | | impl FontWrite for Paint { |
1529 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
1530 | 0 | match self { |
1531 | 0 | Self::ColrLayers(item) => item.write_into(writer), |
1532 | 0 | Self::Solid(item) => item.write_into(writer), |
1533 | 0 | Self::VarSolid(item) => item.write_into(writer), |
1534 | 0 | Self::LinearGradient(item) => item.write_into(writer), |
1535 | 0 | Self::VarLinearGradient(item) => item.write_into(writer), |
1536 | 0 | Self::RadialGradient(item) => item.write_into(writer), |
1537 | 0 | Self::VarRadialGradient(item) => item.write_into(writer), |
1538 | 0 | Self::SweepGradient(item) => item.write_into(writer), |
1539 | 0 | Self::VarSweepGradient(item) => item.write_into(writer), |
1540 | 0 | Self::Glyph(item) => item.write_into(writer), |
1541 | 0 | Self::ColrGlyph(item) => item.write_into(writer), |
1542 | 0 | Self::Transform(item) => item.write_into(writer), |
1543 | 0 | Self::VarTransform(item) => item.write_into(writer), |
1544 | 0 | Self::Translate(item) => item.write_into(writer), |
1545 | 0 | Self::VarTranslate(item) => item.write_into(writer), |
1546 | 0 | Self::Scale(item) => item.write_into(writer), |
1547 | 0 | Self::VarScale(item) => item.write_into(writer), |
1548 | 0 | Self::ScaleAroundCenter(item) => item.write_into(writer), |
1549 | 0 | Self::VarScaleAroundCenter(item) => item.write_into(writer), |
1550 | 0 | Self::ScaleUniform(item) => item.write_into(writer), |
1551 | 0 | Self::VarScaleUniform(item) => item.write_into(writer), |
1552 | 0 | Self::ScaleUniformAroundCenter(item) => item.write_into(writer), |
1553 | 0 | Self::VarScaleUniformAroundCenter(item) => item.write_into(writer), |
1554 | 0 | Self::Rotate(item) => item.write_into(writer), |
1555 | 0 | Self::VarRotate(item) => item.write_into(writer), |
1556 | 0 | Self::RotateAroundCenter(item) => item.write_into(writer), |
1557 | 0 | Self::VarRotateAroundCenter(item) => item.write_into(writer), |
1558 | 0 | Self::Skew(item) => item.write_into(writer), |
1559 | 0 | Self::VarSkew(item) => item.write_into(writer), |
1560 | 0 | Self::SkewAroundCenter(item) => item.write_into(writer), |
1561 | 0 | Self::VarSkewAroundCenter(item) => item.write_into(writer), |
1562 | 0 | Self::Composite(item) => item.write_into(writer), |
1563 | | } |
1564 | 0 | } |
1565 | 0 | fn table_type(&self) -> TableType { |
1566 | 0 | match self { |
1567 | 0 | Self::ColrLayers(item) => item.table_type(), |
1568 | 0 | Self::Solid(item) => item.table_type(), |
1569 | 0 | Self::VarSolid(item) => item.table_type(), |
1570 | 0 | Self::LinearGradient(item) => item.table_type(), |
1571 | 0 | Self::VarLinearGradient(item) => item.table_type(), |
1572 | 0 | Self::RadialGradient(item) => item.table_type(), |
1573 | 0 | Self::VarRadialGradient(item) => item.table_type(), |
1574 | 0 | Self::SweepGradient(item) => item.table_type(), |
1575 | 0 | Self::VarSweepGradient(item) => item.table_type(), |
1576 | 0 | Self::Glyph(item) => item.table_type(), |
1577 | 0 | Self::ColrGlyph(item) => item.table_type(), |
1578 | 0 | Self::Transform(item) => item.table_type(), |
1579 | 0 | Self::VarTransform(item) => item.table_type(), |
1580 | 0 | Self::Translate(item) => item.table_type(), |
1581 | 0 | Self::VarTranslate(item) => item.table_type(), |
1582 | 0 | Self::Scale(item) => item.table_type(), |
1583 | 0 | Self::VarScale(item) => item.table_type(), |
1584 | 0 | Self::ScaleAroundCenter(item) => item.table_type(), |
1585 | 0 | Self::VarScaleAroundCenter(item) => item.table_type(), |
1586 | 0 | Self::ScaleUniform(item) => item.table_type(), |
1587 | 0 | Self::VarScaleUniform(item) => item.table_type(), |
1588 | 0 | Self::ScaleUniformAroundCenter(item) => item.table_type(), |
1589 | 0 | Self::VarScaleUniformAroundCenter(item) => item.table_type(), |
1590 | 0 | Self::Rotate(item) => item.table_type(), |
1591 | 0 | Self::VarRotate(item) => item.table_type(), |
1592 | 0 | Self::RotateAroundCenter(item) => item.table_type(), |
1593 | 0 | Self::VarRotateAroundCenter(item) => item.table_type(), |
1594 | 0 | Self::Skew(item) => item.table_type(), |
1595 | 0 | Self::VarSkew(item) => item.table_type(), |
1596 | 0 | Self::SkewAroundCenter(item) => item.table_type(), |
1597 | 0 | Self::VarSkewAroundCenter(item) => item.table_type(), |
1598 | 0 | Self::Composite(item) => item.table_type(), |
1599 | | } |
1600 | 0 | } |
1601 | | } |
1602 | | |
1603 | | impl Validate for Paint { |
1604 | 0 | fn validate_impl(&self, ctx: &mut ValidationCtx) { |
1605 | 0 | match self { |
1606 | 0 | Self::ColrLayers(item) => item.validate_impl(ctx), |
1607 | 0 | Self::Solid(item) => item.validate_impl(ctx), |
1608 | 0 | Self::VarSolid(item) => item.validate_impl(ctx), |
1609 | 0 | Self::LinearGradient(item) => item.validate_impl(ctx), |
1610 | 0 | Self::VarLinearGradient(item) => item.validate_impl(ctx), |
1611 | 0 | Self::RadialGradient(item) => item.validate_impl(ctx), |
1612 | 0 | Self::VarRadialGradient(item) => item.validate_impl(ctx), |
1613 | 0 | Self::SweepGradient(item) => item.validate_impl(ctx), |
1614 | 0 | Self::VarSweepGradient(item) => item.validate_impl(ctx), |
1615 | 0 | Self::Glyph(item) => item.validate_impl(ctx), |
1616 | 0 | Self::ColrGlyph(item) => item.validate_impl(ctx), |
1617 | 0 | Self::Transform(item) => item.validate_impl(ctx), |
1618 | 0 | Self::VarTransform(item) => item.validate_impl(ctx), |
1619 | 0 | Self::Translate(item) => item.validate_impl(ctx), |
1620 | 0 | Self::VarTranslate(item) => item.validate_impl(ctx), |
1621 | 0 | Self::Scale(item) => item.validate_impl(ctx), |
1622 | 0 | Self::VarScale(item) => item.validate_impl(ctx), |
1623 | 0 | Self::ScaleAroundCenter(item) => item.validate_impl(ctx), |
1624 | 0 | Self::VarScaleAroundCenter(item) => item.validate_impl(ctx), |
1625 | 0 | Self::ScaleUniform(item) => item.validate_impl(ctx), |
1626 | 0 | Self::VarScaleUniform(item) => item.validate_impl(ctx), |
1627 | 0 | Self::ScaleUniformAroundCenter(item) => item.validate_impl(ctx), |
1628 | 0 | Self::VarScaleUniformAroundCenter(item) => item.validate_impl(ctx), |
1629 | 0 | Self::Rotate(item) => item.validate_impl(ctx), |
1630 | 0 | Self::VarRotate(item) => item.validate_impl(ctx), |
1631 | 0 | Self::RotateAroundCenter(item) => item.validate_impl(ctx), |
1632 | 0 | Self::VarRotateAroundCenter(item) => item.validate_impl(ctx), |
1633 | 0 | Self::Skew(item) => item.validate_impl(ctx), |
1634 | 0 | Self::VarSkew(item) => item.validate_impl(ctx), |
1635 | 0 | Self::SkewAroundCenter(item) => item.validate_impl(ctx), |
1636 | 0 | Self::VarSkewAroundCenter(item) => item.validate_impl(ctx), |
1637 | 0 | Self::Composite(item) => item.validate_impl(ctx), |
1638 | | } |
1639 | 0 | } |
1640 | | } |
1641 | | |
1642 | | impl FromObjRef<read_fonts::tables::colr::Paint<'_>> for Paint { |
1643 | 0 | fn from_obj_ref(obj: &read_fonts::tables::colr::Paint, _: FontData) -> Self { |
1644 | | use read_fonts::tables::colr::Paint as ObjRefType; |
1645 | 0 | match obj { |
1646 | 0 | ObjRefType::ColrLayers(item) => Paint::ColrLayers(item.to_owned_table()), |
1647 | 0 | ObjRefType::Solid(item) => Paint::Solid(item.to_owned_table()), |
1648 | 0 | ObjRefType::VarSolid(item) => Paint::VarSolid(item.to_owned_table()), |
1649 | 0 | ObjRefType::LinearGradient(item) => Paint::LinearGradient(item.to_owned_table()), |
1650 | 0 | ObjRefType::VarLinearGradient(item) => Paint::VarLinearGradient(item.to_owned_table()), |
1651 | 0 | ObjRefType::RadialGradient(item) => Paint::RadialGradient(item.to_owned_table()), |
1652 | 0 | ObjRefType::VarRadialGradient(item) => Paint::VarRadialGradient(item.to_owned_table()), |
1653 | 0 | ObjRefType::SweepGradient(item) => Paint::SweepGradient(item.to_owned_table()), |
1654 | 0 | ObjRefType::VarSweepGradient(item) => Paint::VarSweepGradient(item.to_owned_table()), |
1655 | 0 | ObjRefType::Glyph(item) => Paint::Glyph(item.to_owned_table()), |
1656 | 0 | ObjRefType::ColrGlyph(item) => Paint::ColrGlyph(item.to_owned_table()), |
1657 | 0 | ObjRefType::Transform(item) => Paint::Transform(item.to_owned_table()), |
1658 | 0 | ObjRefType::VarTransform(item) => Paint::VarTransform(item.to_owned_table()), |
1659 | 0 | ObjRefType::Translate(item) => Paint::Translate(item.to_owned_table()), |
1660 | 0 | ObjRefType::VarTranslate(item) => Paint::VarTranslate(item.to_owned_table()), |
1661 | 0 | ObjRefType::Scale(item) => Paint::Scale(item.to_owned_table()), |
1662 | 0 | ObjRefType::VarScale(item) => Paint::VarScale(item.to_owned_table()), |
1663 | 0 | ObjRefType::ScaleAroundCenter(item) => Paint::ScaleAroundCenter(item.to_owned_table()), |
1664 | 0 | ObjRefType::VarScaleAroundCenter(item) => { |
1665 | 0 | Paint::VarScaleAroundCenter(item.to_owned_table()) |
1666 | | } |
1667 | 0 | ObjRefType::ScaleUniform(item) => Paint::ScaleUniform(item.to_owned_table()), |
1668 | 0 | ObjRefType::VarScaleUniform(item) => Paint::VarScaleUniform(item.to_owned_table()), |
1669 | 0 | ObjRefType::ScaleUniformAroundCenter(item) => { |
1670 | 0 | Paint::ScaleUniformAroundCenter(item.to_owned_table()) |
1671 | | } |
1672 | 0 | ObjRefType::VarScaleUniformAroundCenter(item) => { |
1673 | 0 | Paint::VarScaleUniformAroundCenter(item.to_owned_table()) |
1674 | | } |
1675 | 0 | ObjRefType::Rotate(item) => Paint::Rotate(item.to_owned_table()), |
1676 | 0 | ObjRefType::VarRotate(item) => Paint::VarRotate(item.to_owned_table()), |
1677 | 0 | ObjRefType::RotateAroundCenter(item) => { |
1678 | 0 | Paint::RotateAroundCenter(item.to_owned_table()) |
1679 | | } |
1680 | 0 | ObjRefType::VarRotateAroundCenter(item) => { |
1681 | 0 | Paint::VarRotateAroundCenter(item.to_owned_table()) |
1682 | | } |
1683 | 0 | ObjRefType::Skew(item) => Paint::Skew(item.to_owned_table()), |
1684 | 0 | ObjRefType::VarSkew(item) => Paint::VarSkew(item.to_owned_table()), |
1685 | 0 | ObjRefType::SkewAroundCenter(item) => Paint::SkewAroundCenter(item.to_owned_table()), |
1686 | 0 | ObjRefType::VarSkewAroundCenter(item) => { |
1687 | 0 | Paint::VarSkewAroundCenter(item.to_owned_table()) |
1688 | | } |
1689 | 0 | ObjRefType::Composite(item) => Paint::Composite(item.to_owned_table()), |
1690 | | } |
1691 | 0 | } |
1692 | | } |
1693 | | |
1694 | | impl FromTableRef<read_fonts::tables::colr::Paint<'_>> for Paint {} |
1695 | | |
1696 | | impl ReadArgs for Paint { |
1697 | | type Args = (); |
1698 | | } |
1699 | | |
1700 | | impl<'a> FontRead<'a> for Paint { |
1701 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
1702 | 0 | <read_fonts::tables::colr::Paint as FontRead>::read(data).map(|x| x.to_owned_table()) |
1703 | 0 | } |
1704 | | } |
1705 | | |
1706 | | impl From<PaintColrLayers> for Paint { |
1707 | 0 | fn from(src: PaintColrLayers) -> Paint { |
1708 | 0 | Paint::ColrLayers(src) |
1709 | 0 | } |
1710 | | } |
1711 | | |
1712 | | impl From<PaintSolid> for Paint { |
1713 | 0 | fn from(src: PaintSolid) -> Paint { |
1714 | 0 | Paint::Solid(src) |
1715 | 0 | } |
1716 | | } |
1717 | | |
1718 | | impl From<PaintVarSolid> for Paint { |
1719 | 0 | fn from(src: PaintVarSolid) -> Paint { |
1720 | 0 | Paint::VarSolid(src) |
1721 | 0 | } |
1722 | | } |
1723 | | |
1724 | | impl From<PaintLinearGradient> for Paint { |
1725 | 0 | fn from(src: PaintLinearGradient) -> Paint { |
1726 | 0 | Paint::LinearGradient(src) |
1727 | 0 | } |
1728 | | } |
1729 | | |
1730 | | impl From<PaintVarLinearGradient> for Paint { |
1731 | 0 | fn from(src: PaintVarLinearGradient) -> Paint { |
1732 | 0 | Paint::VarLinearGradient(src) |
1733 | 0 | } |
1734 | | } |
1735 | | |
1736 | | impl From<PaintRadialGradient> for Paint { |
1737 | 0 | fn from(src: PaintRadialGradient) -> Paint { |
1738 | 0 | Paint::RadialGradient(src) |
1739 | 0 | } |
1740 | | } |
1741 | | |
1742 | | impl From<PaintVarRadialGradient> for Paint { |
1743 | 0 | fn from(src: PaintVarRadialGradient) -> Paint { |
1744 | 0 | Paint::VarRadialGradient(src) |
1745 | 0 | } |
1746 | | } |
1747 | | |
1748 | | impl From<PaintSweepGradient> for Paint { |
1749 | 0 | fn from(src: PaintSweepGradient) -> Paint { |
1750 | 0 | Paint::SweepGradient(src) |
1751 | 0 | } |
1752 | | } |
1753 | | |
1754 | | impl From<PaintVarSweepGradient> for Paint { |
1755 | 0 | fn from(src: PaintVarSweepGradient) -> Paint { |
1756 | 0 | Paint::VarSweepGradient(src) |
1757 | 0 | } |
1758 | | } |
1759 | | |
1760 | | impl From<PaintGlyph> for Paint { |
1761 | 0 | fn from(src: PaintGlyph) -> Paint { |
1762 | 0 | Paint::Glyph(src) |
1763 | 0 | } |
1764 | | } |
1765 | | |
1766 | | impl From<PaintColrGlyph> for Paint { |
1767 | 0 | fn from(src: PaintColrGlyph) -> Paint { |
1768 | 0 | Paint::ColrGlyph(src) |
1769 | 0 | } |
1770 | | } |
1771 | | |
1772 | | impl From<PaintTransform> for Paint { |
1773 | 0 | fn from(src: PaintTransform) -> Paint { |
1774 | 0 | Paint::Transform(src) |
1775 | 0 | } |
1776 | | } |
1777 | | |
1778 | | impl From<PaintVarTransform> for Paint { |
1779 | 0 | fn from(src: PaintVarTransform) -> Paint { |
1780 | 0 | Paint::VarTransform(src) |
1781 | 0 | } |
1782 | | } |
1783 | | |
1784 | | impl From<PaintTranslate> for Paint { |
1785 | 0 | fn from(src: PaintTranslate) -> Paint { |
1786 | 0 | Paint::Translate(src) |
1787 | 0 | } |
1788 | | } |
1789 | | |
1790 | | impl From<PaintVarTranslate> for Paint { |
1791 | 0 | fn from(src: PaintVarTranslate) -> Paint { |
1792 | 0 | Paint::VarTranslate(src) |
1793 | 0 | } |
1794 | | } |
1795 | | |
1796 | | impl From<PaintScale> for Paint { |
1797 | 0 | fn from(src: PaintScale) -> Paint { |
1798 | 0 | Paint::Scale(src) |
1799 | 0 | } |
1800 | | } |
1801 | | |
1802 | | impl From<PaintVarScale> for Paint { |
1803 | 0 | fn from(src: PaintVarScale) -> Paint { |
1804 | 0 | Paint::VarScale(src) |
1805 | 0 | } |
1806 | | } |
1807 | | |
1808 | | impl From<PaintScaleAroundCenter> for Paint { |
1809 | 0 | fn from(src: PaintScaleAroundCenter) -> Paint { |
1810 | 0 | Paint::ScaleAroundCenter(src) |
1811 | 0 | } |
1812 | | } |
1813 | | |
1814 | | impl From<PaintVarScaleAroundCenter> for Paint { |
1815 | 0 | fn from(src: PaintVarScaleAroundCenter) -> Paint { |
1816 | 0 | Paint::VarScaleAroundCenter(src) |
1817 | 0 | } |
1818 | | } |
1819 | | |
1820 | | impl From<PaintScaleUniform> for Paint { |
1821 | 0 | fn from(src: PaintScaleUniform) -> Paint { |
1822 | 0 | Paint::ScaleUniform(src) |
1823 | 0 | } |
1824 | | } |
1825 | | |
1826 | | impl From<PaintVarScaleUniform> for Paint { |
1827 | 0 | fn from(src: PaintVarScaleUniform) -> Paint { |
1828 | 0 | Paint::VarScaleUniform(src) |
1829 | 0 | } |
1830 | | } |
1831 | | |
1832 | | impl From<PaintScaleUniformAroundCenter> for Paint { |
1833 | 0 | fn from(src: PaintScaleUniformAroundCenter) -> Paint { |
1834 | 0 | Paint::ScaleUniformAroundCenter(src) |
1835 | 0 | } |
1836 | | } |
1837 | | |
1838 | | impl From<PaintVarScaleUniformAroundCenter> for Paint { |
1839 | 0 | fn from(src: PaintVarScaleUniformAroundCenter) -> Paint { |
1840 | 0 | Paint::VarScaleUniformAroundCenter(src) |
1841 | 0 | } |
1842 | | } |
1843 | | |
1844 | | impl From<PaintRotate> for Paint { |
1845 | 0 | fn from(src: PaintRotate) -> Paint { |
1846 | 0 | Paint::Rotate(src) |
1847 | 0 | } |
1848 | | } |
1849 | | |
1850 | | impl From<PaintVarRotate> for Paint { |
1851 | 0 | fn from(src: PaintVarRotate) -> Paint { |
1852 | 0 | Paint::VarRotate(src) |
1853 | 0 | } |
1854 | | } |
1855 | | |
1856 | | impl From<PaintRotateAroundCenter> for Paint { |
1857 | 0 | fn from(src: PaintRotateAroundCenter) -> Paint { |
1858 | 0 | Paint::RotateAroundCenter(src) |
1859 | 0 | } |
1860 | | } |
1861 | | |
1862 | | impl From<PaintVarRotateAroundCenter> for Paint { |
1863 | 0 | fn from(src: PaintVarRotateAroundCenter) -> Paint { |
1864 | 0 | Paint::VarRotateAroundCenter(src) |
1865 | 0 | } |
1866 | | } |
1867 | | |
1868 | | impl From<PaintSkew> for Paint { |
1869 | 0 | fn from(src: PaintSkew) -> Paint { |
1870 | 0 | Paint::Skew(src) |
1871 | 0 | } |
1872 | | } |
1873 | | |
1874 | | impl From<PaintVarSkew> for Paint { |
1875 | 0 | fn from(src: PaintVarSkew) -> Paint { |
1876 | 0 | Paint::VarSkew(src) |
1877 | 0 | } |
1878 | | } |
1879 | | |
1880 | | impl From<PaintSkewAroundCenter> for Paint { |
1881 | 0 | fn from(src: PaintSkewAroundCenter) -> Paint { |
1882 | 0 | Paint::SkewAroundCenter(src) |
1883 | 0 | } |
1884 | | } |
1885 | | |
1886 | | impl From<PaintVarSkewAroundCenter> for Paint { |
1887 | 0 | fn from(src: PaintVarSkewAroundCenter) -> Paint { |
1888 | 0 | Paint::VarSkewAroundCenter(src) |
1889 | 0 | } |
1890 | | } |
1891 | | |
1892 | | impl From<PaintComposite> for Paint { |
1893 | 0 | fn from(src: PaintComposite) -> Paint { |
1894 | 0 | Paint::Composite(src) |
1895 | 0 | } |
1896 | | } |
1897 | | |
1898 | | /// [PaintColrLayers](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#format-1-paintcolrlayers) table |
1899 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
1900 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
1901 | | pub struct PaintColrLayers { |
1902 | | /// Number of offsets to paint tables to read from LayerList. |
1903 | | pub num_layers: u8, |
1904 | | /// Index (base 0) into the LayerList. |
1905 | | pub first_layer_index: u32, |
1906 | | } |
1907 | | |
1908 | | impl PaintColrLayers { |
1909 | | /// Construct a new `PaintColrLayers` |
1910 | 0 | pub fn new(num_layers: u8, first_layer_index: u32) -> Self { |
1911 | 0 | Self { |
1912 | 0 | num_layers, |
1913 | 0 | first_layer_index, |
1914 | 0 | } |
1915 | 0 | } |
1916 | | } |
1917 | | |
1918 | | impl FontWrite for PaintColrLayers { |
1919 | | #[allow(clippy::unnecessary_cast)] |
1920 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
1921 | 0 | (1 as u8).write_into(writer); |
1922 | 0 | self.num_layers.write_into(writer); |
1923 | 0 | self.first_layer_index.write_into(writer); |
1924 | 0 | } |
1925 | 0 | fn table_type(&self) -> TableType { |
1926 | 0 | TableType::Named("PaintColrLayers") |
1927 | 0 | } |
1928 | | } |
1929 | | |
1930 | | impl Validate for PaintColrLayers { |
1931 | 0 | fn validate_impl(&self, _ctx: &mut ValidationCtx) {} |
1932 | | } |
1933 | | |
1934 | | impl<'a> FromObjRef<read_fonts::tables::colr::PaintColrLayers<'a>> for PaintColrLayers { |
1935 | 0 | fn from_obj_ref(obj: &read_fonts::tables::colr::PaintColrLayers<'a>, _: FontData) -> Self { |
1936 | 0 | PaintColrLayers { |
1937 | 0 | num_layers: obj.num_layers(), |
1938 | 0 | first_layer_index: obj.first_layer_index(), |
1939 | 0 | } |
1940 | 0 | } |
1941 | | } |
1942 | | |
1943 | | #[allow(clippy::needless_lifetimes)] |
1944 | | impl<'a> FromTableRef<read_fonts::tables::colr::PaintColrLayers<'a>> for PaintColrLayers {} |
1945 | | |
1946 | | impl ReadArgs for PaintColrLayers { |
1947 | | type Args = (); |
1948 | | } |
1949 | | |
1950 | | impl<'a> FontRead<'a> for PaintColrLayers { |
1951 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
1952 | 0 | <read_fonts::tables::colr::PaintColrLayers as FontRead>::read(data) |
1953 | 0 | .map(|x| x.to_owned_table()) |
1954 | 0 | } |
1955 | | } |
1956 | | |
1957 | | /// [PaintSolid](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-2-and-3-paintsolid-paintvarsolid) table |
1958 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
1959 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
1960 | | pub struct PaintSolid { |
1961 | | /// Index for a CPAL palette entry. |
1962 | | pub palette_index: u16, |
1963 | | /// Alpha value. |
1964 | | pub alpha: F2Dot14, |
1965 | | } |
1966 | | |
1967 | | impl PaintSolid { |
1968 | | /// Construct a new `PaintSolid` |
1969 | 0 | pub fn new(palette_index: u16, alpha: F2Dot14) -> Self { |
1970 | 0 | Self { |
1971 | 0 | palette_index, |
1972 | 0 | alpha, |
1973 | 0 | } |
1974 | 0 | } |
1975 | | } |
1976 | | |
1977 | | impl FontWrite for PaintSolid { |
1978 | | #[allow(clippy::unnecessary_cast)] |
1979 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
1980 | 0 | (2 as u8).write_into(writer); |
1981 | 0 | self.palette_index.write_into(writer); |
1982 | 0 | self.alpha.write_into(writer); |
1983 | 0 | } |
1984 | 0 | fn table_type(&self) -> TableType { |
1985 | 0 | TableType::Named("PaintSolid") |
1986 | 0 | } |
1987 | | } |
1988 | | |
1989 | | impl Validate for PaintSolid { |
1990 | 0 | fn validate_impl(&self, _ctx: &mut ValidationCtx) {} |
1991 | | } |
1992 | | |
1993 | | impl<'a> FromObjRef<read_fonts::tables::colr::PaintSolid<'a>> for PaintSolid { |
1994 | 0 | fn from_obj_ref(obj: &read_fonts::tables::colr::PaintSolid<'a>, _: FontData) -> Self { |
1995 | 0 | PaintSolid { |
1996 | 0 | palette_index: obj.palette_index(), |
1997 | 0 | alpha: obj.alpha(), |
1998 | 0 | } |
1999 | 0 | } |
2000 | | } |
2001 | | |
2002 | | #[allow(clippy::needless_lifetimes)] |
2003 | | impl<'a> FromTableRef<read_fonts::tables::colr::PaintSolid<'a>> for PaintSolid {} |
2004 | | |
2005 | | impl ReadArgs for PaintSolid { |
2006 | | type Args = (); |
2007 | | } |
2008 | | |
2009 | | impl<'a> FontRead<'a> for PaintSolid { |
2010 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
2011 | 0 | <read_fonts::tables::colr::PaintSolid as FontRead>::read(data).map(|x| x.to_owned_table()) |
2012 | 0 | } |
2013 | | } |
2014 | | |
2015 | | /// [PaintVarSolid](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-2-and-3-paintsolid-paintvarsolid) table |
2016 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
2017 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
2018 | | pub struct PaintVarSolid { |
2019 | | /// Index for a CPAL palette entry. |
2020 | | pub palette_index: u16, |
2021 | | /// Alpha value. For variation, use varIndexBase + 0. |
2022 | | pub alpha: F2Dot14, |
2023 | | /// Base index into DeltaSetIndexMap. |
2024 | | pub var_index_base: u32, |
2025 | | } |
2026 | | |
2027 | | impl PaintVarSolid { |
2028 | | /// Construct a new `PaintVarSolid` |
2029 | 0 | pub fn new(palette_index: u16, alpha: F2Dot14, var_index_base: u32) -> Self { |
2030 | 0 | Self { |
2031 | 0 | palette_index, |
2032 | 0 | alpha, |
2033 | 0 | var_index_base, |
2034 | 0 | } |
2035 | 0 | } |
2036 | | } |
2037 | | |
2038 | | impl FontWrite for PaintVarSolid { |
2039 | | #[allow(clippy::unnecessary_cast)] |
2040 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
2041 | 0 | (3 as u8).write_into(writer); |
2042 | 0 | self.palette_index.write_into(writer); |
2043 | 0 | self.alpha.write_into(writer); |
2044 | 0 | self.var_index_base.write_into(writer); |
2045 | 0 | } |
2046 | 0 | fn table_type(&self) -> TableType { |
2047 | 0 | TableType::Named("PaintVarSolid") |
2048 | 0 | } |
2049 | | } |
2050 | | |
2051 | | impl Validate for PaintVarSolid { |
2052 | 0 | fn validate_impl(&self, _ctx: &mut ValidationCtx) {} |
2053 | | } |
2054 | | |
2055 | | impl<'a> FromObjRef<read_fonts::tables::colr::PaintVarSolid<'a>> for PaintVarSolid { |
2056 | 0 | fn from_obj_ref(obj: &read_fonts::tables::colr::PaintVarSolid<'a>, _: FontData) -> Self { |
2057 | 0 | PaintVarSolid { |
2058 | 0 | palette_index: obj.palette_index(), |
2059 | 0 | alpha: obj.alpha(), |
2060 | 0 | var_index_base: obj.var_index_base(), |
2061 | 0 | } |
2062 | 0 | } |
2063 | | } |
2064 | | |
2065 | | #[allow(clippy::needless_lifetimes)] |
2066 | | impl<'a> FromTableRef<read_fonts::tables::colr::PaintVarSolid<'a>> for PaintVarSolid {} |
2067 | | |
2068 | | impl ReadArgs for PaintVarSolid { |
2069 | | type Args = (); |
2070 | | } |
2071 | | |
2072 | | impl<'a> FontRead<'a> for PaintVarSolid { |
2073 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
2074 | 0 | <read_fonts::tables::colr::PaintVarSolid as FontRead>::read(data) |
2075 | 0 | .map(|x| x.to_owned_table()) |
2076 | 0 | } |
2077 | | } |
2078 | | |
2079 | | /// [PaintLinearGradient](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-4-and-5-paintlineargradient-paintvarlineargradient) table |
2080 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
2081 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
2082 | | pub struct PaintLinearGradient { |
2083 | | /// Offset to ColorLine table. |
2084 | | pub color_line: OffsetMarker<ColorLine, WIDTH_24>, |
2085 | | /// Start point (p₀) x coordinate. |
2086 | | pub x0: FWord, |
2087 | | /// Start point (p₀) y coordinate. |
2088 | | pub y0: FWord, |
2089 | | /// End point (p₁) x coordinate. |
2090 | | pub x1: FWord, |
2091 | | /// End point (p₁) y coordinate. |
2092 | | pub y1: FWord, |
2093 | | /// Rotation point (p₂) x coordinate. |
2094 | | pub x2: FWord, |
2095 | | /// Rotation point (p₂) y coordinate. |
2096 | | pub y2: FWord, |
2097 | | } |
2098 | | |
2099 | | impl PaintLinearGradient { |
2100 | | /// Construct a new `PaintLinearGradient` |
2101 | 0 | pub fn new( |
2102 | 0 | color_line: ColorLine, |
2103 | 0 | x0: FWord, |
2104 | 0 | y0: FWord, |
2105 | 0 | x1: FWord, |
2106 | 0 | y1: FWord, |
2107 | 0 | x2: FWord, |
2108 | 0 | y2: FWord, |
2109 | 0 | ) -> Self { |
2110 | 0 | Self { |
2111 | 0 | color_line: color_line.into(), |
2112 | 0 | x0, |
2113 | 0 | y0, |
2114 | 0 | x1, |
2115 | 0 | y1, |
2116 | 0 | x2, |
2117 | 0 | y2, |
2118 | 0 | } |
2119 | 0 | } |
2120 | | } |
2121 | | |
2122 | | impl FontWrite for PaintLinearGradient { |
2123 | | #[allow(clippy::unnecessary_cast)] |
2124 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
2125 | 0 | (4 as u8).write_into(writer); |
2126 | 0 | self.color_line.write_into(writer); |
2127 | 0 | self.x0.write_into(writer); |
2128 | 0 | self.y0.write_into(writer); |
2129 | 0 | self.x1.write_into(writer); |
2130 | 0 | self.y1.write_into(writer); |
2131 | 0 | self.x2.write_into(writer); |
2132 | 0 | self.y2.write_into(writer); |
2133 | 0 | } |
2134 | 0 | fn table_type(&self) -> TableType { |
2135 | 0 | TableType::Named("PaintLinearGradient") |
2136 | 0 | } |
2137 | | } |
2138 | | |
2139 | | impl Validate for PaintLinearGradient { |
2140 | 0 | fn validate_impl(&self, ctx: &mut ValidationCtx) { |
2141 | 0 | ctx.in_table("PaintLinearGradient", |ctx| { |
2142 | 0 | ctx.in_field("color_line", |ctx| { |
2143 | 0 | self.color_line.validate_impl(ctx); |
2144 | 0 | }); |
2145 | 0 | }) |
2146 | 0 | } |
2147 | | } |
2148 | | |
2149 | | impl<'a> FromObjRef<read_fonts::tables::colr::PaintLinearGradient<'a>> for PaintLinearGradient { |
2150 | 0 | fn from_obj_ref(obj: &read_fonts::tables::colr::PaintLinearGradient<'a>, _: FontData) -> Self { |
2151 | 0 | PaintLinearGradient { |
2152 | 0 | color_line: obj.color_line().to_owned_table(), |
2153 | 0 | x0: obj.x0(), |
2154 | 0 | y0: obj.y0(), |
2155 | 0 | x1: obj.x1(), |
2156 | 0 | y1: obj.y1(), |
2157 | 0 | x2: obj.x2(), |
2158 | 0 | y2: obj.y2(), |
2159 | 0 | } |
2160 | 0 | } |
2161 | | } |
2162 | | |
2163 | | #[allow(clippy::needless_lifetimes)] |
2164 | | impl<'a> FromTableRef<read_fonts::tables::colr::PaintLinearGradient<'a>> for PaintLinearGradient {} |
2165 | | |
2166 | | impl ReadArgs for PaintLinearGradient { |
2167 | | type Args = (); |
2168 | | } |
2169 | | |
2170 | | impl<'a> FontRead<'a> for PaintLinearGradient { |
2171 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
2172 | 0 | <read_fonts::tables::colr::PaintLinearGradient as FontRead>::read(data) |
2173 | 0 | .map(|x| x.to_owned_table()) |
2174 | 0 | } |
2175 | | } |
2176 | | |
2177 | | /// [PaintVarLinearGradient](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-4-and-5-paintlineargradient-paintvarlineargradient) table |
2178 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
2179 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
2180 | | pub struct PaintVarLinearGradient { |
2181 | | /// Offset to VarColorLine table. |
2182 | | pub color_line: OffsetMarker<VarColorLine, WIDTH_24>, |
2183 | | /// Start point (p₀) x coordinate. For variation, use |
2184 | | /// varIndexBase + 0. |
2185 | | pub x0: FWord, |
2186 | | /// Start point (p₀) y coordinate. For variation, use |
2187 | | /// varIndexBase + 1. |
2188 | | pub y0: FWord, |
2189 | | /// End point (p₁) x coordinate. For variation, use varIndexBase |
2190 | | /// + 2. |
2191 | | pub x1: FWord, |
2192 | | /// End point (p₁) y coordinate. For variation, use varIndexBase |
2193 | | /// + 3. |
2194 | | pub y1: FWord, |
2195 | | /// Rotation point (p₂) x coordinate. For variation, use |
2196 | | /// varIndexBase + 4. |
2197 | | pub x2: FWord, |
2198 | | /// Rotation point (p₂) y coordinate. For variation, use |
2199 | | /// varIndexBase + 5. |
2200 | | pub y2: FWord, |
2201 | | /// Base index into DeltaSetIndexMap. |
2202 | | pub var_index_base: u32, |
2203 | | } |
2204 | | |
2205 | | impl PaintVarLinearGradient { |
2206 | | /// Construct a new `PaintVarLinearGradient` |
2207 | | #[allow(clippy::too_many_arguments)] |
2208 | 0 | pub fn new( |
2209 | 0 | color_line: VarColorLine, |
2210 | 0 | x0: FWord, |
2211 | 0 | y0: FWord, |
2212 | 0 | x1: FWord, |
2213 | 0 | y1: FWord, |
2214 | 0 | x2: FWord, |
2215 | 0 | y2: FWord, |
2216 | 0 | var_index_base: u32, |
2217 | 0 | ) -> Self { |
2218 | 0 | Self { |
2219 | 0 | color_line: color_line.into(), |
2220 | 0 | x0, |
2221 | 0 | y0, |
2222 | 0 | x1, |
2223 | 0 | y1, |
2224 | 0 | x2, |
2225 | 0 | y2, |
2226 | 0 | var_index_base, |
2227 | 0 | } |
2228 | 0 | } |
2229 | | } |
2230 | | |
2231 | | impl FontWrite for PaintVarLinearGradient { |
2232 | | #[allow(clippy::unnecessary_cast)] |
2233 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
2234 | 0 | (5 as u8).write_into(writer); |
2235 | 0 | self.color_line.write_into(writer); |
2236 | 0 | self.x0.write_into(writer); |
2237 | 0 | self.y0.write_into(writer); |
2238 | 0 | self.x1.write_into(writer); |
2239 | 0 | self.y1.write_into(writer); |
2240 | 0 | self.x2.write_into(writer); |
2241 | 0 | self.y2.write_into(writer); |
2242 | 0 | self.var_index_base.write_into(writer); |
2243 | 0 | } |
2244 | 0 | fn table_type(&self) -> TableType { |
2245 | 0 | TableType::Named("PaintVarLinearGradient") |
2246 | 0 | } |
2247 | | } |
2248 | | |
2249 | | impl Validate for PaintVarLinearGradient { |
2250 | 0 | fn validate_impl(&self, ctx: &mut ValidationCtx) { |
2251 | 0 | ctx.in_table("PaintVarLinearGradient", |ctx| { |
2252 | 0 | ctx.in_field("color_line", |ctx| { |
2253 | 0 | self.color_line.validate_impl(ctx); |
2254 | 0 | }); |
2255 | 0 | }) |
2256 | 0 | } |
2257 | | } |
2258 | | |
2259 | | impl<'a> FromObjRef<read_fonts::tables::colr::PaintVarLinearGradient<'a>> |
2260 | | for PaintVarLinearGradient |
2261 | | { |
2262 | 0 | fn from_obj_ref( |
2263 | 0 | obj: &read_fonts::tables::colr::PaintVarLinearGradient<'a>, |
2264 | 0 | _: FontData, |
2265 | 0 | ) -> Self { |
2266 | 0 | PaintVarLinearGradient { |
2267 | 0 | color_line: obj.color_line().to_owned_table(), |
2268 | 0 | x0: obj.x0(), |
2269 | 0 | y0: obj.y0(), |
2270 | 0 | x1: obj.x1(), |
2271 | 0 | y1: obj.y1(), |
2272 | 0 | x2: obj.x2(), |
2273 | 0 | y2: obj.y2(), |
2274 | 0 | var_index_base: obj.var_index_base(), |
2275 | 0 | } |
2276 | 0 | } |
2277 | | } |
2278 | | |
2279 | | #[allow(clippy::needless_lifetimes)] |
2280 | | impl<'a> FromTableRef<read_fonts::tables::colr::PaintVarLinearGradient<'a>> |
2281 | | for PaintVarLinearGradient |
2282 | | { |
2283 | | } |
2284 | | |
2285 | | impl ReadArgs for PaintVarLinearGradient { |
2286 | | type Args = (); |
2287 | | } |
2288 | | |
2289 | | impl<'a> FontRead<'a> for PaintVarLinearGradient { |
2290 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
2291 | 0 | <read_fonts::tables::colr::PaintVarLinearGradient as FontRead>::read(data) |
2292 | 0 | .map(|x| x.to_owned_table()) |
2293 | 0 | } |
2294 | | } |
2295 | | |
2296 | | /// [PaintRadialGradient](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-6-and-7-paintradialgradient-paintvarradialgradient) table |
2297 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
2298 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
2299 | | pub struct PaintRadialGradient { |
2300 | | /// Offset to ColorLine table. |
2301 | | pub color_line: OffsetMarker<ColorLine, WIDTH_24>, |
2302 | | /// Start circle center x coordinate. |
2303 | | pub x0: FWord, |
2304 | | /// Start circle center y coordinate. |
2305 | | pub y0: FWord, |
2306 | | /// Start circle radius. |
2307 | | pub radius0: UfWord, |
2308 | | /// End circle center x coordinate. |
2309 | | pub x1: FWord, |
2310 | | /// End circle center y coordinate. |
2311 | | pub y1: FWord, |
2312 | | /// End circle radius. |
2313 | | pub radius1: UfWord, |
2314 | | } |
2315 | | |
2316 | | impl PaintRadialGradient { |
2317 | | /// Construct a new `PaintRadialGradient` |
2318 | 0 | pub fn new( |
2319 | 0 | color_line: ColorLine, |
2320 | 0 | x0: FWord, |
2321 | 0 | y0: FWord, |
2322 | 0 | radius0: UfWord, |
2323 | 0 | x1: FWord, |
2324 | 0 | y1: FWord, |
2325 | 0 | radius1: UfWord, |
2326 | 0 | ) -> Self { |
2327 | 0 | Self { |
2328 | 0 | color_line: color_line.into(), |
2329 | 0 | x0, |
2330 | 0 | y0, |
2331 | 0 | radius0, |
2332 | 0 | x1, |
2333 | 0 | y1, |
2334 | 0 | radius1, |
2335 | 0 | } |
2336 | 0 | } |
2337 | | } |
2338 | | |
2339 | | impl FontWrite for PaintRadialGradient { |
2340 | | #[allow(clippy::unnecessary_cast)] |
2341 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
2342 | 0 | (6 as u8).write_into(writer); |
2343 | 0 | self.color_line.write_into(writer); |
2344 | 0 | self.x0.write_into(writer); |
2345 | 0 | self.y0.write_into(writer); |
2346 | 0 | self.radius0.write_into(writer); |
2347 | 0 | self.x1.write_into(writer); |
2348 | 0 | self.y1.write_into(writer); |
2349 | 0 | self.radius1.write_into(writer); |
2350 | 0 | } |
2351 | 0 | fn table_type(&self) -> TableType { |
2352 | 0 | TableType::Named("PaintRadialGradient") |
2353 | 0 | } |
2354 | | } |
2355 | | |
2356 | | impl Validate for PaintRadialGradient { |
2357 | 0 | fn validate_impl(&self, ctx: &mut ValidationCtx) { |
2358 | 0 | ctx.in_table("PaintRadialGradient", |ctx| { |
2359 | 0 | ctx.in_field("color_line", |ctx| { |
2360 | 0 | self.color_line.validate_impl(ctx); |
2361 | 0 | }); |
2362 | 0 | }) |
2363 | 0 | } |
2364 | | } |
2365 | | |
2366 | | impl<'a> FromObjRef<read_fonts::tables::colr::PaintRadialGradient<'a>> for PaintRadialGradient { |
2367 | 0 | fn from_obj_ref(obj: &read_fonts::tables::colr::PaintRadialGradient<'a>, _: FontData) -> Self { |
2368 | 0 | PaintRadialGradient { |
2369 | 0 | color_line: obj.color_line().to_owned_table(), |
2370 | 0 | x0: obj.x0(), |
2371 | 0 | y0: obj.y0(), |
2372 | 0 | radius0: obj.radius0(), |
2373 | 0 | x1: obj.x1(), |
2374 | 0 | y1: obj.y1(), |
2375 | 0 | radius1: obj.radius1(), |
2376 | 0 | } |
2377 | 0 | } |
2378 | | } |
2379 | | |
2380 | | #[allow(clippy::needless_lifetimes)] |
2381 | | impl<'a> FromTableRef<read_fonts::tables::colr::PaintRadialGradient<'a>> for PaintRadialGradient {} |
2382 | | |
2383 | | impl ReadArgs for PaintRadialGradient { |
2384 | | type Args = (); |
2385 | | } |
2386 | | |
2387 | | impl<'a> FontRead<'a> for PaintRadialGradient { |
2388 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
2389 | 0 | <read_fonts::tables::colr::PaintRadialGradient as FontRead>::read(data) |
2390 | 0 | .map(|x| x.to_owned_table()) |
2391 | 0 | } |
2392 | | } |
2393 | | |
2394 | | /// [PaintVarRadialGradient](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-6-and-7-paintradialgradient-paintvarradialgradient) table |
2395 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
2396 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
2397 | | pub struct PaintVarRadialGradient { |
2398 | | /// Offset to VarColorLine table. |
2399 | | pub color_line: OffsetMarker<VarColorLine, WIDTH_24>, |
2400 | | /// Start circle center x coordinate. For variation, use |
2401 | | /// varIndexBase + 0. |
2402 | | pub x0: FWord, |
2403 | | /// Start circle center y coordinate. For variation, use |
2404 | | /// varIndexBase + 1. |
2405 | | pub y0: FWord, |
2406 | | /// Start circle radius. For variation, use varIndexBase + 2. |
2407 | | pub radius0: UfWord, |
2408 | | /// End circle center x coordinate. For variation, use varIndexBase |
2409 | | /// + 3. |
2410 | | pub x1: FWord, |
2411 | | /// End circle center y coordinate. For variation, use varIndexBase |
2412 | | /// + 4. |
2413 | | pub y1: FWord, |
2414 | | /// End circle radius. For variation, use varIndexBase + 5. |
2415 | | pub radius1: UfWord, |
2416 | | /// Base index into DeltaSetIndexMap. |
2417 | | pub var_index_base: u32, |
2418 | | } |
2419 | | |
2420 | | impl PaintVarRadialGradient { |
2421 | | /// Construct a new `PaintVarRadialGradient` |
2422 | | #[allow(clippy::too_many_arguments)] |
2423 | 0 | pub fn new( |
2424 | 0 | color_line: VarColorLine, |
2425 | 0 | x0: FWord, |
2426 | 0 | y0: FWord, |
2427 | 0 | radius0: UfWord, |
2428 | 0 | x1: FWord, |
2429 | 0 | y1: FWord, |
2430 | 0 | radius1: UfWord, |
2431 | 0 | var_index_base: u32, |
2432 | 0 | ) -> Self { |
2433 | 0 | Self { |
2434 | 0 | color_line: color_line.into(), |
2435 | 0 | x0, |
2436 | 0 | y0, |
2437 | 0 | radius0, |
2438 | 0 | x1, |
2439 | 0 | y1, |
2440 | 0 | radius1, |
2441 | 0 | var_index_base, |
2442 | 0 | } |
2443 | 0 | } |
2444 | | } |
2445 | | |
2446 | | impl FontWrite for PaintVarRadialGradient { |
2447 | | #[allow(clippy::unnecessary_cast)] |
2448 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
2449 | 0 | (7 as u8).write_into(writer); |
2450 | 0 | self.color_line.write_into(writer); |
2451 | 0 | self.x0.write_into(writer); |
2452 | 0 | self.y0.write_into(writer); |
2453 | 0 | self.radius0.write_into(writer); |
2454 | 0 | self.x1.write_into(writer); |
2455 | 0 | self.y1.write_into(writer); |
2456 | 0 | self.radius1.write_into(writer); |
2457 | 0 | self.var_index_base.write_into(writer); |
2458 | 0 | } |
2459 | 0 | fn table_type(&self) -> TableType { |
2460 | 0 | TableType::Named("PaintVarRadialGradient") |
2461 | 0 | } |
2462 | | } |
2463 | | |
2464 | | impl Validate for PaintVarRadialGradient { |
2465 | 0 | fn validate_impl(&self, ctx: &mut ValidationCtx) { |
2466 | 0 | ctx.in_table("PaintVarRadialGradient", |ctx| { |
2467 | 0 | ctx.in_field("color_line", |ctx| { |
2468 | 0 | self.color_line.validate_impl(ctx); |
2469 | 0 | }); |
2470 | 0 | }) |
2471 | 0 | } |
2472 | | } |
2473 | | |
2474 | | impl<'a> FromObjRef<read_fonts::tables::colr::PaintVarRadialGradient<'a>> |
2475 | | for PaintVarRadialGradient |
2476 | | { |
2477 | 0 | fn from_obj_ref( |
2478 | 0 | obj: &read_fonts::tables::colr::PaintVarRadialGradient<'a>, |
2479 | 0 | _: FontData, |
2480 | 0 | ) -> Self { |
2481 | 0 | PaintVarRadialGradient { |
2482 | 0 | color_line: obj.color_line().to_owned_table(), |
2483 | 0 | x0: obj.x0(), |
2484 | 0 | y0: obj.y0(), |
2485 | 0 | radius0: obj.radius0(), |
2486 | 0 | x1: obj.x1(), |
2487 | 0 | y1: obj.y1(), |
2488 | 0 | radius1: obj.radius1(), |
2489 | 0 | var_index_base: obj.var_index_base(), |
2490 | 0 | } |
2491 | 0 | } |
2492 | | } |
2493 | | |
2494 | | #[allow(clippy::needless_lifetimes)] |
2495 | | impl<'a> FromTableRef<read_fonts::tables::colr::PaintVarRadialGradient<'a>> |
2496 | | for PaintVarRadialGradient |
2497 | | { |
2498 | | } |
2499 | | |
2500 | | impl ReadArgs for PaintVarRadialGradient { |
2501 | | type Args = (); |
2502 | | } |
2503 | | |
2504 | | impl<'a> FontRead<'a> for PaintVarRadialGradient { |
2505 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
2506 | 0 | <read_fonts::tables::colr::PaintVarRadialGradient as FontRead>::read(data) |
2507 | 0 | .map(|x| x.to_owned_table()) |
2508 | 0 | } |
2509 | | } |
2510 | | |
2511 | | /// [PaintSweepGradient](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-8-and-9-paintsweepgradient-paintvarsweepgradient) table |
2512 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
2513 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
2514 | | pub struct PaintSweepGradient { |
2515 | | /// Offset to ColorLine table. |
2516 | | pub color_line: OffsetMarker<ColorLine, WIDTH_24>, |
2517 | | /// Center x coordinate. |
2518 | | pub center_x: FWord, |
2519 | | /// Center y coordinate. |
2520 | | pub center_y: FWord, |
2521 | | /// Start of the angular range of the gradient, 180° in |
2522 | | /// counter-clockwise degrees per 1.0 of value. |
2523 | | pub start_angle: F2Dot14, |
2524 | | /// End of the angular range of the gradient, 180° in |
2525 | | /// counter-clockwise degrees per 1.0 of value. |
2526 | | pub end_angle: F2Dot14, |
2527 | | } |
2528 | | |
2529 | | impl PaintSweepGradient { |
2530 | | /// Construct a new `PaintSweepGradient` |
2531 | 0 | pub fn new( |
2532 | 0 | color_line: ColorLine, |
2533 | 0 | center_x: FWord, |
2534 | 0 | center_y: FWord, |
2535 | 0 | start_angle: F2Dot14, |
2536 | 0 | end_angle: F2Dot14, |
2537 | 0 | ) -> Self { |
2538 | 0 | Self { |
2539 | 0 | color_line: color_line.into(), |
2540 | 0 | center_x, |
2541 | 0 | center_y, |
2542 | 0 | start_angle, |
2543 | 0 | end_angle, |
2544 | 0 | } |
2545 | 0 | } |
2546 | | } |
2547 | | |
2548 | | impl FontWrite for PaintSweepGradient { |
2549 | | #[allow(clippy::unnecessary_cast)] |
2550 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
2551 | 0 | (8 as u8).write_into(writer); |
2552 | 0 | self.color_line.write_into(writer); |
2553 | 0 | self.center_x.write_into(writer); |
2554 | 0 | self.center_y.write_into(writer); |
2555 | 0 | self.start_angle.write_into(writer); |
2556 | 0 | self.end_angle.write_into(writer); |
2557 | 0 | } |
2558 | 0 | fn table_type(&self) -> TableType { |
2559 | 0 | TableType::Named("PaintSweepGradient") |
2560 | 0 | } |
2561 | | } |
2562 | | |
2563 | | impl Validate for PaintSweepGradient { |
2564 | 0 | fn validate_impl(&self, ctx: &mut ValidationCtx) { |
2565 | 0 | ctx.in_table("PaintSweepGradient", |ctx| { |
2566 | 0 | ctx.in_field("color_line", |ctx| { |
2567 | 0 | self.color_line.validate_impl(ctx); |
2568 | 0 | }); |
2569 | 0 | }) |
2570 | 0 | } |
2571 | | } |
2572 | | |
2573 | | impl<'a> FromObjRef<read_fonts::tables::colr::PaintSweepGradient<'a>> for PaintSweepGradient { |
2574 | 0 | fn from_obj_ref(obj: &read_fonts::tables::colr::PaintSweepGradient<'a>, _: FontData) -> Self { |
2575 | 0 | PaintSweepGradient { |
2576 | 0 | color_line: obj.color_line().to_owned_table(), |
2577 | 0 | center_x: obj.center_x(), |
2578 | 0 | center_y: obj.center_y(), |
2579 | 0 | start_angle: obj.start_angle(), |
2580 | 0 | end_angle: obj.end_angle(), |
2581 | 0 | } |
2582 | 0 | } |
2583 | | } |
2584 | | |
2585 | | #[allow(clippy::needless_lifetimes)] |
2586 | | impl<'a> FromTableRef<read_fonts::tables::colr::PaintSweepGradient<'a>> for PaintSweepGradient {} |
2587 | | |
2588 | | impl ReadArgs for PaintSweepGradient { |
2589 | | type Args = (); |
2590 | | } |
2591 | | |
2592 | | impl<'a> FontRead<'a> for PaintSweepGradient { |
2593 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
2594 | 0 | <read_fonts::tables::colr::PaintSweepGradient as FontRead>::read(data) |
2595 | 0 | .map(|x| x.to_owned_table()) |
2596 | 0 | } |
2597 | | } |
2598 | | |
2599 | | /// [PaintVarSweepGradient](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-8-and-9-paintsweepgradient-paintvarsweepgradient) table |
2600 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
2601 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
2602 | | pub struct PaintVarSweepGradient { |
2603 | | /// Offset to VarColorLine table. |
2604 | | pub color_line: OffsetMarker<VarColorLine, WIDTH_24>, |
2605 | | /// Center x coordinate. For variation, use varIndexBase + 0. |
2606 | | pub center_x: FWord, |
2607 | | /// Center y coordinate. For variation, use varIndexBase + 1. |
2608 | | pub center_y: FWord, |
2609 | | /// Start of the angular range of the gradient, 180° in |
2610 | | /// counter-clockwise degrees per 1.0 of value. For variation, use |
2611 | | /// varIndexBase + 2. |
2612 | | pub start_angle: F2Dot14, |
2613 | | /// End of the angular range of the gradient, 180° in |
2614 | | /// counter-clockwise degrees per 1.0 of value. For variation, use |
2615 | | /// varIndexBase + 3. |
2616 | | pub end_angle: F2Dot14, |
2617 | | /// Base index into DeltaSetIndexMap. |
2618 | | pub var_index_base: u32, |
2619 | | } |
2620 | | |
2621 | | impl PaintVarSweepGradient { |
2622 | | /// Construct a new `PaintVarSweepGradient` |
2623 | 0 | pub fn new( |
2624 | 0 | color_line: VarColorLine, |
2625 | 0 | center_x: FWord, |
2626 | 0 | center_y: FWord, |
2627 | 0 | start_angle: F2Dot14, |
2628 | 0 | end_angle: F2Dot14, |
2629 | 0 | var_index_base: u32, |
2630 | 0 | ) -> Self { |
2631 | 0 | Self { |
2632 | 0 | color_line: color_line.into(), |
2633 | 0 | center_x, |
2634 | 0 | center_y, |
2635 | 0 | start_angle, |
2636 | 0 | end_angle, |
2637 | 0 | var_index_base, |
2638 | 0 | } |
2639 | 0 | } |
2640 | | } |
2641 | | |
2642 | | impl FontWrite for PaintVarSweepGradient { |
2643 | | #[allow(clippy::unnecessary_cast)] |
2644 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
2645 | 0 | (9 as u8).write_into(writer); |
2646 | 0 | self.color_line.write_into(writer); |
2647 | 0 | self.center_x.write_into(writer); |
2648 | 0 | self.center_y.write_into(writer); |
2649 | 0 | self.start_angle.write_into(writer); |
2650 | 0 | self.end_angle.write_into(writer); |
2651 | 0 | self.var_index_base.write_into(writer); |
2652 | 0 | } |
2653 | 0 | fn table_type(&self) -> TableType { |
2654 | 0 | TableType::Named("PaintVarSweepGradient") |
2655 | 0 | } |
2656 | | } |
2657 | | |
2658 | | impl Validate for PaintVarSweepGradient { |
2659 | 0 | fn validate_impl(&self, ctx: &mut ValidationCtx) { |
2660 | 0 | ctx.in_table("PaintVarSweepGradient", |ctx| { |
2661 | 0 | ctx.in_field("color_line", |ctx| { |
2662 | 0 | self.color_line.validate_impl(ctx); |
2663 | 0 | }); |
2664 | 0 | }) |
2665 | 0 | } |
2666 | | } |
2667 | | |
2668 | | impl<'a> FromObjRef<read_fonts::tables::colr::PaintVarSweepGradient<'a>> for PaintVarSweepGradient { |
2669 | 0 | fn from_obj_ref( |
2670 | 0 | obj: &read_fonts::tables::colr::PaintVarSweepGradient<'a>, |
2671 | 0 | _: FontData, |
2672 | 0 | ) -> Self { |
2673 | 0 | PaintVarSweepGradient { |
2674 | 0 | color_line: obj.color_line().to_owned_table(), |
2675 | 0 | center_x: obj.center_x(), |
2676 | 0 | center_y: obj.center_y(), |
2677 | 0 | start_angle: obj.start_angle(), |
2678 | 0 | end_angle: obj.end_angle(), |
2679 | 0 | var_index_base: obj.var_index_base(), |
2680 | 0 | } |
2681 | 0 | } |
2682 | | } |
2683 | | |
2684 | | #[allow(clippy::needless_lifetimes)] |
2685 | | impl<'a> FromTableRef<read_fonts::tables::colr::PaintVarSweepGradient<'a>> |
2686 | | for PaintVarSweepGradient |
2687 | | { |
2688 | | } |
2689 | | |
2690 | | impl ReadArgs for PaintVarSweepGradient { |
2691 | | type Args = (); |
2692 | | } |
2693 | | |
2694 | | impl<'a> FontRead<'a> for PaintVarSweepGradient { |
2695 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
2696 | 0 | <read_fonts::tables::colr::PaintVarSweepGradient as FontRead>::read(data) |
2697 | 0 | .map(|x| x.to_owned_table()) |
2698 | 0 | } |
2699 | | } |
2700 | | |
2701 | | /// [PaintGlyph](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#format-10-paintglyph) table |
2702 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
2703 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
2704 | | pub struct PaintGlyph { |
2705 | | /// Offset to a Paint table. |
2706 | | pub paint: OffsetMarker<Paint, WIDTH_24>, |
2707 | | /// Glyph ID for the source outline. |
2708 | | pub glyph_id: GlyphId16, |
2709 | | } |
2710 | | |
2711 | | impl PaintGlyph { |
2712 | | /// Construct a new `PaintGlyph` |
2713 | 0 | pub fn new(paint: Paint, glyph_id: GlyphId16) -> Self { |
2714 | 0 | Self { |
2715 | 0 | paint: paint.into(), |
2716 | 0 | glyph_id, |
2717 | 0 | } |
2718 | 0 | } |
2719 | | } |
2720 | | |
2721 | | impl FontWrite for PaintGlyph { |
2722 | | #[allow(clippy::unnecessary_cast)] |
2723 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
2724 | 0 | (10 as u8).write_into(writer); |
2725 | 0 | self.paint.write_into(writer); |
2726 | 0 | self.glyph_id.write_into(writer); |
2727 | 0 | } |
2728 | 0 | fn table_type(&self) -> TableType { |
2729 | 0 | TableType::Named("PaintGlyph") |
2730 | 0 | } |
2731 | | } |
2732 | | |
2733 | | impl Validate for PaintGlyph { |
2734 | 0 | fn validate_impl(&self, ctx: &mut ValidationCtx) { |
2735 | 0 | ctx.in_table("PaintGlyph", |ctx| { |
2736 | 0 | ctx.in_field("paint", |ctx| { |
2737 | 0 | self.paint.validate_impl(ctx); |
2738 | 0 | }); |
2739 | 0 | }) |
2740 | 0 | } |
2741 | | } |
2742 | | |
2743 | | impl<'a> FromObjRef<read_fonts::tables::colr::PaintGlyph<'a>> for PaintGlyph { |
2744 | 0 | fn from_obj_ref(obj: &read_fonts::tables::colr::PaintGlyph<'a>, _: FontData) -> Self { |
2745 | 0 | PaintGlyph { |
2746 | 0 | paint: obj.paint().to_owned_table(), |
2747 | 0 | glyph_id: obj.glyph_id(), |
2748 | 0 | } |
2749 | 0 | } |
2750 | | } |
2751 | | |
2752 | | #[allow(clippy::needless_lifetimes)] |
2753 | | impl<'a> FromTableRef<read_fonts::tables::colr::PaintGlyph<'a>> for PaintGlyph {} |
2754 | | |
2755 | | impl ReadArgs for PaintGlyph { |
2756 | | type Args = (); |
2757 | | } |
2758 | | |
2759 | | impl<'a> FontRead<'a> for PaintGlyph { |
2760 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
2761 | 0 | <read_fonts::tables::colr::PaintGlyph as FontRead>::read(data).map(|x| x.to_owned_table()) |
2762 | 0 | } |
2763 | | } |
2764 | | |
2765 | | /// [PaintColrGlyph](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#format-11-paintcolrglyph) table |
2766 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
2767 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
2768 | | pub struct PaintColrGlyph { |
2769 | | /// Glyph ID for a BaseGlyphList base glyph. |
2770 | | pub glyph_id: GlyphId16, |
2771 | | } |
2772 | | |
2773 | | impl PaintColrGlyph { |
2774 | | /// Construct a new `PaintColrGlyph` |
2775 | 0 | pub fn new(glyph_id: GlyphId16) -> Self { |
2776 | 0 | Self { glyph_id } |
2777 | 0 | } |
2778 | | } |
2779 | | |
2780 | | impl FontWrite for PaintColrGlyph { |
2781 | | #[allow(clippy::unnecessary_cast)] |
2782 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
2783 | 0 | (11 as u8).write_into(writer); |
2784 | 0 | self.glyph_id.write_into(writer); |
2785 | 0 | } |
2786 | 0 | fn table_type(&self) -> TableType { |
2787 | 0 | TableType::Named("PaintColrGlyph") |
2788 | 0 | } |
2789 | | } |
2790 | | |
2791 | | impl Validate for PaintColrGlyph { |
2792 | 0 | fn validate_impl(&self, _ctx: &mut ValidationCtx) {} |
2793 | | } |
2794 | | |
2795 | | impl<'a> FromObjRef<read_fonts::tables::colr::PaintColrGlyph<'a>> for PaintColrGlyph { |
2796 | 0 | fn from_obj_ref(obj: &read_fonts::tables::colr::PaintColrGlyph<'a>, _: FontData) -> Self { |
2797 | 0 | PaintColrGlyph { |
2798 | 0 | glyph_id: obj.glyph_id(), |
2799 | 0 | } |
2800 | 0 | } |
2801 | | } |
2802 | | |
2803 | | #[allow(clippy::needless_lifetimes)] |
2804 | | impl<'a> FromTableRef<read_fonts::tables::colr::PaintColrGlyph<'a>> for PaintColrGlyph {} |
2805 | | |
2806 | | impl ReadArgs for PaintColrGlyph { |
2807 | | type Args = (); |
2808 | | } |
2809 | | |
2810 | | impl<'a> FontRead<'a> for PaintColrGlyph { |
2811 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
2812 | 0 | <read_fonts::tables::colr::PaintColrGlyph as FontRead>::read(data) |
2813 | 0 | .map(|x| x.to_owned_table()) |
2814 | 0 | } |
2815 | | } |
2816 | | |
2817 | | /// [PaintTransform](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-12-and-13-painttransform-paintvartransform) table |
2818 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
2819 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
2820 | | pub struct PaintTransform { |
2821 | | /// Offset to a Paint subtable. |
2822 | | pub paint: OffsetMarker<Paint, WIDTH_24>, |
2823 | | /// Offset to an Affine2x3 table. |
2824 | | pub transform: OffsetMarker<Affine2x3, WIDTH_24>, |
2825 | | } |
2826 | | |
2827 | | impl PaintTransform { |
2828 | | /// Construct a new `PaintTransform` |
2829 | 0 | pub fn new(paint: Paint, transform: Affine2x3) -> Self { |
2830 | 0 | Self { |
2831 | 0 | paint: paint.into(), |
2832 | 0 | transform: transform.into(), |
2833 | 0 | } |
2834 | 0 | } |
2835 | | } |
2836 | | |
2837 | | impl FontWrite for PaintTransform { |
2838 | | #[allow(clippy::unnecessary_cast)] |
2839 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
2840 | 0 | (12 as u8).write_into(writer); |
2841 | 0 | self.paint.write_into(writer); |
2842 | 0 | self.transform.write_into(writer); |
2843 | 0 | } |
2844 | 0 | fn table_type(&self) -> TableType { |
2845 | 0 | TableType::Named("PaintTransform") |
2846 | 0 | } |
2847 | | } |
2848 | | |
2849 | | impl Validate for PaintTransform { |
2850 | 0 | fn validate_impl(&self, ctx: &mut ValidationCtx) { |
2851 | 0 | ctx.in_table("PaintTransform", |ctx| { |
2852 | 0 | ctx.in_field("paint", |ctx| { |
2853 | 0 | self.paint.validate_impl(ctx); |
2854 | 0 | }); |
2855 | 0 | ctx.in_field("transform", |ctx| { |
2856 | 0 | self.transform.validate_impl(ctx); |
2857 | 0 | }); |
2858 | 0 | }) |
2859 | 0 | } |
2860 | | } |
2861 | | |
2862 | | impl<'a> FromObjRef<read_fonts::tables::colr::PaintTransform<'a>> for PaintTransform { |
2863 | 0 | fn from_obj_ref(obj: &read_fonts::tables::colr::PaintTransform<'a>, _: FontData) -> Self { |
2864 | 0 | PaintTransform { |
2865 | 0 | paint: obj.paint().to_owned_table(), |
2866 | 0 | transform: obj.transform().to_owned_table(), |
2867 | 0 | } |
2868 | 0 | } |
2869 | | } |
2870 | | |
2871 | | #[allow(clippy::needless_lifetimes)] |
2872 | | impl<'a> FromTableRef<read_fonts::tables::colr::PaintTransform<'a>> for PaintTransform {} |
2873 | | |
2874 | | impl ReadArgs for PaintTransform { |
2875 | | type Args = (); |
2876 | | } |
2877 | | |
2878 | | impl<'a> FontRead<'a> for PaintTransform { |
2879 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
2880 | 0 | <read_fonts::tables::colr::PaintTransform as FontRead>::read(data) |
2881 | 0 | .map(|x| x.to_owned_table()) |
2882 | 0 | } |
2883 | | } |
2884 | | |
2885 | | /// [PaintVarTransform](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-12-and-13-painttransform-paintvartransform) table |
2886 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
2887 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
2888 | | pub struct PaintVarTransform { |
2889 | | /// Offset to a Paint subtable. |
2890 | | pub paint: OffsetMarker<Paint, WIDTH_24>, |
2891 | | /// Offset to a VarAffine2x3 table. |
2892 | | pub transform: OffsetMarker<VarAffine2x3, WIDTH_24>, |
2893 | | } |
2894 | | |
2895 | | impl PaintVarTransform { |
2896 | | /// Construct a new `PaintVarTransform` |
2897 | 0 | pub fn new(paint: Paint, transform: VarAffine2x3) -> Self { |
2898 | 0 | Self { |
2899 | 0 | paint: paint.into(), |
2900 | 0 | transform: transform.into(), |
2901 | 0 | } |
2902 | 0 | } |
2903 | | } |
2904 | | |
2905 | | impl FontWrite for PaintVarTransform { |
2906 | | #[allow(clippy::unnecessary_cast)] |
2907 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
2908 | 0 | (13 as u8).write_into(writer); |
2909 | 0 | self.paint.write_into(writer); |
2910 | 0 | self.transform.write_into(writer); |
2911 | 0 | } |
2912 | 0 | fn table_type(&self) -> TableType { |
2913 | 0 | TableType::Named("PaintVarTransform") |
2914 | 0 | } |
2915 | | } |
2916 | | |
2917 | | impl Validate for PaintVarTransform { |
2918 | 0 | fn validate_impl(&self, ctx: &mut ValidationCtx) { |
2919 | 0 | ctx.in_table("PaintVarTransform", |ctx| { |
2920 | 0 | ctx.in_field("paint", |ctx| { |
2921 | 0 | self.paint.validate_impl(ctx); |
2922 | 0 | }); |
2923 | 0 | ctx.in_field("transform", |ctx| { |
2924 | 0 | self.transform.validate_impl(ctx); |
2925 | 0 | }); |
2926 | 0 | }) |
2927 | 0 | } |
2928 | | } |
2929 | | |
2930 | | impl<'a> FromObjRef<read_fonts::tables::colr::PaintVarTransform<'a>> for PaintVarTransform { |
2931 | 0 | fn from_obj_ref(obj: &read_fonts::tables::colr::PaintVarTransform<'a>, _: FontData) -> Self { |
2932 | 0 | PaintVarTransform { |
2933 | 0 | paint: obj.paint().to_owned_table(), |
2934 | 0 | transform: obj.transform().to_owned_table(), |
2935 | 0 | } |
2936 | 0 | } |
2937 | | } |
2938 | | |
2939 | | #[allow(clippy::needless_lifetimes)] |
2940 | | impl<'a> FromTableRef<read_fonts::tables::colr::PaintVarTransform<'a>> for PaintVarTransform {} |
2941 | | |
2942 | | impl ReadArgs for PaintVarTransform { |
2943 | | type Args = (); |
2944 | | } |
2945 | | |
2946 | | impl<'a> FontRead<'a> for PaintVarTransform { |
2947 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
2948 | 0 | <read_fonts::tables::colr::PaintVarTransform as FontRead>::read(data) |
2949 | 0 | .map(|x| x.to_owned_table()) |
2950 | 0 | } |
2951 | | } |
2952 | | |
2953 | | /// [Affine2x3](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-12-and-13-painttransform-paintvartransform) record |
2954 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
2955 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
2956 | | pub struct Affine2x3 { |
2957 | | /// x-component of transformed x-basis vector. |
2958 | | pub xx: Fixed, |
2959 | | /// y-component of transformed x-basis vector. |
2960 | | pub yx: Fixed, |
2961 | | /// x-component of transformed y-basis vector. |
2962 | | pub xy: Fixed, |
2963 | | /// y-component of transformed y-basis vector. |
2964 | | pub yy: Fixed, |
2965 | | /// Translation in x direction. |
2966 | | pub dx: Fixed, |
2967 | | /// Translation in y direction. |
2968 | | pub dy: Fixed, |
2969 | | } |
2970 | | |
2971 | | impl Affine2x3 { |
2972 | | /// Construct a new `Affine2x3` |
2973 | 0 | pub fn new(xx: Fixed, yx: Fixed, xy: Fixed, yy: Fixed, dx: Fixed, dy: Fixed) -> Self { |
2974 | 0 | Self { |
2975 | 0 | xx, |
2976 | 0 | yx, |
2977 | 0 | xy, |
2978 | 0 | yy, |
2979 | 0 | dx, |
2980 | 0 | dy, |
2981 | 0 | } |
2982 | 0 | } |
2983 | | } |
2984 | | |
2985 | | impl FontWrite for Affine2x3 { |
2986 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
2987 | 0 | self.xx.write_into(writer); |
2988 | 0 | self.yx.write_into(writer); |
2989 | 0 | self.xy.write_into(writer); |
2990 | 0 | self.yy.write_into(writer); |
2991 | 0 | self.dx.write_into(writer); |
2992 | 0 | self.dy.write_into(writer); |
2993 | 0 | } |
2994 | 0 | fn table_type(&self) -> TableType { |
2995 | 0 | TableType::Named("Affine2x3") |
2996 | 0 | } |
2997 | | } |
2998 | | |
2999 | | impl Validate for Affine2x3 { |
3000 | 0 | fn validate_impl(&self, _ctx: &mut ValidationCtx) {} |
3001 | | } |
3002 | | |
3003 | | impl<'a> FromObjRef<read_fonts::tables::colr::Affine2x3<'a>> for Affine2x3 { |
3004 | 0 | fn from_obj_ref(obj: &read_fonts::tables::colr::Affine2x3<'a>, _: FontData) -> Self { |
3005 | 0 | Affine2x3 { |
3006 | 0 | xx: obj.xx(), |
3007 | 0 | yx: obj.yx(), |
3008 | 0 | xy: obj.xy(), |
3009 | 0 | yy: obj.yy(), |
3010 | 0 | dx: obj.dx(), |
3011 | 0 | dy: obj.dy(), |
3012 | 0 | } |
3013 | 0 | } |
3014 | | } |
3015 | | |
3016 | | #[allow(clippy::needless_lifetimes)] |
3017 | | impl<'a> FromTableRef<read_fonts::tables::colr::Affine2x3<'a>> for Affine2x3 {} |
3018 | | |
3019 | | impl ReadArgs for Affine2x3 { |
3020 | | type Args = (); |
3021 | | } |
3022 | | |
3023 | | impl<'a> FontRead<'a> for Affine2x3 { |
3024 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
3025 | 0 | <read_fonts::tables::colr::Affine2x3 as FontRead>::read(data).map(|x| x.to_owned_table()) |
3026 | 0 | } |
3027 | | } |
3028 | | |
3029 | | /// [VarAffine2x3](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-12-and-13-painttransform-paintvartransform) record |
3030 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
3031 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
3032 | | pub struct VarAffine2x3 { |
3033 | | /// x-component of transformed x-basis vector. For variation, use |
3034 | | /// varIndexBase + 0. |
3035 | | pub xx: Fixed, |
3036 | | /// y-component of transformed x-basis vector. For variation, use |
3037 | | /// varIndexBase + 1. |
3038 | | pub yx: Fixed, |
3039 | | /// x-component of transformed y-basis vector. For variation, use |
3040 | | /// varIndexBase + 2. |
3041 | | pub xy: Fixed, |
3042 | | /// y-component of transformed y-basis vector. For variation, use |
3043 | | /// varIndexBase + 3. |
3044 | | pub yy: Fixed, |
3045 | | /// Translation in x direction. For variation, use varIndexBase + 4. |
3046 | | pub dx: Fixed, |
3047 | | /// Translation in y direction. For variation, use varIndexBase + 5. |
3048 | | pub dy: Fixed, |
3049 | | /// Base index into DeltaSetIndexMap. |
3050 | | pub var_index_base: u32, |
3051 | | } |
3052 | | |
3053 | | impl VarAffine2x3 { |
3054 | | /// Construct a new `VarAffine2x3` |
3055 | 0 | pub fn new( |
3056 | 0 | xx: Fixed, |
3057 | 0 | yx: Fixed, |
3058 | 0 | xy: Fixed, |
3059 | 0 | yy: Fixed, |
3060 | 0 | dx: Fixed, |
3061 | 0 | dy: Fixed, |
3062 | 0 | var_index_base: u32, |
3063 | 0 | ) -> Self { |
3064 | 0 | Self { |
3065 | 0 | xx, |
3066 | 0 | yx, |
3067 | 0 | xy, |
3068 | 0 | yy, |
3069 | 0 | dx, |
3070 | 0 | dy, |
3071 | 0 | var_index_base, |
3072 | 0 | } |
3073 | 0 | } |
3074 | | } |
3075 | | |
3076 | | impl FontWrite for VarAffine2x3 { |
3077 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
3078 | 0 | self.xx.write_into(writer); |
3079 | 0 | self.yx.write_into(writer); |
3080 | 0 | self.xy.write_into(writer); |
3081 | 0 | self.yy.write_into(writer); |
3082 | 0 | self.dx.write_into(writer); |
3083 | 0 | self.dy.write_into(writer); |
3084 | 0 | self.var_index_base.write_into(writer); |
3085 | 0 | } |
3086 | 0 | fn table_type(&self) -> TableType { |
3087 | 0 | TableType::Named("VarAffine2x3") |
3088 | 0 | } |
3089 | | } |
3090 | | |
3091 | | impl Validate for VarAffine2x3 { |
3092 | 0 | fn validate_impl(&self, _ctx: &mut ValidationCtx) {} |
3093 | | } |
3094 | | |
3095 | | impl<'a> FromObjRef<read_fonts::tables::colr::VarAffine2x3<'a>> for VarAffine2x3 { |
3096 | 0 | fn from_obj_ref(obj: &read_fonts::tables::colr::VarAffine2x3<'a>, _: FontData) -> Self { |
3097 | 0 | VarAffine2x3 { |
3098 | 0 | xx: obj.xx(), |
3099 | 0 | yx: obj.yx(), |
3100 | 0 | xy: obj.xy(), |
3101 | 0 | yy: obj.yy(), |
3102 | 0 | dx: obj.dx(), |
3103 | 0 | dy: obj.dy(), |
3104 | 0 | var_index_base: obj.var_index_base(), |
3105 | 0 | } |
3106 | 0 | } |
3107 | | } |
3108 | | |
3109 | | #[allow(clippy::needless_lifetimes)] |
3110 | | impl<'a> FromTableRef<read_fonts::tables::colr::VarAffine2x3<'a>> for VarAffine2x3 {} |
3111 | | |
3112 | | impl ReadArgs for VarAffine2x3 { |
3113 | | type Args = (); |
3114 | | } |
3115 | | |
3116 | | impl<'a> FontRead<'a> for VarAffine2x3 { |
3117 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
3118 | 0 | <read_fonts::tables::colr::VarAffine2x3 as FontRead>::read(data).map(|x| x.to_owned_table()) |
3119 | 0 | } |
3120 | | } |
3121 | | |
3122 | | /// [PaintTranslate](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-14-and-15-painttranslate-paintvartranslate) table |
3123 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
3124 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
3125 | | pub struct PaintTranslate { |
3126 | | /// Offset to a Paint subtable. |
3127 | | pub paint: OffsetMarker<Paint, WIDTH_24>, |
3128 | | /// Translation in x direction. |
3129 | | pub dx: FWord, |
3130 | | /// Translation in y direction. |
3131 | | pub dy: FWord, |
3132 | | } |
3133 | | |
3134 | | impl PaintTranslate { |
3135 | | /// Construct a new `PaintTranslate` |
3136 | 0 | pub fn new(paint: Paint, dx: FWord, dy: FWord) -> Self { |
3137 | 0 | Self { |
3138 | 0 | paint: paint.into(), |
3139 | 0 | dx, |
3140 | 0 | dy, |
3141 | 0 | } |
3142 | 0 | } |
3143 | | } |
3144 | | |
3145 | | impl FontWrite for PaintTranslate { |
3146 | | #[allow(clippy::unnecessary_cast)] |
3147 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
3148 | 0 | (14 as u8).write_into(writer); |
3149 | 0 | self.paint.write_into(writer); |
3150 | 0 | self.dx.write_into(writer); |
3151 | 0 | self.dy.write_into(writer); |
3152 | 0 | } |
3153 | 0 | fn table_type(&self) -> TableType { |
3154 | 0 | TableType::Named("PaintTranslate") |
3155 | 0 | } |
3156 | | } |
3157 | | |
3158 | | impl Validate for PaintTranslate { |
3159 | 0 | fn validate_impl(&self, ctx: &mut ValidationCtx) { |
3160 | 0 | ctx.in_table("PaintTranslate", |ctx| { |
3161 | 0 | ctx.in_field("paint", |ctx| { |
3162 | 0 | self.paint.validate_impl(ctx); |
3163 | 0 | }); |
3164 | 0 | }) |
3165 | 0 | } |
3166 | | } |
3167 | | |
3168 | | impl<'a> FromObjRef<read_fonts::tables::colr::PaintTranslate<'a>> for PaintTranslate { |
3169 | 0 | fn from_obj_ref(obj: &read_fonts::tables::colr::PaintTranslate<'a>, _: FontData) -> Self { |
3170 | 0 | PaintTranslate { |
3171 | 0 | paint: obj.paint().to_owned_table(), |
3172 | 0 | dx: obj.dx(), |
3173 | 0 | dy: obj.dy(), |
3174 | 0 | } |
3175 | 0 | } |
3176 | | } |
3177 | | |
3178 | | #[allow(clippy::needless_lifetimes)] |
3179 | | impl<'a> FromTableRef<read_fonts::tables::colr::PaintTranslate<'a>> for PaintTranslate {} |
3180 | | |
3181 | | impl ReadArgs for PaintTranslate { |
3182 | | type Args = (); |
3183 | | } |
3184 | | |
3185 | | impl<'a> FontRead<'a> for PaintTranslate { |
3186 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
3187 | 0 | <read_fonts::tables::colr::PaintTranslate as FontRead>::read(data) |
3188 | 0 | .map(|x| x.to_owned_table()) |
3189 | 0 | } |
3190 | | } |
3191 | | |
3192 | | /// [PaintVarTranslate](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-14-and-15-painttranslate-paintvartranslate) table |
3193 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
3194 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
3195 | | pub struct PaintVarTranslate { |
3196 | | /// Offset to a Paint subtable. |
3197 | | pub paint: OffsetMarker<Paint, WIDTH_24>, |
3198 | | /// Translation in x direction. For variation, use varIndexBase + 0. |
3199 | | pub dx: FWord, |
3200 | | /// Translation in y direction. For variation, use varIndexBase + 1. |
3201 | | pub dy: FWord, |
3202 | | /// Base index into DeltaSetIndexMap. |
3203 | | pub var_index_base: u32, |
3204 | | } |
3205 | | |
3206 | | impl PaintVarTranslate { |
3207 | | /// Construct a new `PaintVarTranslate` |
3208 | 0 | pub fn new(paint: Paint, dx: FWord, dy: FWord, var_index_base: u32) -> Self { |
3209 | 0 | Self { |
3210 | 0 | paint: paint.into(), |
3211 | 0 | dx, |
3212 | 0 | dy, |
3213 | 0 | var_index_base, |
3214 | 0 | } |
3215 | 0 | } |
3216 | | } |
3217 | | |
3218 | | impl FontWrite for PaintVarTranslate { |
3219 | | #[allow(clippy::unnecessary_cast)] |
3220 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
3221 | 0 | (15 as u8).write_into(writer); |
3222 | 0 | self.paint.write_into(writer); |
3223 | 0 | self.dx.write_into(writer); |
3224 | 0 | self.dy.write_into(writer); |
3225 | 0 | self.var_index_base.write_into(writer); |
3226 | 0 | } |
3227 | 0 | fn table_type(&self) -> TableType { |
3228 | 0 | TableType::Named("PaintVarTranslate") |
3229 | 0 | } |
3230 | | } |
3231 | | |
3232 | | impl Validate for PaintVarTranslate { |
3233 | 0 | fn validate_impl(&self, ctx: &mut ValidationCtx) { |
3234 | 0 | ctx.in_table("PaintVarTranslate", |ctx| { |
3235 | 0 | ctx.in_field("paint", |ctx| { |
3236 | 0 | self.paint.validate_impl(ctx); |
3237 | 0 | }); |
3238 | 0 | }) |
3239 | 0 | } |
3240 | | } |
3241 | | |
3242 | | impl<'a> FromObjRef<read_fonts::tables::colr::PaintVarTranslate<'a>> for PaintVarTranslate { |
3243 | 0 | fn from_obj_ref(obj: &read_fonts::tables::colr::PaintVarTranslate<'a>, _: FontData) -> Self { |
3244 | 0 | PaintVarTranslate { |
3245 | 0 | paint: obj.paint().to_owned_table(), |
3246 | 0 | dx: obj.dx(), |
3247 | 0 | dy: obj.dy(), |
3248 | 0 | var_index_base: obj.var_index_base(), |
3249 | 0 | } |
3250 | 0 | } |
3251 | | } |
3252 | | |
3253 | | #[allow(clippy::needless_lifetimes)] |
3254 | | impl<'a> FromTableRef<read_fonts::tables::colr::PaintVarTranslate<'a>> for PaintVarTranslate {} |
3255 | | |
3256 | | impl ReadArgs for PaintVarTranslate { |
3257 | | type Args = (); |
3258 | | } |
3259 | | |
3260 | | impl<'a> FontRead<'a> for PaintVarTranslate { |
3261 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
3262 | 0 | <read_fonts::tables::colr::PaintVarTranslate as FontRead>::read(data) |
3263 | 0 | .map(|x| x.to_owned_table()) |
3264 | 0 | } |
3265 | | } |
3266 | | |
3267 | | /// [PaintScale](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-16-to-23-paintscale-and-variant-scaling-formats) table |
3268 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
3269 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
3270 | | pub struct PaintScale { |
3271 | | /// Offset to a Paint subtable. |
3272 | | pub paint: OffsetMarker<Paint, WIDTH_24>, |
3273 | | /// Scale factor in x direction. |
3274 | | pub scale_x: F2Dot14, |
3275 | | /// Scale factor in y direction. |
3276 | | pub scale_y: F2Dot14, |
3277 | | } |
3278 | | |
3279 | | impl PaintScale { |
3280 | | /// Construct a new `PaintScale` |
3281 | 0 | pub fn new(paint: Paint, scale_x: F2Dot14, scale_y: F2Dot14) -> Self { |
3282 | 0 | Self { |
3283 | 0 | paint: paint.into(), |
3284 | 0 | scale_x, |
3285 | 0 | scale_y, |
3286 | 0 | } |
3287 | 0 | } |
3288 | | } |
3289 | | |
3290 | | impl FontWrite for PaintScale { |
3291 | | #[allow(clippy::unnecessary_cast)] |
3292 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
3293 | 0 | (16 as u8).write_into(writer); |
3294 | 0 | self.paint.write_into(writer); |
3295 | 0 | self.scale_x.write_into(writer); |
3296 | 0 | self.scale_y.write_into(writer); |
3297 | 0 | } |
3298 | 0 | fn table_type(&self) -> TableType { |
3299 | 0 | TableType::Named("PaintScale") |
3300 | 0 | } |
3301 | | } |
3302 | | |
3303 | | impl Validate for PaintScale { |
3304 | 0 | fn validate_impl(&self, ctx: &mut ValidationCtx) { |
3305 | 0 | ctx.in_table("PaintScale", |ctx| { |
3306 | 0 | ctx.in_field("paint", |ctx| { |
3307 | 0 | self.paint.validate_impl(ctx); |
3308 | 0 | }); |
3309 | 0 | }) |
3310 | 0 | } |
3311 | | } |
3312 | | |
3313 | | impl<'a> FromObjRef<read_fonts::tables::colr::PaintScale<'a>> for PaintScale { |
3314 | 0 | fn from_obj_ref(obj: &read_fonts::tables::colr::PaintScale<'a>, _: FontData) -> Self { |
3315 | 0 | PaintScale { |
3316 | 0 | paint: obj.paint().to_owned_table(), |
3317 | 0 | scale_x: obj.scale_x(), |
3318 | 0 | scale_y: obj.scale_y(), |
3319 | 0 | } |
3320 | 0 | } |
3321 | | } |
3322 | | |
3323 | | #[allow(clippy::needless_lifetimes)] |
3324 | | impl<'a> FromTableRef<read_fonts::tables::colr::PaintScale<'a>> for PaintScale {} |
3325 | | |
3326 | | impl ReadArgs for PaintScale { |
3327 | | type Args = (); |
3328 | | } |
3329 | | |
3330 | | impl<'a> FontRead<'a> for PaintScale { |
3331 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
3332 | 0 | <read_fonts::tables::colr::PaintScale as FontRead>::read(data).map(|x| x.to_owned_table()) |
3333 | 0 | } |
3334 | | } |
3335 | | |
3336 | | /// [PaintVarScale](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-16-to-23-paintscale-and-variant-scaling-formats) table |
3337 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
3338 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
3339 | | pub struct PaintVarScale { |
3340 | | /// Offset to a Paint subtable. |
3341 | | pub paint: OffsetMarker<Paint, WIDTH_24>, |
3342 | | /// Scale factor in x direction. For variation, use varIndexBase + |
3343 | | /// 0. |
3344 | | pub scale_x: F2Dot14, |
3345 | | /// Scale factor in y direction. For variation, use varIndexBase + |
3346 | | /// 1. |
3347 | | pub scale_y: F2Dot14, |
3348 | | /// Base index into DeltaSetIndexMap. |
3349 | | pub var_index_base: u32, |
3350 | | } |
3351 | | |
3352 | | impl PaintVarScale { |
3353 | | /// Construct a new `PaintVarScale` |
3354 | 0 | pub fn new(paint: Paint, scale_x: F2Dot14, scale_y: F2Dot14, var_index_base: u32) -> Self { |
3355 | 0 | Self { |
3356 | 0 | paint: paint.into(), |
3357 | 0 | scale_x, |
3358 | 0 | scale_y, |
3359 | 0 | var_index_base, |
3360 | 0 | } |
3361 | 0 | } |
3362 | | } |
3363 | | |
3364 | | impl FontWrite for PaintVarScale { |
3365 | | #[allow(clippy::unnecessary_cast)] |
3366 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
3367 | 0 | (17 as u8).write_into(writer); |
3368 | 0 | self.paint.write_into(writer); |
3369 | 0 | self.scale_x.write_into(writer); |
3370 | 0 | self.scale_y.write_into(writer); |
3371 | 0 | self.var_index_base.write_into(writer); |
3372 | 0 | } |
3373 | 0 | fn table_type(&self) -> TableType { |
3374 | 0 | TableType::Named("PaintVarScale") |
3375 | 0 | } |
3376 | | } |
3377 | | |
3378 | | impl Validate for PaintVarScale { |
3379 | 0 | fn validate_impl(&self, ctx: &mut ValidationCtx) { |
3380 | 0 | ctx.in_table("PaintVarScale", |ctx| { |
3381 | 0 | ctx.in_field("paint", |ctx| { |
3382 | 0 | self.paint.validate_impl(ctx); |
3383 | 0 | }); |
3384 | 0 | }) |
3385 | 0 | } |
3386 | | } |
3387 | | |
3388 | | impl<'a> FromObjRef<read_fonts::tables::colr::PaintVarScale<'a>> for PaintVarScale { |
3389 | 0 | fn from_obj_ref(obj: &read_fonts::tables::colr::PaintVarScale<'a>, _: FontData) -> Self { |
3390 | 0 | PaintVarScale { |
3391 | 0 | paint: obj.paint().to_owned_table(), |
3392 | 0 | scale_x: obj.scale_x(), |
3393 | 0 | scale_y: obj.scale_y(), |
3394 | 0 | var_index_base: obj.var_index_base(), |
3395 | 0 | } |
3396 | 0 | } |
3397 | | } |
3398 | | |
3399 | | #[allow(clippy::needless_lifetimes)] |
3400 | | impl<'a> FromTableRef<read_fonts::tables::colr::PaintVarScale<'a>> for PaintVarScale {} |
3401 | | |
3402 | | impl ReadArgs for PaintVarScale { |
3403 | | type Args = (); |
3404 | | } |
3405 | | |
3406 | | impl<'a> FontRead<'a> for PaintVarScale { |
3407 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
3408 | 0 | <read_fonts::tables::colr::PaintVarScale as FontRead>::read(data) |
3409 | 0 | .map(|x| x.to_owned_table()) |
3410 | 0 | } |
3411 | | } |
3412 | | |
3413 | | /// [PaintScaleAroundCenter](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-16-to-23-paintscale-and-variant-scaling-formats) table |
3414 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
3415 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
3416 | | pub struct PaintScaleAroundCenter { |
3417 | | /// Offset to a Paint subtable. |
3418 | | pub paint: OffsetMarker<Paint, WIDTH_24>, |
3419 | | /// Scale factor in x direction. |
3420 | | pub scale_x: F2Dot14, |
3421 | | /// Scale factor in y direction. |
3422 | | pub scale_y: F2Dot14, |
3423 | | /// x coordinate for the center of scaling. |
3424 | | pub center_x: FWord, |
3425 | | /// y coordinate for the center of scaling. |
3426 | | pub center_y: FWord, |
3427 | | } |
3428 | | |
3429 | | impl PaintScaleAroundCenter { |
3430 | | /// Construct a new `PaintScaleAroundCenter` |
3431 | 0 | pub fn new( |
3432 | 0 | paint: Paint, |
3433 | 0 | scale_x: F2Dot14, |
3434 | 0 | scale_y: F2Dot14, |
3435 | 0 | center_x: FWord, |
3436 | 0 | center_y: FWord, |
3437 | 0 | ) -> Self { |
3438 | 0 | Self { |
3439 | 0 | paint: paint.into(), |
3440 | 0 | scale_x, |
3441 | 0 | scale_y, |
3442 | 0 | center_x, |
3443 | 0 | center_y, |
3444 | 0 | } |
3445 | 0 | } |
3446 | | } |
3447 | | |
3448 | | impl FontWrite for PaintScaleAroundCenter { |
3449 | | #[allow(clippy::unnecessary_cast)] |
3450 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
3451 | 0 | (18 as u8).write_into(writer); |
3452 | 0 | self.paint.write_into(writer); |
3453 | 0 | self.scale_x.write_into(writer); |
3454 | 0 | self.scale_y.write_into(writer); |
3455 | 0 | self.center_x.write_into(writer); |
3456 | 0 | self.center_y.write_into(writer); |
3457 | 0 | } |
3458 | 0 | fn table_type(&self) -> TableType { |
3459 | 0 | TableType::Named("PaintScaleAroundCenter") |
3460 | 0 | } |
3461 | | } |
3462 | | |
3463 | | impl Validate for PaintScaleAroundCenter { |
3464 | 0 | fn validate_impl(&self, ctx: &mut ValidationCtx) { |
3465 | 0 | ctx.in_table("PaintScaleAroundCenter", |ctx| { |
3466 | 0 | ctx.in_field("paint", |ctx| { |
3467 | 0 | self.paint.validate_impl(ctx); |
3468 | 0 | }); |
3469 | 0 | }) |
3470 | 0 | } |
3471 | | } |
3472 | | |
3473 | | impl<'a> FromObjRef<read_fonts::tables::colr::PaintScaleAroundCenter<'a>> |
3474 | | for PaintScaleAroundCenter |
3475 | | { |
3476 | 0 | fn from_obj_ref( |
3477 | 0 | obj: &read_fonts::tables::colr::PaintScaleAroundCenter<'a>, |
3478 | 0 | _: FontData, |
3479 | 0 | ) -> Self { |
3480 | 0 | PaintScaleAroundCenter { |
3481 | 0 | paint: obj.paint().to_owned_table(), |
3482 | 0 | scale_x: obj.scale_x(), |
3483 | 0 | scale_y: obj.scale_y(), |
3484 | 0 | center_x: obj.center_x(), |
3485 | 0 | center_y: obj.center_y(), |
3486 | 0 | } |
3487 | 0 | } |
3488 | | } |
3489 | | |
3490 | | #[allow(clippy::needless_lifetimes)] |
3491 | | impl<'a> FromTableRef<read_fonts::tables::colr::PaintScaleAroundCenter<'a>> |
3492 | | for PaintScaleAroundCenter |
3493 | | { |
3494 | | } |
3495 | | |
3496 | | impl ReadArgs for PaintScaleAroundCenter { |
3497 | | type Args = (); |
3498 | | } |
3499 | | |
3500 | | impl<'a> FontRead<'a> for PaintScaleAroundCenter { |
3501 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
3502 | 0 | <read_fonts::tables::colr::PaintScaleAroundCenter as FontRead>::read(data) |
3503 | 0 | .map(|x| x.to_owned_table()) |
3504 | 0 | } |
3505 | | } |
3506 | | |
3507 | | /// [PaintVarScaleAroundCenter](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-16-to-23-paintscale-and-variant-scaling-formats) table |
3508 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
3509 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
3510 | | pub struct PaintVarScaleAroundCenter { |
3511 | | /// Offset to a Paint subtable. |
3512 | | pub paint: OffsetMarker<Paint, WIDTH_24>, |
3513 | | /// Scale factor in x direction. For variation, use varIndexBase + |
3514 | | /// 0. |
3515 | | pub scale_x: F2Dot14, |
3516 | | /// Scale factor in y direction. For variation, use varIndexBase + |
3517 | | /// 1. |
3518 | | pub scale_y: F2Dot14, |
3519 | | /// x coordinate for the center of scaling. For variation, use |
3520 | | /// varIndexBase + 2. |
3521 | | pub center_x: FWord, |
3522 | | /// y coordinate for the center of scaling. For variation, use |
3523 | | /// varIndexBase + 3. |
3524 | | pub center_y: FWord, |
3525 | | /// Base index into DeltaSetIndexMap. |
3526 | | pub var_index_base: u32, |
3527 | | } |
3528 | | |
3529 | | impl PaintVarScaleAroundCenter { |
3530 | | /// Construct a new `PaintVarScaleAroundCenter` |
3531 | 0 | pub fn new( |
3532 | 0 | paint: Paint, |
3533 | 0 | scale_x: F2Dot14, |
3534 | 0 | scale_y: F2Dot14, |
3535 | 0 | center_x: FWord, |
3536 | 0 | center_y: FWord, |
3537 | 0 | var_index_base: u32, |
3538 | 0 | ) -> Self { |
3539 | 0 | Self { |
3540 | 0 | paint: paint.into(), |
3541 | 0 | scale_x, |
3542 | 0 | scale_y, |
3543 | 0 | center_x, |
3544 | 0 | center_y, |
3545 | 0 | var_index_base, |
3546 | 0 | } |
3547 | 0 | } |
3548 | | } |
3549 | | |
3550 | | impl FontWrite for PaintVarScaleAroundCenter { |
3551 | | #[allow(clippy::unnecessary_cast)] |
3552 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
3553 | 0 | (19 as u8).write_into(writer); |
3554 | 0 | self.paint.write_into(writer); |
3555 | 0 | self.scale_x.write_into(writer); |
3556 | 0 | self.scale_y.write_into(writer); |
3557 | 0 | self.center_x.write_into(writer); |
3558 | 0 | self.center_y.write_into(writer); |
3559 | 0 | self.var_index_base.write_into(writer); |
3560 | 0 | } |
3561 | 0 | fn table_type(&self) -> TableType { |
3562 | 0 | TableType::Named("PaintVarScaleAroundCenter") |
3563 | 0 | } |
3564 | | } |
3565 | | |
3566 | | impl Validate for PaintVarScaleAroundCenter { |
3567 | 0 | fn validate_impl(&self, ctx: &mut ValidationCtx) { |
3568 | 0 | ctx.in_table("PaintVarScaleAroundCenter", |ctx| { |
3569 | 0 | ctx.in_field("paint", |ctx| { |
3570 | 0 | self.paint.validate_impl(ctx); |
3571 | 0 | }); |
3572 | 0 | }) |
3573 | 0 | } |
3574 | | } |
3575 | | |
3576 | | impl<'a> FromObjRef<read_fonts::tables::colr::PaintVarScaleAroundCenter<'a>> |
3577 | | for PaintVarScaleAroundCenter |
3578 | | { |
3579 | 0 | fn from_obj_ref( |
3580 | 0 | obj: &read_fonts::tables::colr::PaintVarScaleAroundCenter<'a>, |
3581 | 0 | _: FontData, |
3582 | 0 | ) -> Self { |
3583 | 0 | PaintVarScaleAroundCenter { |
3584 | 0 | paint: obj.paint().to_owned_table(), |
3585 | 0 | scale_x: obj.scale_x(), |
3586 | 0 | scale_y: obj.scale_y(), |
3587 | 0 | center_x: obj.center_x(), |
3588 | 0 | center_y: obj.center_y(), |
3589 | 0 | var_index_base: obj.var_index_base(), |
3590 | 0 | } |
3591 | 0 | } |
3592 | | } |
3593 | | |
3594 | | #[allow(clippy::needless_lifetimes)] |
3595 | | impl<'a> FromTableRef<read_fonts::tables::colr::PaintVarScaleAroundCenter<'a>> |
3596 | | for PaintVarScaleAroundCenter |
3597 | | { |
3598 | | } |
3599 | | |
3600 | | impl ReadArgs for PaintVarScaleAroundCenter { |
3601 | | type Args = (); |
3602 | | } |
3603 | | |
3604 | | impl<'a> FontRead<'a> for PaintVarScaleAroundCenter { |
3605 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
3606 | 0 | <read_fonts::tables::colr::PaintVarScaleAroundCenter as FontRead>::read(data) |
3607 | 0 | .map(|x| x.to_owned_table()) |
3608 | 0 | } |
3609 | | } |
3610 | | |
3611 | | /// [PaintScaleUniform](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-16-to-23-paintscale-and-variant-scaling-formats) table |
3612 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
3613 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
3614 | | pub struct PaintScaleUniform { |
3615 | | /// Offset to a Paint subtable. |
3616 | | pub paint: OffsetMarker<Paint, WIDTH_24>, |
3617 | | /// Scale factor in x and y directions. |
3618 | | pub scale: F2Dot14, |
3619 | | } |
3620 | | |
3621 | | impl PaintScaleUniform { |
3622 | | /// Construct a new `PaintScaleUniform` |
3623 | 0 | pub fn new(paint: Paint, scale: F2Dot14) -> Self { |
3624 | 0 | Self { |
3625 | 0 | paint: paint.into(), |
3626 | 0 | scale, |
3627 | 0 | } |
3628 | 0 | } |
3629 | | } |
3630 | | |
3631 | | impl FontWrite for PaintScaleUniform { |
3632 | | #[allow(clippy::unnecessary_cast)] |
3633 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
3634 | 0 | (20 as u8).write_into(writer); |
3635 | 0 | self.paint.write_into(writer); |
3636 | 0 | self.scale.write_into(writer); |
3637 | 0 | } |
3638 | 0 | fn table_type(&self) -> TableType { |
3639 | 0 | TableType::Named("PaintScaleUniform") |
3640 | 0 | } |
3641 | | } |
3642 | | |
3643 | | impl Validate for PaintScaleUniform { |
3644 | 0 | fn validate_impl(&self, ctx: &mut ValidationCtx) { |
3645 | 0 | ctx.in_table("PaintScaleUniform", |ctx| { |
3646 | 0 | ctx.in_field("paint", |ctx| { |
3647 | 0 | self.paint.validate_impl(ctx); |
3648 | 0 | }); |
3649 | 0 | }) |
3650 | 0 | } |
3651 | | } |
3652 | | |
3653 | | impl<'a> FromObjRef<read_fonts::tables::colr::PaintScaleUniform<'a>> for PaintScaleUniform { |
3654 | 0 | fn from_obj_ref(obj: &read_fonts::tables::colr::PaintScaleUniform<'a>, _: FontData) -> Self { |
3655 | 0 | PaintScaleUniform { |
3656 | 0 | paint: obj.paint().to_owned_table(), |
3657 | 0 | scale: obj.scale(), |
3658 | 0 | } |
3659 | 0 | } |
3660 | | } |
3661 | | |
3662 | | #[allow(clippy::needless_lifetimes)] |
3663 | | impl<'a> FromTableRef<read_fonts::tables::colr::PaintScaleUniform<'a>> for PaintScaleUniform {} |
3664 | | |
3665 | | impl ReadArgs for PaintScaleUniform { |
3666 | | type Args = (); |
3667 | | } |
3668 | | |
3669 | | impl<'a> FontRead<'a> for PaintScaleUniform { |
3670 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
3671 | 0 | <read_fonts::tables::colr::PaintScaleUniform as FontRead>::read(data) |
3672 | 0 | .map(|x| x.to_owned_table()) |
3673 | 0 | } |
3674 | | } |
3675 | | |
3676 | | /// [PaintVarScaleUniform](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-16-to-23-paintscale-and-variant-scaling-formats) table |
3677 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
3678 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
3679 | | pub struct PaintVarScaleUniform { |
3680 | | /// Offset to a Paint subtable. |
3681 | | pub paint: OffsetMarker<Paint, WIDTH_24>, |
3682 | | /// Scale factor in x and y directions. For variation, use |
3683 | | /// varIndexBase + 0. |
3684 | | pub scale: F2Dot14, |
3685 | | /// Base index into DeltaSetIndexMap. |
3686 | | pub var_index_base: u32, |
3687 | | } |
3688 | | |
3689 | | impl PaintVarScaleUniform { |
3690 | | /// Construct a new `PaintVarScaleUniform` |
3691 | 0 | pub fn new(paint: Paint, scale: F2Dot14, var_index_base: u32) -> Self { |
3692 | 0 | Self { |
3693 | 0 | paint: paint.into(), |
3694 | 0 | scale, |
3695 | 0 | var_index_base, |
3696 | 0 | } |
3697 | 0 | } |
3698 | | } |
3699 | | |
3700 | | impl FontWrite for PaintVarScaleUniform { |
3701 | | #[allow(clippy::unnecessary_cast)] |
3702 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
3703 | 0 | (21 as u8).write_into(writer); |
3704 | 0 | self.paint.write_into(writer); |
3705 | 0 | self.scale.write_into(writer); |
3706 | 0 | self.var_index_base.write_into(writer); |
3707 | 0 | } |
3708 | 0 | fn table_type(&self) -> TableType { |
3709 | 0 | TableType::Named("PaintVarScaleUniform") |
3710 | 0 | } |
3711 | | } |
3712 | | |
3713 | | impl Validate for PaintVarScaleUniform { |
3714 | 0 | fn validate_impl(&self, ctx: &mut ValidationCtx) { |
3715 | 0 | ctx.in_table("PaintVarScaleUniform", |ctx| { |
3716 | 0 | ctx.in_field("paint", |ctx| { |
3717 | 0 | self.paint.validate_impl(ctx); |
3718 | 0 | }); |
3719 | 0 | }) |
3720 | 0 | } |
3721 | | } |
3722 | | |
3723 | | impl<'a> FromObjRef<read_fonts::tables::colr::PaintVarScaleUniform<'a>> for PaintVarScaleUniform { |
3724 | 0 | fn from_obj_ref(obj: &read_fonts::tables::colr::PaintVarScaleUniform<'a>, _: FontData) -> Self { |
3725 | 0 | PaintVarScaleUniform { |
3726 | 0 | paint: obj.paint().to_owned_table(), |
3727 | 0 | scale: obj.scale(), |
3728 | 0 | var_index_base: obj.var_index_base(), |
3729 | 0 | } |
3730 | 0 | } |
3731 | | } |
3732 | | |
3733 | | #[allow(clippy::needless_lifetimes)] |
3734 | | impl<'a> FromTableRef<read_fonts::tables::colr::PaintVarScaleUniform<'a>> for PaintVarScaleUniform {} |
3735 | | |
3736 | | impl ReadArgs for PaintVarScaleUniform { |
3737 | | type Args = (); |
3738 | | } |
3739 | | |
3740 | | impl<'a> FontRead<'a> for PaintVarScaleUniform { |
3741 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
3742 | 0 | <read_fonts::tables::colr::PaintVarScaleUniform as FontRead>::read(data) |
3743 | 0 | .map(|x| x.to_owned_table()) |
3744 | 0 | } |
3745 | | } |
3746 | | |
3747 | | /// [PaintScaleUniformAroundCenter](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-16-to-23-paintscale-and-variant-scaling-formats) table |
3748 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
3749 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
3750 | | pub struct PaintScaleUniformAroundCenter { |
3751 | | /// Offset to a Paint subtable. |
3752 | | pub paint: OffsetMarker<Paint, WIDTH_24>, |
3753 | | /// Scale factor in x and y directions. |
3754 | | pub scale: F2Dot14, |
3755 | | /// x coordinate for the center of scaling. |
3756 | | pub center_x: FWord, |
3757 | | /// y coordinate for the center of scaling. |
3758 | | pub center_y: FWord, |
3759 | | } |
3760 | | |
3761 | | impl PaintScaleUniformAroundCenter { |
3762 | | /// Construct a new `PaintScaleUniformAroundCenter` |
3763 | 0 | pub fn new(paint: Paint, scale: F2Dot14, center_x: FWord, center_y: FWord) -> Self { |
3764 | 0 | Self { |
3765 | 0 | paint: paint.into(), |
3766 | 0 | scale, |
3767 | 0 | center_x, |
3768 | 0 | center_y, |
3769 | 0 | } |
3770 | 0 | } |
3771 | | } |
3772 | | |
3773 | | impl FontWrite for PaintScaleUniformAroundCenter { |
3774 | | #[allow(clippy::unnecessary_cast)] |
3775 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
3776 | 0 | (22 as u8).write_into(writer); |
3777 | 0 | self.paint.write_into(writer); |
3778 | 0 | self.scale.write_into(writer); |
3779 | 0 | self.center_x.write_into(writer); |
3780 | 0 | self.center_y.write_into(writer); |
3781 | 0 | } |
3782 | 0 | fn table_type(&self) -> TableType { |
3783 | 0 | TableType::Named("PaintScaleUniformAroundCenter") |
3784 | 0 | } |
3785 | | } |
3786 | | |
3787 | | impl Validate for PaintScaleUniformAroundCenter { |
3788 | 0 | fn validate_impl(&self, ctx: &mut ValidationCtx) { |
3789 | 0 | ctx.in_table("PaintScaleUniformAroundCenter", |ctx| { |
3790 | 0 | ctx.in_field("paint", |ctx| { |
3791 | 0 | self.paint.validate_impl(ctx); |
3792 | 0 | }); |
3793 | 0 | }) |
3794 | 0 | } |
3795 | | } |
3796 | | |
3797 | | impl<'a> FromObjRef<read_fonts::tables::colr::PaintScaleUniformAroundCenter<'a>> |
3798 | | for PaintScaleUniformAroundCenter |
3799 | | { |
3800 | 0 | fn from_obj_ref( |
3801 | 0 | obj: &read_fonts::tables::colr::PaintScaleUniformAroundCenter<'a>, |
3802 | 0 | _: FontData, |
3803 | 0 | ) -> Self { |
3804 | 0 | PaintScaleUniformAroundCenter { |
3805 | 0 | paint: obj.paint().to_owned_table(), |
3806 | 0 | scale: obj.scale(), |
3807 | 0 | center_x: obj.center_x(), |
3808 | 0 | center_y: obj.center_y(), |
3809 | 0 | } |
3810 | 0 | } |
3811 | | } |
3812 | | |
3813 | | #[allow(clippy::needless_lifetimes)] |
3814 | | impl<'a> FromTableRef<read_fonts::tables::colr::PaintScaleUniformAroundCenter<'a>> |
3815 | | for PaintScaleUniformAroundCenter |
3816 | | { |
3817 | | } |
3818 | | |
3819 | | impl ReadArgs for PaintScaleUniformAroundCenter { |
3820 | | type Args = (); |
3821 | | } |
3822 | | |
3823 | | impl<'a> FontRead<'a> for PaintScaleUniformAroundCenter { |
3824 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
3825 | 0 | <read_fonts::tables::colr::PaintScaleUniformAroundCenter as FontRead>::read(data) |
3826 | 0 | .map(|x| x.to_owned_table()) |
3827 | 0 | } |
3828 | | } |
3829 | | |
3830 | | /// [PaintVarScaleUniformAroundCenter](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-16-to-23-paintscale-and-variant-scaling-formats) table |
3831 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
3832 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
3833 | | pub struct PaintVarScaleUniformAroundCenter { |
3834 | | /// Offset to a Paint subtable. |
3835 | | pub paint: OffsetMarker<Paint, WIDTH_24>, |
3836 | | /// Scale factor in x and y directions. For variation, use |
3837 | | /// varIndexBase + 0. |
3838 | | pub scale: F2Dot14, |
3839 | | /// x coordinate for the center of scaling. For variation, use |
3840 | | /// varIndexBase + 1. |
3841 | | pub center_x: FWord, |
3842 | | /// y coordinate for the center of scaling. For variation, use |
3843 | | /// varIndexBase + 2. |
3844 | | pub center_y: FWord, |
3845 | | /// Base index into DeltaSetIndexMap. |
3846 | | pub var_index_base: u32, |
3847 | | } |
3848 | | |
3849 | | impl PaintVarScaleUniformAroundCenter { |
3850 | | /// Construct a new `PaintVarScaleUniformAroundCenter` |
3851 | 0 | pub fn new( |
3852 | 0 | paint: Paint, |
3853 | 0 | scale: F2Dot14, |
3854 | 0 | center_x: FWord, |
3855 | 0 | center_y: FWord, |
3856 | 0 | var_index_base: u32, |
3857 | 0 | ) -> Self { |
3858 | 0 | Self { |
3859 | 0 | paint: paint.into(), |
3860 | 0 | scale, |
3861 | 0 | center_x, |
3862 | 0 | center_y, |
3863 | 0 | var_index_base, |
3864 | 0 | } |
3865 | 0 | } |
3866 | | } |
3867 | | |
3868 | | impl FontWrite for PaintVarScaleUniformAroundCenter { |
3869 | | #[allow(clippy::unnecessary_cast)] |
3870 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
3871 | 0 | (23 as u8).write_into(writer); |
3872 | 0 | self.paint.write_into(writer); |
3873 | 0 | self.scale.write_into(writer); |
3874 | 0 | self.center_x.write_into(writer); |
3875 | 0 | self.center_y.write_into(writer); |
3876 | 0 | self.var_index_base.write_into(writer); |
3877 | 0 | } |
3878 | 0 | fn table_type(&self) -> TableType { |
3879 | 0 | TableType::Named("PaintVarScaleUniformAroundCenter") |
3880 | 0 | } |
3881 | | } |
3882 | | |
3883 | | impl Validate for PaintVarScaleUniformAroundCenter { |
3884 | 0 | fn validate_impl(&self, ctx: &mut ValidationCtx) { |
3885 | 0 | ctx.in_table("PaintVarScaleUniformAroundCenter", |ctx| { |
3886 | 0 | ctx.in_field("paint", |ctx| { |
3887 | 0 | self.paint.validate_impl(ctx); |
3888 | 0 | }); |
3889 | 0 | }) |
3890 | 0 | } |
3891 | | } |
3892 | | |
3893 | | impl<'a> FromObjRef<read_fonts::tables::colr::PaintVarScaleUniformAroundCenter<'a>> |
3894 | | for PaintVarScaleUniformAroundCenter |
3895 | | { |
3896 | 0 | fn from_obj_ref( |
3897 | 0 | obj: &read_fonts::tables::colr::PaintVarScaleUniformAroundCenter<'a>, |
3898 | 0 | _: FontData, |
3899 | 0 | ) -> Self { |
3900 | 0 | PaintVarScaleUniformAroundCenter { |
3901 | 0 | paint: obj.paint().to_owned_table(), |
3902 | 0 | scale: obj.scale(), |
3903 | 0 | center_x: obj.center_x(), |
3904 | 0 | center_y: obj.center_y(), |
3905 | 0 | var_index_base: obj.var_index_base(), |
3906 | 0 | } |
3907 | 0 | } |
3908 | | } |
3909 | | |
3910 | | #[allow(clippy::needless_lifetimes)] |
3911 | | impl<'a> FromTableRef<read_fonts::tables::colr::PaintVarScaleUniformAroundCenter<'a>> |
3912 | | for PaintVarScaleUniformAroundCenter |
3913 | | { |
3914 | | } |
3915 | | |
3916 | | impl ReadArgs for PaintVarScaleUniformAroundCenter { |
3917 | | type Args = (); |
3918 | | } |
3919 | | |
3920 | | impl<'a> FontRead<'a> for PaintVarScaleUniformAroundCenter { |
3921 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
3922 | 0 | <read_fonts::tables::colr::PaintVarScaleUniformAroundCenter as FontRead>::read(data) |
3923 | 0 | .map(|x| x.to_owned_table()) |
3924 | 0 | } |
3925 | | } |
3926 | | |
3927 | | /// [PaintRotate](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-24-to-27-paintrotate-paintvarrotate-paintrotatearoundcenter-paintvarrotatearoundcenter) table |
3928 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
3929 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
3930 | | pub struct PaintRotate { |
3931 | | /// Offset to a Paint subtable. |
3932 | | pub paint: OffsetMarker<Paint, WIDTH_24>, |
3933 | | /// Rotation angle, 180° in counter-clockwise degrees per 1.0 of |
3934 | | /// value. |
3935 | | pub angle: F2Dot14, |
3936 | | } |
3937 | | |
3938 | | impl PaintRotate { |
3939 | | /// Construct a new `PaintRotate` |
3940 | 0 | pub fn new(paint: Paint, angle: F2Dot14) -> Self { |
3941 | 0 | Self { |
3942 | 0 | paint: paint.into(), |
3943 | 0 | angle, |
3944 | 0 | } |
3945 | 0 | } |
3946 | | } |
3947 | | |
3948 | | impl FontWrite for PaintRotate { |
3949 | | #[allow(clippy::unnecessary_cast)] |
3950 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
3951 | 0 | (24 as u8).write_into(writer); |
3952 | 0 | self.paint.write_into(writer); |
3953 | 0 | self.angle.write_into(writer); |
3954 | 0 | } |
3955 | 0 | fn table_type(&self) -> TableType { |
3956 | 0 | TableType::Named("PaintRotate") |
3957 | 0 | } |
3958 | | } |
3959 | | |
3960 | | impl Validate for PaintRotate { |
3961 | 0 | fn validate_impl(&self, ctx: &mut ValidationCtx) { |
3962 | 0 | ctx.in_table("PaintRotate", |ctx| { |
3963 | 0 | ctx.in_field("paint", |ctx| { |
3964 | 0 | self.paint.validate_impl(ctx); |
3965 | 0 | }); |
3966 | 0 | }) |
3967 | 0 | } |
3968 | | } |
3969 | | |
3970 | | impl<'a> FromObjRef<read_fonts::tables::colr::PaintRotate<'a>> for PaintRotate { |
3971 | 0 | fn from_obj_ref(obj: &read_fonts::tables::colr::PaintRotate<'a>, _: FontData) -> Self { |
3972 | 0 | PaintRotate { |
3973 | 0 | paint: obj.paint().to_owned_table(), |
3974 | 0 | angle: obj.angle(), |
3975 | 0 | } |
3976 | 0 | } |
3977 | | } |
3978 | | |
3979 | | #[allow(clippy::needless_lifetimes)] |
3980 | | impl<'a> FromTableRef<read_fonts::tables::colr::PaintRotate<'a>> for PaintRotate {} |
3981 | | |
3982 | | impl ReadArgs for PaintRotate { |
3983 | | type Args = (); |
3984 | | } |
3985 | | |
3986 | | impl<'a> FontRead<'a> for PaintRotate { |
3987 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
3988 | 0 | <read_fonts::tables::colr::PaintRotate as FontRead>::read(data).map(|x| x.to_owned_table()) |
3989 | 0 | } |
3990 | | } |
3991 | | |
3992 | | /// [PaintVarRotate](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-24-to-27-paintrotate-paintvarrotate-paintrotatearoundcenter-paintvarrotatearoundcenter) table |
3993 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
3994 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
3995 | | pub struct PaintVarRotate { |
3996 | | /// Offset to a Paint subtable. |
3997 | | pub paint: OffsetMarker<Paint, WIDTH_24>, |
3998 | | /// Rotation angle, 180° in counter-clockwise degrees per 1.0 of |
3999 | | /// value. For variation, use varIndexBase + 0. |
4000 | | pub angle: F2Dot14, |
4001 | | /// Base index into DeltaSetIndexMap. |
4002 | | pub var_index_base: u32, |
4003 | | } |
4004 | | |
4005 | | impl PaintVarRotate { |
4006 | | /// Construct a new `PaintVarRotate` |
4007 | 0 | pub fn new(paint: Paint, angle: F2Dot14, var_index_base: u32) -> Self { |
4008 | 0 | Self { |
4009 | 0 | paint: paint.into(), |
4010 | 0 | angle, |
4011 | 0 | var_index_base, |
4012 | 0 | } |
4013 | 0 | } |
4014 | | } |
4015 | | |
4016 | | impl FontWrite for PaintVarRotate { |
4017 | | #[allow(clippy::unnecessary_cast)] |
4018 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
4019 | 0 | (25 as u8).write_into(writer); |
4020 | 0 | self.paint.write_into(writer); |
4021 | 0 | self.angle.write_into(writer); |
4022 | 0 | self.var_index_base.write_into(writer); |
4023 | 0 | } |
4024 | 0 | fn table_type(&self) -> TableType { |
4025 | 0 | TableType::Named("PaintVarRotate") |
4026 | 0 | } |
4027 | | } |
4028 | | |
4029 | | impl Validate for PaintVarRotate { |
4030 | 0 | fn validate_impl(&self, ctx: &mut ValidationCtx) { |
4031 | 0 | ctx.in_table("PaintVarRotate", |ctx| { |
4032 | 0 | ctx.in_field("paint", |ctx| { |
4033 | 0 | self.paint.validate_impl(ctx); |
4034 | 0 | }); |
4035 | 0 | }) |
4036 | 0 | } |
4037 | | } |
4038 | | |
4039 | | impl<'a> FromObjRef<read_fonts::tables::colr::PaintVarRotate<'a>> for PaintVarRotate { |
4040 | 0 | fn from_obj_ref(obj: &read_fonts::tables::colr::PaintVarRotate<'a>, _: FontData) -> Self { |
4041 | 0 | PaintVarRotate { |
4042 | 0 | paint: obj.paint().to_owned_table(), |
4043 | 0 | angle: obj.angle(), |
4044 | 0 | var_index_base: obj.var_index_base(), |
4045 | 0 | } |
4046 | 0 | } |
4047 | | } |
4048 | | |
4049 | | #[allow(clippy::needless_lifetimes)] |
4050 | | impl<'a> FromTableRef<read_fonts::tables::colr::PaintVarRotate<'a>> for PaintVarRotate {} |
4051 | | |
4052 | | impl ReadArgs for PaintVarRotate { |
4053 | | type Args = (); |
4054 | | } |
4055 | | |
4056 | | impl<'a> FontRead<'a> for PaintVarRotate { |
4057 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
4058 | 0 | <read_fonts::tables::colr::PaintVarRotate as FontRead>::read(data) |
4059 | 0 | .map(|x| x.to_owned_table()) |
4060 | 0 | } |
4061 | | } |
4062 | | |
4063 | | /// [PaintRotateAroundCenter](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-24-to-27-paintrotate-paintvarrotate-paintrotatearoundcenter-paintvarrotatearoundcenter) table |
4064 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
4065 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
4066 | | pub struct PaintRotateAroundCenter { |
4067 | | /// Offset to a Paint subtable. |
4068 | | pub paint: OffsetMarker<Paint, WIDTH_24>, |
4069 | | /// Rotation angle, 180° in counter-clockwise degrees per 1.0 of |
4070 | | /// value. |
4071 | | pub angle: F2Dot14, |
4072 | | /// x coordinate for the center of rotation. |
4073 | | pub center_x: FWord, |
4074 | | /// y coordinate for the center of rotation. |
4075 | | pub center_y: FWord, |
4076 | | } |
4077 | | |
4078 | | impl PaintRotateAroundCenter { |
4079 | | /// Construct a new `PaintRotateAroundCenter` |
4080 | 0 | pub fn new(paint: Paint, angle: F2Dot14, center_x: FWord, center_y: FWord) -> Self { |
4081 | 0 | Self { |
4082 | 0 | paint: paint.into(), |
4083 | 0 | angle, |
4084 | 0 | center_x, |
4085 | 0 | center_y, |
4086 | 0 | } |
4087 | 0 | } |
4088 | | } |
4089 | | |
4090 | | impl FontWrite for PaintRotateAroundCenter { |
4091 | | #[allow(clippy::unnecessary_cast)] |
4092 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
4093 | 0 | (26 as u8).write_into(writer); |
4094 | 0 | self.paint.write_into(writer); |
4095 | 0 | self.angle.write_into(writer); |
4096 | 0 | self.center_x.write_into(writer); |
4097 | 0 | self.center_y.write_into(writer); |
4098 | 0 | } |
4099 | 0 | fn table_type(&self) -> TableType { |
4100 | 0 | TableType::Named("PaintRotateAroundCenter") |
4101 | 0 | } |
4102 | | } |
4103 | | |
4104 | | impl Validate for PaintRotateAroundCenter { |
4105 | 0 | fn validate_impl(&self, ctx: &mut ValidationCtx) { |
4106 | 0 | ctx.in_table("PaintRotateAroundCenter", |ctx| { |
4107 | 0 | ctx.in_field("paint", |ctx| { |
4108 | 0 | self.paint.validate_impl(ctx); |
4109 | 0 | }); |
4110 | 0 | }) |
4111 | 0 | } |
4112 | | } |
4113 | | |
4114 | | impl<'a> FromObjRef<read_fonts::tables::colr::PaintRotateAroundCenter<'a>> |
4115 | | for PaintRotateAroundCenter |
4116 | | { |
4117 | 0 | fn from_obj_ref( |
4118 | 0 | obj: &read_fonts::tables::colr::PaintRotateAroundCenter<'a>, |
4119 | 0 | _: FontData, |
4120 | 0 | ) -> Self { |
4121 | 0 | PaintRotateAroundCenter { |
4122 | 0 | paint: obj.paint().to_owned_table(), |
4123 | 0 | angle: obj.angle(), |
4124 | 0 | center_x: obj.center_x(), |
4125 | 0 | center_y: obj.center_y(), |
4126 | 0 | } |
4127 | 0 | } |
4128 | | } |
4129 | | |
4130 | | #[allow(clippy::needless_lifetimes)] |
4131 | | impl<'a> FromTableRef<read_fonts::tables::colr::PaintRotateAroundCenter<'a>> |
4132 | | for PaintRotateAroundCenter |
4133 | | { |
4134 | | } |
4135 | | |
4136 | | impl ReadArgs for PaintRotateAroundCenter { |
4137 | | type Args = (); |
4138 | | } |
4139 | | |
4140 | | impl<'a> FontRead<'a> for PaintRotateAroundCenter { |
4141 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
4142 | 0 | <read_fonts::tables::colr::PaintRotateAroundCenter as FontRead>::read(data) |
4143 | 0 | .map(|x| x.to_owned_table()) |
4144 | 0 | } |
4145 | | } |
4146 | | |
4147 | | /// [PaintVarRotateAroundCenter](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-24-to-27-paintrotate-paintvarrotate-paintrotatearoundcenter-paintvarrotatearoundcenter) table |
4148 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
4149 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
4150 | | pub struct PaintVarRotateAroundCenter { |
4151 | | /// Offset to a Paint subtable. |
4152 | | pub paint: OffsetMarker<Paint, WIDTH_24>, |
4153 | | /// Rotation angle, 180° in counter-clockwise degrees per 1.0 of |
4154 | | /// value. For variation, use varIndexBase + 0. |
4155 | | pub angle: F2Dot14, |
4156 | | /// x coordinate for the center of rotation. For variation, use |
4157 | | /// varIndexBase + 1. |
4158 | | pub center_x: FWord, |
4159 | | /// y coordinate for the center of rotation. For variation, use |
4160 | | /// varIndexBase + 2. |
4161 | | pub center_y: FWord, |
4162 | | /// Base index into DeltaSetIndexMap. |
4163 | | pub var_index_base: u32, |
4164 | | } |
4165 | | |
4166 | | impl PaintVarRotateAroundCenter { |
4167 | | /// Construct a new `PaintVarRotateAroundCenter` |
4168 | 0 | pub fn new( |
4169 | 0 | paint: Paint, |
4170 | 0 | angle: F2Dot14, |
4171 | 0 | center_x: FWord, |
4172 | 0 | center_y: FWord, |
4173 | 0 | var_index_base: u32, |
4174 | 0 | ) -> Self { |
4175 | 0 | Self { |
4176 | 0 | paint: paint.into(), |
4177 | 0 | angle, |
4178 | 0 | center_x, |
4179 | 0 | center_y, |
4180 | 0 | var_index_base, |
4181 | 0 | } |
4182 | 0 | } |
4183 | | } |
4184 | | |
4185 | | impl FontWrite for PaintVarRotateAroundCenter { |
4186 | | #[allow(clippy::unnecessary_cast)] |
4187 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
4188 | 0 | (27 as u8).write_into(writer); |
4189 | 0 | self.paint.write_into(writer); |
4190 | 0 | self.angle.write_into(writer); |
4191 | 0 | self.center_x.write_into(writer); |
4192 | 0 | self.center_y.write_into(writer); |
4193 | 0 | self.var_index_base.write_into(writer); |
4194 | 0 | } |
4195 | 0 | fn table_type(&self) -> TableType { |
4196 | 0 | TableType::Named("PaintVarRotateAroundCenter") |
4197 | 0 | } |
4198 | | } |
4199 | | |
4200 | | impl Validate for PaintVarRotateAroundCenter { |
4201 | 0 | fn validate_impl(&self, ctx: &mut ValidationCtx) { |
4202 | 0 | ctx.in_table("PaintVarRotateAroundCenter", |ctx| { |
4203 | 0 | ctx.in_field("paint", |ctx| { |
4204 | 0 | self.paint.validate_impl(ctx); |
4205 | 0 | }); |
4206 | 0 | }) |
4207 | 0 | } |
4208 | | } |
4209 | | |
4210 | | impl<'a> FromObjRef<read_fonts::tables::colr::PaintVarRotateAroundCenter<'a>> |
4211 | | for PaintVarRotateAroundCenter |
4212 | | { |
4213 | 0 | fn from_obj_ref( |
4214 | 0 | obj: &read_fonts::tables::colr::PaintVarRotateAroundCenter<'a>, |
4215 | 0 | _: FontData, |
4216 | 0 | ) -> Self { |
4217 | 0 | PaintVarRotateAroundCenter { |
4218 | 0 | paint: obj.paint().to_owned_table(), |
4219 | 0 | angle: obj.angle(), |
4220 | 0 | center_x: obj.center_x(), |
4221 | 0 | center_y: obj.center_y(), |
4222 | 0 | var_index_base: obj.var_index_base(), |
4223 | 0 | } |
4224 | 0 | } |
4225 | | } |
4226 | | |
4227 | | #[allow(clippy::needless_lifetimes)] |
4228 | | impl<'a> FromTableRef<read_fonts::tables::colr::PaintVarRotateAroundCenter<'a>> |
4229 | | for PaintVarRotateAroundCenter |
4230 | | { |
4231 | | } |
4232 | | |
4233 | | impl ReadArgs for PaintVarRotateAroundCenter { |
4234 | | type Args = (); |
4235 | | } |
4236 | | |
4237 | | impl<'a> FontRead<'a> for PaintVarRotateAroundCenter { |
4238 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
4239 | 0 | <read_fonts::tables::colr::PaintVarRotateAroundCenter as FontRead>::read(data) |
4240 | 0 | .map(|x| x.to_owned_table()) |
4241 | 0 | } |
4242 | | } |
4243 | | |
4244 | | /// [PaintSkew](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-28-to-31-paintskew-paintvarskew-paintskewaroundcenter-paintvarskewaroundcenter) table |
4245 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
4246 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
4247 | | pub struct PaintSkew { |
4248 | | /// Offset to a Paint subtable. |
4249 | | pub paint: OffsetMarker<Paint, WIDTH_24>, |
4250 | | /// Angle of skew in the direction of the x-axis, 180° in |
4251 | | /// counter-clockwise degrees per 1.0 of value. |
4252 | | pub x_skew_angle: F2Dot14, |
4253 | | /// Angle of skew in the direction of the y-axis, 180° in |
4254 | | /// counter-clockwise degrees per 1.0 of value. |
4255 | | pub y_skew_angle: F2Dot14, |
4256 | | } |
4257 | | |
4258 | | impl PaintSkew { |
4259 | | /// Construct a new `PaintSkew` |
4260 | 0 | pub fn new(paint: Paint, x_skew_angle: F2Dot14, y_skew_angle: F2Dot14) -> Self { |
4261 | 0 | Self { |
4262 | 0 | paint: paint.into(), |
4263 | 0 | x_skew_angle, |
4264 | 0 | y_skew_angle, |
4265 | 0 | } |
4266 | 0 | } |
4267 | | } |
4268 | | |
4269 | | impl FontWrite for PaintSkew { |
4270 | | #[allow(clippy::unnecessary_cast)] |
4271 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
4272 | 0 | (28 as u8).write_into(writer); |
4273 | 0 | self.paint.write_into(writer); |
4274 | 0 | self.x_skew_angle.write_into(writer); |
4275 | 0 | self.y_skew_angle.write_into(writer); |
4276 | 0 | } |
4277 | 0 | fn table_type(&self) -> TableType { |
4278 | 0 | TableType::Named("PaintSkew") |
4279 | 0 | } |
4280 | | } |
4281 | | |
4282 | | impl Validate for PaintSkew { |
4283 | 0 | fn validate_impl(&self, ctx: &mut ValidationCtx) { |
4284 | 0 | ctx.in_table("PaintSkew", |ctx| { |
4285 | 0 | ctx.in_field("paint", |ctx| { |
4286 | 0 | self.paint.validate_impl(ctx); |
4287 | 0 | }); |
4288 | 0 | }) |
4289 | 0 | } |
4290 | | } |
4291 | | |
4292 | | impl<'a> FromObjRef<read_fonts::tables::colr::PaintSkew<'a>> for PaintSkew { |
4293 | 0 | fn from_obj_ref(obj: &read_fonts::tables::colr::PaintSkew<'a>, _: FontData) -> Self { |
4294 | 0 | PaintSkew { |
4295 | 0 | paint: obj.paint().to_owned_table(), |
4296 | 0 | x_skew_angle: obj.x_skew_angle(), |
4297 | 0 | y_skew_angle: obj.y_skew_angle(), |
4298 | 0 | } |
4299 | 0 | } |
4300 | | } |
4301 | | |
4302 | | #[allow(clippy::needless_lifetimes)] |
4303 | | impl<'a> FromTableRef<read_fonts::tables::colr::PaintSkew<'a>> for PaintSkew {} |
4304 | | |
4305 | | impl ReadArgs for PaintSkew { |
4306 | | type Args = (); |
4307 | | } |
4308 | | |
4309 | | impl<'a> FontRead<'a> for PaintSkew { |
4310 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
4311 | 0 | <read_fonts::tables::colr::PaintSkew as FontRead>::read(data).map(|x| x.to_owned_table()) |
4312 | 0 | } |
4313 | | } |
4314 | | |
4315 | | /// [PaintVarSkew](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-28-to-31-paintskew-paintvarskew-paintskewaroundcenter-paintvarskewaroundcenter) table |
4316 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
4317 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
4318 | | pub struct PaintVarSkew { |
4319 | | /// Offset to a Paint subtable. |
4320 | | pub paint: OffsetMarker<Paint, WIDTH_24>, |
4321 | | /// Angle of skew in the direction of the x-axis, 180° ┬░ in |
4322 | | /// counter-clockwise degrees per 1.0 of value. For variation, use |
4323 | | /// varIndexBase + 0. |
4324 | | pub x_skew_angle: F2Dot14, |
4325 | | /// Angle of skew in the direction of the y-axis, 180° in |
4326 | | /// counter-clockwise degrees per 1.0 of value. For variation, use |
4327 | | /// varIndexBase + 1. |
4328 | | pub y_skew_angle: F2Dot14, |
4329 | | /// Base index into DeltaSetIndexMap. |
4330 | | pub var_index_base: u32, |
4331 | | } |
4332 | | |
4333 | | impl PaintVarSkew { |
4334 | | /// Construct a new `PaintVarSkew` |
4335 | 0 | pub fn new( |
4336 | 0 | paint: Paint, |
4337 | 0 | x_skew_angle: F2Dot14, |
4338 | 0 | y_skew_angle: F2Dot14, |
4339 | 0 | var_index_base: u32, |
4340 | 0 | ) -> Self { |
4341 | 0 | Self { |
4342 | 0 | paint: paint.into(), |
4343 | 0 | x_skew_angle, |
4344 | 0 | y_skew_angle, |
4345 | 0 | var_index_base, |
4346 | 0 | } |
4347 | 0 | } |
4348 | | } |
4349 | | |
4350 | | impl FontWrite for PaintVarSkew { |
4351 | | #[allow(clippy::unnecessary_cast)] |
4352 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
4353 | 0 | (29 as u8).write_into(writer); |
4354 | 0 | self.paint.write_into(writer); |
4355 | 0 | self.x_skew_angle.write_into(writer); |
4356 | 0 | self.y_skew_angle.write_into(writer); |
4357 | 0 | self.var_index_base.write_into(writer); |
4358 | 0 | } |
4359 | 0 | fn table_type(&self) -> TableType { |
4360 | 0 | TableType::Named("PaintVarSkew") |
4361 | 0 | } |
4362 | | } |
4363 | | |
4364 | | impl Validate for PaintVarSkew { |
4365 | 0 | fn validate_impl(&self, ctx: &mut ValidationCtx) { |
4366 | 0 | ctx.in_table("PaintVarSkew", |ctx| { |
4367 | 0 | ctx.in_field("paint", |ctx| { |
4368 | 0 | self.paint.validate_impl(ctx); |
4369 | 0 | }); |
4370 | 0 | }) |
4371 | 0 | } |
4372 | | } |
4373 | | |
4374 | | impl<'a> FromObjRef<read_fonts::tables::colr::PaintVarSkew<'a>> for PaintVarSkew { |
4375 | 0 | fn from_obj_ref(obj: &read_fonts::tables::colr::PaintVarSkew<'a>, _: FontData) -> Self { |
4376 | 0 | PaintVarSkew { |
4377 | 0 | paint: obj.paint().to_owned_table(), |
4378 | 0 | x_skew_angle: obj.x_skew_angle(), |
4379 | 0 | y_skew_angle: obj.y_skew_angle(), |
4380 | 0 | var_index_base: obj.var_index_base(), |
4381 | 0 | } |
4382 | 0 | } |
4383 | | } |
4384 | | |
4385 | | #[allow(clippy::needless_lifetimes)] |
4386 | | impl<'a> FromTableRef<read_fonts::tables::colr::PaintVarSkew<'a>> for PaintVarSkew {} |
4387 | | |
4388 | | impl ReadArgs for PaintVarSkew { |
4389 | | type Args = (); |
4390 | | } |
4391 | | |
4392 | | impl<'a> FontRead<'a> for PaintVarSkew { |
4393 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
4394 | 0 | <read_fonts::tables::colr::PaintVarSkew as FontRead>::read(data).map(|x| x.to_owned_table()) |
4395 | 0 | } |
4396 | | } |
4397 | | |
4398 | | /// [PaintSkewAroundCenter](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-28-to-31-paintskew-paintvarskew-paintskewaroundcenter-paintvarskewaroundcenter) table |
4399 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
4400 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
4401 | | pub struct PaintSkewAroundCenter { |
4402 | | /// Offset to a Paint subtable. |
4403 | | pub paint: OffsetMarker<Paint, WIDTH_24>, |
4404 | | /// Angle of skew in the direction of the x-axis, 180° in |
4405 | | /// counter-clockwise degrees per 1.0 of value. |
4406 | | pub x_skew_angle: F2Dot14, |
4407 | | /// Angle of skew in the direction of the y-axis, 180° in |
4408 | | /// counter-clockwise degrees per 1.0 of value. |
4409 | | pub y_skew_angle: F2Dot14, |
4410 | | /// x coordinate for the center of rotation. |
4411 | | pub center_x: FWord, |
4412 | | /// y coordinate for the center of rotation. |
4413 | | pub center_y: FWord, |
4414 | | } |
4415 | | |
4416 | | impl PaintSkewAroundCenter { |
4417 | | /// Construct a new `PaintSkewAroundCenter` |
4418 | 0 | pub fn new( |
4419 | 0 | paint: Paint, |
4420 | 0 | x_skew_angle: F2Dot14, |
4421 | 0 | y_skew_angle: F2Dot14, |
4422 | 0 | center_x: FWord, |
4423 | 0 | center_y: FWord, |
4424 | 0 | ) -> Self { |
4425 | 0 | Self { |
4426 | 0 | paint: paint.into(), |
4427 | 0 | x_skew_angle, |
4428 | 0 | y_skew_angle, |
4429 | 0 | center_x, |
4430 | 0 | center_y, |
4431 | 0 | } |
4432 | 0 | } |
4433 | | } |
4434 | | |
4435 | | impl FontWrite for PaintSkewAroundCenter { |
4436 | | #[allow(clippy::unnecessary_cast)] |
4437 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
4438 | 0 | (30 as u8).write_into(writer); |
4439 | 0 | self.paint.write_into(writer); |
4440 | 0 | self.x_skew_angle.write_into(writer); |
4441 | 0 | self.y_skew_angle.write_into(writer); |
4442 | 0 | self.center_x.write_into(writer); |
4443 | 0 | self.center_y.write_into(writer); |
4444 | 0 | } |
4445 | 0 | fn table_type(&self) -> TableType { |
4446 | 0 | TableType::Named("PaintSkewAroundCenter") |
4447 | 0 | } |
4448 | | } |
4449 | | |
4450 | | impl Validate for PaintSkewAroundCenter { |
4451 | 0 | fn validate_impl(&self, ctx: &mut ValidationCtx) { |
4452 | 0 | ctx.in_table("PaintSkewAroundCenter", |ctx| { |
4453 | 0 | ctx.in_field("paint", |ctx| { |
4454 | 0 | self.paint.validate_impl(ctx); |
4455 | 0 | }); |
4456 | 0 | }) |
4457 | 0 | } |
4458 | | } |
4459 | | |
4460 | | impl<'a> FromObjRef<read_fonts::tables::colr::PaintSkewAroundCenter<'a>> for PaintSkewAroundCenter { |
4461 | 0 | fn from_obj_ref( |
4462 | 0 | obj: &read_fonts::tables::colr::PaintSkewAroundCenter<'a>, |
4463 | 0 | _: FontData, |
4464 | 0 | ) -> Self { |
4465 | 0 | PaintSkewAroundCenter { |
4466 | 0 | paint: obj.paint().to_owned_table(), |
4467 | 0 | x_skew_angle: obj.x_skew_angle(), |
4468 | 0 | y_skew_angle: obj.y_skew_angle(), |
4469 | 0 | center_x: obj.center_x(), |
4470 | 0 | center_y: obj.center_y(), |
4471 | 0 | } |
4472 | 0 | } |
4473 | | } |
4474 | | |
4475 | | #[allow(clippy::needless_lifetimes)] |
4476 | | impl<'a> FromTableRef<read_fonts::tables::colr::PaintSkewAroundCenter<'a>> |
4477 | | for PaintSkewAroundCenter |
4478 | | { |
4479 | | } |
4480 | | |
4481 | | impl ReadArgs for PaintSkewAroundCenter { |
4482 | | type Args = (); |
4483 | | } |
4484 | | |
4485 | | impl<'a> FontRead<'a> for PaintSkewAroundCenter { |
4486 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
4487 | 0 | <read_fonts::tables::colr::PaintSkewAroundCenter as FontRead>::read(data) |
4488 | 0 | .map(|x| x.to_owned_table()) |
4489 | 0 | } |
4490 | | } |
4491 | | |
4492 | | /// [PaintVarSkewAroundCenter](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#formats-28-to-31-paintskew-paintvarskew-paintskewaroundcenter-paintvarskewaroundcenter) table |
4493 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
4494 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
4495 | | pub struct PaintVarSkewAroundCenter { |
4496 | | /// Offset to a Paint subtable. |
4497 | | pub paint: OffsetMarker<Paint, WIDTH_24>, |
4498 | | /// Angle of skew in the direction of the x-axis, 180° in |
4499 | | /// counter-clockwise degrees per 1.0 of value. For variation, use |
4500 | | /// varIndexBase + 0. |
4501 | | pub x_skew_angle: F2Dot14, |
4502 | | /// Angle of skew in the direction of the y-axis, 180° in |
4503 | | /// counter-clockwise degrees per 1.0 of value. For variation, use |
4504 | | /// varIndexBase + 1. |
4505 | | pub y_skew_angle: F2Dot14, |
4506 | | /// x coordinate for the center of rotation. For variation, use |
4507 | | /// varIndexBase + 2. |
4508 | | pub center_x: FWord, |
4509 | | /// y coordinate for the center of rotation. For variation, use |
4510 | | /// varIndexBase + 3. |
4511 | | pub center_y: FWord, |
4512 | | /// Base index into DeltaSetIndexMap. |
4513 | | pub var_index_base: u32, |
4514 | | } |
4515 | | |
4516 | | impl PaintVarSkewAroundCenter { |
4517 | | /// Construct a new `PaintVarSkewAroundCenter` |
4518 | 0 | pub fn new( |
4519 | 0 | paint: Paint, |
4520 | 0 | x_skew_angle: F2Dot14, |
4521 | 0 | y_skew_angle: F2Dot14, |
4522 | 0 | center_x: FWord, |
4523 | 0 | center_y: FWord, |
4524 | 0 | var_index_base: u32, |
4525 | 0 | ) -> Self { |
4526 | 0 | Self { |
4527 | 0 | paint: paint.into(), |
4528 | 0 | x_skew_angle, |
4529 | 0 | y_skew_angle, |
4530 | 0 | center_x, |
4531 | 0 | center_y, |
4532 | 0 | var_index_base, |
4533 | 0 | } |
4534 | 0 | } |
4535 | | } |
4536 | | |
4537 | | impl FontWrite for PaintVarSkewAroundCenter { |
4538 | | #[allow(clippy::unnecessary_cast)] |
4539 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
4540 | 0 | (31 as u8).write_into(writer); |
4541 | 0 | self.paint.write_into(writer); |
4542 | 0 | self.x_skew_angle.write_into(writer); |
4543 | 0 | self.y_skew_angle.write_into(writer); |
4544 | 0 | self.center_x.write_into(writer); |
4545 | 0 | self.center_y.write_into(writer); |
4546 | 0 | self.var_index_base.write_into(writer); |
4547 | 0 | } |
4548 | 0 | fn table_type(&self) -> TableType { |
4549 | 0 | TableType::Named("PaintVarSkewAroundCenter") |
4550 | 0 | } |
4551 | | } |
4552 | | |
4553 | | impl Validate for PaintVarSkewAroundCenter { |
4554 | 0 | fn validate_impl(&self, ctx: &mut ValidationCtx) { |
4555 | 0 | ctx.in_table("PaintVarSkewAroundCenter", |ctx| { |
4556 | 0 | ctx.in_field("paint", |ctx| { |
4557 | 0 | self.paint.validate_impl(ctx); |
4558 | 0 | }); |
4559 | 0 | }) |
4560 | 0 | } |
4561 | | } |
4562 | | |
4563 | | impl<'a> FromObjRef<read_fonts::tables::colr::PaintVarSkewAroundCenter<'a>> |
4564 | | for PaintVarSkewAroundCenter |
4565 | | { |
4566 | 0 | fn from_obj_ref( |
4567 | 0 | obj: &read_fonts::tables::colr::PaintVarSkewAroundCenter<'a>, |
4568 | 0 | _: FontData, |
4569 | 0 | ) -> Self { |
4570 | 0 | PaintVarSkewAroundCenter { |
4571 | 0 | paint: obj.paint().to_owned_table(), |
4572 | 0 | x_skew_angle: obj.x_skew_angle(), |
4573 | 0 | y_skew_angle: obj.y_skew_angle(), |
4574 | 0 | center_x: obj.center_x(), |
4575 | 0 | center_y: obj.center_y(), |
4576 | 0 | var_index_base: obj.var_index_base(), |
4577 | 0 | } |
4578 | 0 | } |
4579 | | } |
4580 | | |
4581 | | #[allow(clippy::needless_lifetimes)] |
4582 | | impl<'a> FromTableRef<read_fonts::tables::colr::PaintVarSkewAroundCenter<'a>> |
4583 | | for PaintVarSkewAroundCenter |
4584 | | { |
4585 | | } |
4586 | | |
4587 | | impl ReadArgs for PaintVarSkewAroundCenter { |
4588 | | type Args = (); |
4589 | | } |
4590 | | |
4591 | | impl<'a> FontRead<'a> for PaintVarSkewAroundCenter { |
4592 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
4593 | 0 | <read_fonts::tables::colr::PaintVarSkewAroundCenter as FontRead>::read(data) |
4594 | 0 | .map(|x| x.to_owned_table()) |
4595 | 0 | } |
4596 | | } |
4597 | | |
4598 | | /// [PaintComposite](https://learn.microsoft.com/en-us/typography/opentype/spec/colr#format-32-paintcomposite) table |
4599 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
4600 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
4601 | | pub struct PaintComposite { |
4602 | | /// Offset to a source Paint table. |
4603 | | pub source_paint: OffsetMarker<Paint, WIDTH_24>, |
4604 | | /// A CompositeMode enumeration value. |
4605 | | pub composite_mode: CompositeMode, |
4606 | | /// Offset to a backdrop Paint table. |
4607 | | pub backdrop_paint: OffsetMarker<Paint, WIDTH_24>, |
4608 | | } |
4609 | | |
4610 | | impl PaintComposite { |
4611 | | /// Construct a new `PaintComposite` |
4612 | 0 | pub fn new(source_paint: Paint, composite_mode: CompositeMode, backdrop_paint: Paint) -> Self { |
4613 | 0 | Self { |
4614 | 0 | source_paint: source_paint.into(), |
4615 | 0 | composite_mode, |
4616 | 0 | backdrop_paint: backdrop_paint.into(), |
4617 | 0 | } |
4618 | 0 | } |
4619 | | } |
4620 | | |
4621 | | impl FontWrite for PaintComposite { |
4622 | | #[allow(clippy::unnecessary_cast)] |
4623 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
4624 | 0 | (32 as u8).write_into(writer); |
4625 | 0 | self.source_paint.write_into(writer); |
4626 | 0 | self.composite_mode.write_into(writer); |
4627 | 0 | self.backdrop_paint.write_into(writer); |
4628 | 0 | } |
4629 | 0 | fn table_type(&self) -> TableType { |
4630 | 0 | TableType::Named("PaintComposite") |
4631 | 0 | } |
4632 | | } |
4633 | | |
4634 | | impl Validate for PaintComposite { |
4635 | 0 | fn validate_impl(&self, ctx: &mut ValidationCtx) { |
4636 | 0 | ctx.in_table("PaintComposite", |ctx| { |
4637 | 0 | ctx.in_field("source_paint", |ctx| { |
4638 | 0 | self.source_paint.validate_impl(ctx); |
4639 | 0 | }); |
4640 | 0 | ctx.in_field("backdrop_paint", |ctx| { |
4641 | 0 | self.backdrop_paint.validate_impl(ctx); |
4642 | 0 | }); |
4643 | 0 | }) |
4644 | 0 | } |
4645 | | } |
4646 | | |
4647 | | impl<'a> FromObjRef<read_fonts::tables::colr::PaintComposite<'a>> for PaintComposite { |
4648 | 0 | fn from_obj_ref(obj: &read_fonts::tables::colr::PaintComposite<'a>, _: FontData) -> Self { |
4649 | 0 | PaintComposite { |
4650 | 0 | source_paint: obj.source_paint().to_owned_table(), |
4651 | 0 | composite_mode: obj.composite_mode(), |
4652 | 0 | backdrop_paint: obj.backdrop_paint().to_owned_table(), |
4653 | 0 | } |
4654 | 0 | } |
4655 | | } |
4656 | | |
4657 | | #[allow(clippy::needless_lifetimes)] |
4658 | | impl<'a> FromTableRef<read_fonts::tables::colr::PaintComposite<'a>> for PaintComposite {} |
4659 | | |
4660 | | impl ReadArgs for PaintComposite { |
4661 | | type Args = (); |
4662 | | } |
4663 | | |
4664 | | impl<'a> FontRead<'a> for PaintComposite { |
4665 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
4666 | 0 | <read_fonts::tables::colr::PaintComposite as FontRead>::read(data) |
4667 | 0 | .map(|x| x.to_owned_table()) |
4668 | 0 | } |
4669 | | } |
4670 | | |
4671 | | impl FontWrite for CompositeMode { |
4672 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
4673 | 0 | let val = *self as u8; |
4674 | 0 | writer.write_slice(&val.to_be_bytes()) |
4675 | 0 | } |
4676 | | } |