1 | /* Pango |
2 | * pango-coverage.c: Coverage maps for fonts |
3 | * |
4 | * Copyright (C) 2000 Red Hat Software |
5 | * |
6 | * This library is free software; you can redistribute it and/or |
7 | * modify it under the terms of the GNU Library General Public |
8 | * License as published by the Free Software Foundation; either |
9 | * version 2 of the License, or (at your option) any later version. |
10 | * |
11 | * This library is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | * Library General Public License for more details. |
15 | * |
16 | * You should have received a copy of the GNU Library General Public |
17 | * License along with this library; if not, write to the |
18 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
19 | * Boston, MA 02111-1307, USA. |
20 | */ |
21 | |
22 | #include "config.h" |
23 | #include <string.h> |
24 | |
25 | #include "pango-coverage-private.h" |
26 | |
27 | G_DEFINE_TYPE (PangoCoverage, pango_coverage, G_TYPE_OBJECT) |
28 | |
29 | static void |
30 | pango_coverage_init (PangoCoverage *coverage) |
31 | { |
32 | } |
33 | |
34 | static void |
35 | pango_coverage_finalize (GObject *object) |
36 | { |
37 | PangoCoverage *coverage = PANGO_COVERAGE (object); |
38 | |
39 | if (coverage->chars) |
40 | hb_set_destroy (set: coverage->chars); |
41 | |
42 | G_OBJECT_CLASS (pango_coverage_parent_class)->finalize (object); |
43 | } |
44 | |
45 | static PangoCoverageLevel |
46 | pango_coverage_real_get (PangoCoverage *coverage, |
47 | int index) |
48 | { |
49 | if (coverage->chars == NULL) |
50 | return PANGO_COVERAGE_NONE; |
51 | |
52 | if (hb_set_has (set: coverage->chars, codepoint: (hb_codepoint_t)index)) |
53 | return PANGO_COVERAGE_EXACT; |
54 | else |
55 | return PANGO_COVERAGE_NONE; |
56 | } |
57 | |
58 | static void |
59 | pango_coverage_real_set (PangoCoverage *coverage, |
60 | int index, |
61 | PangoCoverageLevel level) |
62 | { |
63 | if (coverage->chars == NULL) |
64 | coverage->chars = hb_set_create (); |
65 | |
66 | if (level != PANGO_COVERAGE_NONE) |
67 | hb_set_add (set: coverage->chars, codepoint: (hb_codepoint_t)index); |
68 | else |
69 | hb_set_del (set: coverage->chars, codepoint: (hb_codepoint_t)index); |
70 | } |
71 | |
72 | static PangoCoverage * |
73 | pango_coverage_real_copy (PangoCoverage *coverage) |
74 | { |
75 | PangoCoverage *copy; |
76 | |
77 | g_return_val_if_fail (coverage != NULL, NULL); |
78 | |
79 | copy = g_object_new (PANGO_TYPE_COVERAGE, NULL); |
80 | if (coverage->chars) |
81 | { |
82 | int i; |
83 | |
84 | copy->chars = hb_set_create (); |
85 | for (i = hb_set_get_min (set: coverage->chars); i <= hb_set_get_max (set: coverage->chars); i++) |
86 | { |
87 | if (hb_set_has (set: coverage->chars, codepoint: (hb_codepoint_t)i)) |
88 | hb_set_add (set: copy->chars, codepoint: (hb_codepoint_t)i); |
89 | } |
90 | } |
91 | |
92 | return copy; |
93 | } |
94 | |
95 | static void |
96 | pango_coverage_class_init (PangoCoverageClass *class) |
97 | { |
98 | GObjectClass *object_class = G_OBJECT_CLASS (class); |
99 | |
100 | object_class->finalize = pango_coverage_finalize; |
101 | |
102 | class->get = pango_coverage_real_get; |
103 | class->set = pango_coverage_real_set; |
104 | class->copy = pango_coverage_real_copy; |
105 | } |
106 | |
107 | /** |
108 | * pango_coverage_new: |
109 | * |
110 | * Create a new `PangoCoverage` |
111 | * |
112 | * Return value: the newly allocated `PangoCoverage`, initialized |
113 | * to %PANGO_COVERAGE_NONE with a reference count of one, which |
114 | * should be freed with [method@Pango.Coverage.unref]. |
115 | */ |
116 | PangoCoverage * |
117 | pango_coverage_new (void) |
118 | { |
119 | return g_object_new (PANGO_TYPE_COVERAGE, NULL); |
120 | } |
121 | |
122 | /** |
123 | * pango_coverage_copy: |
124 | * @coverage: a `PangoCoverage` |
125 | * |
126 | * Copy an existing `PangoCoverage`. |
127 | * |
128 | * Return value: (transfer full): the newly allocated `PangoCoverage`, |
129 | * with a reference count of one, which should be freed with |
130 | * [method@Pango.Coverage.unref]. |
131 | */ |
132 | PangoCoverage * |
133 | pango_coverage_copy (PangoCoverage *coverage) |
134 | { |
135 | return PANGO_COVERAGE_GET_CLASS (coverage)->copy (coverage); |
136 | } |
137 | |
138 | /** |
139 | * pango_coverage_ref: |
140 | * @coverage: (not nullable): a `PangoCoverage` |
141 | * |
142 | * Increase the reference count on the `PangoCoverage` by one. |
143 | * |
144 | * Return value: (transfer full): @coverage |
145 | * |
146 | * Deprecated: 1.52: Use g_object_ref instead |
147 | */ |
148 | PangoCoverage * |
149 | pango_coverage_ref (PangoCoverage *coverage) |
150 | { |
151 | return g_object_ref (coverage); |
152 | } |
153 | |
154 | /** |
155 | * pango_coverage_unref: |
156 | * @coverage: (transfer full) (not nullable): a `PangoCoverage` |
157 | * |
158 | * Decrease the reference count on the `PangoCoverage` by one. |
159 | * |
160 | * If the result is zero, free the coverage and all associated memory. |
161 | * |
162 | * Deprecated: 1.52: Use g_object_unref instead |
163 | */ |
164 | void |
165 | pango_coverage_unref (PangoCoverage *coverage) |
166 | { |
167 | g_object_unref (object: coverage); |
168 | } |
169 | |
170 | /** |
171 | * pango_coverage_get: |
172 | * @coverage: a `PangoCoverage` |
173 | * @index_: the index to check |
174 | * |
175 | * Determine whether a particular index is covered by @coverage. |
176 | * |
177 | * Return value: the coverage level of @coverage for character @index_. |
178 | */ |
179 | PangoCoverageLevel |
180 | pango_coverage_get (PangoCoverage *coverage, |
181 | int index) |
182 | { |
183 | return PANGO_COVERAGE_GET_CLASS (coverage)->get (coverage, index); |
184 | } |
185 | |
186 | /** |
187 | * pango_coverage_set: |
188 | * @coverage: a `PangoCoverage` |
189 | * @index_: the index to modify |
190 | * @level: the new level for @index_ |
191 | * |
192 | * Modify a particular index within @coverage |
193 | */ |
194 | void |
195 | pango_coverage_set (PangoCoverage *coverage, |
196 | int index, |
197 | PangoCoverageLevel level) |
198 | { |
199 | PANGO_COVERAGE_GET_CLASS (coverage)->set (coverage, index, level); |
200 | } |
201 | |
202 | /** |
203 | * pango_coverage_max: |
204 | * @coverage: a `PangoCoverage` |
205 | * @other: another `PangoCoverage` |
206 | * |
207 | * Set the coverage for each index in @coverage to be the max (better) |
208 | * value of the current coverage for the index and the coverage for |
209 | * the corresponding index in @other. |
210 | * |
211 | * Deprecated: 1.44: This function does nothing |
212 | */ |
213 | void |
214 | pango_coverage_max (PangoCoverage *coverage, |
215 | PangoCoverage *other) |
216 | { |
217 | } |
218 | |
219 | /** |
220 | * pango_coverage_to_bytes: |
221 | * @coverage: a `PangoCoverage` |
222 | * @bytes: (out) (array length=n_bytes) (element-type guint8): |
223 | * location to store result (must be freed with g_free()) |
224 | * @n_bytes: (out): location to store size of result |
225 | * |
226 | * Convert a `PangoCoverage` structure into a flat binary format. |
227 | * |
228 | * Deprecated: 1.44: This returns %NULL |
229 | */ |
230 | void |
231 | pango_coverage_to_bytes (PangoCoverage *coverage, |
232 | guchar **bytes, |
233 | int *n_bytes) |
234 | { |
235 | *bytes = NULL; |
236 | *n_bytes = 0; |
237 | } |
238 | |
239 | /** |
240 | * pango_coverage_from_bytes: |
241 | * @bytes: (array length=n_bytes) (element-type guint8): binary data |
242 | * representing a `PangoCoverage` |
243 | * @n_bytes: the size of @bytes in bytes |
244 | * |
245 | * Convert data generated from [method@Pango.Coverage.to_bytes] |
246 | * back to a `PangoCoverage`. |
247 | * |
248 | * Return value: (transfer full) (nullable): a newly allocated `PangoCoverage` |
249 | * |
250 | * Deprecated: 1.44: This returns %NULL |
251 | */ |
252 | PangoCoverage * |
253 | pango_coverage_from_bytes (guchar *bytes, |
254 | int n_bytes) |
255 | { |
256 | return NULL; |
257 | } |
258 | |