git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@193877 13f79535-47bb-0310-9956-ffa450edef68pull/32/head
@@ -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")) |
@@ -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; | |||
} | |||
} | |||
} | |||
@@ -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; | |||
} | |||
} |
@@ -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 ; | |||
} | |||