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 **/
37hb_subset_input_t *
38hb_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->drop_tables = hb_set_create ();
50 input->drop_hints = false;
51 input->desubroutinize = false;
52 input->retain_gids = false;
53
54 hb_tag_t default_drop_tables[] = {
55 // Layout disabled by default
56 HB_TAG ('G', 'S', 'U', 'B'),
57 HB_TAG ('G', 'P', 'O', 'S'),
58 HB_TAG ('G', 'D', 'E', 'F'),
59 HB_TAG ('m', 'o', 'r', 'x'),
60 HB_TAG ('m', 'o', 'r', 't'),
61 HB_TAG ('k', 'e', 'r', 'x'),
62 HB_TAG ('k', 'e', 'r', 'n'),
63
64 // Copied from fontTools:
65 HB_TAG ('B', 'A', 'S', 'E'),
66 HB_TAG ('J', 'S', 'T', 'F'),
67 HB_TAG ('D', 'S', 'I', 'G'),
68 HB_TAG ('E', 'B', 'D', 'T'),
69 HB_TAG ('E', 'B', 'L', 'C'),
70 HB_TAG ('E', 'B', 'S', 'C'),
71 HB_TAG ('S', 'V', 'G', ' '),
72 HB_TAG ('P', 'C', 'L', 'T'),
73 HB_TAG ('L', 'T', 'S', 'H'),
74 // Graphite tables
75 HB_TAG ('F', 'e', 'a', 't'),
76 HB_TAG ('G', 'l', 'a', 't'),
77 HB_TAG ('G', 'l', 'o', 'c'),
78 HB_TAG ('S', 'i', 'l', 'f'),
79 HB_TAG ('S', 'i', 'l', 'l'),
80 // Colour
81 HB_TAG ('s', 'b', 'i', 'x')
82 };
83
84 input->drop_tables->add_array (default_drop_tables, ARRAY_LENGTH (default_drop_tables));
85
86 return input;
87}
88
89/**
90 * hb_subset_input_reference: (skip)
91 * @subset_input: a subset_input.
92 *
93 *
94 *
95 * Return value:
96 *
97 * Since: 1.8.0
98 **/
99hb_subset_input_t *
100hb_subset_input_reference (hb_subset_input_t *subset_input)
101{
102 return hb_object_reference (subset_input);
103}
104
105/**
106 * hb_subset_input_destroy:
107 * @subset_input: a subset_input.
108 *
109 * Since: 1.8.0
110 **/
111void
112hb_subset_input_destroy (hb_subset_input_t *subset_input)
113{
114 if (!hb_object_destroy (subset_input)) return;
115
116 hb_set_destroy (subset_input->unicodes);
117 hb_set_destroy (subset_input->glyphs);
118 hb_set_destroy (subset_input->name_ids);
119 hb_set_destroy (subset_input->drop_tables);
120
121 free (subset_input);
122}
123
124/**
125 * hb_subset_input_unicode_set:
126 * @subset_input: a subset_input.
127 *
128 * Since: 1.8.0
129 **/
130HB_EXTERN hb_set_t *
131hb_subset_input_unicode_set (hb_subset_input_t *subset_input)
132{
133 return subset_input->unicodes;
134}
135
136/**
137 * hb_subset_input_glyph_set:
138 * @subset_input: a subset_input.
139 *
140 * Since: 1.8.0
141 **/
142HB_EXTERN hb_set_t *
143hb_subset_input_glyph_set (hb_subset_input_t *subset_input)
144{
145 return subset_input->glyphs;
146}
147
148HB_EXTERN hb_set_t *
149hb_subset_input_nameid_set (hb_subset_input_t *subset_input)
150{
151 return subset_input->name_ids;
152}
153
154HB_EXTERN hb_set_t *
155hb_subset_input_drop_tables_set (hb_subset_input_t *subset_input)
156{
157 return subset_input->drop_tables;
158}
159
160HB_EXTERN void
161hb_subset_input_set_drop_hints (hb_subset_input_t *subset_input,
162 hb_bool_t drop_hints)
163{
164 subset_input->drop_hints = drop_hints;
165}
166
167HB_EXTERN hb_bool_t
168hb_subset_input_get_drop_hints (hb_subset_input_t *subset_input)
169{
170 return subset_input->drop_hints;
171}
172
173HB_EXTERN void
174hb_subset_input_set_desubroutinize (hb_subset_input_t *subset_input,
175 hb_bool_t desubroutinize)
176{
177 subset_input->desubroutinize = desubroutinize;
178}
179
180HB_EXTERN hb_bool_t
181hb_subset_input_get_desubroutinize (hb_subset_input_t *subset_input)
182{
183 return subset_input->desubroutinize;
184}
185
186/**
187 * hb_subset_input_set_retain_gids:
188 * @subset_input: a subset_input.
189 * @retain_gids: If true the subsetter will not renumber glyph ids.
190 * Since: 2.4.0
191 **/
192HB_EXTERN void
193hb_subset_input_set_retain_gids (hb_subset_input_t *subset_input,
194 hb_bool_t retain_gids)
195{
196 subset_input->retain_gids = retain_gids;
197}
198
199/**
200 * hb_subset_input_get_retain_gids:
201 * Returns: value of retain_gids.
202 * Since: 2.4.0
203 **/
204HB_EXTERN hb_bool_t
205hb_subset_input_get_retain_gids (hb_subset_input_t *subset_input)
206{
207 return subset_input->retain_gids;
208}
209