Skip to content

HTTPS clone URL

Subversion checkout URL

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