* @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);
}
// 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) {
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>
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() {
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);