Font size from GtkFontChooser as a fractional value

When you get the font description with gtk_font_chooser_get_font then sometimes the font size is given as a fractional value, e.g. “DejaVu Sans Mono 29.849609375”. It seems to happen only by using the slider in the GtkFontChooserDialog, not by using plus/minus buttons. I guess that the raw value produced by the slider is used for generating the returned string. The gtk_font_chooser_get_font_size returns an integer which (in my case) must be divided by PANGO_SCALE: 30566 / 1024 = 29.849609375.

I can reproduce this only with older GTK3 versions, not with newer ones. So it seems to be rather a bug that was fixed. My problem is that I need to support all GTK3 versions starting from 3.10.

However, the old-fashioned GtkFontSelectionDialog also allows using values with a fractional part in the field “Size” (and this is definitely not a bug).

So I would like to ask a more general question: Do fractional font size (point) values make sense? Should I try to round fractional values returned by GtkFileChooser as described above?

I use font descriptions returned by GtkFontChooser for styling, e.g.: “*{font:DejaVu Sans Mono 29.849609375;}”.

Not sure if this helps but here it is.

I use ‘DejaVu Sans 10’ font and when I changed its size to 10.5 using GNOME Tweaks, everything worked as expected including all GTK apps and GNOME Shell itself except only KDE apps. They used truncated font size of 10.

So, I think if you are using fractional font size inside your own GTK app only, it should be fine.

As a general statement, the answer is yes: 29.8496 point DejaVu Sans Mono is a completely legal font size, and really no better or worse than 29 point or 30 point or anything else, since it’s all fractional coordinate scaling.

(IOW, each vertex is going to be at a certain coordinate, and one might happen to end up scaling to (0, 15.2345223) at 30 point, but fall at exactly (0, 15.0) when scaled to 29.8496 point.)

Unlike with bitmap fonts, there’s really nothing magical or special about whole integer scaling factors. Whole numbers make us feel better, but that’s really the only advantage they have.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.