Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 649 lines (519 sloc) 19.001 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 *
6 * This is part of HarfBuzz, an OpenType Layout engine library.
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
5c0adce @behdad [HB] Rename harfbuzz-buffer to hb-buffer
behdad authored
31 /* XXX */
32 #include "hb-buffer-private.h"
33
fd92a3d @behdad Starting public interface
behdad authored
34 #include "hb-ot-layout.h"
35 #include "hb-ot-layout-private.h"
36
37 #include "hb-ot-layout-open-private.h"
38 #include "hb-ot-layout-gdef-private.h"
39 #include "hb-ot-layout-gsub-private.h"
5e5eb05 @behdad [HB] Start GPOS!
behdad authored
40 #include "hb-ot-layout-gpos-private.h"
fd92a3d @behdad Starting public interface
behdad authored
41
6f425b1 @behdad [GDEF] Finish internal API
behdad authored
42
fd92a3d @behdad Starting public interface
behdad authored
43 #include <stdlib.h>
aff831e @behdad Implement glyph properties
behdad authored
44 #include <string.h>
45
fd92a3d @behdad Starting public interface
behdad authored
46
e50c397 @behdad Rename HB_OT_Layout to hb_ot_layout_t
behdad authored
47 hb_ot_layout_t *
4a26ea4 @behdad Finish script, language, and feature public API
behdad authored
48 hb_ot_layout_create (void)
49 {
50 hb_ot_layout_t *layout = (hb_ot_layout_t *) calloc (1, sizeof (hb_ot_layout_t));
51
8b83580 @behdad [HB] Use templates for Null objects
behdad authored
52 layout->gdef = &Null(GDEF);
53 layout->gsub = &Null(GSUB);
5e5eb05 @behdad [HB] Start GPOS!
behdad authored
54 layout->gpos = &Null(GPOS);
4a26ea4 @behdad Finish script, language, and feature public API
behdad authored
55
56 return layout;
57 }
58
59 hb_ot_layout_t *
dfa8119 @behdad Rename hb_ot_layout_create() to hb_ot_layout_create_for_data()
behdad authored
60 hb_ot_layout_create_for_data (const char *font_data,
61 int face_index)
fd92a3d @behdad Starting public interface
behdad authored
62 {
4a26ea4 @behdad Finish script, language, and feature public API
behdad authored
63 hb_ot_layout_t *layout;
64
65 if (HB_UNLIKELY (font_data == NULL))
66 return hb_ot_layout_create ();
67
68 layout = (hb_ot_layout_t *) calloc (1, sizeof (hb_ot_layout_t));
fd92a3d @behdad Starting public interface
behdad authored
69
ead428d @behdad More public api
behdad authored
70 const OpenTypeFontFile &font = OpenTypeFontFile::get_for_data (font_data);
71 const OpenTypeFontFace &face = font.get_face (face_index);
fd92a3d @behdad Starting public interface
behdad authored
72
54e5aac @behdad GDEF completely working now
behdad authored
73 layout->gdef = &GDEF::get_for_data (font.get_table_data (face.get_table_by_tag (GDEF::Tag)));
74 layout->gsub = &GSUB::get_for_data (font.get_table_data (face.get_table_by_tag (GSUB::Tag)));
5e5eb05 @behdad [HB] Start GPOS!
behdad authored
75 layout->gpos = &GPOS::get_for_data (font.get_table_data (face.get_table_by_tag (GPOS::Tag)));
fd92a3d @behdad Starting public interface
behdad authored
76
77 return layout;
78 }
79
80 void
e50c397 @behdad Rename HB_OT_Layout to hb_ot_layout_t
behdad authored
81 hb_ot_layout_destroy (hb_ot_layout_t *layout)
fd92a3d @behdad Starting public interface
behdad authored
82 {
83 free (layout);
84 }
85
0f7e6b2 @behdad [GPOS] Fix more brokenness
behdad authored
86 void
87 hb_ot_layout_set_direction (hb_ot_layout_t *layout,
88 hb_bool_t r2l)
89 {
90 layout->gpos_info.r2l = !!r2l;
91 }
92
e1593a6 @behdad [GPOS] Finally it's working, up to Cursive
behdad authored
93 void
94 hb_ot_layout_set_hinting (hb_ot_layout_t *layout,
95 hb_bool_t hinted)
96 {
97 layout->gpos_info.dvi = !hinted;
98 }
99
100 void
101 hb_ot_layout_set_scale (hb_ot_layout_t *layout,
102 hb_16dot16_t x_scale, hb_16dot16_t y_scale)
103 {
104 layout->gpos_info.x_scale = x_scale;
105 layout->gpos_info.y_scale = y_scale;
106 }
107
108 void
109 hb_ot_layout_set_ppem (hb_ot_layout_t *layout,
110 unsigned int x_ppem, unsigned int y_ppem)
111 {
112 layout->gpos_info.x_ppem = x_ppem;
113 layout->gpos_info.y_ppem = y_ppem;
114 }
115
116
590d55c @behdad [GDEF] Finish public API
behdad authored
117 /*
118 * GDEF
119 */
120
d6aae5f @behdad [HB] Cleanup TODOs
behdad authored
121 /* TODO the public class_t is a mess */
30bd763 @behdad Implement the first substitute()
behdad authored
122
590d55c @behdad [GDEF] Finish public API
behdad authored
123 hb_bool_t
e50c397 @behdad Rename HB_OT_Layout to hb_ot_layout_t
behdad authored
124 hb_ot_layout_has_font_glyph_classes (hb_ot_layout_t *layout)
590d55c @behdad [GDEF] Finish public API
behdad authored
125 {
126 return layout->gdef->has_glyph_classes ();
127 }
128
54e5aac @behdad GDEF completely working now
behdad authored
129 HB_OT_LAYOUT_INTERNAL hb_bool_t
e50c397 @behdad Rename HB_OT_Layout to hb_ot_layout_t
behdad authored
130 _hb_ot_layout_has_new_glyph_classes (hb_ot_layout_t *layout)
590d55c @behdad [GDEF] Finish public API
behdad authored
131 {
132 return layout->new_gdef.len > 0;
133 }
134
30bd763 @behdad Implement the first substitute()
behdad authored
135 HB_OT_LAYOUT_INTERNAL unsigned int
136 _hb_ot_layout_get_glyph_property (hb_ot_layout_t *layout,
137 hb_codepoint_t glyph)
ead428d @behdad More public api
behdad authored
138 {
aff831e @behdad Implement glyph properties
behdad authored
139 hb_ot_layout_class_t klass;
140
141 /* TODO old harfbuzz doesn't always parse mark attachments as it says it was
142 * introduced without a version bump, so it may not be safe */
143 klass = layout->gdef->get_mark_attachment_type (glyph);
144 if (klass)
145 return klass << 8;
146
147 klass = layout->gdef->get_glyph_class (glyph);
ead428d @behdad More public api
behdad authored
148
aff831e @behdad Implement glyph properties
behdad authored
149 if (!klass && glyph < layout->new_gdef.len)
150 klass = layout->new_gdef.klasses[glyph];
151
152 switch (klass) {
153 default:
154 case GDEF::UnclassifiedGlyph: return HB_OT_LAYOUT_GLYPH_CLASS_UNCLASSIFIED;
155 case GDEF::BaseGlyph: return HB_OT_LAYOUT_GLYPH_CLASS_BASE_GLYPH;
156 case GDEF::LigatureGlyph: return HB_OT_LAYOUT_GLYPH_CLASS_LIGATURE;
157 case GDEF::MarkGlyph: return HB_OT_LAYOUT_GLYPH_CLASS_MARK;
158 case GDEF::ComponentGlyph: return HB_OT_LAYOUT_GLYPH_CLASS_COMPONENT;
159 }
ead428d @behdad More public api
behdad authored
160 }
fd92a3d @behdad Starting public interface
behdad authored
161
54e5aac @behdad GDEF completely working now
behdad authored
162 HB_OT_LAYOUT_INTERNAL hb_bool_t
30bd763 @behdad Implement the first substitute()
behdad authored
163 _hb_ot_layout_check_glyph_property (hb_ot_layout_t *layout,
164 HB_GlyphItem gitem,
165 unsigned int lookup_flags,
166 unsigned int *property)
590d55c @behdad [GDEF] Finish public API
behdad authored
167 {
6f425b1 @behdad [GDEF] Finish internal API
behdad authored
168 hb_ot_layout_glyph_class_t basic_glyph_class;
30bd763 @behdad Implement the first substitute()
behdad authored
169 unsigned int desired_attachment_class;
6f425b1 @behdad [GDEF] Finish internal API
behdad authored
170
30bd763 @behdad Implement the first substitute()
behdad authored
171 if (gitem->gproperty == HB_BUFFER_GLYPH_PROPERTIES_UNKNOWN)
6f425b1 @behdad [GDEF] Finish internal API
behdad authored
172 {
30bd763 @behdad Implement the first substitute()
behdad authored
173 gitem->gproperty = *property = _hb_ot_layout_get_glyph_property (layout, gitem->gindex);
174 if (gitem->gproperty == HB_OT_LAYOUT_GLYPH_CLASS_UNCLASSIFIED)
6f425b1 @behdad [GDEF] Finish internal API
behdad authored
175 return false;
176 }
590d55c @behdad [GDEF] Finish public API
behdad authored
177
30bd763 @behdad Implement the first substitute()
behdad authored
178 *property = gitem->gproperty;
6f425b1 @behdad [GDEF] Finish internal API
behdad authored
179
180 /* If the glyph was found in the MarkAttachmentClass table,
181 * then that class value is the high byte of the result,
182 * otherwise the low byte contains the basic type of the glyph
183 * as defined by the GlyphClassDef table.
184 */
185 if (*property & LookupFlag::MarkAttachmentType)
186 basic_glyph_class = HB_OT_LAYOUT_GLYPH_CLASS_MARK;
187 else
188 basic_glyph_class = (hb_ot_layout_glyph_class_t) *property;
189
190 /* Not covered, if, for example, basic_glyph_class
191 * is HB_GDEF_LIGATURE and lookup_flags includes LookupFlags::IgnoreLigatures
192 */
193 if (lookup_flags & basic_glyph_class)
194 return false;
195
196 /* The high byte of lookup_flags has the meaning
197 * "ignore marks of attachment type different than
198 * the attachment type specified."
199 */
200 desired_attachment_class = lookup_flags & LookupFlag::MarkAttachmentType;
201 if (desired_attachment_class)
590d55c @behdad [GDEF] Finish public API
behdad authored
202 {
6f425b1 @behdad [GDEF] Finish internal API
behdad authored
203 if (basic_glyph_class == HB_OT_LAYOUT_GLYPH_CLASS_MARK &&
30bd763 @behdad Implement the first substitute()
behdad authored
204 *property != desired_attachment_class)
6f425b1 @behdad [GDEF] Finish internal API
behdad authored
205 return false;
590d55c @behdad [GDEF] Finish public API
behdad authored
206 }
207
6f425b1 @behdad [GDEF] Finish internal API
behdad authored
208 return true;
590d55c @behdad [GDEF] Finish public API
behdad authored
209 }
210
30bd763 @behdad Implement the first substitute()
behdad authored
211 HB_OT_LAYOUT_INTERNAL void
212 _hb_ot_layout_set_glyph_property (hb_ot_layout_t *layout,
213 hb_codepoint_t glyph,
214 unsigned int property)
215 {
216 hb_ot_layout_glyph_class_t klass;
217
218 if (property & LookupFlag::MarkAttachmentType)
219 klass = HB_OT_LAYOUT_GLYPH_CLASS_MARK;
220 else
221 klass = (hb_ot_layout_glyph_class_t) property;
222
223 hb_ot_layout_set_glyph_class (layout, glyph, klass);
224 }
225
590d55c @behdad [GDEF] Finish public API
behdad authored
226
aff831e @behdad Implement glyph properties
behdad authored
227 hb_ot_layout_glyph_class_t
e50c397 @behdad Rename HB_OT_Layout to hb_ot_layout_t
behdad authored
228 hb_ot_layout_get_glyph_class (hb_ot_layout_t *layout,
2d15e72 @behdad Give it a start at GSUB
behdad authored
229 hb_codepoint_t glyph)
ead428d @behdad More public api
behdad authored
230 {
30bd763 @behdad Implement the first substitute()
behdad authored
231 unsigned int property;
aff831e @behdad Implement glyph properties
behdad authored
232 hb_ot_layout_class_t klass;
ead428d @behdad More public api
behdad authored
233
30bd763 @behdad Implement the first substitute()
behdad authored
234 property = _hb_ot_layout_get_glyph_property (layout, glyph);
aff831e @behdad Implement glyph properties
behdad authored
235
30bd763 @behdad Implement the first substitute()
behdad authored
236 if (property & LookupFlag::MarkAttachmentType)
aff831e @behdad Implement glyph properties
behdad authored
237 return HB_OT_LAYOUT_GLYPH_CLASS_MARK;
238
30bd763 @behdad Implement the first substitute()
behdad authored
239 return (hb_ot_layout_glyph_class_t) property;
ead428d @behdad More public api
behdad authored
240 }
241
aff831e @behdad Implement glyph properties
behdad authored
242 void
e50c397 @behdad Rename HB_OT_Layout to hb_ot_layout_t
behdad authored
243 hb_ot_layout_set_glyph_class (hb_ot_layout_t *layout,
2d15e72 @behdad Give it a start at GSUB
behdad authored
244 hb_codepoint_t glyph,
aff831e @behdad Implement glyph properties
behdad authored
245 hb_ot_layout_glyph_class_t klass)
246 {
247 /* TODO optimize this, similar to old harfbuzz code for example */
248
249 hb_ot_layout_class_t gdef_klass;
250 int len = layout->new_gdef.len;
251
4acaffd @behdad [HB] Don't use G_LIKELY!
behdad authored
252 if (HB_UNLIKELY (glyph > 65535))
30bd763 @behdad Implement the first substitute()
behdad authored
253 return;
254
aff831e @behdad Implement glyph properties
behdad authored
255 if (glyph >= len) {
256 int new_len;
590d55c @behdad [GDEF] Finish public API
behdad authored
257 unsigned char *new_klasses;
aff831e @behdad Implement glyph properties
behdad authored
258
259 new_len = len == 0 ? 120 : 2 * len;
260 if (new_len > 65535)
261 new_len = 65535;
590d55c @behdad [GDEF] Finish public API
behdad authored
262 new_klasses = (unsigned char *) realloc (layout->new_gdef.klasses, new_len * sizeof (unsigned char));
aff831e @behdad Implement glyph properties
behdad authored
263
4acaffd @behdad [HB] Don't use G_LIKELY!
behdad authored
264 if (HB_UNLIKELY (!new_klasses))
aff831e @behdad Implement glyph properties
behdad authored
265 return;
ce48f03 @behdad Merge harfbuzz-ng
behdad authored
266
aff831e @behdad Implement glyph properties
behdad authored
267 memset (new_klasses + len, 0, new_len - len);
268
269 layout->new_gdef.klasses = new_klasses;
270 layout->new_gdef.len = new_len;
271 }
272
273 switch (klass) {
274 default:
275 case HB_OT_LAYOUT_GLYPH_CLASS_UNCLASSIFIED: gdef_klass = GDEF::UnclassifiedGlyph; break;
276 case HB_OT_LAYOUT_GLYPH_CLASS_BASE_GLYPH: gdef_klass = GDEF::BaseGlyph; break;
277 case HB_OT_LAYOUT_GLYPH_CLASS_LIGATURE: gdef_klass = GDEF::LigatureGlyph; break;
278 case HB_OT_LAYOUT_GLYPH_CLASS_MARK: gdef_klass = GDEF::MarkGlyph; break;
279 case HB_OT_LAYOUT_GLYPH_CLASS_COMPONENT: gdef_klass = GDEF::ComponentGlyph; break;
280 }
281
282 layout->new_gdef.klasses[glyph] = gdef_klass;
283 return;
284 }
590d55c @behdad [GDEF] Finish public API
behdad authored
285
286 void
e50c397 @behdad Rename HB_OT_Layout to hb_ot_layout_t
behdad authored
287 hb_ot_layout_build_glyph_classes (hb_ot_layout_t *layout,
288 uint16_t num_total_glyphs,
2d15e72 @behdad Give it a start at GSUB
behdad authored
289 hb_codepoint_t *glyphs,
e50c397 @behdad Rename HB_OT_Layout to hb_ot_layout_t
behdad authored
290 unsigned char *klasses,
291 uint16_t count)
590d55c @behdad [GDEF] Finish public API
behdad authored
292 {
4acaffd @behdad [HB] Don't use G_LIKELY!
behdad authored
293 if (HB_UNLIKELY (!count || !glyphs || !klasses))
590d55c @behdad [GDEF] Finish public API
behdad authored
294 return;
295
296 if (layout->new_gdef.len == 0) {
297 layout->new_gdef.klasses = (unsigned char *) calloc (num_total_glyphs, sizeof (unsigned char));
298 layout->new_gdef.len = count;
299 }
300
f4c9514 @behdad [HB] Simplify more arrays
behdad authored
301 for (unsigned int i = 0; i < count; i++)
590d55c @behdad [GDEF] Finish public API
behdad authored
302 hb_ot_layout_set_glyph_class (layout, glyphs[i], (hb_ot_layout_glyph_class_t) klasses[i]);
303 }
706ab25 @behdad Add script and language public getter API
behdad authored
304
305 /*
306 * GSUB/GPOS
307 */
308
309 static const GSUBGPOS&
310 get_gsubgpos_table (hb_ot_layout_t *layout,
311 hb_ot_layout_table_type_t table_type)
312 {
313 switch (table_type) {
314 case HB_OT_LAYOUT_TABLE_TYPE_GSUB: return *(layout->gsub);
315 case HB_OT_LAYOUT_TABLE_TYPE_GPOS: return *(layout->gpos);
8b83580 @behdad [HB] Use templates for Null objects
behdad authored
316 default: return Null(GSUBGPOS);
706ab25 @behdad Add script and language public getter API
behdad authored
317 }
318 }
319
320
321 unsigned int
c447335 @behdad [hb-ot-layout] Add proper namespace to accessors
behdad authored
322 hb_ot_layout_table_get_script_count (hb_ot_layout_t *layout,
323 hb_ot_layout_table_type_t table_type)
706ab25 @behdad Add script and language public getter API
behdad authored
324 {
325 const GSUBGPOS &g = get_gsubgpos_table (layout, table_type);
326
327 return g.get_script_count ();
328 }
329
330 hb_tag_t
c447335 @behdad [hb-ot-layout] Add proper namespace to accessors
behdad authored
331 hb_ot_layout_table_get_script_tag (hb_ot_layout_t *layout,
332 hb_ot_layout_table_type_t table_type,
333 unsigned int script_index)
706ab25 @behdad Add script and language public getter API
behdad authored
334 {
335 const GSUBGPOS &g = get_gsubgpos_table (layout, table_type);
336
337 return g.get_script_tag (script_index);
338 }
339
340 hb_bool_t
c447335 @behdad [hb-ot-layout] Add proper namespace to accessors
behdad authored
341 hb_ot_layout_table_find_script (hb_ot_layout_t *layout,
342 hb_ot_layout_table_type_t table_type,
343 hb_tag_t script_tag,
344 unsigned int *script_index)
706ab25 @behdad Add script and language public getter API
behdad authored
345 {
4a26ea4 @behdad Finish script, language, and feature public API
behdad authored
346 ASSERT_STATIC (NO_INDEX == HB_OT_LAYOUT_NO_SCRIPT_INDEX);
706ab25 @behdad Add script and language public getter API
behdad authored
347 const GSUBGPOS &g = get_gsubgpos_table (layout, table_type);
348
349 if (g.find_script_index (script_tag, script_index))
350 return TRUE;
351
352 /* try finding 'DFLT' */
353 if (g.find_script_index (HB_OT_LAYOUT_TAG_DEFAULT_SCRIPT, script_index))
354 return FALSE;
355
356 /* try with 'dflt'; MS site has had typos and many fonts use it now :( */
357 if (g.find_script_index (HB_OT_LAYOUT_TAG_DEFAULT_LANGUAGE, script_index))
358 return FALSE;
359
360 if (script_index) *script_index = HB_OT_LAYOUT_NO_SCRIPT_INDEX;
361 return FALSE;
362 }
363
364 unsigned int
c447335 @behdad [hb-ot-layout] Add proper namespace to accessors
behdad authored
365 hb_ot_layout_table_get_feature_count (hb_ot_layout_t *layout,
366 hb_ot_layout_table_type_t table_type)
367 {
368 const GSUBGPOS &g = get_gsubgpos_table (layout, table_type);
369
370 return g.get_feature_count ();
371 }
372
373 hb_tag_t
374 hb_ot_layout_table_get_feature_tag (hb_ot_layout_t *layout,
375 hb_ot_layout_table_type_t table_type,
376 unsigned int feature_index)
377 {
378 const GSUBGPOS &g = get_gsubgpos_table (layout, table_type);
379
380 return g.get_feature_tag (feature_index);
381 }
382
383 hb_bool_t
384 hb_ot_layout_table_find_feature (hb_ot_layout_t *layout,
706ab25 @behdad Add script and language public getter API
behdad authored
385 hb_ot_layout_table_type_t table_type,
c447335 @behdad [hb-ot-layout] Add proper namespace to accessors
behdad authored
386 hb_tag_t feature_tag,
387 unsigned int *feature_index)
388 {
389 ASSERT_STATIC (NO_INDEX == HB_OT_LAYOUT_NO_FEATURE_INDEX);
390 const GSUBGPOS &g = get_gsubgpos_table (layout, table_type);
391
392 if (g.find_feature_index (feature_tag, feature_index))
393 return TRUE;
394
395 if (feature_index) *feature_index = HB_OT_LAYOUT_NO_FEATURE_INDEX;
396 return FALSE;
397 }
398
399 unsigned int
400 hb_ot_layout_table_get_lookup_count (hb_ot_layout_t *layout,
401 hb_ot_layout_table_type_t table_type)
402 {
403 const GSUBGPOS &g = get_gsubgpos_table (layout, table_type);
404
405 return g.get_lookup_count ();
406 }
407
408
409 unsigned int
410 hb_ot_layout_script_get_language_count (hb_ot_layout_t *layout,
411 hb_ot_layout_table_type_t table_type,
412 unsigned int script_index)
706ab25 @behdad Add script and language public getter API
behdad authored
413 {
414 const Script &s = get_gsubgpos_table (layout, table_type).get_script (script_index);
415
416 return s.get_lang_sys_count ();
417 }
418
419 hb_tag_t
c447335 @behdad [hb-ot-layout] Add proper namespace to accessors
behdad authored
420 hb_ot_layout_script_get_language_tag (hb_ot_layout_t *layout,
421 hb_ot_layout_table_type_t table_type,
422 unsigned int script_index,
423 unsigned int language_index)
706ab25 @behdad Add script and language public getter API
behdad authored
424 {
425 const Script &s = get_gsubgpos_table (layout, table_type).get_script (script_index);
426
427 return s.get_lang_sys_tag (language_index);
428 }
429
430 hb_bool_t
c447335 @behdad [hb-ot-layout] Add proper namespace to accessors
behdad authored
431 hb_ot_layout_script_find_language (hb_ot_layout_t *layout,
432 hb_ot_layout_table_type_t table_type,
433 unsigned int script_index,
434 hb_tag_t language_tag,
435 unsigned int *language_index)
706ab25 @behdad Add script and language public getter API
behdad authored
436 {
4a26ea4 @behdad Finish script, language, and feature public API
behdad authored
437 ASSERT_STATIC (NO_INDEX == HB_OT_LAYOUT_DEFAULT_LANGUAGE_INDEX);
706ab25 @behdad Add script and language public getter API
behdad authored
438 const Script &s = get_gsubgpos_table (layout, table_type).get_script (script_index);
439
4a26ea4 @behdad Finish script, language, and feature public API
behdad authored
440 if (s.find_lang_sys_index (language_tag, language_index))
706ab25 @behdad Add script and language public getter API
behdad authored
441 return TRUE;
442
443 /* try with 'dflt'; MS site has had typos and many fonts use it now :( */
4a26ea4 @behdad Finish script, language, and feature public API
behdad authored
444 if (s.find_lang_sys_index (HB_OT_LAYOUT_TAG_DEFAULT_LANGUAGE, language_index))
706ab25 @behdad Add script and language public getter API
behdad authored
445 return FALSE;
446
4a26ea4 @behdad Finish script, language, and feature public API
behdad authored
447 if (language_index) *language_index = HB_OT_LAYOUT_DEFAULT_LANGUAGE_INDEX;
706ab25 @behdad Add script and language public getter API
behdad authored
448 return FALSE;
4a26ea4 @behdad Finish script, language, and feature public API
behdad authored
449 }
706ab25 @behdad Add script and language public getter API
behdad authored
450
4a26ea4 @behdad Finish script, language, and feature public API
behdad authored
451 hb_bool_t
c447335 @behdad [hb-ot-layout] Add proper namespace to accessors
behdad authored
452 hb_ot_layout_language_get_required_feature_index (hb_ot_layout_t *layout,
453 hb_ot_layout_table_type_t table_type,
454 unsigned int script_index,
455 unsigned int language_index,
456 unsigned int *feature_index)
4a26ea4 @behdad Finish script, language, and feature public API
behdad authored
457 {
458 const LangSys &l = get_gsubgpos_table (layout, table_type).get_script (script_index).get_lang_sys (language_index);
706ab25 @behdad Add script and language public getter API
behdad authored
459
4a26ea4 @behdad Finish script, language, and feature public API
behdad authored
460 if (feature_index) *feature_index = l.get_required_feature_index ();
706ab25 @behdad Add script and language public getter API
behdad authored
461
4a26ea4 @behdad Finish script, language, and feature public API
behdad authored
462 return l.has_required_feature ();
463 }
706ab25 @behdad Add script and language public getter API
behdad authored
464
4a26ea4 @behdad Finish script, language, and feature public API
behdad authored
465 unsigned int
c447335 @behdad [hb-ot-layout] Add proper namespace to accessors
behdad authored
466 hb_ot_layout_language_get_feature_count (hb_ot_layout_t *layout,
467 hb_ot_layout_table_type_t table_type,
468 unsigned int script_index,
469 unsigned int language_index)
4a26ea4 @behdad Finish script, language, and feature public API
behdad authored
470 {
471 const LangSys &l = get_gsubgpos_table (layout, table_type).get_script (script_index).get_lang_sys (language_index);
472
473 return l.get_feature_count ();
474 }
475
c447335 @behdad [hb-ot-layout] Add proper namespace to accessors
behdad authored
476 unsigned int
477 hb_ot_layout_language_get_feature_index (hb_ot_layout_t *layout,
478 hb_ot_layout_table_type_t table_type,
479 unsigned int script_index,
480 unsigned int language_index,
481 unsigned int num_feature)
4a26ea4 @behdad Finish script, language, and feature public API
behdad authored
482 {
483 const GSUBGPOS &g = get_gsubgpos_table (layout, table_type);
484 const LangSys &l = g.get_script (script_index).get_lang_sys (language_index);
485
c447335 @behdad [hb-ot-layout] Add proper namespace to accessors
behdad authored
486 return l.get_feature_index (num_feature);
487 }
488
489 hb_tag_t
490 hb_ot_layout_language_get_feature_tag (hb_ot_layout_t *layout,
491 hb_ot_layout_table_type_t table_type,
492 unsigned int script_index,
493 unsigned int language_index,
494 unsigned int num_feature)
495 {
496 const GSUBGPOS &g = get_gsubgpos_table (layout, table_type);
497 const LangSys &l = g.get_script (script_index).get_lang_sys (language_index);
498 unsigned int feature_index = l.get_feature_index (num_feature);
4a26ea4 @behdad Finish script, language, and feature public API
behdad authored
499
500 return g.get_feature_tag (feature_index);
501 }
502
503
504 hb_bool_t
c447335 @behdad [hb-ot-layout] Add proper namespace to accessors
behdad authored
505 hb_ot_layout_language_find_feature (hb_ot_layout_t *layout,
506 hb_ot_layout_table_type_t table_type,
507 unsigned int script_index,
508 unsigned int language_index,
509 hb_tag_t feature_tag,
510 unsigned int *feature_index)
4a26ea4 @behdad Finish script, language, and feature public API
behdad authored
511 {
512 ASSERT_STATIC (NO_INDEX == HB_OT_LAYOUT_NO_FEATURE_INDEX);
513 const GSUBGPOS &g = get_gsubgpos_table (layout, table_type);
514 const LangSys &l = g.get_script (script_index).get_lang_sys (language_index);
515
f4c9514 @behdad [HB] Simplify more arrays
behdad authored
516 unsigned int num_features = l.get_feature_count ();
517 for (unsigned int i = 0; i < num_features; i++) {
4a26ea4 @behdad Finish script, language, and feature public API
behdad authored
518 unsigned int f_index = l.get_feature_index (i);
519
520 if (feature_tag == g.get_feature_tag (f_index)) {
521 if (feature_index) *feature_index = f_index;
522 return TRUE;
523 }
524 }
706ab25 @behdad Add script and language public getter API
behdad authored
525
4a26ea4 @behdad Finish script, language, and feature public API
behdad authored
526 if (feature_index) *feature_index = HB_OT_LAYOUT_NO_FEATURE_INDEX;
706ab25 @behdad Add script and language public getter API
behdad authored
527 return FALSE;
528 }
c447335 @behdad [hb-ot-layout] Add proper namespace to accessors
behdad authored
529
530 unsigned int
531 hb_ot_layout_feature_get_lookup_count (hb_ot_layout_t *layout,
532 hb_ot_layout_table_type_t table_type,
533 unsigned int feature_index)
534 {
535 const GSUBGPOS &g = get_gsubgpos_table (layout, table_type);
536 const Feature &f = g.get_feature (feature_index);
537
538 return f.get_lookup_count ();
539 }
540
541 unsigned int
542 hb_ot_layout_feature_get_lookup_index (hb_ot_layout_t *layout,
543 hb_ot_layout_table_type_t table_type,
544 unsigned int feature_index,
545 unsigned int num_lookup)
546 {
547 const GSUBGPOS &g = get_gsubgpos_table (layout, table_type);
548 const Feature &f = g.get_feature (feature_index);
549
550 return f.get_lookup_index (num_lookup);
551 }
2d15e72 @behdad Give it a start at GSUB
behdad authored
552
553 /*
554 * GSUB
555 */
556
557 hb_bool_t
558 hb_ot_layout_substitute_lookup (hb_ot_layout_t *layout,
559 hb_buffer_t *buffer,
560 unsigned int lookup_index,
561 hb_ot_layout_feature_mask_t mask)
562 {
fc36d94 @behdad [GSUB] Add GSUB::substitute_lookup()
behdad authored
563 return layout->gsub->substitute_lookup (layout, buffer, lookup_index, mask);
5a0b791 @behdad [harfbuzz/GSUB] towards a partially working GSUB
behdad authored
564 }
565
9c42f05 @behdad Switch Pango to new, defunt, GPOS
behdad authored
566 /*
567 * GPOS
568 */
569
570 hb_bool_t
571 hb_ot_layout_position_lookup (hb_ot_layout_t *layout,
572 hb_buffer_t *buffer,
573 unsigned int lookup_index,
574 hb_ot_layout_feature_mask_t mask)
575 {
576 return layout->gpos->position_lookup (layout, buffer, lookup_index, mask);
577 }
578
5a0b791 @behdad [harfbuzz/GSUB] towards a partially working GSUB
behdad authored
579
580
d6aae5f @behdad [HB] Cleanup TODOs
behdad authored
581 /* TODO dupped, until he old code can be removed */
2d15e72 @behdad Give it a start at GSUB
behdad authored
582
5a0b791 @behdad [harfbuzz/GSUB] towards a partially working GSUB
behdad authored
583 static HB_Error
584 hb_buffer_duplicate_out_buffer( HB_Buffer buffer )
585 {
b857b49 @behdad [HB] Remove all references to the old code!
behdad authored
586 if (!buffer->alt_string)
587 buffer->alt_string = (HB_GlyphItemRec_ *) malloc (buffer->allocated * sizeof (buffer->out_string[0]));
2d15e72 @behdad Give it a start at GSUB
behdad authored
588
5a0b791 @behdad [harfbuzz/GSUB] towards a partially working GSUB
behdad authored
589 buffer->out_string = buffer->alt_string;
b857b49 @behdad [HB] Remove all references to the old code!
behdad authored
590 memcpy (buffer->out_string, buffer->in_string, buffer->out_length * sizeof (buffer->out_string[0]));
5a0b791 @behdad [harfbuzz/GSUB] towards a partially working GSUB
behdad authored
591 buffer->separate_out = TRUE;
2d15e72 @behdad Give it a start at GSUB
behdad authored
592
5a0b791 @behdad [harfbuzz/GSUB] towards a partially working GSUB
behdad authored
593 return HB_Err_Ok;
594 }
2d15e72 @behdad Give it a start at GSUB
behdad authored
595
596
597
b857b49 @behdad [HB] Remove all references to the old code!
behdad authored
598 /* XXX */
5a0b791 @behdad [harfbuzz/GSUB] towards a partially working GSUB
behdad authored
599 HB_INTERNAL HB_Error
600 _hb_buffer_add_output_glyph_ids( HB_Buffer buffer,
601 HB_UShort num_in,
602 HB_UShort num_out,
603 const GlyphID *glyph_data,
604 HB_UShort component,
605 HB_UShort ligID )
606 {
607 HB_Error error;
608 HB_UShort i;
609 HB_UInt properties;
610 HB_UInt cluster;
611
b857b49 @behdad [HB] Remove all references to the old code!
behdad authored
612 hb_buffer_ensure( buffer, buffer->out_pos + num_out );
613 /* XXX */
5a0b791 @behdad [harfbuzz/GSUB] towards a partially working GSUB
behdad authored
614
615 if ( !buffer->separate_out )
616 {
617 error = hb_buffer_duplicate_out_buffer( buffer );
618 if ( error )
619 return error;
620 }
2d15e72 @behdad Give it a start at GSUB
behdad authored
621
5a0b791 @behdad [harfbuzz/GSUB] towards a partially working GSUB
behdad authored
622 properties = buffer->in_string[buffer->in_pos].properties;
623 cluster = buffer->in_string[buffer->in_pos].cluster;
624 if ( component == 0xFFFF )
625 component = buffer->in_string[buffer->in_pos].component;
626 if ( ligID == 0xFFFF )
627 ligID = buffer->in_string[buffer->in_pos].ligID;
2d15e72 @behdad Give it a start at GSUB
behdad authored
628
5a0b791 @behdad [harfbuzz/GSUB] towards a partially working GSUB
behdad authored
629 for ( i = 0; i < num_out; i++ )
630 {
631 HB_GlyphItem item = &buffer->out_string[buffer->out_pos + i];
632
633 item->gindex = glyph_data[i];
634 item->properties = properties;
635 item->cluster = cluster;
636 item->component = component;
637 item->ligID = ligID;
638 item->gproperty = HB_GLYPH_PROPERTY_UNKNOWN;
2d15e72 @behdad Give it a start at GSUB
behdad authored
639 }
640
5a0b791 @behdad [harfbuzz/GSUB] towards a partially working GSUB
behdad authored
641 buffer->in_pos += num_in;
642 buffer->out_pos += num_out;
643
644 buffer->out_length = buffer->out_pos;
645
646 return HB_Err_Ok;
2d15e72 @behdad Give it a start at GSUB
behdad authored
647 }
5a0b791 @behdad [harfbuzz/GSUB] towards a partially working GSUB
behdad authored
648
Something went wrong with that request. Please try again.