comparison mupdf-source/thirdparty/harfbuzz/src/OT/Layout/GPOS/SinglePosFormat1.hh @ 2:b50eed0cc0ef upstream

ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4. The directory name has changed: no version number in the expanded directory now.
author Franz Glasner <fzglas.hg@dom66.de>
date Mon, 15 Sep 2025 11:43:07 +0200
parents
children
comparison
equal deleted inserted replaced
1:1d09e1dec1d9 2:b50eed0cc0ef
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 valueFormat.sanitize_value (c, this, values));
32 }
33
34 bool intersects (const hb_set_t *glyphs) const
35 { return (this+coverage).intersects (glyphs); }
36
37 void closure_lookups (hb_closure_lookups_context_t *c) const {}
38 void collect_variation_indices (hb_collect_variation_indices_context_t *c) const
39 {
40 if (!valueFormat.has_device ()) return;
41
42 hb_set_t intersection;
43 (this+coverage).intersect_set (*c->glyph_set, intersection);
44 if (!intersection) return;
45
46 valueFormat.collect_variation_indices (c, this, values.as_array (valueFormat.get_len ()));
47 }
48
49 void collect_glyphs (hb_collect_glyphs_context_t *c) const
50 { if (unlikely (!(this+coverage).collect_coverage (c->input))) return; }
51
52 const Coverage &get_coverage () const { return this+coverage; }
53
54 ValueFormat get_value_format () const { return valueFormat; }
55
56 bool apply (hb_ot_apply_context_t *c) const
57 {
58 TRACE_APPLY (this);
59 hb_buffer_t *buffer = c->buffer;
60 unsigned int index = (this+coverage).get_coverage (buffer->cur().codepoint);
61 if (likely (index == NOT_COVERED)) return_trace (false);
62
63 if (HB_BUFFER_MESSAGE_MORE && c->buffer->messaging ())
64 {
65 c->buffer->message (c->font,
66 "positioning glyph at %d",
67 c->buffer->idx);
68 }
69
70 valueFormat.apply_value (c, this, values, buffer->cur_pos());
71
72 if (HB_BUFFER_MESSAGE_MORE && c->buffer->messaging ())
73 {
74 c->buffer->message (c->font,
75 "positioned glyph at %d",
76 c->buffer->idx);
77 }
78
79 buffer->idx++;
80 return_trace (true);
81 }
82
83 bool
84 position_single (hb_font_t *font,
85 hb_direction_t direction,
86 hb_codepoint_t gid,
87 hb_glyph_position_t &pos) const
88 {
89 unsigned int index = (this+coverage).get_coverage (gid);
90 if (likely (index == NOT_COVERED)) return false;
91
92 /* This is ugly... */
93 hb_buffer_t buffer;
94 buffer.props.direction = direction;
95 OT::hb_ot_apply_context_t c (1, font, &buffer);
96
97 valueFormat.apply_value (&c, this, values, pos);
98 return true;
99 }
100
101 template<typename Iterator,
102 typename SrcLookup,
103 hb_requires (hb_is_iterator (Iterator))>
104 void serialize (hb_serialize_context_t *c,
105 const SrcLookup *src,
106 Iterator it,
107 ValueFormat newFormat,
108 const hb_hashmap_t<unsigned, hb_pair_t<unsigned, int>> *layout_variation_idx_delta_map)
109 {
110 if (unlikely (!c->extend_min (this))) return;
111 if (unlikely (!c->check_assign (valueFormat,
112 newFormat,
113 HB_SERIALIZE_ERROR_INT_OVERFLOW))) return;
114
115 for (const hb_array_t<const Value>& _ : + it | hb_map (hb_second))
116 {
117 src->get_value_format ().copy_values (c, newFormat, src, &_, layout_variation_idx_delta_map);
118 // Only serialize the first entry in the iterator, the rest are assumed to
119 // be the same.
120 break;
121 }
122
123 auto glyphs =
124 + it
125 | hb_map_retains_sorting (hb_first)
126 ;
127
128 coverage.serialize_serialize (c, glyphs);
129 }
130
131 bool subset (hb_subset_context_t *c) const
132 {
133 TRACE_SUBSET (this);
134 const hb_set_t &glyphset = *c->plan->glyphset_gsub ();
135 const hb_map_t &glyph_map = *c->plan->glyph_map;
136
137 hb_set_t intersection;
138 (this+coverage).intersect_set (glyphset, intersection);
139
140 auto it =
141 + hb_iter (intersection)
142 | hb_map_retains_sorting (glyph_map)
143 | hb_zip (hb_repeat (values.as_array (valueFormat.get_len ())))
144 ;
145
146 bool ret = bool (it);
147 SinglePos_serialize (c->serializer, this, it, c->plan->layout_variation_idx_delta_map, c->plan->all_axes_pinned);
148 return_trace (ret);
149 }
150 };
151
152 }
153 }
154 }
155
156 #endif /* OT_LAYOUT_GPOS_SINGLEPOSFORMAT1_HH */