[AdgFontStyle] Guarded args of adg_font_style_font()
[adg.git] / adg / adg-font-style.c
blob646b36195d23ba190a2d9c11cf8ca5e802b54090
1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2007,2008,2009 Nicola Fontana <ntd at entidi.it>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
21 /**
22 * SECTION:adg-font-style
23 * @short_description: Font style related stuff
25 * Contains parameters on how to draw texts such as font family, slanting,
26 * weight, hinting and so on.
29 /**
30 * AdgFontStyle:
32 * All fields are private and should not be used directly.
33 * Use its public methods instead.
34 **/
37 #include "adg-font-style.h"
38 #include "adg-font-style-private.h"
39 #include "adg-dress-builtins.h"
40 #include "adg-util.h"
41 #include "adg-intl.h"
43 #define PARENT_OBJECT_CLASS ((GObjectClass *) adg_font_style_parent_class)
46 enum {
47 PROP_0,
48 PROP_COLOR_DRESS,
49 PROP_FAMILY,
50 PROP_SLANT,
51 PROP_WEIGHT,
52 PROP_SIZE,
53 PROP_ANTIALIAS,
54 PROP_SUBPIXEL_ORDER,
55 PROP_HINT_STYLE,
56 PROP_HINT_METRICS
60 static void dispose (GObject *object);
61 static void get_property (GObject *object,
62 guint prop_id,
63 GValue *value,
64 GParamSpec *pspec);
65 static void set_property (GObject *object,
66 guint prop_id,
67 const GValue *value,
68 GParamSpec *pspec);
69 static void apply (AdgStyle *style,
70 AdgEntity *entity,
71 cairo_t *cr);
72 static gboolean set_family (AdgFontStyle *font_style,
73 const gchar *family);
74 static gboolean set_slant (AdgFontStyle *font_style,
75 cairo_font_slant_t slant);
76 static gboolean set_weight (AdgFontStyle *font_style,
77 cairo_font_weight_t weight);
78 static gboolean set_size (AdgFontStyle *font_style,
79 gdouble size);
80 static gboolean set_antialias (AdgFontStyle *font_style,
81 cairo_antialias_t antialias);
82 static gboolean set_subpixel_order (AdgFontStyle *font_style,
83 cairo_subpixel_order_t subpixel_order);
84 static gboolean set_hint_style (AdgFontStyle *font_style,
85 cairo_hint_style_t hint_style);
86 static gboolean set_hint_metrics (AdgFontStyle *font_style,
87 cairo_hint_metrics_t hint_metrics);
88 static void unset_face (AdgFontStyle *font_style);
89 static void unset_font (AdgFontStyle *font_style);
92 G_DEFINE_TYPE(AdgFontStyle, adg_font_style, ADG_TYPE_STYLE);
95 static void
96 adg_font_style_class_init(AdgFontStyleClass *klass)
98 GObjectClass *gobject_class;
99 AdgStyleClass *style_class;
100 GParamSpec *param;
102 gobject_class = (GObjectClass *) klass;
103 style_class = (AdgStyleClass *) klass;
105 g_type_class_add_private(klass, sizeof(AdgFontStylePrivate));
107 gobject_class->dispose = dispose;
108 gobject_class->get_property = get_property;
109 gobject_class->set_property = set_property;
111 style_class->apply = apply;
113 param = adg_param_spec_dress("color-dress",
114 P_("Color Dress"),
115 P_("The color dress to bind to this font style"),
116 ADG_DRESS_COLOR,
117 G_PARAM_READWRITE);
118 g_object_class_install_property(gobject_class, PROP_COLOR_DRESS, param);
120 param = g_param_spec_string("family",
121 P_("Font Family"),
122 P_("The font family name, encoded in UTF-8"),
123 NULL,
124 G_PARAM_READWRITE);
125 g_object_class_install_property(gobject_class, PROP_FAMILY, param);
127 param = g_param_spec_int("slant",
128 P_("Font Slant"),
129 P_("Variant of a font face based on its slant"),
130 G_MININT, G_MAXINT, CAIRO_FONT_SLANT_NORMAL,
131 G_PARAM_READWRITE);
132 g_object_class_install_property(gobject_class, PROP_SLANT, param);
134 param = g_param_spec_int("weight",
135 P_("Font Weight"),
136 P_("Variant of a font face based on its weight"),
137 G_MININT, G_MAXINT, CAIRO_FONT_WEIGHT_NORMAL,
138 G_PARAM_READWRITE);
139 g_object_class_install_property(gobject_class, PROP_WEIGHT, param);
141 param = g_param_spec_double("size",
142 P_("Font Size"),
143 P_("Font size in user space units"),
144 0, G_MAXDOUBLE, 10,
145 G_PARAM_READWRITE);
146 g_object_class_install_property(gobject_class, PROP_SIZE, param);
148 param = g_param_spec_int("antialias",
149 P_("Font Antialiasing Mode"),
150 P_("Type of antialiasing to do when rendering text"),
151 G_MININT, G_MAXINT, CAIRO_ANTIALIAS_DEFAULT,
152 G_PARAM_READWRITE);
153 g_object_class_install_property(gobject_class, PROP_ANTIALIAS, param);
155 param = g_param_spec_int("subpixel-order",
156 P_("Font Subpixel Order"),
157 P_("The order of color elements within each pixel on the display device when rendering with subpixel antialiasing mode"),
158 G_MININT, G_MAXINT,
159 CAIRO_SUBPIXEL_ORDER_DEFAULT,
160 G_PARAM_READWRITE);
161 g_object_class_install_property(gobject_class, PROP_SUBPIXEL_ORDER, param);
163 param = g_param_spec_int("hint-style",
164 P_("Type of Hinting"),
165 P_("How outlines must fit to the pixel grid in order to improve the glyph appearance"),
166 G_MININT, G_MAXINT, CAIRO_HINT_STYLE_DEFAULT,
167 G_PARAM_READWRITE);
168 g_object_class_install_property(gobject_class, PROP_HINT_STYLE, param);
170 param = g_param_spec_int("hint-metrics",
171 P_("Font Metric Hinting"),
172 P_("Whether to hint font metrics, that is align them to integer values in device space"),
173 G_MININT, G_MAXINT,
174 CAIRO_HINT_METRICS_DEFAULT,
175 G_PARAM_READWRITE);
176 g_object_class_install_property(gobject_class, PROP_HINT_METRICS, param);
179 static void
180 adg_font_style_init(AdgFontStyle *font_style)
182 AdgFontStylePrivate *data = G_TYPE_INSTANCE_GET_PRIVATE(font_style,
183 ADG_TYPE_FONT_STYLE,
184 AdgFontStylePrivate);
186 data->color_dress = ADG_DRESS_COLOR;
187 data->family = NULL;
188 data->slant = CAIRO_FONT_SLANT_NORMAL;
189 data->weight = CAIRO_FONT_WEIGHT_NORMAL;
190 data->size = 10;
191 data->antialias = CAIRO_ANTIALIAS_DEFAULT;
192 data->subpixel_order = CAIRO_SUBPIXEL_ORDER_DEFAULT;
193 data->hint_style = CAIRO_HINT_STYLE_DEFAULT;
194 data->hint_metrics = CAIRO_HINT_METRICS_DEFAULT;
195 data->font = NULL;
197 font_style->data = data;
200 static void
201 dispose(GObject *object)
203 AdgFontStyle *font_style = (AdgFontStyle *) object;
205 unset_font(font_style);
206 unset_face(font_style);
208 if (PARENT_OBJECT_CLASS->dispose != NULL)
209 PARENT_OBJECT_CLASS->dispose(object);
212 static void
213 get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
215 AdgFontStylePrivate *data = ((AdgFontStyle *) object)->data;
217 switch (prop_id) {
218 case PROP_COLOR_DRESS:
219 g_value_set_int(value, data->color_dress);
220 break;
221 case PROP_FAMILY:
222 g_value_set_string(value, data->family);
223 break;
224 case PROP_SLANT:
225 g_value_set_int(value, data->slant);
226 break;
227 case PROP_WEIGHT:
228 g_value_set_int(value, data->weight);
229 break;
230 case PROP_SIZE:
231 g_value_set_double(value, data->size);
232 break;
233 case PROP_ANTIALIAS:
234 g_value_set_int(value, data->antialias);
235 break;
236 case PROP_SUBPIXEL_ORDER:
237 g_value_set_int(value, data->subpixel_order);
238 break;
239 case PROP_HINT_STYLE:
240 g_value_set_int(value, data->hint_style);
241 break;
242 case PROP_HINT_METRICS:
243 g_value_set_int(value, data->hint_metrics);
244 break;
245 default:
246 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
247 break;
251 static void
252 set_property(GObject *object,
253 guint prop_id, const GValue *value, GParamSpec *pspec)
255 AdgFontStyle *font_style;
256 AdgFontStylePrivate *data;
258 font_style = (AdgFontStyle *) object;
259 data = font_style->data;
261 switch (prop_id) {
262 case PROP_COLOR_DRESS:
263 adg_dress_set(&data->color_dress, g_value_get_int(value));
264 break;
265 case PROP_FAMILY:
266 set_family(font_style, g_value_get_string(value));
267 break;
268 case PROP_SLANT:
269 set_slant(font_style, g_value_get_int(value));
270 break;
271 case PROP_WEIGHT:
272 set_weight(font_style, g_value_get_int(value));
273 break;
274 case PROP_SIZE:
275 set_size(font_style, g_value_get_double(value));
276 break;
277 case PROP_ANTIALIAS:
278 set_antialias(font_style, g_value_get_int(value));
279 break;
280 case PROP_SUBPIXEL_ORDER:
281 set_subpixel_order(font_style, g_value_get_int(value));
282 break;
283 case PROP_HINT_STYLE:
284 set_hint_style(font_style, g_value_get_int(value));
285 break;
286 case PROP_HINT_METRICS:
287 set_hint_metrics(font_style, g_value_get_int(value));
288 break;
289 default:
290 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
291 break;
297 * adg_font_style_new:
299 * Constructs a new font style initialized with default params.
301 * Returns: a new font style
303 AdgStyle *
304 adg_font_style_new(void)
306 return g_object_new(ADG_TYPE_FONT_STYLE, NULL);
310 * adg_font_style_font:
311 * @font_style: an #AdgFontStyle object
312 * @ctm: the current transformation matrix
314 * Gets the scaled font of @font_style. The returned font is
315 * owned by @font_style and must not be destroyed by the caller.
317 * Returns: the scaled font
319 cairo_scaled_font_t *
320 adg_font_style_font(AdgFontStyle *font_style, const AdgMatrix *ctm)
322 AdgFontStylePrivate *data;
323 cairo_font_options_t *options;
324 AdgMatrix matrix;
326 g_return_val_if_fail(ADG_IS_FONT_STYLE(font_style), NULL);
327 g_return_val_if_fail(ctm != NULL, NULL);
329 data = font_style->data;
331 /* Check for cached font */
332 if (data->font != NULL) {
333 AdgMatrix font_ctm;
335 cairo_scaled_font_get_ctm(data->font, &font_ctm);
337 /* The scaled font is valid only if the two ctm match */
338 if (ctm->xx == font_ctm.xx && ctm->yy == font_ctm.yy &&
339 ctm->xy == font_ctm.xy && ctm->yx == font_ctm.yx)
340 return data->font;
342 /* No valid cache found: rebuild the scaled font */
343 unset_font(font_style);
346 if (data->face == NULL) {
347 const gchar *family = data->family != NULL ? data->family : "";
349 data->face = cairo_toy_font_face_create(family, data->slant,
350 data->weight);
353 cairo_matrix_init_scale(&matrix, data->size, data->size);
354 options = cairo_font_options_create();
356 cairo_font_options_set_antialias(options, data->antialias);
357 cairo_font_options_set_subpixel_order(options, data->subpixel_order);
358 cairo_font_options_set_hint_style(options, data->hint_style);
359 cairo_font_options_set_hint_metrics(options, data->hint_metrics);
361 data->font = cairo_scaled_font_create(data->face, &matrix, ctm, options);
363 cairo_font_options_destroy(options);
365 return data->font;
369 * adg_font_style_get_color_dress:
370 * @font_style: an #AdgFontStyle
372 * Gets the color dress used by @font_style.
374 * Returns: the current color dress
376 AdgDress
377 adg_font_style_get_color_dress(AdgFontStyle *font_style)
379 AdgFontStylePrivate *data;
381 g_return_val_if_fail(ADG_IS_FONT_STYLE(font_style), ADG_DRESS_UNDEFINED);
383 data = font_style->data;
385 return data->color_dress;
389 * adg_font_style_set_color_dress:
390 * @font_style: an #AdgFontStyle
391 * @dress: the new color dress to use
393 * Sets a new color dress on @font_style. The new dress
394 * should be related to the original dress: you cannot
395 * set a dress used for font styles to a dress managing
396 * fonts.
398 * The validation of the new dress is done by calling
399 * adg_dress_are_related() with @dress and the previous
400 * dress as arguments: check out its documentation for
401 * details on what is a related dress.
403 void
404 adg_font_style_set_color_dress(AdgFontStyle *font_style, AdgDress dress)
406 AdgFontStylePrivate *data;
408 g_return_if_fail(ADG_IS_FONT_STYLE(font_style));
410 data = font_style->data;
412 if (adg_dress_set(&data->color_dress, dress))
413 g_object_notify((GObject *) font_style, "color-dress");
417 * adg_font_style_get_family:
418 * @font_style: an #AdgFontStyle object
420 * Gets the family of @font_style. The returned pointer refers to
421 * internally managed text that must not be modified or freed.
423 * Returns: the requested family
425 const gchar *
426 adg_font_style_get_family(AdgFontStyle *font_style)
428 AdgFontStylePrivate *data;
430 g_return_val_if_fail(ADG_IS_FONT_STYLE(font_style), NULL);
432 data = font_style->data;
434 return data->family;
438 * adg_font_style_set_family:
439 * @font_style: an #AdgFontStyle object
440 * @family: the new family
442 * Sets a new family.
444 void
445 adg_font_style_set_family(AdgFontStyle *font_style, const gchar *family)
447 g_return_if_fail(ADG_IS_FONT_STYLE(font_style));
449 if (set_family(font_style, family))
450 g_object_notify((GObject *) font_style, "family");
454 * adg_font_style_get_slant:
455 * @font_style: an #AdgFontStyle object
457 * Gets the slant variant of @font_style.
459 * Returns: the slant variant
461 cairo_font_slant_t
462 adg_font_style_get_slant(AdgFontStyle *font_style)
464 AdgFontStylePrivate *data;
466 g_return_val_if_fail(ADG_IS_FONT_STYLE(font_style),
467 CAIRO_FONT_SLANT_NORMAL);
469 data = font_style->data;
471 return data->slant;
475 * adg_font_style_set_slant:
476 * @font_style: an #AdgFontStyle object
477 * @slant: the new slant
479 * Sets a new slant variant on @font_style.
481 void
482 adg_font_style_set_slant(AdgFontStyle *font_style,
483 cairo_font_slant_t slant)
485 g_return_if_fail(ADG_IS_FONT_STYLE(font_style));
487 if (set_slant(font_style, slant))
488 g_object_notify((GObject *) font_style, "slant");
492 * adg_font_style_get_weight:
493 * @font_style: an #AdgFontStyle object
495 * Gets the weight variant of @font_style.
497 * Returns: the weight variant
499 cairo_font_weight_t
500 adg_font_style_get_weight(AdgFontStyle *font_style)
502 AdgFontStylePrivate *data;
504 g_return_val_if_fail(ADG_IS_FONT_STYLE(font_style),
505 CAIRO_FONT_WEIGHT_NORMAL);
507 data = font_style->data;
509 return data->weight;
513 * adg_font_style_set_weight:
514 * @font_style: an #AdgFontStyle object
515 * @weight: the new weight
517 * Sets a new weight variant on @font_style.
519 void
520 adg_font_style_set_weight(AdgFontStyle *font_style,
521 cairo_font_weight_t weight)
523 g_return_if_fail(ADG_IS_FONT_STYLE(font_style));
525 if (set_weight(font_style, weight))
526 g_object_notify((GObject *) font_style, "weight");
530 * adg_font_style_get_size:
531 * @font_style: an #AdgFontStyle object
533 * Gets the size (in global space) of @font_style.
535 * Returns: the size variant
537 gdouble
538 adg_font_style_get_size(AdgFontStyle *font_style)
540 AdgFontStylePrivate *data;
542 g_return_val_if_fail(ADG_IS_FONT_STYLE(font_style), 0.);
544 data = font_style->data;
546 return data->size;
550 * adg_font_style_set_size:
551 * @font_style: an #AdgFontStyle object
552 * @size: the new size
554 * Sets a new size (in global space) on @font_style.
556 void
557 adg_font_style_set_size(AdgFontStyle *font_style, gdouble size)
559 g_return_if_fail(ADG_IS_FONT_STYLE(font_style));
561 if (set_size(font_style, size))
562 g_object_notify((GObject *) font_style, "size");
566 * adg_font_style_get_antialias:
567 * @font_style: an #AdgFontStyle object
569 * Gets the antialias mode used.
571 * Returns: the requested antialias mode
573 cairo_antialias_t
574 adg_font_style_get_antialias(AdgFontStyle *font_style)
576 AdgFontStylePrivate *data;
578 g_return_val_if_fail(ADG_IS_FONT_STYLE(font_style),
579 CAIRO_ANTIALIAS_DEFAULT);
581 data = font_style->data;
583 return data->antialias;
587 * adg_font_style_set_antialias:
588 * @font_style: an #AdgFontStyle object
589 * @antialias: the new antialias mode
591 * Sets a new antialias mode.
593 void
594 adg_font_style_set_antialias(AdgFontStyle *font_style,
595 cairo_antialias_t antialias)
597 g_return_if_fail(ADG_IS_FONT_STYLE(font_style));
599 if (set_antialias(font_style, antialias))
600 g_object_notify((GObject *) font_style, "antialias");
604 * adg_font_style_get_subpixel_order:
605 * @font_style: an #AdgFontStyle object
607 * Gets the subpixel order mode used, that is the order of color elements
608 * within each pixel on the display device when rendering with an
609 * antialiasing mode of %CAIRO_ANTIALIAS_SUBPIXEL.
611 * Returns: the requested subpixel order mode
613 cairo_subpixel_order_t
614 adg_font_style_get_subpixel_order(AdgFontStyle *font_style)
616 AdgFontStylePrivate *data;
618 g_return_val_if_fail(ADG_IS_FONT_STYLE(font_style),
619 CAIRO_SUBPIXEL_ORDER_DEFAULT);
621 data = font_style->data;
623 return data->subpixel_order;
627 * adg_font_style_set_subpixel_order:
628 * @font_style: an #AdgFontStyle object
629 * @subpixel_order: the new subpixel order mode
631 * Sets a new subpixel order mode.
633 void
634 adg_font_style_set_subpixel_order(AdgFontStyle *font_style,
635 cairo_subpixel_order_t subpixel_order)
637 g_return_if_fail(ADG_IS_FONT_STYLE(font_style));
639 if (set_subpixel_order(font_style, subpixel_order))
640 g_object_notify((GObject *) font_style, "subpixel-order");
644 * adg_font_style_get_hint_style:
645 * @font_style: an #AdgFontStyle object
647 * Gets the hint style mode used, that is how to fit outlines
648 * to the pixel grid in order to improve the appearance of the result.
650 * Returns: the requested hint style mode
652 cairo_hint_style_t
653 adg_font_style_get_hint_style(AdgFontStyle *font_style)
655 AdgFontStylePrivate *data;
657 g_return_val_if_fail(ADG_IS_FONT_STYLE(font_style),
658 CAIRO_HINT_STYLE_DEFAULT);
660 data = font_style->data;
662 return data->hint_style;
666 * adg_font_style_set_hint_style:
667 * @font_style: an #AdgFontStyle object
668 * @hint_style: the new hint style mode
670 * Sets a new hint style mode.
672 void
673 adg_font_style_set_hint_style(AdgFontStyle *font_style,
674 cairo_hint_style_t hint_style)
676 g_return_if_fail(ADG_IS_FONT_STYLE(font_style));
678 if (set_hint_style(font_style, hint_style))
679 g_object_notify((GObject *) font_style, "hint-style");
683 * adg_font_style_get_hint_metrics:
684 * @font_style: an #AdgFontStyle object
686 * Gets the state on whether to hint font metrics.
688 * Returns: the requested hint metrics state
690 cairo_hint_metrics_t
691 adg_font_style_get_hint_metrics(AdgFontStyle *font_style)
693 AdgFontStylePrivate *data;
695 g_return_val_if_fail(ADG_IS_FONT_STYLE(font_style),
696 CAIRO_HINT_METRICS_DEFAULT);
698 data = font_style->data;
700 return data->hint_metrics;
704 * adg_font_style_set_hint_metrics:
705 * @font_style: an #AdgFontStyle object
706 * @hint_metrics: the new hint metrics state
708 * Sets a new hint metrics state.
710 void
711 adg_font_style_set_hint_metrics(AdgFontStyle *font_style,
712 cairo_hint_metrics_t hint_metrics)
714 g_return_if_fail(ADG_IS_FONT_STYLE(font_style));
716 if (set_hint_metrics(font_style, hint_metrics))
717 g_object_notify((GObject *) font_style, "hint-metrics");
721 static void
722 apply(AdgStyle *style, AdgEntity *entity, cairo_t *cr)
724 AdgFontStyle *font_style;
725 AdgFontStylePrivate *data;
726 AdgMatrix ctm;
727 cairo_scaled_font_t *font;
729 font_style = (AdgFontStyle *) style;
730 data = font_style->data;
732 adg_entity_apply_dress(entity, data->color_dress, cr);
734 cairo_get_matrix(cr, &ctm);
735 font = adg_font_style_font((AdgFontStyle *) style, &ctm);
737 cairo_set_scaled_font(cr, font);
740 static gboolean
741 set_family(AdgFontStyle *font_style, const gchar *family)
743 AdgFontStylePrivate *data = font_style->data;
745 if (adg_strcmp(family, data->family) == 0)
746 return FALSE;
748 g_free(data->family);
749 data->family = g_strdup(family);
750 unset_face(font_style);
752 return TRUE;
755 static gboolean
756 set_slant(AdgFontStyle *font_style, cairo_font_slant_t slant)
758 AdgFontStylePrivate *data = font_style->data;
760 if (slant == data->slant)
761 return FALSE;
763 data->slant = slant;
764 unset_face(font_style);
766 return TRUE;
769 static gboolean
770 set_weight(AdgFontStyle *font_style, cairo_font_weight_t weight)
772 AdgFontStylePrivate *data = font_style->data;
774 if (weight == data->weight)
775 return FALSE;
777 data->weight = weight;
778 unset_face(font_style);
780 return TRUE;
783 static gboolean
784 set_size(AdgFontStyle *font_style, gdouble size)
786 AdgFontStylePrivate *data = font_style->data;
788 if (size == data->size)
789 return FALSE;
791 data->size = size;
792 unset_font(font_style);
794 return TRUE;
797 static gboolean
798 set_antialias(AdgFontStyle *font_style, cairo_antialias_t antialias)
800 AdgFontStylePrivate *data = font_style->data;
802 if (antialias == data->antialias)
803 return FALSE;
805 data->antialias = antialias;
806 unset_font(font_style);
808 return TRUE;
811 static gboolean
812 set_subpixel_order(AdgFontStyle *font_style,
813 cairo_subpixel_order_t subpixel_order)
815 AdgFontStylePrivate *data = font_style->data;
817 if (subpixel_order == data->subpixel_order)
818 return FALSE;
820 data->subpixel_order = subpixel_order;
821 unset_font(font_style);
823 return TRUE;
826 static gboolean
827 set_hint_style(AdgFontStyle *font_style, cairo_hint_style_t hint_style)
829 AdgFontStylePrivate *data = font_style->data;
831 if (hint_style == data->hint_style)
832 return FALSE;
834 data->hint_style = hint_style;
835 unset_font(font_style);
837 return TRUE;
840 static gboolean
841 set_hint_metrics(AdgFontStyle *font_style, cairo_hint_metrics_t hint_metrics)
843 AdgFontStylePrivate *data = font_style->data;
845 if (hint_metrics == data->hint_metrics)
846 return FALSE;
848 data->hint_metrics = hint_metrics;
849 unset_font(font_style);
851 return TRUE;
854 static void
855 unset_face(AdgFontStyle *font_style)
857 AdgFontStylePrivate *data = font_style->data;
859 if (data->face == NULL)
860 return;
862 /* Changing the face invalidates the scaled font too */
863 unset_font(font_style);
865 cairo_font_face_destroy(data->face);
866 data->face = NULL;
869 static void
870 unset_font(AdgFontStyle *font_style)
872 AdgFontStylePrivate *data = font_style->data;
874 if (data->font == NULL)
875 return;
877 cairo_scaled_font_destroy(data->font);
878 data->font = NULL;