1 /* cairo - a vector graphics library with display and print output
3 * Copyright © 2005 Red Hat Inc.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 * You should have received a copy of the MPL along with this library
17 * in the file COPYING-MPL-1.1
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/
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.
28 * The Original Code is the cairo graphics library.
30 * The Initial Developer of the Original Code is University of Southern
34 * Owen Taylor <otaylor@redhat.com>
39 static const cairo_font_options_t _cairo_font_options_nil
= {
40 CAIRO_ANTIALIAS_DEFAULT
,
41 CAIRO_SUBPIXEL_ORDER_DEFAULT
,
42 CAIRO_HINT_STYLE_DEFAULT
,
43 CAIRO_HINT_METRICS_DEFAULT
47 * _cairo_font_options_init_default:
48 * @options: a #cairo_font_options_t
50 * Initializes all fields of the font options object to default values.
53 _cairo_font_options_init_default (cairo_font_options_t
*options
)
55 options
->antialias
= CAIRO_ANTIALIAS_DEFAULT
;
56 options
->subpixel_order
= CAIRO_SUBPIXEL_ORDER_DEFAULT
;
57 options
->hint_style
= CAIRO_HINT_STYLE_DEFAULT
;
58 options
->hint_metrics
= CAIRO_HINT_METRICS_DEFAULT
;
62 _cairo_font_options_init_copy (cairo_font_options_t
*options
,
63 const cairo_font_options_t
*other
)
65 options
->antialias
= other
->antialias
;
66 options
->subpixel_order
= other
->subpixel_order
;
67 options
->hint_style
= other
->hint_style
;
68 options
->hint_metrics
= other
->hint_metrics
;
72 * cairo_font_options_create:
74 * Allocates a new font options object with all options initialized
77 * Return value: a newly allocated #cairo_font_options_t. Free with
78 * cairo_font_options_destroy(). This function always returns a
79 * valid pointer; if memory cannot be allocated, then a special
80 * error object is returned where all operations on the object do nothing.
81 * You can check for this with cairo_font_options_status().
83 cairo_font_options_t
*
84 cairo_font_options_create (void)
86 cairo_font_options_t
*options
;
88 options
= malloc (sizeof (cairo_font_options_t
));
90 _cairo_error_throw (CAIRO_STATUS_NO_MEMORY
);
91 return (cairo_font_options_t
*) &_cairo_font_options_nil
;
94 _cairo_font_options_init_default (options
);
100 * cairo_font_options_copy:
101 * @original: a #cairo_font_options_t
103 * Allocates a new font options object copying the option values from
106 * Return value: a newly allocated #cairo_font_options_t. Free with
107 * cairo_font_options_destroy(). This function always returns a
108 * valid pointer; if memory cannot be allocated, then a special
109 * error object is returned where all operations on the object do nothing.
110 * You can check for this with cairo_font_options_status().
112 cairo_font_options_t
*
113 cairo_font_options_copy (const cairo_font_options_t
*original
)
115 cairo_font_options_t
*options
;
117 if (cairo_font_options_status ((cairo_font_options_t
*) original
))
118 return (cairo_font_options_t
*) &_cairo_font_options_nil
;
120 options
= malloc (sizeof (cairo_font_options_t
));
122 _cairo_error_throw (CAIRO_STATUS_NO_MEMORY
);
123 return (cairo_font_options_t
*) &_cairo_font_options_nil
;
126 _cairo_font_options_init_copy (options
, original
);
132 * cairo_font_options_destroy:
133 * @options: a #cairo_font_options_t
135 * Destroys a #cairo_font_options_t object created with
136 * cairo_font_options_create() or cairo_font_options_copy().
139 cairo_font_options_destroy (cairo_font_options_t
*options
)
141 if (cairo_font_options_status (options
))
148 * cairo_font_options_status:
149 * @options: a #cairo_font_options_t
151 * Checks whether an error has previously occurred for this
152 * font options object
154 * Return value: %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY
157 cairo_font_options_status (cairo_font_options_t
*options
)
160 return CAIRO_STATUS_NULL_POINTER
;
161 else if (options
== (cairo_font_options_t
*) &_cairo_font_options_nil
)
162 return CAIRO_STATUS_NO_MEMORY
;
164 return CAIRO_STATUS_SUCCESS
;
166 slim_hidden_def (cairo_font_options_status
);
169 * cairo_font_options_merge:
170 * @options: a #cairo_font_options_t
171 * @other: another #cairo_font_options_t
173 * Merges non-default options from @other into @options, replacing
174 * existing values. This operation can be thought of as somewhat
175 * similar to compositing @other onto @options with the operation
176 * of %CAIRO_OPERATION_OVER.
179 cairo_font_options_merge (cairo_font_options_t
*options
,
180 const cairo_font_options_t
*other
)
182 if (cairo_font_options_status (options
))
185 if (cairo_font_options_status ((cairo_font_options_t
*) other
))
188 if (other
->antialias
!= CAIRO_ANTIALIAS_DEFAULT
)
189 options
->antialias
= other
->antialias
;
190 if (other
->subpixel_order
!= CAIRO_SUBPIXEL_ORDER_DEFAULT
)
191 options
->subpixel_order
= other
->subpixel_order
;
192 if (other
->hint_style
!= CAIRO_HINT_STYLE_DEFAULT
)
193 options
->hint_style
= other
->hint_style
;
194 if (other
->hint_metrics
!= CAIRO_HINT_METRICS_DEFAULT
)
195 options
->hint_metrics
= other
->hint_metrics
;
197 slim_hidden_def (cairo_font_options_merge
);
200 * cairo_font_options_equal:
201 * @options: a #cairo_font_options_t
202 * @other: another #cairo_font_options_t
204 * Compares two font options objects for equality.
206 * Return value: %TRUE if all fields of the two font options objects match.
207 * Note that this function will return %FALSE if either object is in
211 cairo_font_options_equal (const cairo_font_options_t
*options
,
212 const cairo_font_options_t
*other
)
214 if (cairo_font_options_status ((cairo_font_options_t
*) options
))
216 if (cairo_font_options_status ((cairo_font_options_t
*) other
))
219 if (options
== other
)
222 return (options
->antialias
== other
->antialias
&&
223 options
->subpixel_order
== other
->subpixel_order
&&
224 options
->hint_style
== other
->hint_style
&&
225 options
->hint_metrics
== other
->hint_metrics
);
227 slim_hidden_def (cairo_font_options_equal
);
230 * cairo_font_options_hash:
231 * @options: a #cairo_font_options_t
233 * Compute a hash for the font options object; this value will
234 * be useful when storing an object containing a #cairo_font_options_t
237 * Return value: the hash value for the font options object.
238 * The return value can be cast to a 32-bit type if a
239 * 32-bit hash value is needed.
242 cairo_font_options_hash (const cairo_font_options_t
*options
)
244 if (cairo_font_options_status ((cairo_font_options_t
*) options
))
245 options
= &_cairo_font_options_nil
; /* force default values */
247 return ((options
->antialias
) |
248 (options
->subpixel_order
<< 4) |
249 (options
->hint_style
<< 8) |
250 (options
->hint_metrics
<< 16));
252 slim_hidden_def (cairo_font_options_hash
);
255 * cairo_font_options_set_antialias:
256 * @options: a #cairo_font_options_t
257 * @antialias: the new antialiasing mode
259 * Sets the antialiasing mode for the font options object. This
260 * specifies the type of antialiasing to do when rendering text.
263 cairo_font_options_set_antialias (cairo_font_options_t
*options
,
264 cairo_antialias_t antialias
)
266 if (cairo_font_options_status (options
))
269 options
->antialias
= antialias
;
271 slim_hidden_def (cairo_font_options_set_antialias
);
274 * cairo_font_options_get_antialias:
275 * @options: a #cairo_font_options_t
277 * Gets the antialiasing mode for the font options object.
279 * Return value: the antialiasing mode
282 cairo_font_options_get_antialias (const cairo_font_options_t
*options
)
284 if (cairo_font_options_status ((cairo_font_options_t
*) options
))
285 return CAIRO_ANTIALIAS_DEFAULT
;
287 return options
->antialias
;
291 * cairo_font_options_set_subpixel_order:
292 * @options: a #cairo_font_options_t
293 * @subpixel_order: the new subpixel order
295 * Sets the subpixel order for the font options object. The subpixel
296 * order specifies the order of color elements within each pixel on
297 * the display device when rendering with an antialiasing mode of
298 * %CAIRO_ANTIALIAS_SUBPIXEL. See the documentation for
299 * #cairo_subpixel_order_t for full details.
302 cairo_font_options_set_subpixel_order (cairo_font_options_t
*options
,
303 cairo_subpixel_order_t subpixel_order
)
305 if (cairo_font_options_status (options
))
308 options
->subpixel_order
= subpixel_order
;
310 slim_hidden_def (cairo_font_options_set_subpixel_order
);
313 * cairo_font_options_get_subpixel_order:
314 * @options: a #cairo_font_options_t
316 * Gets the subpixel order for the font options object.
317 * See the documentation for #cairo_subpixel_order_t for full details.
319 * Return value: the subpixel order for the font options object
321 cairo_subpixel_order_t
322 cairo_font_options_get_subpixel_order (const cairo_font_options_t
*options
)
324 if (cairo_font_options_status ((cairo_font_options_t
*) options
))
325 return CAIRO_SUBPIXEL_ORDER_DEFAULT
;
327 return options
->subpixel_order
;
331 * cairo_font_options_set_hint_style:
332 * @options: a #cairo_font_options_t
333 * @hint_style: the new hint style
335 * Sets the hint style for font outlines for the font options object.
336 * This controls whether to fit font outlines to the pixel grid,
337 * and if so, whether to optimize for fidelity or contrast.
338 * See the documentation for #cairo_hint_style_t for full details.
341 cairo_font_options_set_hint_style (cairo_font_options_t
*options
,
342 cairo_hint_style_t hint_style
)
344 if (cairo_font_options_status (options
))
347 options
->hint_style
= hint_style
;
349 slim_hidden_def (cairo_font_options_set_hint_style
);
352 * cairo_font_options_get_hint_style:
353 * @options: a #cairo_font_options_t
355 * Gets the hint style for font outlines for the font options object.
356 * See the documentation for #cairo_hint_style_t for full details.
358 * Return value: the hint style for the font options object
361 cairo_font_options_get_hint_style (const cairo_font_options_t
*options
)
363 if (cairo_font_options_status ((cairo_font_options_t
*) options
))
364 return CAIRO_HINT_STYLE_DEFAULT
;
366 return options
->hint_style
;
370 * cairo_font_options_set_hint_metrics:
371 * @options: a #cairo_font_options_t
372 * @hint_metrics: the new metrics hinting mode
374 * Sets the metrics hinting mode for the font options object. This
375 * controls whether metrics are quantized to integer values in
377 * See the documentation for #cairo_hint_metrics_t for full details.
380 cairo_font_options_set_hint_metrics (cairo_font_options_t
*options
,
381 cairo_hint_metrics_t hint_metrics
)
383 if (cairo_font_options_status (options
))
386 options
->hint_metrics
= hint_metrics
;
388 slim_hidden_def (cairo_font_options_set_hint_metrics
);
391 * cairo_font_options_get_hint_metrics:
392 * @options: a #cairo_font_options_t
394 * Gets the metrics hinting mode for the font options object.
395 * See the documentation for #cairo_hint_metrics_t for full details.
397 * Return value: the metrics hinting mode for the font options object
400 cairo_font_options_get_hint_metrics (const cairo_font_options_t
*options
)
402 if (cairo_font_options_status ((cairo_font_options_t
*) options
))
403 return CAIRO_HINT_METRICS_DEFAULT
;
405 return options
->hint_metrics
;