Search code examples
cairopangolibrsvg

Pango unable to find fonts with librsvg


I'm using librsvg to render an SVG file to a Cairo context. Afterwards I "manually" render some text on top using Pango.

When rendering the SVG I get Pango warnings that it could not load the fonts:
"couldn't load font "'Calibri' Not-Rotated 16", falling back to "Sans Not-Rotated 16", expect ugly output."

The manual text rendering via Pango afterwards works perfectly fine. I tried multiple different font families and they all render just fine without any warnings.

I even skimmed through the librsvg source to see how it is using Pango but I couldn't see any major differences to what I am doing.

I have no idea left how to continue debugging this issue, any advice on how Pango is locating the fonts under Windows and what may influence its ability to find them is greatly appreciated.

If that matters:
I downloaded all needed binaries from here: http://sourceforge.net/projects/ezwinports/files/


Solution

  • I must concentrate to not think about the amount of time wasted on this issue or my brain would melt.

    Anyways, in case someone comes across this post I will share what I had to figure out till it worked:

    • To get proper error messages from pango register a glib log handler, see below.
    • Pango assumes a specific folder-structure relative to the pango dll to look for some files. If the pango dll is located in /foo/bin or /foo it will try to locate "pango.modules" under /foo/etc/pango. That file contains information about where to find the pango module dlls. The easiest way I found was to place the pango module dlls under /foo/lib/pango/1.8.0/modules and then execute "pango-querymodules.exe > pango.modules" to generate the contents of the modules file and then manually remove the path, except for the actual dll filename. See below for the contents on my machine.
    • The actual problem which took me days to find out was this: I used SVGs which were exported from Adobe Illustrator and these contain text elements like this
      <text style="font-family:'Arial'; font-size:20;">Foo Bar</text>
      which looked fine to me, but the single quotation marks around the font family seem to be included and cause Pango to be unable to find the font 'Arial', because the fonts name is of course actually Arial and not 'Arial', if you know what I mean.

    Pango message handler

    void PangoMessageHandler(const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer user_data)
    {
        //TODO: handle log message
    }
    g_log_set_handler("Pango", G_LOG_LEVEL_WARNING | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION, PangoMessageHandler, NULL);
    

    pango.modules

    "pango-arabic-lang.dll" ArabicScriptEngineLang PangoEngineLang PangoRenderNone arabic:*
    "pango-basic-win32.dll" BasicScriptEngineWin32 PangoEngineShape PangoRenderWin32 common:
    "pango-indic-lang.dll" devaIndicScriptEngineLang PangoEngineLang PangoRenderNone devanagari:*
    "pango-indic-lang.dll" bengIndicScriptEngineLang PangoEngineLang PangoRenderNone bengali:*
    "pango-indic-lang.dll" guruIndicScriptEngineLang PangoEngineLang PangoRenderNone gurmukhi:*
    "pango-indic-lang.dll" gujrIndicScriptEngineLang PangoEngineLang PangoRenderNone gujarati:*
    "pango-indic-lang.dll" oryaIndicScriptEngineLang PangoEngineLang PangoRenderNone oriya:*
    "pango-indic-lang.dll" tamlIndicScriptEngineLang PangoEngineLang PangoRenderNone tamil:*
    "pango-indic-lang.dll" teluIndicScriptEngineLang PangoEngineLang PangoRenderNone telugu:*
    "pango-indic-lang.dll" kndaIndicScriptEngineLang PangoEngineLang PangoRenderNone kannada:*
    "pango-indic-lang.dll" mlymIndicScriptEngineLang PangoEngineLang PangoRenderNone malayalam:*
    "pango-indic-lang.dll" sinhIndicScriptEngineLang PangoEngineLang PangoRenderNone sinhala:*