summaryrefslogtreecommitdiff
path: root/pango/pangocairo-context.c
diff options
context:
space:
mode:
authorBehdad Esfahbod <behdad@gnome.org>2007-06-12 05:23:45 +0000
committerBehdad Esfahbod <behdad@src.gnome.org>2007-06-12 05:23:45 +0000
commit356746d28aaf516ea605060cef991f6e29034a66 (patch)
treeda3b87fefa68dc563ee76f68d79fb3b8b2ca3936 /pango/pangocairo-context.c
parent4b9a95cf71f5c9cf45159899cc9674fcc248fb83 (diff)
downloadpango-356746d28aaf516ea605060cef991f6e29034a66.tar.gz
Bug 445832 – pango_cairo_update_layout() always invalidates layout
2007-06-12 Behdad Esfahbod <behdad@gnome.org> Bug 445832 – pango_cairo_update_layout() always invalidates layout * pango/pangocairo-context.c (_pango_cairo_update_context), (pango_cairo_update_context), (pango_cairo_update_layout): Don't invalidate layout if matrix and font options didn't change. svn path=/trunk/; revision=2346
Diffstat (limited to 'pango/pangocairo-context.c')
-rw-r--r--pango/pangocairo-context.c80
1 files changed, 56 insertions, 24 deletions
diff --git a/pango/pangocairo-context.c b/pango/pangocairo-context.c
index 6bdaa532..98558f89 100644
--- a/pango/pangocairo-context.c
+++ b/pango/pangocairo-context.c
@@ -25,6 +25,8 @@
#include "pangocairo-private.h"
#include "pango-impl-utils.h"
+#include <string.h>
+
typedef struct _PangoCairoContextInfo PangoCairoContextInfo;
struct _PangoCairoContextInfo
@@ -80,30 +82,16 @@ get_context_info (PangoContext *context,
return info;
}
-/**
- * pango_cairo_update_context:
- * @cr: a Cairo context
- * @context: a #PangoContext, from pango_cairo_font_map_create_context()
- *
- * Updates a #PangoContext previously created for use with Cairo to
- * match the current transformation and target surface of a Cairo
- * context. If any layouts have been created for the context,
- * it's necessary to call pango_layout_context_changed() on those
- * layouts.
- *
- * Since: 1.10
- **/
-void
-pango_cairo_update_context (cairo_t *cr,
- PangoContext *context)
+static gboolean
+_pango_cairo_update_context (cairo_t *cr,
+ PangoContext *context)
{
PangoCairoContextInfo *info;
cairo_matrix_t cairo_matrix;
cairo_surface_t *target;
PangoMatrix pango_matrix;
-
- g_return_if_fail (cr != NULL);
- g_return_if_fail (PANGO_IS_CONTEXT (context));
+ const PangoMatrix *layout_matrix, identity_matrix = PANGO_MATRIX_INIT;
+ gboolean changed = FALSE;
info = get_context_info (context, TRUE);
@@ -115,19 +103,63 @@ pango_cairo_update_context (cairo_t *cr,
pango_matrix.x0 = cairo_matrix.x0;
pango_matrix.y0 = cairo_matrix.y0;
+ layout_matrix = pango_context_get_matrix (context);
+ if (!layout_matrix)
+ layout_matrix = &identity_matrix;
+
+ if (0 != memcmp (&pango_matrix, layout_matrix, sizeof (pango_matrix)))
+ changed = TRUE;
+
pango_context_set_matrix (context, &pango_matrix);
- if (!info->surface_options)
- info->surface_options = cairo_font_options_create ();
target = cairo_get_target (cr);
- cairo_surface_get_font_options (target, info->surface_options);
+
+ if (!info->surface_options) {
+ info->surface_options = cairo_font_options_create ();
+ changed = TRUE;
+ cairo_surface_get_font_options (target, info->surface_options);
+ } else {
+ cairo_font_options_t *surface_options = cairo_font_options_create ();
+ cairo_surface_get_font_options (target, surface_options);
+ if (!cairo_font_options_equal (surface_options, info->surface_options))
+ {
+ cairo_surface_get_font_options (target, info->surface_options);
+ changed = TRUE;
+ }
+ cairo_font_options_destroy (surface_options);
+ }
if (info->merged_options)
{
cairo_font_options_destroy (info->merged_options);
info->merged_options = NULL;
}
+
+ return changed;
+}
+
+/**
+ * pango_cairo_update_context:
+ * @cr: a Cairo context
+ * @context: a #PangoContext, from pango_cairo_font_map_create_context()
+ *
+ * Updates a #PangoContext previously created for use with Cairo to
+ * match the current transformation and target surface of a Cairo
+ * context. If any layouts have been created for the context,
+ * it's necessary to call pango_layout_context_changed() on those
+ * layouts.
+ *
+ * Since: 1.10
+ **/
+void
+pango_cairo_update_context (cairo_t *cr,
+ PangoContext *context)
+{
+ g_return_if_fail (cr != NULL);
+ g_return_if_fail (PANGO_IS_CONTEXT (context));
+
+ (void) _pango_cairo_update_context (cr, context);
}
/**
@@ -400,7 +432,7 @@ pango_cairo_update_layout (cairo_t *cr,
g_return_if_fail (cr != NULL);
g_return_if_fail (PANGO_IS_LAYOUT (layout));
- pango_cairo_update_context (cr, pango_layout_get_context (layout));
- pango_layout_context_changed (layout);
+ if (_pango_cairo_update_context (cr, pango_layout_get_context (layout)))
+ pango_layout_context_changed (layout);
}