Hello.

I'm trying to make a small application in C using GTK+3 (the latest
stable). The application is going to have a text field implemented using
GtkTextView where a user can write text. I also font a user to be able to
change font, so I've added a font chooser using GtkFontChooserDialog.

The problem is that I don't know how to actually set the font of a text
field to the one that a user chose using font chooser. Well, at least not
using an up-to-date method. I know I can use gtk_widget_override_font(),
and though it works perfectly, I'd rather not use it since it's deprecated
function so it's not meant to be used anymore.

I've tried two other ways though, but both of them failed in one respect or
the other. I'll now describe those two ways:

 1. Using CSS
    I tried using CSS. The way I'd do this is I'd get a font that a user
chose using gtk_font_chooser_get_font(), then I'd format it in a CSS
syntax, such that, for example, Hack 11 Bold, becomes textview { bold 11pt
Hack }. This worked for the most fonts, but there were fonts like B&H
LucidaBright that had "strange" styles like Sans or Book, or Linux
Libertine Initials O Initials that had style called Initial. I managed to
format some of them too, but not all of them, leaving few fonts non-usable.

2. Using GtkTextTag
    I tried creating a tag for a buffer that with a font description of the
currently selected font. This worked perfectly for all fonts, but it
produced two other "errors": 1. It didn't actually change the context style
of the widget, through which I get currently active font for some other
purpose, and 2. using gtk_text_buffer_apply_tag() I was able to set the
font only to the text between the current begin and end, meaning that later
modifications to the text were in the starting font.

In a nutshell, the problem with first approach is that it doesn't work for
all fonts, while the problem with the second one is that it doesn't really
change the font of a widget but only the font of the current text in a
buffer.

Therefore, I'd like to know a non-deprecated way of achieving what a
deprecated function gtk_widget_override_font() achieves. Also, I see that
the first problem with the second approach can be fixed by holding the
user-selected font in a variable, and the second problem of the same
approach by setting the font on every insertion, but those are impractical
"patches" rather than proper methods. I guess that a proper way is using
CSS, but I just don't know how to do it properly (if it is possible, of
course).

If it is not possible to achieve the same effects of
gtk_widget_override_font() in an up-to-date way, then I guess I'd just have
to use gtk_widget_override_font() after all.

Thank you for reading this and I'll hope you'll help me to solve my problem.
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Reply via email to