Page 1 of 1

PhysicalFonts doesn't handle case-sensitive font names

PostPosted: Mon Dec 12, 2011 2:39 pm
by jeromyevans
(Version 2.7.1)
In the PhysicalFonts class, the static method addPhysicalFont(URL) can't correctly load fonts with uppercase letters on case-sensitive filesystems.

Code: Select all
eg. file:/usr/share/fonts/type1/mathml/Symbol.pfb


The FontInfoFinder correctly reads the EmbedFontInfo of the .pfb and associated .afm file.
addPhysicalFont() later checks (again) whether the .afm file exists, however it converts the path to lowercase to compare extensions and then incorrectly expects to find the font file with the lowercase name. The cause is shown below at (1) and (2).

Code: Select all
EmbedFontInfo[] embedFontInfoList = fontInfoFinder.find(fontUrl, fontResolver, fontCache);
// ... snip ....
String lower = fontInfo.getEmbedFile().toLowerCase();   /// <----- (1) CONVERT TO LOWERCASE FOR EXT COMPARISON
log.debug("Processing physical font: " + lower);
debug.append(".. triplet " + triplet.getName()
    + " (priority " + triplet.getPriority() +"\n" );
                           
pf = null;
// xhtmlrenderer's org.xhtmlrenderer.pdf.ITextFontResolver.addFont
/ can handle
// .otf, .ttf, .ttc, .pfb
if (lower.endsWith(".otf") || lower.endsWith(".ttf") || lower.endsWith(".ttc") ) {
    pf = new PhysicalFont(triplet.getName(), fontInfo, fontResolver);
} else if (lower.endsWith(".pfb") ) {
    // See whether we have everything org.xhtmlrenderer.pdf.ITextFontResolver.addFont
    // will need - for a .pfb file, it needs a corresponding .afm or .pfm
    String afm = FontUtils.pathFromURL(lower);
    afm = afm.substring(0, afm.length()-4 ) + ".afm";  // drop the 'file:'
    log.debug("Looking for: " + afm);               
    File f = new File(afm);   /// <----- (2) STILL ASSUMES LOWERCASE FILENAME
    if (f.exists()) {  ....


I've attached a patch that corrects it by using fontInfo.getEmbedFile().

Regards,
Jeromy Evans