aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaren Lease <klease@apache.org>2000-12-16 21:50:24 +0000
committerKaren Lease <klease@apache.org>2000-12-16 21:50:24 +0000
commitddd7116161ba1f121ae887615c7b3daaee45f7ed (patch)
treead5d4c9f4f0c08794ad1566ee91f9cc7470a1d55
parent569f46309e9d2df122515fe27cc2a67684a5d07c (diff)
downloadxmlgraphics-fop-ddd7116161ba1f121ae887615c7b3daaee45f7ed.tar.gz
xmlgraphics-fop-ddd7116161ba1f121ae887615c7b3daaee45f7ed.zip
Modify for new subproperty default setting code generated by properties.xsl
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@193877 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--src/org/apache/fop/datatypes/CondLength.java8
-rw-r--r--src/org/apache/fop/datatypes/LengthBase.java72
-rw-r--r--src/org/apache/fop/datatypes/LengthRange.java112
-rw-r--r--src/org/apache/fop/datatypes/Space.java22
4 files changed, 160 insertions, 54 deletions
diff --git a/src/org/apache/fop/datatypes/CondLength.java b/src/org/apache/fop/datatypes/CondLength.java
index 04a7bff60..019f43e51 100644
--- a/src/org/apache/fop/datatypes/CondLength.java
+++ b/src/org/apache/fop/datatypes/CondLength.java
@@ -61,15 +61,19 @@ public class CondLength extends Length {
private int conditionality=DISCARD ;
+ public CondLength () {
+ super(0);
+ }
+
public CondLength (Length l) {
super(l.mvalue());
}
- public void setLength(Length l) {
+ public void setLength(Length l, boolean bIsDefault) {
setValue(l.mvalue());
}
- public void setConditionality(String conditionality) {
+ public void setConditionality(String conditionality, boolean bIsDefault) {
if (conditionality.equals("retain"))
this.conditionality = Space.RETAIN;
else if (conditionality.equals("discard"))
diff --git a/src/org/apache/fop/datatypes/LengthBase.java b/src/org/apache/fop/datatypes/LengthBase.java
index 301b60542..b7a3601c4 100644
--- a/src/org/apache/fop/datatypes/LengthBase.java
+++ b/src/org/apache/fop/datatypes/LengthBase.java
@@ -50,9 +50,77 @@
*/
package org.apache.fop.datatypes;
-public abstract class LengthBase implements PercentBase {
+import org.apache.fop.fo.FObj;
+import org.apache.fop.fo.PropertyList;
+import org.apache.fop.messaging.MessageHandler;
+
+public class LengthBase implements PercentBase {
+ // Standard kinds of percent-based length
+ public static final int CUSTOM_BASE=0;
+ public static final int FONTSIZE=1;
+ public static final int INH_FONTSIZE=2;
+ public static final int CONTAINING_BOX=3;
+ public static final int CONTAINING_REFAREA=4;
+
+ /**
+ * FO parent of the FO for which this property is to be calculated.
+ */
+ protected final FObj parentFO;
+ /**
+ * PropertyList for the FO where this property is calculated.
+ */
+ private final PropertyList propertyList;
+ /** One of the defined types of LengthBase */
+ private final int iBaseType;
+
+ public LengthBase(FObj parentFO, PropertyList plist, int iBaseType) {
+ this.parentFO = parentFO;
+ this.propertyList = plist;
+ this.iBaseType = iBaseType;
+ }
+
+ /** Accessor for parentFO object from subclasses which define
+ * custom kinds of LengthBase calculations.
+ */
+ protected FObj getParentFO() {
+ return parentFO;
+ }
+
+ /** Accessor for propertyList object from subclasses which define
+ * custom kinds of LengthBase calculations.
+ */
+ protected PropertyList getPropertyList() {
+ return propertyList;
+ }
+
public int getDimension() { return 1; }
public double getBaseValue() { return 1.0; }
- abstract public int getBaseLength();
+
+ public int getBaseLength() {
+ switch(iBaseType) {
+ case FONTSIZE:
+ return propertyList.get("font-size").getLength().mvalue();
+ case INH_FONTSIZE:
+ return propertyList.getInherited("font-size").getLength().mvalue();
+ case CONTAINING_BOX:
+ // depends on property?? inline-progression vs block-progression
+ return parentFO.getContentWidth();
+ case CONTAINING_REFAREA: // example: start-indent, end-indent
+ {
+ FObj fo;
+ for (fo = parentFO;
+ fo != null && !fo.generatesReferenceAreas();
+ fo = fo.getParent())
+ ;
+ return (fo != null? fo.getContentWidth():0);
+ }
+ case CUSTOM_BASE:
+ MessageHandler.errorln("!!! LengthBase.getBaseLength() called on CUSTOM_BASE type !!!");
+ return 0;
+ default:
+ MessageHandler.errorln("Unknown base type for LengthBase.");
+ return 0;
+ }
+ }
}
diff --git a/src/org/apache/fop/datatypes/LengthRange.java b/src/org/apache/fop/datatypes/LengthRange.java
index b47d74ba0..093414264 100644
--- a/src/org/apache/fop/datatypes/LengthRange.java
+++ b/src/org/apache/fop/datatypes/LengthRange.java
@@ -50,6 +50,8 @@
*/
package org.apache.fop.datatypes;
+import org.apache.fop.messaging.MessageHandler;
+
/**
* a "progression-dimension" quantity
* ex. block-progression-dimension, inline-progression-dimension
@@ -64,63 +66,105 @@ public class LengthRange {
private static final int OPTSET=2;
private static final int MAXSET=4;
private int bfSet = 0; // bit field
+ private boolean bChecked = false;
- /**
- * set the space values, and make sure that min <= opt <= max
- */
- public LengthRange (Length l) {
- this.minimum = l;
- this.optimum = l;
- this.maximum = l;
- }
- /** Set minimum value to min if it is <= optimum or optimum isn't set
+ /**
+ * Set minimum value to min.
+ * @param min A Length value specifying the minimum value for this
+ * LengthRange.
+ * @param bIsDefault If true, this is set as a "default" value
+ * and not a user-specified explicit value.
*/
- public void setMinimum(Length min) {
- if ((bfSet&OPTSET)==0) {
- if ((bfSet&MAXSET)!=0 && (min.mvalue() > maximum.mvalue()))
- min = maximum;
- }
- else if (min.mvalue() > optimum.mvalue())
- min = optimum;
+ public void setMinimum(Length min, boolean bIsDefault) {
minimum = min;
- bfSet |= MINSET;
+ if (!bIsDefault) bfSet |= MINSET;
}
- /** Set maximum value to max if it is >= optimum or optimum isn't set
+ /**
+ * Set maximum value to max if it is >= optimum or optimum isn't set.
+ * @param max A Length value specifying the maximum value for this
+ * @param bIsDefault If true, this is set as a "default" value
+ * and not a user-specified explicit value.
*/
- public void setMaximum(Length max) {
- if ((bfSet&OPTSET)==0) {
- if ((bfSet&MINSET) != 0 && (max.mvalue() < minimum.mvalue()))
- max = minimum;
- }
- else if (max.mvalue() < optimum.mvalue())
- max = optimum;
+ public void setMaximum(Length max, boolean bIsDefault) {
maximum = max;
- bfSet |= MAXSET;
+ if (!bIsDefault) bfSet |= MAXSET;
}
/**
* Set the optimum value.
+ * @param opt A Length value specifying the optimum value for this
+ * @param bIsDefault If true, this is set as a "default" value
+ * and not a user-specified explicit value.
*/
- public void setOptimum(Length opt) {
- if (((bfSet&MINSET)==0 || opt.mvalue() >= minimum.mvalue()) &&
- ((bfSet&MAXSET)==0 || opt.mvalue() <= maximum.mvalue())) {
- optimum = opt;
- bfSet |= OPTSET;
+ public void setOptimum(Length opt, boolean bIsDefault) {
+ optimum = opt;
+ if (!bIsDefault) bfSet |= OPTSET;
+ }
+
+ // Minimum is prioritaire, if explicit
+ private void checkConsistency() {
+ if (bChecked) return;
+ // Make sure max >= min
+ if (minimum.mvalue() > maximum.mvalue()) {
+ if ((bfSet&MINSET)!=0) {
+ // if minimum is explicit, force max to min
+ if ((bfSet&MAXSET)!=0) {
+ // Warning: min>max, resetting max to min
+ MessageHandler.errorln("WARNING: forcing max to min in LengthRange");
+ }
+ maximum = minimum ;
+ }
+ else {
+ minimum = maximum; // minimum was default value
+ }
+ }
+ // Now make sure opt <= max and opt >= min
+ if (optimum.mvalue() > maximum.mvalue()) {
+ if ((bfSet&OPTSET)!=0) {
+ if ((bfSet&MAXSET)!=0) {
+ // Warning: opt > max, resetting opt to max
+ MessageHandler.errorln("WARNING: forcing opt to max in LengthRange");
+ optimum = maximum ;
+ }
+ else {
+ maximum = optimum; // maximum was default value
+ }
+ }
+ else {
+ // opt is default and max is explicit or default
+ optimum = maximum ;
+ }
+ }
+ else if (optimum.mvalue() < minimum.mvalue()) {
+ if ((bfSet&MINSET)!=0) {
+ // if minimum is explicit, force opt to min
+ if ((bfSet&OPTSET)!=0) {
+ MessageHandler.errorln("WARNING: forcing opt to min in LengthRange");
}
+ optimum = minimum ;
+ }
+ else {
+ minimum = optimum; // minimum was default value
+ }
}
+ bChecked = true;
+ }
public Length getMinimum() {
- return this.minimum;
+ checkConsistency();
+ return this.minimum;
}
public Length getMaximum() {
- return this.maximum;
+ checkConsistency();
+ return this.maximum;
}
public Length getOptimum() {
- return this.optimum;
+ checkConsistency();
+ return this.optimum;
}
}
diff --git a/src/org/apache/fop/datatypes/Space.java b/src/org/apache/fop/datatypes/Space.java
index 71481af79..378172f9d 100644
--- a/src/org/apache/fop/datatypes/Space.java
+++ b/src/org/apache/fop/datatypes/Space.java
@@ -60,23 +60,14 @@ public class Space extends LengthRange {
public static final int RETAIN = 1;
//private Precedence precedence;
- private int precedence=0;
+ private Number precedence;
private int conditionality=DISCARD ;
-
- /**
- * set the space values, and make sure that min <= opt <= max
- */
- public Space (Length l) {
- super(l);
- }
-
-
- // public void setPrecedence(Precedence precedence) {
- public void setPrecedence(Number precedence) {
- this.precedence = precedence.intValue();
+
+ public void setPrecedence(Number precedence, boolean bIsDefault) {
+ this.precedence = precedence;
}
- public void setConditionality(String conditionality) {
+ public void setConditionality(String conditionality, boolean bIsDefault) {
if (conditionality.equals("retain"))
this.conditionality = Space.RETAIN;
else if (conditionality.equals("discard"))
@@ -84,8 +75,7 @@ public class Space extends LengthRange {
// else unrecognized value
}
- // public Precedence getPrecedence() {
- public int getPrecedence() {
+ public Number getPrecedence() {
return this.precedence ;
}