Setting font for GtkTextView

From gedit 3.20 we have

gedit_view_set_font (GeditView   *view,
                     gboolean     default_font,
                     const gchar *font_name)
        PangoFontDescription *font_desc;

        gedit_debug (DEBUG_VIEW);

        g_return_if_fail (GEDIT_IS_VIEW (view));

        if (default_font)
                GeditSettings *settings;
                gchar *font;

                settings = _gedit_app_get_settings (GEDIT_APP (g_application_get_default ()));
                font = gedit_settings_get_system_font (settings);

                font_desc = pango_font_description_from_string (font);
                g_free (font);
                g_return_if_fail (font_name != NULL);

                font_desc = pango_font_description_from_string (font_name);

        g_return_if_fail (font_desc != NULL);

        gtk_widget_override_font (GTK_WIDGET (view), font_desc);

        pango_font_description_free (font_desc);


/* Change default font throughout the widget */
font_desc = pango_font_description_from_string ("Serif 15");
gtk_widget_modify_font (view, font_desc);
pango_font_description_free (font_desc);


gtk_widget_override_font has been deprecated since version 3.16 and
should not be used in newly-written code.
This function is not useful in the context of CSS-based rendering. If
you wish to change the font a widget uses to render its text you should
use a custom CSS style, through an application-specific
GtkStyleProvider and a CSS style class.

So I should try to set font with CSS? It's a large effort without an
available example. And it seems that CSS style has changed for 3.20, so
same CSS code may not work for 3.18 and 3.20 and above.

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]