• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef OT_LAYOUT_GPOS_SINGLEPOSFORMAT2_HH
2 #define OT_LAYOUT_GPOS_SINGLEPOSFORMAT2_HH
3 
4 #include "Common.hh"
5 
6 namespace OT {
7 namespace Layout {
8 namespace GPOS_impl {
9 
10 struct SinglePosFormat2
11 {
12   protected:
13   HBUINT16      format;                 /* Format identifier--format = 2 */
14   Offset16To<Coverage>
15                 coverage;               /* Offset to Coverage table--from
16                                          * beginning of subtable */
17   ValueFormat   valueFormat;            /* Defines the types of data in the
18                                          * ValueRecord */
19   HBUINT16      valueCount;             /* Number of ValueRecords */
20   ValueRecord   values;                 /* Array of ValueRecords--positioning
21                                          * values applied to glyphs */
22   public:
23   DEFINE_SIZE_ARRAY (8, values);
24 
sanitizeOT::Layout::GPOS_impl::SinglePosFormat225   bool sanitize (hb_sanitize_context_t *c) const
26   {
27     TRACE_SANITIZE (this);
28     return_trace (c->check_struct (this) &&
29                   coverage.sanitize (c, this) &&
30                   valueFormat.sanitize_values (c, this, values, valueCount));
31   }
32 
intersectsOT::Layout::GPOS_impl::SinglePosFormat233   bool intersects (const hb_set_t *glyphs) const
34   { return (this+coverage).intersects (glyphs); }
35 
closure_lookupsOT::Layout::GPOS_impl::SinglePosFormat236   void closure_lookups (hb_closure_lookups_context_t *c) const {}
collect_variation_indicesOT::Layout::GPOS_impl::SinglePosFormat237   void collect_variation_indices (hb_collect_variation_indices_context_t *c) const
38   {
39     if (!valueFormat.has_device ()) return;
40 
41     auto it =
42     + hb_zip (this+coverage, hb_range ((unsigned) valueCount))
43     | hb_filter (c->glyph_set, hb_first)
44     ;
45 
46     if (!it) return;
47 
48     unsigned sub_length = valueFormat.get_len ();
49     const hb_array_t<const Value> values_array = values.as_array (valueCount * sub_length);
50 
51     for (unsigned i : + it
52                       | hb_map (hb_second))
53       valueFormat.collect_variation_indices (c, this, values_array.sub_array (i * sub_length, sub_length));
54 
55   }
56 
collect_glyphsOT::Layout::GPOS_impl::SinglePosFormat257   void collect_glyphs (hb_collect_glyphs_context_t *c) const
58   { if (unlikely (!(this+coverage).collect_coverage (c->input))) return; }
59 
get_coverageOT::Layout::GPOS_impl::SinglePosFormat260   const Coverage &get_coverage () const { return this+coverage; }
61 
get_value_formatOT::Layout::GPOS_impl::SinglePosFormat262   ValueFormat get_value_format () const { return valueFormat; }
63 
applyOT::Layout::GPOS_impl::SinglePosFormat264   bool apply (hb_ot_apply_context_t *c) const
65   {
66     TRACE_APPLY (this);
67     hb_buffer_t *buffer = c->buffer;
68     unsigned int index = (this+coverage).get_coverage  (buffer->cur().codepoint);
69     if (likely (index == NOT_COVERED)) return_trace (false);
70 
71     if (unlikely (index >= valueCount)) return_trace (false);
72 
73     if (HB_BUFFER_MESSAGE_MORE && c->buffer->messaging ())
74     {
75       c->buffer->message (c->font,
76 			  "positioning glyph at %d",
77 			  c->buffer->idx);
78     }
79 
80     valueFormat.apply_value (c, this,
81                              &values[index * valueFormat.get_len ()],
82                              buffer->cur_pos());
83 
84     if (HB_BUFFER_MESSAGE_MORE && c->buffer->messaging ())
85     {
86       c->buffer->message (c->font,
87 			  "positioned glyph at %d",
88 			  c->buffer->idx);
89     }
90 
91     buffer->idx++;
92     return_trace (true);
93   }
94 
95   bool
position_singleOT::Layout::GPOS_impl::SinglePosFormat296   position_single (hb_font_t           *font,
97 		   hb_direction_t       direction,
98 		   hb_codepoint_t       gid,
99 		   hb_glyph_position_t &pos) const
100   {
101     unsigned int index = (this+coverage).get_coverage  (gid);
102     if (likely (index == NOT_COVERED)) return false;
103     if (unlikely (index >= valueCount)) return false;
104 
105     /* This is ugly... */
106     hb_buffer_t buffer;
107     buffer.props.direction = direction;
108     OT::hb_ot_apply_context_t c (1, font, &buffer);
109 
110     valueFormat.apply_value (&c, this,
111                              &values[index * valueFormat.get_len ()],
112                              pos);
113     return true;
114   }
115 
116 
117   template<typename Iterator,
118       typename SrcLookup,
119       hb_requires (hb_is_iterator (Iterator))>
serializeOT::Layout::GPOS_impl::SinglePosFormat2120   void serialize (hb_serialize_context_t *c,
121                   const SrcLookup *src,
122                   Iterator it,
123                   ValueFormat newFormat,
124                   const hb_hashmap_t<unsigned, hb_pair_t<unsigned, int>> *layout_variation_idx_delta_map)
125   {
126     auto out = c->extend_min (this);
127     if (unlikely (!out)) return;
128     if (unlikely (!c->check_assign (valueFormat, newFormat, HB_SERIALIZE_ERROR_INT_OVERFLOW))) return;
129     if (unlikely (!c->check_assign (valueCount, it.len (), HB_SERIALIZE_ERROR_ARRAY_OVERFLOW))) return;
130 
131     + it
132     | hb_map (hb_second)
133     | hb_apply ([&] (hb_array_t<const Value> _)
134     { src->get_value_format ().copy_values (c, newFormat, src, &_, layout_variation_idx_delta_map); })
135     ;
136 
137     auto glyphs =
138     + it
139     | hb_map_retains_sorting (hb_first)
140     ;
141 
142     coverage.serialize_serialize (c, glyphs);
143   }
144 
subsetOT::Layout::GPOS_impl::SinglePosFormat2145   bool subset (hb_subset_context_t *c) const
146   {
147     TRACE_SUBSET (this);
148     const hb_set_t &glyphset = *c->plan->glyphset_gsub ();
149     const hb_map_t &glyph_map = *c->plan->glyph_map;
150 
151     unsigned sub_length = valueFormat.get_len ();
152     auto values_array = values.as_array (valueCount * sub_length);
153 
154     auto it =
155     + hb_zip (this+coverage, hb_range ((unsigned) valueCount))
156     | hb_filter (glyphset, hb_first)
157     | hb_map_retains_sorting ([&] (const hb_pair_t<hb_codepoint_t, unsigned>& _)
158                               {
159                                 return hb_pair (glyph_map[_.first],
160                                                 values_array.sub_array (_.second * sub_length,
161                                                                         sub_length));
162                               })
163     ;
164 
165     bool ret = bool (it);
166     SinglePos_serialize (c->serializer, this, it, c->plan->layout_variation_idx_delta_map, c->plan->all_axes_pinned);
167     return_trace (ret);
168   }
169 };
170 
171 
172 }
173 }
174 }
175 
176 #endif /* OT_LAYOUT_GPOS_SINGLEPOSFORMAT2_HH */
177