pbwest 02/05/07 08:58:53 Modified: src/org/apache/fop/datatypes Tag: FOP_0-20-0_Alt-Design Length.java Keep.java Log: Updated to experimental code. Revision Changes Path No revision No revision 1.12.2.1 +119 -117 xml-fop/src/org/apache/fop/datatypes/Length.java Index: Length.java =================================================================== RCS file: /home/cvs/xml-fop/src/org/apache/fop/datatypes/Length.java,v retrieving revision 1.12 retrieving revision 1.12.2.1 diff -u -r1.12 -r1.12.2.1 --- Length.java 9 Aug 2001 13:51:55 -0000 1.12 +++ Length.java 7 May 2002 15:58:53 -0000 1.12.2.1 @@ -1,131 +1,133 @@ + +package org.apache.fop.datatypes; + +import org.apache.fop.fo.expr.PropertyException; + /* - * $Id: Length.java,v 1.12 2001/08/09 13:51:55 keiron Exp $ + * Length.java + * $Id: Length.java,v 1.12.2.1 2002/05/07 15:58:53 pbwest Exp $ + * 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 <a href="mailto:[EMAIL PROTECTED]">Peter B. West</a> + * @version $Revision: 1.12.2.1 $ $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 <tt>Numeric</tt>. */ -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; - /** - * Set the length given a number of relative units and the current - * font size in base units. - */ - public Length(double numRelUnits, int iCurFontSize) { - millipoints = (int)(numRelUnits * (double)iCurFontSize); - setIsComputed(true); - } - - /** - * Set the length given a number of units and a unit name. - */ - public Length(double numUnits, String units) { - convert(numUnits, units); - } - - /** - * set the length as a number of base units - */ - public Length(int baseUnits) { - millipoints = baseUnits; - setIsComputed(true); - } +public class Length { - /** - * Convert the given length to a dimensionless integer representing - * a whole number of base units (milli-points). + /* + * Constants for LengthUnitNames */ - 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 - + "'"); + 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 + ; + + /** + * 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 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 + }; + + /** + * Private constructor - don't instantiate a <i>Length</i> object. + */ + private Length() {} + + /** + * Construct a <tt>Numeric</tt> 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 <tt>Numeric</tt> representing this <i>Length</i>. + */ + public static Numeric makeLength(int property, double value, int unit) + throws PropertyException + { + return new Numeric(property, value * milliPtsPerUnit[unit], + Numeric.MILLIPOINTS, 1, unit); + } + + /** + * Construct a <tt>Numeric</tt> 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 <tt>Numeric</tt> representing this <i>Length</i>. + */ + public static Numeric makeLength + (String propertyName, double value, int unit) + throws PropertyException + { + return new Numeric(propertyName, value * milliPtsPerUnit[unit], + Numeric.MILLIPOINTS, 1, unit); + } + + /** + * @param unit an <tt>int</tt> encoding a <i>Length</i> unit. + * @return the <tt>String</tt> name of the unit. + */ + 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 ""; } - this.millipoints = (int)(dvalue * 1000); - setIsComputed(true); - } - - protected void setIsComputed(boolean bIsComputed) { - this.bIsComputed = bIsComputed; - } - - /** - * return the length in 1/1000ths of a point - */ - 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; - } - - /** - * 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). - * <p>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. - */ - public double getTableUnits() { - return 0.0; - } - - public String toString() { - String s = millipoints + "mpt"; - return s; } } 1.3.4.1 +7 -67 xml-fop/src/org/apache/fop/datatypes/Keep.java Index: Keep.java =================================================================== RCS file: /home/cvs/xml-fop/src/org/apache/fop/datatypes/Keep.java,v retrieving revision 1.3 retrieving revision 1.3.4.1 diff -u -r1.3 -r1.3.4.1 --- Keep.java 30 Jul 2001 20:29:19 -0000 1.3 +++ Keep.java 7 May 2002 15:58:53 -0000 1.3.4.1 @@ -1,77 +1,17 @@ +package org.apache.fop.datatypes; + +import org.apache.fop.datatypes.Compound; + /* - * $Id: Keep.java,v 1.3 2001/07/30 20:29:19 tore Exp $ + * $Id: Keep.java,v 1.3.4.1 2002/05/07 15:58:53 pbwest Exp $ * 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 { }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]