Replace clutter_set_use_mipmapped_text with clutter_set_font_flags
authorNeil Roberts <neil@linux.intel.com>
Tue, 27 Jan 2009 14:25:50 +0000 (14:25 +0000)
committerNeil Roberts <neil@linux.intel.com>
Tue, 27 Jan 2009 14:43:44 +0000 (14:43 +0000)
The hope is that this function makes it easier to extend the font
settings with more flags without having to add a function for every
setting.

A new flag for enabling hinting has been added. If set, this changes
the font options on the global PangoContext and any newly created
PangoContexts. The options are only set if the flag is changed from
the default so it won't override any detailed setting chosen by the
backend.

clutter/clutter-deprecated.h
clutter/clutter-main.c
clutter/clutter-main.h
clutter/clutter-private.h
clutter/clutter-types.h
doc/reference/clutter/clutter-sections.txt

index 3c38c98..958b7e6 100644 (file)
@@ -55,4 +55,7 @@
 #define clutter_stage_get_resolution    clutter_backend_get_resolution
 #define clutter_stage_get_resolutionx   clutter_backend_get_resolution
 
+#define clutter_set_use_mipmapped_text               clutter_actor_set_use_mipmapped_text_REPLACED_BY_clutter_set_font_flags
+#define clutter_get_use_mipmapped_text               clutter_actor_get_use_mipmapped_text_REPLACED_BY_clutter_get_font_flags
+
 #endif /* CLUTTER_DEPRECATED_H */
index 745fcbb..35d0afc 100644 (file)
@@ -453,6 +453,7 @@ 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);
@@ -460,8 +461,13 @@ 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);
@@ -2591,45 +2597,92 @@ clutter_clear_glyph_cache (void)
 }
 
 /**
- * clutter_set_use_mipmapped_text:
- * @value: %TRUE to enable mipmapping or %FALSE to disable.
+ * clutter_set_font_flags:
+ * @flags: The new flags
  *
- * Sets whether subsequent text rendering operations will use
- * mipmapped textures or not. Using mipmapped textures will improve
- * the quality for scaled down text but will use more texture memory.
+ * Sets the font quality options for subsequent text rendering
+ * operations.
  *
- * Since: 0.8
+ * Using mipmapped textures will improve the quality for scaled down
+ * 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.
+ *
+ * Since: 1.0
  */
 void
-clutter_set_use_mipmapped_text (gboolean value)
+clutter_set_font_flags (ClutterFontFlags flags)
 {
+  ClutterFontFlags old_flags, changed_flags;
+
   if (CLUTTER_CONTEXT ()->font_map)
     cogl_pango_font_map_set_use_mipmapping (CLUTTER_CONTEXT ()->font_map,
-                                           value);
+                                           (flags
+                                             & CLUTTER_FONT_MIPMAPPING) != 0);
+
+  old_flags = clutter_get_font_flags ();
+
+  if (CLUTTER_CONTEXT ()->user_font_options == NULL)
+    CLUTTER_CONTEXT ()->user_font_options = cairo_font_options_create ();
+
+  /* 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,
+                                       (flags & CLUTTER_FONT_HINTING)
+                                       ? CAIRO_HINT_STYLE_FULL
+                                       : CAIRO_HINT_STYLE_NONE);
+
+  if (CLUTTER_CONTEXT ()->pango_context)
+    update_pango_context (CLUTTER_CONTEXT ()->backend,
+                          CLUTTER_CONTEXT ()->pango_context);
 }
 
 /**
- * clutter_get_use_mipmapped_text:
+ * clutter_get_font_flags:
  *
- * Gets whether mipmapped textures are used in text operations.
- * See clutter_set_use_mipmapped_text().
+ * Gets the current font flags for rendering text. See
+ * clutter_set_font_flags().
  *
- * Return value: %TRUE if text operations should use mipmapped
- *   textures
+ * Return value: The font flags
  *
- * Since: 0.8
+ * Since: 1.0
  */
-gboolean
-clutter_get_use_mipmapped_text (void)
+ClutterFontFlags
+clutter_get_font_flags (void)
 {
+  ClutterMainContext *ctxt = CLUTTER_CONTEXT ();
   CoglPangoFontMap *font_map = NULL;
+  cairo_font_options_t *font_options;
+  ClutterFontFlags flags = 0;
 
   font_map = CLUTTER_CONTEXT ()->font_map;
 
-  if (G_LIKELY (font_map))
-    return cogl_pango_font_map_get_use_mipmapping (font_map);
+  if (G_LIKELY (font_map)
+      && cogl_pango_font_map_get_use_mipmapping (font_map))
+    flags |= CLUTTER_FONT_MIPMAPPING;
 
-  return FALSE;
+  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)
+      && (cairo_font_options_get_hint_style (font_options)
+          != CAIRO_HINT_STYLE_NONE))
+    flags |= CLUTTER_FONT_HINTING;
+
+  cairo_font_options_destroy (font_options);
+
+  return flags;
 }
 
 /**
index 9927d12..a4ce75f 100644 (file)
@@ -155,8 +155,8 @@ void             clutter_ungrab_keyboard             (void);
 ClutterActor *   clutter_get_keyboard_grab           (void);
 
 void             clutter_clear_glyph_cache           (void);
-void             clutter_set_use_mipmapped_text      (gboolean      value);
-gboolean         clutter_get_use_mipmapped_text      (void);
+void             clutter_set_font_flags              (ClutterFontFlags flags);
+ClutterFontFlags clutter_get_font_flags              (void);
 
 ClutterInputDevice*  clutter_get_input_device_for_id (gint id);
 
index d6f7d11..d1debaa 100644 (file)
@@ -129,6 +129,9 @@ 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 */
 };
index 968a7a5..f8e0e97 100644 (file)
@@ -313,6 +313,22 @@ typedef enum {
   CLUTTER_ANIMATION_LAST
 } ClutterAnimationMode;
 
+/**
+ * ClutterFontFlags:
+ * @CLUTTER_FONT_MIPMAPPING: Set to use mipmaps for the glyph cache textures.
+ * @CLUTTER_FONT_HINTING: Set to enable hinting on the glyphs.
+ *
+ * Runtime flags to change the font quality. To be used with
+ * clutter_set_font_flags().
+ *
+ * Since: 1.0
+ */
+typedef enum
+{
+  CLUTTER_FONT_MIPMAPPING = (1 << 0),
+  CLUTTER_FONT_HINTING    = (1 << 1),
+} ClutterFontFlags;
+
 G_END_DECLS
 
 #endif /* __CLUTTER_TYPES_H__ */
index 8720e20..54b1f60 100644 (file)
@@ -1089,8 +1089,9 @@ clutter_get_motion_events_enabled
 clutter_set_motion_events_frequency
 clutter_get_motion_events_frequency
 clutter_clear_glyph_cache
-clutter_set_use_mipmapped_text
-clutter_get_use_mipmapped_text
+ClutterFontFlags
+clutter_set_font_flags
+clutter_get_font_flags
 clutter_get_font_map
 
 <SUBSECTION>