From 6b9da72ab053eb96bed20655d8894c614a3077f1 Mon Sep 17 00:00:00 2001
From: Neil Roberts <neil@linux.intel.com>
Date: Tue, 27 Jan 2009 16:55:25 +0000
Subject: [PATCH] Directly set backend font options in clutter_set_font_flags

Instead of having a separate set of font options that override the
backend options when clutter_set_font_flags is called, it now just
directly sets the backend font options. So now the font flags are just
a convenience wrapper around the backend font options.

This also makes the ClutterText labels automatically update when the
font flags are changed because they will respond to the 'font-changed'
signal from the backend.
---
 clutter/clutter-main.c    | 28 +++++++++-------------------
 clutter/clutter-private.h |  3 ---
 2 files changed, 9 insertions(+), 22 deletions(-)

diff --git a/clutter/clutter-main.c b/clutter/clutter-main.c
index 1cb21fa25..a1eaceb21 100644
--- a/clutter/clutter-main.c
+++ b/clutter/clutter-main.c
@@ -453,7 +453,6 @@ update_pango_context (ClutterBackend *backend,
   /* get the configuration for the PangoContext from the backend */
   font_name = clutter_backend_get_font_name (backend);
   font_options = clutter_backend_get_font_options (backend);
-  font_options = cairo_font_options_copy (font_options);
   resolution = clutter_backend_get_resolution (backend);
 
   font_desc = pango_font_description_from_string (font_name);
@@ -461,13 +460,8 @@ update_pango_context (ClutterBackend *backend,
   if (resolution < 0)
     resolution = 96.0; /* fall back */
 
-  if (CLUTTER_CONTEXT ()->user_font_options)
-    cairo_font_options_merge (font_options,
-                              CLUTTER_CONTEXT ()->user_font_options);
-
   pango_context_set_font_description (context, font_desc);
   pango_cairo_context_set_font_options (context, font_options);
-  cairo_font_options_destroy (font_options);
   pango_cairo_context_set_resolution (context, resolution);
 
   pango_font_description_free (font_desc);
@@ -2610,10 +2604,7 @@ clutter_clear_glyph_cache (void)
  * text but will use more texture memory.
  *
  * Enabling hinting improves text quality for static text but may
- * introduce some artifacts if the text is animated. Changing the
- * hinting flag will only effect newly created PangoLayouts. So
- * #ClutterText actors will not show the change until a property which
- * causes it to recreate the layout is also changed.
+ * introduce some artifacts if the text is animated.
  *
  * Since: 1.0
  */
@@ -2621,6 +2612,7 @@ void
 clutter_set_font_flags (ClutterFontFlags flags)
 {
   ClutterFontFlags old_flags, changed_flags;
+  cairo_font_options_t *font_options;
 
   if (CLUTTER_CONTEXT ()->font_map)
     cogl_pango_font_map_set_use_mipmapping (CLUTTER_CONTEXT ()->font_map,
@@ -2629,19 +2621,23 @@ clutter_set_font_flags (ClutterFontFlags flags)
 
   old_flags = clutter_get_font_flags ();
 
-  if (CLUTTER_CONTEXT ()->user_font_options == NULL)
-    CLUTTER_CONTEXT ()->user_font_options = cairo_font_options_create ();
+  font_options = clutter_backend_get_font_options (CLUTTER_CONTEXT ()->backend);
+  font_options = cairo_font_options_copy (font_options);
 
   /* Only set the font options that have actually changed so we don't
      override a detailed setting from the backend */
   changed_flags = old_flags ^ flags;
 
   if ((changed_flags & CLUTTER_FONT_HINTING))
-    cairo_font_options_set_hint_style (CLUTTER_CONTEXT ()->user_font_options,
+    cairo_font_options_set_hint_style (font_options,
                                        (flags & CLUTTER_FONT_HINTING)
                                        ? CAIRO_HINT_STYLE_FULL
                                        : CAIRO_HINT_STYLE_NONE);
 
+  clutter_backend_set_font_options (CLUTTER_CONTEXT ()->backend, font_options);
+
+  cairo_font_options_destroy (font_options);
+
   if (CLUTTER_CONTEXT ()->pango_context)
     update_pango_context (CLUTTER_CONTEXT ()->backend,
                           CLUTTER_CONTEXT ()->pango_context);
@@ -2672,10 +2668,6 @@ clutter_get_font_flags (void)
     flags |= CLUTTER_FONT_MIPMAPPING;
 
   font_options = clutter_backend_get_font_options (ctxt->backend);
-  font_options = cairo_font_options_copy (font_options);
-
-  if (ctxt->user_font_options)
-    cairo_font_options_merge (font_options, ctxt->user_font_options);
 
   if ((cairo_font_options_get_hint_style (font_options)
        != CAIRO_HINT_STYLE_DEFAULT)
@@ -2683,8 +2675,6 @@ clutter_get_font_flags (void)
           != CAIRO_HINT_STYLE_NONE))
     flags |= CLUTTER_FONT_HINTING;
 
-  cairo_font_options_destroy (font_options);
-
   return flags;
 }
 
diff --git a/clutter/clutter-private.h b/clutter/clutter-private.h
index 6b4779e23..c7345c832 100644
--- a/clutter/clutter-private.h
+++ b/clutter/clutter-private.h
@@ -129,9 +129,6 @@ struct _ClutterMainContext
   PangoContext     *pango_context;      /* Global Pango context */
   CoglPangoFontMap *font_map;           /* Global font map */
 
-  /* Font options set by clutter_set_font_flags */
-  cairo_font_options_t *user_font_options;
-
   GSList              *input_devices;   /* For extra input devices, i.e
                                            MultiTouch */
 };