From: Adrian Cumiskey Date: Fri, 18 Jul 2008 09:17:24 +0000 (+0000) Subject: Merged revisions 677863 via svnmerge from X-Git-Tag: fop-1_0~376^2~134 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=d6c3b958f2bdf839a99ac83cfbd5149c661a9e75;p=xmlgraphics-fop.git Merged revisions 677863 via svnmerge from https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk ........ r677863 | acumiskey | 2008-07-18 10:11:10 +0100 (Fri, 18 Jul 2008) | 4 lines Ok, I am much happier with this fix now, it doesn't feel like a temporary hack anymore :). I have revised the fontLookup() algorithm in FontInfo so it now first tries to find matching font triplets by iterating over all the font family names *without substitutions*, if this fails it then iterates over all the font family names looking for matching font triplets *with substitutions* rather then just take the last one in the font family name list with substitutions. ........ git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_AFPGOCAResources@677864 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/fop/fonts/FontInfo.java b/src/java/org/apache/fop/fonts/FontInfo.java index 8e915588f..8272a9bdf 100644 --- a/src/java/org/apache/fop/fonts/FontInfo.java +++ b/src/java/org/apache/fop/fonts/FontInfo.java @@ -188,12 +188,12 @@ public class FontInfo { * @param family font family * @param style font style * @param weight font weight - * @param substFont true if the font may be substituted with the + * @param substitutable true if the font may be substituted with the * default font if not found * @return internal font triplet key */ private FontTriplet fontLookup(String family, String style, - int weight, boolean substFont) { + int weight, boolean substitutable) { if (log.isTraceEnabled()) { log.trace("Font lookup: " + family + " " + style + " " + weight); } @@ -203,7 +203,7 @@ public class FontInfo { // first try given parameters String internalFontKey = getInternalFontKey(fontTriplet); if (internalFontKey == null) { - fontTriplet = fuzzyFontLookup(family, style, weight, startKey, substFont); + fontTriplet = fuzzyFontLookup(family, style, weight, startKey, substitutable); } if (fontTriplet != null) { @@ -345,6 +345,19 @@ public class FontInfo { return fontLookup(family, style, weight, true); } + private List/**/ fontLookup(String[] families, String style, + int weight, boolean substitutable) { + List matchingTriplets = new java.util.ArrayList(); + FontTriplet triplet = null; + for (int i = 0; i < families.length; i++) { + triplet = fontLookup(families[i], style, weight, substitutable); + if (triplet != null) { + matchingTriplets.add(triplet); + } + } + return matchingTriplets; + } + /** * Looks up a set of fonts. *
@@ -363,28 +376,32 @@ public class FontInfo { if (families.length == 0) { throw new IllegalArgumentException("Specify at least one font family"); } - FontTriplet triplet; - List tmpTriplets = new java.util.ArrayList(); - for (int i = 0, c = families.length; i < c; i++) { - boolean substitutable = (i >= families.length - 1); - triplet = fontLookup(families[i], style, weight, substitutable); - if (triplet != null) { - tmpTriplets.add(triplet); - } - } - if (tmpTriplets.size() != 0) { - return (FontTriplet[]) tmpTriplets.toArray(TRIPLETS_TYPE); + + // try matching without substitutions + List/**/ matchedTriplets = fontLookup(families, style, weight, false); + + // if there are no matching font triplets found try with substitutions + if (matchedTriplets.size() == 0) { + matchedTriplets = fontLookup(families, style, weight, true); } - StringBuffer sb = new StringBuffer(); - for (int i = 0, c = families.length; i < c; i++) { - if (i > 0) { - sb.append(", "); + + // no matching font triplets found! + if (matchedTriplets.size() == 0) { + StringBuffer sb = new StringBuffer(); + for (int i = 0, c = families.length; i < c; i++) { + if (i > 0) { + sb.append(", "); + } + sb.append(families[i]); } - sb.append(families[i]); + throw new IllegalStateException( + "fontLookup must return an array with at least one " + + "FontTriplet on the last call. Lookup: " + sb.toString()); + } - throw new IllegalStateException( - "fontLookup must return an array with at least one " - + "FontTriplet on the last call. Lookup: " + sb.toString()); + + // found some matching fonts so return them + return (FontTriplet[]) matchedTriplets.toArray(TRIPLETS_TYPE); } private Set/**/ getLoggedFontKeys() { diff --git a/src/java/org/apache/fop/render/afp/fonts/AFPFontCollection.java b/src/java/org/apache/fop/render/afp/fonts/AFPFontCollection.java index df2f4a105..55953daf0 100644 --- a/src/java/org/apache/fop/render/afp/fonts/AFPFontCollection.java +++ b/src/java/org/apache/fop/render/afp/fonts/AFPFontCollection.java @@ -97,22 +97,6 @@ public class AFPFontCollection implements FontCollection { fontInfo.addMetrics("F" + num, bf); num++; } - if (fontInfo.fontLookup("Symbol", Font.STYLE_NORMAL, Font.WEIGHT_NORMAL) == null) { - FontTriplet ft = fontInfo.fontLookup( - "sans-serif", Font.STYLE_NORMAL, Font.WEIGHT_NORMAL); - fontInfo.addFontProperties( - fontInfo.getInternalFontKey(ft), - "Symbol", Font.STYLE_NORMAL, Font.WEIGHT_NORMAL); - num++; - } - if (fontInfo.fontLookup("ZapfDingbats", Font.STYLE_NORMAL, Font.WEIGHT_NORMAL) == null) { - FontTriplet ft = fontInfo.fontLookup( - "sans-serif", Font.STYLE_NORMAL, Font.WEIGHT_NORMAL); - fontInfo.addFontProperties( - fontInfo.getInternalFontKey(ft), - "ZapfDingbats", Font.STYLE_NORMAL, Font.WEIGHT_NORMAL); - num++; - } if (fontInfo.fontLookup("any", Font.STYLE_NORMAL, Font.WEIGHT_NORMAL) == null) { FontTriplet ft = fontInfo.fontLookup( "sans-serif", Font.STYLE_NORMAL, Font.WEIGHT_NORMAL);