1 | /* |
2 | * Copyright © 2018 Google, Inc. |
3 | * |
4 | * This is part of HarfBuzz, a text shaping library. |
5 | * |
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. |
11 | * |
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 |
16 | * DAMAGE. |
17 | * |
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. |
23 | * |
24 | * Google Author(s): Garret Rieger, Rod Sheeter, Behdad Esfahbod |
25 | */ |
26 | |
27 | #include "hb-subset.hh" |
28 | #include "hb-set.hh" |
29 | |
30 | /** |
31 | * hb_subset_input_create_or_fail: |
32 | * |
33 | * Return value: New subset input. |
34 | * |
35 | * Since: 1.8.0 |
36 | **/ |
37 | hb_subset_input_t * |
38 | hb_subset_input_create_or_fail () |
39 | { |
40 | hb_subset_input_t *input = hb_object_create<hb_subset_input_t>(); |
41 | |
42 | if (unlikely (!input)) |
43 | return nullptr; |
44 | |
45 | input->unicodes = hb_set_create (); |
46 | input->glyphs = hb_set_create (); |
47 | input->name_ids = hb_set_create (); |
48 | hb_set_add_range (input->name_ids, 0, 6); |
49 | input->name_languages = hb_set_create (); |
50 | hb_set_add (input->name_languages, 0x0409); |
51 | input->drop_tables = hb_set_create (); |
52 | input->drop_hints = false; |
53 | input->desubroutinize = false; |
54 | input->retain_gids = false; |
55 | input->name_legacy = false; |
56 | |
57 | hb_tag_t default_drop_tables[] = { |
58 | // Layout disabled by default |
59 | HB_TAG ('G', 'S', 'U', 'B'), |
60 | HB_TAG ('G', 'P', 'O', 'S'), |
61 | HB_TAG ('G', 'D', 'E', 'F'), |
62 | HB_TAG ('m', 'o', 'r', 'x'), |
63 | HB_TAG ('m', 'o', 'r', 't'), |
64 | HB_TAG ('k', 'e', 'r', 'x'), |
65 | HB_TAG ('k', 'e', 'r', 'n'), |
66 | |
67 | // Copied from fontTools: |
68 | HB_TAG ('B', 'A', 'S', 'E'), |
69 | HB_TAG ('J', 'S', 'T', 'F'), |
70 | HB_TAG ('D', 'S', 'I', 'G'), |
71 | HB_TAG ('E', 'B', 'D', 'T'), |
72 | HB_TAG ('E', 'B', 'L', 'C'), |
73 | HB_TAG ('E', 'B', 'S', 'C'), |
74 | HB_TAG ('S', 'V', 'G', ' '), |
75 | HB_TAG ('P', 'C', 'L', 'T'), |
76 | HB_TAG ('L', 'T', 'S', 'H'), |
77 | // Graphite tables |
78 | HB_TAG ('F', 'e', 'a', 't'), |
79 | HB_TAG ('G', 'l', 'a', 't'), |
80 | HB_TAG ('G', 'l', 'o', 'c'), |
81 | HB_TAG ('S', 'i', 'l', 'f'), |
82 | HB_TAG ('S', 'i', 'l', 'l'), |
83 | }; |
84 | |
85 | input->drop_tables->add_array (default_drop_tables, ARRAY_LENGTH (default_drop_tables)); |
86 | |
87 | return input; |
88 | } |
89 | |
90 | /** |
91 | * hb_subset_input_reference: (skip) |
92 | * @subset_input: a subset_input. |
93 | * |
94 | * |
95 | * |
96 | * Return value: |
97 | * |
98 | * Since: 1.8.0 |
99 | **/ |
100 | hb_subset_input_t * |
101 | hb_subset_input_reference (hb_subset_input_t *subset_input) |
102 | { |
103 | return hb_object_reference (subset_input); |
104 | } |
105 | |
106 | /** |
107 | * hb_subset_input_destroy: |
108 | * @subset_input: a subset_input. |
109 | * |
110 | * Since: 1.8.0 |
111 | **/ |
112 | void |
113 | hb_subset_input_destroy (hb_subset_input_t *subset_input) |
114 | { |
115 | if (!hb_object_destroy (subset_input)) return; |
116 | |
117 | hb_set_destroy (subset_input->unicodes); |
118 | hb_set_destroy (subset_input->glyphs); |
119 | hb_set_destroy (subset_input->name_ids); |
120 | hb_set_destroy (subset_input->name_languages); |
121 | hb_set_destroy (subset_input->drop_tables); |
122 | |
123 | free (subset_input); |
124 | } |
125 | |
126 | /** |
127 | * hb_subset_input_unicode_set: |
128 | * @subset_input: a subset_input. |
129 | * |
130 | * Since: 1.8.0 |
131 | **/ |
132 | HB_EXTERN hb_set_t * |
133 | hb_subset_input_unicode_set (hb_subset_input_t *subset_input) |
134 | { |
135 | return subset_input->unicodes; |
136 | } |
137 | |
138 | /** |
139 | * hb_subset_input_glyph_set: |
140 | * @subset_input: a subset_input. |
141 | * |
142 | * Since: 1.8.0 |
143 | **/ |
144 | HB_EXTERN hb_set_t * |
145 | hb_subset_input_glyph_set (hb_subset_input_t *subset_input) |
146 | { |
147 | return subset_input->glyphs; |
148 | } |
149 | |
150 | HB_EXTERN hb_set_t * |
151 | hb_subset_input_nameid_set (hb_subset_input_t *subset_input) |
152 | { |
153 | return subset_input->name_ids; |
154 | } |
155 | |
156 | HB_EXTERN hb_set_t * |
157 | hb_subset_input_namelangid_set (hb_subset_input_t *subset_input) |
158 | { |
159 | return subset_input->name_languages; |
160 | } |
161 | |
162 | HB_EXTERN hb_set_t * |
163 | hb_subset_input_drop_tables_set (hb_subset_input_t *subset_input) |
164 | { |
165 | return subset_input->drop_tables; |
166 | } |
167 | |
168 | HB_EXTERN void |
169 | hb_subset_input_set_drop_hints (hb_subset_input_t *subset_input, |
170 | hb_bool_t drop_hints) |
171 | { |
172 | subset_input->drop_hints = drop_hints; |
173 | } |
174 | |
175 | HB_EXTERN hb_bool_t |
176 | hb_subset_input_get_drop_hints (hb_subset_input_t *subset_input) |
177 | { |
178 | return subset_input->drop_hints; |
179 | } |
180 | |
181 | HB_EXTERN void |
182 | hb_subset_input_set_desubroutinize (hb_subset_input_t *subset_input, |
183 | hb_bool_t desubroutinize) |
184 | { |
185 | subset_input->desubroutinize = desubroutinize; |
186 | } |
187 | |
188 | HB_EXTERN hb_bool_t |
189 | hb_subset_input_get_desubroutinize (hb_subset_input_t *subset_input) |
190 | { |
191 | return subset_input->desubroutinize; |
192 | } |
193 | |
194 | /** |
195 | * hb_subset_input_set_retain_gids: |
196 | * @subset_input: a subset_input. |
197 | * @retain_gids: If true the subsetter will not renumber glyph ids. |
198 | * Since: 2.4.0 |
199 | **/ |
200 | HB_EXTERN void |
201 | hb_subset_input_set_retain_gids (hb_subset_input_t *subset_input, |
202 | hb_bool_t retain_gids) |
203 | { |
204 | subset_input->retain_gids = retain_gids; |
205 | } |
206 | |
207 | /** |
208 | * hb_subset_input_get_retain_gids: |
209 | * Returns: value of retain_gids. |
210 | * Since: 2.4.0 |
211 | **/ |
212 | HB_EXTERN hb_bool_t |
213 | hb_subset_input_get_retain_gids (hb_subset_input_t *subset_input) |
214 | { |
215 | return subset_input->retain_gids; |
216 | } |
217 | |
218 | HB_EXTERN void |
219 | hb_subset_input_set_name_legacy (hb_subset_input_t *subset_input, |
220 | hb_bool_t name_legacy) |
221 | { |
222 | subset_input->name_legacy = name_legacy; |
223 | } |
224 | |
225 | HB_EXTERN hb_bool_t |
226 | hb_subset_input_get_name_legacy (hb_subset_input_t *subset_input) |
227 | { |
228 | return subset_input->name_legacy; |
229 | } |
230 | |