Behdad Esfahbod | fd92a3d | 2008-01-24 03:11:09 -0500 | [diff] [blame] | 1 | /* |
Behdad Esfahbod | 2409d5f | 2011-04-21 17:14:28 -0400 | [diff] [blame] | 2 | * Copyright © 1998-2004 David Turner and Werner Lemberg |
| 3 | * Copyright © 2006 Behdad Esfahbod |
| 4 | * Copyright © 2007,2008,2009 Red Hat, Inc. |
Behdad Esfahbod | f860366 | 2012-07-30 02:38:39 -0400 | [diff] [blame] | 5 | * Copyright © 2012 Google, Inc. |
Behdad Esfahbod | fd92a3d | 2008-01-24 03:11:09 -0500 | [diff] [blame] | 6 | * |
Behdad Esfahbod | c755cb3 | 2010-04-22 00:11:43 -0400 | [diff] [blame] | 7 | * This is part of HarfBuzz, a text shaping library. |
Behdad Esfahbod | fd92a3d | 2008-01-24 03:11:09 -0500 | [diff] [blame] | 8 | * |
| 9 | * Permission is hereby granted, without written agreement and without |
| 10 | * license or royalty fees, to use, copy, modify, and distribute this |
| 11 | * software and its documentation for any purpose, provided that the |
| 12 | * above copyright notice and the following two paragraphs appear in |
| 13 | * all copies of this software. |
| 14 | * |
| 15 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR |
| 16 | * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES |
| 17 | * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN |
| 18 | * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH |
| 19 | * DAMAGE. |
| 20 | * |
| 21 | * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, |
| 22 | * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 23 | * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS |
| 24 | * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO |
| 25 | * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
| 26 | * |
| 27 | * Red Hat Author(s): Behdad Esfahbod |
Behdad Esfahbod | f860366 | 2012-07-30 02:38:39 -0400 | [diff] [blame] | 28 | * Google Author(s): Behdad Esfahbod |
Behdad Esfahbod | fd92a3d | 2008-01-24 03:11:09 -0500 | [diff] [blame] | 29 | */ |
| 30 | |
Behdad Esfahbod | 22da7fd | 2010-05-12 18:23:21 -0400 | [diff] [blame] | 31 | #include "hb-ot-layout-private.hh" |
Behdad Esfahbod | fd92a3d | 2008-01-24 03:11:09 -0500 | [diff] [blame] | 32 | |
Behdad Esfahbod | 7a750ac | 2011-08-17 14:19:59 +0200 | [diff] [blame] | 33 | #include "hb-ot-layout-gdef-table.hh" |
| 34 | #include "hb-ot-layout-gsub-table.hh" |
| 35 | #include "hb-ot-layout-gpos-table.hh" |
| 36 | #include "hb-ot-maxp-table.hh" |
Behdad Esfahbod | fd92a3d | 2008-01-24 03:11:09 -0500 | [diff] [blame] | 37 | |
| 38 | #include <stdlib.h> |
Behdad Esfahbod | aff831e | 2008-01-24 06:03:45 -0500 | [diff] [blame] | 39 | #include <string.h> |
| 40 | |
Behdad Esfahbod | acdba3f | 2010-07-23 15:11:18 -0400 | [diff] [blame] | 41 | |
Behdad Esfahbod | cfe9882 | 2012-07-27 03:06:30 -0400 | [diff] [blame] | 42 | HB_SHAPER_DATA_ENSURE_DECLARE(ot, face) |
Behdad Esfahbod | 11f4c87 | 2012-07-30 02:36:46 -0400 | [diff] [blame] | 43 | |
Behdad Esfahbod | 0a4399c | 2010-05-19 15:45:06 -0400 | [diff] [blame] | 44 | hb_ot_layout_t * |
Behdad Esfahbod | 266b344 | 2011-05-03 00:35:53 -0400 | [diff] [blame] | 45 | _hb_ot_layout_create (hb_face_t *face) |
Behdad Esfahbod | 4a26ea4 | 2008-01-28 07:40:10 -0500 | [diff] [blame] | 46 | { |
Behdad Esfahbod | 0a4399c | 2010-05-19 15:45:06 -0400 | [diff] [blame] | 47 | hb_ot_layout_t *layout = (hb_ot_layout_t *) calloc (1, sizeof (hb_ot_layout_t)); |
Behdad Esfahbod | 3dcbdc2 | 2012-07-30 19:31:17 -0400 | [diff] [blame] | 48 | if (unlikely (!layout)) |
| 49 | return NULL; |
Behdad Esfahbod | 555d112 | 2010-01-26 12:58:59 -0500 | [diff] [blame] | 50 | |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 51 | layout->gdef_blob = OT::Sanitizer<OT::GDEF>::sanitize (face->reference_table (HB_OT_TAG_GDEF)); |
| 52 | layout->gdef = OT::Sanitizer<OT::GDEF>::lock_instance (layout->gdef_blob); |
Behdad Esfahbod | 70e0f2a | 2009-08-03 22:01:47 -0400 | [diff] [blame] | 53 | |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 54 | layout->gsub_blob = OT::Sanitizer<OT::GSUB>::sanitize (face->reference_table (HB_OT_TAG_GSUB)); |
| 55 | layout->gsub = OT::Sanitizer<OT::GSUB>::lock_instance (layout->gsub_blob); |
Behdad Esfahbod | 70e0f2a | 2009-08-03 22:01:47 -0400 | [diff] [blame] | 56 | |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 57 | layout->gpos_blob = OT::Sanitizer<OT::GPOS>::sanitize (face->reference_table (HB_OT_TAG_GPOS)); |
| 58 | layout->gpos = OT::Sanitizer<OT::GPOS>::lock_instance (layout->gpos_blob); |
Behdad Esfahbod | 0a4399c | 2010-05-19 15:45:06 -0400 | [diff] [blame] | 59 | |
Behdad Esfahbod | 6f76113 | 2012-08-02 04:00:31 -0400 | [diff] [blame] | 60 | layout->gsub_lookup_count = layout->gsub->get_lookup_count (); |
| 61 | layout->gpos_lookup_count = layout->gpos->get_lookup_count (); |
| 62 | |
Behdad Esfahbod | 1336ecd | 2012-08-01 21:46:36 -0400 | [diff] [blame] | 63 | layout->gsub_digests = (hb_set_digest_t *) calloc (layout->gsub->get_lookup_count (), sizeof (hb_set_digest_t)); |
| 64 | layout->gpos_digests = (hb_set_digest_t *) calloc (layout->gpos->get_lookup_count (), sizeof (hb_set_digest_t)); |
| 65 | |
Behdad Esfahbod | 6f76113 | 2012-08-02 04:00:31 -0400 | [diff] [blame] | 66 | if (unlikely ((layout->gsub_lookup_count && !layout->gsub_digests) || |
| 67 | (layout->gpos_lookup_count && !layout->gpos_digests))) |
Behdad Esfahbod | 1336ecd | 2012-08-01 21:46:36 -0400 | [diff] [blame] | 68 | { |
| 69 | _hb_ot_layout_destroy (layout); |
| 70 | return NULL; |
| 71 | } |
| 72 | |
Behdad Esfahbod | 6f76113 | 2012-08-02 04:00:31 -0400 | [diff] [blame] | 73 | for (unsigned int i = 0; i < layout->gsub_lookup_count; i++) |
Behdad Esfahbod | 1336ecd | 2012-08-01 21:46:36 -0400 | [diff] [blame] | 74 | layout->gsub->add_coverage (&layout->gsub_digests[i], i); |
Behdad Esfahbod | 6f76113 | 2012-08-02 04:00:31 -0400 | [diff] [blame] | 75 | for (unsigned int i = 0; i < layout->gpos_lookup_count; i++) |
Behdad Esfahbod | 1336ecd | 2012-08-01 21:46:36 -0400 | [diff] [blame] | 76 | layout->gpos->add_coverage (&layout->gpos_digests[i], i); |
| 77 | |
Behdad Esfahbod | 0a4399c | 2010-05-19 15:45:06 -0400 | [diff] [blame] | 78 | return layout; |
Behdad Esfahbod | 4a26ea4 | 2008-01-28 07:40:10 -0500 | [diff] [blame] | 79 | } |
| 80 | |
Behdad Esfahbod | fd92a3d | 2008-01-24 03:11:09 -0500 | [diff] [blame] | 81 | void |
Behdad Esfahbod | 266b344 | 2011-05-03 00:35:53 -0400 | [diff] [blame] | 82 | _hb_ot_layout_destroy (hb_ot_layout_t *layout) |
Behdad Esfahbod | fd92a3d | 2008-01-24 03:11:09 -0500 | [diff] [blame] | 83 | { |
Behdad Esfahbod | 70e0f2a | 2009-08-03 22:01:47 -0400 | [diff] [blame] | 84 | hb_blob_destroy (layout->gdef_blob); |
| 85 | hb_blob_destroy (layout->gsub_blob); |
| 86 | hb_blob_destroy (layout->gpos_blob); |
Behdad Esfahbod | 679f41f | 2009-08-04 21:32:06 -0400 | [diff] [blame] | 87 | |
Behdad Esfahbod | 1336ecd | 2012-08-01 21:46:36 -0400 | [diff] [blame] | 88 | free (layout->gsub_digests); |
| 89 | free (layout->gpos_digests); |
| 90 | |
Behdad Esfahbod | 9ea7368 | 2010-09-22 17:38:44 -0400 | [diff] [blame] | 91 | free (layout); |
Behdad Esfahbod | 2ebb89d | 2009-07-25 19:09:01 -0400 | [diff] [blame] | 92 | } |
| 93 | |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 94 | static inline const OT::GDEF& |
Behdad Esfahbod | 23c86aa | 2009-08-03 21:40:20 -0400 | [diff] [blame] | 95 | _get_gdef (hb_face_t *face) |
| 96 | { |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 97 | if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return OT::Null(OT::GDEF); |
Behdad Esfahbod | ea278d3 | 2012-07-27 02:12:28 -0400 | [diff] [blame] | 98 | return *hb_ot_layout_from_face (face)->gdef; |
Behdad Esfahbod | 23c86aa | 2009-08-03 21:40:20 -0400 | [diff] [blame] | 99 | } |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 100 | static inline const OT::GSUB& |
Behdad Esfahbod | 23c86aa | 2009-08-03 21:40:20 -0400 | [diff] [blame] | 101 | _get_gsub (hb_face_t *face) |
| 102 | { |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 103 | if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return OT::Null(OT::GSUB); |
Behdad Esfahbod | ea278d3 | 2012-07-27 02:12:28 -0400 | [diff] [blame] | 104 | return *hb_ot_layout_from_face (face)->gsub; |
Behdad Esfahbod | 23c86aa | 2009-08-03 21:40:20 -0400 | [diff] [blame] | 105 | } |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 106 | static inline const OT::GPOS& |
Behdad Esfahbod | 23c86aa | 2009-08-03 21:40:20 -0400 | [diff] [blame] | 107 | _get_gpos (hb_face_t *face) |
| 108 | { |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 109 | if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return OT::Null(OT::GPOS); |
Behdad Esfahbod | ea278d3 | 2012-07-27 02:12:28 -0400 | [diff] [blame] | 110 | return *hb_ot_layout_from_face (face)->gpos; |
Behdad Esfahbod | 23c86aa | 2009-08-03 21:40:20 -0400 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | |
Behdad Esfahbod | 590d55c | 2008-01-24 19:13:50 -0500 | [diff] [blame] | 114 | /* |
| 115 | * GDEF |
| 116 | */ |
| 117 | |
| 118 | hb_bool_t |
Behdad Esfahbod | 52ea477 | 2009-11-06 17:45:38 -0500 | [diff] [blame] | 119 | hb_ot_layout_has_glyph_classes (hb_face_t *face) |
Behdad Esfahbod | 590d55c | 2008-01-24 19:13:50 -0500 | [diff] [blame] | 120 | { |
Behdad Esfahbod | 23c86aa | 2009-08-03 21:40:20 -0400 | [diff] [blame] | 121 | return _get_gdef (face).has_glyph_classes (); |
Behdad Esfahbod | 590d55c | 2008-01-24 19:13:50 -0500 | [diff] [blame] | 122 | } |
| 123 | |
Behdad Esfahbod | 5a08ecf | 2012-11-16 13:34:29 -0800 | [diff] [blame] | 124 | hb_ot_layout_glyph_class_t |
| 125 | hb_ot_layout_get_glyph_class (hb_face_t *face, |
| 126 | hb_codepoint_t glyph) |
| 127 | { |
| 128 | return (hb_ot_layout_glyph_class_t) _get_gdef (face).get_glyph_class (glyph); |
| 129 | } |
Behdad Esfahbod | 4a2d844 | 2010-11-03 15:28:56 -0400 | [diff] [blame] | 130 | |
Behdad Esfahbod | 89ca8ee | 2012-11-16 13:53:40 -0800 | [diff] [blame] | 131 | void |
| 132 | hb_ot_layout_get_glyphs_in_class (hb_face_t *face, |
| 133 | hb_ot_layout_glyph_class_t klass, |
| 134 | hb_set_t *glyphs /* OUT */) |
| 135 | { |
| 136 | return _get_gdef (face).get_glyphs_in_class (klass, glyphs); |
| 137 | } |
| 138 | |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 139 | unsigned int |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 140 | hb_ot_layout_get_attach_points (hb_face_t *face, |
Behdad Esfahbod | 79420ad | 2009-05-26 12:24:16 -0400 | [diff] [blame] | 141 | hb_codepoint_t glyph, |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 142 | unsigned int start_offset, |
Behdad Esfahbod | 79420ad | 2009-05-26 12:24:16 -0400 | [diff] [blame] | 143 | unsigned int *point_count /* IN/OUT */, |
| 144 | unsigned int *point_array /* OUT */) |
| 145 | { |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 146 | return _get_gdef (face).get_attach_points (glyph, start_offset, point_count, point_array); |
Behdad Esfahbod | 62964af | 2009-05-26 12:40:10 -0400 | [diff] [blame] | 147 | } |
| 148 | |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 149 | unsigned int |
Behdad Esfahbod | e204674 | 2010-10-27 12:32:02 -0400 | [diff] [blame] | 150 | hb_ot_layout_get_ligature_carets (hb_font_t *font, |
Behdad Esfahbod | e204674 | 2010-10-27 12:32:02 -0400 | [diff] [blame] | 151 | hb_direction_t direction, |
| 152 | hb_codepoint_t glyph, |
| 153 | unsigned int start_offset, |
| 154 | unsigned int *caret_count /* IN/OUT */, |
| 155 | int *caret_array /* OUT */) |
Behdad Esfahbod | 62964af | 2009-05-26 12:40:10 -0400 | [diff] [blame] | 156 | { |
Behdad Esfahbod | abcfe9b | 2011-05-11 00:02:02 -0400 | [diff] [blame] | 157 | return _get_gdef (font->face).get_lig_carets (font, direction, glyph, start_offset, caret_count, caret_array); |
Behdad Esfahbod | 79420ad | 2009-05-26 12:24:16 -0400 | [diff] [blame] | 158 | } |
| 159 | |
Behdad Esfahbod | 05bd1b6 | 2012-07-30 19:30:01 -0400 | [diff] [blame] | 160 | |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 161 | /* |
| 162 | * GSUB/GPOS |
| 163 | */ |
| 164 | |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 165 | static const OT::GSUBGPOS& |
Behdad Esfahbod | 23c86aa | 2009-08-03 21:40:20 -0400 | [diff] [blame] | 166 | get_gsubgpos_table (hb_face_t *face, |
| 167 | hb_tag_t table_tag) |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 168 | { |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 169 | switch (table_tag) { |
Behdad Esfahbod | 23c86aa | 2009-08-03 21:40:20 -0400 | [diff] [blame] | 170 | case HB_OT_TAG_GSUB: return _get_gsub (face); |
| 171 | case HB_OT_TAG_GPOS: return _get_gpos (face); |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 172 | default: return OT::Null(OT::GSUBGPOS); |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 173 | } |
| 174 | } |
| 175 | |
| 176 | |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 177 | unsigned int |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 178 | hb_ot_layout_table_get_script_tags (hb_face_t *face, |
| 179 | hb_tag_t table_tag, |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 180 | unsigned int start_offset, |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 181 | unsigned int *script_count /* IN/OUT */, |
| 182 | hb_tag_t *script_tags /* OUT */) |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 183 | { |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 184 | const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 185 | |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 186 | return g.get_script_tags (start_offset, script_count, script_tags); |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | hb_bool_t |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 190 | hb_ot_layout_table_find_script (hb_face_t *face, |
| 191 | hb_tag_t table_tag, |
| 192 | hb_tag_t script_tag, |
| 193 | unsigned int *script_index) |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 194 | { |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 195 | ASSERT_STATIC (OT::Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_NO_SCRIPT_INDEX); |
| 196 | const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 197 | |
| 198 | if (g.find_script_index (script_tag, script_index)) |
Behdad Esfahbod | 0594a24 | 2012-06-05 20:35:40 -0400 | [diff] [blame] | 199 | return true; |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 200 | |
| 201 | /* try finding 'DFLT' */ |
Behdad Esfahbod | 8a3511a | 2009-11-04 19:45:39 -0500 | [diff] [blame] | 202 | if (g.find_script_index (HB_OT_TAG_DEFAULT_SCRIPT, script_index)) |
Behdad Esfahbod | 0594a24 | 2012-06-05 20:35:40 -0400 | [diff] [blame] | 203 | return false; |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 204 | |
Behdad Esfahbod | dca8aff | 2010-09-28 16:25:23 -0400 | [diff] [blame] | 205 | /* try with 'dflt'; MS site has had typos and many fonts use it now :(. |
| 206 | * including many versions of DejaVu Sans Mono! */ |
Behdad Esfahbod | 8a3511a | 2009-11-04 19:45:39 -0500 | [diff] [blame] | 207 | if (g.find_script_index (HB_OT_TAG_DEFAULT_LANGUAGE, script_index)) |
Behdad Esfahbod | 0594a24 | 2012-06-05 20:35:40 -0400 | [diff] [blame] | 208 | return false; |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 209 | |
| 210 | if (script_index) *script_index = HB_OT_LAYOUT_NO_SCRIPT_INDEX; |
Behdad Esfahbod | 0594a24 | 2012-06-05 20:35:40 -0400 | [diff] [blame] | 211 | return false; |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 212 | } |
| 213 | |
Behdad Esfahbod | 2014b8d | 2009-12-20 20:58:26 +0100 | [diff] [blame] | 214 | hb_bool_t |
| 215 | hb_ot_layout_table_choose_script (hb_face_t *face, |
| 216 | hb_tag_t table_tag, |
| 217 | const hb_tag_t *script_tags, |
Behdad Esfahbod | c47a31f | 2011-07-30 20:57:01 -0400 | [diff] [blame] | 218 | unsigned int *script_index, |
| 219 | hb_tag_t *chosen_script) |
Behdad Esfahbod | 2014b8d | 2009-12-20 20:58:26 +0100 | [diff] [blame] | 220 | { |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 221 | ASSERT_STATIC (OT::Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_NO_SCRIPT_INDEX); |
| 222 | const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); |
Behdad Esfahbod | 2014b8d | 2009-12-20 20:58:26 +0100 | [diff] [blame] | 223 | |
| 224 | while (*script_tags) |
| 225 | { |
Behdad Esfahbod | c47a31f | 2011-07-30 20:57:01 -0400 | [diff] [blame] | 226 | if (g.find_script_index (*script_tags, script_index)) { |
| 227 | if (chosen_script) |
| 228 | *chosen_script = *script_tags; |
Behdad Esfahbod | 0594a24 | 2012-06-05 20:35:40 -0400 | [diff] [blame] | 229 | return true; |
Behdad Esfahbod | c47a31f | 2011-07-30 20:57:01 -0400 | [diff] [blame] | 230 | } |
Behdad Esfahbod | 2014b8d | 2009-12-20 20:58:26 +0100 | [diff] [blame] | 231 | script_tags++; |
| 232 | } |
| 233 | |
| 234 | /* try finding 'DFLT' */ |
Behdad Esfahbod | c47a31f | 2011-07-30 20:57:01 -0400 | [diff] [blame] | 235 | if (g.find_script_index (HB_OT_TAG_DEFAULT_SCRIPT, script_index)) { |
| 236 | if (chosen_script) |
| 237 | *chosen_script = HB_OT_TAG_DEFAULT_SCRIPT; |
Behdad Esfahbod | 0594a24 | 2012-06-05 20:35:40 -0400 | [diff] [blame] | 238 | return false; |
Behdad Esfahbod | c47a31f | 2011-07-30 20:57:01 -0400 | [diff] [blame] | 239 | } |
Behdad Esfahbod | 2014b8d | 2009-12-20 20:58:26 +0100 | [diff] [blame] | 240 | |
| 241 | /* try with 'dflt'; MS site has had typos and many fonts use it now :( */ |
Behdad Esfahbod | c47a31f | 2011-07-30 20:57:01 -0400 | [diff] [blame] | 242 | if (g.find_script_index (HB_OT_TAG_DEFAULT_LANGUAGE, script_index)) { |
| 243 | if (chosen_script) |
| 244 | *chosen_script = HB_OT_TAG_DEFAULT_LANGUAGE; |
Behdad Esfahbod | 0594a24 | 2012-06-05 20:35:40 -0400 | [diff] [blame] | 245 | return false; |
Behdad Esfahbod | c47a31f | 2011-07-30 20:57:01 -0400 | [diff] [blame] | 246 | } |
Behdad Esfahbod | 2014b8d | 2009-12-20 20:58:26 +0100 | [diff] [blame] | 247 | |
Behdad Esfahbod | 71632c9 | 2012-01-22 15:31:44 -0500 | [diff] [blame] | 248 | /* try with 'latn'; some old fonts put their features there even though |
| 249 | they're really trying to support Thai, for example :( */ |
| 250 | #define HB_OT_TAG_LATIN_SCRIPT HB_TAG ('l', 'a', 't', 'n') |
| 251 | if (g.find_script_index (HB_OT_TAG_LATIN_SCRIPT, script_index)) { |
| 252 | if (chosen_script) |
| 253 | *chosen_script = HB_OT_TAG_LATIN_SCRIPT; |
Behdad Esfahbod | 0594a24 | 2012-06-05 20:35:40 -0400 | [diff] [blame] | 254 | return false; |
Behdad Esfahbod | 71632c9 | 2012-01-22 15:31:44 -0500 | [diff] [blame] | 255 | } |
| 256 | |
Behdad Esfahbod | 2014b8d | 2009-12-20 20:58:26 +0100 | [diff] [blame] | 257 | if (script_index) *script_index = HB_OT_LAYOUT_NO_SCRIPT_INDEX; |
Behdad Esfahbod | c47a31f | 2011-07-30 20:57:01 -0400 | [diff] [blame] | 258 | if (chosen_script) |
| 259 | *chosen_script = HB_OT_LAYOUT_NO_SCRIPT_INDEX; |
Behdad Esfahbod | 0594a24 | 2012-06-05 20:35:40 -0400 | [diff] [blame] | 260 | return false; |
Behdad Esfahbod | 2014b8d | 2009-12-20 20:58:26 +0100 | [diff] [blame] | 261 | } |
| 262 | |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 263 | unsigned int |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 264 | hb_ot_layout_table_get_feature_tags (hb_face_t *face, |
| 265 | hb_tag_t table_tag, |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 266 | unsigned int start_offset, |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 267 | unsigned int *feature_count /* IN/OUT */, |
| 268 | hb_tag_t *feature_tags /* OUT */) |
Behdad Esfahbod | c447335 | 2008-02-18 21:14:23 -0500 | [diff] [blame] | 269 | { |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 270 | const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); |
Behdad Esfahbod | c447335 | 2008-02-18 21:14:23 -0500 | [diff] [blame] | 271 | |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 272 | return g.get_feature_tags (start_offset, feature_count, feature_tags); |
Behdad Esfahbod | c447335 | 2008-02-18 21:14:23 -0500 | [diff] [blame] | 273 | } |
| 274 | |
Behdad Esfahbod | c447335 | 2008-02-18 21:14:23 -0500 | [diff] [blame] | 275 | |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 276 | unsigned int |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 277 | hb_ot_layout_script_get_language_tags (hb_face_t *face, |
| 278 | hb_tag_t table_tag, |
| 279 | unsigned int script_index, |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 280 | unsigned int start_offset, |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 281 | unsigned int *language_count /* IN/OUT */, |
| 282 | hb_tag_t *language_tags /* OUT */) |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 283 | { |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 284 | const OT::Script &s = get_gsubgpos_table (face, table_tag).get_script (script_index); |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 285 | |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 286 | return s.get_lang_sys_tags (start_offset, language_count, language_tags); |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | hb_bool_t |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 290 | hb_ot_layout_script_find_language (hb_face_t *face, |
| 291 | hb_tag_t table_tag, |
| 292 | unsigned int script_index, |
| 293 | hb_tag_t language_tag, |
| 294 | unsigned int *language_index) |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 295 | { |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 296 | ASSERT_STATIC (OT::Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_DEFAULT_LANGUAGE_INDEX); |
| 297 | const OT::Script &s = get_gsubgpos_table (face, table_tag).get_script (script_index); |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 298 | |
Behdad Esfahbod | 4a26ea4 | 2008-01-28 07:40:10 -0500 | [diff] [blame] | 299 | if (s.find_lang_sys_index (language_tag, language_index)) |
Behdad Esfahbod | 0594a24 | 2012-06-05 20:35:40 -0400 | [diff] [blame] | 300 | return true; |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 301 | |
| 302 | /* try with 'dflt'; MS site has had typos and many fonts use it now :( */ |
Behdad Esfahbod | 8a3511a | 2009-11-04 19:45:39 -0500 | [diff] [blame] | 303 | if (s.find_lang_sys_index (HB_OT_TAG_DEFAULT_LANGUAGE, language_index)) |
Behdad Esfahbod | 0594a24 | 2012-06-05 20:35:40 -0400 | [diff] [blame] | 304 | return false; |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 305 | |
Behdad Esfahbod | 4a26ea4 | 2008-01-28 07:40:10 -0500 | [diff] [blame] | 306 | if (language_index) *language_index = HB_OT_LAYOUT_DEFAULT_LANGUAGE_INDEX; |
Behdad Esfahbod | 0594a24 | 2012-06-05 20:35:40 -0400 | [diff] [blame] | 307 | return false; |
Behdad Esfahbod | 4a26ea4 | 2008-01-28 07:40:10 -0500 | [diff] [blame] | 308 | } |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 309 | |
Behdad Esfahbod | 4a26ea4 | 2008-01-28 07:40:10 -0500 | [diff] [blame] | 310 | hb_bool_t |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 311 | hb_ot_layout_language_get_required_feature_index (hb_face_t *face, |
| 312 | hb_tag_t table_tag, |
| 313 | unsigned int script_index, |
| 314 | unsigned int language_index, |
| 315 | unsigned int *feature_index) |
Behdad Esfahbod | 4a26ea4 | 2008-01-28 07:40:10 -0500 | [diff] [blame] | 316 | { |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 317 | const OT::LangSys &l = get_gsubgpos_table (face, table_tag).get_script (script_index).get_lang_sys (language_index); |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 318 | |
Behdad Esfahbod | 4a26ea4 | 2008-01-28 07:40:10 -0500 | [diff] [blame] | 319 | if (feature_index) *feature_index = l.get_required_feature_index (); |
| 320 | |
| 321 | return l.has_required_feature (); |
| 322 | } |
| 323 | |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 324 | unsigned int |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 325 | hb_ot_layout_language_get_feature_indexes (hb_face_t *face, |
| 326 | hb_tag_t table_tag, |
| 327 | unsigned int script_index, |
| 328 | unsigned int language_index, |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 329 | unsigned int start_offset, |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 330 | unsigned int *feature_count /* IN/OUT */, |
| 331 | unsigned int *feature_indexes /* OUT */) |
Behdad Esfahbod | 4a26ea4 | 2008-01-28 07:40:10 -0500 | [diff] [blame] | 332 | { |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 333 | const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); |
| 334 | const OT::LangSys &l = g.get_script (script_index).get_lang_sys (language_index); |
Behdad Esfahbod | 4a26ea4 | 2008-01-28 07:40:10 -0500 | [diff] [blame] | 335 | |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 336 | return l.get_feature_indexes (start_offset, feature_count, feature_indexes); |
Behdad Esfahbod | c447335 | 2008-02-18 21:14:23 -0500 | [diff] [blame] | 337 | } |
| 338 | |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 339 | unsigned int |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 340 | hb_ot_layout_language_get_feature_tags (hb_face_t *face, |
| 341 | hb_tag_t table_tag, |
| 342 | unsigned int script_index, |
| 343 | unsigned int language_index, |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 344 | unsigned int start_offset, |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 345 | unsigned int *feature_count /* IN/OUT */, |
| 346 | hb_tag_t *feature_tags /* OUT */) |
Behdad Esfahbod | c447335 | 2008-02-18 21:14:23 -0500 | [diff] [blame] | 347 | { |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 348 | const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); |
| 349 | const OT::LangSys &l = g.get_script (script_index).get_lang_sys (language_index); |
Behdad Esfahbod | 4a26ea4 | 2008-01-28 07:40:10 -0500 | [diff] [blame] | 350 | |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 351 | ASSERT_STATIC (sizeof (unsigned int) == sizeof (hb_tag_t)); |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 352 | unsigned int ret = l.get_feature_indexes (start_offset, feature_count, (unsigned int *) feature_tags); |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 353 | |
Behdad Esfahbod | 9897749 | 2009-08-27 01:32:17 -0400 | [diff] [blame] | 354 | if (feature_tags) { |
| 355 | unsigned int count = *feature_count; |
| 356 | for (unsigned int i = 0; i < count; i++) |
| 357 | feature_tags[i] = g.get_feature_tag ((unsigned int) feature_tags[i]); |
| 358 | } |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 359 | |
| 360 | return ret; |
Behdad Esfahbod | 4a26ea4 | 2008-01-28 07:40:10 -0500 | [diff] [blame] | 361 | } |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 362 | |
| 363 | |
Behdad Esfahbod | 4a26ea4 | 2008-01-28 07:40:10 -0500 | [diff] [blame] | 364 | hb_bool_t |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 365 | hb_ot_layout_language_find_feature (hb_face_t *face, |
| 366 | hb_tag_t table_tag, |
| 367 | unsigned int script_index, |
| 368 | unsigned int language_index, |
| 369 | hb_tag_t feature_tag, |
| 370 | unsigned int *feature_index) |
Behdad Esfahbod | 4a26ea4 | 2008-01-28 07:40:10 -0500 | [diff] [blame] | 371 | { |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 372 | ASSERT_STATIC (OT::Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_NO_FEATURE_INDEX); |
| 373 | const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); |
| 374 | const OT::LangSys &l = g.get_script (script_index).get_lang_sys (language_index); |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 375 | |
Behdad Esfahbod | f4c9514 | 2009-05-17 04:59:56 -0400 | [diff] [blame] | 376 | unsigned int num_features = l.get_feature_count (); |
| 377 | for (unsigned int i = 0; i < num_features; i++) { |
Behdad Esfahbod | 4a26ea4 | 2008-01-28 07:40:10 -0500 | [diff] [blame] | 378 | unsigned int f_index = l.get_feature_index (i); |
| 379 | |
| 380 | if (feature_tag == g.get_feature_tag (f_index)) { |
| 381 | if (feature_index) *feature_index = f_index; |
Behdad Esfahbod | 0594a24 | 2012-06-05 20:35:40 -0400 | [diff] [blame] | 382 | return true; |
Behdad Esfahbod | 4a26ea4 | 2008-01-28 07:40:10 -0500 | [diff] [blame] | 383 | } |
| 384 | } |
| 385 | |
| 386 | if (feature_index) *feature_index = HB_OT_LAYOUT_NO_FEATURE_INDEX; |
Behdad Esfahbod | 0594a24 | 2012-06-05 20:35:40 -0400 | [diff] [blame] | 387 | return false; |
Behdad Esfahbod | 706ab25 | 2008-01-28 05:58:50 -0500 | [diff] [blame] | 388 | } |
Behdad Esfahbod | c447335 | 2008-02-18 21:14:23 -0500 | [diff] [blame] | 389 | |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 390 | unsigned int |
Behdad Esfahbod | f306410 | 2012-11-15 18:39:46 -0800 | [diff] [blame] | 391 | hb_ot_layout_feature_get_lookups (hb_face_t *face, |
| 392 | hb_tag_t table_tag, |
| 393 | unsigned int feature_index, |
| 394 | unsigned int start_offset, |
| 395 | unsigned int *lookup_count /* IN/OUT */, |
| 396 | unsigned int *lookup_indexes /* OUT */) |
Behdad Esfahbod | c447335 | 2008-02-18 21:14:23 -0500 | [diff] [blame] | 397 | { |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 398 | const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); |
| 399 | const OT::Feature &f = g.get_feature (feature_index); |
Behdad Esfahbod | c447335 | 2008-02-18 21:14:23 -0500 | [diff] [blame] | 400 | |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 401 | return f.get_lookup_indexes (start_offset, lookup_count, lookup_indexes); |
Behdad Esfahbod | c447335 | 2008-02-18 21:14:23 -0500 | [diff] [blame] | 402 | } |
| 403 | |
Behdad Esfahbod | a88e716 | 2012-11-24 02:31:02 -0500 | [diff] [blame] | 404 | static void |
| 405 | _hb_ot_layout_collect_lookups_lookups (hb_face_t *face, |
| 406 | hb_tag_t table_tag, |
| 407 | unsigned int feature_index, |
| 408 | hb_set_t *lookup_indexes /* OUT */) |
| 409 | { |
| 410 | unsigned int lookup_indices[32]; |
| 411 | unsigned int offset, len; |
| 412 | |
| 413 | offset = 0; |
| 414 | do { |
| 415 | len = ARRAY_LENGTH (lookup_indices); |
| 416 | hb_ot_layout_feature_get_lookups (face, |
| 417 | table_tag, |
| 418 | feature_index, |
| 419 | offset, &len, |
| 420 | lookup_indices); |
| 421 | |
| 422 | for (unsigned int i = 0; i < len; i++) |
| 423 | lookup_indexes->add (lookup_indices[i]); |
| 424 | |
| 425 | offset += len; |
| 426 | } while (len == ARRAY_LENGTH (lookup_indices)); |
| 427 | } |
| 428 | |
| 429 | static void |
| 430 | _hb_ot_layout_collect_lookups_features (hb_face_t *face, |
| 431 | hb_tag_t table_tag, |
| 432 | unsigned int script_index, |
| 433 | unsigned int language_index, |
| 434 | const hb_tag_t *features, |
| 435 | hb_set_t *lookup_indexes /* OUT */) |
| 436 | { |
| 437 | if (!features) |
| 438 | { |
| 439 | /* All features */ |
| 440 | unsigned int count = hb_ot_layout_language_get_feature_tags (face, table_tag, script_index, language_index, 0, NULL, NULL); |
| 441 | for (unsigned int feature_index = 0; feature_index < count; feature_index++) |
| 442 | _hb_ot_layout_collect_lookups_lookups (face, table_tag, feature_index, lookup_indexes); |
| 443 | } else { |
| 444 | for (; *features; features++) |
| 445 | { |
| 446 | unsigned int feature_index; |
| 447 | if (hb_ot_layout_language_find_feature (face, table_tag, script_index, language_index, *features, &feature_index)) |
| 448 | _hb_ot_layout_collect_lookups_lookups (face, table_tag, feature_index, lookup_indexes); |
| 449 | } |
| 450 | } |
| 451 | } |
| 452 | |
| 453 | static void |
| 454 | _hb_ot_layout_collect_lookups_languages (hb_face_t *face, |
| 455 | hb_tag_t table_tag, |
| 456 | unsigned int script_index, |
| 457 | const hb_tag_t *languages, |
| 458 | const hb_tag_t *features, |
| 459 | hb_set_t *lookup_indexes /* OUT */) |
| 460 | { |
| 461 | if (!languages) |
| 462 | { |
| 463 | /* All languages */ |
| 464 | unsigned int count = hb_ot_layout_script_get_language_tags (face, table_tag, script_index, 0, NULL, NULL); |
| 465 | for (unsigned int language_index = 0; language_index < count; language_index++) |
| 466 | _hb_ot_layout_collect_lookups_features (face, table_tag, script_index, language_index, features, lookup_indexes); |
| 467 | } else { |
| 468 | for (; *languages; languages++) |
| 469 | { |
| 470 | unsigned int language_index; |
| 471 | if (hb_ot_layout_script_find_language (face, table_tag, script_index, *languages, &language_index)) |
| 472 | _hb_ot_layout_collect_lookups_features (face, table_tag, script_index, language_index, features, lookup_indexes); |
| 473 | } |
| 474 | } |
| 475 | } |
| 476 | |
| 477 | void |
| 478 | hb_ot_layout_collect_lookups (hb_face_t *face, |
| 479 | hb_tag_t table_tag, |
| 480 | const hb_tag_t *scripts, |
| 481 | const hb_tag_t *languages, |
| 482 | const hb_tag_t *features, |
| 483 | hb_set_t *lookup_indexes /* OUT */) |
| 484 | { |
| 485 | if (!scripts) |
| 486 | { |
| 487 | /* All scripts */ |
| 488 | unsigned int count = hb_ot_layout_table_get_script_tags (face, table_tag, 0, NULL, NULL); |
| 489 | for (unsigned int script_index = 0; script_index < count; script_index++) |
| 490 | _hb_ot_layout_collect_lookups_languages (face, table_tag, script_index, languages, features, lookup_indexes); |
| 491 | } else { |
| 492 | for (; *scripts; scripts++) |
| 493 | { |
| 494 | unsigned int script_index; |
| 495 | if (hb_ot_layout_table_find_script (face, table_tag, *scripts, &script_index)) |
| 496 | _hb_ot_layout_collect_lookups_languages (face, table_tag, script_index, languages, features, lookup_indexes); |
| 497 | } |
| 498 | } |
| 499 | } |
| 500 | |
Behdad Esfahbod | e8cfdd7 | 2012-11-16 19:07:06 -0800 | [diff] [blame] | 501 | void |
| 502 | hb_ot_layout_lookup_collect_glyphs (hb_face_t *face, |
| 503 | hb_tag_t table_tag, |
| 504 | unsigned int lookup_index, |
| 505 | hb_set_t *glyphs_before, /* OUT. May be NULL */ |
| 506 | hb_set_t *glyphs_input, /* OUT. May be NULL */ |
| 507 | hb_set_t *glyphs_after, /* OUT. May be NULL */ |
| 508 | hb_set_t *glyphs_output /* OUT. May be NULL */) |
| 509 | { |
| 510 | if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return; |
| 511 | |
Behdad Esfahbod | cdd756b | 2012-11-24 01:38:41 -0500 | [diff] [blame] | 512 | OT::hb_collect_glyphs_context_t c (face, glyphs_before, glyphs_input, glyphs_after, glyphs_output); |
Behdad Esfahbod | e8cfdd7 | 2012-11-16 19:07:06 -0800 | [diff] [blame] | 513 | |
| 514 | switch (table_tag) { |
| 515 | case HB_OT_TAG_GSUB: |
| 516 | { |
Behdad Esfahbod | cdd756b | 2012-11-24 01:38:41 -0500 | [diff] [blame] | 517 | const OT::SubstLookup& l = hb_ot_layout_from_face (face)->gsub->get_lookup (lookup_index); |
| 518 | l.collect_glyphs_lookup (&c); |
Behdad Esfahbod | e8cfdd7 | 2012-11-16 19:07:06 -0800 | [diff] [blame] | 519 | return; |
| 520 | } |
| 521 | case HB_OT_TAG_GPOS: |
| 522 | { |
Behdad Esfahbod | cdd756b | 2012-11-24 01:38:41 -0500 | [diff] [blame] | 523 | const OT::PosLookup& l = hb_ot_layout_from_face (face)->gpos->get_lookup (lookup_index); |
| 524 | l.collect_glyphs_lookup (&c); |
Behdad Esfahbod | e8cfdd7 | 2012-11-16 19:07:06 -0800 | [diff] [blame] | 525 | return; |
| 526 | } |
| 527 | } |
| 528 | } |
| 529 | |
Behdad Esfahbod | 2d15e72 | 2009-04-15 19:50:16 -0400 | [diff] [blame] | 530 | |
| 531 | /* |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 532 | * OT::GSUB |
Behdad Esfahbod | 2d15e72 | 2009-04-15 19:50:16 -0400 | [diff] [blame] | 533 | */ |
| 534 | |
| 535 | hb_bool_t |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 536 | hb_ot_layout_has_substitution (hb_face_t *face) |
| 537 | { |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 538 | return &_get_gsub (face) != &OT::Null(OT::GSUB); |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 539 | } |
| 540 | |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 541 | hb_bool_t |
Behdad Esfahbod | 362a990 | 2012-11-15 14:57:31 -0800 | [diff] [blame] | 542 | hb_ot_layout_lookup_would_substitute (hb_face_t *face, |
Behdad Esfahbod | d9b204d | 2012-08-23 16:22:28 -0400 | [diff] [blame] | 543 | unsigned int lookup_index, |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 544 | const hb_codepoint_t *glyphs, |
| 545 | unsigned int glyphs_length, |
Behdad Esfahbod | d9b204d | 2012-08-23 16:22:28 -0400 | [diff] [blame] | 546 | hb_bool_t zero_context) |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 547 | { |
Behdad Esfahbod | 6f76113 | 2012-08-02 04:00:31 -0400 | [diff] [blame] | 548 | if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return false; |
Behdad Esfahbod | 362a990 | 2012-11-15 14:57:31 -0800 | [diff] [blame] | 549 | return hb_ot_layout_lookup_would_substitute_fast (face, lookup_index, glyphs, glyphs_length, zero_context); |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 550 | } |
| 551 | |
Behdad Esfahbod | f860366 | 2012-07-30 02:38:39 -0400 | [diff] [blame] | 552 | hb_bool_t |
Behdad Esfahbod | 362a990 | 2012-11-15 14:57:31 -0800 | [diff] [blame] | 553 | hb_ot_layout_lookup_would_substitute_fast (hb_face_t *face, |
Behdad Esfahbod | d9b204d | 2012-08-23 16:22:28 -0400 | [diff] [blame] | 554 | unsigned int lookup_index, |
Behdad Esfahbod | f860366 | 2012-07-30 02:38:39 -0400 | [diff] [blame] | 555 | const hb_codepoint_t *glyphs, |
| 556 | unsigned int glyphs_length, |
Behdad Esfahbod | d9b204d | 2012-08-23 16:22:28 -0400 | [diff] [blame] | 557 | hb_bool_t zero_context) |
Behdad Esfahbod | f860366 | 2012-07-30 02:38:39 -0400 | [diff] [blame] | 558 | { |
Behdad Esfahbod | 6f76113 | 2012-08-02 04:00:31 -0400 | [diff] [blame] | 559 | if (unlikely (lookup_index >= hb_ot_layout_from_face (face)->gsub_lookup_count)) return false; |
Behdad Esfahbod | 2bd9fe3 | 2012-09-04 15:15:19 -0400 | [diff] [blame] | 560 | OT::hb_would_apply_context_t c (face, glyphs, glyphs_length, zero_context); |
| 561 | |
| 562 | const OT::SubstLookup& l = hb_ot_layout_from_face (face)->gsub->get_lookup (lookup_index); |
| 563 | |
| 564 | return l.would_apply (&c, &hb_ot_layout_from_face (face)->gsub_digests[lookup_index]); |
Behdad Esfahbod | f860366 | 2012-07-30 02:38:39 -0400 | [diff] [blame] | 565 | } |
| 566 | |
Behdad Esfahbod | 46d6a21 | 2011-05-11 22:33:13 -0400 | [diff] [blame] | 567 | void |
Behdad Esfahbod | afbcc24 | 2012-08-02 08:36:40 -0400 | [diff] [blame] | 568 | hb_ot_layout_substitute_start (hb_font_t *font, hb_buffer_t *buffer) |
Behdad Esfahbod | 46d6a21 | 2011-05-11 22:33:13 -0400 | [diff] [blame] | 569 | { |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 570 | OT::GSUB::substitute_start (font, buffer); |
Behdad Esfahbod | 46d6a21 | 2011-05-11 22:33:13 -0400 | [diff] [blame] | 571 | } |
| 572 | |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 573 | hb_bool_t |
Behdad Esfahbod | afbcc24 | 2012-08-02 08:36:40 -0400 | [diff] [blame] | 574 | hb_ot_layout_substitute_lookup (hb_font_t *font, |
Behdad Esfahbod | 468769b | 2009-08-08 16:53:23 -0400 | [diff] [blame] | 575 | hb_buffer_t *buffer, |
| 576 | unsigned int lookup_index, |
| 577 | hb_mask_t mask) |
Behdad Esfahbod | 2d15e72 | 2009-04-15 19:50:16 -0400 | [diff] [blame] | 578 | { |
Behdad Esfahbod | afbcc24 | 2012-08-02 08:36:40 -0400 | [diff] [blame] | 579 | if (unlikely (lookup_index >= hb_ot_layout_from_face (font->face)->gsub_lookup_count)) return false; |
Behdad Esfahbod | 2bd9fe3 | 2012-09-04 15:15:19 -0400 | [diff] [blame] | 580 | |
| 581 | OT::hb_apply_context_t c (font, buffer, mask); |
| 582 | |
| 583 | const OT::SubstLookup& l = hb_ot_layout_from_face (font->face)->gsub->get_lookup (lookup_index); |
| 584 | |
| 585 | return l.apply_string (&c, &hb_ot_layout_from_face (font->face)->gsub_digests[lookup_index]); |
Behdad Esfahbod | f860366 | 2012-07-30 02:38:39 -0400 | [diff] [blame] | 586 | } |
| 587 | |
Behdad Esfahbod | 46d6a21 | 2011-05-11 22:33:13 -0400 | [diff] [blame] | 588 | void |
Behdad Esfahbod | afbcc24 | 2012-08-02 08:36:40 -0400 | [diff] [blame] | 589 | hb_ot_layout_substitute_finish (hb_font_t *font, hb_buffer_t *buffer) |
Behdad Esfahbod | 46d6a21 | 2011-05-11 22:33:13 -0400 | [diff] [blame] | 590 | { |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 591 | OT::GSUB::substitute_finish (font, buffer); |
Behdad Esfahbod | 46d6a21 | 2011-05-11 22:33:13 -0400 | [diff] [blame] | 592 | } |
| 593 | |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 594 | void |
Behdad Esfahbod | 362a990 | 2012-11-15 14:57:31 -0800 | [diff] [blame] | 595 | hb_ot_layout_lookup_substitute_closure (hb_face_t *face, |
Behdad Esfahbod | d9b204d | 2012-08-23 16:22:28 -0400 | [diff] [blame] | 596 | unsigned int lookup_index, |
| 597 | hb_set_t *glyphs) |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 598 | { |
Behdad Esfahbod | 9b34677 | 2012-11-23 17:55:40 -0500 | [diff] [blame] | 599 | OT::hb_closure_context_t c (face, glyphs); |
| 600 | |
| 601 | const OT::SubstLookup& l = _get_gsub (face).get_lookup (lookup_index); |
| 602 | |
| 603 | l.closure (&c); |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 604 | } |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 605 | |
Behdad Esfahbod | 9c42f05 | 2009-05-18 17:43:49 -0400 | [diff] [blame] | 606 | /* |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 607 | * OT::GPOS |
Behdad Esfahbod | 9c42f05 | 2009-05-18 17:43:49 -0400 | [diff] [blame] | 608 | */ |
| 609 | |
| 610 | hb_bool_t |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 611 | hb_ot_layout_has_positioning (hb_face_t *face) |
| 612 | { |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 613 | return &_get_gpos (face) != &OT::Null(OT::GPOS); |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 614 | } |
| 615 | |
Behdad Esfahbod | 8f0d7e0 | 2011-04-15 18:59:56 -0400 | [diff] [blame] | 616 | void |
Behdad Esfahbod | 05bd1b6 | 2012-07-30 19:30:01 -0400 | [diff] [blame] | 617 | hb_ot_layout_position_start (hb_font_t *font, hb_buffer_t *buffer) |
Behdad Esfahbod | 8f0d7e0 | 2011-04-15 18:59:56 -0400 | [diff] [blame] | 618 | { |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 619 | OT::GPOS::position_start (font, buffer); |
Behdad Esfahbod | 8f0d7e0 | 2011-04-15 18:59:56 -0400 | [diff] [blame] | 620 | } |
| 621 | |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 622 | hb_bool_t |
Behdad Esfahbod | f860366 | 2012-07-30 02:38:39 -0400 | [diff] [blame] | 623 | hb_ot_layout_position_lookup (hb_font_t *font, |
| 624 | hb_buffer_t *buffer, |
| 625 | unsigned int lookup_index, |
| 626 | hb_mask_t mask) |
Behdad Esfahbod | 9c42f05 | 2009-05-18 17:43:49 -0400 | [diff] [blame] | 627 | { |
Behdad Esfahbod | 6f76113 | 2012-08-02 04:00:31 -0400 | [diff] [blame] | 628 | if (unlikely (lookup_index >= hb_ot_layout_from_face (font->face)->gpos_lookup_count)) return false; |
Behdad Esfahbod | 2bd9fe3 | 2012-09-04 15:15:19 -0400 | [diff] [blame] | 629 | |
| 630 | OT::hb_apply_context_t c (font, buffer, mask); |
| 631 | |
| 632 | const OT::PosLookup& l = hb_ot_layout_from_face (font->face)->gpos->get_lookup (lookup_index); |
| 633 | |
| 634 | return l.apply_string (&c, &hb_ot_layout_from_face (font->face)->gpos_digests[lookup_index]); |
Behdad Esfahbod | f860366 | 2012-07-30 02:38:39 -0400 | [diff] [blame] | 635 | } |
| 636 | |
Behdad Esfahbod | 9db8ad7 | 2009-11-06 16:47:31 -0500 | [diff] [blame] | 637 | void |
Behdad Esfahbod | 1e7d860 | 2012-07-31 23:41:06 -0400 | [diff] [blame] | 638 | hb_ot_layout_position_finish (hb_font_t *font, hb_buffer_t *buffer, hb_bool_t zero_width_attached_marks) |
Behdad Esfahbod | 9db8ad7 | 2009-11-06 16:47:31 -0500 | [diff] [blame] | 639 | { |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 640 | OT::GPOS::position_finish (font, buffer, zero_width_attached_marks); |
Behdad Esfahbod | 9db8ad7 | 2009-11-06 16:47:31 -0500 | [diff] [blame] | 641 | } |
Behdad Esfahbod | f54cce3 | 2012-11-26 14:02:31 +0200 | [diff] [blame] | 642 | |
| 643 | hb_bool_t |
Behdad Esfahbod | e9ad71d | 2012-11-30 08:10:26 +0200 | [diff] [blame] | 644 | hb_ot_layout_get_size_params (hb_face_t *face, |
| 645 | uint16_t *data /* OUT, 5 items */) |
Behdad Esfahbod | f54cce3 | 2012-11-26 14:02:31 +0200 | [diff] [blame] | 646 | { |
| 647 | const OT::GPOS &gpos = _get_gpos (face); |
Behdad Esfahbod | f54cce3 | 2012-11-26 14:02:31 +0200 | [diff] [blame] | 648 | |
Behdad Esfahbod | 0dff11f | 2012-11-30 08:14:20 +0200 | [diff] [blame^] | 649 | unsigned int num_features = gpos.get_feature_count (); |
| 650 | for (unsigned int i = 0; i < num_features; i++) |
| 651 | { |
| 652 | if (HB_TAG ('s','i','z','e') == gpos.get_feature_tag (i)) |
Behdad Esfahbod | f54cce3 | 2012-11-26 14:02:31 +0200 | [diff] [blame] | 653 | { |
Behdad Esfahbod | 0dff11f | 2012-11-30 08:14:20 +0200 | [diff] [blame^] | 654 | const OT::Feature &f = gpos.get_feature (i); |
Behdad Esfahbod | f54cce3 | 2012-11-26 14:02:31 +0200 | [diff] [blame] | 655 | const OT::FeatureParams ¶ms = f.get_feature_params (); |
| 656 | |
| 657 | for (unsigned int i = 0; i < 5; i++) |
| 658 | data[i] = params.u.size.params[i]; |
| 659 | |
| 660 | return true; |
| 661 | } |
| 662 | } |
| 663 | |
| 664 | for (unsigned int i = 0; i < 5; i++) |
| 665 | data[i] = 0; |
| 666 | |
| 667 | return false; |
| 668 | } |