/** look up a font-name to get a font (that implements FontMetrics at least) */
private Map fonts;
+ /** collection of missing fonts; used to make sure the user gets
+ * a warning for a missing font only once (not every time the font is used)
+ */
private Collection loggedFontKeys;
/** Cache for Font instances. */
* @param family font family
* @param style font style
* @param weight font weight
- * @param substFont true if the font may be substituted with the default font if not found
+ * @param substFont true if the font may be substituted with the
+ * default font if not found
* @return internal key
*/
private FontTriplet fontLookup(String family, String style,
if (!substFont && f == null) {
return null;
}
- // then try any family with orig weight
+
+ // try the same font-family and weight with default style
+ if (f == null) {
+ key = createFontKey(family, "normal", weight);
+ f = getInternalFontKey(key);
+ }
+
+ // then try any family with orig style/weight
if (f == null) {
- notifyFontReplacement(startKey);
key = createFontKey("any", style, weight);
f = getInternalFontKey(key);
}
}
if (f != null) {
+ if (key != startKey) {
+ notifyFontReplacement(startKey, key);
+ }
return key;
} else {
return null;
throw new IllegalStateException("fontLookup must return a key on the last call");
}
- private void notifyFontReplacement(FontTriplet key) {
+ private void notifyFontReplacement(FontTriplet replacedKey, FontTriplet newKey) {
if (loggedFontKeys == null) {
loggedFontKeys = new java.util.HashSet();
}
- if (!loggedFontKeys.contains(key)) {
- loggedFontKeys.add(key);
- log.warn("Font '" + key + "' not found. Substituting with default font.");
+ if (!loggedFontKeys.contains(replacedKey)) {
+ loggedFontKeys.add(replacedKey);
+ log.warn("Font '" + replacedKey + "' not found. "
+ + "Substituting with '" + newKey + "'.");
}
}
<eval expected="normal" xpath="//flow/block[2]/lineArea/text/@font-style"/>
<eval expected="italic" xpath="//flow/block[3]/lineArea/text/@font-style"/>
<eval expected="oblique" xpath="//flow/block[4]/lineArea/text/@font-style"/>
- <eval expected="normal" xpath="//flow/block[5]/lineArea/text/@font-style"/>
- <eval expected="any" xpath="//flow/block[5]/lineArea/text/@font-name"/> <!-- style not registered -> any, normal -->
- <eval expected="normal" xpath="//flow/block[6]/lineArea/text/@font-style"/>
- <eval expected="serif" xpath="//flow/block[6]/lineArea/text/@font-name"/> <!-- illegal style -> back to default=serif, normal -->
+ <eval expected="normal" xpath="//flow/block[5]/lineArea/text/@font-style"/> <!-- style not registered -> normal -->
+ <eval expected="normal" xpath="//flow/block[6]/lineArea/text/@font-style"/> <!-- illegal style -> normal -->
<eval expected="normal" xpath="//flow/block[7]/lineArea/text/@font-style"/>
<eval expected="normal" xpath="//flow/block[8]/lineArea/text/@font-style"/>
<eval expected="italic" xpath="//flow/block[9]/lineArea/text/@font-style"/>
<eval expected="oblique" xpath="//flow/block[10]/lineArea/text/@font-style"/>
- <eval expected="normal" xpath="//flow/block[11]/lineArea/text/@font-style"/>
- <eval expected="any" xpath="//flow/block[11]/lineArea/text/@font-name"/> <!-- style not registered -> any, normal -->
- <eval expected="normal" xpath="//flow/block[12]/lineArea/text/@font-style"/>
- <eval expected="sans-serif" xpath="//flow/block[12]/lineArea/text/@font-name"/> <!-- illegal style -> back to default=sans-serif, normal -->
+ <eval expected="normal" xpath="//flow/block[11]/lineArea/text/@font-style"/> <!-- style not registered -> normal -->
+ <eval expected="normal" xpath="//flow/block[12]/lineArea/text/@font-style"/> <!-- illegal style -> normal -->
<eval expected="normal" xpath="//flow/block[13]/lineArea/text/@font-style"/>
<eval expected="normal" xpath="//flow/block[14]/lineArea/text/@font-style"/>
<eval expected="italic" xpath="//flow/block[15]/lineArea/text/@font-style"/>
<eval expected="oblique" xpath="//flow/block[16]/lineArea/text/@font-style"/>
- <eval expected="normal" xpath="//flow/block[17]/lineArea/text/@font-style"/>
- <eval expected="any" xpath="//flow/block[17]/lineArea/text/@font-name"/> <!-- style not registered -> any, normal -->
- <eval expected="normal" xpath="//flow/block[18]/lineArea/text/@font-style"/>
- <eval expected="monospace" xpath="//flow/block[18]/lineArea/text/@font-name"/> <!-- illegal style -> back to default=monospace, normal -->
+ <eval expected="normal" xpath="//flow/block[17]/lineArea/text/@font-style"/> <!-- style not registered -> normal -->
+ <eval expected="normal" xpath="//flow/block[18]/lineArea/text/@font-style"/> <!-- illegal style -> normal -->
</checks>
</testcase>