Update the PangoContext on backend changes
authorEmmanuele Bassi <ebassi@linux.intel.com>
Tue, 23 Dec 2008 14:34:16 +0000 (14:34 +0000)
committerEmmanuele Bassi <ebassi@linux.intel.com>
Tue, 23 Dec 2008 14:34:16 +0000 (14:34 +0000)
When the ClutterBackend notifies of changes in the resolution or
font options, update the PangoContext stored by Clutter's main
context. This allows changing the backend font-related settings at
runtime.

clutter/clutter-main.c

index 5b6a8d3..5065610 100644 (file)
@@ -401,12 +401,27 @@ _clutter_do_pick (ClutterStage   *stage,
   return clutter_get_actor_by_gid (id);
 }
 
+static void
+update_pango_context (ClutterBackend     *backend,
+                      ClutterMainContext *main_context)
+{
+  PangoContext *context = main_context->pango_context;
+  cairo_font_options_t *font_options;
+  gdouble resolution;
+
+  font_options = clutter_backend_get_font_options (backend);
+  resolution = clutter_backend_get_resolution (backend);
+  if (resolution < 0)
+    resolution = 96.0; /* fall back */
+
+  pango_cairo_context_set_font_options (context, font_options);
+  pango_cairo_context_set_resolution (context, resolution);
+}
+
 PangoContext *
 _clutter_context_create_pango_context (ClutterMainContext *self)
 {
   PangoContext *context;
-  gdouble resolution;
-  cairo_font_options_t *font_options;
 
   if (G_LIKELY (self->pango_context != NULL))
     context = self->pango_context;
@@ -416,13 +431,14 @@ _clutter_context_create_pango_context (ClutterMainContext *self)
       self->pango_context = context;
     }
 
-  font_options = clutter_backend_get_font_options (self->backend);
-  resolution = clutter_backend_get_resolution (self->backend);
-  if (resolution < 0)
-    resolution = 96.0; /* fall back */
+  g_signal_connect (self->backend, "resolution-changed",
+                    G_CALLBACK (update_pango_context),
+                    self);
+  g_signal_connect (self->backend, "font-changed",
+                    G_CALLBACK (update_pango_context),
+                    self);
 
-  pango_cairo_context_set_font_options (context, font_options);
-  pango_cairo_context_set_resolution (context, resolution);
+  update_pango_context (self->backend, self);
 
   return context;
 }