1 | #ifndef OT_LAYOUT_GPOS_SINGLEPOSFORMAT1_HH |
2 | #define OT_LAYOUT_GPOS_SINGLEPOSFORMAT1_HH |
3 | |
4 | #include "Common.hh" |
5 | #include "ValueFormat.hh" |
6 | |
7 | namespace OT { |
8 | namespace Layout { |
9 | namespace GPOS_impl { |
10 | |
11 | struct SinglePosFormat1 |
12 | { |
13 | protected: |
14 | HBUINT16 format; /* Format identifier--format = 1 */ |
15 | Offset16To<Coverage> |
16 | coverage; /* Offset to Coverage table--from |
17 | * beginning of subtable */ |
18 | ValueFormat valueFormat; /* Defines the types of data in the |
19 | * ValueRecord */ |
20 | ValueRecord values; /* Defines positioning |
21 | * value(s)--applied to all glyphs in |
22 | * the Coverage table */ |
23 | public: |
24 | DEFINE_SIZE_ARRAY (6, values); |
25 | |
26 | bool sanitize (hb_sanitize_context_t *c) const |
27 | { |
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. |
35 | * |
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)); |
39 | |
40 | } |
41 | |
42 | bool intersects (const hb_set_t *glyphs) const |
43 | { return (this+coverage).intersects (glyphs); } |
44 | |
45 | void closure_lookups (hb_closure_lookups_context_t *c) const {} |
46 | void collect_variation_indices (hb_collect_variation_indices_context_t *c) const |
47 | { |
48 | if (!valueFormat.has_device ()) return; |
49 | |
50 | hb_set_t intersection; |
51 | (this+coverage).intersect_set (*c->glyph_set, intersection); |
52 | if (!intersection) return; |
53 | |
54 | valueFormat.collect_variation_indices (c, this, values.as_array (valueFormat.get_len ())); |
55 | } |
56 | |
57 | void collect_glyphs (hb_collect_glyphs_context_t *c) const |
58 | { if (unlikely (!(this+coverage).collect_coverage (c->input))) return; } |
59 | |
60 | const Coverage &get_coverage () const { return this+coverage; } |
61 | |
62 | ValueFormat get_value_format () const { return valueFormat; } |
63 | |
64 | 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 (HB_BUFFER_MESSAGE_MORE && c->buffer->messaging ()) |
72 | { |
73 | c->buffer->message (c->font, |
74 | "positioning glyph at %u" , |
75 | c->buffer->idx); |
76 | } |
77 | |
78 | valueFormat.apply_value (c, this, values, buffer->cur_pos()); |
79 | |
80 | if (HB_BUFFER_MESSAGE_MORE && c->buffer->messaging ()) |
81 | { |
82 | c->buffer->message (c->font, |
83 | "positioned glyph at %u" , |
84 | c->buffer->idx); |
85 | } |
86 | |
87 | buffer->idx++; |
88 | return_trace (true); |
89 | } |
90 | |
91 | bool |
92 | position_single (hb_font_t *font, |
93 | hb_blob_t *table_blob, |
94 | hb_direction_t direction, |
95 | hb_codepoint_t gid, |
96 | hb_glyph_position_t &pos) const |
97 | { |
98 | unsigned int index = (this+coverage).get_coverage (gid); |
99 | if (likely (index == NOT_COVERED)) return false; |
100 | |
101 | /* This is ugly... */ |
102 | hb_buffer_t buffer; |
103 | buffer.props.direction = direction; |
104 | OT::hb_ot_apply_context_t c (1, font, &buffer, table_blob); |
105 | |
106 | valueFormat.apply_value (&c, this, values, pos); |
107 | return true; |
108 | } |
109 | |
110 | template<typename Iterator, |
111 | typename SrcLookup, |
112 | hb_requires (hb_is_iterator (Iterator))> |
113 | void serialize (hb_serialize_context_t *c, |
114 | const SrcLookup *src, |
115 | Iterator it, |
116 | ValueFormat newFormat, |
117 | const hb_hashmap_t<unsigned, hb_pair_t<unsigned, int>> *layout_variation_idx_delta_map) |
118 | { |
119 | if (unlikely (!c->extend_min (this))) return; |
120 | if (unlikely (!c->check_assign (valueFormat, |
121 | newFormat, |
122 | HB_SERIALIZE_ERROR_INT_OVERFLOW))) return; |
123 | |
124 | for (const hb_array_t<const Value>& _ : + it | hb_map (hb_second)) |
125 | { |
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 |
128 | // be the same. |
129 | break; |
130 | } |
131 | |
132 | auto glyphs = |
133 | + it |
134 | | hb_map_retains_sorting (hb_first) |
135 | ; |
136 | |
137 | coverage.serialize_serialize (c, glyphs); |
138 | } |
139 | |
140 | bool subset (hb_subset_context_t *c) const |
141 | { |
142 | TRACE_SUBSET (this); |
143 | const hb_set_t &glyphset = *c->plan->glyphset_gsub (); |
144 | const hb_map_t &glyph_map = *c->plan->glyph_map; |
145 | |
146 | hb_set_t intersection; |
147 | (this+coverage).intersect_set (glyphset, intersection); |
148 | |
149 | auto it = |
150 | + hb_iter (intersection) |
151 | | hb_map_retains_sorting (glyph_map) |
152 | | hb_zip (hb_repeat (values.as_array (valueFormat.get_len ()))) |
153 | ; |
154 | |
155 | bool ret = bool (it); |
156 | SinglePos_serialize (c->serializer, this, it, &c->plan->layout_variation_idx_delta_map, c->plan->all_axes_pinned); |
157 | return_trace (ret); |
158 | } |
159 | }; |
160 | |
161 | } |
162 | } |
163 | } |
164 | |
165 | #endif /* OT_LAYOUT_GPOS_SINGLEPOSFORMAT1_HH */ |
166 | |