forked from AuroraMiddleware/gtk
font button: Convert from pango to css properly
This utility function should probably find a home somewhere else. For now, this makes the deprecation warning go away.
This commit is contained in:
parent
519af3f91d
commit
99c2423043
@ -1164,6 +1164,127 @@ dialog_destroy (GtkWidget *widget,
|
||||
font_button->priv->font_dialog = NULL;
|
||||
}
|
||||
|
||||
static gchar *
|
||||
pango_font_description_to_css (PangoFontDescription *desc)
|
||||
{
|
||||
GString *s;
|
||||
PangoFontMask set;
|
||||
|
||||
s = g_string_new ("* { ");
|
||||
|
||||
set = pango_font_description_get_set_fields (desc);
|
||||
if (set & PANGO_FONT_MASK_FAMILY)
|
||||
{
|
||||
g_string_append (s, "font-family: ");
|
||||
g_string_append (s, pango_font_description_get_family (desc));
|
||||
g_string_append (s, "; ");
|
||||
}
|
||||
if (set & PANGO_FONT_MASK_STYLE)
|
||||
{
|
||||
switch (pango_font_description_get_style (desc))
|
||||
{
|
||||
case PANGO_STYLE_NORMAL:
|
||||
g_string_append (s, "font-style: normal; ");
|
||||
break;
|
||||
case PANGO_STYLE_OBLIQUE:
|
||||
g_string_append (s, "font-style: oblique; ");
|
||||
break;
|
||||
case PANGO_STYLE_ITALIC:
|
||||
g_string_append (s, "font-style: italic; ");
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (set & PANGO_FONT_MASK_VARIANT)
|
||||
{
|
||||
switch (pango_font_description_get_variant (desc))
|
||||
{
|
||||
case PANGO_VARIANT_NORMAL:
|
||||
g_string_append (s, "font-variant: normal; ");
|
||||
break;
|
||||
case PANGO_VARIANT_SMALL_CAPS:
|
||||
g_string_append (s, "font-variant: small-caps; ");
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (set & PANGO_FONT_MASK_WEIGHT)
|
||||
{
|
||||
switch (pango_font_description_get_weight (desc))
|
||||
{
|
||||
case PANGO_WEIGHT_THIN:
|
||||
g_string_append (s, "font-weight: 100; ");
|
||||
break;
|
||||
case PANGO_WEIGHT_ULTRALIGHT:
|
||||
g_string_append (s, "font-weight: 200; ");
|
||||
break;
|
||||
case PANGO_WEIGHT_LIGHT:
|
||||
case PANGO_WEIGHT_SEMILIGHT:
|
||||
g_string_append (s, "font-weight: 300; ");
|
||||
break;
|
||||
case PANGO_WEIGHT_BOOK:
|
||||
case PANGO_WEIGHT_NORMAL:
|
||||
g_string_append (s, "font-weight: 400; ");
|
||||
break;
|
||||
case PANGO_WEIGHT_MEDIUM:
|
||||
g_string_append (s, "font-weight: 500; ");
|
||||
break;
|
||||
case PANGO_WEIGHT_SEMIBOLD:
|
||||
g_string_append (s, "font-weight: 600; ");
|
||||
break;
|
||||
case PANGO_WEIGHT_BOLD:
|
||||
g_string_append (s, "font-weight: 700; ");
|
||||
break;
|
||||
case PANGO_WEIGHT_ULTRABOLD:
|
||||
g_string_append (s, "font-weight: 800; ");
|
||||
break;
|
||||
case PANGO_WEIGHT_HEAVY:
|
||||
case PANGO_WEIGHT_ULTRAHEAVY:
|
||||
g_string_append (s, "font-weight: 900; ");
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (set & PANGO_FONT_MASK_STRETCH)
|
||||
{
|
||||
switch (pango_font_description_get_stretch (desc))
|
||||
{
|
||||
case PANGO_STRETCH_ULTRA_CONDENSED:
|
||||
g_string_append (s, "font-stretch: ultra-condensed; ");
|
||||
break;
|
||||
case PANGO_STRETCH_EXTRA_CONDENSED:
|
||||
g_string_append (s, "font-stretch: extra-condensed; ");
|
||||
break;
|
||||
case PANGO_STRETCH_CONDENSED:
|
||||
g_string_append (s, "font-stretch: condensed; ");
|
||||
break;
|
||||
case PANGO_STRETCH_SEMI_CONDENSED:
|
||||
g_string_append (s, "font-stretch: semi-condensed; ");
|
||||
break;
|
||||
case PANGO_STRETCH_NORMAL:
|
||||
g_string_append (s, "font-stretch: normal; ");
|
||||
break;
|
||||
case PANGO_STRETCH_SEMI_EXPANDED:
|
||||
g_string_append (s, "font-stretch: semi-expanded; ");
|
||||
break;
|
||||
case PANGO_STRETCH_EXPANDED:
|
||||
g_string_append (s, "font-stretch: expanded; ");
|
||||
break;
|
||||
case PANGO_STRETCH_EXTRA_EXPANDED:
|
||||
g_string_append (s, "font-stretch: extra-expanded; ");
|
||||
break;
|
||||
case PANGO_STRETCH_ULTRA_EXPANDED:
|
||||
g_string_append (s, "font-stretch: ultra-expanded; ");
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (set & PANGO_FONT_MASK_SIZE)
|
||||
{
|
||||
g_string_append_printf (s, "font-size: %dpt", pango_font_description_get_size (desc) / PANGO_SCALE);
|
||||
}
|
||||
|
||||
g_string_append (s, "}");
|
||||
|
||||
return g_string_free (s, FALSE);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_font_button_label_use_font (GtkFontButton *font_button)
|
||||
{
|
||||
@ -1183,7 +1304,7 @@ gtk_font_button_label_use_font (GtkFontButton *font_button)
|
||||
else
|
||||
{
|
||||
PangoFontDescription *desc;
|
||||
gchar *font, *data;
|
||||
gchar *data;
|
||||
|
||||
if (!priv->provider)
|
||||
{
|
||||
@ -1198,14 +1319,10 @@ gtk_font_button_label_use_font (GtkFontButton *font_button)
|
||||
if (!priv->use_size)
|
||||
pango_font_description_unset_fields (desc, PANGO_FONT_MASK_SIZE);
|
||||
|
||||
font = pango_font_description_to_string (desc);
|
||||
data = g_strconcat ("* { font: ", font, "; }", NULL);
|
||||
|
||||
data = pango_font_description_to_css (desc);
|
||||
gtk_css_provider_load_from_data (priv->provider, data, -1, NULL);
|
||||
|
||||
g_free (data);
|
||||
g_free (font);
|
||||
|
||||
pango_font_description_free (desc);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user