[build] Bumped version to 0.5.3
[adg.git] / adg / adg-font-style.c
blobc94f2952654a4f4eede29f85fd118734ed0da72c
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
313 * Gets the scaled font of @font_style. The returned font is
314 * owned by @font_style and must not be destroyed by the caller.
316 * Returns: the scaled font
318 cairo_scaled_font_t *
319 adg_font_style_font(AdgFontStyle *font_style, const AdgMatrix *ctm)
321 AdgFontStylePrivate *data;
322 cairo_font_options_t *options;
323 AdgMatrix matrix;
325 data = font_style->data;
327 /* Check for cached font */
328 if (data->font != NULL) {
329 AdgMatrix font_ctm;
331 cairo_scaled_font_get_ctm(data->font, &font_ctm);
333 /* The scaled font is valid only if the two ctm match */
334 if (ctm->xx == font_ctm.xx && ctm->yy == font_ctm.yy &&
335 ctm->xy == font_ctm.xy && ctm->yx == font_ctm.yx)
336 return data->font;
338 /* No valid cache found: rebuild the scaled font */
339 unset_font(font_style);
342 if (data->face == NULL) {
343 const gchar *family = data->family != NULL ? data->family : "";
345 data->face = cairo_toy_font_face_create(family, data->slant,
346 data->weight);
349 cairo_matrix_init_scale(&matrix, data->size, data->size);
350 options = cairo_font_options_create();
352 cairo_font_options_set_antialias(options, data->antialias);
353 cairo_font_options_set_subpixel_order(options, data->subpixel_order);
354 cairo_font_options_set_hint_style(options, data->hint_style);
355 cairo_font_options_set_hint_metrics(options, data->hint_metrics);
357 data->font = cairo_scaled_font_create(data->face, &matrix, ctm, options);
359 cairo_font_options_destroy(options);
361 return data->font;
365 * adg_font_style_get_color_dress:
366 * @font_style: an #AdgFontStyle
368 * Gets the color dress used by @font_style.
370 * Returns: the current color dress
372 AdgDress
373 adg_font_style_get_color_dress(AdgFontStyle *font_style)
375 AdgFontStylePrivate *data;
377 g_return_val_if_fail(ADG_IS_FONT_STYLE(font_style), ADG_DRESS_UNDEFINED);
379 data = font_style->data;
381 return data->color_dress;
385 * adg_font_style_set_color_dress:
386 * @font_style: an #AdgFontStyle
387 * @dress: the new color dress to use
389 * Sets a new color dress on @font_style. The new dress
390 * should be related to the original dress: you cannot
391 * set a dress used for font styles to a dress managing
392 * fonts.
394 * The validation of the new dress is done by calling
395 * adg_dress_are_related() with @dress and the previous
396 * dress as arguments: check out its documentation for
397 * details on what is a related dress.
399 void
400 adg_font_style_set_color_dress(AdgFontStyle *font_style, AdgDress dress)
402 AdgFontStylePrivate *data;
404 g_return_if_fail(ADG_IS_FONT_STYLE(font_style));
406 data = font_style->data;
408 if (adg_dress_set(&data->color_dress, dress))
409 g_object_notify((GObject *) font_style, "color-dress");
413 * adg_font_style_get_family:
414 * @font_style: an #AdgFontStyle object
416 * Gets the family of @font_style. The returned pointer refers to
417 * internally managed text that must not be modified or freed.
419 * Returns: the requested family
421 const gchar *
422 adg_font_style_get_family(AdgFontStyle *font_style)
424 AdgFontStylePrivate *data;
426 g_return_val_if_fail(ADG_IS_FONT_STYLE(font_style), NULL);
428 data = font_style->data;
430 return data->family;
434 * adg_font_style_set_family:
435 * @font_style: an #AdgFontStyle object
436 * @family: the new family
438 * Sets a new family.
440 void
441 adg_font_style_set_family(AdgFontStyle *font_style, const gchar *family)
443 g_return_if_fail(ADG_IS_FONT_STYLE(font_style));
445 if (set_family(font_style, family))
446 g_object_notify((GObject *) font_style, "family");
450 * adg_font_style_get_slant:
451 * @font_style: an #AdgFontStyle object
453 * Gets the slant variant of @font_style.
455 * Returns: the slant variant
457 cairo_font_slant_t
458 adg_font_style_get_slant(AdgFontStyle *font_style)
460 AdgFontStylePrivate *data;
462 g_return_val_if_fail(ADG_IS_FONT_STYLE(font_style),
463 CAIRO_FONT_SLANT_NORMAL);
465 data = font_style->data;
467 return data->slant;
471 * adg_font_style_set_slant:
472 * @font_style: an #AdgFontStyle object
473 * @slant: the new slant
475 * Sets a new slant variant on @font_style.
477 void
478 adg_font_style_set_slant(AdgFontStyle *font_style,
479 cairo_font_slant_t slant)
481 g_return_if_fail(ADG_IS_FONT_STYLE(font_style));
483 if (set_slant(font_style, slant))
484 g_object_notify((GObject *) font_style, "slant");
488 * adg_font_style_get_weight:
489 * @font_style: an #AdgFontStyle object
491 * Gets the weight variant of @font_style.
493 * Returns: the weight variant
495 cairo_font_weight_t
496 adg_font_style_get_weight(AdgFontStyle *font_style)
498 AdgFontStylePrivate *data;
500 g_return_val_if_fail(ADG_IS_FONT_STYLE(font_style),
501 CAIRO_FONT_WEIGHT_NORMAL);
503 data = font_style->data;
505 return data->weight;
509 * adg_font_style_set_weight:
510 * @font_style: an #AdgFontStyle object
511 * @weight: the new weight
513 * Sets a new weight variant on @font_style.
515 void
516 adg_font_style_set_weight(AdgFontStyle *font_style,
517 cairo_font_weight_t weight)
519 g_return_if_fail(ADG_IS_FONT_STYLE(font_style));
521 if (set_weight(font_style, weight))
522 g_object_notify((GObject *) font_style, "weight");
526 * adg_font_style_get_size:
527 * @font_style: an #AdgFontStyle object
529 * Gets the size (in global space) of @font_style.
531 * Returns: the size variant
533 gdouble
534 adg_font_style_get_size(AdgFontStyle *font_style)
536 AdgFontStylePrivate *data;
538 g_return_val_if_fail(ADG_IS_FONT_STYLE(font_style), 0.);
540 data = font_style->data;
542 return data->size;
546 * adg_font_style_set_size:
547 * @font_style: an #AdgFontStyle object
548 * @size: the new size
550 * Sets a new size (in global space) on @font_style.
552 void
553 adg_font_style_set_size(AdgFontStyle *font_style, gdouble size)
555 g_return_if_fail(ADG_IS_FONT_STYLE(font_style));
557 if (set_size(font_style, size))
558 g_object_notify((GObject *) font_style, "size");
562 * adg_font_style_get_antialias:
563 * @font_style: an #AdgFontStyle object
565 * Gets the antialias mode used.
567 * Returns: the requested antialias mode
569 cairo_antialias_t
570 adg_font_style_get_antialias(AdgFontStyle *font_style)
572 AdgFontStylePrivate *data;
574 g_return_val_if_fail(ADG_IS_FONT_STYLE(font_style),
575 CAIRO_ANTIALIAS_DEFAULT);
577 data = font_style->data;
579 return data->antialias;
583 * adg_font_style_set_antialias:
584 * @font_style: an #AdgFontStyle object
585 * @antialias: the new antialias mode
587 * Sets a new antialias mode.
589 void
590 adg_font_style_set_antialias(AdgFontStyle *font_style,
591 cairo_antialias_t antialias)
593 g_return_if_fail(ADG_IS_FONT_STYLE(font_style));
595 if (set_antialias(font_style, antialias))
596 g_object_notify((GObject *) font_style, "antialias");
600 * adg_font_style_get_subpixel_order:
601 * @font_style: an #AdgFontStyle object
603 * Gets the subpixel order mode used, that is the order of color elements
604 * within each pixel on the display device when rendering with an
605 * antialiasing mode of %CAIRO_ANTIALIAS_SUBPIXEL.
607 * Returns: the requested subpixel order mode
609 cairo_subpixel_order_t
610 adg_font_style_get_subpixel_order(AdgFontStyle *font_style)
612 AdgFontStylePrivate *data;
614 g_return_val_if_fail(ADG_IS_FONT_STYLE(font_style),
615 CAIRO_SUBPIXEL_ORDER_DEFAULT);
617 data = font_style->data;
619 return data->subpixel_order;
623 * adg_font_style_set_subpixel_order:
624 * @font_style: an #AdgFontStyle object
625 * @subpixel_order: the new subpixel order mode
627 * Sets a new subpixel order mode.
629 void
630 adg_font_style_set_subpixel_order(AdgFontStyle *font_style,
631 cairo_subpixel_order_t subpixel_order)
633 g_return_if_fail(ADG_IS_FONT_STYLE(font_style));
635 if (set_subpixel_order(font_style, subpixel_order))
636 g_object_notify((GObject *) font_style, "subpixel-order");
640 * adg_font_style_get_hint_style:
641 * @font_style: an #AdgFontStyle object
643 * Gets the hint style mode used, that is how to fit outlines
644 * to the pixel grid in order to improve the appearance of the result.
646 * Returns: the requested hint style mode
648 cairo_hint_style_t
649 adg_font_style_get_hint_style(AdgFontStyle *font_style)
651 AdgFontStylePrivate *data;
653 g_return_val_if_fail(ADG_IS_FONT_STYLE(font_style),
654 CAIRO_HINT_STYLE_DEFAULT);
656 data = font_style->data;
658 return data->hint_style;
662 * adg_font_style_set_hint_style:
663 * @font_style: an #AdgFontStyle object
664 * @hint_style: the new hint style mode
666 * Sets a new hint style mode.
668 void
669 adg_font_style_set_hint_style(AdgFontStyle *font_style,
670 cairo_hint_style_t hint_style)
672 g_return_if_fail(ADG_IS_FONT_STYLE(font_style));
674 if (set_hint_style(font_style, hint_style))
675 g_object_notify((GObject *) font_style, "hint-style");
679 * adg_font_style_get_hint_metrics:
680 * @font_style: an #AdgFontStyle object
682 * Gets the state on whether to hint font metrics.
684 * Returns: the requested hint metrics state
686 cairo_hint_metrics_t
687 adg_font_style_get_hint_metrics(AdgFontStyle *font_style)
689 AdgFontStylePrivate *data;
691 g_return_val_if_fail(ADG_IS_FONT_STYLE(font_style),
692 CAIRO_HINT_METRICS_DEFAULT);
694 data = font_style->data;
696 return data->hint_metrics;
700 * adg_font_style_set_hint_metrics:
701 * @font_style: an #AdgFontStyle object
702 * @hint_metrics: the new hint metrics state
704 * Sets a new hint metrics state.
706 void
707 adg_font_style_set_hint_metrics(AdgFontStyle *font_style,
708 cairo_hint_metrics_t hint_metrics)
710 g_return_if_fail(ADG_IS_FONT_STYLE(font_style));
712 if (set_hint_metrics(font_style, hint_metrics))
713 g_object_notify((GObject *) font_style, "hint-metrics");
717 static void
718 apply(AdgStyle *style, AdgEntity *entity, cairo_t *cr)
720 AdgFontStyle *font_style;
721 AdgFontStylePrivate *data;
722 AdgMatrix ctm;
723 cairo_scaled_font_t *font;
725 font_style = (AdgFontStyle *) style;
726 data = font_style->data;
728 adg_entity_apply_dress(entity, data->color_dress, cr);
730 cairo_get_matrix(cr, &ctm);
731 font = adg_font_style_font((AdgFontStyle *) style, &ctm);
733 cairo_set_scaled_font(cr, font);
736 static gboolean
737 set_family(AdgFontStyle *font_style, const gchar *family)
739 AdgFontStylePrivate *data = font_style->data;
741 if (adg_strcmp(family, data->family) == 0)
742 return FALSE;
744 g_free(data->family);
745 data->family = g_strdup(family);
746 unset_face(font_style);
748 return TRUE;
751 static gboolean
752 set_slant(AdgFontStyle *font_style, cairo_font_slant_t slant)
754 AdgFontStylePrivate *data = font_style->data;
756 if (slant == data->slant)
757 return FALSE;
759 data->slant = slant;
760 unset_face(font_style);
762 return TRUE;
765 static gboolean
766 set_weight(AdgFontStyle *font_style, cairo_font_weight_t weight)
768 AdgFontStylePrivate *data = font_style->data;
770 if (weight == data->weight)
771 return FALSE;
773 data->weight = weight;
774 unset_face(font_style);
776 return TRUE;
779 static gboolean
780 set_size(AdgFontStyle *font_style, gdouble size)
782 AdgFontStylePrivate *data = font_style->data;
784 if (size == data->size)
785 return FALSE;
787 data->size = size;
788 unset_font(font_style);
790 return TRUE;
793 static gboolean
794 set_antialias(AdgFontStyle *font_style, cairo_antialias_t antialias)
796 AdgFontStylePrivate *data = font_style->data;
798 if (antialias == data->antialias)
799 return FALSE;
801 data->antialias = antialias;
802 unset_font(font_style);
804 return TRUE;
807 static gboolean
808 set_subpixel_order(AdgFontStyle *font_style,
809 cairo_subpixel_order_t subpixel_order)
811 AdgFontStylePrivate *data = font_style->data;
813 if (subpixel_order == data->subpixel_order)
814 return FALSE;
816 data->subpixel_order = subpixel_order;
817 unset_font(font_style);
819 return TRUE;
822 static gboolean
823 set_hint_style(AdgFontStyle *font_style, cairo_hint_style_t hint_style)
825 AdgFontStylePrivate *data = font_style->data;
827 if (hint_style == data->hint_style)
828 return FALSE;
830 data->hint_style = hint_style;
831 unset_font(font_style);
833 return TRUE;
836 static gboolean
837 set_hint_metrics(AdgFontStyle *font_style, cairo_hint_metrics_t hint_metrics)
839 AdgFontStylePrivate *data = font_style->data;
841 if (hint_metrics == data->hint_metrics)
842 return FALSE;
844 data->hint_metrics = hint_metrics;
845 unset_font(font_style);
847 return TRUE;
850 static void
851 unset_face(AdgFontStyle *font_style)
853 AdgFontStylePrivate *data = font_style->data;
855 if (data->face == NULL)
856 return;
858 /* Changing the face invalidates the scaled font too */
859 unset_font(font_style);
861 cairo_font_face_destroy(data->face);
862 data->face = NULL;
865 static void
866 unset_font(AdgFontStyle *font_style)
868 AdgFontStylePrivate *data = font_style->data;
870 if (data->font == NULL)
871 return;
873 cairo_scaled_font_destroy(data->font);
874 data->font = NULL;