/work/workdir/UnpackedTarball/harfbuzz/src/hb-ot-shape.hh
Line | Count | Source |
1 | | /* |
2 | | * Copyright © 2010 Google, Inc. |
3 | | * |
4 | | * This is part of HarfBuzz, a text shaping library. |
5 | | * |
6 | | * Permission is hereby granted, without written agreement and without |
7 | | * license or royalty fees, to use, copy, modify, and distribute this |
8 | | * software and its documentation for any purpose, provided that the |
9 | | * above copyright notice and the following two paragraphs appear in |
10 | | * all copies of this software. |
11 | | * |
12 | | * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR |
13 | | * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES |
14 | | * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN |
15 | | * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH |
16 | | * DAMAGE. |
17 | | * |
18 | | * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, |
19 | | * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND |
20 | | * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS |
21 | | * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO |
22 | | * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
23 | | * |
24 | | * Google Author(s): Behdad Esfahbod |
25 | | */ |
26 | | |
27 | | #ifndef HB_OT_SHAPE_HH |
28 | | #define HB_OT_SHAPE_HH |
29 | | |
30 | | #include "hb.hh" |
31 | | |
32 | | #include "hb-ot-map.hh" |
33 | | #include "hb-aat-map.hh" |
34 | | |
35 | | |
36 | | HB_INTERNAL bool |
37 | | _hb_ot_layout_table_get_feature_variations_state (hb_face_t *face, |
38 | | hb_tag_t table_tag, |
39 | | const int *coords, |
40 | | unsigned int num_coords, |
41 | | unsigned int *variations_index, |
42 | | hb_vector_t<unsigned> *lookup_variations); |
43 | | |
44 | | struct hb_ot_shape_plan_key_t |
45 | | { |
46 | | unsigned int variations_index[2]; |
47 | | hb_vector_t<unsigned> lookup_variations[2]; |
48 | | |
49 | | bool init (hb_face_t *face, |
50 | | const int *coords, |
51 | | unsigned num_coords) |
52 | 17.5M | { |
53 | 52.7M | for (unsigned int table_index = 0; table_index < 2; table_index++) |
54 | 35.1M | if (unlikely (!_hb_ot_layout_table_get_feature_variations_state ( |
55 | 35.1M | face, |
56 | 35.1M | table_tags[table_index], |
57 | 35.1M | coords, |
58 | 35.1M | num_coords, |
59 | 35.1M | &variations_index[table_index], |
60 | 35.1M | &lookup_variations[table_index]))) |
61 | 0 | { |
62 | 0 | for (auto &v : lookup_variations) |
63 | 0 | v.fini (); |
64 | 0 | return false; |
65 | 0 | } |
66 | 17.5M | return true; |
67 | 17.5M | } |
68 | | |
69 | | void fini () |
70 | 0 | { |
71 | 0 | for (auto &v : lookup_variations) |
72 | 0 | v.fini (); |
73 | 0 | } |
74 | | |
75 | | bool get_lookup_variations (unsigned int table_index, |
76 | | unsigned int feature_index, |
77 | | hb_array_t<const unsigned> &lookups) const |
78 | 16.9k | { |
79 | 16.9k | hb_array_t<const unsigned> state = lookup_variations[table_index].as_array (); |
80 | 16.9k | for (unsigned i = 0; i + 2 <= state.length;) |
81 | 0 | { |
82 | 0 | unsigned index = state[i++]; |
83 | 0 | unsigned count = state[i++]; |
84 | 0 | if (unlikely (count > state.length - i)) |
85 | 0 | return false; |
86 | 0 | if (index == feature_index) |
87 | 0 | { |
88 | 0 | lookups = state.sub_array (i, count); |
89 | 0 | return true; |
90 | 0 | } |
91 | 0 | i += count; |
92 | 0 | } |
93 | 16.9k | return false; |
94 | 16.9k | } |
95 | | |
96 | | bool equal (const hb_ot_shape_plan_key_t *other) |
97 | 17.5M | { |
98 | 17.5M | return variations_index[0] == other->variations_index[0] && |
99 | 17.5M | variations_index[1] == other->variations_index[1] && |
100 | 17.5M | lookup_variations[0] == other->lookup_variations[0] && |
101 | 17.5M | lookup_variations[1] == other->lookup_variations[1]; |
102 | 17.5M | } |
103 | | }; |
104 | | |
105 | | |
106 | | struct hb_shape_plan_key_t; |
107 | | |
108 | | struct hb_ot_shape_plan_t |
109 | | { |
110 | 0 | ~hb_ot_shape_plan_t () { fini (); } |
111 | | |
112 | | hb_segment_properties_t props; |
113 | | const struct hb_ot_shaper_t *shaper; |
114 | | hb_ot_map_t map; |
115 | | hb_aat_map_t aat_map; |
116 | | const void *data; |
117 | | #ifndef HB_NO_OT_SHAPE_FRACTIONS |
118 | | hb_mask_t frac_mask, numr_mask, dnom_mask; |
119 | | #else |
120 | | static constexpr hb_mask_t frac_mask = 0; |
121 | | static constexpr hb_mask_t numr_mask = 0; |
122 | | static constexpr hb_mask_t dnom_mask = 0; |
123 | | #endif |
124 | | hb_mask_t rtlm_mask; |
125 | | #ifndef HB_NO_OT_KERN |
126 | | hb_mask_t kern_mask; |
127 | | #else |
128 | | static constexpr hb_mask_t kern_mask = 0; |
129 | | #endif |
130 | | |
131 | | #ifndef HB_NO_OT_KERN |
132 | | bool requested_kerning : 1; |
133 | | #else |
134 | | static constexpr bool requested_kerning = false; |
135 | | #endif |
136 | | #ifndef HB_NO_OT_SHAPE_FRACTIONS |
137 | | bool has_frac : 1; |
138 | | #else |
139 | | static constexpr bool has_frac = false; |
140 | | #endif |
141 | | bool has_vert : 1; |
142 | | bool has_gpos_mark : 1; |
143 | | bool zero_marks : 1; |
144 | | bool fallback_glyph_classes : 1; |
145 | | bool fallback_mark_positioning : 1; |
146 | | bool adjust_mark_positioning_when_zeroing : 1; |
147 | | |
148 | | bool apply_gpos : 1; |
149 | | #ifndef HB_NO_OT_KERN |
150 | | bool apply_kern : 1; |
151 | | #else |
152 | | static constexpr bool apply_kern = false; |
153 | | #endif |
154 | | bool apply_fallback_kern : 1; |
155 | | #ifndef HB_NO_AAT_SHAPE |
156 | | bool apply_kerx : 1; |
157 | | bool apply_morx : 1; |
158 | | bool apply_trak : 1; |
159 | | #else |
160 | | static constexpr bool apply_kerx = false; |
161 | | static constexpr bool apply_morx = false; |
162 | | static constexpr bool apply_trak = false; |
163 | | #endif |
164 | | |
165 | | void collect_lookups (hb_tag_t table_tag, hb_set_t *lookups) const |
166 | 0 | { |
167 | 0 | unsigned int table_index; |
168 | 0 | switch (table_tag) { |
169 | 0 | case HB_OT_TAG_GSUB: table_index = 0; break; |
170 | 0 | case HB_OT_TAG_GPOS: table_index = 1; break; |
171 | 0 | default: return; |
172 | 0 | } |
173 | 0 | map.collect_lookups (table_index, lookups); |
174 | 0 | } |
175 | | |
176 | | HB_INTERNAL bool init0 (hb_face_t *face, |
177 | | const hb_shape_plan_key_t *key); |
178 | | HB_INTERNAL void fini (); |
179 | | |
180 | | HB_INTERNAL void substitute (hb_font_t *font, hb_buffer_t *buffer) const; |
181 | | HB_INTERNAL void position (hb_font_t *font, hb_buffer_t *buffer) const; |
182 | | }; |
183 | | |
184 | | struct hb_shape_plan_t; |
185 | | |
186 | | struct hb_ot_shape_planner_t |
187 | | { |
188 | | /* In the order that they are filled in. */ |
189 | | hb_face_t *face; |
190 | | hb_segment_properties_t props; |
191 | | hb_ot_map_builder_t map; |
192 | | #ifndef HB_NO_AAT_SHAPE |
193 | | hb_aat_map_builder_t aat_map; |
194 | | bool apply_morx : 1; |
195 | | #else |
196 | | static constexpr bool apply_morx = false; |
197 | | #endif |
198 | | bool script_zero_marks : 1; |
199 | | bool script_fallback_position : 1; |
200 | | const struct hb_ot_shaper_t *shaper; |
201 | | |
202 | | HB_INTERNAL hb_ot_shape_planner_t (hb_face_t *face, |
203 | | const hb_segment_properties_t &props); |
204 | | |
205 | | HB_INTERNAL void compile (hb_ot_shape_plan_t &plan, |
206 | | const hb_ot_shape_plan_key_t &key); |
207 | | }; |
208 | | |
209 | | |
210 | | #endif /* HB_OT_SHAPE_HH */ |