How to find out which OS-specific backends are in use?

I’m using prebuilt versions of Pango on Windows and macOS. On Windows I’m using the Pango build provided by MSYS2 and on macOS I’m using the one provided by Macports. How can I find out which OS-specific backends are used by the builds?

Specifically, I want to find out the following:

  1. Does the build use fontconfig or some Windows/macOS-specific API to match fonts?
  2. Does the build use freetype2 or CoreText on macOS?
  3. Does the build use freetype2 or GDI/DirectWrite on Windows?

How can I find this out please? Thanks!

Well, it depends on which objects you create (mostly). When not using PangoCairo, you have the option of creating the following font maps:

  • PangoFcFontMap (Linux, Windows, macOS)
  • PangoWin32FontMap (Windows - used GDI until Pango 1.50.12, uses DirectWrite since then)
  • PangoCoreTextFontMap (macOS)

That tells you what’s used for font discovery and font fallback. For the rendering part, you have the option of creating:

  • FreeType2 fonts (Linux, Windows, macOS)
  • Win32 fonts (Windows - uses GDI for rendering)
  • Xft fonts (Linux, perhaps even macOS?)
  • CoreText fonts (macOS)

These fonts render on native surfaces, i.e you can render onto FT_BitMap, HDC, XftDraw or even a Xft Picture. For CoreText fonts instead it’s a bit different though - you get a CTFontRef back and render yourself using native macOS APIs.

When using PangoCairo, instead, you can set the environment variable PANGOCAIRO_BACKEND to one of fc, win32, coretext to use a specific Cairo backend. Otherwise you can call pango_cairo_font_map_new_for_font_type() passing wither CAIRO_FONT_TYPE_QUARTZ, CAIRO_FONT_TYPE_WIN32, CAIRO_FONT_TYPE_FT, it’s the same.

  • PANGOCAIRO_BACKEND=fc: PangoCairo uses PangoFcFontMap to discover fonts on the system
  • PANGOCAIRO_BACKEND=win32: PangoCairo uses PangoWin32FontMap to discover fonts. Cairo fonts created that way use DirectWrite for rendering if Cairo was compiled DirectWrite support, otherwise uses GDI
  • PANGOCAIRO_BACKEND=coretext: PangoCairo uses PangoCoreTextFontMap to discover fonts

See Pango Reference Manual: Pango Reference Manual for an overview

1 Like

Thanks for your elaborate reply but how can I find out the backend if I don’t specify it explicitly? I’m using PangoCairo and I create my fonts like this:

fontmap = pango_cairo_font_map_new();
fontdesc = pango_font_description_from_string("Arial 144px");
context = pango_font_map_create_context(fontmap);
layout = pango_layout_new(context);
pango_layout_set_font_description(layout, fontdesc);
font = pango_font_map_load_font(fontmap, context, fontdesc);

So how can I find out which backend Cairo uses in that case? The documentation on pango_cairo_font_map_new says that Cairo will use the “particular font backend Cairo was compiled to use” but that doesn’t help me because I didn’t compile Cairo myself. How can I find out what’s the default backend in that case?

Defaults are coded here: pango/pangocairo-fontmap.c · 1.50.14 · GNOME / pango · GitLab

Basically, it’s FontConfig (discovery) & FreeType (rendering) on Linux, GDI/DirectWrite on Windows and CoreText on macOS. You can also override that using pango_cairo_font_map_new_for_font_type()

1 Like

The documentation for specifically says

Note that the type of the returned object will depend on the particular font backend Cairo was compiled to use

What this means is that will not return an object of type PangoCairo.FontMap. Instead, it will return an object of its subclass.

So, you can use G_OBJECT_TYPE_NAME() macro to get type name of the returned object. Once you know the type names for all backends you are interested in, you can use <LIB_NAME>_IS_<TYPE_NAME>() style macros e.g. PANGO_FC_IS_FONT_MAP(), PANGO_XFT_IS_FONT_MAP(), etc. to find out if the object is of the specified type or not. This will effectively let you know, what backend is being used.

Edit: It seems like backend-specific classes are private. So, you cannot use PANGO_CAIRO_IS_<CLASS_NAME>() macros e.g PANGO_CAIRO_IS_FC_FONT_MAP(). Therefore, you’ll have to do string comparisons on the string returned by G_OBJECT_TYPE_NAME() in order to find out what backend is being used.


Right! :+1: To add to that, one can also use pango_cairo_font_map_get_font_type to find out


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