From: Peter Bernard West Date: Tue, 7 May 2002 15:58:53 +0000 (+0000) Subject: Updated to experimental code. X-Git-Tag: FOP_Alt-Design_Migration~17 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=96385e6f8134ae3c78c8a25a32c118d3392998f2;p=xmlgraphics-fop.git Updated to experimental code. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/FOP_0-20-0_Alt-Design@194793 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/org/apache/fop/datatypes/Keep.java b/src/org/apache/fop/datatypes/Keep.java index 8d16c25b9..253f632ce 100644 --- a/src/org/apache/fop/datatypes/Keep.java +++ b/src/org/apache/fop/datatypes/Keep.java @@ -1,77 +1,17 @@ +package org.apache.fop.datatypes; + +import org.apache.fop.datatypes.Compound; + /* * $Id$ * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. */ - -package org.apache.fop.datatypes; - -import org.apache.fop.fo.Property; - /** - * XSL FO Keep Property datatype (keep-together, etc) + * Interface for <keep> compound properties */ -public class Keep implements CompoundDatatype { - private Property withinLine; - private Property withinColumn; - private Property withinPage; - - public Keep() {} - - // From CompoundDatatype - public void setComponent(String sCmpnName, Property cmpnValue, - boolean bIsDefault) { - if (sCmpnName.equals("within-line")) - setWithinLine(cmpnValue, bIsDefault); - else if (sCmpnName.equals("within-column")) - setWithinColumn(cmpnValue, bIsDefault); - else if (sCmpnName.equals("within-page")) - setWithinPage(cmpnValue, bIsDefault); - } - - // From CompoundDatatype - public Property getComponent(String sCmpnName) { - if (sCmpnName.equals("within-line")) - return getWithinLine(); - else if (sCmpnName.equals("within-column")) - return getWithinColumn(); - else if (sCmpnName.equals("within-page")) - return getWithinPage(); - else - return null; - } - - public void setWithinLine(Property withinLine, boolean bIsDefault) { - this.withinLine = withinLine; - } - - protected void setWithinColumn(Property withinColumn, - boolean bIsDefault) { - this.withinColumn = withinColumn; - } - - public void setWithinPage(Property withinPage, boolean bIsDefault) { - this.withinPage = withinPage; - } - - public Property getWithinLine() { - return this.withinLine; - } - - public Property getWithinColumn() { - return this.withinColumn; - } - - public Property getWithinPage() { - return this.withinPage; - } - /** - * What to do here?? There isn't really a meaningful single value. - */ - public String toString() { - return "Keep"; - } +public interface Keep extends Compound { } diff --git a/src/org/apache/fop/datatypes/Length.java b/src/org/apache/fop/datatypes/Length.java index 0dad1fd77..55c34b0c4 100644 --- a/src/org/apache/fop/datatypes/Length.java +++ b/src/org/apache/fop/datatypes/Length.java @@ -1,131 +1,133 @@ + +package org.apache.fop.datatypes; + +import org.apache.fop.fo.expr.PropertyException; + /* + * Length.java * $Id$ + * Created: Wed Nov 21 15:39:30 2001 * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. + * @author Peter B. West + * @version $Revision$ $Name$ */ - -package org.apache.fop.datatypes; - -import org.apache.fop.fo.Property; -import org.apache.fop.messaging.MessageHandler; - /** - * a length quantity in XSL + * A constructor class for Length datatype. Constructs a Numeric. */ -public class Length { - public static final Length AUTO = new Length(0); - - static { - AUTO.bAuto = true; - } - protected int millipoints = 0; - protected boolean bIsComputed = false; - private boolean bAuto = false; +public class Length { - /** - * Set the length given a number of relative units and the current - * font size in base units. + /* + * Constants for LengthUnitNames */ - public Length(double numRelUnits, int iCurFontSize) { - millipoints = (int)(numRelUnits * (double)iCurFontSize); - setIsComputed(true); - } + public static final int + NOUNIT = 0 + ,CM = 1 + ,MM = 2 + ,IN = 3 + ,PT = 4 + ,PC = 5 + ,PX = 6 + ,MPT = 7 // Millipoints + ; + + /* + * Constants for conversions into millipoints + */ + public static final double + PTSPERINCH = 72.0 + ,PTSPERPICA = 12.0 + ,CMSPERINCH = 2.54 + ,MMSPERINCH = 25.4 + ,PTSPERCM = PTSPERINCH / CMSPERINCH + ,PTSPERMM = PTSPERINCH / MMSPERINCH + ,PXSPERINCH = 92.0 + ,PTSPERPX = PTSPERINCH / PXSPERINCH + ,PXSPERPT = PXSPERINCH / PTSPERINCH + ,PXSPERPICA = PTSPERPICA * PXSPERPT + ,PXSPERCM = PXSPERINCH / CMSPERINCH + ,PXSPERMM = PXSPERINCH / MMSPERINCH + ; /** - * Set the length given a number of units and a unit name. + * Array of constant conversion factors from unit to millipoints, + * indexed by integer unit constant. Keep this array in sync with + * the integer constants or bear the consequences. */ - public Length(double numUnits, String units) { - convert(numUnits, units); - } + public static final double[] milliPtsPerUnit = { + 0.0 + ,PTSPERCM * 1000.0 + ,PTSPERMM * 1000.0 + ,PTSPERINCH * 1000.0 + ,1000.0 + ,PTSPERPICA * 1000.0 + ,PTSPERPX * 1000.0 + ,1.0 + }; /** - * set the length as a number of base units + * Private constructor - don't instantiate a Length object. */ - public Length(int baseUnits) { - millipoints = baseUnits; - setIsComputed(true); - } + private Length() {} /** - * Convert the given length to a dimensionless integer representing - * a whole number of base units (milli-points). + * Construct a Numeric with a given unit and quantity. + * The unit power is assumed as 1. The base unit is millipoints. + * @param property the index of the property with which this value + * is associated. + * @param value the number of units. + * @param unit an integer constant representing the unit + * @return a Numeric representing this Length. */ - protected void convert(double dvalue, String unit) { - - int assumed_resolution = 1; // points/pixel - - if (unit.equals("in")) - dvalue = dvalue * 72; - else if (unit.equals("cm")) - dvalue = dvalue * 28.3464567; - else if (unit.equals("mm")) - dvalue = dvalue * 2.83464567; - else if (unit.equals("pt")) - dvalue = dvalue; - else if (unit.equals("pc")) - dvalue = dvalue * 12; - /* - * else if (unit.equals("em")) - * dvalue = dvalue * fontsize; - */ - else if (unit.equals("px")) - dvalue = dvalue * assumed_resolution; - else { - dvalue = 0; - MessageHandler.errorln("ERROR: unknown length unit '" + unit - + "'"); - } - this.millipoints = (int)(dvalue * 1000); - setIsComputed(true); - } - - protected void setIsComputed(boolean bIsComputed) { - this.bIsComputed = bIsComputed; + public static Numeric makeLength(int property, double value, int unit) + throws PropertyException + { + return new Numeric(property, value * milliPtsPerUnit[unit], + Numeric.MILLIPOINTS, 1, unit); } /** - * return the length in 1/1000ths of a point + * Construct a Numeric with a given unit and quantity. + * The unit power is assumed as 1. The base unit is millipoints. + * @param propertyName the name of the property with which this value + * is associated. + * @param value the number of units. + * @param unit an integer constant representing the unit. + * @return a Numeric representing this Length. */ - public int mvalue() { - if (!bIsComputed) - millipoints = computeValue(); - return millipoints; - } - - protected int computeValue() { - return millipoints; - } - - protected void setValue(int millipoints) { - this.millipoints = millipoints; - setIsComputed(true); - } - - public boolean isAuto() { - return bAuto; + public static Numeric makeLength + (String propertyName, double value, int unit) + throws PropertyException + { + return new Numeric(propertyName, value * milliPtsPerUnit[unit], + Numeric.MILLIPOINTS, 1, unit); } /** - * Return the number of table units which are included in this - * length specification. - * This will always be 0 unless the property specification used - * the proportional-column-width() function (only only table - * column FOs). - *

If this value is not 0, the actual value of the Length cannot - * be known without looking at all of the columns in the table to - * determine the value of a "table-unit". - * @return The number of table units which are included in this - * length specification. + * @param unit an int encoding a Length unit. + * @return the String name of the unit. */ - public double getTableUnits() { - return 0.0; - } - - public String toString() { - String s = millipoints + "mpt"; - return s; + public static String getUnitName(int unit) { + switch (unit) { + case CM: + return "cm"; + case MM: + return "mm"; + case IN: + return "in"; + case PT: + return "pt"; + case PC: + return "pc"; + case PX: + return "px"; + case MPT: + return "millipt"; + default: + return ""; + } } }