aboutsummaryrefslogtreecommitdiffstats
path: root/src/java
diff options
context:
space:
mode:
authorFinn Bock <bckfnn@apache.org>2005-09-12 08:05:59 +0000
committerFinn Bock <bckfnn@apache.org>2005-09-12 08:05:59 +0000
commita1c7c4a1a07a266b9be7bf0feb9e33c79bc56d0e (patch)
tree0eee65f724ef9ac4e8de336419c1ba8dc6fc4655 /src/java
parent2ed5293a408b38cb2ed1dcbd2ecdcd7fe99c4943 (diff)
downloadxmlgraphics-fop-a1c7c4a1a07a266b9be7bf0feb9e33c79bc56d0e.tar.gz
xmlgraphics-fop-a1c7c4a1a07a266b9be7bf0feb9e33c79bc56d0e.zip
Bugzilla #36068:
Validation added for font-style and font-weight by making both properties enums. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@280286 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java')
-rw-r--r--src/java/org/apache/fop/fo/Constants.java30
-rw-r--r--src/java/org/apache/fop/fo/FOPropertyMapping.java20
-rwxr-xr-xsrc/java/org/apache/fop/fo/properties/CommonFont.java47
-rw-r--r--src/java/org/apache/fop/render/rtf/TextAttributesConverter.java4
4 files changed, 79 insertions, 22 deletions
diff --git a/src/java/org/apache/fop/fo/Constants.java b/src/java/org/apache/fop/fo/Constants.java
index a7674100f..68f1c3f02 100644
--- a/src/java/org/apache/fop/fo/Constants.java
+++ b/src/java/org/apache/fop/fo/Constants.java
@@ -1070,6 +1070,34 @@ public interface Constants {
int EN_X_FILL = 162;
/** Enumeration constant - non-standard for display-align */
int EN_X_DISTRIBUTE = 163;
+ /** Enumeration constant */
+ int EN_ITALIC = 164;
+ /** Enumeration constant */
+ int EN_OBLIQUE = 165;
+ /** Enumeration constant */
+ int EN_BACKSLANT = 166;
+ /** Enumeration constant */
+ int EN_BOLDER = 167;
+ /** Enumeration constant */
+ int EN_LIGHTER = 168;
+ /** Enumeration constant */
+ int EN_100 = 168;
+ /** Enumeration constant */
+ int EN_200 = 169;
+ /** Enumeration constant */
+ int EN_300 = 170;
+ /** Enumeration constant */
+ int EN_400 = 171;
+ /** Enumeration constant */
+ int EN_500 = 172;
+ /** Enumeration constant */
+ int EN_600 = 173;
+ /** Enumeration constant */
+ int EN_700 = 174;
+ /** Enumeration constant */
+ int EN_800 = 175;
+ /** Enumeration constant */
+ int EN_900 = 176;
/** Number of enumeration constants defined */
- int ENUM_COUNT = 163;
+ int ENUM_COUNT = 176;
}
diff --git a/src/java/org/apache/fop/fo/FOPropertyMapping.java b/src/java/org/apache/fop/fo/FOPropertyMapping.java
index de2f5a55b..7490cb941 100644
--- a/src/java/org/apache/fop/fo/FOPropertyMapping.java
+++ b/src/java/org/apache/fop/fo/FOPropertyMapping.java
@@ -1124,8 +1124,13 @@ public class FOPropertyMapping implements Constants {
addPropertyMaker("font-size-adjust", m);
// font-style
- m = new StringProperty.Maker(PR_FONT_STYLE);
+ m = new EnumProperty.Maker(PR_FONT_STYLE);
m.setInherited(true);
+ m.addEnum("normal", getEnumProperty(EN_NORMAL, "NORMAL"));
+ m.addEnum("italic", getEnumProperty(EN_ITALIC, "ITALIC"));
+ m.addEnum("oblique", getEnumProperty(EN_OBLIQUE, "OBLIQUE"));
+ m.addEnum("backslant", getEnumProperty(EN_BACKSLANT, "BACKSLANT"));
+
m.setDefault("normal");
addPropertyMaker("font-style", m);
@@ -1138,10 +1143,21 @@ public class FOPropertyMapping implements Constants {
addPropertyMaker("font-variant", m);
// font-weight
- m = new StringProperty.Maker(PR_FONT_WEIGHT);
+ m = new EnumProperty.Maker(PR_FONT_WEIGHT);
m.setInherited(true);
m.addKeyword("normal", "400");
m.addKeyword("bold", "700");
+ m.addEnum("bolder",getEnumProperty(EN_BOLDER, "BOLDER"));
+ m.addEnum("lighter",getEnumProperty(EN_LIGHTER, "LIGHTER"));
+ m.addEnum("100",getEnumProperty(EN_100, "100"));
+ m.addEnum("200",getEnumProperty(EN_200, "200"));
+ m.addEnum("300",getEnumProperty(EN_300, "300"));
+ m.addEnum("400",getEnumProperty(EN_400, "400"));
+ m.addEnum("500",getEnumProperty(EN_500, "500"));
+ m.addEnum("600",getEnumProperty(EN_600, "600"));
+ m.addEnum("700",getEnumProperty(EN_700, "700"));
+ m.addEnum("800",getEnumProperty(EN_800, "800"));
+ m.addEnum("900",getEnumProperty(EN_900, "900"));
m.setDefault("400");
addPropertyMaker("font-weight", m);
}
diff --git a/src/java/org/apache/fop/fo/properties/CommonFont.java b/src/java/org/apache/fop/fo/properties/CommonFont.java
index c24c0c941..fb1c53236 100755
--- a/src/java/org/apache/fop/fo/properties/CommonFont.java
+++ b/src/java/org/apache/fop/fo/properties/CommonFont.java
@@ -62,7 +62,7 @@ public class CommonFont {
/**
* The "font-style" property.
*/
- public String fontStyle;
+ public int fontStyle;
/**
* The "font-variant" property.
@@ -72,7 +72,7 @@ public class CommonFont {
/**
* The "font-weight" property.
*/
- public String fontWeight;
+ public int fontWeight;
private Font fontState;
@@ -86,9 +86,9 @@ public class CommonFont {
fontSize = pList.get(Constants.PR_FONT_SIZE).getLength();
fontStretch = pList.get(Constants.PR_FONT_STRETCH).getEnum();
fontSizeAdjust = pList.get(Constants.PR_FONT_SIZE_ADJUST).getNumeric();
- fontStyle = pList.get(Constants.PR_FONT_STYLE).getString();
+ fontStyle = pList.get(Constants.PR_FONT_STYLE).getEnum();
fontVariant = pList.get(Constants.PR_FONT_VARIANT).getEnum();
- fontWeight = pList.get(Constants.PR_FONT_WEIGHT).getString();
+ fontWeight = pList.get(Constants.PR_FONT_WEIGHT).getEnum();
}
/**
@@ -102,27 +102,40 @@ public class CommonFont {
/**@todo this is ugly. need to improve. */
int font_weight = 400;
- if (fontWeight.equals("bolder")) {
+ if (fontWeight == Constants.EN_BOLDER) {
// +100 from inherited
- } else if (fontWeight.equals("lighter")) {
+ } else if (fontWeight == Constants.EN_LIGHTER) {
// -100 from inherited
} else {
- try {
- font_weight = Integer.parseInt(fontWeight);
- } catch (NumberFormatException nfe) {
- } /** TODO: log that exception */
- }
- font_weight = ((int) font_weight / 100) * 100;
- if (font_weight < 100) {
- font_weight = 100;
- } else if (font_weight > 900) {
- font_weight = 900;
+ switch (fontWeight) {
+ case Constants.EN_100: font_weight = 100; break;
+ case Constants.EN_200: font_weight = 200; break;
+ case Constants.EN_300: font_weight = 300; break;
+ case Constants.EN_400: font_weight = 400; break;
+ case Constants.EN_500: font_weight = 500; break;
+ case Constants.EN_600: font_weight = 600; break;
+ case Constants.EN_700: font_weight = 700; break;
+ case Constants.EN_800: font_weight = 800; break;
+ case Constants.EN_900: font_weight = 900; break;
+ }
}
+ String style = "normal";
+ switch (fontStyle) {
+ case Constants.EN_ITALIC:
+ style = "italic";
+ break;
+ case Constants.EN_OBLIQUE:
+ style = "oblique";
+ break;
+ case Constants.EN_BACKSLANT:
+ style = "backslant";
+ break;
+ }
// NOTE: this is incomplete. font-size may be specified with
// various kinds of keywords too
//int fontVariant = propertyList.get("font-variant").getEnum();
- String fname = fontInfo.fontLookup(fontFamily, fontStyle,
+ String fname = fontInfo.fontLookup(fontFamily, style,
font_weight);
FontMetrics metrics = fontInfo.getMetricsFor(fname);
fontState = new Font(fname, metrics, fontSize.getValue(context));
diff --git a/src/java/org/apache/fop/render/rtf/TextAttributesConverter.java b/src/java/org/apache/fop/render/rtf/TextAttributesConverter.java
index a8eb96274..99bc5eede 100644
--- a/src/java/org/apache/fop/render/rtf/TextAttributesConverter.java
+++ b/src/java/org/apache/fop/render/rtf/TextAttributesConverter.java
@@ -135,13 +135,13 @@ class TextAttributesConverter {
RtfFontManager.getInstance().getFontNumber(font.fontFamily));
rtfAttr.setHalfPoints(RtfText.ATTR_FONT_SIZE, font.fontSize);
- if (font.fontWeight.equals("bold") || font.fontWeight.equals("700")) {
+ if (font.fontWeight == Constants.EN_700) {
rtfAttr.set("b", 1);
} else {
rtfAttr.set("b", 0);
}
- if (font.fontStyle.equals("italic")) {
+ if (font.fontStyle == Constants.EN_ITALIC) {
rtfAttr.set(RtfText.ATTR_ITALIC, 1);
} else {
rtfAttr.set(RtfText.ATTR_ITALIC, 0);