aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdrian Cumiskey <acumiskey@apache.org>2008-07-18 09:11:10 +0000
committerAdrian Cumiskey <acumiskey@apache.org>2008-07-18 09:11:10 +0000
commit18f3e432c4b8d9c7574e4feb4a1aca644ee50669 (patch)
tree6f09829f0f7b679de5221e7eb1610ee477f9f6b1
parent89c2011b3d6329bf957190e7b5316fff9fdec2bb (diff)
downloadxmlgraphics-fop-18f3e432c4b8d9c7574e4feb4a1aca644ee50669.tar.gz
xmlgraphics-fop-18f3e432c4b8d9c7574e4feb4a1aca644ee50669.zip
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/trunk@677863 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--src/java/org/apache/fop/fonts/FontInfo.java61
-rw-r--r--src/java/org/apache/fop/render/afp/fonts/AFPFontCollection.java16
2 files changed, 39 insertions, 38 deletions
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/*<FontTriplet>*/ 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.
* <br>
@@ -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/*<FontTriplet>*/ 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/*<FontTriplet>*/ 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);