summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2021-03-18 00:09:58 -0400
committerMatthias Clasen <mclasen@redhat.com>2021-03-18 00:11:12 -0400
commit2214326a9669af950593da08c98505c62e27974a (patch)
tree3f670f6ca980acc52da591ffa63dc30df7d95614
parent7e7ceb2425201bb4c7be3dcd0864d3da9632f9ef (diff)
downloadpango-2214326a9669af950593da08c98505c62e27974a.tar.gz
context: Cache metrics for the current fontcache-context-metrics
GTK calls pango_context_get_metrics() frequently to determine character widths and alignments, and does not expect this to involve expensive layout operations.
-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);
}
/**