Forum How do I...?

Font/-config problems with a bit of a twist

ap
Hi,

I can’t get Prince to work. At first I used the generic Linux version, which gave me these error messages:

Fontconfig warning: no <cachedir> elements found. Check configuration.
Fontconfig warning: adding <cachedir>/var/cache/fontconfig</cachedir>
Fontconfig warning: adding <cachedir>~/.fontconfig</cachedir>
Fontconfig error: out of memory
prince: internal error: no available fonts


So I read around and found that the first thing people are told is to install the msttcorefonts package. Well, I can’t do that, but I did what I thought was the next best thing, and copied the MS Core Fonts TTF files I have into the lib/prince/fonts/ directory of my Prince installation.

That made no difference.

Then I saw it was recommended to people who have those errors to use the package appropriate to their OS. The server I’m on runs RHEL4, so I downloaded that package. Of course I can’t install this package any more than msttcorefonts, so I resorted to extracting the files from the RPM and copying the binary from lib/prince/bin/prince into my previous installation.

However, all I achieved by doing this was to silence the fontconfig warnings. I still get the final error message:

prince: internal error: no available fonts


And of course no joy – no PDF comes out.

Any hints?
mikeday
If you are on RHEL4, installing the appropriate Prince RPM package will give the best results.

With regards to fonts, if you can't install them in the system font directories to be picked up by fontconfig then you need to point to the files yourself using @font-face rules in a style sheet such as fonts.css, as described here.
ap
Thanks for the response. I tried the following:
@font-face {
    font-family: Arial;
    font-style: normal;
    font-weight: normal;
    src: url("../fonts/arial.ttf");
}

@font-face {
    font-family: Arial;
    font-style: normal;
    font-weight: bold;
    src: url("../fonts/arialbd.ttf");
}

@font-face {
    font-family: Arial;
    font-style: italic;
    font-weight: bold;
    src: url("../fonts/arialbi.ttf");
}

@font-face {
    font-family: Arial;
    font-style: italic;
    font-weight: normal;
    src: url("../fonts/ariali.ttf");
}

And many more. (I think I’ll post the complete file for the benefit of anyone else needing to do this, once I have my installation working.) I put this in a file called `microsoft-fonts.css` in the `lib/prince/style/`directory, next to Prince’s own `fonts.css` file, then added the following line to `fonts.css`:
import url("microsoft-fonts.css");

However, Prince still gives me the same error about having no fonts available.

Any further ideas?
ap
Answering my own question: simply inserting the rules directly into `fonts.css` instead of trying to `@import` them from another file will work.

Here, then, is a list of `@font-face` rules with pretty comprehensive coverage for the Microsoft fonts. It includes all the Core fonts, the new Vista fonts, and Century Gothic.
@font-face {
    font-family: Calibri;
    font-style: normal;
    font-weight: normal;
    src: url("../fonts/calibri.ttf");
}

@font-face {
    font-family: Calibri;
    font-style: normal;
    font-weight: bold;
    src: url("../fonts/calibrib.ttf");
}

@font-face {
    font-family: Calibri;
    font-style: italic;
    font-weight: normal;
    src: url("../fonts/calibrii.ttf");
}

@font-face {
    font-family: Calibri;
    font-style: italic;
    font-weight: bold;
    src: url("../fonts/calibriz.ttf");
}

@font-face {
    font-family: Cambria;
    font-style: normal;
    font-weight: normal;
    src: url("../fonts/cambria.ttf");
}

@font-face {
    font-family: Cambria;
    font-style: normal;
    font-weight: bold;
    src: url("../fonts/cambriab.ttf");
}

@font-face {
    font-family: Cambria;
    font-style: italic;
    font-weight: normal;
    src: url("../fonts/cambriai.ttf");
}

@font-face {
    font-family: Cambria;
    font-style: italic;
    font-weight: bold;
    src: url("../fonts/cambriaz.ttf");
}

@font-face {
    font-family: Candara;
    font-style: normal;
    font-weight: normal;
    src: url("../fonts/candara.ttf");
}

@font-face {
    font-family: Candara;
    font-style: normal;
    font-weight: bold;
    src: url("../fonts/candarab.ttf");
}

@font-face {
    font-family: Candara;
    font-style: italic;
    font-weight: normal;
    src: url("../fonts/candarai.ttf");
}

@font-face {
    font-family: Candara;
    font-style: italic;
    font-weight: bold;
    src: url("../fonts/candaraz.ttf");
}

@font-face {
    font-family: Consolas;
    font-style: normal;
    font-weight: normal;
    src: url("../fonts/consola.ttf");
}

@font-face {
    font-family: Consolas;
    font-style: normal;
    font-weight: bold;
    src: url("../fonts/consolab.ttf");
}

@font-face {
    font-family: Consolas;
    font-style: italic;
    font-weight: normal;
    src: url("../fonts/consolai.ttf");
}

@font-face {
    font-family: Consolas;
    font-style: italic;
    font-weight: bold;
    src: url("../fonts/consolaz.ttf");
}

@font-face {
    font-family: Constantia;
    font-style: normal;
    font-weight: normal;
    src: url("../fonts/constan.ttf");
}

@font-face {
    font-family: Constantia;
    font-style: normal;
    font-weight: bold;
    src: url("../fonts/constanb.ttf");
}

@font-face {
    font-family: Constantia;
    font-style: italic;
    font-weight: normal;
    src: url("../fonts/constani.ttf");
}

@font-face {
    font-family: Constantia;
    font-style: italic;
    font-weight: bold;
    src: url("../fonts/constanz.ttf");
}

@font-face {
    font-family: Corbel;
    font-style: normal;
    font-weight: normal;
    src: url("../fonts/corbel.ttf");
}

@font-face {
    font-family: Corbel;
    font-style: normal;
    font-weight: bold;
    src: url("../fonts/corbelb.ttf");
}

@font-face {
    font-family: Corbel;
    font-style: italic;
    font-weight: normal;
    src: url("../fonts/corbeli.ttf");
}

@font-face {
    font-family: Corbel;
    font-style: italic;
    font-weight: bold;
    src: url("../fonts/corbelz.ttf");
}

@font-face {
    font-family: Andale Mono;
    font-style: normal;
    font-weight: normal;
    src: url("../fonts/andalemo.ttf");
}

@font-face {
    font-family: Arial;
    font-style: normal;
    font-weight: normal;
    src: url("../fonts/arial.ttf");
}

@font-face {
    font-family: Arial;
    font-style: normal;
    font-weight: bold;
    src: url("../fonts/arialbd.ttf");
}

@font-face {
    font-family: Arial;
    font-style: italic;
    font-weight: bold;
    src: url("../fonts/arialbi.ttf");
}

@font-face {
    font-family: Arial;
    font-style: italic;
    font-weight: normal;
    src: url("../fonts/ariali.ttf");
}

@font-face {
    font-family: Arial Black;
    font-style: normal;
    font-weight: normal;
    src: url("../fonts/ariblk.ttf");
}

@font-face {
    font-family: Comic Sans MS;
    font-style: normal;
    font-weight: normal;
    src: url("../fonts/comic.ttf");
}

@font-face {
    font-family: Comic Sans MS;
    font-style: normal;
    font-weight: bold;
    src: url("../fonts/comicbd.ttf");
}

@font-face {
    font-family: Courier New;
    font-style: normal;
    font-weight: normal;
    src: url("../fonts/cour.ttf");
}

@font-face {
    font-family: Courier New;
    font-style: normal;
    font-weight: bold;
    src: url("../fonts/courbd.ttf");
}

@font-face {
    font-family: Courier New;
    font-style: italic;
    font-weight: bold;
    src: url("../fonts/courbi.ttf");
}

@font-face {
    font-family: Courier New;
    font-style: italic;
    font-weight: normal;
    src: url("../fonts/couri.ttf");
}

@font-face {
    font-family: Georgia;
    font-style: normal;
    font-weight: normal;
    src: url("../fonts/georgia.ttf");
}

@font-face {
    font-family: Georgia;
    font-style: normal;
    font-weight: bold;
    src: url("../fonts/georgiab.ttf");
}

@font-face {
    font-family: Georgia;
    font-style: italic;
    font-weight: normal;
    src: url("../fonts/georgiai.ttf");
}

@font-face {
    font-family: Georgia;
    font-style: italic;
    font-weight: bold;
    src: url("../fonts/georgiaz.ttf");
}

@font-face {
    font-family: Impact;
    font-style: normal;
    font-weight: normal;
    src: url("../fonts/impact.ttf");
}

@font-face {
    font-family: Tahoma;
    font-style: normal;
    font-weight: normal;
    src: url("../fonts/tahoma.ttf");
}

@font-face {
    font-family: Tahoma;
    font-style: normal;
    font-weight: bold;
    src: url("../fonts/tahomabd.ttf");
}

@font-face {
    font-family: Times New Roman;
    font-style: normal;
    font-weight: normal;
    src: url("../fonts/times.ttf");
}

@font-face {
    font-family: Times New Roman;
    font-style: normal;
    font-weight: bold;
    src: url("../fonts/timesbd.ttf");
}

@font-face {
    font-family: Times New Roman;
    font-style: italic;
    font-weight: bold;
    src: url("../fonts/timesbi.ttf");
}

@font-face {
    font-family: Times New Roman;
    font-style: italic;
    font-weight: normal;
    src: url("../fonts/timesi.ttf");
}

@font-face {
    font-family: Trebuchet MS;
    font-style: normal;
    font-weight: normal;
    src: url("../fonts/trebuc.ttf");
}

@font-face {
    font-family: Trebuchet MS;
    font-style: normal;
    font-weight: bold;
    src: url("../fonts/trebucbd.ttf");
}

@font-face {
    font-family: Trebuchet MS;
    font-style: italic;
    font-weight: bold;
    src: url("../fonts/trebucbi.ttf");
}

@font-face {
    font-family: Trebuchet MS;
    font-style: italic;
    font-weight: normal;
    src: url("../fonts/trebucit.ttf");
}

@font-face {
    font-family: Verdana;
    font-style: normal;
    font-weight: normal;
    src: url("../fonts/verdana.ttf");
}

@font-face {
    font-family: Verdana;
    font-style: normal;
    font-weight: bold;
    src: url("../fonts/verdanab.ttf");
}

@font-face {
    font-family: Verdana;
    font-style: italic;
    font-weight: normal;
    src: url("../fonts/verdanai.ttf");
}

@font-face {
    font-family: Verdana;
    font-style: italic;
    font-weight: bold;
    src: url("../fonts/verdanaz.ttf");
}

@font-face {
    font-family: Webdings;
    font-style: normal;
    font-weight: normal;
    src: url("../fonts/webdings.ttf");
}

@font-face {
    font-family: Century Gothic;
    font-style: normal;
    font-weight: normal;
    src: url("../fonts/gothic.ttf");
}

@font-face {
    font-family: Century Gothic;
    font-style: normal;
    font-weight: bold;
    src: url("../fonts/gothicb.ttf");
}

@font-face {
    font-family: Century Gothic;
    font-style: italic;
    font-weight: bold;
    src: url("../fonts/gothicbi.ttf");
}

@font-face {
    font-family: Century Gothic;
    font-style: italic;
    font-weight: normal;
    src: url("../fonts/gothici.ttf");
}
lhalaa
Fontconfig warning: no <cachedir> elements found. Check configuration.
Fontconfig warning: adding <cachedir>/var/cache/fontconfig</cachedir>
Fontconfig warning: adding <cachedir>~/.fontconfig</cachedir>

Hi,

How can I solve these warnings? I still can't get Prince to work. Any thoughts?

Thanks
mikeday
What Linux platform are you running on, which Prince build are you running, is Fontconfig installed on your system, and are there any fonts installed? (These last two questions probably depend on whether you're running on a desktop or server Linux machine).
lhalaa
Hi,

I'm running on a server RHL 4 and installed prince-6.0r7-linux.tar.gz. Recently, the msttcorefonts was installed that's why I don't get the internal error: no available fonts anymore but still getting these fontconfig warnings. I've also tried locate fontconfig and here's what I saw:
/usr/lib/libfontconfig.so.1
/usr/lib/libfontconfig.so.1.0.4
/var/cache/fontconfig
and some other folders..

If these warnings don't affect prince on generating pdfs, then I guess this isn't that important since I've successfully generated a pdf. I'm just wondering what's behind this warning. :)

Thanks
mikeday
Different versions of Fontconfig have different configuration file formats and look in different locations. If you're running on RHEL 4 you could install the RPM package instead, which uses the expected version of Fontconfig and will not produce any warnings.
lhalaa
Ok thanks! :)
somnath
Hi,
Can anyone let me know why the rules inserted directly into `fonts.css` will work and not when using `@import` from another file?

Thanks,
Somnath
mikeday
You should be able to import rules from other files, just remember that @imports must occur before other rules in the file and check the paths and syntax are correct.