1 | /* |
2 | * Copyright © 2017 Google, Inc. |
3 | * Copyright © 2018 Ebrahim Byagowi |
4 | * |
5 | * This is part of HarfBuzz, a text shaping library. |
6 | * |
7 | * Permission is hereby granted, without written agreement and without |
8 | * license or royalty fees, to use, copy, modify, and distribute this |
9 | * software and its documentation for any purpose, provided that the |
10 | * above copyright notice and the following two paragraphs appear in |
11 | * all copies of this software. |
12 | * |
13 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR |
14 | * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES |
15 | * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN |
16 | * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH |
17 | * DAMAGE. |
18 | * |
19 | * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, |
20 | * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND |
21 | * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS |
22 | * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO |
23 | * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
24 | * |
25 | * Google Author(s): Behdad Esfahbod |
26 | */ |
27 | |
28 | #include "hb.hh" |
29 | |
30 | #include "hb-aat-layout.hh" |
31 | #include "hb-aat-fdsc-table.hh" // Just so we compile it; unused otherwise. |
32 | #include "hb-aat-layout-ankr-table.hh" |
33 | #include "hb-aat-layout-bsln-table.hh" // Just so we compile it; unused otherwise. |
34 | #include "hb-aat-layout-feat-table.hh" |
35 | #include "hb-aat-layout-just-table.hh" // Just so we compile it; unused otherwise. |
36 | #include "hb-aat-layout-kerx-table.hh" |
37 | #include "hb-aat-layout-morx-table.hh" |
38 | #include "hb-aat-layout-trak-table.hh" |
39 | #include "hb-aat-ltag-table.hh" |
40 | |
41 | |
42 | /* |
43 | * hb_aat_apply_context_t |
44 | */ |
45 | |
46 | /* Note: This context is used for kerning, even without AAT, hence the condition. */ |
47 | #if !defined(HB_NO_AAT) || !defined(HB_NO_OT_KERN) |
48 | |
49 | AAT::hb_aat_apply_context_t::hb_aat_apply_context_t (const hb_ot_shape_plan_t *plan_, |
50 | hb_font_t *font_, |
51 | hb_buffer_t *buffer_, |
52 | hb_blob_t *blob) : |
53 | plan (plan_), |
54 | font (font_), |
55 | face (font->face), |
56 | buffer (buffer_), |
57 | sanitizer (), |
58 | ankr_table (&Null(AAT::ankr)), |
59 | lookup_index (0), |
60 | debug_depth (0) |
61 | { |
62 | sanitizer.init (blob); |
63 | sanitizer.set_num_glyphs (face->get_num_glyphs ()); |
64 | sanitizer.start_processing (); |
65 | sanitizer.set_max_ops (HB_SANITIZE_MAX_OPS_MAX); |
66 | } |
67 | |
68 | AAT::hb_aat_apply_context_t::~hb_aat_apply_context_t () |
69 | { sanitizer.end_processing (); } |
70 | |
71 | void |
72 | AAT::hb_aat_apply_context_t::set_ankr_table (const AAT::ankr *ankr_table_) |
73 | { ankr_table = ankr_table_; } |
74 | |
75 | #endif |
76 | |
77 | |
78 | /** |
79 | * SECTION:hb-aat-layout |
80 | * @title: hb-aat-layout |
81 | * @short_description: Apple Advanced Typography Layout |
82 | * @include: hb-aat.h |
83 | * |
84 | * Functions for querying OpenType Layout features in the font face. |
85 | **/ |
86 | |
87 | |
88 | #if !defined(HB_NO_AAT) || defined(HAVE_CORETEXT) |
89 | |
90 | /* Table data courtesy of Apple. Converted from mnemonics to integers |
91 | * when moving to this file. */ |
92 | static const hb_aat_feature_mapping_t feature_mappings[] = |
93 | { |
94 | {HB_TAG ('a','f','r','c'), HB_AAT_LAYOUT_FEATURE_TYPE_FRACTIONS, HB_AAT_LAYOUT_FEATURE_SELECTOR_VERTICAL_FRACTIONS, HB_AAT_LAYOUT_FEATURE_SELECTOR_NO_FRACTIONS}, |
95 | {HB_TAG ('c','2','p','c'), HB_AAT_LAYOUT_FEATURE_TYPE_UPPER_CASE, HB_AAT_LAYOUT_FEATURE_SELECTOR_UPPER_CASE_PETITE_CAPS, HB_AAT_LAYOUT_FEATURE_SELECTOR_DEFAULT_UPPER_CASE}, |
96 | {HB_TAG ('c','2','s','c'), HB_AAT_LAYOUT_FEATURE_TYPE_UPPER_CASE, HB_AAT_LAYOUT_FEATURE_SELECTOR_UPPER_CASE_SMALL_CAPS, HB_AAT_LAYOUT_FEATURE_SELECTOR_DEFAULT_UPPER_CASE}, |
97 | {HB_TAG ('c','a','l','t'), HB_AAT_LAYOUT_FEATURE_TYPE_CONTEXTUAL_ALTERNATIVES, HB_AAT_LAYOUT_FEATURE_SELECTOR_CONTEXTUAL_ALTERNATES_ON, HB_AAT_LAYOUT_FEATURE_SELECTOR_CONTEXTUAL_ALTERNATES_OFF}, |
98 | {HB_TAG ('c','a','s','e'), HB_AAT_LAYOUT_FEATURE_TYPE_CASE_SENSITIVE_LAYOUT, HB_AAT_LAYOUT_FEATURE_SELECTOR_CASE_SENSITIVE_LAYOUT_ON, HB_AAT_LAYOUT_FEATURE_SELECTOR_CASE_SENSITIVE_LAYOUT_OFF}, |
99 | {HB_TAG ('c','l','i','g'), HB_AAT_LAYOUT_FEATURE_TYPE_LIGATURES, HB_AAT_LAYOUT_FEATURE_SELECTOR_CONTEXTUAL_LIGATURES_ON, HB_AAT_LAYOUT_FEATURE_SELECTOR_CONTEXTUAL_LIGATURES_OFF}, |
100 | {HB_TAG ('c','p','s','p'), HB_AAT_LAYOUT_FEATURE_TYPE_CASE_SENSITIVE_LAYOUT, HB_AAT_LAYOUT_FEATURE_SELECTOR_CASE_SENSITIVE_SPACING_ON, HB_AAT_LAYOUT_FEATURE_SELECTOR_CASE_SENSITIVE_SPACING_OFF}, |
101 | {HB_TAG ('c','s','w','h'), HB_AAT_LAYOUT_FEATURE_TYPE_CONTEXTUAL_ALTERNATIVES, HB_AAT_LAYOUT_FEATURE_SELECTOR_CONTEXTUAL_SWASH_ALTERNATES_ON, HB_AAT_LAYOUT_FEATURE_SELECTOR_CONTEXTUAL_SWASH_ALTERNATES_OFF}, |
102 | {HB_TAG ('d','l','i','g'), HB_AAT_LAYOUT_FEATURE_TYPE_LIGATURES, HB_AAT_LAYOUT_FEATURE_SELECTOR_RARE_LIGATURES_ON, HB_AAT_LAYOUT_FEATURE_SELECTOR_RARE_LIGATURES_OFF}, |
103 | {HB_TAG ('e','x','p','t'), HB_AAT_LAYOUT_FEATURE_TYPE_CHARACTER_SHAPE, HB_AAT_LAYOUT_FEATURE_SELECTOR_EXPERT_CHARACTERS, (hb_aat_layout_feature_selector_t) 16}, |
104 | {HB_TAG ('f','r','a','c'), HB_AAT_LAYOUT_FEATURE_TYPE_FRACTIONS, HB_AAT_LAYOUT_FEATURE_SELECTOR_DIAGONAL_FRACTIONS, HB_AAT_LAYOUT_FEATURE_SELECTOR_NO_FRACTIONS}, |
105 | {HB_TAG ('f','w','i','d'), HB_AAT_LAYOUT_FEATURE_TYPE_TEXT_SPACING, HB_AAT_LAYOUT_FEATURE_SELECTOR_MONOSPACED_TEXT, (hb_aat_layout_feature_selector_t) 7}, |
106 | {HB_TAG ('h','a','l','t'), HB_AAT_LAYOUT_FEATURE_TYPE_TEXT_SPACING, HB_AAT_LAYOUT_FEATURE_SELECTOR_ALT_HALF_WIDTH_TEXT, (hb_aat_layout_feature_selector_t) 7}, |
107 | {HB_TAG ('h','i','s','t'), HB_AAT_LAYOUT_FEATURE_TYPE_LIGATURES, HB_AAT_LAYOUT_FEATURE_SELECTOR_HISTORICAL_LIGATURES_ON, HB_AAT_LAYOUT_FEATURE_SELECTOR_HISTORICAL_LIGATURES_OFF}, |
108 | {HB_TAG ('h','k','n','a'), HB_AAT_LAYOUT_FEATURE_TYPE_ALTERNATE_KANA, HB_AAT_LAYOUT_FEATURE_SELECTOR_ALTERNATE_HORIZ_KANA_ON, HB_AAT_LAYOUT_FEATURE_SELECTOR_ALTERNATE_HORIZ_KANA_OFF}, |
109 | {HB_TAG ('h','l','i','g'), HB_AAT_LAYOUT_FEATURE_TYPE_LIGATURES, HB_AAT_LAYOUT_FEATURE_SELECTOR_HISTORICAL_LIGATURES_ON, HB_AAT_LAYOUT_FEATURE_SELECTOR_HISTORICAL_LIGATURES_OFF}, |
110 | {HB_TAG ('h','n','g','l'), HB_AAT_LAYOUT_FEATURE_TYPE_TRANSLITERATION, HB_AAT_LAYOUT_FEATURE_SELECTOR_HANJA_TO_HANGUL, HB_AAT_LAYOUT_FEATURE_SELECTOR_NO_TRANSLITERATION}, |
111 | {HB_TAG ('h','o','j','o'), HB_AAT_LAYOUT_FEATURE_TYPE_CHARACTER_SHAPE, HB_AAT_LAYOUT_FEATURE_SELECTOR_HOJO_CHARACTERS, (hb_aat_layout_feature_selector_t) 16}, |
112 | {HB_TAG ('h','w','i','d'), HB_AAT_LAYOUT_FEATURE_TYPE_TEXT_SPACING, HB_AAT_LAYOUT_FEATURE_SELECTOR_HALF_WIDTH_TEXT, (hb_aat_layout_feature_selector_t) 7}, |
113 | {HB_TAG ('i','t','a','l'), HB_AAT_LAYOUT_FEATURE_TYPE_ITALIC_CJK_ROMAN, HB_AAT_LAYOUT_FEATURE_SELECTOR_CJK_ITALIC_ROMAN_ON, HB_AAT_LAYOUT_FEATURE_SELECTOR_CJK_ITALIC_ROMAN_OFF}, |
114 | {HB_TAG ('j','p','0','4'), HB_AAT_LAYOUT_FEATURE_TYPE_CHARACTER_SHAPE, HB_AAT_LAYOUT_FEATURE_SELECTOR_JIS2004_CHARACTERS, (hb_aat_layout_feature_selector_t) 16}, |
115 | {HB_TAG ('j','p','7','8'), HB_AAT_LAYOUT_FEATURE_TYPE_CHARACTER_SHAPE, HB_AAT_LAYOUT_FEATURE_SELECTOR_JIS1978_CHARACTERS, (hb_aat_layout_feature_selector_t) 16}, |
116 | {HB_TAG ('j','p','8','3'), HB_AAT_LAYOUT_FEATURE_TYPE_CHARACTER_SHAPE, HB_AAT_LAYOUT_FEATURE_SELECTOR_JIS1983_CHARACTERS, (hb_aat_layout_feature_selector_t) 16}, |
117 | {HB_TAG ('j','p','9','0'), HB_AAT_LAYOUT_FEATURE_TYPE_CHARACTER_SHAPE, HB_AAT_LAYOUT_FEATURE_SELECTOR_JIS1990_CHARACTERS, (hb_aat_layout_feature_selector_t) 16}, |
118 | {HB_TAG ('l','i','g','a'), HB_AAT_LAYOUT_FEATURE_TYPE_LIGATURES, HB_AAT_LAYOUT_FEATURE_SELECTOR_COMMON_LIGATURES_ON, HB_AAT_LAYOUT_FEATURE_SELECTOR_COMMON_LIGATURES_OFF}, |
119 | {HB_TAG ('l','n','u','m'), HB_AAT_LAYOUT_FEATURE_TYPE_NUMBER_CASE, HB_AAT_LAYOUT_FEATURE_SELECTOR_UPPER_CASE_NUMBERS, (hb_aat_layout_feature_selector_t) 2}, |
120 | {HB_TAG ('m','g','r','k'), HB_AAT_LAYOUT_FEATURE_TYPE_MATHEMATICAL_EXTRAS, HB_AAT_LAYOUT_FEATURE_SELECTOR_MATHEMATICAL_GREEK_ON, HB_AAT_LAYOUT_FEATURE_SELECTOR_MATHEMATICAL_GREEK_OFF}, |
121 | {HB_TAG ('n','l','c','k'), HB_AAT_LAYOUT_FEATURE_TYPE_CHARACTER_SHAPE, HB_AAT_LAYOUT_FEATURE_SELECTOR_NLCCHARACTERS, (hb_aat_layout_feature_selector_t) 16}, |
122 | {HB_TAG ('o','n','u','m'), HB_AAT_LAYOUT_FEATURE_TYPE_NUMBER_CASE, HB_AAT_LAYOUT_FEATURE_SELECTOR_LOWER_CASE_NUMBERS, (hb_aat_layout_feature_selector_t) 2}, |
123 | {HB_TAG ('o','r','d','n'), HB_AAT_LAYOUT_FEATURE_TYPE_VERTICAL_POSITION, HB_AAT_LAYOUT_FEATURE_SELECTOR_ORDINALS, HB_AAT_LAYOUT_FEATURE_SELECTOR_NORMAL_POSITION}, |
124 | {HB_TAG ('p','a','l','t'), HB_AAT_LAYOUT_FEATURE_TYPE_TEXT_SPACING, HB_AAT_LAYOUT_FEATURE_SELECTOR_ALT_PROPORTIONAL_TEXT, (hb_aat_layout_feature_selector_t) 7}, |
125 | {HB_TAG ('p','c','a','p'), HB_AAT_LAYOUT_FEATURE_TYPE_LOWER_CASE, HB_AAT_LAYOUT_FEATURE_SELECTOR_LOWER_CASE_PETITE_CAPS, HB_AAT_LAYOUT_FEATURE_SELECTOR_DEFAULT_LOWER_CASE}, |
126 | {HB_TAG ('p','k','n','a'), HB_AAT_LAYOUT_FEATURE_TYPE_TEXT_SPACING, HB_AAT_LAYOUT_FEATURE_SELECTOR_PROPORTIONAL_TEXT, (hb_aat_layout_feature_selector_t) 7}, |
127 | {HB_TAG ('p','n','u','m'), HB_AAT_LAYOUT_FEATURE_TYPE_NUMBER_SPACING, HB_AAT_LAYOUT_FEATURE_SELECTOR_PROPORTIONAL_NUMBERS, (hb_aat_layout_feature_selector_t) 4}, |
128 | {HB_TAG ('p','w','i','d'), HB_AAT_LAYOUT_FEATURE_TYPE_TEXT_SPACING, HB_AAT_LAYOUT_FEATURE_SELECTOR_PROPORTIONAL_TEXT, (hb_aat_layout_feature_selector_t) 7}, |
129 | {HB_TAG ('q','w','i','d'), HB_AAT_LAYOUT_FEATURE_TYPE_TEXT_SPACING, HB_AAT_LAYOUT_FEATURE_SELECTOR_QUARTER_WIDTH_TEXT, (hb_aat_layout_feature_selector_t) 7}, |
130 | {HB_TAG ('r','u','b','y'), HB_AAT_LAYOUT_FEATURE_TYPE_RUBY_KANA, HB_AAT_LAYOUT_FEATURE_SELECTOR_RUBY_KANA_ON, HB_AAT_LAYOUT_FEATURE_SELECTOR_RUBY_KANA_OFF}, |
131 | {HB_TAG ('s','i','n','f'), HB_AAT_LAYOUT_FEATURE_TYPE_VERTICAL_POSITION, HB_AAT_LAYOUT_FEATURE_SELECTOR_SCIENTIFIC_INFERIORS, HB_AAT_LAYOUT_FEATURE_SELECTOR_NORMAL_POSITION}, |
132 | {HB_TAG ('s','m','c','p'), HB_AAT_LAYOUT_FEATURE_TYPE_LOWER_CASE, HB_AAT_LAYOUT_FEATURE_SELECTOR_LOWER_CASE_SMALL_CAPS, HB_AAT_LAYOUT_FEATURE_SELECTOR_DEFAULT_LOWER_CASE}, |
133 | {HB_TAG ('s','m','p','l'), HB_AAT_LAYOUT_FEATURE_TYPE_CHARACTER_SHAPE, HB_AAT_LAYOUT_FEATURE_SELECTOR_SIMPLIFIED_CHARACTERS, (hb_aat_layout_feature_selector_t) 16}, |
134 | {HB_TAG ('s','s','0','1'), HB_AAT_LAYOUT_FEATURE_TYPE_STYLISTIC_ALTERNATIVES, HB_AAT_LAYOUT_FEATURE_SELECTOR_STYLISTIC_ALT_ONE_ON, HB_AAT_LAYOUT_FEATURE_SELECTOR_STYLISTIC_ALT_ONE_OFF}, |
135 | {HB_TAG ('s','s','0','2'), HB_AAT_LAYOUT_FEATURE_TYPE_STYLISTIC_ALTERNATIVES, HB_AAT_LAYOUT_FEATURE_SELECTOR_STYLISTIC_ALT_TWO_ON, HB_AAT_LAYOUT_FEATURE_SELECTOR_STYLISTIC_ALT_TWO_OFF}, |
136 | {HB_TAG ('s','s','0','3'), HB_AAT_LAYOUT_FEATURE_TYPE_STYLISTIC_ALTERNATIVES, HB_AAT_LAYOUT_FEATURE_SELECTOR_STYLISTIC_ALT_THREE_ON, HB_AAT_LAYOUT_FEATURE_SELECTOR_STYLISTIC_ALT_THREE_OFF}, |
137 | {HB_TAG ('s','s','0','4'), HB_AAT_LAYOUT_FEATURE_TYPE_STYLISTIC_ALTERNATIVES, HB_AAT_LAYOUT_FEATURE_SELECTOR_STYLISTIC_ALT_FOUR_ON, HB_AAT_LAYOUT_FEATURE_SELECTOR_STYLISTIC_ALT_FOUR_OFF}, |
138 | {HB_TAG ('s','s','0','5'), HB_AAT_LAYOUT_FEATURE_TYPE_STYLISTIC_ALTERNATIVES, HB_AAT_LAYOUT_FEATURE_SELECTOR_STYLISTIC_ALT_FIVE_ON, HB_AAT_LAYOUT_FEATURE_SELECTOR_STYLISTIC_ALT_FIVE_OFF}, |
139 | {HB_TAG ('s','s','0','6'), HB_AAT_LAYOUT_FEATURE_TYPE_STYLISTIC_ALTERNATIVES, HB_AAT_LAYOUT_FEATURE_SELECTOR_STYLISTIC_ALT_SIX_ON, HB_AAT_LAYOUT_FEATURE_SELECTOR_STYLISTIC_ALT_SIX_OFF}, |
140 | {HB_TAG ('s','s','0','7'), HB_AAT_LAYOUT_FEATURE_TYPE_STYLISTIC_ALTERNATIVES, HB_AAT_LAYOUT_FEATURE_SELECTOR_STYLISTIC_ALT_SEVEN_ON, HB_AAT_LAYOUT_FEATURE_SELECTOR_STYLISTIC_ALT_SEVEN_OFF}, |
141 | {HB_TAG ('s','s','0','8'), HB_AAT_LAYOUT_FEATURE_TYPE_STYLISTIC_ALTERNATIVES, HB_AAT_LAYOUT_FEATURE_SELECTOR_STYLISTIC_ALT_EIGHT_ON, HB_AAT_LAYOUT_FEATURE_SELECTOR_STYLISTIC_ALT_EIGHT_OFF}, |
142 | {HB_TAG ('s','s','0','9'), HB_AAT_LAYOUT_FEATURE_TYPE_STYLISTIC_ALTERNATIVES, HB_AAT_LAYOUT_FEATURE_SELECTOR_STYLISTIC_ALT_NINE_ON, HB_AAT_LAYOUT_FEATURE_SELECTOR_STYLISTIC_ALT_NINE_OFF}, |
143 | {HB_TAG ('s','s','1','0'), HB_AAT_LAYOUT_FEATURE_TYPE_STYLISTIC_ALTERNATIVES, HB_AAT_LAYOUT_FEATURE_SELECTOR_STYLISTIC_ALT_TEN_ON, HB_AAT_LAYOUT_FEATURE_SELECTOR_STYLISTIC_ALT_TEN_OFF}, |
144 | {HB_TAG ('s','s','1','1'), HB_AAT_LAYOUT_FEATURE_TYPE_STYLISTIC_ALTERNATIVES, HB_AAT_LAYOUT_FEATURE_SELECTOR_STYLISTIC_ALT_ELEVEN_ON, HB_AAT_LAYOUT_FEATURE_SELECTOR_STYLISTIC_ALT_ELEVEN_OFF}, |
145 | {HB_TAG ('s','s','1','2'), HB_AAT_LAYOUT_FEATURE_TYPE_STYLISTIC_ALTERNATIVES, HB_AAT_LAYOUT_FEATURE_SELECTOR_STYLISTIC_ALT_TWELVE_ON, HB_AAT_LAYOUT_FEATURE_SELECTOR_STYLISTIC_ALT_TWELVE_OFF}, |
146 | {HB_TAG ('s','s','1','3'), HB_AAT_LAYOUT_FEATURE_TYPE_STYLISTIC_ALTERNATIVES, HB_AAT_LAYOUT_FEATURE_SELECTOR_STYLISTIC_ALT_THIRTEEN_ON, HB_AAT_LAYOUT_FEATURE_SELECTOR_STYLISTIC_ALT_THIRTEEN_OFF}, |
147 | {HB_TAG ('s','s','1','4'), HB_AAT_LAYOUT_FEATURE_TYPE_STYLISTIC_ALTERNATIVES, HB_AAT_LAYOUT_FEATURE_SELECTOR_STYLISTIC_ALT_FOURTEEN_ON, HB_AAT_LAYOUT_FEATURE_SELECTOR_STYLISTIC_ALT_FOURTEEN_OFF}, |
148 | {HB_TAG ('s','s','1','5'), HB_AAT_LAYOUT_FEATURE_TYPE_STYLISTIC_ALTERNATIVES, HB_AAT_LAYOUT_FEATURE_SELECTOR_STYLISTIC_ALT_FIFTEEN_ON, HB_AAT_LAYOUT_FEATURE_SELECTOR_STYLISTIC_ALT_FIFTEEN_OFF}, |
149 | {HB_TAG ('s','s','1','6'), HB_AAT_LAYOUT_FEATURE_TYPE_STYLISTIC_ALTERNATIVES, HB_AAT_LAYOUT_FEATURE_SELECTOR_STYLISTIC_ALT_SIXTEEN_ON, HB_AAT_LAYOUT_FEATURE_SELECTOR_STYLISTIC_ALT_SIXTEEN_OFF}, |
150 | {HB_TAG ('s','s','1','7'), HB_AAT_LAYOUT_FEATURE_TYPE_STYLISTIC_ALTERNATIVES, HB_AAT_LAYOUT_FEATURE_SELECTOR_STYLISTIC_ALT_SEVENTEEN_ON, HB_AAT_LAYOUT_FEATURE_SELECTOR_STYLISTIC_ALT_SEVENTEEN_OFF}, |
151 | {HB_TAG ('s','s','1','8'), HB_AAT_LAYOUT_FEATURE_TYPE_STYLISTIC_ALTERNATIVES, HB_AAT_LAYOUT_FEATURE_SELECTOR_STYLISTIC_ALT_EIGHTEEN_ON, HB_AAT_LAYOUT_FEATURE_SELECTOR_STYLISTIC_ALT_EIGHTEEN_OFF}, |
152 | {HB_TAG ('s','s','1','9'), HB_AAT_LAYOUT_FEATURE_TYPE_STYLISTIC_ALTERNATIVES, HB_AAT_LAYOUT_FEATURE_SELECTOR_STYLISTIC_ALT_NINETEEN_ON, HB_AAT_LAYOUT_FEATURE_SELECTOR_STYLISTIC_ALT_NINETEEN_OFF}, |
153 | {HB_TAG ('s','s','2','0'), HB_AAT_LAYOUT_FEATURE_TYPE_STYLISTIC_ALTERNATIVES, HB_AAT_LAYOUT_FEATURE_SELECTOR_STYLISTIC_ALT_TWENTY_ON, HB_AAT_LAYOUT_FEATURE_SELECTOR_STYLISTIC_ALT_TWENTY_OFF}, |
154 | {HB_TAG ('s','u','b','s'), HB_AAT_LAYOUT_FEATURE_TYPE_VERTICAL_POSITION, HB_AAT_LAYOUT_FEATURE_SELECTOR_INFERIORS, HB_AAT_LAYOUT_FEATURE_SELECTOR_NORMAL_POSITION}, |
155 | {HB_TAG ('s','u','p','s'), HB_AAT_LAYOUT_FEATURE_TYPE_VERTICAL_POSITION, HB_AAT_LAYOUT_FEATURE_SELECTOR_SUPERIORS, HB_AAT_LAYOUT_FEATURE_SELECTOR_NORMAL_POSITION}, |
156 | {HB_TAG ('s','w','s','h'), HB_AAT_LAYOUT_FEATURE_TYPE_CONTEXTUAL_ALTERNATIVES, HB_AAT_LAYOUT_FEATURE_SELECTOR_SWASH_ALTERNATES_ON, HB_AAT_LAYOUT_FEATURE_SELECTOR_SWASH_ALTERNATES_OFF}, |
157 | {HB_TAG ('t','i','t','l'), HB_AAT_LAYOUT_FEATURE_TYPE_STYLE_OPTIONS, HB_AAT_LAYOUT_FEATURE_SELECTOR_TITLING_CAPS, HB_AAT_LAYOUT_FEATURE_SELECTOR_NO_STYLE_OPTIONS}, |
158 | {HB_TAG ('t','n','a','m'), HB_AAT_LAYOUT_FEATURE_TYPE_CHARACTER_SHAPE, HB_AAT_LAYOUT_FEATURE_SELECTOR_TRADITIONAL_NAMES_CHARACTERS, (hb_aat_layout_feature_selector_t) 16}, |
159 | {HB_TAG ('t','n','u','m'), HB_AAT_LAYOUT_FEATURE_TYPE_NUMBER_SPACING, HB_AAT_LAYOUT_FEATURE_SELECTOR_MONOSPACED_NUMBERS, (hb_aat_layout_feature_selector_t) 4}, |
160 | {HB_TAG ('t','r','a','d'), HB_AAT_LAYOUT_FEATURE_TYPE_CHARACTER_SHAPE, HB_AAT_LAYOUT_FEATURE_SELECTOR_TRADITIONAL_CHARACTERS, (hb_aat_layout_feature_selector_t) 16}, |
161 | {HB_TAG ('t','w','i','d'), HB_AAT_LAYOUT_FEATURE_TYPE_TEXT_SPACING, HB_AAT_LAYOUT_FEATURE_SELECTOR_THIRD_WIDTH_TEXT, (hb_aat_layout_feature_selector_t) 7}, |
162 | {HB_TAG ('u','n','i','c'), HB_AAT_LAYOUT_FEATURE_TYPE_LETTER_CASE, (hb_aat_layout_feature_selector_t) 14, (hb_aat_layout_feature_selector_t) 15}, |
163 | {HB_TAG ('v','a','l','t'), HB_AAT_LAYOUT_FEATURE_TYPE_TEXT_SPACING, HB_AAT_LAYOUT_FEATURE_SELECTOR_ALT_PROPORTIONAL_TEXT, (hb_aat_layout_feature_selector_t) 7}, |
164 | {HB_TAG ('v','e','r','t'), HB_AAT_LAYOUT_FEATURE_TYPE_VERTICAL_SUBSTITUTION, HB_AAT_LAYOUT_FEATURE_SELECTOR_SUBSTITUTE_VERTICAL_FORMS_ON, HB_AAT_LAYOUT_FEATURE_SELECTOR_SUBSTITUTE_VERTICAL_FORMS_OFF}, |
165 | {HB_TAG ('v','h','a','l'), HB_AAT_LAYOUT_FEATURE_TYPE_TEXT_SPACING, HB_AAT_LAYOUT_FEATURE_SELECTOR_ALT_HALF_WIDTH_TEXT, (hb_aat_layout_feature_selector_t) 7}, |
166 | {HB_TAG ('v','k','n','a'), HB_AAT_LAYOUT_FEATURE_TYPE_ALTERNATE_KANA, HB_AAT_LAYOUT_FEATURE_SELECTOR_ALTERNATE_VERT_KANA_ON, HB_AAT_LAYOUT_FEATURE_SELECTOR_ALTERNATE_VERT_KANA_OFF}, |
167 | {HB_TAG ('v','p','a','l'), HB_AAT_LAYOUT_FEATURE_TYPE_TEXT_SPACING, HB_AAT_LAYOUT_FEATURE_SELECTOR_ALT_PROPORTIONAL_TEXT, (hb_aat_layout_feature_selector_t) 7}, |
168 | {HB_TAG ('v','r','t','2'), HB_AAT_LAYOUT_FEATURE_TYPE_VERTICAL_SUBSTITUTION, HB_AAT_LAYOUT_FEATURE_SELECTOR_SUBSTITUTE_VERTICAL_FORMS_ON, HB_AAT_LAYOUT_FEATURE_SELECTOR_SUBSTITUTE_VERTICAL_FORMS_OFF}, |
169 | {HB_TAG ('z','e','r','o'), HB_AAT_LAYOUT_FEATURE_TYPE_TYPOGRAPHIC_EXTRAS, HB_AAT_LAYOUT_FEATURE_SELECTOR_SLASHED_ZERO_ON, HB_AAT_LAYOUT_FEATURE_SELECTOR_SLASHED_ZERO_OFF}, |
170 | }; |
171 | |
172 | const hb_aat_feature_mapping_t * |
173 | hb_aat_layout_find_feature_mapping (hb_tag_t tag) |
174 | { |
175 | return (const hb_aat_feature_mapping_t *) hb_bsearch (&tag, |
176 | feature_mappings, |
177 | ARRAY_LENGTH (feature_mappings), |
178 | sizeof (feature_mappings[0]), |
179 | hb_aat_feature_mapping_t::cmp); |
180 | } |
181 | #endif |
182 | |
183 | |
184 | #ifndef HB_NO_AAT |
185 | |
186 | /* |
187 | * mort/morx/kerx/trak |
188 | */ |
189 | |
190 | |
191 | void |
192 | hb_aat_layout_compile_map (const hb_aat_map_builder_t *mapper, |
193 | hb_aat_map_t *map) |
194 | { |
195 | const AAT::morx& morx = *mapper->face->table.morx; |
196 | if (morx.has_data ()) |
197 | { |
198 | morx.compile_flags (mapper, map); |
199 | return; |
200 | } |
201 | |
202 | const AAT::mort& mort = *mapper->face->table.mort; |
203 | if (mort.has_data ()) |
204 | { |
205 | mort.compile_flags (mapper, map); |
206 | return; |
207 | } |
208 | } |
209 | |
210 | |
211 | /* |
212 | * hb_aat_layout_has_substitution: |
213 | * @face: |
214 | * |
215 | * Returns: |
216 | * Since: 2.3.0 |
217 | */ |
218 | hb_bool_t |
219 | hb_aat_layout_has_substitution (hb_face_t *face) |
220 | { |
221 | return face->table.morx->has_data () || |
222 | face->table.mort->has_data (); |
223 | } |
224 | |
225 | void |
226 | hb_aat_layout_substitute (const hb_ot_shape_plan_t *plan, |
227 | hb_font_t *font, |
228 | hb_buffer_t *buffer) |
229 | { |
230 | hb_blob_t *morx_blob = font->face->table.morx.get_blob (); |
231 | const AAT::morx& morx = *morx_blob->as<AAT::morx> (); |
232 | if (morx.has_data ()) |
233 | { |
234 | AAT::hb_aat_apply_context_t c (plan, font, buffer, morx_blob); |
235 | morx.apply (&c); |
236 | return; |
237 | } |
238 | |
239 | hb_blob_t *mort_blob = font->face->table.mort.get_blob (); |
240 | const AAT::mort& mort = *mort_blob->as<AAT::mort> (); |
241 | if (mort.has_data ()) |
242 | { |
243 | AAT::hb_aat_apply_context_t c (plan, font, buffer, mort_blob); |
244 | mort.apply (&c); |
245 | return; |
246 | } |
247 | } |
248 | |
249 | void |
250 | hb_aat_layout_zero_width_deleted_glyphs (hb_buffer_t *buffer) |
251 | { |
252 | unsigned int count = buffer->len; |
253 | hb_glyph_info_t *info = buffer->info; |
254 | hb_glyph_position_t *pos = buffer->pos; |
255 | for (unsigned int i = 0; i < count; i++) |
256 | if (unlikely (info[i].codepoint == AAT::DELETED_GLYPH)) |
257 | pos[i].x_advance = pos[i].y_advance = pos[i].x_offset = pos[i].y_offset = 0; |
258 | } |
259 | |
260 | static bool |
261 | is_deleted_glyph (const hb_glyph_info_t *info) |
262 | { |
263 | return info->codepoint == AAT::DELETED_GLYPH; |
264 | } |
265 | |
266 | void |
267 | hb_aat_layout_remove_deleted_glyphs (hb_buffer_t *buffer) |
268 | { |
269 | hb_ot_layout_delete_glyphs_inplace (buffer, is_deleted_glyph); |
270 | } |
271 | |
272 | /* |
273 | * hb_aat_layout_has_positioning: |
274 | * @face: |
275 | * |
276 | * Returns: |
277 | * Since: 2.3.0 |
278 | */ |
279 | hb_bool_t |
280 | hb_aat_layout_has_positioning (hb_face_t *face) |
281 | { |
282 | return face->table.kerx->has_data (); |
283 | } |
284 | |
285 | void |
286 | hb_aat_layout_position (const hb_ot_shape_plan_t *plan, |
287 | hb_font_t *font, |
288 | hb_buffer_t *buffer) |
289 | { |
290 | hb_blob_t *kerx_blob = font->face->table.kerx.get_blob (); |
291 | const AAT::kerx& kerx = *kerx_blob->as<AAT::kerx> (); |
292 | |
293 | AAT::hb_aat_apply_context_t c (plan, font, buffer, kerx_blob); |
294 | c.set_ankr_table (font->face->table.ankr.get ()); |
295 | kerx.apply (&c); |
296 | } |
297 | |
298 | |
299 | /* |
300 | * hb_aat_layout_has_tracking: |
301 | * @face: |
302 | * |
303 | * Returns: |
304 | * Since: 2.3.0 |
305 | */ |
306 | hb_bool_t |
307 | hb_aat_layout_has_tracking (hb_face_t *face) |
308 | { |
309 | return face->table.trak->has_data (); |
310 | } |
311 | |
312 | void |
313 | hb_aat_layout_track (const hb_ot_shape_plan_t *plan, |
314 | hb_font_t *font, |
315 | hb_buffer_t *buffer) |
316 | { |
317 | const AAT::trak& trak = *font->face->table.trak; |
318 | |
319 | AAT::hb_aat_apply_context_t c (plan, font, buffer); |
320 | trak.apply (&c); |
321 | } |
322 | |
323 | /** |
324 | * hb_aat_layout_get_feature_types: |
325 | * @face: a face object |
326 | * @start_offset: iteration's start offset |
327 | * @feature_count:(inout) (allow-none): buffer size as input, filled size as output |
328 | * @features: (out caller-allocates) (array length=feature_count): features buffer |
329 | * |
330 | * Return value: Number of all available feature types. |
331 | * |
332 | * Since: 2.2.0 |
333 | */ |
334 | unsigned int |
335 | hb_aat_layout_get_feature_types (hb_face_t *face, |
336 | unsigned int start_offset, |
337 | unsigned int *feature_count, /* IN/OUT. May be NULL. */ |
338 | hb_aat_layout_feature_type_t *features /* OUT. May be NULL. */) |
339 | { |
340 | return face->table.feat->get_feature_types (start_offset, feature_count, features); |
341 | } |
342 | |
343 | /** |
344 | * hb_aat_layout_feature_type_get_name_id: |
345 | * @face: a face object |
346 | * @feature_type: feature id |
347 | * |
348 | * Return value: Name ID index |
349 | * |
350 | * Since: 2.2.0 |
351 | */ |
352 | hb_ot_name_id_t |
353 | hb_aat_layout_feature_type_get_name_id (hb_face_t *face, |
354 | hb_aat_layout_feature_type_t feature_type) |
355 | { |
356 | return face->table.feat->get_feature_name_id (feature_type); |
357 | } |
358 | |
359 | /** |
360 | * hb_aat_layout_feature_type_get_selectors: |
361 | * @face: a face object |
362 | * @feature_type: feature id |
363 | * @start_offset: iteration's start offset |
364 | * @selector_count: (inout) (allow-none): buffer size as input, filled size as output |
365 | * @selectors: (out caller-allocates) (array length=selector_count): settings buffer |
366 | * @default_index: (out) (allow-none): index of default selector if any |
367 | * |
368 | * If upon return, @default_index is set to #HB_AAT_LAYOUT_NO_SELECTOR_INDEX, then |
369 | * the feature type is non-exclusive. Otherwise, @default_index is the index of |
370 | * the selector that is selected by default. |
371 | * |
372 | * Return value: Number of all available feature selectors. |
373 | * |
374 | * Since: 2.2.0 |
375 | */ |
376 | unsigned int |
377 | hb_aat_layout_feature_type_get_selector_infos (hb_face_t *face, |
378 | hb_aat_layout_feature_type_t feature_type, |
379 | unsigned int start_offset, |
380 | unsigned int *selector_count, /* IN/OUT. May be NULL. */ |
381 | hb_aat_layout_feature_selector_info_t *selectors, /* OUT. May be NULL. */ |
382 | unsigned int *default_index /* OUT. May be NULL. */) |
383 | { |
384 | return face->table.feat->get_selector_infos (feature_type, start_offset, selector_count, selectors, default_index); |
385 | } |
386 | |
387 | |
388 | #endif |
389 | |