1 #ifndef OT_LAYOUT_GPOS_SINGLEPOSFORMAT1_HH
2 #define OT_LAYOUT_GPOS_SINGLEPOSFORMAT1_HH
5 #include "ValueFormat.hh"
11 struct SinglePosFormat1
14 HBUINT16 format; /* Format identifier--format = 1 */
16 coverage; /* Offset to Coverage table--from
17 * beginning of subtable */
18 ValueFormat valueFormat; /* Defines the types of data in the
20 ValueRecord values; /* Defines positioning
21 * value(s)--applied to all glyphs in
22 * the Coverage table */
24 DEFINE_SIZE_ARRAY (6, values);
26 bool sanitize (hb_sanitize_context_t *c) const
28 TRACE_SANITIZE (this);
29 return_trace (c->check_struct (this) &&
30 coverage.sanitize (c, this) &&
31 /* The coverage table may use a range to represent a set
32 * of glyphs, which means a small number of bytes can
33 * generate a large glyph set. Manually modify the
34 * sanitizer max ops to take this into account.
36 * Note: This check *must* be right after coverage sanitize. */
37 c->check_ops ((this + coverage).get_population () >> 1) &&
38 valueFormat.sanitize_value (c, this, values));
42 bool intersects (const hb_set_t *glyphs) const
43 { return (this+coverage).intersects (glyphs); }
45 void closure_lookups (hb_closure_lookups_context_t *c) const {}
46 void collect_variation_indices (hb_collect_variation_indices_context_t *c) const
48 if (!valueFormat.has_device ()) return;
50 hb_set_t intersection;
51 (this+coverage).intersect_set (*c->glyph_set, intersection);
52 if (!intersection) return;
54 valueFormat.collect_variation_indices (c, this, values.as_array (valueFormat.get_len ()));
57 void collect_glyphs (hb_collect_glyphs_context_t *c) const
58 { if (unlikely (!(this+coverage).collect_coverage (c->input))) return; }
60 const Coverage &get_coverage () const { return this+coverage; }
62 ValueFormat get_value_format () const { return valueFormat; }
64 bool apply (hb_ot_apply_context_t *c) const
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);
71 if (HB_BUFFER_MESSAGE_MORE && c->buffer->messaging ())
73 c->buffer->message (c->font,
74 "positioning glyph at %u",
78 valueFormat.apply_value (c, this, values, buffer->cur_pos());
80 if (HB_BUFFER_MESSAGE_MORE && c->buffer->messaging ())
82 c->buffer->message (c->font,
83 "positioned glyph at %u",
92 position_single (hb_font_t *font,
93 hb_blob_t *table_blob,
94 hb_direction_t direction,
96 hb_glyph_position_t &pos) const
98 unsigned int index = (this+coverage).get_coverage (gid);
99 if (likely (index == NOT_COVERED)) return false;
101 /* This is ugly... */
103 buffer.props.direction = direction;
104 OT::hb_ot_apply_context_t c (1, font, &buffer, table_blob);
106 valueFormat.apply_value (&c, this, values, pos);
110 template<typename Iterator,
112 hb_requires (hb_is_iterator (Iterator))>
113 void serialize (hb_serialize_context_t *c,
114 const SrcLookup *src,
116 ValueFormat newFormat,
117 const hb_hashmap_t<unsigned, hb_pair_t<unsigned, int>> *layout_variation_idx_delta_map)
119 if (unlikely (!c->extend_min (this))) return;
120 if (unlikely (!c->check_assign (valueFormat,
122 HB_SERIALIZE_ERROR_INT_OVERFLOW))) return;
124 for (const hb_array_t<const Value>& _ : + it | hb_map (hb_second))
126 src->get_value_format ().copy_values (c, newFormat, src, &_, layout_variation_idx_delta_map);
127 // Only serialize the first entry in the iterator, the rest are assumed to
134 | hb_map_retains_sorting (hb_first)
137 coverage.serialize_serialize (c, glyphs);
140 bool subset (hb_subset_context_t *c) const
143 const hb_set_t &glyphset = *c->plan->glyphset_gsub ();
144 const hb_map_t &glyph_map = *c->plan->glyph_map;
146 hb_set_t intersection;
147 (this+coverage).intersect_set (glyphset, intersection);
150 + hb_iter (intersection)
151 | hb_map_retains_sorting (glyph_map)
152 | hb_zip (hb_repeat (values.as_array (valueFormat.get_len ())))
155 bool ret = bool (it);
156 SinglePos_serialize (c->serializer, this, it, &c->plan->layout_variation_idx_delta_map, c->plan->all_axes_pinned);
165 #endif /* OT_LAYOUT_GPOS_SINGLEPOSFORMAT1_HH */