diff options
author | Maximilian Berger <maxberger@apache.org> | 2008-02-14 11:57:05 +0000 |
---|---|---|
committer | Maximilian Berger <maxberger@apache.org> | 2008-02-14 11:57:05 +0000 |
commit | e397444e624314c9b1d4ea3bd9e2a958d129e9f4 (patch) | |
tree | 660a95515aed4b7cf97ed73410d0e80d17534fca /src | |
parent | 5aab37b2dece063adf9e7809e38fe3100862f8ca (diff) | |
download | xmlgraphics-fop-e397444e624314c9b1d4ea3bd9e2a958d129e9f4.tar.gz xmlgraphics-fop-e397444e624314c9b1d4ea3bd9e2a958d129e9f4.zip |
Created Constants for unit descriptions
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@627719 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
6 files changed, 45 insertions, 22 deletions
diff --git a/src/java/org/apache/fop/fo/expr/NumericProperty.java b/src/java/org/apache/fop/fo/expr/NumericProperty.java index 9c0b9e2ba..54fe1f2f7 100644 --- a/src/java/org/apache/fop/fo/expr/NumericProperty.java +++ b/src/java/org/apache/fop/fo/expr/NumericProperty.java @@ -25,6 +25,7 @@ import org.apache.fop.apps.FOUserAgent; import org.apache.fop.datatypes.Length; import org.apache.fop.datatypes.PercentBaseContext; import org.apache.fop.datatypes.Numeric; +import org.apache.fop.fo.properties.FixedLength; import org.apache.fop.fo.properties.Property; /** @@ -121,7 +122,7 @@ public class NumericProperty extends Property implements Numeric, Length { /** {@inheritDoc} */ public String toString() { if (dim == 1) { - return (int) value + "mpt"; + return (int) value + FixedLength.MPT; } else { return value + "^" + dim; } diff --git a/src/java/org/apache/fop/fo/properties/FixedLength.java b/src/java/org/apache/fop/fo/properties/FixedLength.java index 7c4344b53..6debdd145 100644 --- a/src/java/org/apache/fop/fo/properties/FixedLength.java +++ b/src/java/org/apache/fop/fo/properties/FixedLength.java @@ -26,11 +26,29 @@ import org.apache.fop.datatypes.PercentBaseContext; */ public final class FixedLength extends LengthProperty { + /** Describes the unit pica. */ + public static final String PICA = "pc"; + + /** Describes the unit point. */ + public static final String POINT = "pt"; + + /** Describes the unit millimeter. */ + public static final String MM = "mm"; + + /** Describes the unit centimeter. */ + public static final String CM = "cm"; + + /** Describes the unit inch. */ + public static final String INCH = "in"; + + /** Describes the unit millipoint. */ + public static final String MPT = "mpt"; + /** cache holding all canonical FixedLength instances */ private static final PropertyCache cache = new PropertyCache(); /** canonical zero-length instance */ - public static final FixedLength ZERO_FIXED_LENGTH = new FixedLength(0, "mpt", 1.0f); + public static final FixedLength ZERO_FIXED_LENGTH = new FixedLength(0, FixedLength.MPT, 1.0f); private int millipoints; @@ -96,7 +114,7 @@ public final class FixedLength extends LengthProperty { * to the given number of units and unit specifier */ public static FixedLength getInstance(double numUnits) { - return getInstance(numUnits, "mpt", 1.0f); + return getInstance(numUnits, FixedLength.MPT, 1.0f); } @@ -115,17 +133,17 @@ public final class FixedLength extends LengthProperty { //device-dependent units, take the resolution into account dvalue *= (res * 1000); } else { - if ("in".equals(unit)) { + if (FixedLength.INCH.equals(unit)) { dvalue *= 72000; - } else if ("cm".equals(unit)) { + } else if (FixedLength.CM.equals(unit)) { dvalue *= 28346.4567; - } else if ("mm".equals(unit)) { + } else if (FixedLength.MM.equals(unit)) { dvalue *= 2834.64567; - } else if ("pt".equals(unit)) { + } else if (FixedLength.POINT.equals(unit)) { dvalue *= 1000; - } else if ("pc".equals(unit)) { + } else if (FixedLength.PICA.equals(unit)) { dvalue *= 12000; - } else if (!"mpt".equals(unit)) { + } else if (!FixedLength.MPT.equals(unit)) { dvalue = 0; log.error("Unknown length unit '" + unit + "'"); } @@ -163,7 +181,7 @@ public final class FixedLength extends LengthProperty { /** {@inheritDoc} */ public String toString() { - return millipoints + "mpt"; + return millipoints + FixedLength.MPT; } /** {@inheritDoc} */ diff --git a/src/java/org/apache/fop/render/afp/fonts/RasterFont.java b/src/java/org/apache/fop/render/afp/fonts/RasterFont.java index d383660b9..a61f97ab5 100644 --- a/src/java/org/apache/fop/render/afp/fonts/RasterFont.java +++ b/src/java/org/apache/fop/render/afp/fonts/RasterFont.java @@ -25,6 +25,7 @@ import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.fop.fo.properties.FixedLength; import org.apache.fop.render.afp.exceptions.FontRuntimeException; /** @@ -75,7 +76,7 @@ public class RasterFont extends AFPFont { String pointsize = String.valueOf(size / 1000); CharacterSet csm = (CharacterSet) charSets.get(pointsize); if (csm == null) { - csm = (CharacterSet) charSets.get(size + "mpt"); + csm = (CharacterSet) charSets.get(size + FixedLength.MPT); } if (csm == null) { // Get char set with nearest font size @@ -83,7 +84,7 @@ public class RasterFont extends AFPFont { for (Iterator it = charSets.entrySet().iterator(); it.hasNext();) { Map.Entry me = (Map.Entry)it.next(); String key = (String)me.getKey(); - if (!key.endsWith("mpt")) { + if (!key.endsWith(FixedLength.MPT)) { int mpt = Integer.parseInt(key) * 1000; if (Math.abs(size - mpt) < distance) { distance = Math.abs(size - mpt); @@ -93,7 +94,7 @@ public class RasterFont extends AFPFont { } } if (csm != null) { - charSets.put(size + "mpt", csm); + charSets.put(size + FixedLength.MPT, csm); String msg = "No " + (size / 1000) + "pt font " + getFontName() + " found, substituted with " + pointsize + "pt font"; log.warn(msg); diff --git a/src/java/org/apache/fop/render/rtf/FoUnitsConverter.java b/src/java/org/apache/fop/render/rtf/FoUnitsConverter.java index 8a7e2612b..fa95b8502 100644 --- a/src/java/org/apache/fop/render/rtf/FoUnitsConverter.java +++ b/src/java/org/apache/fop/render/rtf/FoUnitsConverter.java @@ -24,6 +24,7 @@ import java.util.HashMap; //FOP import org.apache.fop.apps.FOPException; +import org.apache.fop.fo.properties.FixedLength; /** Converts XSL-FO units to RTF units @@ -51,10 +52,10 @@ final class FoUnitsConverter { /** conversion factors keyed by xsl:fo units names */ private static final Map TWIP_FACTORS = new HashMap(); static { - TWIP_FACTORS.put("mm", new Float(MM_TO_TWIPS)); - TWIP_FACTORS.put("cm", new Float(CM_TO_TWIPS)); - TWIP_FACTORS.put("pt", new Float(POINT_TO_TWIPS)); - TWIP_FACTORS.put("in", new Float(IN_TO_TWIPS)); + TWIP_FACTORS.put(FixedLength.MM, new Float(MM_TO_TWIPS)); + TWIP_FACTORS.put(FixedLength.CM, new Float(CM_TO_TWIPS)); + TWIP_FACTORS.put(FixedLength.POINT, new Float(POINT_TO_TWIPS)); + TWIP_FACTORS.put(FixedLength.INCH, new Float(IN_TO_TWIPS)); } /** singleton pattern */ @@ -125,7 +126,7 @@ final class FoUnitsConverter { /** convert a font size given in points like "12pt" */ int convertFontSize(String size) throws FOPException { size = size.trim(); - final String sFONTSUFFIX = "pt"; + final String sFONTSUFFIX = FixedLength.POINT; if (!size.endsWith(sFONTSUFFIX)) { throw new FOPException("Invalid font size '" + size + "', must end with '" + sFONTSUFFIX + "'"); diff --git a/src/java/org/apache/fop/render/rtf/RTFHandler.java b/src/java/org/apache/fop/render/rtf/RTFHandler.java index 333e4ab95..d2f2c4192 100644 --- a/src/java/org/apache/fop/render/rtf/RTFHandler.java +++ b/src/java/org/apache/fop/render/rtf/RTFHandler.java @@ -85,6 +85,7 @@ import org.apache.fop.fo.pagination.Region; import org.apache.fop.fo.pagination.SimplePageMaster; import org.apache.fop.fo.pagination.StaticContent; import org.apache.fop.fo.properties.CommonBorderPaddingBackground; +import org.apache.fop.fo.properties.FixedLength; import org.apache.fop.fonts.FontSetup; import org.apache.fop.render.DefaultFontResolver; import org.apache.fop.render.rtf.rtflib.rtfdoc.IRtfAfterContainer; @@ -578,7 +579,7 @@ public class RTFHandler extends FOEventHandler { Integer iWidth = new Integer(tc.getColumnWidth().getValue(context) / 1000); - String strWidth = iWidth.toString() + "pt"; + String strWidth = iWidth.toString() + FixedLength.POINT; Float width = new Float( FoUnitsConverter.getInstance().convertToTwips(strWidth)); builderContext.getTableContext().setNextColumnWidth(width); @@ -1277,11 +1278,11 @@ public class RTFHandler extends FOEventHandler { } //set width in rtf - //newGraphic.setWidth((long) (contentwidth / 1000f) + "pt"); + //newGraphic.setWidth((long) (contentwidth / 1000f) + FixedLength.POINT); rtfGraphic.setWidth((long) (contentwidth / 50f) + "twips"); //set height in rtf - //newGraphic.setHeight((long) (contentheight / 1000f) + "pt"); + //newGraphic.setHeight((long) (contentheight / 1000f) + FixedLength.POINT); rtfGraphic.setHeight((long) (contentheight / 50f) + "twips"); //TODO: make this configurable: diff --git a/src/java/org/apache/fop/render/rtf/TableAttributesConverter.java b/src/java/org/apache/fop/render/rtf/TableAttributesConverter.java index 4c8865598..677832418 100644 --- a/src/java/org/apache/fop/render/rtf/TableAttributesConverter.java +++ b/src/java/org/apache/fop/render/rtf/TableAttributesConverter.java @@ -29,6 +29,7 @@ import org.apache.fop.fo.flow.table.TableCell; import org.apache.fop.fo.flow.table.TableHeader; import org.apache.fop.fo.flow.table.TableRow; import org.apache.fop.fo.properties.CommonBorderPaddingBackground; +import org.apache.fop.fo.properties.FixedLength; import org.apache.fop.render.rtf.rtflib.rtfdoc.ITableAttributes; import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfAttributes; @@ -343,7 +344,7 @@ public final class TableAttributesConverter { LengthProperty lengthprop = (LengthProperty)p; Float f = new Float(lengthprop.getLength().getValue() / 1000f); - String sValue = f.toString() + "pt"; + String sValue = f.toString() + FixedLength.POINT; attrib.set(BorderAttributesConverter.BORDER_WIDTH, (int)FoUnitsConverter.getInstance().convertToTwips(sValue)); |