[AdgFontStyle] Rely on automatic dress validation
[adg.git] / src / adg / adg-font-style.c
blobbf33ba21f91b8a2d2cb66b4b275d88324c5964b7
1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2007,2008,2009,2010 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-internal.h"
38 #include "adg-font-style.h"
39 #include "adg-font-style-private.h"
40 #include "adg-dress-builtins.h"
42 #define PARENT_OBJECT_CLASS ((GObjectClass *) adg_font_style_parent_class)
45 enum {
46 PROP_0,
47 PROP_COLOR_DRESS,
48 PROP_FAMILY,
49 PROP_SLANT,
50 PROP_WEIGHT,
51 PROP_SIZE,
52 PROP_ANTIALIAS,
53 PROP_SUBPIXEL_ORDER,
54 PROP_HINT_STYLE,
55 PROP_HINT_METRICS
59 static void dispose (GObject *object);
60 static void get_property (GObject *object,
61 guint prop_id,
62 GValue *value,
63 GParamSpec *pspec);
64 static void set_property (GObject *object,
65 guint prop_id,
66 const GValue *value,
67 GParamSpec *pspec);
68 static void apply (AdgStyle *style,
69 AdgEntity *entity,
70 cairo_t *cr);
71 static gboolean set_family (AdgFontStyle *font_style,
72 const gchar *family);
73 static gboolean set_slant (AdgFontStyle *font_style,
74 cairo_font_slant_t slant);
75 static gboolean set_weight (AdgFontStyle *font_style,
76 cairo_font_weight_t weight);
77 static gboolean set_size (AdgFontStyle *font_style,
78 gdouble size);
79 static gboolean set_antialias (AdgFontStyle *font_style,
80 cairo_antialias_t antialias);
81 static gboolean set_subpixel_order (AdgFontStyle *font_style,
82 cairo_subpixel_order_t subpixel_order);
83 static gboolean set_hint_style (AdgFontStyle *font_style,
84 cairo_hint_style_t hint_style);
85 static gboolean set_hint_metrics (AdgFontStyle *font_style,
86 cairo_hint_metrics_t hint_metrics);
87 static void unset_face (AdgFontStyle *font_style);
88 static void unset_font (AdgFontStyle *font_style);
91 G_DEFINE_TYPE(AdgFontStyle, adg_font_style, ADG_TYPE_STYLE);
94 static void
95 adg_font_style_class_init(AdgFontStyleClass *klass)
97 GObjectClass *gobject_class;
98 AdgStyleClass *style_class;
99 GParamSpec *param;
101 gobject_class = (GObjectClass *) klass;
102 style_class = (AdgStyleClass *) klass;
104 g_type_class_add_private(klass, sizeof(AdgFontStylePrivate));
106 gobject_class->dispose = dispose;
107 gobject_class->get_property = get_property;
108 gobject_class->set_property = set_property;
110 style_class->apply = apply;
112 param = adg_param_spec_dress("color-dress",
113 P_("Color Dress"),
114 P_("The color dress to bind to this font style"),
115 ADG_DRESS_COLOR,
116 G_PARAM_READWRITE);
117 g_object_class_install_property(gobject_class, PROP_COLOR_DRESS, param);
119 param = g_param_spec_string("family",
120 P_("Font Family"),
121 P_("The font family name, encoded in UTF-8"),
122 NULL,
123 G_PARAM_READWRITE);
124 g_object_class_install_property(gobject_class, PROP_FAMILY, param);
126 param = g_param_spec_int("slant",
127 P_("Font Slant"),
128 P_("Variant of a font face based on its slant"),
129 G_MININT, G_MAXINT, CAIRO_FONT_SLANT_NORMAL,
130 G_PARAM_READWRITE);
131 g_object_class_install_property(gobject_class, PROP_SLANT, param);
133 param = g_param_spec_int("weight",
134 P_("Font Weight"),
135 P_("Variant of a font face based on its weight"),
136 G_MININT, G_MAXINT, CAIRO_FONT_WEIGHT_NORMAL,
137 G_PARAM_READWRITE);
138 g_object_class_install_property(gobject_class, PROP_WEIGHT, param);
140 param = g_param_spec_double("size",
141 P_("Font Size"),
142 P_("Font size in user space units"),
143 0, G_MAXDOUBLE, 10,
144 G_PARAM_READWRITE);
145 g_object_class_install_property(gobject_class, PROP_SIZE, param);
147 param = g_param_spec_int("antialias",
148 P_("Font Antialiasing Mode"),
149 P_("Type of antialiasing to do when rendering text"),
150 G_MININT, G_MAXINT, CAIRO_ANTIALIAS_DEFAULT,
151 G_PARAM_READWRITE);
152 g_object_class_install_property(gobject_class, PROP_ANTIALIAS, param);
154 param = g_param_spec_int("subpixel-order",
155 P_("Font Subpixel Order"),
156 P_("The order of color elements within each pixel on the display device when rendering with subpixel antialiasing mode"),
157 G_MININT, G_MAXINT,
158 CAIRO_SUBPIXEL_ORDER_DEFAULT,
159 G_PARAM_READWRITE);
160 g_object_class_install_property(gobject_class, PROP_SUBPIXEL_ORDER, param);
162 param = g_param_spec_int("hint-style",
163 P_("Type of Hinting"),
164 P_("How outlines must fit to the pixel grid in order to improve the glyph appearance"),
165 G_MININT, G_MAXINT, CAIRO_HINT_STYLE_DEFAULT,
166 G_PARAM_READWRITE);
167 g_object_class_install_property(gobject_class, PROP_HINT_STYLE, param);
169 param = g_param_spec_int("hint-metrics",
170 P_("Font Metric Hinting"),
171 P_("Whether to hint font metrics, that is align them to integer values in device space"),
172 G_MININT, G_MAXINT,
173 CAIRO_HINT_METRICS_DEFAULT,
174 G_PARAM_READWRITE);
175 g_object_class_install_property(gobject_class, PROP_HINT_METRICS, param);
178 static void
179 adg_font_style_init(AdgFontStyle *font_style)
181 AdgFontStylePrivate *data = G_TYPE_INSTANCE_GET_PRIVATE(font_style,
182 ADG_TYPE_FONT_STYLE,
183 AdgFontStylePrivate);
185 data->color_dress = ADG_DRESS_COLOR;
186 data->family = NULL;
187 data->slant = CAIRO_FONT_SLANT_NORMAL;
188 data->weight = CAIRO_FONT_WEIGHT_NORMAL;
189 data->size = 10;
190 data->antialias = CAIRO_ANTIALIAS_DEFAULT;
191 data->subpixel_order = CAIRO_SUBPIXEL_ORDER_DEFAULT;
192 data->hint_style = CAIRO_HINT_STYLE_DEFAULT;
193 data->hint_metrics = CAIRO_HINT_METRICS_DEFAULT;
194 data->font = NULL;
196 font_style->data = data;
199 static void
200 dispose(GObject *object)
202 AdgFontStyle *font_style = (AdgFontStyle *) object;
204 unset_font(font_style);
205 unset_face(font_style);
207 if (PARENT_OBJECT_CLASS->dispose)
208 PARENT_OBJECT_CLASS->dispose(object);
211 static void
212 get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
214 AdgFontStylePrivate *data = ((AdgFontStyle *) object)->data;
216 switch (prop_id) {
217 case PROP_COLOR_DRESS:
218 g_value_set_int(value, data->color_dress);
219 break;
220 case PROP_FAMILY:
221 g_value_set_string(value, data->family);
222 break;
223 case PROP_SLANT:
224 g_value_set_int(value, data->slant);
225 break;
226 case PROP_WEIGHT:
227 g_value_set_int(value, data->weight);
228 break;
229 case PROP_SIZE:
230 g_value_set_double(value, data->size);
231 break;
232 case PROP_ANTIALIAS:
233 g_value_set_int(value, data->antialias);
234 break;
235 case PROP_SUBPIXEL_ORDER:
236 g_value_set_int(value, data->subpixel_order);
237 break;
238 case PROP_HINT_STYLE:
239 g_value_set_int(value, data->hint_style);
240 break;
241 case PROP_HINT_METRICS:
242 g_value_set_int(value, data->hint_metrics);
243 break;
244 default:
245 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
246 break;
250 static void
251 set_property(GObject *object,
252 guint prop_id, const GValue *value, GParamSpec *pspec)
254 AdgFontStyle *font_style;
255 AdgFontStylePrivate *data;
257 font_style = (AdgFontStyle *) object;
258 data = font_style->data;
260 switch (prop_id) {
261 case PROP_COLOR_DRESS:
262 data->color_dress = g_value_get_int(value);
263 break;
264 case PROP_FAMILY:
265 set_family(font_style, g_value_get_string(value));
266 break;
267 case PROP_SLANT:
268 set_slant(font_style, g_value_get_int(value));
269 break;
270 case PROP_WEIGHT:
271 set_weight(font_style, g_value_get_int(value));
272 break;
273 case PROP_SIZE:
274 set_size(font_style, g_value_get_double(value));
275 break;
276 case PROP_ANTIALIAS:
277 set_antialias(font_style, g_value_get_int(value));
278 break;
279 case PROP_SUBPIXEL_ORDER:
280 set_subpixel_order(font_style, g_value_get_int(value));
281 break;
282 case PROP_HINT_STYLE:
283 set_hint_style(font_style, g_value_get_int(value));
284 break;
285 case PROP_HINT_METRICS:
286 set_hint_metrics(font_style, g_value_get_int(value));
287 break;
288 default:
289 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
290 break;
296 * adg_font_style_new:
298 * Constructs a new font style initialized with default params.
300 * Returns: a newly created font style
302 AdgFontStyle *
303 adg_font_style_new(void)
305 return g_object_new(ADG_TYPE_FONT_STYLE, NULL);
309 * adg_font_style_get_scaled_font:
310 * @font_style: an #AdgFontStyle object
311 * @ctm: the current transformation matrix
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_get_scaled_font(AdgFontStyle *font_style, const AdgMatrix *ctm)
321 AdgFontStylePrivate *data;
322 cairo_font_options_t *options;
323 AdgMatrix matrix;
325 g_return_val_if_fail(ADG_IS_FONT_STYLE(font_style), NULL);
326 g_return_val_if_fail(ctm != NULL, NULL);
328 data = font_style->data;
330 /* Check for cached font */
331 if (data->font != NULL) {
332 AdgMatrix font_ctm;
334 cairo_scaled_font_get_ctm(data->font, &font_ctm);
336 /* The scaled font is valid only if the two ctm match */
337 if (ctm->xx == font_ctm.xx && ctm->yy == font_ctm.yy &&
338 ctm->xy == font_ctm.xy && ctm->yx == font_ctm.yx)
339 return data->font;
341 /* No valid cache found: rebuild the scaled font */
342 unset_font(font_style);
345 if (data->face == NULL) {
346 const gchar *family = data->family != NULL ? data->family : "";
348 data->face = cairo_toy_font_face_create(family, data->slant,
349 data->weight);
352 cairo_matrix_init_scale(&matrix, data->size, data->size);
353 options = cairo_font_options_create();
355 cairo_font_options_set_antialias(options, data->antialias);
356 cairo_font_options_set_subpixel_order(options, data->subpixel_order);
357 cairo_font_options_set_hint_style(options, data->hint_style);
358 cairo_font_options_set_hint_metrics(options, data->hint_metrics);
360 data->font = cairo_scaled_font_create(data->face, &matrix, ctm, options);
362 cairo_font_options_destroy(options);
364 return data->font;
368 * adg_font_style_set_color_dress:
369 * @font_style: an #AdgFontStyle
370 * @dress: the new color dress to use
372 * Sets a new color dress on @font_style. The new dress
373 * should be related to the original dress: you cannot
374 * set a dress used for font styles to a dress managing
375 * fonts.
377 * The validation of the new dress is done by calling
378 * adg_dress_are_related() with @dress and the previous
379 * dress as arguments: check out its documentation for
380 * details on what is a related dress.
382 void
383 adg_font_style_set_color_dress(AdgFontStyle *font_style, AdgDress dress)
385 g_return_if_fail(ADG_IS_FONT_STYLE(font_style));
386 g_object_set((GObject *) font_style, "color-dress", dress, NULL);
390 * adg_font_style_get_color_dress:
391 * @font_style: an #AdgFontStyle
393 * Gets the color dress used by @font_style.
395 * Returns: the current color dress
397 AdgDress
398 adg_font_style_get_color_dress(AdgFontStyle *font_style)
400 AdgFontStylePrivate *data;
402 g_return_val_if_fail(ADG_IS_FONT_STYLE(font_style), ADG_DRESS_UNDEFINED);
404 data = font_style->data;
406 return data->color_dress;
410 * adg_font_style_set_family:
411 * @font_style: an #AdgFontStyle object
412 * @family: the new family
414 * Sets a new family.
416 void
417 adg_font_style_set_family(AdgFontStyle *font_style, const gchar *family)
419 g_return_if_fail(ADG_IS_FONT_STYLE(font_style));
421 if (set_family(font_style, family))
422 g_object_notify((GObject *) font_style, "family");
426 * adg_font_style_get_family:
427 * @font_style: an #AdgFontStyle object
429 * Gets the family of @font_style. The returned pointer refers to
430 * internally managed text that must not be modified or freed.
432 * Returns: the requested family
434 const gchar *
435 adg_font_style_get_family(AdgFontStyle *font_style)
437 AdgFontStylePrivate *data;
439 g_return_val_if_fail(ADG_IS_FONT_STYLE(font_style), NULL);
441 data = font_style->data;
443 return data->family;
447 * adg_font_style_set_slant:
448 * @font_style: an #AdgFontStyle object
449 * @slant: the new slant
451 * Sets a new slant variant on @font_style.
453 void
454 adg_font_style_set_slant(AdgFontStyle *font_style,
455 cairo_font_slant_t slant)
457 g_return_if_fail(ADG_IS_FONT_STYLE(font_style));
459 if (set_slant(font_style, slant))
460 g_object_notify((GObject *) font_style, "slant");
464 * adg_font_style_get_slant:
465 * @font_style: an #AdgFontStyle object
467 * Gets the slant variant of @font_style.
469 * Returns: the slant variant
471 cairo_font_slant_t
472 adg_font_style_get_slant(AdgFontStyle *font_style)
474 AdgFontStylePrivate *data;
476 g_return_val_if_fail(ADG_IS_FONT_STYLE(font_style),
477 CAIRO_FONT_SLANT_NORMAL);
479 data = font_style->data;
481 return data->slant;
485 * adg_font_style_set_weight:
486 * @font_style: an #AdgFontStyle object
487 * @weight: the new weight
489 * Sets a new weight variant on @font_style.
491 void
492 adg_font_style_set_weight(AdgFontStyle *font_style,
493 cairo_font_weight_t weight)
495 g_return_if_fail(ADG_IS_FONT_STYLE(font_style));
497 if (set_weight(font_style, weight))
498 g_object_notify((GObject *) font_style, "weight");
502 * adg_font_style_get_weight:
503 * @font_style: an #AdgFontStyle object
505 * Gets the weight variant of @font_style.
507 * Returns: the weight variant
509 cairo_font_weight_t
510 adg_font_style_get_weight(AdgFontStyle *font_style)
512 AdgFontStylePrivate *data;
514 g_return_val_if_fail(ADG_IS_FONT_STYLE(font_style),
515 CAIRO_FONT_WEIGHT_NORMAL);
517 data = font_style->data;
519 return data->weight;
523 * adg_font_style_set_size:
524 * @font_style: an #AdgFontStyle object
525 * @size: the new size
527 * Sets a new size (in global space) on @font_style.
529 void
530 adg_font_style_set_size(AdgFontStyle *font_style, gdouble size)
532 g_return_if_fail(ADG_IS_FONT_STYLE(font_style));
534 if (set_size(font_style, size))
535 g_object_notify((GObject *) font_style, "size");
539 * adg_font_style_get_size:
540 * @font_style: an #AdgFontStyle object
542 * Gets the size (in global space) of @font_style.
544 * Returns: the size variant
546 gdouble
547 adg_font_style_get_size(AdgFontStyle *font_style)
549 AdgFontStylePrivate *data;
551 g_return_val_if_fail(ADG_IS_FONT_STYLE(font_style), 0.);
553 data = font_style->data;
555 return data->size;
559 * adg_font_style_set_antialias:
560 * @font_style: an #AdgFontStyle object
561 * @antialias: the new antialias mode
563 * Sets a new antialias mode.
565 void
566 adg_font_style_set_antialias(AdgFontStyle *font_style,
567 cairo_antialias_t antialias)
569 g_return_if_fail(ADG_IS_FONT_STYLE(font_style));
571 if (set_antialias(font_style, antialias))
572 g_object_notify((GObject *) font_style, "antialias");
576 * adg_font_style_get_antialias:
577 * @font_style: an #AdgFontStyle object
579 * Gets the antialias mode used.
581 * Returns: the requested antialias mode
583 cairo_antialias_t
584 adg_font_style_get_antialias(AdgFontStyle *font_style)
586 AdgFontStylePrivate *data;
588 g_return_val_if_fail(ADG_IS_FONT_STYLE(font_style),
589 CAIRO_ANTIALIAS_DEFAULT);
591 data = font_style->data;
593 return data->antialias;
597 * adg_font_style_set_subpixel_order:
598 * @font_style: an #AdgFontStyle object
599 * @subpixel_order: the new subpixel order mode
601 * Sets a new subpixel order mode.
603 void
604 adg_font_style_set_subpixel_order(AdgFontStyle *font_style,
605 cairo_subpixel_order_t subpixel_order)
607 g_return_if_fail(ADG_IS_FONT_STYLE(font_style));
609 if (set_subpixel_order(font_style, subpixel_order))
610 g_object_notify((GObject *) font_style, "subpixel-order");
614 * adg_font_style_get_subpixel_order:
615 * @font_style: an #AdgFontStyle object
617 * Gets the subpixel order mode used, that is the order of color elements
618 * within each pixel on the display device when rendering with an
619 * antialiasing mode of %CAIRO_ANTIALIAS_SUBPIXEL.
621 * Returns: the requested subpixel order mode
623 cairo_subpixel_order_t
624 adg_font_style_get_subpixel_order(AdgFontStyle *font_style)
626 AdgFontStylePrivate *data;
628 g_return_val_if_fail(ADG_IS_FONT_STYLE(font_style),
629 CAIRO_SUBPIXEL_ORDER_DEFAULT);
631 data = font_style->data;
633 return data->subpixel_order;
637 * adg_font_style_set_hint_style:
638 * @font_style: an #AdgFontStyle object
639 * @hint_style: the new hint style mode
641 * Sets a new hint style mode.
643 void
644 adg_font_style_set_hint_style(AdgFontStyle *font_style,
645 cairo_hint_style_t hint_style)
647 g_return_if_fail(ADG_IS_FONT_STYLE(font_style));
649 if (set_hint_style(font_style, hint_style))
650 g_object_notify((GObject *) font_style, "hint-style");
654 * adg_font_style_get_hint_style:
655 * @font_style: an #AdgFontStyle object
657 * Gets the hint style mode used, that is how to fit outlines
658 * to the pixel grid in order to improve the appearance of the result.
660 * Returns: the requested hint style mode
662 cairo_hint_style_t
663 adg_font_style_get_hint_style(AdgFontStyle *font_style)
665 AdgFontStylePrivate *data;
667 g_return_val_if_fail(ADG_IS_FONT_STYLE(font_style),
668 CAIRO_HINT_STYLE_DEFAULT);
670 data = font_style->data;
672 return data->hint_style;
676 * adg_font_style_set_hint_metrics:
677 * @font_style: an #AdgFontStyle object
678 * @hint_metrics: the new hint metrics state
680 * Sets a new hint metrics state.
682 void
683 adg_font_style_set_hint_metrics(AdgFontStyle *font_style,
684 cairo_hint_metrics_t hint_metrics)
686 g_return_if_fail(ADG_IS_FONT_STYLE(font_style));
688 if (set_hint_metrics(font_style, hint_metrics))
689 g_object_notify((GObject *) font_style, "hint-metrics");
693 * adg_font_style_get_hint_metrics:
694 * @font_style: an #AdgFontStyle object
696 * Gets the state on whether to hint font metrics.
698 * Returns: the requested hint metrics state
700 cairo_hint_metrics_t
701 adg_font_style_get_hint_metrics(AdgFontStyle *font_style)
703 AdgFontStylePrivate *data;
705 g_return_val_if_fail(ADG_IS_FONT_STYLE(font_style),
706 CAIRO_HINT_METRICS_DEFAULT);
708 data = font_style->data;
710 return data->hint_metrics;
714 static void
715 apply(AdgStyle *style, AdgEntity *entity, cairo_t *cr)
717 AdgFontStyle *font_style;
718 AdgFontStylePrivate *data;
719 AdgMatrix ctm;
720 cairo_scaled_font_t *font;
722 font_style = (AdgFontStyle *) style;
723 data = font_style->data;
725 adg_entity_apply_dress(entity, data->color_dress, cr);
727 cairo_get_matrix(cr, &ctm);
728 font = adg_font_style_get_scaled_font((AdgFontStyle *) style, &ctm);
730 cairo_set_scaled_font(cr, font);
733 static gboolean
734 set_family(AdgFontStyle *font_style, const gchar *family)
736 AdgFontStylePrivate *data = font_style->data;
738 if (g_strcmp0(family, data->family) == 0)
739 return FALSE;
741 g_free(data->family);
742 data->family = g_strdup(family);
743 unset_face(font_style);
745 return TRUE;
748 static gboolean
749 set_slant(AdgFontStyle *font_style, cairo_font_slant_t slant)
751 AdgFontStylePrivate *data = font_style->data;
753 if (slant == data->slant)
754 return FALSE;
756 data->slant = slant;
757 unset_face(font_style);
759 return TRUE;
762 static gboolean
763 set_weight(AdgFontStyle *font_style, cairo_font_weight_t weight)
765 AdgFontStylePrivate *data = font_style->data;
767 if (weight == data->weight)
768 return FALSE;
770 data->weight = weight;
771 unset_face(font_style);
773 return TRUE;
776 static gboolean
777 set_size(AdgFontStyle *font_style, gdouble size)
779 AdgFontStylePrivate *data = font_style->data;
781 /* A better approach would be to use the GParamSpec of this property */
782 g_return_val_if_fail(size >= 0, FALSE);
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;