]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Created Constants for unit descriptions
authorMaximilian Berger <maxberger@apache.org>
Thu, 14 Feb 2008 11:57:05 +0000 (11:57 +0000)
committerMaximilian Berger <maxberger@apache.org>
Thu, 14 Feb 2008 11:57:05 +0000 (11:57 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@627719 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/fop/fo/expr/NumericProperty.java
src/java/org/apache/fop/fo/properties/FixedLength.java
src/java/org/apache/fop/render/afp/fonts/RasterFont.java
src/java/org/apache/fop/render/rtf/FoUnitsConverter.java
src/java/org/apache/fop/render/rtf/RTFHandler.java
src/java/org/apache/fop/render/rtf/TableAttributesConverter.java

index 9c0b9e2ba1939995ae49a7b1f8900202e2b6971b..54fe1f2f7337f81520dc6b5bb90ea3c4afcf0559 100644 (file)
@@ -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;
         }
index 7c4344b5319264a3682a82e16bb3e7db9b9c45b3..6debdd145cdd1b2d086efe73a9d4ee8bf3928280 100644 (file)
@@ -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} */
index d383660b9339914cbd401fbc009c6a31f0b05921..a61f97ab5201312f0b1da9f6965706564c78515d 100644 (file)
@@ -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);
index 8a7e2612b26c2661955f485ffe7346b4863ad5bf..fa95b8502e7bcf9322a342758e3b459fe672bbcf 100644 (file)
@@ -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 + "'");
index 333e4ab953ed3d512c41a273d7a20f424dda08ea..d2f2c4192389ab2fb4e45f86c89a3928fa829391 100644 (file)
@@ -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:
index 4c8865598a02b58d671529fe3795898361d06392..6778324186cb65a6cc078f3b69a41d55a2b72082 100644 (file)
@@ -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));