Forum How do I...?

figure out why prince can't find the font family serif

dahainsworth
So i have a work around in place but at this point I'm just annoyed I can't figure out why this isn't working. I think I have read everything on fonts I can find but still at a bit of a loss. Would be very grateful if anyone has ideas. Here's the situation.

I have a bit of a custom linux system that is heavily based on RHEL5ish.
I have always used the statically linked binary up until v10. I also have whats appears to be a functional fontconfig setup though I currently am not using it for anything else. If I run fc-match -s 'serif' for instance it tells me "Tymes.ttf: "Tymes" "Regular"" which is correct and expected, which is why i THINK fontconfig is largely setup correctly though it has way too many config files to make me happy. I have 2 font bundles installed in /usr/local/lib/X11/fonts/ ttf-arkpandora-2.04 and ttf-bitstream-vera.

The reason the statically linked binary is important is that the fontconfig config it uses differs from my system such that prince has always reported a fontconfig error about missing default config. Which was fine because everything worked. This is due to the fact I modified /usr/local/lib/prince/style/fonts.css thusly

@font-face {
font-family: serif;
src: local("Times New Roman"), local("DejaVu Serif")
}

and later

/* Times New Roman, Regular */
@font-face {
font-family: "Times New Roman";
font-weight: normal;
font-style: normal;
font-stretch: normal;
src: url("/usr/local/lib/X11/fonts/ttf-arkpandora-2.04/Tymes.ttf")
}


This always worked fine as I said through 9 and xml using elemets that created pre tags would request the serif font and find Tymes.

So when I needed v10 I saw that the static binary was finally gone. So i grabbed the dynamic one. In general it runs with no obvious errors. However processing an xml file that works perfect with v9-static I get an error of
prince: internal error: no available fonts
If I run prince through strace I can see it is happily interacting with fontconfig but not finding the fonts.

The workaround is to change font-family serif to map directly to the font file. This works fine, but I can't let go of two things that confuse me.

1) why isn't fontconfig working. i would expect if fc-match can map serif and 'Times New Roman' both to Tymes.ttf everything should be working. Since fontconfig can be such a beast to get right I should ignore it but I'd love to understand whats wrong. Thoughts? I can't really tell how prince interacts with fontconfig if there are other methods to discover why it can't get from Times New Roman to Tymes.ttf using fontconfig.

2) I tried taking fontconfig out of the picture by moving the font config default configs assuming that would cause princexml to fall back to its previous v9-static behavior but that also isnt working as expected. I get the same "no available fonts" error, which suggests a change in v10 on how it processes the fonts.css file maybe? I'm surprised v9-static and v10-dynamic wouldn't work the same with fontconfig effectively out of the picture. So i'm also curious if anything changed in how fonts.css is processed between 9 and 10 or static and dynamic.



mikeday
Which Prince 10 package are you using, the CentOS 5 package or Generic Linux?
dahainsworth
generic linux
mikeday
The CentOS package might give better results if the distribution is sufficiently RHEL5ish in terms of shared library versions.

The rules for @font-face have changed: local() now only matches system fonts, not other @font-face rules defined in CSS, so you have to use prince-lookup("Times New Roman") instead to match a @font-face rule that is defining Times New Roman.
dahainsworth
AHA! so that did change. thank you so much for explaining it was a mystery that was driving me crazy :)
thank you so much for that info.

as i said I have at least one work around in place. mostly im curious why what i expect to work doesnt. i still can't see why it can't find Tymes when fontconfig is being used, since fontconfig claims it can see it. i think i need to find some test code for fontconfig or something. its very odd and my last mystery.
dahainsworth
bah that was totally in the release notes. now i feel bad because i help write release notes for some products.
mikeday
If you run "fc-list Tymes" it should return available fonts, and those fonts should be visible to Prince unless something funny is going on with fontconfig. Running Prince with the --debug option might provide some helpful output regarding font scanning.
dahainsworth
thats whats so odd


> prince --debug xml2.xml
prince: debug: init locking for OpenSSL
prince: debug: loading license: /usr/local/lib/prince/license/license.dat
prince: loading document: /usr/local/lib/prince/license/license.dat
prince: debug: loaded resource: /usr/local/lib/prince/license/license.dat
prince: debug: loaded resource: type: no
prince: loading style sheet: /usr/local/lib/prince/style/fonts.css
prince: debug: loaded resource: /usr/local/lib/prince/style/fonts.css
prince: debug: loaded resource: type: no
prince: Loading document...
prince: debug: starting prefetch threads
prince: loading XML input: xml2.xml
prince: loading document: xml2.xml
prince: debug: loaded resource: xml2.xml
prince: debug: loaded resource: type: no
prince: debug: loaded document: xml2.xml
prince: debug: sniffed doctype: XML
prince: Applying style sheets...
prince: loading style sheet: /usr/local/lib/prince/style/xhtml-ns.css
prince: debug: loaded resource: /usr/local/lib/prince/style/xhtml-ns.css
prince: debug: loaded resource: type: no
prince: loading style sheet: /usr/local/lib/prince/style/common.css
prince: debug: loaded resource: /usr/local/lib/prince/style/common.css
prince: debug: loaded resource: type: no
prince: loading style sheet: /usr/local/lib/prince/style/hyph.css
prince: debug: loaded resource: /usr/local/lib/prince/style/hyph.css
prince: debug: loaded resource: type: no
prince: loading style sheet: /usr/local/lib/prince/style/mathml.css
prince: debug: loaded resource: /usr/local/lib/prince/style/mathml.css
prince: debug: loaded resource: type: no
prince: loading style sheet: /usr/local/lib/prince/style/svg.css
prince: debug: loaded resource: /usr/local/lib/prince/style/svg.css
prince: debug: loaded resource: type: no
prince: Preparing document...
prince: debug: stopping prefetch threads
prince: Converting document...
prince: debug: pack
prince: debug: font request: serif
prince: internal error: no available fonts

from fonts.css
---
@font-face {
font-family: serif;
src: local("Times New Roman"), local("DejaVu Serif")
}
<snip>
/* Times New Roman, Regular */
@font-face {
font-family: "Times New Roman";
font-weight: normal;
font-style: normal;
font-stretch: normal;
src: url("/usr/local/lib/X11/fonts/ttf-arkpandora-2.04/Tymes.ttf")
}
---



> fc-match serif
Tymes.ttf: "Tymes" "Regular"

> fc-match "Times New Roman"
Tymes.ttf: "Tymes" "Regular"

> fc-list Tymes
/usr/local/lib/X11/fonts/ttf-arkpandora-2.04/Tymes.ttf: Tymes:style=Regular
/usr/local/lib/X11/fonts/ttf-arkpandora-2.04/TymesBd.ttf: Tymes:style=Bold




oddly
src: local("Tymes") works
src: prince-lookup("Times New Roman") works

So clearly I have an issue with fontconfig finding "Times New Roman" even though it would appear fontconfig knows that should map to the same thing as Tymes. Still digging.
mikeday
That helps to narrow down the issue. If local("Tymes") or just "font-family: Tymes" works then that is consistent with "fc-list Tymes" pointing to specific .ttf files. But it appears that Fontconfig is returning some kind of redirect for Times New Roman that Prince can't process. Do you know what rule in the Fontconfig config file might be causing this?
dahainsworth
yeah that is what I figured too, though I was imagining that pricexml would use similar calls to however fc-match works which would suggest it should be able to resolve "Times New Roman" to Tymes.ttf as fc-match does. however as you are probably well aware proper fontconfig configs are more an art than science :)

as far as I know our config is fairly standard without only a couple of changes

all files are in /usr/local/etc/fonts/

/usr/local/etc/fonts/local.conf has

<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<dir>/usr/local/lib/X11/fonts/ttf-bitstream-vera</dir>
<dir>/usr/local/lib/X11/fonts/ttf-arkpandora-2.04</dir>
<dir>/usr/local/lib/prince/fonts</dir>
<cachedir>/var/cache/fontconfig</cachedir>
<alias>
<family>serif</family>
<prefer>
<family>Tymes</family>
</prefer>
</alias>


there are no references to Times New Roman there .. however there are in /usr/local/etc/fonts/conf.d/

I thought I was on to something when I saw that /usr/local/etc/fonts/conf.d/45-latin.conf maps Times New Roman to serif .. and in /usr/local/etc/fonts/conf.d/60-latin.conf they map serif to Times New Roman among other families .. aha, I thought, a loop! :) but removing this and rerunning rc-cache did not change the odd behavior.

<alias>
<family>Times New Roman</family>
<default><family>serif</family></default>
</alias>

and

<alias>
<family>serif</family>
<prefer>
<family>Bitstream Vera Serif</family>
<family>DejaVu Serif</family>
<family>Times New Roman</family>
<family>Thorndale AMT</family>
<family>Luxi Serif</family>
<family>Nimbus Roman No9 L</family>
<family>Times</family>
</prefer>
</alias>



/usr/local/etc/fonts/conf.d/30-metric-aliases.conf also adds an alies to TImes New Roman of Times as sort of a multiple fallback but again removing that did not seem to resolve the issue.