xref: /aosp_15_r20/external/harfbuzz_ng/src/OT/Layout/GPOS/SinglePos.hh (revision 2d1272b857b1f7575e6e246373e1cb218663db8a)
1 #ifndef OT_LAYOUT_GPOS_SINGLEPOS_HH
2 #define OT_LAYOUT_GPOS_SINGLEPOS_HH
3 
4 #include "SinglePosFormat1.hh"
5 #include "SinglePosFormat2.hh"
6 
7 namespace OT {
8 namespace Layout {
9 namespace GPOS_impl {
10 
11 struct SinglePos
12 {
13   protected:
14   union {
15   HBUINT16              format;         /* Format identifier */
16   SinglePosFormat1      format1;
17   SinglePosFormat2      format2;
18   } u;
19 
20   public:
21   template<typename Iterator,
22            hb_requires (hb_is_iterator (Iterator))>
get_formatOT::Layout::GPOS_impl::SinglePos23   unsigned get_format (Iterator glyph_val_iter_pairs)
24   {
25     hb_array_t<const Value> first_val_iter = hb_second (*glyph_val_iter_pairs);
26 
27     for (const auto iter : glyph_val_iter_pairs)
28       for (const auto _ : hb_zip (iter.second, first_val_iter))
29         if (_.first != _.second)
30           return 2;
31 
32     return 1;
33   }
34 
35   template<typename Iterator,
36       typename SrcLookup,
37       hb_requires (hb_is_iterator (Iterator))>
serializeOT::Layout::GPOS_impl::SinglePos38   void serialize (hb_serialize_context_t *c,
39                   const SrcLookup* src,
40                   Iterator glyph_val_iter_pairs,
41                   const hb_hashmap_t<unsigned, hb_pair_t<unsigned, int>> *layout_variation_idx_delta_map,
42                   unsigned newFormat)
43   {
44     if (unlikely (!c->extend_min (u.format))) return;
45     unsigned format = 2;
46     ValueFormat new_format;
47     new_format = newFormat;
48 
49     if (glyph_val_iter_pairs)
50       format = get_format (glyph_val_iter_pairs);
51 
52     u.format = format;
53     switch (u.format) {
54     case 1: u.format1.serialize (c,
55                                  src,
56                                  glyph_val_iter_pairs,
57                                  new_format,
58                                  layout_variation_idx_delta_map);
59       return;
60     case 2: u.format2.serialize (c,
61                                  src,
62                                  glyph_val_iter_pairs,
63                                  new_format,
64                                  layout_variation_idx_delta_map);
65       return;
66     default:return;
67     }
68   }
69 
70   template <typename context_t, typename ...Ts>
dispatchOT::Layout::GPOS_impl::SinglePos71   typename context_t::return_t dispatch (context_t *c, Ts&&... ds) const
72   {
73     if (unlikely (!c->may_dispatch (this, &u.format))) return c->no_dispatch_return_value ();
74     TRACE_DISPATCH (this, u.format);
75     switch (u.format) {
76     case 1: return_trace (c->dispatch (u.format1, std::forward<Ts> (ds)...));
77     case 2: return_trace (c->dispatch (u.format2, std::forward<Ts> (ds)...));
78     default:return_trace (c->default_return_value ());
79     }
80   }
81 };
82 
83 
84 template<typename Iterator, typename SrcLookup>
85 static void
SinglePos_serialize(hb_serialize_context_t * c,const SrcLookup * src,Iterator it,const hb_hashmap_t<unsigned,hb_pair_t<unsigned,int>> * layout_variation_idx_delta_map,unsigned new_format)86 SinglePos_serialize (hb_serialize_context_t *c,
87                      const SrcLookup *src,
88                      Iterator it,
89                      const hb_hashmap_t<unsigned, hb_pair_t<unsigned, int>> *layout_variation_idx_delta_map,
90                      unsigned new_format)
91 { c->start_embed<SinglePos> ()->serialize (c, src, it, layout_variation_idx_delta_map, new_format); }
92 
93 
94 }
95 }
96 }
97 
98 #endif /* OT_LAYOUT_GPOS_SINGLEPOS_HH */
99