diff options
author | Simon Pepping <spepping@apache.org> | 2008-04-18 19:07:57 +0000 |
---|---|---|
committer | Simon Pepping <spepping@apache.org> | 2008-04-18 19:07:57 +0000 |
commit | a0a75029b98d18c23601745bad7669fb60503fe8 (patch) | |
tree | fca65849f4bf3d2ed2c2b0de5b59d2abf86075dc | |
parent | fa13f5c3f1434e4d0413ed418236b355018679ed (diff) | |
download | xmlgraphics-fop-a0a75029b98d18c23601745bad7669fb60503fe8.tar.gz xmlgraphics-fop-a0a75029b98d18c23601745bad7669fb60503fe8.zip |
An implementation of a positive integer property maker. It implements
convertProperty, which is the correct method to implement if one wants
to add to the make process. This fixes bug 44619.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@649657 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | src/java/org/apache/fop/fo/FOPropertyMapping.java | 14 | ||||
-rw-r--r-- | src/java/org/apache/fop/fo/flow/table/TableFObj.java | 20 | ||||
-rw-r--r-- | src/java/org/apache/fop/fo/properties/NumberProperty.java | 34 |
3 files changed, 42 insertions, 26 deletions
diff --git a/src/java/org/apache/fop/fo/FOPropertyMapping.java b/src/java/org/apache/fop/fo/FOPropertyMapping.java index 539648f5a..db19d6515 100644 --- a/src/java/org/apache/fop/fo/FOPropertyMapping.java +++ b/src/java/org/apache/fop/fo/FOPropertyMapping.java @@ -1095,13 +1095,13 @@ public final class FOPropertyMapping implements Constants { addPropertyMaker("hyphenation-character", m); // hyphenation-push-character-count - m = new NumberProperty.Maker(PR_HYPHENATION_PUSH_CHARACTER_COUNT); + m = new NumberProperty.PositiveIntegerMaker(PR_HYPHENATION_PUSH_CHARACTER_COUNT); m.setInherited(true); m.setDefault("2"); addPropertyMaker("hyphenation-push-character-count", m); // hyphenation-remain-character-count - m = new NumberProperty.Maker(PR_HYPHENATION_REMAIN_CHARACTER_COUNT); + m = new NumberProperty.PositiveIntegerMaker(PR_HYPHENATION_REMAIN_CHARACTER_COUNT); m.setInherited(true); m.setDefault("2"); addPropertyMaker("hyphenation-remain-character-count", m); @@ -2137,7 +2137,7 @@ public final class FOPropertyMapping implements Constants { addPropertyMaker("blank-or-not-blank", m); // column-count - m = new NumberProperty.Maker(PR_COLUMN_COUNT); + m = new NumberProperty.PositiveIntegerMaker(PR_COLUMN_COUNT); m.setInherited(false); m.setDefault("1"); addPropertyMaker("column-count", m); @@ -2175,7 +2175,7 @@ public final class FOPropertyMapping implements Constants { addPropertyMaker("force-page-count", m); // initial-page-number - m = new NumberProperty.Maker(PR_INITIAL_PAGE_NUMBER); + m = new NumberProperty.PositiveIntegerMaker(PR_INITIAL_PAGE_NUMBER); m.setInherited(false); m.addEnum("auto", getEnumProperty(EN_AUTO, "AUTO")); m.addEnum("auto-odd", getEnumProperty(EN_AUTO_ODD, "AUTO_ODD")); @@ -2359,19 +2359,19 @@ public final class FOPropertyMapping implements Constants { addPropertyMaker("ends-row", m); // number-columns-repeated - m = new NumberProperty.Maker(PR_NUMBER_COLUMNS_REPEATED); + m = new NumberProperty.PositiveIntegerMaker(PR_NUMBER_COLUMNS_REPEATED); m.setInherited(false); m.setDefault("1"); addPropertyMaker("number-columns-repeated", m); // number-columns-spanned - m = new NumberProperty.Maker(PR_NUMBER_COLUMNS_SPANNED); + m = new NumberProperty.PositiveIntegerMaker(PR_NUMBER_COLUMNS_SPANNED); m.setInherited(false); m.setDefault("1"); addPropertyMaker("number-columns-spanned", m); // number-rows-spanned - m = new NumberProperty.Maker(PR_NUMBER_ROWS_SPANNED); + m = new NumberProperty.PositiveIntegerMaker(PR_NUMBER_ROWS_SPANNED); m.setInherited(false); m.setDefault("1"); addPropertyMaker("number-rows-spanned", m); diff --git a/src/java/org/apache/fop/fo/flow/table/TableFObj.java b/src/java/org/apache/fop/fo/flow/table/TableFObj.java index 24528f622..9b60de740 100644 --- a/src/java/org/apache/fop/fo/flow/table/TableFObj.java +++ b/src/java/org/apache/fop/fo/flow/table/TableFObj.java @@ -117,7 +117,7 @@ public abstract class TableFObj extends FObj { * PropertyMaker subclass for the column-number property * */ - public static class ColumnNumberPropertyMaker extends NumberProperty.Maker { + public static class ColumnNumberPropertyMaker extends NumberProperty.PositiveIntegerMaker { /** * Constructor @@ -153,24 +153,6 @@ public abstract class TableFObj extends FObj { = (ColumnNumberManagerHolder) propertyList.getParentFObj(); ColumnNumberManager columnIndexManager = parent.getColumnNumberManager(); int columnIndex = p.getNumeric().getValue(); - if (columnIndex <= 0) { - /* No warning necessary as the spec clearly defines how to handle these cases. - log.warn("Specified negative or zero value for " - + "column-number on " + fo.getName() + ": " - + columnIndex + " forced to " - + columnIndexManager.getCurrentColumnNumber());*/ - return NumberProperty.getInstance(columnIndexManager.getCurrentColumnNumber()); - } else { - double tmpIndex = p.getNumeric().getNumericValue(); - if (tmpIndex - columnIndex > 0.0) { - columnIndex = (int) Math.round(tmpIndex); - /* No warning necessary as the spec clearly defines how to handle these cases. - log.warn("Rounding specified column-number of " - + tmpIndex + " to " + columnIndex);*/ - p = NumberProperty.getInstance(columnIndex); - } - } - int colSpan = propertyList.get(Constants.PR_NUMBER_COLUMNS_SPANNED) .getNumeric().getValue(); int i = -1; diff --git a/src/java/org/apache/fop/fo/properties/NumberProperty.java b/src/java/org/apache/fop/fo/properties/NumberProperty.java index 6f8d8a1d2..58400d76e 100644 --- a/src/java/org/apache/fop/fo/properties/NumberProperty.java +++ b/src/java/org/apache/fop/fo/properties/NumberProperty.java @@ -68,6 +68,40 @@ public final class NumberProperty extends Property implements Numeric { } + public static class PositiveIntegerMaker extends PropertyMaker { + + /** + * Constructor for NumberProperty.PositiveIntegerMaker + * @param propId the id of the property for which a PositiveIntegerMaker should be created + */ + public PositiveIntegerMaker(int propId) { + super(propId); + } + + /** + * If the value is not positive, return a property with value 1 + * + * {@inheritDoc} + */ + public Property convertProperty(Property p, + PropertyList propertyList, FObj fo) + throws PropertyException { + if (p instanceof EnumProperty) { + return EnumNumber.getInstance(p); + } + Number val = p.getNumber(); + if (val != null) { + int i = val.intValue(); + if (i <= 0) { + i = 1; + } + return getInstance(i); + } + return convertPropertyDatatype(p, propertyList, fo); + } + + } + /** cache holding all canonical NumberProperty instances */ private static final PropertyCache cache = new PropertyCache(); |