mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-25 13:11:13 +00:00
gsk: Avoid some allocations
We can use a static font options object and allocate it only once.
This commit is contained in:
parent
6abd9def55
commit
144cd2d91c
@ -44,9 +44,9 @@ gsk_reload_font (PangoFont *font,
|
||||
cairo_hint_style_t hint_style,
|
||||
cairo_antialias_t antialias)
|
||||
{
|
||||
cairo_font_options_t *options;
|
||||
cairo_scaled_font_t *sf;
|
||||
static cairo_font_options_t *options = NULL;
|
||||
static PangoContext *context = NULL;
|
||||
cairo_scaled_font_t *sf;
|
||||
#if !PANGO_VERSION_CHECK (1, 52, 0)
|
||||
PangoFontDescription *desc;
|
||||
FcPattern *pattern;
|
||||
@ -80,7 +80,9 @@ gsk_reload_font (PangoFont *font,
|
||||
g_set_object (&last_font, font);
|
||||
g_clear_object (&last_result);
|
||||
|
||||
options = cairo_font_options_create ();
|
||||
if (G_UNLIKELY (options == NULL))
|
||||
options = cairo_font_options_create ();
|
||||
|
||||
sf = pango_cairo_font_get_scaled_font (PANGO_CAIRO_FONT (font));
|
||||
cairo_scaled_font_get_font_options (sf, options);
|
||||
|
||||
@ -100,7 +102,6 @@ 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);
|
||||
}
|
||||
|
||||
@ -109,11 +110,10 @@ gsk_reload_font (PangoFont *font,
|
||||
cairo_font_options_set_antialias (options, antialias);
|
||||
cairo_font_options_set_subpixel_order (options, CAIRO_SUBPIXEL_ORDER_DEFAULT);
|
||||
|
||||
if (!context)
|
||||
if (G_UNLIKELY (context == NULL))
|
||||
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);
|
||||
@ -123,14 +123,9 @@ gsk_reload_font (PangoFont *font,
|
||||
if (FcPatternGetDouble (pattern, FC_DPI, 0, &dpi) == FcResultMatch)
|
||||
pango_cairo_context_set_resolution (context, dpi);
|
||||
|
||||
desc = pango_font_describe (font);
|
||||
desc = pango_font_describe_with_absolute_size (font);
|
||||
size = pango_font_description_get_size (desc);
|
||||
|
||||
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));
|
||||
|
||||
pango_font_description_set_absolute_size (desc, size * scale);
|
||||
last_result = pango_font_map_load_font (pango_font_get_font_map (font), context, desc);
|
||||
pango_font_description_free (desc);
|
||||
#endif
|
||||
@ -178,15 +173,16 @@ gsk_get_unhinted_glyph_string_extents (PangoGlyphString *glyphs,
|
||||
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user