Revert "gsk: Avoid some allocations"

This reverts commit 144cd2d91c.

This commit is causing problems when using GTK 4.14 with
Pango 1.51.

Fixes: #6606
This commit is contained in:
Matthias Clasen
2024-04-04 10:22:17 +02:00
parent 4b2b6d6212
commit 96aa58e9b0

View File

@@ -48,9 +48,9 @@ gsk_reload_font (PangoFont *font,
cairo_hint_style_t hint_style,
cairo_antialias_t antialias)
{
static cairo_font_options_t *options = NULL;
static PangoContext *context = NULL;
cairo_font_options_t *options;
cairo_scaled_font_t *sf;
static PangoContext *context = NULL;
#if !PANGO_VERSION_CHECK (1, 52, 0)
PangoFontDescription *desc;
FcPattern *pattern;
@@ -84,9 +84,7 @@ gsk_reload_font (PangoFont *font,
g_set_object (&last_font, font);
g_clear_object (&last_result);
if (G_UNLIKELY (options == NULL))
options = cairo_font_options_create ();
options = cairo_font_options_create ();
sf = pango_cairo_font_get_scaled_font (PANGO_CAIRO_FONT (font));
cairo_scaled_font_get_font_options (sf, options);
@@ -106,6 +104,7 @@ gsk_reload_font (PangoFont *font,
cairo_font_options_get_subpixel_order (options) == CAIRO_SUBPIXEL_ORDER_DEFAULT)
{
last_result = g_object_ref (font);
cairo_font_options_destroy (options);
return g_object_ref (font);
}
@@ -114,10 +113,11 @@ gsk_reload_font (PangoFont *font,
cairo_font_options_set_antialias (options, antialias);
cairo_font_options_set_subpixel_order (options, CAIRO_SUBPIXEL_ORDER_DEFAULT);
if (G_UNLIKELY (context == NULL))
if (!context)
context = pango_context_new ();
pango_cairo_context_set_font_options (context, options);
cairo_font_options_destroy (options);
#if PANGO_VERSION_CHECK (1, 52, 0)
last_result = pango_font_map_reload_font (pango_font_get_font_map (font), font, scale, context, NULL);
@@ -129,9 +129,14 @@ gsk_reload_font (PangoFont *font,
pango_cairo_context_set_resolution (context, dpi);
#endif
desc = pango_font_describe_with_absolute_size (font);
desc = pango_font_describe (font);
size = pango_font_description_get_size (desc);
pango_font_description_set_absolute_size (desc, size * scale);
if (pango_font_description_get_size_is_absolute (desc))
pango_font_description_set_absolute_size (desc, size * scale);
else
pango_font_description_set_size (desc, (int) floor (size * scale + .5));
last_result = pango_font_map_load_font (pango_font_get_font_map (font), context, desc);
pango_font_description_free (desc);
#endif
@@ -150,16 +155,15 @@ gsk_reload_font (PangoFont *font,
cairo_hint_style_t
gsk_font_get_hint_style (PangoFont *font)
{
static cairo_font_options_t *options = NULL;
cairo_scaled_font_t *sf;
cairo_font_options_t *options;
cairo_hint_style_t style;
if (G_UNLIKELY (options == NULL))
options = cairo_font_options_create ();
sf = pango_cairo_font_get_scaled_font (PANGO_CAIRO_FONT (font));
options = cairo_font_options_create ();
cairo_scaled_font_get_font_options (sf, options);
style = cairo_font_options_get_hint_style (options);
cairo_font_options_destroy (options);
return style;
}