I’m using the library from freetype.org to load a font into OpenGL. For now, the filename passed to FT_New_Face is given manually, but these filenames tend to change during Fedora upgrades.
Looking at pango_font_description_to_filename (accessed through gtk_widget_get_pango_context and pango_context_get_font_description), I’d hoped to get a filename located in /usr/share/fonts, such that I can share the font specified in CSS and used across my GtkWindows with OpenGL, but instead I get a string that has no connection to any physical file at all.
Hi @MischaBaars! Pango.FontDescription.to_filename doesn’t return the path to the font file, it’s just a way to serialize the PangoFontDescription structure to a string. I suggest that:
- Get a
PangoCairoFontMap for FreeType fonts: call pango_cairo_font_map_new_for_font_type with the
- Call pango_font_map_load_font to get a
PangoFont from your
- Get the underlying
hb_font_t using pango_font_get_hb_font
- Get the
FT_Face using either
hb_ft_font_get_face or hb_ft_font_lock_face
Note that unless you want to use advanced rendering features of FreeType, you can use Pango directly to render into a Cairo image surface
Migrating to HarfBuzz would only make things complicated. I don’t use any GSK or Cairo related functions either. I use OpenGL and the GtkGLArea to do some font related rendering. I would like to keep it that way for now.
All I’d like to know from GTK is the name of the font file it uses, when I tell the application to use a particular font, i.e.
Because the during a Fedora upgrade, the CSS syntax stays the same, but most likely the names of the font files in /usr/share/fonts/ will have changed.
Is it possible, and how do I do it?
PangoFontDescription Is a logical font description, only a PangoFontMap can map that description to a physical font. If you want the same PangoFontMap used by GTK, just call pango_cairo_font_map_get_default on the UI thread. Anyway you don’t have to use harfbuzz, it’s just an intermediate step to get the
Note that a font is not always backed by a file; it could be created from in-memory data, a resource bundle or a remote service. In addition, some font files provide multiple font faces.
That said, perhaps there are FontConfig or FreeType API that give you back a file path, but I don’t know any.
Thank you for this information. Let me try.
Ok. These are my findings:
The font family name can be retrieved using gtk_widget_get_pango_context() → pango_context_get_font_description() → pango_font_description_get_family(), but the output relates only to input from GtkSettings::gtk-font-name and does not relate to CSS input.
I fear it’s not only the /usr/share/fonts file that can not be retrieved, but when specified from CSS, it’s the font-family as well.
Also I was unable to find a function that makes changes to pango_font_description permanent. Calling gtk_widget_queue_draw() is insufficient.
I think my only option is to inline all CSS. That way I have the font-family available at all times.
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.