summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2021-03-18 04:17:42 +0000
committerMatthias Clasen <mclasen@redhat.com>2021-03-18 04:17:42 +0000
commitbff2adace6949e598e085eb23497e7d2629d06d5 (patch)
tree3f670f6ca980acc52da591ffa63dc30df7d95614
parent7e7ceb2425201bb4c7be3dcd0864d3da9632f9ef (diff)
parent2214326a9669af950593da08c98505c62e27974a (diff)
downloadpango-bff2adace6949e598e085eb23497e7d2629d06d5.tar.gz
Merge branch 'cache-context-metrics' into 'master'
context: Cache metrics for the current font See merge request GNOME/pango!299
-rw-r--r--pango/pango-context.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/pango/pango-context.c b/pango/pango-context.c
index 1db11a1c..ccaa1bac 100644
--- a/pango/pango-context.c
+++ b/pango/pango-context.c
@@ -63,6 +63,8 @@ struct _PangoContext
PangoFontMap *font_map;
+ PangoFontMetrics *metrics;
+
gboolean round_glyph_positions;
};
@@ -121,6 +123,9 @@ pango_context_finalize (GObject *object)
if (context->matrix)
pango_matrix_free (context->matrix);
+ if (context->metrics)
+ pango_font_metrics_unref (context->metrics);
+
G_OBJECT_CLASS (pango_context_parent_class)->finalize (object);
}
@@ -1783,6 +1788,11 @@ pango_context_get_metrics (PangoContext *context,
if (!language)
language = context->language;
+ if (desc == context->font_desc &&
+ language == context->language &&
+ context->metrics != NULL)
+ return pango_font_metrics_ref (context->metrics);
+
current_fonts = pango_font_map_load_fontset (context->font_map, context, desc, language);
metrics = get_base_metrics (current_fonts);
@@ -1797,6 +1807,10 @@ pango_context_get_metrics (PangoContext *context,
g_object_unref (current_fonts);
+ if (desc == context->font_desc &&
+ language == context->language)
+ context->metrics = pango_font_metrics_ref (metrics);
+
return metrics;
}
@@ -1806,6 +1820,8 @@ context_changed (PangoContext *context)
context->serial++;
if (context->serial == 0)
context->serial++;
+
+ g_clear_pointer (&context->metrics, pango_font_metrics_unref);
}
/**