@@ -647,32 +647,43 @@ pluma_view_scroll_to_cursor (PlumaView *view)
647647}
648648
649649static void
650- pluma_override_font (GtkWidget * widget ,
651- const gchar * font )
650+ pluma_override_font (GtkWidget * widget ,
651+ PangoFontDescription * font )
652652{
653- gchar * css ;
654653 GtkCssProvider * provider ;
655- gchar * tempsize ;
654+ gchar * css ;
655+ gchar * family ;
656+ gchar * weight ;
657+ const gchar * style ;
658+ gchar * size ;
656659
657- provider = gtk_css_provider_new ();
658- tempsize = g_strdup (font );
660+ family = g_strdup_printf ("font-family: %s;" , pango_font_description_get_family (font ));
661+
662+ weight = g_strdup_printf ("font-weight: %d;" , pango_font_description_get_weight (font ));
659663
660- g_strreverse (tempsize );
661- g_strcanon (tempsize , "1234567890" , '\0' );
662- g_strreverse (tempsize );
664+ if (pango_font_description_get_style (font ) == PANGO_STYLE_NORMAL )
665+ style = "font-style: normal;" ;
666+ else if (pango_font_description_get_style (font ) == PANGO_STYLE_ITALIC )
667+ style = "font-style: italic;" ;
668+ else
669+ style = "font-style: oblique;" ;
663670
664- gchar tempfont [ strlen ( font )];
665- strcpy ( tempfont , font );
666- tempfont [ strlen (font ) - strlen ( tempsize )] = 0 ;
671+ size = g_strdup_printf ( " font-size: %d%s;" ,
672+ pango_font_description_get_size ( font ) / PANGO_SCALE ,
673+ pango_font_description_get_size_is_absolute (font ) ? "px" : "pt" ) ;
667674
668- css = g_strdup_printf ("textview { font-family: %s; font-size: %spt; }" , tempfont , tempsize );
675+ provider = gtk_css_provider_new ();
676+ css = g_strdup_printf ("textview { %s %s %s %s }" , family , weight , style , size );
669677 gtk_css_provider_load_from_data (provider , css , -1 , NULL );
670- g_free (css );
671678
672679 gtk_style_context_add_provider (gtk_widget_get_style_context (widget ),
673680 GTK_STYLE_PROVIDER (provider ),
674681 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION );
675682 g_object_unref (provider );
683+ g_free (css );
684+ g_free (family );
685+ g_free (weight );
686+ g_free (size );
676687}
677688
678689/* FIXME this is an issue for introspection */
@@ -713,7 +724,7 @@ pluma_view_set_font (PlumaView *view,
713724
714725 g_return_if_fail (font_desc != NULL );
715726
716- pluma_override_font (GTK_WIDGET (view ), pango_font_description_to_string ( font_desc ) );
727+ pluma_override_font (GTK_WIDGET (view ), font_desc );
717728
718729 pango_font_description_free (font_desc );
719730}
0 commit comments