2008-05-28 Emmanuele Bassi <ebassi@openedhand.com>
authorEmmanuele Bassi <ebassi@openedhand.com>
Wed, 28 May 2008 14:03:28 +0000 (14:03 +0000)
committerEmmanuele Bassi <ebassi@openedhand.com>
Wed, 28 May 2008 14:03:28 +0000 (14:03 +0000)
Bug #919 - Replacement pango renderer (Neil Roberts)

* clutter/clutter-backend.h:
* clutter/clutter-backend.c:
(clutter_backend_set_font_options),
(clutter_backend_get_font_options): Add the ability to set
the cairo_font_options_t* for the backend at construction
time, so that backend implementations can have their own
options.

* clutter/clutter-color.c: Include pango/pango-attributes.h
for the pango_color_parse() function.

* clutter/clutter-label.c:
(clutter_label_ensure_layout),
(clutter_label_init), (clutter_label_set_text),
(clutter_label_set_font_name), (clutter_label_set_ellipsize),
(clutter_label_set_use_markup): Ensure that the cache is
always primed when the Label changes; this makes sure that
the cache is rebuilt outside the paint run, which should
make the painting perform better especially on embedded
devices.

* clutter/clutter-entry.c:
(clutter_entry_ensure_layout),
(clutter_entry_init), (clutter_entry_set_text),
(clutter_entry_set_font_name): Ditto as above.

* clutter/clutter-private.h:
* clutter/clutter-main.[ch]: Create the font-map inside the
main context; add two new functions:

  clutter_clear_glyph_cache()
  clutter_set_use_mipmapped_text()

that control the glyphs cache.

* clutter/pango/Makefile.am:
* clutter/pango/pangoclutter-fontmap.c:
* clutter/pango/pangoclutter-private.h:
* clutter/pango/pangoclutter-render.c:
* clutter/pango/pangoclutter.h: Rewrite the Pango renderer
using a PangoCairo context and saving the glyphs inside a
more efficient cache.

* configure.ac: Depend on pangocairo instead of pangoft2.

15 files changed:
ChangeLog
clutter/clutter-backend.c
clutter/clutter-backend.h
clutter/clutter-color.c
clutter/clutter-entry.c
clutter/clutter-label.c
clutter/clutter-main.c
clutter/clutter-main.h
clutter/clutter-private.h
clutter/pango/Makefile.am
clutter/pango/pangoclutter-fontmap.c
clutter/pango/pangoclutter-private.h
clutter/pango/pangoclutter-render.c
clutter/pango/pangoclutter.h
configure.ac

index 8aeeaca..930d350 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,54 @@
 2008-05-28  Emmanuele Bassi  <ebassi@openedhand.com>
 
+       Bug #919 - Replacement pango renderer (Neil Roberts)
+
+       * clutter/clutter-backend.h:
+       * clutter/clutter-backend.c:
+       (clutter_backend_set_font_options),
+       (clutter_backend_get_font_options): Add the ability to set
+       the cairo_font_options_t* for the backend at construction
+       time, so that backend implementations can have their own
+       options.
+
+       * clutter/clutter-color.c: Include pango/pango-attributes.h
+       for the pango_color_parse() function.
+
+       * clutter/clutter-label.c:
+       (clutter_label_ensure_layout),
+       (clutter_label_init), (clutter_label_set_text),
+       (clutter_label_set_font_name), (clutter_label_set_ellipsize),
+       (clutter_label_set_use_markup): Ensure that the cache is
+       always primed when the Label changes; this makes sure that
+       the cache is rebuilt outside the paint run, which should
+       make the painting perform better especially on embedded
+       devices.
+
+       * clutter/clutter-entry.c:
+       (clutter_entry_ensure_layout),
+       (clutter_entry_init), (clutter_entry_set_text),
+       (clutter_entry_set_font_name): Ditto as above.
+
+       * clutter/clutter-private.h:
+       * clutter/clutter-main.[ch]: Create the font-map inside the
+       main context; add two new functions:
+
+         clutter_clear_glyph_cache()
+         clutter_set_use_mipmapped_text()
+
+       that control the glyphs cache.
+
+       * clutter/pango/Makefile.am:
+       * clutter/pango/pangoclutter-fontmap.c:
+       * clutter/pango/pangoclutter-private.h:
+       * clutter/pango/pangoclutter-render.c:
+       * clutter/pango/pangoclutter.h: Rewrite the Pango renderer
+       using a PangoCairo context and saving the glyphs inside a
+       more efficient cache.
+
+       * configure.ac: Depend on pangocairo instead of pangoft2.
+
+2008-05-28  Emmanuele Bassi  <ebassi@openedhand.com>
+
        Bug 882 - Allow child properties for containers implementing the
                  ClutterContainer interface (Øyvind Kolås)
 
index 869c334..e98b540 100644 (file)
 #include "config.h"
 #endif
 
-#include "clutter-fixed.h"
 #include "clutter-backend.h"
-#include "clutter-private.h"
 #include "clutter-debug.h"
+#include "clutter-fixed.h"
+#include "clutter-private.h"
 
 G_DEFINE_ABSTRACT_TYPE (ClutterBackend, clutter_backend, G_TYPE_OBJECT);
 
@@ -58,6 +58,8 @@ struct _ClutterBackendPrivate
   guint double_click_distance;
 
   ClutterFixed resolution;
+
+  cairo_font_options_t *font_options;
 };
 
 static void
@@ -74,6 +76,8 @@ clutter_backend_dispose (GObject *gobject)
       clutter_context->events_queue = NULL;
     }
 
+  clutter_backend_set_font_options (CLUTTER_BACKEND (gobject), NULL);
+
   G_OBJECT_CLASS (clutter_backend_parent_class)->dispose (gobject);
 }
 
@@ -382,6 +386,10 @@ clutter_backend_set_resolution (ClutterBackend *backend,
   fixed_dpi = CLUTTER_FLOAT_TO_FIXED (dpi);
   if (priv->resolution != fixed_dpi)
     priv->resolution = fixed_dpi;
+
+  if (CLUTTER_CONTEXT ()->font_map)
+    pango_clutter_font_map_set_resolution (CLUTTER_CONTEXT ()->font_map,
+                                          CLUTTER_FIXED_TO_FLOAT (fixed_dpi));
 }
 
 /**
@@ -403,3 +411,49 @@ clutter_backend_get_resolution (ClutterBackend *backend)
 
   return CLUTTER_FIXED_TO_FLOAT (backend->priv->resolution);
 }
+
+void
+clutter_backend_set_font_options (ClutterBackend       *backend,
+                                  cairo_font_options_t *options)
+{
+  ClutterBackendPrivate *priv;
+
+  g_return_if_fail (CLUTTER_IS_BACKEND (backend));
+
+  priv = backend->priv;
+
+  if (priv->font_options != options)
+    {
+      if (priv->font_options)
+        cairo_font_options_destroy (priv->font_options);
+
+      if (options)
+        priv->font_options = cairo_font_options_copy (options);
+      else
+        priv->font_options = NULL;
+    }
+}
+
+cairo_font_options_t *
+clutter_backend_get_font_options (ClutterBackend *backend)
+{
+  ClutterBackendPrivate *priv;
+
+  g_return_val_if_fail (CLUTTER_IS_BACKEND (backend), NULL);
+
+  priv = backend->priv;
+
+  if (G_LIKELY (priv->font_options))
+    return priv->font_options;
+
+  priv->font_options = cairo_font_options_create ();
+
+  cairo_font_options_set_hint_style (priv->font_options,
+                                     CAIRO_HINT_STYLE_NONE);
+  cairo_font_options_set_subpixel_order (priv->font_options,
+                                         CAIRO_SUBPIXEL_ORDER_DEFAULT);
+  cairo_font_options_set_antialias (priv->font_options,
+                                    CAIRO_ANTIALIAS_DEFAULT);
+
+  return priv->font_options;
+}
index ffccf4e..ab5395c 100644 (file)
@@ -26,6 +26,7 @@
 #ifndef __CLUTTER_BACKEND_H__
 #define __CLUTTER_BACKEND_H__
 
+#include <cairo.h>
 #include <glib-object.h>
 #include <clutter/clutter-actor.h>
 #include <clutter/clutter-stage.h>
@@ -80,15 +81,18 @@ GType clutter_backend_get_type    (void) G_GNUC_CONST;
 
 ClutterBackend *clutter_get_default_backend (void);
 
-void    clutter_backend_set_resolution            (ClutterBackend *backend,
-                                                   gdouble         dpi);
-gdouble clutter_backend_get_resolution            (ClutterBackend *backend);
-void    clutter_backend_set_double_click_time     (ClutterBackend *backend,
-                                                   guint           msec);
-guint   clutter_backend_get_double_click_time     (ClutterBackend *backend);
-void    clutter_backend_set_double_click_distance (ClutterBackend *backend,
-                                                   guint           distance);
-guint   clutter_backend_get_double_click_distance (ClutterBackend *backend);
+void                  clutter_backend_set_resolution            (ClutterBackend       *backend,
+                                                                 gdouble               dpi);
+gdouble               clutter_backend_get_resolution            (ClutterBackend       *backend);
+void                  clutter_backend_set_double_click_time     (ClutterBackend       *backend,
+                                                                 guint                 msec);
+guint                 clutter_backend_get_double_click_time     (ClutterBackend       *backend);
+void                  clutter_backend_set_double_click_distance (ClutterBackend       *backend,
+                                                                 guint                 distance);
+guint                 clutter_backend_get_double_click_distance (ClutterBackend       *backend);
+void                  clutter_backend_set_font_options          (ClutterBackend       *backend,
+                                                                 cairo_font_options_t *options);
+cairo_font_options_t *clutter_backend_get_font_options          (ClutterBackend       *backend);
 
 G_END_DECLS
 
index d5bdbdf..8888a09 100644 (file)
@@ -34,6 +34,8 @@
 #include "config.h"
 #endif
 
+#include <pango/pango-attributes.h>
+
 #include "clutter-main.h"
 #include "clutter-color.h"
 #include "clutter-private.h"
index a205d03..1a79da3 100644 (file)
@@ -56,7 +56,6 @@
 G_DEFINE_TYPE (ClutterEntry, clutter_entry, CLUTTER_TYPE_ACTOR);
 
 /* Probably move into main */
-static PangoClutterFontMap  *_font_map = NULL;
 static PangoContext         *_context  = NULL;
 
 enum
@@ -289,6 +288,9 @@ clutter_entry_ensure_layout (ClutterEntry *entry, gint width)
        pango_layout_set_width (priv->layout, width * PANGO_SCALE);
       else
        pango_layout_set_width (priv->layout, -1);
+
+      /* Prime the cache for the layout */
+      pango_clutter_ensure_glyph_cache_for_layout (priv->layout);
     }
 }
 
@@ -858,9 +860,17 @@ clutter_entry_init (ClutterEntry *self)
 
   if (G_UNLIKELY (_context == NULL))
     {
-      _font_map = PANGO_CLUTTER_FONT_MAP (pango_clutter_font_map_new ());
-      pango_clutter_font_map_set_resolution (_font_map, resolution);
-      _context = pango_clutter_font_map_create_context (_font_map);
+      ClutterBackend *backend = clutter_get_default_backend ();
+      PangoClutterFontMap *font_map = CLUTTER_CONTEXT ()->font_map;
+      gdouble resolution;
+      cairo_font_options_t *font_options;
+
+      _context = pango_clutter_font_map_create_context (font_map);
+
+      pango_cairo_context_set_resolution (_context, resolution);
+
+      font_options = clutter_backend_get_font_options (backend);
+      pango_cairo_context_set_font_options (_context, font_options);
     }
 
   priv->alignment     = PANGO_ALIGN_LEFT;
@@ -1040,6 +1050,8 @@ clutter_entry_set_text (ClutterEntry *entry,
 
   clutter_entry_clear_layout (entry);
   clutter_entry_clear_cursor_position (entry);
+  /* Recreate the layout so the glyph cache will be primed */
+  clutter_entry_ensure_layout (entry, -1);
 
   if (CLUTTER_ACTOR_IS_VISIBLE (entry))
     clutter_actor_queue_redraw (CLUTTER_ACTOR (entry));
@@ -1123,6 +1135,8 @@ clutter_entry_set_font_name (ClutterEntry *entry,
   if (entry->priv->text && entry->priv->text[0] != '\0')
     {
       clutter_entry_clear_layout (entry);
+      /* Recreate the layout so the glyph cache will be primed */
+      clutter_entry_ensure_layout (entry, -1);
 
       if (CLUTTER_ACTOR_IS_VISIBLE (entry))
        clutter_actor_queue_redraw (CLUTTER_ACTOR (entry));
index 15c4929..a55d292 100644 (file)
@@ -48,7 +48,6 @@
 G_DEFINE_TYPE (ClutterLabel, clutter_label, CLUTTER_TYPE_ACTOR)
 
 /* Probably move into main */
-static PangoClutterFontMap  *_font_map = NULL;
 static PangoContext         *_context  = NULL;
 
 enum
@@ -268,6 +267,9 @@ clutter_label_ensure_layout (ClutterLabel *label)
       else
        pango_layout_set_width (priv->layout, raw_width > 0 ? CLUTTER_UNITS_TO_PANGO_UNIT (raw_width) 
                                                             : -1);
+
+      /* Prime the glyph cache */
+      pango_clutter_ensure_glyph_cache_for_layout (priv->layout);
     }
 
   CLUTTER_NOTE (ACTOR, "Label width set to %d pixels", width);
@@ -637,17 +639,18 @@ clutter_label_init (ClutterLabel *self)
 
   if (G_UNLIKELY (_context == NULL))
     {
-      ClutterBackend *backend;
+      ClutterBackend *backend = clutter_get_default_backend ();
+      PangoClutterFontMap *font_map = CLUTTER_CONTEXT ()->font_map;
       gdouble resolution;
+      cairo_font_options_t *font_options;
+
+      _context = pango_clutter_font_map_create_context (font_map);
 
-      backend = clutter_get_default_backend ();
       resolution = clutter_backend_get_resolution (backend);
-      if (resolution < 0)
-        resolution = 96.0;
+      pango_cairo_context_set_resolution (_context, resolution);
 
-      _font_map = PANGO_CLUTTER_FONT_MAP (pango_clutter_font_map_new ());
-      pango_clutter_font_map_set_resolution (_font_map, resolution);
-      _context = pango_clutter_font_map_create_context (_font_map);
+      font_options = clutter_backend_get_font_options (backend);
+      pango_cairo_context_set_font_options (_context, font_options);
     }
 
   priv->alignment     = PANGO_ALIGN_LEFT;
@@ -769,6 +772,9 @@ clutter_label_set_text (ClutterLabel *label,
   priv->text = g_strdup (text);
 
   clutter_label_clear_layout (label);   
+  /* Recreate the layout now so that the glyph cache will be primed
+     outside of the paint run */
+  clutter_label_ensure_layout (label);
 
   if (CLUTTER_ACTOR_IS_VISIBLE (CLUTTER_ACTOR(label)))
     clutter_actor_queue_redraw (CLUTTER_ACTOR(label));
@@ -847,7 +853,10 @@ clutter_label_set_font_name (ClutterLabel *label,
   if (label->priv->text && label->priv->text[0] != '\0')
     {
       clutter_label_clear_layout (label);      
-
+      /* Recreate the layout now so that the glyph cache will be
+        primed outside of the paint run */
+      clutter_label_ensure_layout (label);
+      
       if (CLUTTER_ACTOR_IS_VISIBLE (label))
        clutter_actor_queue_redraw (CLUTTER_ACTOR (label));
     }
@@ -947,6 +956,9 @@ clutter_label_set_ellipsize (ClutterLabel          *label,
       priv->ellipsize = mode;
 
       clutter_label_clear_layout (label);      
+      /* Recreate the layout now so that the glyph cache will be
+        primed outside of the paint run */
+      clutter_label_ensure_layout (label);
       
       if (CLUTTER_ACTOR_IS_VISIBLE (CLUTTER_ACTOR(label)))
        clutter_actor_queue_redraw (CLUTTER_ACTOR(label));
@@ -1214,6 +1226,9 @@ clutter_label_set_use_markup (ClutterLabel *label,
 
       priv->use_markup = setting;
       clutter_label_clear_layout (label);
+      /* Recreate the layout now so that the glyph cache will be
+        primed outside of the paint run */
+      clutter_label_ensure_layout (label);
 
       if (CLUTTER_ACTOR_IS_VISIBLE (CLUTTER_ACTOR (label)))
        clutter_actor_queue_redraw (CLUTTER_ACTOR (label));
index ba36113..0c8789d 100644 (file)
@@ -367,6 +367,9 @@ clutter_context_free (ClutterMainContext *context)
   clutter_id_pool_free (context->id_pool);
   context->id_pool = NULL;
 
+  g_object_unref (context->font_map);
+  context->font_map = NULL;
+
   /* XXX: The cleaning up of the event queue should be moved here from
           the backend base class. */
 
@@ -877,8 +880,9 @@ clutter_context_get_default (void)
   if (G_UNLIKELY(!ClutterCntx))
     {
       ClutterMainContext *ctx;
+      gdouble resolution;
 
-      ctx = g_new0 (ClutterMainContext, 1);
+      ClutterCntx = ctx = g_new0 (ClutterMainContext, 1);
       ctx->backend = g_object_new (_clutter_backend_impl_get_type (), NULL);
 
       ctx->is_initialized = FALSE;
@@ -889,7 +893,12 @@ clutter_context_get_default (void)
       g_timer_start (ctx->timer);
 #endif
 
-      ClutterCntx = ctx;
+      ctx->font_map = PANGO_CLUTTER_FONT_MAP (pango_clutter_font_map_new ());
+
+      resolution = clutter_backend_get_resolution (ctx->backend);
+      pango_clutter_font_map_set_resolution (ctx->font_map, resolution);
+
+      pango_clutter_font_map_set_use_mipmapping (ctx->font_map, TRUE);
     }
 
   return ClutterCntx;
@@ -983,8 +992,6 @@ pre_parse_hook (GOptionContext  *context,
 
   clutter_context = clutter_context_get_default ();
 
-  clutter_context->font_map = PANGO_FT2_FONT_MAP (pango_ft2_font_map_new ());
-  pango_ft2_font_map_set_resolution (clutter_context->font_map, 96.0, 96.0);
   clutter_context->id_pool = clutter_id_pool_new (256);
 
   backend = clutter_context->backend;
@@ -2071,3 +2078,38 @@ clutter_set_motion_events_frequency (guint frequency)
   /* never allow the motion events to exceed the default frame rate */
   context->motion_frequency = CLAMP (frequency, 1, clutter_default_fps);
 }
+
+/**
+ * clutter_clear_glyph_cache:
+ *
+ * Clears the internal cache of glyphs used by the Pango
+ * renderer. This will free up some memory and GL texture
+ * resources. The cache will be automatically refilled as more text is
+ * drawn.
+ * 
+ * Since: 0.8
+ */
+void
+clutter_clear_glyph_cache (void)
+{
+  if (CLUTTER_CONTEXT ()->font_map)
+    pango_clutter_font_map_clear_glyph_cache (CLUTTER_CONTEXT ()->font_map);
+}
+
+/**
+ * clutter_set_use_mipmapped_text:
+ * @value: %TRUE to enable mipmapping or %FALSE to disable.
+ *
+ * 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.
+ *
+ * Since: 0.8
+ */
+void
+clutter_set_use_mipmapped_text (gboolean value)
+{
+  if (CLUTTER_CONTEXT ()->font_map)
+    pango_clutter_font_map_set_use_mipmapping (CLUTTER_CONTEXT ()->font_map,
+                                              value);
+}
index de93e2e..535d6d9 100644 (file)
@@ -127,6 +127,9 @@ void             clutter_grab_keyboard               (ClutterActor *actor);
 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);
+
 G_END_DECLS
 
 #endif /* _HAVE_CLUTTER_MAIN_H */
index f462557..acf2be9 100644 (file)
@@ -38,8 +38,6 @@
 
 #include <glib.h>
 
-#include <pango/pangoft2.h>
-
 #include "clutter-backend.h"
 #include "clutter-event.h"
 #include "clutter-feature.h"
@@ -47,6 +45,7 @@
 #include "clutter-stage-manager.h"
 #include "clutter-stage-window.h"
 #include "clutter-stage.h"
+#include "pango/pangoclutter.h"
 
 G_BEGIN_DECLS
 
@@ -77,7 +76,6 @@ struct _ClutterMainContext
                                           system backend */
   ClutterStageManager *stage_manager;  /* stages */
   GQueue          *events_queue;       /* the main event queue */
-  PangoFT2FontMap *font_map;
   
   guint            is_initialized : 1;  
   GTimer          *timer;             /* Used for debugging scheduler */
@@ -110,6 +108,7 @@ or enter/leave events */
   gint fb_r_mask, fb_g_mask, fb_b_mask;
   gint fb_r_mask_used, fb_g_mask_used, fb_b_mask_used;
 
+  PangoClutterFontMap *font_map;       /* Global font map */
 };
 
 #define CLUTTER_CONTEXT()      (clutter_context_get_default ())
index 41439d2..4a46575 100644 (file)
@@ -1,16 +1,17 @@
-source_c = pangoclutter-font.c     \
-           pangoclutter-fontmap.c  \
-           pangoclutter-render.c
+source_c = pangoclutter-fontmap.c  \
+           pangoclutter-render.c   \
+          pangoclutter-glyph-cache.c
 
 source_h = pangoclutter.h
 
-source_h_priv = pangoclutter-private.h
+source_h_priv = pangoclutter-private.h      \
+               pangoclutter-glyph-cache.h
 
 noinst_LTLIBRARIES = libpangoclutter.la
 
 libpangoclutter_la_SOURCES = $(source_c)     \
-                            $(source_h)     \
-                             $(source_h_priv)
+                            $(source_h)     \
+                            $(source_h_priv)
 
 INCLUDES = \
        @GCC_FLAGS@ @CLUTTER_CFLAGS@                    \
index 4623efa..72366fe 100644 (file)
-/* Pango
- * Clutter fonts handling
+/*
+ * Clutter.
  *
- * Copyright (C) 2000 Red Hat Software
- * Copyright (C) 2000 Tor Lillqvist
- * Copyright (C) 2006 Marc Lehmann <pcg@goof.com>
+ * An OpenGL based 'interactive canvas' library.
  *
- * This file is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
+ * Authored By Matthew Allum  <mallum@openedhand.com>
+ *
+ * Copyright (C) 2008 OpenedHand
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
  * version 2 of the License, or (at your option) any later version.
  *
- * This file is distributed in the hope that it will be useful,
+ * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.         See the GNU
- * Library General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU Library General Public
+ * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the
  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  * Boston, MA 02111-1307, USA.
  */
 
-#include <glib.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-
-#include "pangoclutter.h"
-#include "pangoclutter-private.h"
-
-
-#include <pango/pangofc-font.h>
-#include <pango/pangofc-fontmap.h>
-
-struct _PangoClutterFontMap
-{
-  PangoFcFontMap parent_instance;
-
-  FT_Library library;
-
-  double dpi;
-
-  /* Function to call on prepared patterns to do final
-   * config tweaking.
-   */
-  PangoClutterSubstituteFunc substitute_func;
-  gpointer substitute_data;
-  GDestroyNotify substitute_destroy;
-
-  PangoRenderer *renderer;
-};
-
-struct _PangoClutterFontMapClass
-{
-  PangoFcFontMapClass parent_class;
-};
-
-G_DEFINE_TYPE (PangoClutterFontMap, pango_clutter_font_map, PANGO_TYPE_FC_FONT_MAP)
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
 
-static void
-pango_clutter_font_map_finalize (GObject *object)
-{
-  PangoClutterFontMap *fontmap = PANGO_CLUTTER_FONT_MAP (object);
-  
-  if (fontmap->renderer)
-    g_object_unref (fontmap->renderer);
+/* This is needed to get the Pango headers to export stuff needed to
+   subclass */
+#ifndef PANGO_ENABLE_BACKEND
+#define PANGO_ENABLE_BACKEND 1
+#endif
 
-  if (fontmap->substitute_destroy)
-    fontmap->substitute_destroy (fontmap->substitute_data);
+#include <pango/pango-fontmap.h>
+#include <pango/pangocairo.h>
+#include <pango/pango-renderer.h>
 
-  FT_Done_FreeType (fontmap->library);
+#include "pangoclutter.h"
+#include "pangoclutter-private.h"
 
-  G_OBJECT_CLASS (pango_clutter_font_map_parent_class)->finalize (object);
-}
+static GQuark pango_clutter_font_map_get_renderer_key (void) G_GNUC_CONST;
 
 PangoFontMap *
 pango_clutter_font_map_new (void)
 {
-  PangoClutterFontMap *fontmap;
-  FT_Error error;
-  
-  /* Make sure that the type system is initialized */
-  g_type_init ();
-  
-  fontmap = g_object_new (PANGO_TYPE_CLUTTER_FONT_MAP, NULL);
-  
-  error = FT_Init_FreeType (&fontmap->library);
-  if (error != FT_Err_Ok)
-    g_critical ("pango_clutter_font_map_new: Could not initialize freetype");
-
-  return (PangoFontMap *)fontmap;
+  return pango_cairo_font_map_new ();
 }
 
-void
-pango_clutter_font_map_set_default_substitute (PangoClutterFontMap        *fontmap,
-                                          PangoClutterSubstituteFunc  func,
-                                          gpointer                data,
-                                          GDestroyNotify          notify)
+PangoContext *
+pango_clutter_font_map_create_context (PangoClutterFontMap *fm)
 {
-  if (fontmap->substitute_destroy)
-    fontmap->substitute_destroy (fontmap->substitute_data);
-
-  fontmap->substitute_func = func;
-  fontmap->substitute_data = data;
-  fontmap->substitute_destroy = notify;
-  
-  pango_fc_font_map_cache_clear (PANGO_FC_FONT_MAP (fontmap));
-}
+  g_return_val_if_fail (PANGO_CLUTTER_IS_FONT_MAP (fm), NULL);
 
-/**
- * pango_clutter_font_map_substitute_changed:
- * @fontmap: a #PangoClutterFontmap
- * 
- * Call this function any time the results of the
- * default substitution function set with
- * pango_clutter_font_map_set_default_substitute() change.
- * That is, if your subsitution function will return different
- * results for the same input pattern, you must call this function.
- *
- * Since: 1.2
- **/
-void
-pango_clutter_font_map_substitute_changed (PangoClutterFontMap *fontmap)
-{
-  pango_fc_font_map_cache_clear (PANGO_FC_FONT_MAP (fontmap));
+  /* We can just directly use the pango context from the Cairo font
+     map */
+  return pango_cairo_font_map_create_context (PANGO_CAIRO_FONT_MAP (fm));
 }
 
-/**
- * pango_clutter_font_map_create_context:
- * @fontmap: a #PangoClutterFontmap
- * 
- * Create a #PangoContext for the given fontmap.
- * 
- * Return value: the newly created context; free with g_object_unref().
- *
- * Since: 1.2
- **/
-PangoContext *
-pango_clutter_font_map_create_context (PangoClutterFontMap *fontmap)
+PangoRenderer *
+_pango_clutter_font_map_get_renderer (PangoClutterFontMap *fm)
 {
-  g_return_val_if_fail (PANGO_CLUTTER_IS_FONT_MAP (fontmap), NULL);
-  
-  return pango_fc_font_map_create_context (PANGO_FC_FONT_MAP (fontmap));
-}
+  PangoRenderer *renderer;
 
-FT_Library
-_pango_clutter_font_map_get_library (PangoFontMap *fontmap_)
-{
-  PangoClutterFontMap *fontmap = (PangoClutterFontMap *)fontmap_;
-  
-  return fontmap->library;
-}
+  /* We want to keep a cached pointer to the renderer from the font
+     map instance but as we don't have a proper subclass we have to
+     store it in the object data instead */
 
-void
-pango_clutter_font_map_set_resolution (PangoClutterFontMap *fontmap,
-                                       double               dpi)
-{
-  g_return_if_fail (PANGO_CLUTTER_IS_FONT_MAP (fontmap));
+  renderer = g_object_get_qdata (G_OBJECT (fm),
+                                pango_clutter_font_map_get_renderer_key ());
 
-  fontmap->dpi = dpi;
+  if (G_UNLIKELY (renderer == NULL))
+    {
+      renderer = g_object_new (PANGO_CLUTTER_TYPE_RENDERER, NULL);
+      g_object_set_qdata_full (G_OBJECT (fm),
+                              pango_clutter_font_map_get_renderer_key (),
+                              renderer,
+                              g_object_unref);
+    }
 
-  pango_clutter_font_map_substitute_changed (fontmap);
+  return renderer;
 }
 
-/**
- * _pango_clutter_font_map_get_renderer:
- * @fontmap: a #PangoClutterFontmap
- * 
- * Gets the singleton PangoClutterRenderer for this fontmap.
- * 
- * Return value: 
- **/
-PangoRenderer *
-_pango_clutter_font_map_get_renderer (PangoClutterFontMap *fontmap)
+void
+pango_clutter_font_map_set_resolution (PangoClutterFontMap *font_map,
+                                      double               dpi)
 {
-  if (!fontmap->renderer)
-    fontmap->renderer = g_object_new (PANGO_TYPE_CLUTTER_RENDERER, NULL);
+  g_return_if_fail (PANGO_CLUTTER_IS_FONT_MAP (font_map));
 
-  return fontmap->renderer;
+  pango_cairo_font_map_set_resolution (PANGO_CAIRO_FONT_MAP (font_map), dpi);
 }
 
-static void
-pango_clutter_font_map_default_substitute (PangoFcFontMap *fcfontmap,
-                                      FcPattern      *pattern)
+void
+pango_clutter_font_map_clear_glyph_cache (PangoClutterFontMap *fm)
 {
-  PangoClutterFontMap *fontmap = PANGO_CLUTTER_FONT_MAP (fcfontmap);
-
-  FcConfigSubstitute (NULL, pattern, FcMatchPattern);
-
-  if (fontmap->substitute_func)
-    fontmap->substitute_func (pattern, fontmap->substitute_data);
-
-#if 0
-  FcValue v;
-  if (FcPatternGet (pattern, FC_DPI, 0, &v) == FcResultNoMatch)
-    FcPatternAddDouble (pattern, FC_DPI, fontmap->dpi_y);
-#endif
+  PangoRenderer *renderer;
 
-   /* Turn off hinting, since we most of the time are not using the glyphs
-    * from our cache at their nativly rendered resolution
-    */
-   FcPatternDel (pattern, FC_HINTING);
-   FcPatternAddBool (pattern, FC_HINTING, FALSE);
+  renderer = _pango_clutter_font_map_get_renderer (fm);
 
-  FcDefaultSubstitute (pattern);
+  _pango_clutter_renderer_clear_glyph_cache (PANGO_CLUTTER_RENDERER (renderer));
 }
 
-static PangoFcFont *
-pango_clutter_font_map_new_font (PangoFcFontMap  *fcfontmap,
-                               FcPattern       *pattern)
+void
+pango_clutter_font_map_set_use_mipmapping (PangoClutterFontMap *fm,
+                                          gboolean             value)
 {
-  return (PangoFcFont *)_pango_clutter_font_new (PANGO_CLUTTER_FONT_MAP (fcfontmap), pattern);
-}
+  PangoClutterRenderer *renderer;
 
-static double
-pango_clutter_font_map_get_resolution (PangoFcFontMap *fcfontmap,
-                                       PangoContext   *context)
-{
-  return ((PangoClutterFontMap *)fcfontmap)->dpi;
-}
+  renderer = PANGO_CLUTTER_RENDERER (_pango_clutter_font_map_get_renderer (fm));
 
-static void
-pango_clutter_font_map_class_init (PangoClutterFontMapClass *class)
-{
-  GObjectClass *gobject_class = G_OBJECT_CLASS (class);
-  PangoFcFontMapClass *fcfontmap_class = PANGO_FC_FONT_MAP_CLASS (class);
-  
-  gobject_class->finalize = pango_clutter_font_map_finalize;
-  fcfontmap_class->default_substitute = pango_clutter_font_map_default_substitute;
-  fcfontmap_class->new_font = pango_clutter_font_map_new_font;
-  fcfontmap_class->get_resolution = pango_clutter_font_map_get_resolution;
+  _pango_clutter_renderer_set_use_mipmapping (renderer, value);
 }
 
-static void
-pango_clutter_font_map_init (PangoClutterFontMap *fontmap)
+static GQuark
+pango_clutter_font_map_get_renderer_key (void)
 {
-  fontmap->library = NULL;
-  fontmap->dpi = 96.0;
-}
+  static GQuark renderer_key = 0;
+
+  if (G_UNLIKELY (renderer_key == 0))
+      renderer_key = g_quark_from_static_string ("PangoClutterFontMap");
 
+  return renderer_key;
+}
index 4e39339..549b23f 100644 (file)
-/* Pango
- * pangoclutter-private.h: private symbols for Clutter backend
+/*
+ * Clutter.
  *
- * Copyright (C) 2006 Matthew Allum <mallum@o-hand.com>
+ * An OpenGL based 'interactive canvas' library.
  *
- * This file is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
+ * Authored By Matthew Allum  <mallum@openedhand.com>
+ *
+ * Copyright (C) 2008 OpenedHand
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
  * version 2 of the License, or (at your option) any later version.
  *
- * This file is distributed in the hope that it will be useful,
+ * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.         See the GNU
- * Library General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU Library General Public
+ * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the
  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  * Boston, MA 02111-1307, USA.
  */
-#ifndef __PANGOCLUTTER_PRIVATE_H__
-#define __PANGOCLUTTER_PRIVATE_H__
-
-#include "pangoclutter.h"
-#include <pango/pango-renderer.h>
-#include <glib-object.h>
-#include <pango/pangofc-decoder.h>
-
-/* Defines duped - fun,fun.. */
-
-#ifndef PANGO_GLYPH_EMPTY
-#define PANGO_GLYPH_EMPTY           ((PangoGlyph)0x0FFFFFFF)
-#endif
-#ifndef PANGO_GLYPH_UNKNOWN_FLAG
-#define PANGO_GLYPH_UNKNOWN_FLAG ((PangoGlyph)0x10000000)
-#endif
-#ifndef PANGO_UNKNOWN_GLYPH_WIDTH
-#define PANGO_UNKNOWN_GLYPH_WIDTH 10
-#endif
-#ifndef PANGO_UNKNOWN_GLYPH_HEIGHT
-#define PANGO_UNKNOWN_GLYPH_HEIGHT 14
-#endif
-
-#define PANGO_SCALE_26_6 (PANGO_SCALE / (1<<6))
-
-/* We only use the PANGO_SCALE_26_6 macro for scaling font size.
- * Font sizes are normally given in points with at most one single
- * decimal place fraction. If we do not do the rounding here, we will
- * be suffering from an error < 0.016pt, which is entirely negligeable
- * as far as font sizes are concerned.
- */
-#if 0
-#define PANGO_PIXELS_26_6(d)                            \
-  (((d) >= 0) ?                                         \
-   ((d) + PANGO_SCALE_26_6 / 2) / PANGO_SCALE_26_6 :    \
-   ((d) - PANGO_SCALE_26_6 / 2) / PANGO_SCALE_26_6)
-#else
-#define PANGO_PIXELS_26_6(d)                            \
-   (d / PANGO_SCALE_26_6)
-#endif
-
-#define PANGO_UNITS_26_6(d) (PANGO_SCALE_26_6 * (d))
-
-#define PANGO_TYPE_CLUTTER_FONT (pango_clutter_font_get_type ())
-
-#define PANGO_CLUTTER_FONT(object)                                   \
-               (G_TYPE_CHECK_INSTANCE_CAST ((object),                \
-                                           PANGO_TYPE_CLUTTER_FONT, \
-                                           PangoClutterFont))
-#define PANGO_CLUTTER_IS_FONT(object)                                  \
-               (G_TYPE_CHECK_INSTANCE_TYPE ((object), PANGO_TYPE_CLUTTER_FONT))
 
-typedef struct _PangoClutterFont       PangoClutterFont;
-typedef struct _PangoClutterGlyphInfo  PangoClutterGlyphInfo;
+#ifndef _HAVE_PANGO_CLUTTER_PRIVATE_H
+#define _HAVE_PANGO_CLUTTER_PRIVATE_H
 
-struct _PangoClutterFont
-{
-  PangoFcFont    font;
-  FT_Face        face;
-  int            load_flags;
-  int            size;
-  GSList        *metrics_by_lang;
-  GHashTable    *glyph_info;
-  GDestroyNotify glyph_cache_destroy;
-};
-
-struct _PangoClutterGlyphInfo
-{
-  PangoRectangle logical_rect;
-  PangoRectangle ink_rect;
-  void          *cached_glyph;
-};
-
-PangoGlyph
-pango_clutter_get_unknown_glyph (PangoFont *font);
-
-GType pango_clutter_font_get_type (void);
-
-PangoClutterFont *
-_pango_clutter_font_new (PangoClutterFontMap *fontmap, 
-                        FcPattern           *pattern);
-FT_Face
-pango_clutter_font_get_face (PangoFont *font);
-
-FT_Library 
-_pango_clutter_font_map_get_library (PangoFontMap *fontmap);
-
-void *
-_pango_clutter_font_get_cache_glyph_data (PangoFont *font, 
-                                         int        glyph_index);
-void 
-_pango_clutter_font_set_cache_glyph_data (PangoFont *font, 
-                                         int        glyph_index, 
-                                         void      *cached_glyph);
-void 
-_pango_clutter_font_set_glyph_cache_destroy (PangoFont    *font, 
-                                            GDestroyNotify destroy_notify);
-
-/* Renderer  */
-
-typedef struct _PangoClutterRenderer     PangoClutterRenderer;
-
-#define PANGO_TYPE_CLUTTER_RENDERER  (pango_clutter_renderer_get_type())
-
-#define PANGO_CLUTTER_RENDERER(object)                               \
-           (G_TYPE_CHECK_INSTANCE_CAST ((object),                    \
-                                        PANGO_TYPE_CLUTTER_RENDERER, \
-                                       PangoClutterRenderer))
+#include "pangoclutter.h"
 
-#define PANGO_IS_CLUTTER_RENDERER(object)                            \
-           (G_TYPE_CHECK_INSTANCE_TYPE ((object), PANGO_TYPE_CLUTTER_RENDERER))
+G_BEGIN_DECLS
 
-GType pango_clutter_renderer_get_type (void);
+PangoRenderer *_pango_clutter_font_map_get_renderer (PangoClutterFontMap *fm);
 
-PangoRenderer *
-_pango_clutter_font_map_get_renderer (PangoClutterFontMap *fontmap);
+void _pango_clutter_renderer_clear_glyph_cache (PangoClutterRenderer *renderer);
 
+void _pango_clutter_renderer_set_use_mipmapping (PangoClutterRenderer *renderer,
+                                                gboolean              value);
 
-/* HACK make this public to avoid a mass of re-implementation*/
-void 
-pango_fc_font_get_raw_extents (PangoFcFont    *font, 
-                              FT_Int32        load_flags, 
-                              PangoGlyph      glyph, 
-                              PangoRectangle *ink_rect, 
-                              PangoRectangle *logical_rect);
+G_END_DECLS
 
-#endif
+#endif /* _HAVE_PANGO_CLUTTER_H */
index c65e047..f54b095 100644 (file)
@@ -1,22 +1,23 @@
-/* Pango
- * Rendering routines to Clutter
+/*
+ * Clutter.
+ *
+ * An OpenGL based 'interactive canvas' library.
+ *
+ * Authored By Matthew Allum  <mallum@openedhand.com>
  *
- * Copyright (C) 2006 Matthew Allum <mallum@o-hand.com>
- * Copyright (C) 2006 Marc Lehmann <pcg@goof.com>
- * Copyright (C) 2004 Red Hat Software
- * Copyright (C) 2000 Tor Lillqvist
+ * Copyright (C) 2008 OpenedHand
  *
- * This file is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
  * version 2 of the License, or (at your option) any later version.
  *
- * This file is distributed in the hope that it will be useful,
+ * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.         See the GNU
- * Library General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU Library General Public
+ * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the
  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  * Boston, MA 02111-1307, USA.
 #include "config.h"
 #endif
 
-#include <math.h>
+#ifndef PANGO_ENABLE_BACKEND
+#define PANGO_ENABLE_BACKEND 1
+#endif
+
+#include <pango/pango-fontmap.h>
+#include <pango/pangocairo.h>
+#include <pango/pango-renderer.h>
+#include <cairo/cairo.h>
 
 #include "pangoclutter.h"
 #include "pangoclutter-private.h"
+#include "pangoclutter-glyph-cache.h"
 #include "../clutter-debug.h"
-
 #include "cogl/cogl.h"
 
-/*
- * Texture cache support code
- */
+struct _PangoClutterRenderer
+{
+  PangoRenderer parent_instance;
 
-#define TC_WIDTH  256
-#define TC_HEIGHT 256
-#define TC_ROUND  4
+  /* The color to draw the glyphs with */
+  ClutterColor color;
 
-typedef struct {
-  CoglHandle cogl_tex;
-  int x, y, w, h;
-} tc_area;
+  /* Two caches of glyphs as textures, one with mipmapped textures and
+     one without */
+  PangoClutterGlyphCache *glyph_cache;
+  PangoClutterGlyphCache *mipmapped_glyph_cache;
 
-typedef struct tc_texture {
-  struct tc_texture *next;
-  CoglHandle cogl_tex;
-  int avail;
-} tc_texture;
+  gboolean use_mipmapping;
+};
 
-typedef struct tc_slice {
-  CoglHandle cogl_tex;
-  int avail, y;
-} tc_slice;
+struct _PangoClutterRendererClass
+{
+  PangoRendererClass class_instance;
+};
 
-static int tc_generation = 0;
-static tc_slice slices[TC_HEIGHT / TC_ROUND];
-static tc_texture *first_texture;
+static void pango_clutter_renderer_finalize (GObject *object);
+static void pango_clutter_renderer_draw_glyph (PangoRenderer *renderer,
+                                              PangoFont     *font,
+                                              PangoGlyph     glyph,
+                                              double         x,
+                                              double         y);
+static void pango_clutter_renderer_draw_rectangle (PangoRenderer    *renderer,
+                                                  PangoRenderPart   part,
+                                                  int               x,
+                                                  int               y,
+                                                  int               width,
+                                                  int               height);
+static void pango_clutter_renderer_draw_trapezoid (PangoRenderer    *renderer,
+                                                  PangoRenderPart   part,
+                                                  double            y1,
+                                                  double            x11,
+                                                  double            x21,
+                                                  double            y2,
+                                                  double            x12,
+                                                  double            x22);
+static void pango_clutter_renderer_prepare_run (PangoRenderer  *renderer,
+                                               PangoLayoutRun *run);
+
+static GObjectClass *parent_class = NULL;
+
+G_DEFINE_TYPE (PangoClutterRenderer, pango_clutter_renderer,
+              PANGO_TYPE_RENDERER);
 
 static void
-tc_clear ()
+pango_clutter_renderer_init (PangoClutterRenderer *priv)
 {
-  int i;
-
-  for (i = TC_HEIGHT / TC_ROUND; i--; )
-    slices [i].cogl_tex = COGL_INVALID_HANDLE;
-
-  while (first_texture)
-    {
-      tc_texture *next = first_texture->next;
-      cogl_texture_unref (first_texture->cogl_tex);
-      g_slice_free (tc_texture, first_texture);
-      first_texture = next;
-    }
-
-  ++tc_generation;
+  priv->glyph_cache = pango_clutter_glyph_cache_new (FALSE);
+  priv->mipmapped_glyph_cache = pango_clutter_glyph_cache_new (TRUE);
+  priv->use_mipmapping = FALSE;
 }
 
 static void
-tc_get (tc_area *area, int width, int height)
+pango_clutter_renderer_class_init (PangoClutterRendererClass *klass)
 {
-  int       slice_height;
-  tc_slice *slice;
-
-  area->w = width;
-  area->h = height;
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  PangoRendererClass *renderer_class = PANGO_RENDERER_CLASS (klass);
 
-  /* Provide for blank rows/columns of pixels between adjecant glyphs in the
-   * texture cache to avoid bilinear interpolation spillage at edges of glyphs.
-   */
-  width += 1;
-  height += 1;
+  parent_class = g_type_class_peek_parent (klass);
 
-  slice_height = MIN (height + TC_ROUND - 1, TC_HEIGHT) & ~(TC_ROUND - 1);
-  slice = slices + slice_height / TC_ROUND;
+  object_class->finalize = pango_clutter_renderer_finalize;
 
-  width = MIN (width, TC_WIDTH);
+  renderer_class->draw_glyph = pango_clutter_renderer_draw_glyph;
+  renderer_class->draw_rectangle = pango_clutter_renderer_draw_rectangle;
+  renderer_class->draw_trapezoid = pango_clutter_renderer_draw_trapezoid;
+  renderer_class->prepare_run = pango_clutter_renderer_prepare_run;
+}
 
-  if (slice->cogl_tex == COGL_INVALID_HANDLE || slice->avail < width)
-    {
-      /* try to find a texture with enough space */
-      tc_texture *tex, *match = 0;
+static void
+pango_clutter_renderer_finalize (GObject *object)
+{
+  PangoClutterRenderer *priv = PANGO_CLUTTER_RENDERER (object);
 
-      for (tex = first_texture; tex; tex = tex->next)
-        if (tex->avail >= slice_height && (!match || match->avail > tex->avail))
-          match = tex;
+  pango_clutter_glyph_cache_free (priv->mipmapped_glyph_cache);
+  pango_clutter_glyph_cache_free (priv->glyph_cache);
 
-      /* create a new texture if necessary */
-      if (!match)
-        {
-         CLUTTER_NOTE (PANGO, "creating new texture %i x %i",
-                       TC_WIDTH, TC_HEIGHT);
-
-          match = g_slice_new (tc_texture);
-          match->next = first_texture;
-          first_texture = match;
-          match->avail = TC_HEIGHT;
-
-         match->cogl_tex = cogl_texture_new_with_size (TC_WIDTH, TC_HEIGHT, 0, TRUE,
-                                                        COGL_PIXEL_FORMAT_A_8);
-         
-         /* We use mipmapping instead of just CGL_LINEAR here
-           * which allows rendering of glyphs to look nice even at
-           * scales far below 50%.
-          */
-          cogl_texture_set_filters (match->cogl_tex,
-                                    CGL_LINEAR_MIPMAP_LINEAR,
-                                    CGL_LINEAR);
-        }
+  G_OBJECT_CLASS (parent_class)->finalize (object);
+}
 
-      match->avail -= slice_height;
+void
+pango_clutter_render_layout_subpixel (PangoLayout  *layout,
+                                     int           x,
+                                     int           y,
+                                     ClutterColor *color,
+                                     int           flags)
+{
+  PangoContext         *context;
+  PangoFontMap         *font_map;
+  PangoRenderer        *renderer;
+  PangoClutterRenderer *priv;
 
-      slice->cogl_tex = match->cogl_tex;
-      slice->avail    = TC_WIDTH;
-      slice->y        = match->avail;
-    }
+  context = pango_layout_get_context (layout);
+  font_map = pango_context_get_font_map (context);
+  g_return_if_fail (PANGO_CLUTTER_IS_FONT_MAP (font_map));
+  renderer = _pango_clutter_font_map_get_renderer
+    (PANGO_CLUTTER_FONT_MAP (font_map));
+  priv = PANGO_CLUTTER_RENDERER (renderer);
 
-  slice->avail -= width;
+  priv->color = *color;
 
-  area->cogl_tex = slice->cogl_tex;
-  area->x        = slice->avail;
-  area->y        = slice->y;
+  pango_renderer_draw_layout (renderer, layout, x, y);
 }
 
-static void
-tc_put (tc_area *area)
+void
+pango_clutter_render_layout (PangoLayout  *layout,
+                            int           x,
+                            int           y,
+                            ClutterColor *color,
+                            int           flags)
 {
-  /* our management is too primitive to support this operation yet */
+  return pango_clutter_render_layout_subpixel (layout,
+                                              x * PANGO_SCALE,
+                                              y * PANGO_SCALE,
+                                              color, flags);
 }
 
-/*******************/
-
-
-#define PANGO_CLUTTER_RENDERER_CLASS(klass)                       \
-          (G_TYPE_CHECK_CLASS_CAST ((klass),                      \
-                                    PANGO_TYPE_CLUTTER_RENDERER,  \
-                                    PangoClutterRendererClass))
+void
+pango_clutter_render_layout_line (PangoLayoutLine  *line,
+                                 int               x,
+                                 int               y,
+                                 ClutterColor     *color)
+{
+  PangoContext         *context;
+  PangoFontMap         *font_map;
+  PangoRenderer        *renderer;
+  PangoClutterRenderer *priv;
 
-#define PANGO_IS_CLUTTER_RENDERER_CLASS(klass)                    \
-          (G_TYPE_CHECK_CLASS_TYPE ((klass), PANGO_TYPE_CLUTTER_RENDERER))
+  context = pango_layout_get_context (line->layout);
+  font_map = pango_context_get_font_map (context);
+  g_return_if_fail (PANGO_CLUTTER_IS_FONT_MAP (font_map));
+  renderer = _pango_clutter_font_map_get_renderer
+    (PANGO_CLUTTER_FONT_MAP (font_map));
+  priv = PANGO_CLUTTER_RENDERER (renderer);
 
-#define PANGO_CLUTTER_RENDERER_GET_CLASS(obj)                      \
-          (G_TYPE_INSTANCE_GET_CLASS ((obj),                       \
-                                     PANGO_TYPE_CLUTTER_RENDERER, \
-                                     PangoClutterRendererClass))
+  priv->color = *color;
 
-typedef struct {
-  PangoRendererClass parent_class;
-} PangoClutterRendererClass;
+  pango_renderer_draw_layout_line (renderer, line, x, y);
+}
 
-struct _PangoClutterRenderer
+void
+_pango_clutter_renderer_clear_glyph_cache (PangoClutterRenderer *renderer)
 {
-  PangoRenderer parent_instance;
-  ClutterColor  color;
-  int           flags;
-};
-
-G_DEFINE_TYPE (PangoClutterRenderer,   \
-              pango_clutter_renderer, \
-              PANGO_TYPE_RENDERER)
+  pango_clutter_glyph_cache_clear (renderer->glyph_cache);
+  pango_clutter_glyph_cache_clear (renderer->mipmapped_glyph_cache);
+}
 
-typedef struct
+void
+_pango_clutter_renderer_set_use_mipmapping (PangoClutterRenderer *renderer,
+                                           gboolean value)
 {
-  guint8 *bitmap;
-  int     width, stride, height, top, left;
-} Glyph;
+  renderer->use_mipmapping = value;
+}
 
-static void *
-temp_buffer (size_t size)
+static PangoClutterGlyphCacheValue *
+pango_clutter_renderer_get_cached_glyph (PangoRenderer *renderer,
+                                        PangoFont     *font,
+                                        PangoGlyph     glyph)
 {
-  static char *buffer;
-  static size_t alloc;
+  PangoClutterRenderer *priv = PANGO_CLUTTER_RENDERER (renderer);
+  PangoClutterGlyphCacheValue *value;
+  PangoClutterGlyphCache *glyph_cache;
 
-  if (size > alloc)
+  glyph_cache = priv->use_mipmapping
+    ? priv->mipmapped_glyph_cache : priv->glyph_cache;
+
+  if ((value = pango_clutter_glyph_cache_lookup (glyph_cache,
+                                                font,
+                                                glyph)) == NULL)
     {
-      size = (size + 4095) & ~4095;
-      g_free (buffer);
-      alloc = size;
-      buffer = g_malloc (size);
+      cairo_surface_t *surface;
+      cairo_t *cr;
+      cairo_scaled_font_t *scaled_font;
+      PangoRectangle ink_rect;
+      cairo_glyph_t cairo_glyph;
+
+      pango_font_get_glyph_extents (font, glyph, &ink_rect, NULL);
+      pango_extents_to_pixels (&ink_rect, NULL);
+
+      surface = cairo_image_surface_create (CAIRO_FORMAT_A8,
+                                           ink_rect.width,
+                                           ink_rect.height);
+      cr = cairo_create (surface);
+
+      scaled_font = pango_cairo_font_get_scaled_font (PANGO_CAIRO_FONT (font));
+      cairo_set_scaled_font (cr, scaled_font);
+
+      cairo_glyph.x = -ink_rect.x;
+      cairo_glyph.y = -ink_rect.y;
+      /* The PangoCairo glyph numbers directly map to Cairo glyph
+        numbers */
+      cairo_glyph.index = glyph;
+      cairo_show_glyphs (cr, &cairo_glyph, 1);
+
+      cairo_destroy (cr);
+      cairo_surface_flush (surface);
+
+      /* Copy the glyph to the cache */
+      value = pango_clutter_glyph_cache_set
+       (glyph_cache, font, glyph,
+        cairo_image_surface_get_data (surface),
+        cairo_image_surface_get_width (surface),
+        cairo_image_surface_get_height (surface),
+        cairo_image_surface_get_stride (surface),
+        ink_rect.x, ink_rect.y);
+
+      cairo_surface_destroy (surface);
+
+      CLUTTER_NOTE (PANGO, "cache fail    %i", glyph);
     }
+  else
+    CLUTTER_NOTE (PANGO, "cache success %i", glyph);
 
-  return buffer;
+  return value;
 }
 
-static void
-render_box (Glyph *glyph, int width, int height, int top)
+void
+pango_clutter_ensure_glyph_cache_for_layout (PangoLayout *layout)
 {
-  int i;
-  int left = 0;
-
-  if (height > 2)
-    {
-      height -= 2;
-      top++;
-    }
-
-  if (width > 2)
+  PangoContext    *context;
+  PangoFontMap    *fontmap;
+  PangoRenderer   *renderer;
+  PangoLayoutIter *iter;
+  g_return_if_fail (PANGO_IS_LAYOUT (layout));
+  context = pango_layout_get_context (layout);
+  fontmap = pango_context_get_font_map (context);
+  g_return_if_fail (PANGO_CLUTTER_IS_FONT_MAP (fontmap));
+  renderer = _pango_clutter_font_map_get_renderer
+    (PANGO_CLUTTER_FONT_MAP (fontmap));
+  if ((iter = pango_layout_get_iter (layout)) == NULL)
+    return;
+  do
     {
-      width -= 2;
-      left++;
+      PangoLayoutLine *line;
+      GSList *l;
+      line = pango_layout_iter_get_line_readonly (iter);
+      for (l = line->runs; l; l = l->next)
+        {
+          PangoLayoutRun *run = l->data;
+          PangoGlyphString *glyphs = run->glyphs;
+         int i;
+          for (i = 0; i < glyphs->num_glyphs; i++)
+            {
+              PangoGlyphInfo *gi = &glyphs->glyphs[i];
+             pango_clutter_renderer_get_cached_glyph (renderer,
+                                                      run->item->analysis.font,
+                                                      gi->glyph);
+            }
+        }
     }
+  while (pango_layout_iter_next_line (iter));
+  pango_layout_iter_free (iter);
+}
 
-  glyph->stride = (width + 3) & ~3;
-  glyph->width  = width;
-  glyph->height = height;
-  glyph->top    = top;
-  glyph->left   = left;
-
-  glyph->bitmap = temp_buffer (width * height);
-  memset (glyph->bitmap, 0, glyph->stride * height);
-
-  for (i = width; i--; )
-    glyph->bitmap [i]
-      = glyph->bitmap [i + (height - 1) * glyph->stride] = 0xff;
-
-  for (i = height; i--; )
-    glyph->bitmap [i * glyph->stride]
-      = glyph->bitmap [i * glyph->stride + (width - 1)] = 0xff;
+static void
+pango_clutter_renderer_draw_box (int x,     int y,
+                                int width, int height)
+{
+  cogl_path_rectangle (CLUTTER_INT_TO_FIXED (x),
+                      CLUTTER_INT_TO_FIXED (y - height),
+                      CLUTTER_INT_TO_FIXED (width),
+                      CLUTTER_INT_TO_FIXED (height));
+  cogl_path_stroke ();
 }
 
 static void
-font_render_glyph (Glyph *glyph, PangoFont *font, int glyph_index)
+pango_clutter_renderer_draw_rectangle (PangoRenderer    *renderer,
+                                      PangoRenderPart   part,
+                                      int               x,
+                                      int               y,
+                                      int               width,
+                                      int               height)
 {
-  FT_Face face;
+  float x1, x2, y1, y2;
+  const PangoMatrix *matrix;
 
-  if (glyph_index & PANGO_GLYPH_UNKNOWN_FLAG)
+  if ((matrix = pango_renderer_get_matrix (renderer)))
     {
-      PangoFontMetrics *metrics;
-
-      if (!font)
-       goto generic_box;
-
-      metrics = pango_font_get_metrics (font, NULL);
-      if (!metrics)
-       goto generic_box;
-
-      render_box (glyph, PANGO_PIXELS (metrics->approximate_char_width),
-                        PANGO_PIXELS (metrics->ascent + metrics->descent),
-                        PANGO_PIXELS (metrics->ascent));
-
-      pango_font_metrics_unref (metrics);
-
-      return;
+      /* Convert user-space coords to device coords */
+      x1 = (x * matrix->xx + y * matrix->xy) / PANGO_SCALE + matrix->x0;
+      x2 = ((x + width) * matrix->xx + (y + height) * matrix->xy)
+       / PANGO_SCALE + matrix->x0;
+      y1 = (y * matrix->yy + x * matrix->yx) / PANGO_SCALE + matrix->y0;
+      y2 = ((y + height) * matrix->yy + (x + width) * matrix->yx)
+       / PANGO_SCALE + matrix->y0;
     }
-
-  face = pango_clutter_font_get_face (font);
-
-  if (face)
+  else
     {
-      PangoClutterFont *glfont = (PangoClutterFont *)font;
-
-      FT_Load_Glyph (face, glyph_index, glfont->load_flags);
-      FT_Render_Glyph (face->glyph, ft_render_mode_normal);
-
-      glyph->width  = face->glyph->bitmap.width;
-      glyph->stride = face->glyph->bitmap.pitch;
-      glyph->height = face->glyph->bitmap.rows;
-      glyph->top    = face->glyph->bitmap_top;
-      glyph->left   = face->glyph->bitmap_left;
-      glyph->bitmap = face->glyph->bitmap.buffer;
+      x1 = x / PANGO_SCALE;
+      x2 = (x + width) / PANGO_SCALE;
+      y1 = y / PANGO_SCALE;
+      y2 = (y + height) / PANGO_SCALE;
     }
-  else
-    generic_box:
-      render_box (glyph, PANGO_UNKNOWN_GLYPH_WIDTH,
-                 PANGO_UNKNOWN_GLYPH_HEIGHT, PANGO_UNKNOWN_GLYPH_HEIGHT);
-}
 
-typedef struct glyph_info
-{
-  tc_area tex;
-  int     left, top;
-  int     generation;
+  cogl_rectangle (x1, y1, x2 - x1, y2 - y1);
 }
-glyph_info;
 
 static void
-free_glyph_info (glyph_info *g)
+pango_clutter_renderer_draw_trapezoid (PangoRenderer    *renderer,
+                                      PangoRenderPart   part,
+                                      double            y1,
+                                      double            x11,
+                                      double            x21,
+                                      double            y2,
+                                      double            x12,
+                                      double            x22)
 {
-  tc_put (&g->tex);
-  g_slice_free (glyph_info, g);
+  ClutterFixed points[8];
+
+  points[0] = CLUTTER_FLOAT_TO_FIXED (x11);
+  points[1] = CLUTTER_FLOAT_TO_FIXED (y1);
+  points[2] = CLUTTER_FLOAT_TO_FIXED (x12);
+  points[3] = CLUTTER_FLOAT_TO_FIXED (y2);
+  points[4] = CLUTTER_FLOAT_TO_FIXED (x22);
+  points[5] = points[3];
+  points[6] = CLUTTER_FLOAT_TO_FIXED (x21);
+  points[7] = points[1];
+
+  cogl_path_polygon (points, 4);
+  cogl_path_fill ();
 }
 
 static void
-draw_glyph (PangoRenderer *renderer_,
-           PangoFont     *font,
-           PangoGlyph     glyph,
-           double         xd,
-           double         yd)
+pango_clutter_renderer_draw_glyph (PangoRenderer *renderer,
+                                  PangoFont     *font,
+                                  PangoGlyph     glyph,
+                                  double         xd,
+                                  double         yd)
 {
-  glyph_info           *g;
-  gint                  x = (gint)xd, y = (gint)yd;
-  ClutterFixed          fx, fy;
-
-  if (glyph & PANGO_GLYPH_UNKNOWN_FLAG)
-    {
-      glyph = pango_clutter_get_unknown_glyph (font);
+  PangoClutterGlyphCacheValue *cache_value;
+  ClutterFixed x = CLUTTER_FLOAT_TO_FIXED ((float) xd);
+  ClutterFixed y = CLUTTER_FLOAT_TO_FIXED ((float) yd);
 
-      if (glyph == PANGO_GLYPH_EMPTY)
-       glyph = PANGO_GLYPH_UNKNOWN_FLAG;
-    }
-
-  g = _pango_clutter_font_get_cache_glyph_data (font, glyph);
-
-  if (!g || g->generation != tc_generation)
+  if ((glyph & PANGO_GLYPH_UNKNOWN_FLAG))
     {
-      Glyph bm;
-      font_render_glyph (&bm, font, glyph);
-
-      if (bm.width < 1 || bm.height < 1 || bm.bitmap == NULL)
-        {
-          /* Safety on */
-          if (g)
-            {
-              x += g->left;
-              y -= g->top;
-            }
-          return;
-        }
-
-      if (bm.height > TC_HEIGHT)
-        {
-          g_warning ("%s: Glyph too large for cache, increase TC_HEIGHT",
-                     G_STRLOC);
-        }
+      PangoFontMetrics *metrics;
 
-      if (g)
-        g->generation = tc_generation;
+      if (font == NULL
+         || (metrics = pango_font_get_metrics (font, NULL)) == NULL)
+       pango_clutter_renderer_draw_box (CLUTTER_FIXED_TO_INT (x),
+                                        CLUTTER_FIXED_TO_INT (y),
+                                        PANGO_UNKNOWN_GLYPH_WIDTH,
+                                        PANGO_UNKNOWN_GLYPH_HEIGHT);
       else
-        {
-          g = g_slice_new0 (glyph_info);
-
-          _pango_clutter_font_set_glyph_cache_destroy
-                               (font, (GDestroyNotify)free_glyph_info);
-          _pango_clutter_font_set_cache_glyph_data (font, glyph, g);
-        }
-
-      tc_get (&g->tex, bm.width, bm.height);
-
-      g->left = bm.left;
-      g->top  = bm.top;
+       {
+         pango_clutter_renderer_draw_box (CLUTTER_FIXED_TO_INT (x),
+                                          CLUTTER_FIXED_TO_INT (y),
+                                          metrics->approximate_char_width
+                                          / PANGO_SCALE,
+                                          metrics->ascent / PANGO_SCALE);
 
-      CLUTTER_NOTE (PANGO, "cache fail; subimage2d %i", glyph);
+         pango_font_metrics_unref (metrics);
+       }
 
-      cogl_texture_set_region (g->tex.cogl_tex,
-                              0, 0,
-                              g->tex.x, g->tex.y,
-                              bm.width, bm.height,
-                              bm.width, bm.height,
-                              COGL_PIXEL_FORMAT_A_8,
-                              bm.stride,
-                              bm.bitmap);
+      return;
     }
-  else
-    CLUTTER_NOTE (PANGO, "cache success %i\n", glyph);
-
-  x += g->left;
-  y -= g->top;
-
-  fx = CLUTTER_INT_TO_FIXED (g->tex.x) / TC_WIDTH;
-  fy = CLUTTER_INT_TO_FIXED (g->tex.y) / TC_HEIGHT;
-
-  cogl_texture_rectangle (g->tex.cogl_tex,
-                         CLUTTER_INT_TO_FIXED (x),
-                         CLUTTER_INT_TO_FIXED (y),
-                         CLUTTER_INT_TO_FIXED (x + g->tex.w),
-                         CLUTTER_INT_TO_FIXED (y + g->tex.h),
-                         fx, fy,
-                         CLUTTER_INT_TO_FIXED (g->tex.w) / TC_WIDTH + fx,
-                         CLUTTER_INT_TO_FIXED (g->tex.h) / TC_WIDTH + fy);
-}
-
-void
-pango_clutter_render_layout_subpixel (PangoLayout  *layout,
-                                     int           x,
-                                     int           y,
-                                     ClutterColor *color,
-                                     int           flags)
-{
-  PangoContext  *context;
-  PangoFontMap  *fontmap;
-  PangoRenderer *renderer;
-
-  context = pango_layout_get_context (layout);
-  fontmap = pango_context_get_font_map (context);
-  renderer = _pango_clutter_font_map_get_renderer
-                     (PANGO_CLUTTER_FONT_MAP (fontmap));
-
-  memcpy (&(PANGO_CLUTTER_RENDERER (renderer)->color),
-         color, sizeof(ClutterColor));
-
-  pango_renderer_draw_layout (renderer, layout, x, y);
-}
-
-void
-pango_clutter_render_layout (PangoLayout  *layout,
-                            int           x,
-                            int           y,
-                            ClutterColor *color,
-                            int           flags)
-{
-  pango_clutter_render_layout_subpixel (layout,
-                                       x * PANGO_SCALE,
-                                       y * PANGO_SCALE,
-                                       color,
-                                       flags);
-}
 
-void
-pango_clutter_render_layout_line (PangoLayoutLine *line,
-                                 int              x,
-                                 int              y,
-                                 ClutterColor    *color)
-{
-  PangoContext  *context;
-  PangoFontMap  *fontmap;
-  PangoRenderer *renderer;
-
-  context = pango_layout_get_context (line->layout);
-  fontmap = pango_context_get_font_map (context);
-  renderer = _pango_clutter_font_map_get_renderer
-                     (PANGO_CLUTTER_FONT_MAP (fontmap));
+  /* Get the texture containing the glyph. This will create the cache
+     entry if there isn't already one */
+  cache_value = pango_clutter_renderer_get_cached_glyph (renderer, font, glyph);
 
-  memcpy (&(PANGO_CLUTTER_RENDERER (renderer)->color),
-         color, sizeof(ClutterColor));
+  if (cache_value == NULL)
+    {
+      pango_clutter_renderer_draw_box (CLUTTER_FIXED_TO_INT (x),
+                                      CLUTTER_FIXED_TO_INT (y),
+                                      PANGO_UNKNOWN_GLYPH_WIDTH,
+                                      PANGO_UNKNOWN_GLYPH_HEIGHT);
 
-  pango_renderer_draw_layout_line (renderer, line, x, y);
-}
+      return;
+    }
 
-void
-pango_clutter_render_clear_caches (void)
-{
-  tc_clear();
-}
+  x += CLUTTER_INT_TO_FIXED (cache_value->draw_x);
+  y += CLUTTER_INT_TO_FIXED (cache_value->draw_y);
 
-static void
-pango_clutter_renderer_init (PangoClutterRenderer *renderer)
-{
-  memset (&renderer->color, 0xff, sizeof(ClutterColor));
+  /* Render the glyph from the texture */
+  cogl_texture_rectangle (cache_value->texture, x, y,
+                         x + CLUTTER_INT_TO_FIXED (cache_value->draw_width),
+                         y + CLUTTER_INT_TO_FIXED (cache_value->draw_height),
+                         cache_value->tx1, cache_value->ty1,
+                         cache_value->tx2, cache_value->ty2);
 }
 
 static void
-prepare_run (PangoRenderer *renderer, PangoLayoutRun *run)
+pango_clutter_renderer_prepare_run (PangoRenderer  *renderer,
+                                   PangoLayoutRun *run)
 {
-  PangoClutterRenderer *glrenderer = (PangoClutterRenderer *)renderer;
-  PangoColor           *fg = 0;
-  GSList               *l;
+  GSList               *node;
+  PangoColor           *fg = NULL;
   ClutterColor          col;
+  PangoClutterRenderer *priv = PANGO_CLUTTER_RENDERER (renderer);
 
-  renderer->underline = PANGO_UNDERLINE_NONE;
-  renderer->strikethrough = FALSE;
-
-  for (l = run->item->analysis.extra_attrs; l; l = l->next)
+  for (node = run->item->analysis.extra_attrs; node; node = node->next)
     {
-      PangoAttribute *attr = l->data;
+      PangoAttribute *attr = node->data;
 
       switch (attr->klass->type)
        {
-       case PANGO_ATTR_UNDERLINE:
-         renderer->underline = ((PangoAttrInt *)attr)->value;
-         break;
-
-       case PANGO_ATTR_STRIKETHROUGH:
-         renderer->strikethrough = ((PangoAttrInt *)attr)->value;
-         break;
-
        case PANGO_ATTR_FOREGROUND:
-          fg = &((PangoAttrColor *)attr)->color;
-         break;
+         fg = &((PangoAttrColor *) attr)->color;
+
        default:
          break;
        }
     }
 
-  if (fg)
+   if (fg)
     {
       col.red   = (fg->red   * 255) / 65535;
       col.green = (fg->green * 255) / 65535;
@@ -504,41 +467,15 @@ prepare_run (PangoRenderer *renderer, PangoLayoutRun *run)
     }
   else
     {
-      col.red   = glrenderer->color.red;
-      col.green = glrenderer->color.green;
-      col.blue  = glrenderer->color.blue;
+      col.red   = priv->color.red;
+      col.green = priv->color.green;
+      col.blue  = priv->color.blue;
     }
 
-  col.alpha = glrenderer->color.alpha;
-
-  if (glrenderer->flags & FLAG_INVERSE)
-    {
-      col.red   ^= 0xffU;
-      col.green ^= 0xffU;
-      col.blue   ^= 0xffU;
-    }
+  col.alpha = priv->color.alpha;
 
-  cogl_color(&col);
-}
+  cogl_color (&col);
 
-static void
-draw_begin (PangoRenderer *renderer_)
-{
+  /* Chain up */
+  (* PANGO_RENDERER_CLASS (parent_class)->prepare_run) (renderer, run);
 }
-
-static void
-draw_end (PangoRenderer *renderer_)
-{
-}
-
-static void
-pango_clutter_renderer_class_init (PangoClutterRendererClass *klass)
-{
-  PangoRendererClass *renderer_class = PANGO_RENDERER_CLASS (klass);
-
-  renderer_class->draw_glyph     = draw_glyph;
-  renderer_class->prepare_run    = prepare_run;
-  renderer_class->begin          = draw_begin;
-  renderer_class->end            = draw_end;
-}
-
index 44aee07..304f5be 100644 (file)
-/* Pango
- * pangoclutter.h: Clutter/Freetype2 backend
+/*
+ * Clutter.
  *
- * Copyright (C) 1999 Red Hat Software
- * Copyright (C) 2000 Tor Lillqvist
- * Copyright (C) 2006 Marc Lehmann <pcg@goof.com>
+ * An OpenGL based 'interactive canvas' library.
  *
- * This file is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
+ * Authored By Matthew Allum  <mallum@openedhand.com>
+ *
+ * Copyright (C) 2008 OpenedHand
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
  * version 2 of the License, or (at your option) any later version.
  *
- * This file is distributed in the hope that it will be useful,
+ * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.         See the GNU
- * Library General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU Library General Public
+ * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the
  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  * Boston, MA 02111-1307, USA.
  */
-#ifndef PANGOCLUTTER_H__
-#define PANGOCLUTTER_H__
-
-#define PANGO_ENABLE_BACKEND
 
-/* we always want to disable cast checks */
-#ifndef G_DISABLE_CAST_CHECKS
-#define G_DISABLE_CAST_CHECKS
-#endif
+#ifndef _HAVE_PANGO_CLUTTER_H
+#define _HAVE_PANGO_CLUTTER_H
 
 #include <glib-object.h>
-#include <pango/pango.h>
-#include <fontconfig/fontconfig.h>
+#include <pango/pangocairo.h>
 #include <clutter/clutter-color.h>
 
 G_BEGIN_DECLS
 
-#define PANGO_TYPE_CLUTTER_FONT_MAP                                   \
-            (pango_clutter_font_map_get_type ())
-
-#define PANGO_CLUTTER_FONT_MAP(object)                                \
-            (G_TYPE_CHECK_INSTANCE_CAST ((object),                    \
-                                         PANGO_TYPE_CLUTTER_FONT_MAP, \
-                                         PangoClutterFontMap))
-
-#define PANGO_CLUTTER_IS_FONT_MAP(object)                             \
-           (G_TYPE_CHECK_INSTANCE_TYPE ((object), PANGO_TYPE_CLUTTER_FONT_MAP))
-
-typedef struct _PangoClutterFontMap      PangoClutterFontMap;
-typedef struct _PangoClutterFontMapClass PangoClutterFontMapClass;
-
-typedef void (*PangoClutterSubstituteFunc) (FcPattern *pattern, gpointer data);
-
-GType pango_clutter_font_map_get_type (void);
-
-PangoFontMap*
-pango_clutter_font_map_new (void);
-
-void  
-pango_clutter_font_map_set_default_substitute 
-                           (PangoClutterFontMap        *fontmap,
-                           PangoClutterSubstituteFunc  func,
-                           gpointer                    data,
-                           GDestroyNotify              notify);
-
-void
-pango_clutter_font_map_set_resolution (PangoClutterFontMap *fontmap,
-                                       double               dpi);
-
-void          
-pango_clutter_font_map_substitute_changed (PangoClutterFontMap *fontmap);
-
-PangoContext *
-pango_clutter_font_map_create_context (PangoClutterFontMap *fontmap);
-
-#define FLAG_INVERSE 1
-#define FLAG_OUTLINE 2 // not yet implemented
-
-void 
-pango_clutter_render_layout_subpixel (PangoLayout *layout,
-                                     int           x, 
-                                     int           y,
-                                     ClutterColor *color,
-                                     int           flags);
-void 
-pango_clutter_render_layout (PangoLayout  *layout,
-                            int           x, 
-                            int           y,
-                            ClutterColor *color,
-                            int           flags);
-
-void 
-pango_clutter_render_layout_line (PangoLayoutLine *line,
-                                 int              x,
-                                 int              y,
-                                 ClutterColor    *color);
-
-void 
-pango_clutter_render_clear_caches ();
+/* It's too difficult to actually subclass the pango cairo font
+   map. Instead we just make a fake set of macros that actually just
+   directly use the original type */
+#define PANGO_CLUTTER_TYPE_FONT_MAP PANGO_TYPE_CAIRO_FONT_MAP
+
+#define PANGO_CLUTTER_FONT_MAP(obj)                            \
+  (G_TYPE_CHECK_INSTANCE_CAST ((obj),                          \
+                              PANGO_CLUTTER_TYPE_FONT_MAP,     \
+                              PangoClutterFontMap))
+#define PANGO_CLUTTER_IS_FONT_MAP(obj)                         \
+  (G_TYPE_CHECK_INSTANCE_TYPE ((obj),                          \
+                              PANGO_CLUTTER_TYPE_FONT_MAP))
+
+typedef PangoCairoFontMap PangoClutterFontMap;
+
+PangoFontMap *pango_clutter_font_map_new (void);
+
+PangoContext *pango_clutter_font_map_create_context (PangoClutterFontMap *fm);
+
+void pango_clutter_font_map_set_resolution (PangoClutterFontMap *font_map,
+                                           double               dpi);
+
+void pango_clutter_font_map_clear_glyph_cache (PangoClutterFontMap *fm);
+
+void pango_clutter_font_map_set_use_mipmapping (PangoClutterFontMap *fm,
+                                               gboolean             value);
+
+void pango_clutter_ensure_glyph_cache_for_layout (PangoLayout *layout);
+
+#define PANGO_CLUTTER_TYPE_RENDERER (pango_clutter_renderer_get_type ())
+
+#define PANGO_CLUTTER_RENDERER(obj)                            \
+  (G_TYPE_CHECK_INSTANCE_CAST ((obj),                          \
+                              PANGO_CLUTTER_TYPE_RENDERER,     \
+                              PangoClutterRenderer))
+#define PANGO_CLUTTER_RENDERER_CLASS(klass)                    \
+  (G_TYPE_CHECK_CLASS_CAST ((klass),                           \
+                           PANGO_CLUTTER_TYPE_RENDERER,        \
+                           PangoClutterRendererClass))
+#define PANGO_CLUTTER_IS_RENDERER(obj)                         \
+  (G_TYPE_CHECK_INSTANCE_TYPE ((obj),                          \
+                              PANGO_CLUTTER_TYPE_RENDERER))
+#define PANGO_CLUTTER_IS_RENDERER_CLASS(klass)                 \
+  (G_TYPE_CHECK_CLASS_TYPE ((klass),                           \
+                           PANGO_CLUTTER_TYPE_RENDERER))
+#define PANGO_CLUTTER_RENDERER_GET_CLASS(obj)                  \
+  (G_TYPE_INSTANCE_GET_CLASS ((obj),                           \
+                             PANGO_CLUTTER_TYPE_RENDERER,      \
+                             PangoClutterRendererClass))
+
+typedef struct _PangoClutterRenderer      PangoClutterRenderer;
+typedef struct _PangoClutterRendererClass PangoClutterRendererClass;
+
+GType pango_clutter_renderer_get_type (void) G_GNUC_CONST;
+
+void pango_clutter_render_layout_subpixel (PangoLayout  *layout,
+                                          int           x,
+                                          int           y,
+                                          ClutterColor *color,
+                                          int           flags);
+
+void pango_clutter_render_layout (PangoLayout  *layout,
+                                 int           x,
+                                 int           y,
+                                 ClutterColor *color,
+                                 int           flags);
+
+void pango_clutter_render_layout_line (PangoLayoutLine  *line,
+                                      int               x,
+                                      int               y,
+                                      ClutterColor     *color);
 
 G_END_DECLS
 
-#endif
+#endif /* _HAVE_PANGO_CLUTTER_H */
index 51d6b2d..bbaa3d3 100644 (file)
@@ -448,7 +448,7 @@ fi
 AC_SUBST(JSON_PREFIX)
 AM_CONDITIONAL(LOCAL_JSON_GLIB, test "x$have_json" = "xno")
 
-CLUTTER_REQUIRES="pangoft2 glib-2.0 >= 2.14 gobject-2.0 gthread-2.0 gmodule-2.0 $BACKEND_PC_FILES $JSON_GLIB_PC"
+CLUTTER_REQUIRES="pangocairo glib-2.0 >= 2.14 gobject-2.0 gthread-2.0 gmodule-2.0 $BACKEND_PC_FILES $JSON_GLIB_PC"
 
 if test "x$imagebackend" = "xgdk-pixbuf"; then
         CLUTTER_REQUIRES="$CLUTTER_REQUIRES gdk-pixbuf-2.0"