#include "pangocairo-private.h"
#include "pango-impl-utils.h"
+#include <string.h>
+
typedef struct _PangoCairoContextInfo PangoCairoContextInfo;
struct _PangoCairoContextInfo
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);
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);
}
/**
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);
}