Quellcode durchsuchen

Make FontInfo look for the same font-family and weight first, but with default font-style

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@438251 13f79535-47bb-0310-9956-ffa450edef68
tags/fop-0_93
Andreas L. Delmelle vor 18 Jahren
Ursprung
Commit
1db3f305e2

+ 21
- 7
src/java/org/apache/fop/fonts/FontInfo.java Datei anzeigen

@@ -53,6 +53,9 @@ public class FontInfo {
/** 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. */
@@ -121,7 +124,8 @@ 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 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,
@@ -138,9 +142,15 @@ public class FontInfo {
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);
}
@@ -153,6 +163,9 @@ public class FontInfo {
}

if (f != null) {
if (key != startKey) {
notifyFontReplacement(startKey, key);
}
return key;
} else {
return null;
@@ -231,13 +244,14 @@ public class FontInfo {
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 + "'.");
}
}

+ 6
- 12
test/layoutengine/standard-testcases/block_font-style.xml Datei anzeigen

@@ -60,27 +60,21 @@
<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>

Laden…
Abbrechen
Speichern