aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/fop/fonts/FontInfo.java
diff options
context:
space:
mode:
authorAdrian Cumiskey <acumiskey@apache.org>2008-07-18 09:17:24 +0000
committerAdrian Cumiskey <acumiskey@apache.org>2008-07-18 09:17:24 +0000
commitd6c3b958f2bdf839a99ac83cfbd5149c661a9e75 (patch)
tree2c99fb381b66b96ee9b906a899c5a3d2f8f96b01 /src/java/org/apache/fop/fonts/FontInfo.java
parent030cd56ed235409e5fe6d2914d7224d9a58380c1 (diff)
downloadxmlgraphics-fop-d6c3b958f2bdf839a99ac83cfbd5149c661a9e75.tar.gz
xmlgraphics-fop-d6c3b958f2bdf839a99ac83cfbd5149c661a9e75.zip
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
Diffstat (limited to 'src/java/org/apache/fop/fonts/FontInfo.java')
-rw-r--r--src/java/org/apache/fop/fonts/FontInfo.java61
1 files changed, 39 insertions, 22 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() {