css: Use setters for font size and family
This avoid creating pango font descriptions all the time, when the gtk-font-name setting hasn't actually changed.
This commit is contained in:
parent
71d6816817
commit
309c6dfaf8
@ -144,30 +144,19 @@ gtk_css_font_size_get_default_px (GtkStyleProviderPrivate *provider,
|
|||||||
{
|
{
|
||||||
GtkSettings *settings;
|
GtkSettings *settings;
|
||||||
PangoFontDescription *description;
|
PangoFontDescription *description;
|
||||||
char *font_name;
|
int font_size;
|
||||||
double font_size;
|
|
||||||
|
|
||||||
settings = _gtk_style_provider_private_get_settings (provider);
|
settings = _gtk_style_provider_private_get_settings (provider);
|
||||||
if (settings == NULL)
|
if (settings == NULL)
|
||||||
return DEFAULT_FONT_SIZE_PT * get_dpi (style) / 72.0;
|
return DEFAULT_FONT_SIZE_PT * get_dpi (style) / 72.0;
|
||||||
|
|
||||||
g_object_get (settings, "gtk-font-name", &font_name, NULL);
|
font_size = gtk_settings_get_font_size (settings);
|
||||||
description = pango_font_description_from_string (font_name);
|
if (font_size == 0)
|
||||||
g_free (font_name);
|
|
||||||
if (description == NULL)
|
|
||||||
return DEFAULT_FONT_SIZE_PT * get_dpi (style) / 72.0;
|
return DEFAULT_FONT_SIZE_PT * get_dpi (style) / 72.0;
|
||||||
|
else if (gtk_settings_get_font_size_is_absolute (settings))
|
||||||
if (pango_font_description_get_set_fields (description) & PANGO_FONT_MASK_SIZE)
|
return (double) font_size / PANGO_SCALE;
|
||||||
{
|
|
||||||
font_size = (double) pango_font_description_get_size (description) / PANGO_SCALE;
|
|
||||||
if (!pango_font_description_get_size_is_absolute (description))
|
|
||||||
font_size = font_size * get_dpi (style) / 72.0;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
font_size = DEFAULT_FONT_SIZE_PT * get_dpi (style) / 72.0;
|
return ((double) font_size / PANGO_SCALE) * get_dpi (style) / 72.0;
|
||||||
|
|
||||||
pango_font_description_free (description);
|
|
||||||
return font_size;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static GtkCssValue *
|
static GtkCssValue *
|
||||||
|
@ -62,29 +62,8 @@ gtk_css_value_initial_compute (GtkCssValue *value,
|
|||||||
|
|
||||||
case GTK_CSS_PROPERTY_FONT_FAMILY:
|
case GTK_CSS_PROPERTY_FONT_FAMILY:
|
||||||
settings = _gtk_style_provider_private_get_settings (provider);
|
settings = _gtk_style_provider_private_get_settings (provider);
|
||||||
if (settings)
|
if (settings && gtk_settings_get_font_family (settings) != NULL)
|
||||||
{
|
return _gtk_css_array_value_new (_gtk_css_string_value_new (gtk_settings_get_font_family (settings)));
|
||||||
PangoFontDescription *description;
|
|
||||||
char *font_name;
|
|
||||||
|
|
||||||
g_object_get (settings, "gtk-font-name", &font_name, NULL);
|
|
||||||
description = pango_font_description_from_string (font_name);
|
|
||||||
g_free (font_name);
|
|
||||||
if (description == NULL)
|
|
||||||
break;
|
|
||||||
|
|
||||||
if (pango_font_description_get_set_fields (description) & PANGO_FONT_MASK_FAMILY)
|
|
||||||
{
|
|
||||||
GtkCssValue *val;
|
|
||||||
|
|
||||||
val = _gtk_css_array_value_new (_gtk_css_string_value_new (pango_font_description_get_family (description)));
|
|
||||||
pango_font_description_free (description);
|
|
||||||
|
|
||||||
return val;
|
|
||||||
}
|
|
||||||
|
|
||||||
pango_font_description_free (description);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
Loading…
Reference in New Issue
Block a user