OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 1998-2004 David Turner and Werner Lemberg | 2 * Copyright © 1998-2004 David Turner and Werner Lemberg |
3 * Copyright (C) 2006 Behdad Esfahbod | 3 * Copyright © 2006 Behdad Esfahbod |
4 * Copyright (C) 2007,2008,2009 Red Hat, Inc. | 4 * Copyright © 2007,2008,2009 Red Hat, Inc. |
5 * | 5 * |
6 * This is part of HarfBuzz, a text shaping library. | 6 * This is part of HarfBuzz, a text shaping library. |
7 * | 7 * |
8 * Permission is hereby granted, without written agreement and without | 8 * Permission is hereby granted, without written agreement and without |
9 * license or royalty fees, to use, copy, modify, and distribute this | 9 * license or royalty fees, to use, copy, modify, and distribute this |
10 * software and its documentation for any purpose, provided that the | 10 * software and its documentation for any purpose, provided that the |
11 * above copyright notice and the following two paragraphs appear in | 11 * above copyright notice and the following two paragraphs appear in |
12 * all copies of this software. | 12 * all copies of this software. |
13 * | 13 * |
14 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR | 14 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR |
15 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES | 15 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES |
16 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN | 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 | 17 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH |
18 * DAMAGE. | 18 * DAMAGE. |
19 * | 19 * |
20 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, | 20 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, |
21 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND | 21 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND |
22 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS | 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 | 23 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO |
24 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | 24 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
25 * | 25 * |
26 * Red Hat Author(s): Behdad Esfahbod | 26 * Red Hat Author(s): Behdad Esfahbod |
27 */ | 27 */ |
28 | 28 |
29 #define HB_OT_LAYOUT_CC | |
30 | |
31 #include "hb-ot-layout-private.hh" | 29 #include "hb-ot-layout-private.hh" |
32 | 30 |
33 #include "hb-ot-layout-gdef-private.hh" | 31 #include "hb-ot-layout-gdef-table.hh" |
34 #include "hb-ot-layout-gsub-private.hh" | 32 #include "hb-ot-layout-gsub-table.hh" |
35 #include "hb-ot-layout-gpos-private.hh" | 33 #include "hb-ot-layout-gpos-table.hh" |
| 34 #include "hb-ot-maxp-table.hh" |
36 | 35 |
37 | 36 |
38 #include <stdlib.h> | 37 #include <stdlib.h> |
39 #include <string.h> | 38 #include <string.h> |
40 | 39 |
41 HB_BEGIN_DECLS | |
42 | 40 |
43 | 41 |
44 hb_ot_layout_t * | 42 hb_ot_layout_t * |
45 _hb_ot_layout_new (hb_face_t *face) | 43 _hb_ot_layout_create (hb_face_t *face) |
46 { | 44 { |
47 /* Remove this object altogether */ | 45 /* TODO Remove this object altogether */ |
48 hb_ot_layout_t *layout = (hb_ot_layout_t *) calloc (1, sizeof (hb_ot_layout_t)
); | 46 hb_ot_layout_t *layout = (hb_ot_layout_t *) calloc (1, sizeof (hb_ot_layout_t)
); |
49 | 47 |
50 layout->gdef_blob = Sanitizer<GDEF>::sanitize (hb_face_get_table (face, HB_OT_
TAG_GDEF)); | 48 layout->gdef_blob = Sanitizer<GDEF>::sanitize (hb_face_reference_table (face,
HB_OT_TAG_GDEF)); |
51 layout->gdef = Sanitizer<GDEF>::lock_instance (layout->gdef_blob); | 49 layout->gdef = Sanitizer<GDEF>::lock_instance (layout->gdef_blob); |
52 | 50 |
53 layout->gsub_blob = Sanitizer<GSUB>::sanitize (hb_face_get_table (face, HB_OT_
TAG_GSUB)); | 51 layout->gsub_blob = Sanitizer<GSUB>::sanitize (hb_face_reference_table (face,
HB_OT_TAG_GSUB)); |
54 layout->gsub = Sanitizer<GSUB>::lock_instance (layout->gsub_blob); | 52 layout->gsub = Sanitizer<GSUB>::lock_instance (layout->gsub_blob); |
55 | 53 |
56 layout->gpos_blob = Sanitizer<GPOS>::sanitize (hb_face_get_table (face, HB_OT_
TAG_GPOS)); | 54 layout->gpos_blob = Sanitizer<GPOS>::sanitize (hb_face_reference_table (face,
HB_OT_TAG_GPOS)); |
57 layout->gpos = Sanitizer<GPOS>::lock_instance (layout->gpos_blob); | 55 layout->gpos = Sanitizer<GPOS>::lock_instance (layout->gpos_blob); |
58 | 56 |
59 return layout; | 57 return layout; |
60 } | 58 } |
61 | 59 |
62 void | 60 void |
63 _hb_ot_layout_free (hb_ot_layout_t *layout) | 61 _hb_ot_layout_destroy (hb_ot_layout_t *layout) |
64 { | 62 { |
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); | 63 hb_blob_destroy (layout->gdef_blob); |
70 hb_blob_destroy (layout->gsub_blob); | 64 hb_blob_destroy (layout->gsub_blob); |
71 hb_blob_destroy (layout->gpos_blob); | 65 hb_blob_destroy (layout->gpos_blob); |
72 | 66 |
73 free (layout); | 67 free (layout); |
74 } | 68 } |
75 | 69 |
76 static inline const GDEF& | 70 static inline const GDEF& |
77 _get_gdef (hb_face_t *face) | 71 _get_gdef (hb_face_t *face) |
78 { | 72 { |
79 return likely (face->ot_layout && face->ot_layout->gdef) ? *face->ot_layout->g
def : Null(GDEF); | 73 return likely (face->ot_layout && face->ot_layout->gdef) ? *face->ot_layout->g
def : Null(GDEF); |
80 } | 74 } |
81 | |
82 static inline const GSUB& | 75 static inline const GSUB& |
83 _get_gsub (hb_face_t *face) | 76 _get_gsub (hb_face_t *face) |
84 { | 77 { |
85 return likely (face->ot_layout && face->ot_layout->gsub) ? *face->ot_layout->g
sub : Null(GSUB); | 78 return likely (face->ot_layout && face->ot_layout->gsub) ? *face->ot_layout->g
sub : Null(GSUB); |
86 } | 79 } |
87 | |
88 static inline const GPOS& | 80 static inline const GPOS& |
89 _get_gpos (hb_face_t *face) | 81 _get_gpos (hb_face_t *face) |
90 { | 82 { |
91 return likely (face->ot_layout && face->ot_layout->gpos) ? *face->ot_layout->g
pos : Null(GPOS); | 83 return likely (face->ot_layout && face->ot_layout->gpos) ? *face->ot_layout->g
pos : Null(GPOS); |
92 } | 84 } |
93 | 85 |
94 | 86 |
95 /* | 87 /* |
96 * GDEF | 88 * GDEF |
97 */ | 89 */ |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 hb_codepoint_t glyph, | 178 hb_codepoint_t glyph, |
187 unsigned int start_offset, | 179 unsigned int start_offset, |
188 unsigned int *point_count /* IN/OUT */, | 180 unsigned int *point_count /* IN/OUT */, |
189 unsigned int *point_array /* OUT */) | 181 unsigned int *point_array /* OUT */) |
190 { | 182 { |
191 return _get_gdef (face).get_attach_points (glyph, start_offset, point_count, p
oint_array); | 183 return _get_gdef (face).get_attach_points (glyph, start_offset, point_count, p
oint_array); |
192 } | 184 } |
193 | 185 |
194 unsigned int | 186 unsigned int |
195 hb_ot_layout_get_ligature_carets (hb_font_t *font, | 187 hb_ot_layout_get_ligature_carets (hb_font_t *font, |
196 hb_face_t *face, | |
197 hb_direction_t direction, | 188 hb_direction_t direction, |
198 hb_codepoint_t glyph, | 189 hb_codepoint_t glyph, |
199 unsigned int start_offset, | 190 unsigned int start_offset, |
200 unsigned int *caret_count /* IN/OUT */, | 191 unsigned int *caret_count /* IN/OUT */, |
201 int *caret_array /* OUT */) | 192 int *caret_array /* OUT */) |
202 { | 193 { |
203 hb_ot_layout_context_t c; | 194 return _get_gdef (font->face).get_lig_carets (font, direction, glyph, start_of
fset, caret_count, caret_array); |
204 c.font = font; | |
205 c.face = face; | |
206 return _get_gdef (face).get_lig_carets (&c, direction, glyph, start_offset, ca
ret_count, caret_array); | |
207 } | 195 } |
208 | 196 |
209 /* | 197 /* |
210 * GSUB/GPOS | 198 * GSUB/GPOS |
211 */ | 199 */ |
212 | 200 |
213 static const GSUBGPOS& | 201 static const GSUBGPOS& |
214 get_gsubgpos_table (hb_face_t *face, | 202 get_gsubgpos_table (hb_face_t *face, |
215 hb_tag_t table_tag) | 203 hb_tag_t table_tag) |
216 { | 204 { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 return FALSE; | 244 return FALSE; |
257 | 245 |
258 if (script_index) *script_index = HB_OT_LAYOUT_NO_SCRIPT_INDEX; | 246 if (script_index) *script_index = HB_OT_LAYOUT_NO_SCRIPT_INDEX; |
259 return FALSE; | 247 return FALSE; |
260 } | 248 } |
261 | 249 |
262 hb_bool_t | 250 hb_bool_t |
263 hb_ot_layout_table_choose_script (hb_face_t *face, | 251 hb_ot_layout_table_choose_script (hb_face_t *face, |
264 hb_tag_t table_tag, | 252 hb_tag_t table_tag, |
265 const hb_tag_t *script_tags, | 253 const hb_tag_t *script_tags, |
266 » » » » unsigned int *script_index) | 254 » » » » unsigned int *script_index, |
| 255 » » » » hb_tag_t *chosen_script) |
267 { | 256 { |
268 ASSERT_STATIC (Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_NO_SCRIPT_INDEX); | 257 ASSERT_STATIC (Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_NO_SCRIPT_INDEX); |
269 const GSUBGPOS &g = get_gsubgpos_table (face, table_tag); | 258 const GSUBGPOS &g = get_gsubgpos_table (face, table_tag); |
270 | 259 |
271 while (*script_tags) | 260 while (*script_tags) |
272 { | 261 { |
273 if (g.find_script_index (*script_tags, script_index)) | 262 if (g.find_script_index (*script_tags, script_index)) { |
| 263 if (chosen_script) |
| 264 *chosen_script = *script_tags; |
274 return TRUE; | 265 return TRUE; |
| 266 } |
275 script_tags++; | 267 script_tags++; |
276 } | 268 } |
277 | 269 |
278 /* try finding 'DFLT' */ | 270 /* try finding 'DFLT' */ |
279 if (g.find_script_index (HB_OT_TAG_DEFAULT_SCRIPT, script_index)) | 271 if (g.find_script_index (HB_OT_TAG_DEFAULT_SCRIPT, script_index)) { |
| 272 if (chosen_script) |
| 273 *chosen_script = HB_OT_TAG_DEFAULT_SCRIPT; |
280 return FALSE; | 274 return FALSE; |
| 275 } |
281 | 276 |
282 /* try with 'dflt'; MS site has had typos and many fonts use it now :( */ | 277 /* try with 'dflt'; MS site has had typos and many fonts use it now :( */ |
283 if (g.find_script_index (HB_OT_TAG_DEFAULT_LANGUAGE, script_index)) | 278 if (g.find_script_index (HB_OT_TAG_DEFAULT_LANGUAGE, script_index)) { |
| 279 if (chosen_script) |
| 280 *chosen_script = HB_OT_TAG_DEFAULT_LANGUAGE; |
284 return FALSE; | 281 return FALSE; |
| 282 } |
| 283 |
| 284 /* try with 'latn'; some old fonts put their features there even though |
| 285 they're really trying to support Thai, for example :( */ |
| 286 #define HB_OT_TAG_LATIN_SCRIPT HB_TAG ('l', 'a', 't', 'n') |
| 287 if (g.find_script_index (HB_OT_TAG_LATIN_SCRIPT, script_index)) { |
| 288 if (chosen_script) |
| 289 *chosen_script = HB_OT_TAG_LATIN_SCRIPT; |
| 290 return FALSE; |
| 291 } |
285 | 292 |
286 if (script_index) *script_index = HB_OT_LAYOUT_NO_SCRIPT_INDEX; | 293 if (script_index) *script_index = HB_OT_LAYOUT_NO_SCRIPT_INDEX; |
| 294 if (chosen_script) |
| 295 *chosen_script = HB_OT_LAYOUT_NO_SCRIPT_INDEX; |
287 return FALSE; | 296 return FALSE; |
288 } | 297 } |
289 | 298 |
290 unsigned int | 299 unsigned int |
291 hb_ot_layout_table_get_feature_tags (hb_face_t *face, | 300 hb_ot_layout_table_get_feature_tags (hb_face_t *face, |
292 hb_tag_t table_tag, | 301 hb_tag_t table_tag, |
293 unsigned int start_offset, | 302 unsigned int start_offset, |
294 unsigned int *feature_count /* IN/OUT */, | 303 unsigned int *feature_count /* IN/OUT */, |
295 hb_tag_t *feature_tags /* OUT */) | 304 hb_tag_t *feature_tags /* OUT */) |
296 { | 305 { |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 /* | 441 /* |
433 * GSUB | 442 * GSUB |
434 */ | 443 */ |
435 | 444 |
436 hb_bool_t | 445 hb_bool_t |
437 hb_ot_layout_has_substitution (hb_face_t *face) | 446 hb_ot_layout_has_substitution (hb_face_t *face) |
438 { | 447 { |
439 return &_get_gsub (face) != &Null(GSUB); | 448 return &_get_gsub (face) != &Null(GSUB); |
440 } | 449 } |
441 | 450 |
| 451 void |
| 452 hb_ot_layout_substitute_start (hb_buffer_t *buffer) |
| 453 { |
| 454 GSUB::substitute_start (buffer); |
| 455 } |
| 456 |
442 hb_bool_t | 457 hb_bool_t |
443 hb_ot_layout_substitute_lookup (hb_face_t *face, | 458 hb_ot_layout_substitute_lookup (hb_face_t *face, |
444 hb_buffer_t *buffer, | 459 hb_buffer_t *buffer, |
445 unsigned int lookup_index, | 460 unsigned int lookup_index, |
446 hb_mask_t mask) | 461 hb_mask_t mask) |
447 { | 462 { |
448 hb_ot_layout_context_t c; | 463 return _get_gsub (face).substitute_lookup (face, buffer, lookup_index, mask); |
449 c.font = NULL; | 464 } |
450 c.face = face; | 465 |
451 return _get_gsub (face).substitute_lookup (&c, buffer, lookup_index, mask); | 466 void |
| 467 hb_ot_layout_substitute_finish (hb_buffer_t *buffer HB_UNUSED) |
| 468 { |
| 469 GSUB::substitute_finish (buffer); |
452 } | 470 } |
453 | 471 |
454 | 472 |
455 /* | 473 /* |
456 * GPOS | 474 * GPOS |
457 */ | 475 */ |
458 | 476 |
459 hb_bool_t | 477 hb_bool_t |
460 hb_ot_layout_has_positioning (hb_face_t *face) | 478 hb_ot_layout_has_positioning (hb_face_t *face) |
461 { | 479 { |
462 return &_get_gpos (face) != &Null(GPOS); | 480 return &_get_gpos (face) != &Null(GPOS); |
463 } | 481 } |
464 | 482 |
| 483 void |
| 484 hb_ot_layout_position_start (hb_buffer_t *buffer) |
| 485 { |
| 486 GPOS::position_start (buffer); |
| 487 } |
| 488 |
465 hb_bool_t | 489 hb_bool_t |
466 hb_ot_layout_position_lookup (hb_font_t *font, | 490 hb_ot_layout_position_lookup (hb_font_t *font, |
467 hb_face_t *face, | |
468 hb_buffer_t *buffer, | 491 hb_buffer_t *buffer, |
469 unsigned int lookup_index, | 492 unsigned int lookup_index, |
470 hb_mask_t mask) | 493 hb_mask_t mask) |
471 { | 494 { |
472 hb_ot_layout_context_t c; | 495 return _get_gpos (font->face).position_lookup (font, buffer, lookup_index, mas
k); |
473 c.font = font; | |
474 c.face = face; | |
475 return _get_gpos (face).position_lookup (&c, buffer, lookup_index, mask); | |
476 } | 496 } |
477 | 497 |
478 void | 498 void |
479 hb_ot_layout_position_finish (hb_buffer_t *buffer) | 499 hb_ot_layout_position_finish (hb_buffer_t *buffer) |
480 { | 500 { |
481 GPOS::position_finish (buffer); | 501 GPOS::position_finish (buffer); |
482 } | 502 } |
483 | 503 |
484 | 504 |
485 HB_END_DECLS | |
OLD | NEW |