2 * Copyright © 2018 Google, Inc.
4 * This is part of HarfBuzz, a text shaping library.
6 * Permission is hereby granted, without written agreement and without
7 * license or royalty fees, to use, copy, modify, and distribute this
8 * software and its documentation for any purpose, provided that the
9 * above copyright notice and the following two paragraphs appear in
10 * all copies of this software.
12 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
13 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
14 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
15 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
18 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
19 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
21 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
22 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
24 * Google Author(s): Garret Rieger, Rod Sheeter, Behdad Esfahbod
27 #include "hb-subset.hh"
31 * hb_subset_input_create_or_fail:
33 * Creates a new subset input object.
35 * Return value: (transfer full): New subset input, or %NULL if failed. Destroy
36 * with hb_subset_input_destroy().
41 hb_subset_input_create_or_fail (void)
43 hb_subset_input_t *input = hb_object_create<hb_subset_input_t>();
45 if (unlikely (!input))
48 for (auto& set : input->sets_iter ())
49 set = hb_set_create ();
51 if (input->in_error ())
53 hb_subset_input_destroy (input);
57 input->flags = HB_SUBSET_FLAGS_DEFAULT;
59 hb_set_add_range (input->sets.name_ids, 0, 6);
60 hb_set_add (input->sets.name_languages, 0x0409);
62 hb_tag_t default_drop_tables[] = {
63 // Layout disabled by default
64 HB_TAG ('m', 'o', 'r', 'x'),
65 HB_TAG ('m', 'o', 'r', 't'),
66 HB_TAG ('k', 'e', 'r', 'x'),
67 HB_TAG ('k', 'e', 'r', 'n'),
69 // Copied from fontTools:
70 HB_TAG ('B', 'A', 'S', 'E'),
71 HB_TAG ('J', 'S', 'T', 'F'),
72 HB_TAG ('D', 'S', 'I', 'G'),
73 HB_TAG ('E', 'B', 'D', 'T'),
74 HB_TAG ('E', 'B', 'L', 'C'),
75 HB_TAG ('E', 'B', 'S', 'C'),
76 HB_TAG ('S', 'V', 'G', ' '),
77 HB_TAG ('P', 'C', 'L', 'T'),
78 HB_TAG ('L', 'T', 'S', 'H'),
80 HB_TAG ('F', 'e', 'a', 't'),
81 HB_TAG ('G', 'l', 'a', 't'),
82 HB_TAG ('G', 'l', 'o', 'c'),
83 HB_TAG ('S', 'i', 'l', 'f'),
84 HB_TAG ('S', 'i', 'l', 'l'),
86 input->sets.drop_tables->add_array (default_drop_tables, ARRAY_LENGTH (default_drop_tables));
88 hb_tag_t default_no_subset_tables[] = {
89 HB_TAG ('a', 'v', 'a', 'r'),
90 HB_TAG ('f', 'v', 'a', 'r'),
91 HB_TAG ('g', 'a', 's', 'p'),
92 HB_TAG ('c', 'v', 't', ' '),
93 HB_TAG ('f', 'p', 'g', 'm'),
94 HB_TAG ('p', 'r', 'e', 'p'),
95 HB_TAG ('V', 'D', 'M', 'X'),
96 HB_TAG ('D', 'S', 'I', 'G'),
97 HB_TAG ('M', 'V', 'A', 'R'),
98 HB_TAG ('c', 'v', 'a', 'r'),
99 HB_TAG ('S', 'T', 'A', 'T'),
101 input->sets.no_subset_tables->add_array (default_no_subset_tables,
102 ARRAY_LENGTH (default_no_subset_tables));
104 //copied from _layout_features_groups in fonttools
105 hb_tag_t default_layout_features[] = {
108 HB_TAG ('r', 'v', 'r', 'n'),
109 HB_TAG ('c', 'c', 'm', 'p'),
110 HB_TAG ('l', 'i', 'g', 'a'),
111 HB_TAG ('l', 'o', 'c', 'l'),
112 HB_TAG ('m', 'a', 'r', 'k'),
113 HB_TAG ('m', 'k', 'm', 'k'),
114 HB_TAG ('r', 'l', 'i', 'g'),
117 HB_TAG ('f', 'r', 'a', 'c'),
118 HB_TAG ('n', 'u', 'm', 'r'),
119 HB_TAG ('d', 'n', 'o', 'm'),
122 HB_TAG ('c', 'a', 'l', 't'),
123 HB_TAG ('c', 'l', 'i', 'g'),
124 HB_TAG ('c', 'u', 'r', 's'),
125 HB_TAG ('k', 'e', 'r', 'n'),
126 HB_TAG ('r', 'c', 'l', 't'),
129 HB_TAG ('v', 'a', 'l', 't'),
130 HB_TAG ('v', 'e', 'r', 't'),
131 HB_TAG ('v', 'k', 'r', 'n'),
132 HB_TAG ('v', 'p', 'a', 'l'),
133 HB_TAG ('v', 'r', 't', '2'),
136 HB_TAG ('l', 't', 'r', 'a'),
137 HB_TAG ('l', 't', 'r', 'm'),
140 HB_TAG ('r', 't', 'l', 'a'),
141 HB_TAG ('r', 't', 'l', 'm'),
145 HB_TAG ('i', 'n', 'i', 't'),
146 HB_TAG ('m', 'e', 'd', 'i'),
147 HB_TAG ('f', 'i', 'n', 'a'),
148 HB_TAG ('i', 's', 'o', 'l'),
149 HB_TAG ('m', 'e', 'd', '2'),
150 HB_TAG ('f', 'i', 'n', '2'),
151 HB_TAG ('f', 'i', 'n', '3'),
152 HB_TAG ('c', 's', 'w', 'h'),
153 HB_TAG ('m', 's', 'e', 't'),
154 HB_TAG ('s', 't', 'c', 'h'),
157 HB_TAG ('l', 'j', 'm', 'o'),
158 HB_TAG ('v', 'j', 'm', 'o'),
159 HB_TAG ('t', 'j', 'm', 'o'),
162 HB_TAG ('a', 'b', 'v', 's'),
163 HB_TAG ('b', 'l', 'w', 's'),
164 HB_TAG ('a', 'b', 'v', 'm'),
165 HB_TAG ('b', 'l', 'w', 'm'),
168 HB_TAG ('n', 'u', 'k', 't'),
169 HB_TAG ('a', 'k', 'h', 'n'),
170 HB_TAG ('r', 'p', 'h', 'f'),
171 HB_TAG ('r', 'k', 'r', 'f'),
172 HB_TAG ('p', 'r', 'e', 'f'),
173 HB_TAG ('b', 'l', 'w', 'f'),
174 HB_TAG ('h', 'a', 'l', 'f'),
175 HB_TAG ('a', 'b', 'v', 'f'),
176 HB_TAG ('p', 's', 't', 'f'),
177 HB_TAG ('c', 'f', 'a', 'r'),
178 HB_TAG ('v', 'a', 't', 'u'),
179 HB_TAG ('c', 'j', 'c', 't'),
180 HB_TAG ('i', 'n', 'i', 't'),
181 HB_TAG ('p', 'r', 'e', 's'),
182 HB_TAG ('a', 'b', 'v', 's'),
183 HB_TAG ('b', 'l', 'w', 's'),
184 HB_TAG ('p', 's', 't', 's'),
185 HB_TAG ('h', 'a', 'l', 'n'),
186 HB_TAG ('d', 'i', 's', 't'),
187 HB_TAG ('a', 'b', 'v', 'm'),
188 HB_TAG ('b', 'l', 'w', 'm'),
191 input->sets.layout_features->add_array (default_layout_features, ARRAY_LENGTH (default_layout_features));
193 if (input->in_error ())
195 hb_subset_input_destroy (input);
202 * hb_subset_input_reference: (skip)
203 * @input: a #hb_subset_input_t object.
205 * Increases the reference count on @input.
207 * Return value: @input.
212 hb_subset_input_reference (hb_subset_input_t *input)
214 return hb_object_reference (input);
218 * hb_subset_input_destroy:
219 * @input: a #hb_subset_input_t object.
221 * Decreases the reference count on @input, and if it reaches zero, destroys
222 * @input, freeing all memory.
227 hb_subset_input_destroy (hb_subset_input_t *input)
229 if (!hb_object_destroy (input)) return;
231 for (hb_set_t* set : input->sets_iter ())
232 hb_set_destroy (set);
238 * hb_subset_input_unicode_set:
239 * @input: a #hb_subset_input_t object.
241 * Gets the set of Unicode code points to retain, the caller should modify the
244 * Return value: (transfer none): pointer to the #hb_set_t of Unicode code
250 hb_subset_input_unicode_set (hb_subset_input_t *input)
252 return input->sets.unicodes;
256 * hb_subset_input_glyph_set:
257 * @input: a #hb_subset_input_t object.
259 * Gets the set of glyph IDs to retain, the caller should modify the set as
262 * Return value: (transfer none): pointer to the #hb_set_t of glyph IDs.
267 hb_subset_input_glyph_set (hb_subset_input_t *input)
269 return input->sets.glyphs;
273 * hb_subset_input_set:
274 * @input: a #hb_subset_input_t object.
275 * @set_type: a #hb_subset_sets_t set type.
277 * Gets the set of the specified type.
279 * Return value: (transfer none): pointer to the #hb_set_t of the specified type.
284 hb_subset_input_set (hb_subset_input_t *input, hb_subset_sets_t set_type)
286 return input->sets_iter () [set_type];
290 * hb_subset_input_get_flags:
291 * @input: a #hb_subset_input_t object.
293 * Gets all of the subsetting flags in the input object.
295 * Return value: the subsetting flags bit field.
299 HB_EXTERN hb_subset_flags_t
300 hb_subset_input_get_flags (hb_subset_input_t *input)
302 return (hb_subset_flags_t) input->flags;
306 * hb_subset_input_set_flags:
307 * @input: a #hb_subset_input_t object.
308 * @value: bit field of flags
310 * Sets all of the flags in the input object to the values specified by the bit
316 hb_subset_input_set_flags (hb_subset_input_t *input,
319 input->flags = (hb_subset_flags_t) value;
323 * hb_subset_input_set_user_data: (skip)
324 * @input: a #hb_subset_input_t object.
325 * @key: The user-data key to set
326 * @data: A pointer to the user data
327 * @destroy: (nullable): A callback to call when @data is not needed anymore
328 * @replace: Whether to replace an existing data with the same key
330 * Attaches a user-data key/data pair to the given subset input object.
332 * Return value: %true if success, %false otherwise
337 hb_subset_input_set_user_data (hb_subset_input_t *input,
338 hb_user_data_key_t *key,
340 hb_destroy_func_t destroy,
343 return hb_object_set_user_data (input, key, data, destroy, replace);
347 * hb_subset_input_get_user_data: (skip)
348 * @input: a #hb_subset_input_t object.
349 * @key: The user-data key to query
351 * Fetches the user data associated with the specified key,
352 * attached to the specified subset input object.
354 * Return value: (transfer none): A pointer to the user data
359 hb_subset_input_get_user_data (const hb_subset_input_t *input,
360 hb_user_data_key_t *key)
362 return hb_object_get_user_data (input, key);