/src/cairo/src/cairo-font-options.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* cairo - a vector graphics library with display and print output |
2 | | * |
3 | | * Copyright © 2005 Red Hat Inc. |
4 | | * |
5 | | * This library is free software; you can redistribute it and/or |
6 | | * modify it either under the terms of the GNU Lesser General Public |
7 | | * License version 2.1 as published by the Free Software Foundation |
8 | | * (the "LGPL") or, at your option, under the terms of the Mozilla |
9 | | * Public License Version 1.1 (the "MPL"). If you do not alter this |
10 | | * notice, a recipient may use your version of this file under either |
11 | | * the MPL or the LGPL. |
12 | | * |
13 | | * You should have received a copy of the LGPL along with this library |
14 | | * in the file COPYING-LGPL-2.1; if not, write to the Free Software |
15 | | * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA |
16 | | * You should have received a copy of the MPL along with this library |
17 | | * in the file COPYING-MPL-1.1 |
18 | | * |
19 | | * The contents of this file are subject to the Mozilla Public License |
20 | | * Version 1.1 (the "License"); you may not use this file except in |
21 | | * compliance with the License. You may obtain a copy of the License at |
22 | | * http://www.mozilla.org/MPL/ |
23 | | * |
24 | | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY |
25 | | * OF ANY KIND, either express or implied. See the LGPL or the MPL for |
26 | | * the specific language governing rights and limitations. |
27 | | * |
28 | | * The Original Code is the cairo graphics library. |
29 | | * |
30 | | * The Initial Developer of the Original Code is University of Southern |
31 | | * California. |
32 | | * |
33 | | * Contributor(s): |
34 | | * Owen Taylor <otaylor@redhat.com> |
35 | | */ |
36 | | |
37 | | #include "cairoint.h" |
38 | | #include "cairo-error-private.h" |
39 | | |
40 | | /** |
41 | | * SECTION:cairo-font-options |
42 | | * @Title: cairo_font_options_t |
43 | | * @Short_Description: How a font should be rendered |
44 | | * @See_Also: #cairo_scaled_font_t |
45 | | * |
46 | | * The font options specify how fonts should be rendered. Most of the |
47 | | * time the font options implied by a surface are just right and do not |
48 | | * need any changes, but for pixel-based targets tweaking font options |
49 | | * may result in superior output on a particular display. |
50 | | **/ |
51 | | |
52 | | static const cairo_font_options_t _cairo_font_options_nil = { |
53 | | CAIRO_ANTIALIAS_DEFAULT, |
54 | | CAIRO_SUBPIXEL_ORDER_DEFAULT, |
55 | | CAIRO_LCD_FILTER_DEFAULT, |
56 | | CAIRO_HINT_STYLE_DEFAULT, |
57 | | CAIRO_HINT_METRICS_DEFAULT, |
58 | | CAIRO_ROUND_GLYPH_POS_DEFAULT, |
59 | | NULL, /* variations */ |
60 | | CAIRO_COLOR_MODE_DEFAULT, |
61 | | CAIRO_COLOR_PALETTE_DEFAULT, |
62 | | NULL, 0, /* custom palette */ |
63 | | }; |
64 | | |
65 | | /** |
66 | | * _cairo_font_options_init_default: |
67 | | * @options: a #cairo_font_options_t |
68 | | * |
69 | | * Initializes all fields of the font options object to default values. |
70 | | **/ |
71 | | void |
72 | | _cairo_font_options_init_default (cairo_font_options_t *options) |
73 | 10.1k | { |
74 | 10.1k | options->antialias = CAIRO_ANTIALIAS_DEFAULT; |
75 | 10.1k | options->subpixel_order = CAIRO_SUBPIXEL_ORDER_DEFAULT; |
76 | 10.1k | options->lcd_filter = CAIRO_LCD_FILTER_DEFAULT; |
77 | 10.1k | options->hint_style = CAIRO_HINT_STYLE_DEFAULT; |
78 | 10.1k | options->hint_metrics = CAIRO_HINT_METRICS_DEFAULT; |
79 | 10.1k | options->round_glyph_positions = CAIRO_ROUND_GLYPH_POS_DEFAULT; |
80 | 10.1k | options->variations = NULL; |
81 | 10.1k | options->color_mode = CAIRO_COLOR_MODE_DEFAULT; |
82 | 10.1k | options->palette_index = CAIRO_COLOR_PALETTE_DEFAULT; |
83 | 10.1k | options->custom_palette = NULL; |
84 | 10.1k | options->custom_palette_size = 0; |
85 | 10.1k | } |
86 | | |
87 | | void |
88 | | _cairo_font_options_init_copy (cairo_font_options_t *options, |
89 | | const cairo_font_options_t *other) |
90 | 1.12M | { |
91 | 1.12M | options->antialias = other->antialias; |
92 | 1.12M | options->subpixel_order = other->subpixel_order; |
93 | 1.12M | options->lcd_filter = other->lcd_filter; |
94 | 1.12M | options->hint_style = other->hint_style; |
95 | 1.12M | options->hint_metrics = other->hint_metrics; |
96 | 1.12M | options->round_glyph_positions = other->round_glyph_positions; |
97 | 1.12M | options->variations = other->variations ? strdup (other->variations) : NULL; |
98 | 1.12M | options->color_mode = other->color_mode; |
99 | 1.12M | options->palette_index = other->palette_index; |
100 | 1.12M | options->custom_palette_size = other->custom_palette_size; |
101 | 1.12M | options->custom_palette = NULL; |
102 | 1.12M | if (other->custom_palette) { |
103 | 0 | options->custom_palette = (cairo_palette_color_t *) malloc (sizeof (cairo_palette_color_t) * options->custom_palette_size); |
104 | 0 | memcpy (options->custom_palette, other->custom_palette, sizeof (cairo_palette_color_t) * options->custom_palette_size); |
105 | 0 | } |
106 | 1.12M | } |
107 | | |
108 | | cairo_bool_t |
109 | | _cairo_font_options_compare (const cairo_font_options_t *a, |
110 | | const cairo_font_options_t *b) |
111 | 662 | { |
112 | 662 | if (a->antialias != b->antialias || |
113 | 662 | a->subpixel_order != b->subpixel_order || |
114 | 662 | a->lcd_filter != b->lcd_filter || |
115 | 662 | a->hint_style != b->hint_style || |
116 | 662 | a->hint_metrics != b->hint_metrics || |
117 | 662 | a->round_glyph_positions != b->round_glyph_positions || |
118 | 662 | a->color_mode != b->color_mode || |
119 | 662 | a->palette_index != b->palette_index || |
120 | 662 | a->custom_palette_size != b->custom_palette_size) |
121 | 0 | { |
122 | 0 | return FALSE; |
123 | 0 | } |
124 | | |
125 | 662 | if (a->variations && b->variations && strcmp (a->variations, b->variations) != 0) |
126 | 0 | return FALSE; |
127 | 662 | else if (a->variations != b->variations) |
128 | 0 | return FALSE; |
129 | | |
130 | 662 | if (a->custom_palette && b->custom_palette && |
131 | 662 | memcmp (a->custom_palette, b->custom_palette, sizeof (cairo_palette_color_t) * a->custom_palette_size) != 0) |
132 | 0 | { |
133 | 0 | return FALSE; |
134 | 0 | } |
135 | 662 | else if (a->custom_palette != b->custom_palette) |
136 | 0 | { |
137 | 0 | return FALSE; |
138 | 0 | } |
139 | | |
140 | 662 | return TRUE; |
141 | 662 | } |
142 | | |
143 | | /** |
144 | | * cairo_font_options_create: |
145 | | * |
146 | | * Allocates a new font options object with all options initialized |
147 | | * to default values. |
148 | | * |
149 | | * Return value: a newly allocated #cairo_font_options_t. Free with |
150 | | * cairo_font_options_destroy(). This function always returns a |
151 | | * valid pointer; if memory cannot be allocated, then a special |
152 | | * error object is returned where all operations on the object do nothing. |
153 | | * You can check for this with cairo_font_options_status(). |
154 | | * |
155 | | * Since: 1.0 |
156 | | **/ |
157 | | cairo_font_options_t * |
158 | | cairo_font_options_create (void) |
159 | 5.79k | { |
160 | 5.79k | cairo_font_options_t *options; |
161 | | |
162 | 5.79k | options = _cairo_calloc (sizeof (cairo_font_options_t)); |
163 | 5.79k | if (!options) { |
164 | 0 | _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); |
165 | 0 | return (cairo_font_options_t *) &_cairo_font_options_nil; |
166 | 0 | } |
167 | | |
168 | 5.79k | _cairo_font_options_init_default (options); |
169 | | |
170 | 5.79k | return options; |
171 | 5.79k | } |
172 | | |
173 | | /** |
174 | | * cairo_font_options_copy: |
175 | | * @original: a #cairo_font_options_t |
176 | | * |
177 | | * Allocates a new font options object copying the option values from |
178 | | * @original. |
179 | | * |
180 | | * Return value: a newly allocated #cairo_font_options_t. Free with |
181 | | * cairo_font_options_destroy(). This function always returns a |
182 | | * valid pointer; if memory cannot be allocated, then a special |
183 | | * error object is returned where all operations on the object do nothing. |
184 | | * You can check for this with cairo_font_options_status(). |
185 | | * |
186 | | * Since: 1.0 |
187 | | **/ |
188 | | cairo_font_options_t * |
189 | | cairo_font_options_copy (const cairo_font_options_t *original) |
190 | 0 | { |
191 | 0 | cairo_font_options_t *options; |
192 | |
|
193 | 0 | if (cairo_font_options_status ((cairo_font_options_t *) original)) |
194 | 0 | return (cairo_font_options_t *) &_cairo_font_options_nil; |
195 | | |
196 | 0 | options = _cairo_calloc (sizeof (cairo_font_options_t)); |
197 | 0 | if (!options) { |
198 | 0 | _cairo_error_throw (CAIRO_STATUS_NO_MEMORY); |
199 | 0 | return (cairo_font_options_t *) &_cairo_font_options_nil; |
200 | 0 | } |
201 | | |
202 | 0 | _cairo_font_options_init_copy (options, original); |
203 | |
|
204 | 0 | return options; |
205 | 0 | } |
206 | | |
207 | | void |
208 | | _cairo_font_options_fini (cairo_font_options_t *options) |
209 | 102k | { |
210 | 102k | free (options->variations); |
211 | 102k | free (options->custom_palette); |
212 | 102k | } |
213 | | |
214 | | /** |
215 | | * cairo_font_options_destroy: |
216 | | * @options: a #cairo_font_options_t |
217 | | * |
218 | | * Destroys a #cairo_font_options_t object created with |
219 | | * cairo_font_options_create() or cairo_font_options_copy(). |
220 | | * |
221 | | * Since: 1.0 |
222 | | **/ |
223 | | void |
224 | | cairo_font_options_destroy (cairo_font_options_t *options) |
225 | 5.79k | { |
226 | 5.79k | if (cairo_font_options_status (options)) |
227 | 0 | return; |
228 | | |
229 | 5.79k | _cairo_font_options_fini (options); |
230 | 5.79k | free (options); |
231 | 5.79k | } |
232 | | |
233 | | /** |
234 | | * cairo_font_options_status: |
235 | | * @options: a #cairo_font_options_t |
236 | | * |
237 | | * Checks whether an error has previously occurred for this |
238 | | * font options object |
239 | | * |
240 | | * Return value: %CAIRO_STATUS_SUCCESS, %CAIRO_STATUS_NO_MEMORY, or |
241 | | * %CAIRO_STATUS_NULL_POINTER. |
242 | | * |
243 | | * Since: 1.0 |
244 | | **/ |
245 | | cairo_status_t |
246 | | cairo_font_options_status (cairo_font_options_t *options) |
247 | 8.16M | { |
248 | 8.16M | if (options == NULL) |
249 | 0 | return CAIRO_STATUS_NULL_POINTER; |
250 | 8.16M | else if (options == (cairo_font_options_t *) &_cairo_font_options_nil) |
251 | 0 | return CAIRO_STATUS_NO_MEMORY; |
252 | 8.16M | else |
253 | 8.16M | return CAIRO_STATUS_SUCCESS; |
254 | 8.16M | } |
255 | | |
256 | | /** |
257 | | * cairo_font_options_merge: |
258 | | * @options: a #cairo_font_options_t |
259 | | * @other: another #cairo_font_options_t |
260 | | * |
261 | | * Merges non-default options from @other into @options, replacing |
262 | | * existing values. This operation can be thought of as somewhat |
263 | | * similar to compositing @other onto @options with the operation |
264 | | * of %CAIRO_OPERATOR_OVER. |
265 | | * |
266 | | * Since: 1.0 |
267 | | **/ |
268 | | void |
269 | | cairo_font_options_merge (cairo_font_options_t *options, |
270 | | const cairo_font_options_t *other) |
271 | 1.05M | { |
272 | 1.05M | if (cairo_font_options_status (options)) |
273 | 0 | return; |
274 | | |
275 | 1.05M | if (cairo_font_options_status ((cairo_font_options_t *) other)) |
276 | 0 | return; |
277 | | |
278 | 1.05M | if (other->antialias != CAIRO_ANTIALIAS_DEFAULT) |
279 | 1.03M | options->antialias = other->antialias; |
280 | 1.05M | if (other->subpixel_order != CAIRO_SUBPIXEL_ORDER_DEFAULT) |
281 | 0 | options->subpixel_order = other->subpixel_order; |
282 | 1.05M | if (other->lcd_filter != CAIRO_LCD_FILTER_DEFAULT) |
283 | 0 | options->lcd_filter = other->lcd_filter; |
284 | 1.05M | if (other->hint_style != CAIRO_HINT_STYLE_DEFAULT) |
285 | 1.03M | options->hint_style = other->hint_style; |
286 | 1.05M | if (other->hint_metrics != CAIRO_HINT_METRICS_DEFAULT) |
287 | 1.03M | options->hint_metrics = other->hint_metrics; |
288 | 1.05M | if (other->round_glyph_positions != CAIRO_ROUND_GLYPH_POS_DEFAULT) |
289 | 1.03M | options->round_glyph_positions = other->round_glyph_positions; |
290 | | |
291 | 1.05M | if (other->variations) { |
292 | 0 | if (options->variations) { |
293 | 0 | char *p; |
294 | | |
295 | | /* 'merge' variations by concatenating - later entries win */ |
296 | 0 | p = malloc (strlen (other->variations) + strlen (options->variations) + 2); |
297 | 0 | p[0] = 0; |
298 | 0 | strcat (p, options->variations); |
299 | 0 | strcat (p, ","); |
300 | 0 | strcat (p, other->variations); |
301 | 0 | free (options->variations); |
302 | 0 | options->variations = p; |
303 | 0 | } |
304 | 0 | else { |
305 | 0 | options->variations = strdup (other->variations); |
306 | 0 | } |
307 | 0 | } |
308 | | |
309 | 1.05M | if (other->color_mode != CAIRO_COLOR_MODE_DEFAULT) |
310 | 0 | options->color_mode = other->color_mode; |
311 | 1.05M | if (other->palette_index != CAIRO_COLOR_PALETTE_DEFAULT) |
312 | 0 | options->palette_index = other->palette_index; |
313 | 1.05M | if (other->custom_palette) { |
314 | 0 | options->custom_palette_size = other->custom_palette_size; |
315 | 0 | free (options->custom_palette); |
316 | 0 | options->custom_palette = (cairo_palette_color_t *) malloc (sizeof (cairo_palette_color_t) * options->custom_palette_size); |
317 | 0 | memcpy (options->custom_palette, other->custom_palette, sizeof (cairo_palette_color_t) * options->custom_palette_size); |
318 | 0 | } |
319 | 1.05M | } |
320 | | |
321 | | /** |
322 | | * cairo_font_options_equal: |
323 | | * @options: a #cairo_font_options_t |
324 | | * @other: another #cairo_font_options_t |
325 | | * |
326 | | * Compares two font options objects for equality. |
327 | | * |
328 | | * Return value: %TRUE if all fields of the two font options objects match. |
329 | | * Note that this function will return %FALSE if either object is in |
330 | | * error. |
331 | | * |
332 | | * Since: 1.0 |
333 | | **/ |
334 | | cairo_bool_t |
335 | | cairo_font_options_equal (const cairo_font_options_t *options, |
336 | | const cairo_font_options_t *other) |
337 | 1.05M | { |
338 | 1.05M | if (cairo_font_options_status ((cairo_font_options_t *) options)) |
339 | 0 | return FALSE; |
340 | 1.05M | if (cairo_font_options_status ((cairo_font_options_t *) other)) |
341 | 0 | return FALSE; |
342 | | |
343 | 1.05M | if (options == other) |
344 | 0 | return TRUE; |
345 | | |
346 | 1.05M | return (options->antialias == other->antialias && |
347 | 1.05M | options->subpixel_order == other->subpixel_order && |
348 | 1.05M | options->lcd_filter == other->lcd_filter && |
349 | 1.05M | options->hint_style == other->hint_style && |
350 | 1.05M | options->hint_metrics == other->hint_metrics && |
351 | 1.05M | options->round_glyph_positions == other->round_glyph_positions && |
352 | 1.05M | ((options->variations == NULL && other->variations == NULL) || |
353 | 1.05M | (options->variations != NULL && other->variations != NULL && |
354 | 0 | strcmp (options->variations, other->variations) == 0)) && |
355 | 1.05M | options->color_mode == other->color_mode && |
356 | 1.05M | options->palette_index == other->palette_index && |
357 | 1.05M | ((options->custom_palette == NULL && other->custom_palette == NULL) || |
358 | 1.05M | (options->custom_palette != NULL && other->custom_palette != NULL && |
359 | 0 | options->custom_palette_size == other->custom_palette_size && |
360 | 0 | memcmp (options->custom_palette, other->custom_palette, |
361 | 0 | sizeof (cairo_palette_color_t) * options->custom_palette_size) == 0))); |
362 | 1.05M | } |
363 | | |
364 | | /** |
365 | | * cairo_font_options_hash: |
366 | | * @options: a #cairo_font_options_t |
367 | | * |
368 | | * Compute a hash for the font options object; this value will |
369 | | * be useful when storing an object containing a #cairo_font_options_t |
370 | | * in a hash table. |
371 | | * |
372 | | * Return value: the hash value for the font options object. |
373 | | * The return value can be cast to a 32-bit type if a |
374 | | * 32-bit hash value is needed. |
375 | | * |
376 | | * Since: 1.0 |
377 | | **/ |
378 | | unsigned long |
379 | | cairo_font_options_hash (const cairo_font_options_t *options) |
380 | 26.5k | { |
381 | 26.5k | unsigned long hash = 0; |
382 | | |
383 | 26.5k | if (cairo_font_options_status ((cairo_font_options_t *) options)) |
384 | 0 | options = &_cairo_font_options_nil; /* force default values */ |
385 | | |
386 | 26.5k | if (options->variations) |
387 | 0 | hash = _cairo_string_hash (options->variations, strlen (options->variations)); |
388 | | |
389 | 26.5k | hash ^= options->palette_index; |
390 | | |
391 | 26.5k | return ((options->antialias) | |
392 | 26.5k | (options->subpixel_order << 4) | |
393 | 26.5k | (options->lcd_filter << 8) | |
394 | 26.5k | (options->hint_style << 12) | |
395 | 26.5k | (options->hint_metrics << 16) | |
396 | 26.5k | (options->color_mode << 20)) ^ hash; |
397 | 26.5k | } |
398 | | |
399 | | /** |
400 | | * cairo_font_options_set_antialias: |
401 | | * @options: a #cairo_font_options_t |
402 | | * @antialias: the new antialiasing mode |
403 | | * |
404 | | * Sets the antialiasing mode for the font options object. This |
405 | | * specifies the type of antialiasing to do when rendering text. |
406 | | * |
407 | | * Since: 1.0 |
408 | | **/ |
409 | | void |
410 | | cairo_font_options_set_antialias (cairo_font_options_t *options, |
411 | | cairo_antialias_t antialias) |
412 | 75 | { |
413 | 75 | if (cairo_font_options_status (options)) |
414 | 0 | return; |
415 | | |
416 | 75 | options->antialias = antialias; |
417 | 75 | } |
418 | | |
419 | | /** |
420 | | * cairo_font_options_get_antialias: |
421 | | * @options: a #cairo_font_options_t |
422 | | * |
423 | | * Gets the antialiasing mode for the font options object. |
424 | | * |
425 | | * Return value: the antialiasing mode |
426 | | * |
427 | | * Since: 1.0 |
428 | | **/ |
429 | | cairo_antialias_t |
430 | | cairo_font_options_get_antialias (const cairo_font_options_t *options) |
431 | 0 | { |
432 | 0 | if (cairo_font_options_status ((cairo_font_options_t *) options)) |
433 | 0 | return CAIRO_ANTIALIAS_DEFAULT; |
434 | | |
435 | 0 | return options->antialias; |
436 | 0 | } |
437 | | |
438 | | /** |
439 | | * cairo_font_options_set_subpixel_order: |
440 | | * @options: a #cairo_font_options_t |
441 | | * @subpixel_order: the new subpixel order |
442 | | * |
443 | | * Sets the subpixel order for the font options object. The subpixel |
444 | | * order specifies the order of color elements within each pixel on |
445 | | * the display device when rendering with an antialiasing mode of |
446 | | * %CAIRO_ANTIALIAS_SUBPIXEL. See the documentation for |
447 | | * #cairo_subpixel_order_t for full details. |
448 | | * |
449 | | * Since: 1.0 |
450 | | **/ |
451 | | void |
452 | | cairo_font_options_set_subpixel_order (cairo_font_options_t *options, |
453 | | cairo_subpixel_order_t subpixel_order) |
454 | 0 | { |
455 | 0 | if (cairo_font_options_status (options)) |
456 | 0 | return; |
457 | | |
458 | 0 | options->subpixel_order = subpixel_order; |
459 | 0 | } |
460 | | |
461 | | /** |
462 | | * cairo_font_options_get_subpixel_order: |
463 | | * @options: a #cairo_font_options_t |
464 | | * |
465 | | * Gets the subpixel order for the font options object. |
466 | | * See the documentation for #cairo_subpixel_order_t for full details. |
467 | | * |
468 | | * Return value: the subpixel order for the font options object |
469 | | * |
470 | | * Since: 1.0 |
471 | | **/ |
472 | | cairo_subpixel_order_t |
473 | | cairo_font_options_get_subpixel_order (const cairo_font_options_t *options) |
474 | 0 | { |
475 | 0 | if (cairo_font_options_status ((cairo_font_options_t *) options)) |
476 | 0 | return CAIRO_SUBPIXEL_ORDER_DEFAULT; |
477 | | |
478 | 0 | return options->subpixel_order; |
479 | 0 | } |
480 | | |
481 | | /** |
482 | | * _cairo_font_options_set_lcd_filter: |
483 | | * @options: a #cairo_font_options_t |
484 | | * @lcd_filter: the new LCD filter |
485 | | * |
486 | | * Sets the LCD filter for the font options object. The LCD filter |
487 | | * specifies how pixels are filtered when rendered with an antialiasing |
488 | | * mode of %CAIRO_ANTIALIAS_SUBPIXEL. See the documentation for |
489 | | * #cairo_lcd_filter_t for full details. |
490 | | **/ |
491 | | void |
492 | | _cairo_font_options_set_lcd_filter (cairo_font_options_t *options, |
493 | | cairo_lcd_filter_t lcd_filter) |
494 | 0 | { |
495 | 0 | if (cairo_font_options_status (options)) |
496 | 0 | return; |
497 | | |
498 | 0 | options->lcd_filter = lcd_filter; |
499 | 0 | } |
500 | | |
501 | | /** |
502 | | * _cairo_font_options_get_lcd_filter: |
503 | | * @options: a #cairo_font_options_t |
504 | | * |
505 | | * Gets the LCD filter for the font options object. |
506 | | * See the documentation for #cairo_lcd_filter_t for full details. |
507 | | * |
508 | | * Return value: the LCD filter for the font options object |
509 | | **/ |
510 | | cairo_lcd_filter_t |
511 | | _cairo_font_options_get_lcd_filter (const cairo_font_options_t *options) |
512 | 0 | { |
513 | 0 | if (cairo_font_options_status ((cairo_font_options_t *) options)) |
514 | 0 | return CAIRO_LCD_FILTER_DEFAULT; |
515 | | |
516 | 0 | return options->lcd_filter; |
517 | 0 | } |
518 | | |
519 | | /** |
520 | | * _cairo_font_options_set_round_glyph_positions: |
521 | | * @options: a #cairo_font_options_t |
522 | | * @round: the new rounding value |
523 | | * |
524 | | * Sets the rounding options for the font options object. If rounding is set, a |
525 | | * glyph's position will be rounded to integer values. |
526 | | **/ |
527 | | void |
528 | | _cairo_font_options_set_round_glyph_positions (cairo_font_options_t *options, |
529 | | cairo_round_glyph_positions_t round) |
530 | 75 | { |
531 | 75 | if (cairo_font_options_status (options)) |
532 | 0 | return; |
533 | | |
534 | 75 | options->round_glyph_positions = round; |
535 | 75 | } |
536 | | |
537 | | /** |
538 | | * _cairo_font_options_get_round_glyph_positions: |
539 | | * @options: a #cairo_font_options_t |
540 | | * |
541 | | * Gets the glyph position rounding option for the font options object. |
542 | | * |
543 | | * Return value: The round glyph posistions flag for the font options object. |
544 | | **/ |
545 | | cairo_round_glyph_positions_t |
546 | | _cairo_font_options_get_round_glyph_positions (const cairo_font_options_t *options) |
547 | 2.82M | { |
548 | 2.82M | if (cairo_font_options_status ((cairo_font_options_t *) options)) |
549 | 0 | return CAIRO_ROUND_GLYPH_POS_DEFAULT; |
550 | | |
551 | 2.82M | return options->round_glyph_positions; |
552 | 2.82M | } |
553 | | |
554 | | /** |
555 | | * cairo_font_options_set_hint_style: |
556 | | * @options: a #cairo_font_options_t |
557 | | * @hint_style: the new hint style |
558 | | * |
559 | | * Sets the hint style for font outlines for the font options object. |
560 | | * This controls whether to fit font outlines to the pixel grid, |
561 | | * and if so, whether to optimize for fidelity or contrast. |
562 | | * See the documentation for #cairo_hint_style_t for full details. |
563 | | * |
564 | | * Since: 1.0 |
565 | | **/ |
566 | | void |
567 | | cairo_font_options_set_hint_style (cairo_font_options_t *options, |
568 | | cairo_hint_style_t hint_style) |
569 | 5.78k | { |
570 | 5.78k | if (cairo_font_options_status (options)) |
571 | 0 | return; |
572 | | |
573 | 5.78k | options->hint_style = hint_style; |
574 | 5.78k | } |
575 | | |
576 | | /** |
577 | | * cairo_font_options_get_hint_style: |
578 | | * @options: a #cairo_font_options_t |
579 | | * |
580 | | * Gets the hint style for font outlines for the font options object. |
581 | | * See the documentation for #cairo_hint_style_t for full details. |
582 | | * |
583 | | * Return value: the hint style for the font options object |
584 | | * |
585 | | * Since: 1.0 |
586 | | **/ |
587 | | cairo_hint_style_t |
588 | | cairo_font_options_get_hint_style (const cairo_font_options_t *options) |
589 | 0 | { |
590 | 0 | if (cairo_font_options_status ((cairo_font_options_t *) options)) |
591 | 0 | return CAIRO_HINT_STYLE_DEFAULT; |
592 | | |
593 | 0 | return options->hint_style; |
594 | 0 | } |
595 | | |
596 | | /** |
597 | | * cairo_font_options_set_hint_metrics: |
598 | | * @options: a #cairo_font_options_t |
599 | | * @hint_metrics: the new metrics hinting mode |
600 | | * |
601 | | * Sets the metrics hinting mode for the font options object. This |
602 | | * controls whether metrics are quantized to integer values in |
603 | | * device units. |
604 | | * See the documentation for #cairo_hint_metrics_t for full details. |
605 | | * |
606 | | * Since: 1.0 |
607 | | **/ |
608 | | void |
609 | | cairo_font_options_set_hint_metrics (cairo_font_options_t *options, |
610 | | cairo_hint_metrics_t hint_metrics) |
611 | 5.78k | { |
612 | 5.78k | if (cairo_font_options_status (options)) |
613 | 0 | return; |
614 | | |
615 | 5.78k | options->hint_metrics = hint_metrics; |
616 | 5.78k | } |
617 | | |
618 | | /** |
619 | | * cairo_font_options_get_hint_metrics: |
620 | | * @options: a #cairo_font_options_t |
621 | | * |
622 | | * Gets the metrics hinting mode for the font options object. |
623 | | * See the documentation for #cairo_hint_metrics_t for full details. |
624 | | * |
625 | | * Return value: the metrics hinting mode for the font options object |
626 | | * |
627 | | * Since: 1.0 |
628 | | **/ |
629 | | cairo_hint_metrics_t |
630 | | cairo_font_options_get_hint_metrics (const cairo_font_options_t *options) |
631 | 0 | { |
632 | 0 | if (cairo_font_options_status ((cairo_font_options_t *) options)) |
633 | 0 | return CAIRO_HINT_METRICS_DEFAULT; |
634 | | |
635 | 0 | return options->hint_metrics; |
636 | 0 | } |
637 | | |
638 | | /** |
639 | | * cairo_font_options_set_variations: |
640 | | * @options: a #cairo_font_options_t |
641 | | * @variations: the new font variations, or %NULL |
642 | | * |
643 | | * Sets the OpenType font variations for the font options object. |
644 | | * Font variations are specified as a string with a format that |
645 | | * is similar to the CSS font-variation-settings. The string contains |
646 | | * a comma-separated list of axis assignments, which each assignment |
647 | | * consists of a 4-character axis name and a value, separated by |
648 | | * whitespace and optional equals sign. |
649 | | * |
650 | | * Examples: |
651 | | * |
652 | | * wght=200,wdth=140.5 |
653 | | * |
654 | | * wght 200 , wdth 140.5 |
655 | | * |
656 | | * Since: 1.16 |
657 | | **/ |
658 | | void |
659 | | cairo_font_options_set_variations (cairo_font_options_t *options, |
660 | | const char *variations) |
661 | 0 | { |
662 | 0 | char *tmp = variations ? strdup (variations) : NULL; |
663 | 0 | free (options->variations); |
664 | 0 | options->variations = tmp; |
665 | 0 | } |
666 | | |
667 | | /** |
668 | | * cairo_font_options_get_variations: |
669 | | * @options: a #cairo_font_options_t |
670 | | * |
671 | | * Gets the OpenType font variations for the font options object. |
672 | | * See cairo_font_options_set_variations() for details about the |
673 | | * string format. |
674 | | * |
675 | | * Return value: the font variations for the font options object. The |
676 | | * returned string belongs to the @options and must not be modified. |
677 | | * It is valid until either the font options object is destroyed or |
678 | | * the font variations in this object is modified with |
679 | | * cairo_font_options_set_variations(). |
680 | | * |
681 | | * Since: 1.16 |
682 | | **/ |
683 | | const char * |
684 | | cairo_font_options_get_variations (cairo_font_options_t *options) |
685 | 0 | { |
686 | 0 | return options->variations; |
687 | 0 | } |
688 | | |
689 | | /** |
690 | | * cairo_font_options_set_color_mode: |
691 | | * @options: a #cairo_font_options_t |
692 | | * @color_mode: the new color mode |
693 | | * |
694 | | * Sets the color mode for the font options object. This controls |
695 | | * whether color fonts are to be rendered in color or as outlines. |
696 | | * See the documentation for #cairo_color_mode_t for full details. |
697 | | * |
698 | | * Since: 1.18 |
699 | | **/ |
700 | | cairo_public void |
701 | | cairo_font_options_set_color_mode (cairo_font_options_t *options, |
702 | | cairo_color_mode_t color_mode) |
703 | 0 | { |
704 | 0 | if (cairo_font_options_status (options)) |
705 | 0 | return; |
706 | | |
707 | 0 | options->color_mode = color_mode; |
708 | 0 | } |
709 | | |
710 | | /** |
711 | | * cairo_font_options_get_color_mode: |
712 | | * @options: a #cairo_font_options_t |
713 | | * |
714 | | * Gets the color mode for the font options object. |
715 | | * See the documentation for #cairo_color_mode_t for full details. |
716 | | * |
717 | | * Return value: the color mode for the font options object |
718 | | * |
719 | | * Since: 1.18 |
720 | | **/ |
721 | | cairo_public cairo_color_mode_t |
722 | | cairo_font_options_get_color_mode (const cairo_font_options_t *options) |
723 | 0 | { |
724 | 0 | if (cairo_font_options_status ((cairo_font_options_t *) options)) |
725 | 0 | return CAIRO_COLOR_MODE_DEFAULT; |
726 | | |
727 | 0 | return options->color_mode; |
728 | 0 | } |
729 | | |
730 | | /** |
731 | | * CAIRO_COLOR_PALETTE_DEFAULT: |
732 | | * |
733 | | * The default color palette index. |
734 | | * |
735 | | * Since: 1.18 |
736 | | **/ |
737 | | |
738 | | /** |
739 | | * cairo_font_options_set_color_palette: |
740 | | * @options: a #cairo_font_options_t |
741 | | * @palette_index: the palette index in the CPAL table |
742 | | * |
743 | | * Sets the OpenType font color palette for the font options |
744 | | * object. OpenType color fonts with a CPAL table may contain multiple |
745 | | * palettes. The default color palette index is %CAIRO_COLOR_PALETTE_DEFAULT. |
746 | | * |
747 | | * If @palette_index is invalid, the default palette is used. |
748 | | * |
749 | | * Individual colors within the palette may be overriden with |
750 | | * cairo_font_options_set_custom_palette_color(). |
751 | | * |
752 | | * Since: 1.18 |
753 | | **/ |
754 | | void |
755 | | cairo_font_options_set_color_palette (cairo_font_options_t *options, |
756 | | unsigned int palette_index) |
757 | 0 | { |
758 | 0 | if (cairo_font_options_status (options)) |
759 | 0 | return; |
760 | | |
761 | 0 | options->palette_index = palette_index; |
762 | 0 | } |
763 | | |
764 | | /** |
765 | | * cairo_font_options_get_color_palette: |
766 | | * @options: a #cairo_font_options_t |
767 | | * |
768 | | * Gets the current OpenType color font palette for the font options object. |
769 | | * |
770 | | * Return value: the palette index |
771 | | * |
772 | | * Since: 1.18 |
773 | | **/ |
774 | | unsigned int |
775 | | cairo_font_options_get_color_palette (const cairo_font_options_t *options) |
776 | 0 | { |
777 | 0 | if (cairo_font_options_status ((cairo_font_options_t *) options)) |
778 | 0 | return CAIRO_COLOR_PALETTE_DEFAULT; |
779 | | |
780 | 0 | return options->palette_index; |
781 | 0 | } |
782 | | |
783 | | /** |
784 | | * cairo_font_options_set_custom_palette_color: |
785 | | * @options: a #cairo_font_options_t |
786 | | * @index: the index of the color to set |
787 | | * @red: red component of color |
788 | | * @green: green component of color |
789 | | * @blue: blue component of color |
790 | | * @alpha: alpha component of color |
791 | | * |
792 | | * Sets a custom palette color for the font options object. This |
793 | | * overrides the palette color at the specified color index. This override is |
794 | | * independent of the selected palette index and will remain in place |
795 | | * even if cairo_font_options_set_color_palette() is called to change |
796 | | * the palette index. |
797 | | * |
798 | | * It is only possible to override color indexes already in the font |
799 | | * palette. |
800 | | * |
801 | | * Since: 1.18 |
802 | | */ |
803 | | void |
804 | | cairo_font_options_set_custom_palette_color (cairo_font_options_t *options, |
805 | | unsigned int index, |
806 | | double red, double green, |
807 | | double blue, double alpha) |
808 | 0 | { |
809 | 0 | unsigned int idx; |
810 | |
|
811 | 0 | for (idx = 0; idx < options->custom_palette_size; idx++) { |
812 | 0 | if (options->custom_palette[idx].index == index) { |
813 | 0 | break; |
814 | 0 | } |
815 | 0 | } |
816 | |
|
817 | 0 | if (idx == options->custom_palette_size) { |
818 | 0 | options->custom_palette_size++; |
819 | 0 | options->custom_palette = (cairo_palette_color_t *) |
820 | 0 | _cairo_realloc_ab (options->custom_palette, |
821 | 0 | sizeof (cairo_palette_color_t), |
822 | 0 | options->custom_palette_size); |
823 | 0 | } |
824 | | |
825 | | /* beware of holes */ |
826 | 0 | memset (&options->custom_palette[idx], 0, sizeof (cairo_palette_color_t)); |
827 | |
|
828 | 0 | options->custom_palette[idx].index = index; |
829 | 0 | options->custom_palette[idx].red = red; |
830 | 0 | options->custom_palette[idx].green = green; |
831 | 0 | options->custom_palette[idx].blue = blue; |
832 | 0 | options->custom_palette[idx].alpha = alpha; |
833 | 0 | } |
834 | | |
835 | | /** |
836 | | * cairo_font_options_get_custom_palette_color: |
837 | | * @options: a #cairo_font_options_t |
838 | | * @index: the index of the color to get |
839 | | * @red: return location for red component of color |
840 | | * @green: return location for green component of color |
841 | | * @blue: return location for blue component of color |
842 | | * @alpha: return location for alpha component of color |
843 | | * |
844 | | * Gets the custom palette color for the color index for the font options object. |
845 | | * |
846 | | * Returns: `CAIRO_STATUS_SUCCESS` if a custom palette color is |
847 | | * returned, `CAIRO_STATUS_INVALID_INDEX` if no custom color exists |
848 | | * for the color index. |
849 | | * |
850 | | * Since: 1.18 |
851 | | */ |
852 | | cairo_status_t |
853 | | cairo_font_options_get_custom_palette_color (cairo_font_options_t *options, |
854 | | unsigned int index, |
855 | | double *red, double *green, |
856 | | double *blue, double *alpha) |
857 | 0 | { |
858 | 0 | unsigned int idx; |
859 | |
|
860 | 0 | for (idx = 0; idx < options->custom_palette_size; idx++) { |
861 | 0 | if (options->custom_palette[idx].index == index) { |
862 | 0 | *red = options->custom_palette[idx].red; |
863 | 0 | *green = options->custom_palette[idx].green; |
864 | 0 | *blue = options->custom_palette[idx].blue; |
865 | 0 | *alpha = options->custom_palette[idx].alpha; |
866 | 0 | return CAIRO_STATUS_SUCCESS; |
867 | 0 | } |
868 | 0 | } |
869 | | |
870 | 0 | return CAIRO_STATUS_INVALID_INDEX; |
871 | 0 | } |