Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 652 lines (534 sloc) 19.112 kb
fd92a3d @behdad Starting public interface
behdad authored
1 /*
6f425b1 @behdad [GDEF] Finish internal API
behdad authored
2 * Copyright (C) 1998-2004 David Turner and Werner Lemberg
3 * Copyright (C) 2006 Behdad Esfahbod
ee58aae @behdad [HB] Update copyright years
behdad authored
4 * Copyright (C) 2007,2008,2009 Red Hat, Inc.
fd92a3d @behdad Starting public interface
behdad authored
5 *
c755cb3 @behdad Change header comment
behdad authored
6 * This is part of HarfBuzz, a text shaping library.
fd92a3d @behdad Starting public interface
behdad authored
7 *
8 * Permission is hereby granted, without written agreement and without
9 * license or royalty fees, to use, copy, modify, and distribute this
10 * software and its documentation for any purpose, provided that the
11 * above copyright notice and the following two paragraphs appear in
12 * all copies of this software.
13 *
14 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
15 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
16 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
17 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
18 * DAMAGE.
19 *
20 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
21 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
22 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
23 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
24 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
25 *
26 * Red Hat Author(s): Behdad Esfahbod
27 */
28
29 #define HB_OT_LAYOUT_CC
30
22da7fd @behdad Rename a few files to be C++ sources
behdad authored
31 #include "hb-ot-layout-private.hh"
fd92a3d @behdad Starting public interface
behdad authored
32
5f5b24f @behdad [OT] Rename C++ header files from *.h to *.hh
behdad authored
33 #include "hb-ot-layout-gdef-private.hh"
34 #include "hb-ot-layout-gsub-private.hh"
35 #include "hb-ot-layout-gpos-private.hh"
fd92a3d @behdad Starting public interface
behdad authored
36
6f425b1 @behdad [GDEF] Finish internal API
behdad authored
37
fd92a3d @behdad Starting public interface
behdad authored
38 #include <stdlib.h>
aff831e @behdad Implement glyph properties
behdad authored
39 #include <string.h>
40
acdba3f @behdad Prefer C linkage
behdad authored
41 HB_BEGIN_DECLS
42
fd92a3d @behdad Starting public interface
behdad authored
43
0a4399c @behdad Fix scale issues
behdad authored
44 hb_ot_layout_t *
45 _hb_ot_layout_new (hb_face_t *face)
4a26ea4 @behdad Finish script, language, and feature public API
behdad authored
46 {
0a4399c @behdad Fix scale issues
behdad authored
47 /* Remove this object altogether */
48 hb_ot_layout_t *layout = (hb_ot_layout_t *) calloc (1, sizeof (hb_ot_layout_t));
555d112 @behdad [GDEF] Fix bug in building synthetic GDEF
behdad authored
49
d60bb8c @behdad [HB] Hook Sanitizer up. Hell's breaking loose right now
behdad authored
50 layout->gdef_blob = Sanitizer<GDEF>::sanitize (hb_face_get_table (face, HB_OT_TAG_GDEF));
b435ab7 @behdad Fix accessing tables from NULL pointer
behdad authored
51 layout->gdef = Sanitizer<GDEF>::lock_instance (layout->gdef_blob);
70e0f2a @behdad [HB] Make it all work again
behdad authored
52
d60bb8c @behdad [HB] Hook Sanitizer up. Hell's breaking loose right now
behdad authored
53 layout->gsub_blob = Sanitizer<GSUB>::sanitize (hb_face_get_table (face, HB_OT_TAG_GSUB));
b435ab7 @behdad Fix accessing tables from NULL pointer
behdad authored
54 layout->gsub = Sanitizer<GSUB>::lock_instance (layout->gsub_blob);
70e0f2a @behdad [HB] Make it all work again
behdad authored
55
d60bb8c @behdad [HB] Hook Sanitizer up. Hell's breaking loose right now
behdad authored
56 layout->gpos_blob = Sanitizer<GPOS>::sanitize (hb_face_get_table (face, HB_OT_TAG_GPOS));
b435ab7 @behdad Fix accessing tables from NULL pointer
behdad authored
57 layout->gpos = Sanitizer<GPOS>::lock_instance (layout->gpos_blob);
0a4399c @behdad Fix scale issues
behdad authored
58
59 return layout;
f9cd101 @behdad Apply patch from Jonathan Kew
behdad authored
60 }
61
23c86aa @behdad [HB] Use face_t directly instead of ot_layout_t
behdad authored
62 void
0a4399c @behdad Fix scale issues
behdad authored
63 _hb_ot_layout_free (hb_ot_layout_t *layout)
fd92a3d @behdad Starting public interface
behdad authored
64 {
70e0f2a @behdad [HB] Make it all work again
behdad authored
65 hb_blob_unlock (layout->gdef_blob);
66 hb_blob_unlock (layout->gsub_blob);
67 hb_blob_unlock (layout->gpos_blob);
68
69 hb_blob_destroy (layout->gdef_blob);
70 hb_blob_destroy (layout->gsub_blob);
71 hb_blob_destroy (layout->gpos_blob);
679f41f @behdad [HB] Fix leak
behdad authored
72
73 free (layout->new_gdef.klasses);
23c86aa @behdad [HB] Use face_t directly instead of ot_layout_t
behdad authored
74 }
f9cd101 @behdad Apply patch from Jonathan Kew
behdad authored
75
23c86aa @behdad [HB] Use face_t directly instead of ot_layout_t
behdad authored
76 static const GDEF&
77 _get_gdef (hb_face_t *face)
78 {
ed4acbd @behdad Fix NULL dereference
behdad authored
79 return likely (face->ot_layout && face->ot_layout->gdef) ? *face->ot_layout->gdef : Null(GDEF);
23c86aa @behdad [HB] Use face_t directly instead of ot_layout_t
behdad authored
80 }
f9cd101 @behdad Apply patch from Jonathan Kew
behdad authored
81
23c86aa @behdad [HB] Use face_t directly instead of ot_layout_t
behdad authored
82 static const GSUB&
83 _get_gsub (hb_face_t *face)
fd92a3d @behdad Starting public interface
behdad authored
84 {
ed4acbd @behdad Fix NULL dereference
behdad authored
85 return likely (face->ot_layout && face->ot_layout->gsub) ? *face->ot_layout->gsub : Null(GSUB);
fd92a3d @behdad Starting public interface
behdad authored
86 }
87
23c86aa @behdad [HB] Use face_t directly instead of ot_layout_t
behdad authored
88 static const GPOS&
89 _get_gpos (hb_face_t *face)
2ebb89d @behdad Revert "XX"
behdad authored
90 {
ed4acbd @behdad Fix NULL dereference
behdad authored
91 return likely (face->ot_layout && face->ot_layout->gpos) ? *face->ot_layout->gpos : Null(GPOS);
2ebb89d @behdad Revert "XX"
behdad authored
92 }
93
23c86aa @behdad [HB] Use face_t directly instead of ot_layout_t
behdad authored
94
590d55c @behdad [GDEF] Finish public API
behdad authored
95 /*
96 * GDEF
97 */
98
d6aae5f @behdad [HB] Cleanup TODOs
behdad authored
99 /* TODO the public class_t is a mess */
30bd763 @behdad Implement the first substitute()
behdad authored
100
590d55c @behdad [GDEF] Finish public API
behdad authored
101 hb_bool_t
52ea477 @behdad Change order of font and face for API consistency
behdad authored
102 hb_ot_layout_has_glyph_classes (hb_face_t *face)
590d55c @behdad [GDEF] Finish public API
behdad authored
103 {
23c86aa @behdad [HB] Use face_t directly instead of ot_layout_t
behdad authored
104 return _get_gdef (face).has_glyph_classes ();
590d55c @behdad [GDEF] Finish public API
behdad authored
105 }
106
081819e @behdad [OT] Hookup glib unicode funcs
behdad authored
107 hb_bool_t
23c86aa @behdad [HB] Use face_t directly instead of ot_layout_t
behdad authored
108 _hb_ot_layout_has_new_glyph_classes (hb_face_t *face)
590d55c @behdad [GDEF] Finish public API
behdad authored
109 {
0a4399c @behdad Fix scale issues
behdad authored
110 return face->ot_layout->new_gdef.len > 0;
590d55c @behdad [GDEF] Finish public API
behdad authored
111 }
112
23c86aa @behdad [HB] Use face_t directly instead of ot_layout_t
behdad authored
113 static unsigned int
114 _hb_ot_layout_get_glyph_property (hb_face_t *face,
30bd763 @behdad Implement the first substitute()
behdad authored
115 hb_codepoint_t glyph)
ead428d @behdad More public api
behdad authored
116 {
aff831e @behdad Implement glyph properties
behdad authored
117 hb_ot_layout_class_t klass;
23c86aa @behdad [HB] Use face_t directly instead of ot_layout_t
behdad authored
118 const GDEF &gdef = _get_gdef (face);
aff831e @behdad Implement glyph properties
behdad authored
119
23c86aa @behdad [HB] Use face_t directly instead of ot_layout_t
behdad authored
120 klass = gdef.get_glyph_class (glyph);
ead428d @behdad More public api
behdad authored
121
0a4399c @behdad Fix scale issues
behdad authored
122 if (!klass && glyph < face->ot_layout->new_gdef.len)
123 klass = face->ot_layout->new_gdef.klasses[glyph];
aff831e @behdad Implement glyph properties
behdad authored
124
125 switch (klass) {
126 default:
127 case GDEF::UnclassifiedGlyph: return HB_OT_LAYOUT_GLYPH_CLASS_UNCLASSIFIED;
128 case GDEF::BaseGlyph: return HB_OT_LAYOUT_GLYPH_CLASS_BASE_GLYPH;
129 case GDEF::LigatureGlyph: return HB_OT_LAYOUT_GLYPH_CLASS_LIGATURE;
130 case GDEF::ComponentGlyph: return HB_OT_LAYOUT_GLYPH_CLASS_COMPONENT;
5130c35 @behdad [HB] Simplify MarkAttachmentType handling
behdad authored
131 case GDEF::MarkGlyph:
23c86aa @behdad [HB] Use face_t directly instead of ot_layout_t
behdad authored
132 klass = gdef.get_mark_attachment_type (glyph);
09c292e @behdad [HB] Fix glyph properties
behdad authored
133 return HB_OT_LAYOUT_GLYPH_CLASS_MARK + (klass << 8);
aff831e @behdad Implement glyph properties
behdad authored
134 }
ead428d @behdad More public api
behdad authored
135 }
fd92a3d @behdad Starting public interface
behdad authored
136
081819e @behdad [OT] Hookup glib unicode funcs
behdad authored
137 hb_bool_t
23c86aa @behdad [HB] Use face_t directly instead of ot_layout_t
behdad authored
138 _hb_ot_layout_check_glyph_property (hb_face_t *face,
f1322e5 @behdad [HB] Cleanup public buffer structs
behdad authored
139 hb_internal_glyph_info_t *ginfo,
23c86aa @behdad [HB] Use face_t directly instead of ot_layout_t
behdad authored
140 unsigned int lookup_flags,
141 unsigned int *property_out)
590d55c @behdad [GDEF] Finish public API
behdad authored
142 {
4189b92 @behdad [HB] When looking back/forward, skip marks only
behdad authored
143 unsigned int property;
6f425b1 @behdad [GDEF] Finish internal API
behdad authored
144
f1322e5 @behdad [HB] Cleanup public buffer structs
behdad authored
145 if (ginfo->gproperty == HB_BUFFER_GLYPH_PROPERTIES_UNKNOWN)
23c86aa @behdad [HB] Use face_t directly instead of ot_layout_t
behdad authored
146 ginfo->gproperty = _hb_ot_layout_get_glyph_property (face, ginfo->codepoint);
f1322e5 @behdad [HB] Cleanup public buffer structs
behdad authored
147 property = ginfo->gproperty;
4189b92 @behdad [HB] When looking back/forward, skip marks only
behdad authored
148 if (property_out)
149 *property_out = property;
6f425b1 @behdad [GDEF] Finish internal API
behdad authored
150
4189b92 @behdad [HB] When looking back/forward, skip marks only
behdad authored
151 /* Not covered, if, for example, glyph class is ligature and
1246e41 @behdad [GDEF] Support MarkFilteringSets
behdad authored
152 * lookup_flags includes LookupFlags::IgnoreLigatures
6f425b1 @behdad [GDEF] Finish internal API
behdad authored
153 */
aa87d95 @behdad [HB] Fix lookup_flag ignoring
behdad authored
154 if (property & lookup_flags & LookupFlag::IgnoreFlags)
6f425b1 @behdad [GDEF] Finish internal API
behdad authored
155 return false;
156
4189b92 @behdad [HB] When looking back/forward, skip marks only
behdad authored
157 if (property & HB_OT_LAYOUT_GLYPH_CLASS_MARK)
590d55c @behdad [GDEF] Finish public API
behdad authored
158 {
1246e41 @behdad [GDEF] Support MarkFilteringSets
behdad authored
159 /* If using mark filtering sets, the high short of
4189b92 @behdad [HB] When looking back/forward, skip marks only
behdad authored
160 * lookup_flags has the set index.
1246e41 @behdad [GDEF] Support MarkFilteringSets
behdad authored
161 */
162 if (lookup_flags & LookupFlag::UseMarkFilteringSet)
23c86aa @behdad [HB] Use face_t directly instead of ot_layout_t
behdad authored
163 return _get_gdef (face).mark_set_covers (lookup_flags >> 16, ginfo->codepoint);
1246e41 @behdad [GDEF] Support MarkFilteringSets
behdad authored
164
165 /* The second byte of lookup_flags has the meaning
166 * "ignore marks of attachment type different than
167 * the attachment type specified."
168 */
4189b92 @behdad [HB] When looking back/forward, skip marks only
behdad authored
169 if (lookup_flags & LookupFlag::MarkAttachmentType && property & LookupFlag::MarkAttachmentType)
170 return (lookup_flags & LookupFlag::MarkAttachmentType) == (property & LookupFlag::MarkAttachmentType);
590d55c @behdad [GDEF] Finish public API
behdad authored
171 }
172
6f425b1 @behdad [GDEF] Finish internal API
behdad authored
173 return true;
590d55c @behdad [GDEF] Finish public API
behdad authored
174 }
175
081819e @behdad [OT] Hookup glib unicode funcs
behdad authored
176 hb_bool_t
23c86aa @behdad [HB] Use face_t directly instead of ot_layout_t
behdad authored
177 _hb_ot_layout_skip_mark (hb_face_t *face,
f1322e5 @behdad [HB] Cleanup public buffer structs
behdad authored
178 hb_internal_glyph_info_t *ginfo,
23c86aa @behdad [HB] Use face_t directly instead of ot_layout_t
behdad authored
179 unsigned int lookup_flags,
180 unsigned int *property_out)
4189b92 @behdad [HB] When looking back/forward, skip marks only
behdad authored
181 {
182 unsigned int property;
183
f1322e5 @behdad [HB] Cleanup public buffer structs
behdad authored
184 if (ginfo->gproperty == HB_BUFFER_GLYPH_PROPERTIES_UNKNOWN)
23c86aa @behdad [HB] Use face_t directly instead of ot_layout_t
behdad authored
185 ginfo->gproperty = _hb_ot_layout_get_glyph_property (face, ginfo->codepoint);
f1322e5 @behdad [HB] Cleanup public buffer structs
behdad authored
186 property = ginfo->gproperty;
4189b92 @behdad [HB] When looking back/forward, skip marks only
behdad authored
187 if (property_out)
188 *property_out = property;
189
190 if (property & HB_OT_LAYOUT_GLYPH_CLASS_MARK)
191 {
192 /* Skip mark if lookup_flags includes LookupFlags::IgnoreMarks */
193 if (lookup_flags & LookupFlag::IgnoreMarks)
194 return true;
195
196 /* If using mark filtering sets, the high short of lookup_flags has the set index. */
197 if (lookup_flags & LookupFlag::UseMarkFilteringSet)
23c86aa @behdad [HB] Use face_t directly instead of ot_layout_t
behdad authored
198 return !_get_gdef (face).mark_set_covers (lookup_flags >> 16, ginfo->codepoint);
4189b92 @behdad [HB] When looking back/forward, skip marks only
behdad authored
199
200 /* The second byte of lookup_flags has the meaning "ignore marks of attachment type
201 * different than the attachment type specified." */
202 if (lookup_flags & LookupFlag::MarkAttachmentType && property & LookupFlag::MarkAttachmentType)
203 return (lookup_flags & LookupFlag::MarkAttachmentType) != (property & LookupFlag::MarkAttachmentType);
204 }
205
206 return false;
207 }
208
081819e @behdad [OT] Hookup glib unicode funcs
behdad authored
209 void
23c86aa @behdad [HB] Use face_t directly instead of ot_layout_t
behdad authored
210 _hb_ot_layout_set_glyph_class (hb_face_t *face,
0ead481 @behdad [HB] Port ot-layout to new public API
behdad authored
211 hb_codepoint_t glyph,
212 hb_ot_layout_glyph_class_t klass)
aff831e @behdad Implement glyph properties
behdad authored
213 {
23c86aa @behdad [HB] Use face_t directly instead of ot_layout_t
behdad authored
214 if (HB_OBJECT_IS_INERT (face))
215 return;
216
2c80296 @behdad [HB] Add XXX marks
behdad authored
217 /* TODO optimize this? similar to old harfbuzz code for example */
aff831e @behdad Implement glyph properties
behdad authored
218
0a4399c @behdad Fix scale issues
behdad authored
219 hb_ot_layout_t *layout = face->ot_layout;
aff831e @behdad Implement glyph properties
behdad authored
220 hb_ot_layout_class_t gdef_klass;
15164d9 @behdad [HB] Fix mix warnings
behdad authored
221 unsigned int len = layout->new_gdef.len;
aff831e @behdad Implement glyph properties
behdad authored
222
64d3fc8 @behdad Cosmetic: Rename HB_LIKELY/HB_UNLIKELY to likely/unlikely
behdad authored
223 if (unlikely (glyph > 65535))
30bd763 @behdad Implement the first substitute()
behdad authored
224 return;
225
2c80296 @behdad [HB] Add XXX marks
behdad authored
226 /* XXX this is not threadsafe */
aff831e @behdad Implement glyph properties
behdad authored
227 if (glyph >= len) {
37006bd @behdad Fix stupid array growing bug
behdad authored
228 unsigned int new_len;
590d55c @behdad [GDEF] Finish public API
behdad authored
229 unsigned char *new_klasses;
aff831e @behdad Implement glyph properties
behdad authored
230
231 new_len = len == 0 ? 120 : 2 * len;
37006bd @behdad Fix stupid array growing bug
behdad authored
232 while (new_len <= glyph)
233 new_len *= 2;
234
f0c7540 @behdad Bug 592484 - invalid write in HB
behdad authored
235 if (new_len > 65536)
236 new_len = 65536;
590d55c @behdad [GDEF] Finish public API
behdad authored
237 new_klasses = (unsigned char *) realloc (layout->new_gdef.klasses, new_len * sizeof (unsigned char));
aff831e @behdad Implement glyph properties
behdad authored
238
64d3fc8 @behdad Cosmetic: Rename HB_LIKELY/HB_UNLIKELY to likely/unlikely
behdad authored
239 if (unlikely (!new_klasses))
aff831e @behdad Implement glyph properties
behdad authored
240 return;
ce48f03 @behdad Merge harfbuzz-ng
behdad authored
241
aff831e @behdad Implement glyph properties
behdad authored
242 memset (new_klasses + len, 0, new_len - len);
243
244 layout->new_gdef.klasses = new_klasses;
245 layout->new_gdef.len = new_len;
246 }
247
248 switch (klass) {
249 default:
250 case HB_OT_LAYOUT_GLYPH_CLASS_UNCLASSIFIED: gdef_klass = GDEF::UnclassifiedGlyph; break;
251 case HB_OT_LAYOUT_GLYPH_CLASS_BASE_GLYPH: gdef_klass = GDEF::BaseGlyph; break;
252 case HB_OT_LAYOUT_GLYPH_CLASS_LIGATURE: gdef_klass = GDEF::LigatureGlyph; break;
253 case HB_OT_LAYOUT_GLYPH_CLASS_MARK: gdef_klass = GDEF::MarkGlyph; break;
254 case HB_OT_LAYOUT_GLYPH_CLASS_COMPONENT: gdef_klass = GDEF::ComponentGlyph; break;
255 }
256
257 layout->new_gdef.klasses[glyph] = gdef_klass;
258 return;
259 }
590d55c @behdad [GDEF] Finish public API
behdad authored
260
081819e @behdad [OT] Hookup glib unicode funcs
behdad authored
261 void
23c86aa @behdad [HB] Use face_t directly instead of ot_layout_t
behdad authored
262 _hb_ot_layout_set_glyph_property (hb_face_t *face,
0ead481 @behdad [HB] Port ot-layout to new public API
behdad authored
263 hb_codepoint_t glyph,
264 unsigned int property)
23c86aa @behdad [HB] Use face_t directly instead of ot_layout_t
behdad authored
265 { _hb_ot_layout_set_glyph_class (face, glyph, (hb_ot_layout_glyph_class_t) (property & 0xff)); }
0ead481 @behdad [HB] Port ot-layout to new public API
behdad authored
266
267
268 hb_ot_layout_glyph_class_t
269 hb_ot_layout_get_glyph_class (hb_face_t *face,
270 hb_codepoint_t glyph)
271 {
23c86aa @behdad [HB] Use face_t directly instead of ot_layout_t
behdad authored
272 return (hb_ot_layout_glyph_class_t) (_hb_ot_layout_get_glyph_property (face, glyph) & 0xff);
0ead481 @behdad [HB] Port ot-layout to new public API
behdad authored
273 }
274
590d55c @behdad [GDEF] Finish public API
behdad authored
275 void
0ead481 @behdad [HB] Port ot-layout to new public API
behdad authored
276 hb_ot_layout_set_glyph_class (hb_face_t *face,
277 hb_codepoint_t glyph,
278 hb_ot_layout_glyph_class_t klass)
279 {
23c86aa @behdad [HB] Use face_t directly instead of ot_layout_t
behdad authored
280 _hb_ot_layout_set_glyph_class (face, glyph, klass);
0ead481 @behdad [HB] Port ot-layout to new public API
behdad authored
281 }
282
283 void
284 hb_ot_layout_build_glyph_classes (hb_face_t *face,
2d15e72 @behdad Give it a start at GSUB
behdad authored
285 hb_codepoint_t *glyphs,
e50c397 @behdad Rename HB_OT_Layout to hb_ot_layout_t
behdad authored
286 unsigned char *klasses,
287 uint16_t count)
590d55c @behdad [GDEF] Finish public API
behdad authored
288 {
23c86aa @behdad [HB] Use face_t directly instead of ot_layout_t
behdad authored
289 if (HB_OBJECT_IS_INERT (face))
290 return;
291
0a4399c @behdad Fix scale issues
behdad authored
292 hb_ot_layout_t *layout = face->ot_layout;
0ead481 @behdad [HB] Port ot-layout to new public API
behdad authored
293
64d3fc8 @behdad Cosmetic: Rename HB_LIKELY/HB_UNLIKELY to likely/unlikely
behdad authored
294 if (unlikely (!count || !glyphs || !klasses))
590d55c @behdad [GDEF] Finish public API
behdad authored
295 return;
296
297 if (layout->new_gdef.len == 0) {
555d112 @behdad [GDEF] Fix bug in building synthetic GDEF
behdad authored
298 layout->new_gdef.klasses = (unsigned char *) calloc (count, sizeof (unsigned char));
590d55c @behdad [GDEF] Finish public API
behdad authored
299 layout->new_gdef.len = count;
300 }
301
f4c9514 @behdad [HB] Simplify more arrays
behdad authored
302 for (unsigned int i = 0; i < count; i++)
23c86aa @behdad [HB] Use face_t directly instead of ot_layout_t
behdad authored
303 _hb_ot_layout_set_glyph_class (face, glyphs[i], (hb_ot_layout_glyph_class_t) klasses[i]);
590d55c @behdad [GDEF] Finish public API
behdad authored
304 }
706ab25 @behdad Add script and language public getter API
behdad authored
305
e21899b @behdad Fix array query API
behdad authored
306 unsigned int
0ead481 @behdad [HB] Port ot-layout to new public API
behdad authored
307 hb_ot_layout_get_attach_points (hb_face_t *face,
79420ad @behdad [HB] Add get_attach_points()
behdad authored
308 hb_codepoint_t glyph,
e21899b @behdad Fix array query API
behdad authored
309 unsigned int start_offset,
79420ad @behdad [HB] Add get_attach_points()
behdad authored
310 unsigned int *point_count /* IN/OUT */,
311 unsigned int *point_array /* OUT */)
312 {
e21899b @behdad Fix array query API
behdad authored
313 return _get_gdef (face).get_attach_points (glyph, start_offset, point_count, point_array);
62964af @behdad [HB] Implement get_lig_carets()
behdad authored
314 }
315
e21899b @behdad Fix array query API
behdad authored
316 unsigned int
52ea477 @behdad Change order of font and face for API consistency
behdad authored
317 hb_ot_layout_get_lig_carets (hb_font_t *font,
318 hb_face_t *face,
62964af @behdad [HB] Implement get_lig_carets()
behdad authored
319 hb_codepoint_t glyph,
e21899b @behdad Fix array query API
behdad authored
320 unsigned int start_offset,
62964af @behdad [HB] Implement get_lig_carets()
behdad authored
321 unsigned int *caret_count /* IN/OUT */,
322 int *caret_array /* OUT */)
323 {
d7cfb3b @behdad s/\<context\>/c/g
behdad authored
324 hb_ot_layout_context_t c;
325 c.font = font;
326 c.face = face;
327 return _get_gdef (face).get_lig_carets (&c, glyph, start_offset, caret_count, caret_array);
79420ad @behdad [HB] Add get_attach_points()
behdad authored
328 }
329
706ab25 @behdad Add script and language public getter API
behdad authored
330 /*
331 * GSUB/GPOS
332 */
333
334 static const GSUBGPOS&
23c86aa @behdad [HB] Use face_t directly instead of ot_layout_t
behdad authored
335 get_gsubgpos_table (hb_face_t *face,
336 hb_tag_t table_tag)
706ab25 @behdad Add script and language public getter API
behdad authored
337 {
0ead481 @behdad [HB] Port ot-layout to new public API
behdad authored
338 switch (table_tag) {
23c86aa @behdad [HB] Use face_t directly instead of ot_layout_t
behdad authored
339 case HB_OT_TAG_GSUB: return _get_gsub (face);
340 case HB_OT_TAG_GPOS: return _get_gpos (face);
0ead481 @behdad [HB] Port ot-layout to new public API
behdad authored
341 default: return Null(GSUBGPOS);
706ab25 @behdad Add script and language public getter API
behdad authored
342 }
343 }
344
345
e21899b @behdad Fix array query API
behdad authored
346 unsigned int
bff3c0f @behdad [HB] Remove clumsy macros and improve API
behdad authored
347 hb_ot_layout_table_get_script_tags (hb_face_t *face,
348 hb_tag_t table_tag,
e21899b @behdad Fix array query API
behdad authored
349 unsigned int start_offset,
bff3c0f @behdad [HB] Remove clumsy macros and improve API
behdad authored
350 unsigned int *script_count /* IN/OUT */,
351 hb_tag_t *script_tags /* OUT */)
706ab25 @behdad Add script and language public getter API
behdad authored
352 {
23c86aa @behdad [HB] Use face_t directly instead of ot_layout_t
behdad authored
353 const GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
706ab25 @behdad Add script and language public getter API
behdad authored
354
e21899b @behdad Fix array query API
behdad authored
355 return g.get_script_tags (start_offset, script_count, script_tags);
706ab25 @behdad Add script and language public getter API
behdad authored
356 }
357
358 hb_bool_t
0ead481 @behdad [HB] Port ot-layout to new public API
behdad authored
359 hb_ot_layout_table_find_script (hb_face_t *face,
360 hb_tag_t table_tag,
361 hb_tag_t script_tag,
362 unsigned int *script_index)
706ab25 @behdad Add script and language public getter API
behdad authored
363 {
b5db4f1 @behdad Clean up NO_INDEX
behdad authored
364 ASSERT_STATIC (Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_NO_SCRIPT_INDEX);
23c86aa @behdad [HB] Use face_t directly instead of ot_layout_t
behdad authored
365 const GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
706ab25 @behdad Add script and language public getter API
behdad authored
366
367 if (g.find_script_index (script_tag, script_index))
368 return TRUE;
369
370 /* try finding 'DFLT' */
8a3511a @behdad Add hb_language_t as well as language/script conversion to OT tags
behdad authored
371 if (g.find_script_index (HB_OT_TAG_DEFAULT_SCRIPT, script_index))
706ab25 @behdad Add script and language public getter API
behdad authored
372 return FALSE;
373
374 /* try with 'dflt'; MS site has had typos and many fonts use it now :( */
8a3511a @behdad Add hb_language_t as well as language/script conversion to OT tags
behdad authored
375 if (g.find_script_index (HB_OT_TAG_DEFAULT_LANGUAGE, script_index))
2014b8d @behdad Hook OpenType shaping up
behdad authored
376 return FALSE;
377
378 if (script_index) *script_index = HB_OT_LAYOUT_NO_SCRIPT_INDEX;
379 return FALSE;
380 }
381
382 hb_bool_t
383 hb_ot_layout_table_choose_script (hb_face_t *face,
384 hb_tag_t table_tag,
385 const hb_tag_t *script_tags,
386 unsigned int *script_index)
387 {
b5db4f1 @behdad Clean up NO_INDEX
behdad authored
388 ASSERT_STATIC (Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_NO_SCRIPT_INDEX);
2014b8d @behdad Hook OpenType shaping up
behdad authored
389 const GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
390
391 while (*script_tags)
392 {
393 if (g.find_script_index (*script_tags, script_index))
394 return TRUE;
395 script_tags++;
396 }
397
398 /* try finding 'DFLT' */
399 if (g.find_script_index (HB_OT_TAG_DEFAULT_SCRIPT, script_index))
400 return FALSE;
401
402 /* try with 'dflt'; MS site has had typos and many fonts use it now :( */
403 if (g.find_script_index (HB_OT_TAG_DEFAULT_LANGUAGE, script_index))
706ab25 @behdad Add script and language public getter API
behdad authored
404 return FALSE;
405
406 if (script_index) *script_index = HB_OT_LAYOUT_NO_SCRIPT_INDEX;
407 return FALSE;
408 }
409
e21899b @behdad Fix array query API
behdad authored
410 unsigned int
bff3c0f @behdad [HB] Remove clumsy macros and improve API
behdad authored
411 hb_ot_layout_table_get_feature_tags (hb_face_t *face,
412 hb_tag_t table_tag,
e21899b @behdad Fix array query API
behdad authored
413 unsigned int start_offset,
bff3c0f @behdad [HB] Remove clumsy macros and improve API
behdad authored
414 unsigned int *feature_count /* IN/OUT */,
415 hb_tag_t *feature_tags /* OUT */)
c447335 @behdad [hb-ot-layout] Add proper namespace to accessors
behdad authored
416 {
23c86aa @behdad [HB] Use face_t directly instead of ot_layout_t
behdad authored
417 const GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
c447335 @behdad [hb-ot-layout] Add proper namespace to accessors
behdad authored
418
e21899b @behdad Fix array query API
behdad authored
419 return g.get_feature_tags (start_offset, feature_count, feature_tags);
c447335 @behdad [hb-ot-layout] Add proper namespace to accessors
behdad authored
420 }
421
422
e21899b @behdad Fix array query API
behdad authored
423 unsigned int
bff3c0f @behdad [HB] Remove clumsy macros and improve API
behdad authored
424 hb_ot_layout_script_get_language_tags (hb_face_t *face,
425 hb_tag_t table_tag,
426 unsigned int script_index,
e21899b @behdad Fix array query API
behdad authored
427 unsigned int start_offset,
bff3c0f @behdad [HB] Remove clumsy macros and improve API
behdad authored
428 unsigned int *language_count /* IN/OUT */,
429 hb_tag_t *language_tags /* OUT */)
706ab25 @behdad Add script and language public getter API
behdad authored
430 {
23c86aa @behdad [HB] Use face_t directly instead of ot_layout_t
behdad authored
431 const Script &s = get_gsubgpos_table (face, table_tag).get_script (script_index);
706ab25 @behdad Add script and language public getter API
behdad authored
432
e21899b @behdad Fix array query API
behdad authored
433 return s.get_lang_sys_tags (start_offset, language_count, language_tags);
706ab25 @behdad Add script and language public getter API
behdad authored
434 }
435
436 hb_bool_t
0ead481 @behdad [HB] Port ot-layout to new public API
behdad authored
437 hb_ot_layout_script_find_language (hb_face_t *face,
438 hb_tag_t table_tag,
439 unsigned int script_index,
440 hb_tag_t language_tag,
441 unsigned int *language_index)
706ab25 @behdad Add script and language public getter API
behdad authored
442 {
b5db4f1 @behdad Clean up NO_INDEX
behdad authored
443 ASSERT_STATIC (Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_DEFAULT_LANGUAGE_INDEX);
23c86aa @behdad [HB] Use face_t directly instead of ot_layout_t
behdad authored
444 const Script &s = get_gsubgpos_table (face, table_tag).get_script (script_index);
706ab25 @behdad Add script and language public getter API
behdad authored
445
4a26ea4 @behdad Finish script, language, and feature public API
behdad authored
446 if (s.find_lang_sys_index (language_tag, language_index))
706ab25 @behdad Add script and language public getter API
behdad authored
447 return TRUE;
448
449 /* try with 'dflt'; MS site has had typos and many fonts use it now :( */
8a3511a @behdad Add hb_language_t as well as language/script conversion to OT tags
behdad authored
450 if (s.find_lang_sys_index (HB_OT_TAG_DEFAULT_LANGUAGE, language_index))
706ab25 @behdad Add script and language public getter API
behdad authored
451 return FALSE;
452
4a26ea4 @behdad Finish script, language, and feature public API
behdad authored
453 if (language_index) *language_index = HB_OT_LAYOUT_DEFAULT_LANGUAGE_INDEX;
706ab25 @behdad Add script and language public getter API
behdad authored
454 return FALSE;
4a26ea4 @behdad Finish script, language, and feature public API
behdad authored
455 }
706ab25 @behdad Add script and language public getter API
behdad authored
456
4a26ea4 @behdad Finish script, language, and feature public API
behdad authored
457 hb_bool_t
0ead481 @behdad [HB] Port ot-layout to new public API
behdad authored
458 hb_ot_layout_language_get_required_feature_index (hb_face_t *face,
459 hb_tag_t table_tag,
460 unsigned int script_index,
461 unsigned int language_index,
462 unsigned int *feature_index)
4a26ea4 @behdad Finish script, language, and feature public API
behdad authored
463 {
23c86aa @behdad [HB] Use face_t directly instead of ot_layout_t
behdad authored
464 const LangSys &l = get_gsubgpos_table (face, table_tag).get_script (script_index).get_lang_sys (language_index);
706ab25 @behdad Add script and language public getter API
behdad authored
465
4a26ea4 @behdad Finish script, language, and feature public API
behdad authored
466 if (feature_index) *feature_index = l.get_required_feature_index ();
706ab25 @behdad Add script and language public getter API
behdad authored
467
4a26ea4 @behdad Finish script, language, and feature public API
behdad authored
468 return l.has_required_feature ();
469 }
706ab25 @behdad Add script and language public getter API
behdad authored
470
e21899b @behdad Fix array query API
behdad authored
471 unsigned int
bff3c0f @behdad [HB] Remove clumsy macros and improve API
behdad authored
472 hb_ot_layout_language_get_feature_indexes (hb_face_t *face,
473 hb_tag_t table_tag,
474 unsigned int script_index,
475 unsigned int language_index,
e21899b @behdad Fix array query API
behdad authored
476 unsigned int start_offset,
bff3c0f @behdad [HB] Remove clumsy macros and improve API
behdad authored
477 unsigned int *feature_count /* IN/OUT */,
478 unsigned int *feature_indexes /* OUT */)
0ead481 @behdad [HB] Port ot-layout to new public API
behdad authored
479 {
23c86aa @behdad [HB] Use face_t directly instead of ot_layout_t
behdad authored
480 const GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
4a26ea4 @behdad Finish script, language, and feature public API
behdad authored
481 const LangSys &l = g.get_script (script_index).get_lang_sys (language_index);
482
e21899b @behdad Fix array query API
behdad authored
483 return l.get_feature_indexes (start_offset, feature_count, feature_indexes);
c447335 @behdad [hb-ot-layout] Add proper namespace to accessors
behdad authored
484 }
485
e21899b @behdad Fix array query API
behdad authored
486 unsigned int
bff3c0f @behdad [HB] Remove clumsy macros and improve API
behdad authored
487 hb_ot_layout_language_get_feature_tags (hb_face_t *face,
488 hb_tag_t table_tag,
489 unsigned int script_index,
490 unsigned int language_index,
e21899b @behdad Fix array query API
behdad authored
491 unsigned int start_offset,
bff3c0f @behdad [HB] Remove clumsy macros and improve API
behdad authored
492 unsigned int *feature_count /* IN/OUT */,
493 hb_tag_t *feature_tags /* OUT */)
0ead481 @behdad [HB] Port ot-layout to new public API
behdad authored
494 {
23c86aa @behdad [HB] Use face_t directly instead of ot_layout_t
behdad authored
495 const GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
c447335 @behdad [hb-ot-layout] Add proper namespace to accessors
behdad authored
496 const LangSys &l = g.get_script (script_index).get_lang_sys (language_index);
4a26ea4 @behdad Finish script, language, and feature public API
behdad authored
497
bff3c0f @behdad [HB] Remove clumsy macros and improve API
behdad authored
498 ASSERT_STATIC (sizeof (unsigned int) == sizeof (hb_tag_t));
e21899b @behdad Fix array query API
behdad authored
499 unsigned int ret = l.get_feature_indexes (start_offset, feature_count, (unsigned int *) feature_tags);
bff3c0f @behdad [HB] Remove clumsy macros and improve API
behdad authored
500
9897749 @behdad [HB] Simplify counting
behdad authored
501 if (feature_tags) {
502 unsigned int count = *feature_count;
503 for (unsigned int i = 0; i < count; i++)
504 feature_tags[i] = g.get_feature_tag ((unsigned int) feature_tags[i]);
505 }
bff3c0f @behdad [HB] Remove clumsy macros and improve API
behdad authored
506
507 return ret;
4a26ea4 @behdad Finish script, language, and feature public API
behdad authored
508 }
509
510
511 hb_bool_t
0ead481 @behdad [HB] Port ot-layout to new public API
behdad authored
512 hb_ot_layout_language_find_feature (hb_face_t *face,
513 hb_tag_t table_tag,
514 unsigned int script_index,
515 unsigned int language_index,
516 hb_tag_t feature_tag,
517 unsigned int *feature_index)
4a26ea4 @behdad Finish script, language, and feature public API
behdad authored
518 {
b5db4f1 @behdad Clean up NO_INDEX
behdad authored
519 ASSERT_STATIC (Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_NO_FEATURE_INDEX);
23c86aa @behdad [HB] Use face_t directly instead of ot_layout_t
behdad authored
520 const GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
4a26ea4 @behdad Finish script, language, and feature public API
behdad authored
521 const LangSys &l = g.get_script (script_index).get_lang_sys (language_index);
522
f4c9514 @behdad [HB] Simplify more arrays
behdad authored
523 unsigned int num_features = l.get_feature_count ();
524 for (unsigned int i = 0; i < num_features; i++) {
4a26ea4 @behdad Finish script, language, and feature public API
behdad authored
525 unsigned int f_index = l.get_feature_index (i);
526
527 if (feature_tag == g.get_feature_tag (f_index)) {
528 if (feature_index) *feature_index = f_index;
529 return TRUE;
530 }
531 }
706ab25 @behdad Add script and language public getter API
behdad authored
532
4a26ea4 @behdad Finish script, language, and feature public API
behdad authored
533 if (feature_index) *feature_index = HB_OT_LAYOUT_NO_FEATURE_INDEX;
706ab25 @behdad Add script and language public getter API
behdad authored
534 return FALSE;
535 }
c447335 @behdad [hb-ot-layout] Add proper namespace to accessors
behdad authored
536
e21899b @behdad Fix array query API
behdad authored
537 unsigned int
bff3c0f @behdad [HB] Remove clumsy macros and improve API
behdad authored
538 hb_ot_layout_feature_get_lookup_indexes (hb_face_t *face,
539 hb_tag_t table_tag,
540 unsigned int feature_index,
e21899b @behdad Fix array query API
behdad authored
541 unsigned int start_offset,
bff3c0f @behdad [HB] Remove clumsy macros and improve API
behdad authored
542 unsigned int *lookup_count /* IN/OUT */,
543 unsigned int *lookup_indexes /* OUT */)
c447335 @behdad [hb-ot-layout] Add proper namespace to accessors
behdad authored
544 {
23c86aa @behdad [HB] Use face_t directly instead of ot_layout_t
behdad authored
545 const GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
c447335 @behdad [hb-ot-layout] Add proper namespace to accessors
behdad authored
546 const Feature &f = g.get_feature (feature_index);
547
e21899b @behdad Fix array query API
behdad authored
548 return f.get_lookup_indexes (start_offset, lookup_count, lookup_indexes);
c447335 @behdad [hb-ot-layout] Add proper namespace to accessors
behdad authored
549 }
550
2d15e72 @behdad Give it a start at GSUB
behdad authored
551
552 /*
553 * GSUB
554 */
555
556 hb_bool_t
0ead481 @behdad [HB] Port ot-layout to new public API
behdad authored
557 hb_ot_layout_has_substitution (hb_face_t *face)
558 {
23c86aa @behdad [HB] Use face_t directly instead of ot_layout_t
behdad authored
559 return &_get_gsub (face) != &Null(GSUB);
0ead481 @behdad [HB] Port ot-layout to new public API
behdad authored
560 }
561
562 hb_bool_t
468769b @behdad [HB] Rename hb_ot_layout_feature_mask_t to hb_mask_t
behdad authored
563 hb_ot_layout_substitute_lookup (hb_face_t *face,
564 hb_buffer_t *buffer,
565 unsigned int lookup_index,
566 hb_mask_t mask)
2d15e72 @behdad Give it a start at GSUB
behdad authored
567 {
d7cfb3b @behdad s/\<context\>/c/g
behdad authored
568 hb_ot_layout_context_t c;
569 c.font = NULL;
570 c.face = face;
571 return _get_gsub (face).substitute_lookup (&c, buffer, lookup_index, mask);
5a0b791 @behdad [harfbuzz/GSUB] towards a partially working GSUB
behdad authored
572 }
573
bff3c0f @behdad [HB] Remove clumsy macros and improve API
behdad authored
574
9c42f05 @behdad Switch Pango to new, defunt, GPOS
behdad authored
575 /*
576 * GPOS
577 */
578
579 hb_bool_t
0ead481 @behdad [HB] Port ot-layout to new public API
behdad authored
580 hb_ot_layout_has_positioning (hb_face_t *face)
581 {
23c86aa @behdad [HB] Use face_t directly instead of ot_layout_t
behdad authored
582 return &_get_gpos (face) != &Null(GPOS);
0ead481 @behdad [HB] Port ot-layout to new public API
behdad authored
583 }
584
585 hb_bool_t
52ea477 @behdad Change order of font and face for API consistency
behdad authored
586 hb_ot_layout_position_lookup (hb_font_t *font,
587 hb_face_t *face,
468769b @behdad [HB] Rename hb_ot_layout_feature_mask_t to hb_mask_t
behdad authored
588 hb_buffer_t *buffer,
589 unsigned int lookup_index,
590 hb_mask_t mask)
9c42f05 @behdad Switch Pango to new, defunt, GPOS
behdad authored
591 {
d7cfb3b @behdad s/\<context\>/c/g
behdad authored
592 hb_ot_layout_context_t c;
593 c.font = font;
594 c.face = face;
595 return _get_gpos (face).position_lookup (&c, buffer, lookup_index, mask);
9c42f05 @behdad Switch Pango to new, defunt, GPOS
behdad authored
596 }
9db8ad7 @behdad Add hb_ot_layout_position_finish()
behdad authored
597
598 void
33d13fd @behdad Rename HB_GNUC_UNUSED -> HB_UNUSED
behdad authored
599 hb_ot_layout_position_finish (hb_font_t *font HB_UNUSED,
600 hb_face_t *face HB_UNUSED,
9db8ad7 @behdad Add hb_ot_layout_position_finish()
behdad authored
601 hb_buffer_t *buffer)
602 {
603 unsigned int i, j;
604 unsigned int len = hb_buffer_get_length (buffer);
f415755 @behdad Minor
behdad authored
605 hb_internal_glyph_position_t *pos = (hb_internal_glyph_position_t *) hb_buffer_get_glyph_positions (buffer);
9db8ad7 @behdad Add hb_ot_layout_position_finish()
behdad authored
606
607 /* TODO: Vertical */
608
609 /* Handle cursive connections */
610 /* First handle all left-to-right connections */
611 for (j = 0; j < len; j++) {
f415755 @behdad Minor
behdad authored
612 if (pos[j].cursive_chain > 0)
613 {
614 pos[j].y_offset += pos[j - pos[j].cursive_chain].y_offset;
615 pos[j].cursive_chain = 0;
9db8ad7 @behdad Add hb_ot_layout_position_finish()
behdad authored
616 }
617 }
618 /* Then handle all right-to-left connections */
619 for (i = len; i > 0; i--) {
620 j = i - 1;
f415755 @behdad Minor
behdad authored
621 if (pos[j].cursive_chain < 0)
622 {
623 pos[j].y_offset += pos[j - pos[j].cursive_chain].y_offset;
624 pos[j].cursive_chain = 0;
9db8ad7 @behdad Add hb_ot_layout_position_finish()
behdad authored
625 }
626 }
627
628 /* Handle attachments */
629 for (i = 0; i < len; i++)
f415755 @behdad Minor
behdad authored
630 if (pos[i].back)
631 {
632 unsigned int back = i - pos[i].back;
633 pos[i].back = 0;
634 pos[i].x_offset += pos[back].x_offset;
635 pos[i].y_offset += pos[back].y_offset;
636
4e4ef24 @behdad Towards separating bit allocation from shaping
behdad authored
637 if (buffer->props.direction == HB_DIRECTION_RTL)
f415755 @behdad Minor
behdad authored
638 for (j = back + 1; j < i + 1; j++) {
639 pos[i].x_offset += pos[j].x_advance;
640 pos[i].y_offset += pos[j].y_advance;
641 }
642 else
643 for (j = back; j < i; j++) {
644 pos[i].x_offset -= pos[j].x_advance;
645 pos[i].y_offset -= pos[j].y_advance;
646 }
647 }
9db8ad7 @behdad Add hb_ot_layout_position_finish()
behdad authored
648 }
acdba3f @behdad Prefer C linkage
behdad authored
649
650
651 HB_END_DECLS
Something went wrong with that request. Please try again.