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:
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.
window *
{
font-family: …;
}
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.
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 FT_Face back.
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.
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.