1#[allow(unused_imports)]
6use crate::codegen_prelude::*;
7
8pub use read_fonts::tables::variations::EntryFormat;
9
10#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
12#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
13pub struct TupleVariationHeader {
14 pub variation_data_size: u16,
17 pub tuple_index: TupleIndex,
20 pub peak_tuple: Vec<F2Dot14>,
24 pub intermediate_start_tuple: Vec<F2Dot14>,
27 pub intermediate_end_tuple: Vec<F2Dot14>,
30}
31
32impl FontWrite for TupleVariationHeader {
33 fn write_into(&self, writer: &mut TableWriter) {
34 self.variation_data_size.write_into(writer);
35 self.tuple_index.write_into(writer);
36 self.peak_tuple.write_into(writer);
37 self.intermediate_start_tuple.write_into(writer);
38 self.intermediate_end_tuple.write_into(writer);
39 }
40 fn table_type(&self) -> TableType {
41 TableType::Named("TupleVariationHeader")
42 }
43}
44
45impl Validate for TupleVariationHeader {
46 fn validate_impl(&self, _ctx: &mut ValidationCtx) {}
47}
48
49impl<'a> FromObjRef<read_fonts::tables::variations::TupleVariationHeader<'a>>
50 for TupleVariationHeader
51{
52 fn from_obj_ref(
53 obj: &read_fonts::tables::variations::TupleVariationHeader<'a>,
54 _: FontData,
55 ) -> Self {
56 let offset_data = obj.offset_data();
57 TupleVariationHeader {
58 variation_data_size: obj.variation_data_size(),
59 tuple_index: obj.tuple_index(),
60 peak_tuple: obj.peak_tuple().to_owned_obj(offset_data),
61 intermediate_start_tuple: obj.intermediate_start_tuple().to_owned_obj(offset_data),
62 intermediate_end_tuple: obj.intermediate_end_tuple().to_owned_obj(offset_data),
63 }
64 }
65}
66
67#[allow(clippy::needless_lifetimes)]
68impl<'a> FromTableRef<read_fonts::tables::variations::TupleVariationHeader<'a>>
69 for TupleVariationHeader
70{
71}
72
73#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
79#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
80pub struct Tuple {
81 pub values: Vec<F2Dot14>,
86}
87
88impl Tuple {
89 pub fn new(values: Vec<F2Dot14>) -> Self {
91 Self { values }
92 }
93}
94
95impl FontWrite for Tuple {
96 fn write_into(&self, writer: &mut TableWriter) {
97 self.values.write_into(writer);
98 }
99 fn table_type(&self) -> TableType {
100 TableType::Named("Tuple")
101 }
102}
103
104impl Validate for Tuple {
105 fn validate_impl(&self, ctx: &mut ValidationCtx) {
106 ctx.in_table("Tuple", |ctx| {
107 ctx.in_field("values", |ctx| {
108 if self.values.len() > (u16::MAX as usize) {
109 ctx.report("array exceeds max length");
110 }
111 });
112 })
113 }
114}
115
116impl FromObjRef<read_fonts::tables::variations::Tuple<'_>> for Tuple {
117 fn from_obj_ref(obj: &read_fonts::tables::variations::Tuple, offset_data: FontData) -> Self {
118 Tuple {
119 values: obj.values().to_owned_obj(offset_data),
120 }
121 }
122}
123
124#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
126#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
127pub struct DeltaSetIndexMapFormat0 {
128 pub entry_format: EntryFormat,
131 pub map_count: u16,
133 pub map_data: Vec<u8>,
135}
136
137impl DeltaSetIndexMapFormat0 {
138 pub fn new(entry_format: EntryFormat, map_count: u16, map_data: Vec<u8>) -> Self {
140 Self {
141 entry_format,
142 map_count,
143 map_data,
144 }
145 }
146}
147
148impl FontWrite for DeltaSetIndexMapFormat0 {
149 #[allow(clippy::unnecessary_cast)]
150 fn write_into(&self, writer: &mut TableWriter) {
151 (0 as u8).write_into(writer);
152 self.entry_format.write_into(writer);
153 self.map_count.write_into(writer);
154 self.map_data.write_into(writer);
155 }
156 fn table_type(&self) -> TableType {
157 TableType::Named("DeltaSetIndexMapFormat0")
158 }
159}
160
161impl Validate for DeltaSetIndexMapFormat0 {
162 fn validate_impl(&self, _ctx: &mut ValidationCtx) {}
163}
164
165impl<'a> FromObjRef<read_fonts::tables::variations::DeltaSetIndexMapFormat0<'a>>
166 for DeltaSetIndexMapFormat0
167{
168 fn from_obj_ref(
169 obj: &read_fonts::tables::variations::DeltaSetIndexMapFormat0<'a>,
170 _: FontData,
171 ) -> Self {
172 let offset_data = obj.offset_data();
173 DeltaSetIndexMapFormat0 {
174 entry_format: obj.entry_format(),
175 map_count: obj.map_count(),
176 map_data: obj.map_data().to_owned_obj(offset_data),
177 }
178 }
179}
180
181#[allow(clippy::needless_lifetimes)]
182impl<'a> FromTableRef<read_fonts::tables::variations::DeltaSetIndexMapFormat0<'a>>
183 for DeltaSetIndexMapFormat0
184{
185}
186
187impl<'a> FontRead<'a> for DeltaSetIndexMapFormat0 {
188 fn read(data: FontData<'a>) -> Result<Self, ReadError> {
189 <read_fonts::tables::variations::DeltaSetIndexMapFormat0 as FontRead>::read(data)
190 .map(|x| x.to_owned_table())
191 }
192}
193
194#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
196#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
197pub struct DeltaSetIndexMapFormat1 {
198 pub entry_format: EntryFormat,
201 pub map_count: u32,
203 pub map_data: Vec<u8>,
205}
206
207impl DeltaSetIndexMapFormat1 {
208 pub fn new(entry_format: EntryFormat, map_count: u32, map_data: Vec<u8>) -> Self {
210 Self {
211 entry_format,
212 map_count,
213 map_data,
214 }
215 }
216}
217
218impl FontWrite for DeltaSetIndexMapFormat1 {
219 #[allow(clippy::unnecessary_cast)]
220 fn write_into(&self, writer: &mut TableWriter) {
221 (1 as u8).write_into(writer);
222 self.entry_format.write_into(writer);
223 self.map_count.write_into(writer);
224 self.map_data.write_into(writer);
225 }
226 fn table_type(&self) -> TableType {
227 TableType::Named("DeltaSetIndexMapFormat1")
228 }
229}
230
231impl Validate for DeltaSetIndexMapFormat1 {
232 fn validate_impl(&self, _ctx: &mut ValidationCtx) {}
233}
234
235impl<'a> FromObjRef<read_fonts::tables::variations::DeltaSetIndexMapFormat1<'a>>
236 for DeltaSetIndexMapFormat1
237{
238 fn from_obj_ref(
239 obj: &read_fonts::tables::variations::DeltaSetIndexMapFormat1<'a>,
240 _: FontData,
241 ) -> Self {
242 let offset_data = obj.offset_data();
243 DeltaSetIndexMapFormat1 {
244 entry_format: obj.entry_format(),
245 map_count: obj.map_count(),
246 map_data: obj.map_data().to_owned_obj(offset_data),
247 }
248 }
249}
250
251#[allow(clippy::needless_lifetimes)]
252impl<'a> FromTableRef<read_fonts::tables::variations::DeltaSetIndexMapFormat1<'a>>
253 for DeltaSetIndexMapFormat1
254{
255}
256
257impl<'a> FontRead<'a> for DeltaSetIndexMapFormat1 {
258 fn read(data: FontData<'a>) -> Result<Self, ReadError> {
259 <read_fonts::tables::variations::DeltaSetIndexMapFormat1 as FontRead>::read(data)
260 .map(|x| x.to_owned_table())
261 }
262}
263
264#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
266#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
267pub enum DeltaSetIndexMap {
268 Format0(DeltaSetIndexMapFormat0),
269 Format1(DeltaSetIndexMapFormat1),
270}
271
272impl DeltaSetIndexMap {
273 pub fn format_0(entry_format: EntryFormat, map_count: u16, map_data: Vec<u8>) -> Self {
275 Self::Format0(DeltaSetIndexMapFormat0::new(
276 entry_format,
277 map_count,
278 map_data,
279 ))
280 }
281
282 pub fn format_1(entry_format: EntryFormat, map_count: u32, map_data: Vec<u8>) -> Self {
284 Self::Format1(DeltaSetIndexMapFormat1::new(
285 entry_format,
286 map_count,
287 map_data,
288 ))
289 }
290}
291
292impl Default for DeltaSetIndexMap {
293 fn default() -> Self {
294 Self::Format0(Default::default())
295 }
296}
297
298impl FontWrite for DeltaSetIndexMap {
299 fn write_into(&self, writer: &mut TableWriter) {
300 match self {
301 Self::Format0(item) => item.write_into(writer),
302 Self::Format1(item) => item.write_into(writer),
303 }
304 }
305 fn table_type(&self) -> TableType {
306 match self {
307 Self::Format0(item) => item.table_type(),
308 Self::Format1(item) => item.table_type(),
309 }
310 }
311}
312
313impl Validate for DeltaSetIndexMap {
314 fn validate_impl(&self, ctx: &mut ValidationCtx) {
315 match self {
316 Self::Format0(item) => item.validate_impl(ctx),
317 Self::Format1(item) => item.validate_impl(ctx),
318 }
319 }
320}
321
322impl FromObjRef<read_fonts::tables::variations::DeltaSetIndexMap<'_>> for DeltaSetIndexMap {
323 fn from_obj_ref(obj: &read_fonts::tables::variations::DeltaSetIndexMap, _: FontData) -> Self {
324 use read_fonts::tables::variations::DeltaSetIndexMap as ObjRefType;
325 match obj {
326 ObjRefType::Format0(item) => DeltaSetIndexMap::Format0(item.to_owned_table()),
327 ObjRefType::Format1(item) => DeltaSetIndexMap::Format1(item.to_owned_table()),
328 }
329 }
330}
331
332impl FromTableRef<read_fonts::tables::variations::DeltaSetIndexMap<'_>> for DeltaSetIndexMap {}
333
334impl<'a> FontRead<'a> for DeltaSetIndexMap {
335 fn read(data: FontData<'a>) -> Result<Self, ReadError> {
336 <read_fonts::tables::variations::DeltaSetIndexMap as FontRead>::read(data)
337 .map(|x| x.to_owned_table())
338 }
339}
340
341impl From<DeltaSetIndexMapFormat0> for DeltaSetIndexMap {
342 fn from(src: DeltaSetIndexMapFormat0) -> DeltaSetIndexMap {
343 DeltaSetIndexMap::Format0(src)
344 }
345}
346
347impl From<DeltaSetIndexMapFormat1> for DeltaSetIndexMap {
348 fn from(src: DeltaSetIndexMapFormat1) -> DeltaSetIndexMap {
349 DeltaSetIndexMap::Format1(src)
350 }
351}
352
353impl FontWrite for EntryFormat {
354 fn write_into(&self, writer: &mut TableWriter) {
355 writer.write_slice(&self.bits().to_be_bytes())
356 }
357}
358
359#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
361#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
362pub struct VariationRegionList {
363 pub axis_count: u16,
366 pub variation_regions: Vec<VariationRegion>,
368}
369
370impl VariationRegionList {
371 pub fn new(axis_count: u16, variation_regions: Vec<VariationRegion>) -> Self {
373 Self {
374 axis_count,
375 variation_regions,
376 }
377 }
378}
379
380impl FontWrite for VariationRegionList {
381 #[allow(clippy::unnecessary_cast)]
382 fn write_into(&self, writer: &mut TableWriter) {
383 self.axis_count.write_into(writer);
384 (u16::try_from(array_len(&self.variation_regions)).unwrap()).write_into(writer);
385 self.variation_regions.write_into(writer);
386 }
387 fn table_type(&self) -> TableType {
388 TableType::Named("VariationRegionList")
389 }
390}
391
392impl Validate for VariationRegionList {
393 fn validate_impl(&self, ctx: &mut ValidationCtx) {
394 ctx.in_table("VariationRegionList", |ctx| {
395 ctx.in_field("variation_regions", |ctx| {
396 if self.variation_regions.len() > (u16::MAX as usize) {
397 ctx.report("array exceeds max length");
398 }
399 self.variation_regions.validate_impl(ctx);
400 });
401 })
402 }
403}
404
405impl<'a> FromObjRef<read_fonts::tables::variations::VariationRegionList<'a>>
406 for VariationRegionList
407{
408 fn from_obj_ref(
409 obj: &read_fonts::tables::variations::VariationRegionList<'a>,
410 _: FontData,
411 ) -> Self {
412 let offset_data = obj.offset_data();
413 VariationRegionList {
414 axis_count: obj.axis_count(),
415 variation_regions: obj
416 .variation_regions()
417 .iter()
418 .filter_map(|x| x.map(|x| FromObjRef::from_obj_ref(&x, offset_data)).ok())
419 .collect(),
420 }
421 }
422}
423
424#[allow(clippy::needless_lifetimes)]
425impl<'a> FromTableRef<read_fonts::tables::variations::VariationRegionList<'a>>
426 for VariationRegionList
427{
428}
429
430impl<'a> FontRead<'a> for VariationRegionList {
431 fn read(data: FontData<'a>) -> Result<Self, ReadError> {
432 <read_fonts::tables::variations::VariationRegionList as FontRead>::read(data)
433 .map(|x| x.to_owned_table())
434 }
435}
436
437#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
439#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
440pub struct VariationRegion {
441 pub region_axes: Vec<RegionAxisCoordinates>,
444}
445
446impl VariationRegion {
447 pub fn new(region_axes: Vec<RegionAxisCoordinates>) -> Self {
449 Self { region_axes }
450 }
451}
452
453impl FontWrite for VariationRegion {
454 fn write_into(&self, writer: &mut TableWriter) {
455 self.region_axes.write_into(writer);
456 }
457 fn table_type(&self) -> TableType {
458 TableType::Named("VariationRegion")
459 }
460}
461
462impl Validate for VariationRegion {
463 fn validate_impl(&self, ctx: &mut ValidationCtx) {
464 ctx.in_table("VariationRegion", |ctx| {
465 ctx.in_field("region_axes", |ctx| {
466 if self.region_axes.len() > (u16::MAX as usize) {
467 ctx.report("array exceeds max length");
468 }
469 self.region_axes.validate_impl(ctx);
470 });
471 })
472 }
473}
474
475impl FromObjRef<read_fonts::tables::variations::VariationRegion<'_>> for VariationRegion {
476 fn from_obj_ref(
477 obj: &read_fonts::tables::variations::VariationRegion,
478 offset_data: FontData,
479 ) -> Self {
480 VariationRegion {
481 region_axes: obj.region_axes().to_owned_obj(offset_data),
482 }
483 }
484}
485
486#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
488#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
489pub struct RegionAxisCoordinates {
490 pub start_coord: F2Dot14,
492 pub peak_coord: F2Dot14,
494 pub end_coord: F2Dot14,
496}
497
498impl RegionAxisCoordinates {
499 pub fn new(start_coord: F2Dot14, peak_coord: F2Dot14, end_coord: F2Dot14) -> Self {
501 Self {
502 start_coord,
503 peak_coord,
504 end_coord,
505 }
506 }
507}
508
509impl FontWrite for RegionAxisCoordinates {
510 fn write_into(&self, writer: &mut TableWriter) {
511 self.start_coord.write_into(writer);
512 self.peak_coord.write_into(writer);
513 self.end_coord.write_into(writer);
514 }
515 fn table_type(&self) -> TableType {
516 TableType::Named("RegionAxisCoordinates")
517 }
518}
519
520impl Validate for RegionAxisCoordinates {
521 fn validate_impl(&self, _ctx: &mut ValidationCtx) {}
522}
523
524impl FromObjRef<read_fonts::tables::variations::RegionAxisCoordinates> for RegionAxisCoordinates {
525 fn from_obj_ref(
526 obj: &read_fonts::tables::variations::RegionAxisCoordinates,
527 _: FontData,
528 ) -> Self {
529 RegionAxisCoordinates {
530 start_coord: obj.start_coord(),
531 peak_coord: obj.peak_coord(),
532 end_coord: obj.end_coord(),
533 }
534 }
535}
536
537#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
539#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
540pub struct ItemVariationStore {
541 pub variation_region_list: OffsetMarker<VariationRegionList, WIDTH_32>,
544 pub item_variation_data: Vec<NullableOffsetMarker<ItemVariationData, WIDTH_32>>,
547}
548
549impl ItemVariationStore {
550 pub fn new(
552 variation_region_list: VariationRegionList,
553 item_variation_data: Vec<Option<ItemVariationData>>,
554 ) -> Self {
555 Self {
556 variation_region_list: variation_region_list.into(),
557 item_variation_data: item_variation_data.into_iter().map(Into::into).collect(),
558 }
559 }
560}
561
562impl FontWrite for ItemVariationStore {
563 #[allow(clippy::unnecessary_cast)]
564 fn write_into(&self, writer: &mut TableWriter) {
565 (1 as u16).write_into(writer);
566 self.variation_region_list.write_into(writer);
567 (u16::try_from(array_len(&self.item_variation_data)).unwrap()).write_into(writer);
568 self.item_variation_data.write_into(writer);
569 }
570 fn table_type(&self) -> TableType {
571 TableType::Named("ItemVariationStore")
572 }
573}
574
575impl Validate for ItemVariationStore {
576 fn validate_impl(&self, ctx: &mut ValidationCtx) {
577 ctx.in_table("ItemVariationStore", |ctx| {
578 ctx.in_field("variation_region_list", |ctx| {
579 self.variation_region_list.validate_impl(ctx);
580 });
581 ctx.in_field("item_variation_data", |ctx| {
582 if self.item_variation_data.len() > (u16::MAX as usize) {
583 ctx.report("array exceeds max length");
584 }
585 self.item_variation_data.validate_impl(ctx);
586 });
587 })
588 }
589}
590
591impl<'a> FromObjRef<read_fonts::tables::variations::ItemVariationStore<'a>> for ItemVariationStore {
592 fn from_obj_ref(
593 obj: &read_fonts::tables::variations::ItemVariationStore<'a>,
594 _: FontData,
595 ) -> Self {
596 ItemVariationStore {
597 variation_region_list: obj.variation_region_list().to_owned_table(),
598 item_variation_data: obj.item_variation_data().to_owned_table(),
599 }
600 }
601}
602
603#[allow(clippy::needless_lifetimes)]
604impl<'a> FromTableRef<read_fonts::tables::variations::ItemVariationStore<'a>>
605 for ItemVariationStore
606{
607}
608
609impl<'a> FontRead<'a> for ItemVariationStore {
610 fn read(data: FontData<'a>) -> Result<Self, ReadError> {
611 <read_fonts::tables::variations::ItemVariationStore as FontRead>::read(data)
612 .map(|x| x.to_owned_table())
613 }
614}
615
616#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
618#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
619pub struct ItemVariationData {
620 pub item_count: u16,
622 pub word_delta_count: u16,
624 pub region_indexes: Vec<u16>,
627 pub delta_sets: Vec<u8>,
629}
630
631impl ItemVariationData {
632 pub fn new(
634 item_count: u16,
635 word_delta_count: u16,
636 region_indexes: Vec<u16>,
637 delta_sets: Vec<u8>,
638 ) -> Self {
639 Self {
640 item_count,
641 word_delta_count,
642 region_indexes,
643 delta_sets,
644 }
645 }
646}
647
648impl FontWrite for ItemVariationData {
649 #[allow(clippy::unnecessary_cast)]
650 fn write_into(&self, writer: &mut TableWriter) {
651 self.item_count.write_into(writer);
652 self.word_delta_count.write_into(writer);
653 (u16::try_from(array_len(&self.region_indexes)).unwrap()).write_into(writer);
654 self.region_indexes.write_into(writer);
655 self.delta_sets.write_into(writer);
656 }
657 fn table_type(&self) -> TableType {
658 TableType::Named("ItemVariationData")
659 }
660}
661
662impl Validate for ItemVariationData {
663 fn validate_impl(&self, ctx: &mut ValidationCtx) {
664 ctx.in_table("ItemVariationData", |ctx| {
665 ctx.in_field("region_indexes", |ctx| {
666 if self.region_indexes.len() > (u16::MAX as usize) {
667 ctx.report("array exceeds max length");
668 }
669 });
670 })
671 }
672}
673
674impl<'a> FromObjRef<read_fonts::tables::variations::ItemVariationData<'a>> for ItemVariationData {
675 fn from_obj_ref(
676 obj: &read_fonts::tables::variations::ItemVariationData<'a>,
677 _: FontData,
678 ) -> Self {
679 let offset_data = obj.offset_data();
680 ItemVariationData {
681 item_count: obj.item_count(),
682 word_delta_count: obj.word_delta_count(),
683 region_indexes: obj.region_indexes().to_owned_obj(offset_data),
684 delta_sets: obj.delta_sets().to_owned_obj(offset_data),
685 }
686 }
687}
688
689#[allow(clippy::needless_lifetimes)]
690impl<'a> FromTableRef<read_fonts::tables::variations::ItemVariationData<'a>> for ItemVariationData {}
691
692impl<'a> FontRead<'a> for ItemVariationData {
693 fn read(data: FontData<'a>) -> Result<Self, ReadError> {
694 <read_fonts::tables::variations::ItemVariationData as FontRead>::read(data)
695 .map(|x| x.to_owned_table())
696 }
697}