Skip to content
Permalink
Browse files

pluma-view: Fix: Bold and Italic fonts don't work

  • Loading branch information...
sc0w committed Jul 9, 2018
1 parent 28fdfbb commit 8f3b1d625c86cc57b51c8acb3b1ab4e5f59d4d4d
Showing with 26 additions and 15 deletions.
  1. +26 −15 pluma/pluma-view.c
@@ -647,32 +647,43 @@ pluma_view_scroll_to_cursor (PlumaView *view)
}

static void
pluma_override_font (GtkWidget *widget,
const gchar *font)
pluma_override_font (GtkWidget *widget,
PangoFontDescription *font)
{
gchar *css;
GtkCssProvider *provider;
gchar *tempsize;
gchar *css;
gchar *family;
gchar *weight;
const gchar *style;
gchar *size;

provider = gtk_css_provider_new ();
tempsize = g_strdup (font);
family = g_strdup_printf ("font-family: %s;", pango_font_description_get_family (font));

weight = g_strdup_printf ("font-weight: %d;", pango_font_description_get_weight (font));

g_strreverse (tempsize);
g_strcanon (tempsize, "1234567890", '\0');
g_strreverse (tempsize);
if (pango_font_description_get_style (font) == PANGO_STYLE_NORMAL)
style = "font-style: normal;";
else if (pango_font_description_get_style (font) == PANGO_STYLE_ITALIC)
style = "font-style: italic;";
else
style = "font-style: oblique;";

gchar tempfont [strlen (font)];
strcpy (tempfont, font);
tempfont [strlen (font) - strlen (tempsize)] = 0;
size = g_strdup_printf ("font-size: %d%s;",
pango_font_description_get_size (font) / PANGO_SCALE,
pango_font_description_get_size_is_absolute (font) ? "px" : "pt");

css = g_strdup_printf ("textview { font-family: %s; font-size: %spt; }", tempfont, tempsize);
provider = gtk_css_provider_new ();
css = g_strdup_printf ("textview { %s %s %s %s }", family, weight, style, size);
gtk_css_provider_load_from_data (provider, css, -1, NULL);
g_free (css);

gtk_style_context_add_provider (gtk_widget_get_style_context (widget),
GTK_STYLE_PROVIDER (provider),
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
g_object_unref (provider);
g_free (css);
g_free (family);
g_free (weight);
g_free (size);
}

/* FIXME this is an issue for introspection */
@@ -713,7 +724,7 @@ pluma_view_set_font (PlumaView *view,

g_return_if_fail (font_desc != NULL);

pluma_override_font (GTK_WIDGET (view), pango_font_description_to_string (font_desc));
pluma_override_font (GTK_WIDGET (view), font_desc);

pango_font_description_free (font_desc);
}

0 comments on commit 8f3b1d6

Please sign in to comment.
You can’t perform that action at this time.