[docs] Updated TODO.xml
[adg.git] / adg / adg-font-style.c
blobb21c6985ca07fa011ab49a48e7a4fd028343c285
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)
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_get_scaled_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_get_scaled_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_set_color_dress:
370 * @font_style: an #AdgFontStyle
371 * @dress: the new color dress to use
373 * Sets a new color dress on @font_style. The new dress
374 * should be related to the original dress: you cannot
375 * set a dress used for font styles to a dress managing
376 * fonts.
378 * The validation of the new dress is done by calling
379 * adg_dress_are_related() with @dress and the previous
380 * dress as arguments: check out its documentation for
381 * details on what is a related dress.
383 void
384 adg_font_style_set_color_dress(AdgFontStyle *font_style, AdgDress dress)
386 AdgFontStylePrivate *data;
388 g_return_if_fail(ADG_IS_FONT_STYLE(font_style));
390 data = font_style->data;
392 if (adg_dress_set(&data->color_dress, dress))
393 g_object_notify((GObject *) font_style, "color-dress");
397 * adg_font_style_get_color_dress:
398 * @font_style: an #AdgFontStyle
400 * Gets the color dress used by @font_style.
402 * Returns: the current color dress
404 AdgDress
405 adg_font_style_get_color_dress(AdgFontStyle *font_style)
407 AdgFontStylePrivate *data;
409 g_return_val_if_fail(ADG_IS_FONT_STYLE(font_style), ADG_DRESS_UNDEFINED);
411 data = font_style->data;
413 return data->color_dress;
417 * adg_font_style_set_family:
418 * @font_style: an #AdgFontStyle object
419 * @family: the new family
421 * Sets a new family.
423 void
424 adg_font_style_set_family(AdgFontStyle *font_style, const gchar *family)
426 g_return_if_fail(ADG_IS_FONT_STYLE(font_style));
428 if (set_family(font_style, family))
429 g_object_notify((GObject *) font_style, "family");
433 * adg_font_style_get_family:
434 * @font_style: an #AdgFontStyle object
436 * Gets the family of @font_style. The returned pointer refers to
437 * internally managed text that must not be modified or freed.
439 * Returns: the requested family
441 const gchar *
442 adg_font_style_get_family(AdgFontStyle *font_style)
444 AdgFontStylePrivate *data;
446 g_return_val_if_fail(ADG_IS_FONT_STYLE(font_style), NULL);
448 data = font_style->data;
450 return data->family;
454 * adg_font_style_set_slant:
455 * @font_style: an #AdgFontStyle object
456 * @slant: the new slant
458 * Sets a new slant variant on @font_style.
460 void
461 adg_font_style_set_slant(AdgFontStyle *font_style,
462 cairo_font_slant_t slant)
464 g_return_if_fail(ADG_IS_FONT_STYLE(font_style));
466 if (set_slant(font_style, slant))
467 g_object_notify((GObject *) font_style, "slant");
471 * adg_font_style_get_slant:
472 * @font_style: an #AdgFontStyle object
474 * Gets the slant variant of @font_style.
476 * Returns: the slant variant
478 cairo_font_slant_t
479 adg_font_style_get_slant(AdgFontStyle *font_style)
481 AdgFontStylePrivate *data;
483 g_return_val_if_fail(ADG_IS_FONT_STYLE(font_style),
484 CAIRO_FONT_SLANT_NORMAL);
486 data = font_style->data;
488 return data->slant;
492 * adg_font_style_set_weight:
493 * @font_style: an #AdgFontStyle object
494 * @weight: the new weight
496 * Sets a new weight variant on @font_style.
498 void
499 adg_font_style_set_weight(AdgFontStyle *font_style,
500 cairo_font_weight_t weight)
502 g_return_if_fail(ADG_IS_FONT_STYLE(font_style));
504 if (set_weight(font_style, weight))
505 g_object_notify((GObject *) font_style, "weight");
509 * adg_font_style_get_weight:
510 * @font_style: an #AdgFontStyle object
512 * Gets the weight variant of @font_style.
514 * Returns: the weight variant
516 cairo_font_weight_t
517 adg_font_style_get_weight(AdgFontStyle *font_style)
519 AdgFontStylePrivate *data;
521 g_return_val_if_fail(ADG_IS_FONT_STYLE(font_style),
522 CAIRO_FONT_WEIGHT_NORMAL);
524 data = font_style->data;
526 return data->weight;
530 * adg_font_style_set_size:
531 * @font_style: an #AdgFontStyle object
532 * @size: the new size
534 * Sets a new size (in global space) on @font_style.
536 void
537 adg_font_style_set_size(AdgFontStyle *font_style, gdouble size)
539 g_return_if_fail(ADG_IS_FONT_STYLE(font_style));
541 if (set_size(font_style, size))
542 g_object_notify((GObject *) font_style, "size");
546 * adg_font_style_get_size:
547 * @font_style: an #AdgFontStyle object
549 * Gets the size (in global space) of @font_style.
551 * Returns: the size variant
553 gdouble
554 adg_font_style_get_size(AdgFontStyle *font_style)
556 AdgFontStylePrivate *data;
558 g_return_val_if_fail(ADG_IS_FONT_STYLE(font_style), 0.);
560 data = font_style->data;
562 return data->size;
566 * adg_font_style_set_antialias:
567 * @font_style: an #AdgFontStyle object
568 * @antialias: the new antialias mode
570 * Sets a new antialias mode.
572 void
573 adg_font_style_set_antialias(AdgFontStyle *font_style,
574 cairo_antialias_t antialias)
576 g_return_if_fail(ADG_IS_FONT_STYLE(font_style));
578 if (set_antialias(font_style, antialias))
579 g_object_notify((GObject *) font_style, "antialias");
583 * adg_font_style_get_antialias:
584 * @font_style: an #AdgFontStyle object
586 * Gets the antialias mode used.
588 * Returns: the requested antialias mode
590 cairo_antialias_t
591 adg_font_style_get_antialias(AdgFontStyle *font_style)
593 AdgFontStylePrivate *data;
595 g_return_val_if_fail(ADG_IS_FONT_STYLE(font_style),
596 CAIRO_ANTIALIAS_DEFAULT);
598 data = font_style->data;
600 return data->antialias;
604 * adg_font_style_set_subpixel_order:
605 * @font_style: an #AdgFontStyle object
606 * @subpixel_order: the new subpixel order mode
608 * Sets a new subpixel order mode.
610 void
611 adg_font_style_set_subpixel_order(AdgFontStyle *font_style,
612 cairo_subpixel_order_t subpixel_order)
614 g_return_if_fail(ADG_IS_FONT_STYLE(font_style));
616 if (set_subpixel_order(font_style, subpixel_order))
617 g_object_notify((GObject *) font_style, "subpixel-order");
621 * adg_font_style_get_subpixel_order:
622 * @font_style: an #AdgFontStyle object
624 * Gets the subpixel order mode used, that is the order of color elements
625 * within each pixel on the display device when rendering with an
626 * antialiasing mode of %CAIRO_ANTIALIAS_SUBPIXEL.
628 * Returns: the requested subpixel order mode
630 cairo_subpixel_order_t
631 adg_font_style_get_subpixel_order(AdgFontStyle *font_style)
633 AdgFontStylePrivate *data;
635 g_return_val_if_fail(ADG_IS_FONT_STYLE(font_style),
636 CAIRO_SUBPIXEL_ORDER_DEFAULT);
638 data = font_style->data;
640 return data->subpixel_order;
644 * adg_font_style_set_hint_style:
645 * @font_style: an #AdgFontStyle object
646 * @hint_style: the new hint style mode
648 * Sets a new hint style mode.
650 void
651 adg_font_style_set_hint_style(AdgFontStyle *font_style,
652 cairo_hint_style_t hint_style)
654 g_return_if_fail(ADG_IS_FONT_STYLE(font_style));
656 if (set_hint_style(font_style, hint_style))
657 g_object_notify((GObject *) font_style, "hint-style");
661 * adg_font_style_get_hint_style:
662 * @font_style: an #AdgFontStyle object
664 * Gets the hint style mode used, that is how to fit outlines
665 * to the pixel grid in order to improve the appearance of the result.
667 * Returns: the requested hint style mode
669 cairo_hint_style_t
670 adg_font_style_get_hint_style(AdgFontStyle *font_style)
672 AdgFontStylePrivate *data;
674 g_return_val_if_fail(ADG_IS_FONT_STYLE(font_style),
675 CAIRO_HINT_STYLE_DEFAULT);
677 data = font_style->data;
679 return data->hint_style;
683 * adg_font_style_set_hint_metrics:
684 * @font_style: an #AdgFontStyle object
685 * @hint_metrics: the new hint metrics state
687 * Sets a new hint metrics state.
689 void
690 adg_font_style_set_hint_metrics(AdgFontStyle *font_style,
691 cairo_hint_metrics_t hint_metrics)
693 g_return_if_fail(ADG_IS_FONT_STYLE(font_style));
695 if (set_hint_metrics(font_style, hint_metrics))
696 g_object_notify((GObject *) font_style, "hint-metrics");
700 * adg_font_style_get_hint_metrics:
701 * @font_style: an #AdgFontStyle object
703 * Gets the state on whether to hint font metrics.
705 * Returns: the requested hint metrics state
707 cairo_hint_metrics_t
708 adg_font_style_get_hint_metrics(AdgFontStyle *font_style)
710 AdgFontStylePrivate *data;
712 g_return_val_if_fail(ADG_IS_FONT_STYLE(font_style),
713 CAIRO_HINT_METRICS_DEFAULT);
715 data = font_style->data;
717 return data->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_get_scaled_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;