Bugfix: font-weight:bold (700) was not mapped to TextAttribute.BOLD, possibly resulting in too bold a font.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/batik/branches/svgcolor12@1141530 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/sources/org/apache/batik/bridge/TextUtilities.java b/sources/org/apache/batik/bridge/TextUtilities.java
index 52aa679..0373e65 100644
--- a/sources/org/apache/batik/bridge/TextUtilities.java
+++ b/sources/org/apache/batik/bridge/TextUtilities.java
@@ -206,8 +206,10 @@
public static Float convertFontWeight(Element e) {
Value v = CSSUtilities.getComputedStyle
(e, SVGCSSEngine.FONT_WEIGHT_INDEX);
- float f = v.getFloatValue();
- switch ((int)f) {
+ int weight = (int)v.getFloatValue();
+ //Note: the mapping from CSS2 to TextAttribute's weights is somewhat arbitrary.
+ //Important is to map 400/normal to REGULAR and 700/bold to BOLD.
+ switch (weight) {
case 100:
return TextAttribute.WEIGHT_EXTRA_LIGHT;
case 200:
@@ -219,17 +221,27 @@
case 500:
return TextAttribute.WEIGHT_SEMIBOLD;
default:
- return TextAttribute.WEIGHT_BOLD;
- /* Would like to do this but the JDK 1.3 & 1.4
- seems to drop back to 'REGULAR' instead of 'BOLD'
- if there is not a match.
- case 700:
- return TextAttribute.WEIGHT_HEAVY;
- case 800:
- return TextAttribute.WEIGHT_EXTRABOLD;
- case 900:
- return TextAttribute.WEIGHT_ULTRABOLD;
- */
+ String javaVersionString = System.getProperty("java.specification.version");
+ float javaVersion = (javaVersionString != null
+ ? Float.parseFloat(javaVersionString) : 1.5f);
+ if (javaVersion < 1.5) {
+ // Would like to do this but the JDK 1.3 & 1.4
+ // seems to drop back to 'REGULAR' instead of 'BOLD'
+ // if there is not a match.
+ return TextAttribute.WEIGHT_BOLD;
+ }
+ switch (weight) {
+ case 600:
+ return TextAttribute.WEIGHT_MEDIUM;
+ case 700:
+ return TextAttribute.WEIGHT_BOLD;
+ case 800:
+ return TextAttribute.WEIGHT_HEAVY;
+ case 900:
+ return TextAttribute.WEIGHT_ULTRABOLD;
+ default:
+ return TextAttribute.WEIGHT_REGULAR; //No matching CSS value (probably illegal)
+ }
}
}