xmlgraphics-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cbowdi...@apache.org
Subject svn commit: r824246 - /xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/util/UnitConv.java
Date Mon, 12 Oct 2009 07:20:21 GMT
Author: cbowditch
Date: Mon Oct 12 07:20:21 2009
New Revision: 824246

URL: http://svn.apache.org/viewvc?rev=824246&view=rev
Log:
copy method from deprecated equivalent in FOP; org.apache.fop.util.UnitConv

Modified:
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/util/UnitConv.java

Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/util/UnitConv.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/util/UnitConv.java?rev=824246&r1=824245&r2=824246&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/util/UnitConv.java (original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/util/UnitConv.java Mon Oct 12
07:20:21 2009
@@ -35,6 +35,27 @@
     /** conversion factory from inches to points. */
     public static final int IN2PT = 72;
 
+    /** 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";
+
+        /** Describes the unit pixel. */
+    public static final String PX = "px";
+
     /**
      * Converts millimeters (mm) to points (pt)
      * @param mm the value in mm
@@ -155,4 +176,44 @@
         return new AffineTransform(matrix);
     }
 
+    /**
+     * Convert the given unit length to a dimensionless integer representing
+     * a whole number of base units (milli-points).
+     *
+     * @param value input unit value
+     * @return int millipoints
+     */
+    public static int convert(String value) {
+        double retValue = 0;
+        if (value != null) {
+            if (value.toLowerCase().indexOf(PX) > 0) {
+                retValue = Double.parseDouble(value.substring(0, value.length() - 2));
+                retValue *= 1000;
+            }
+            else if (value.toLowerCase().indexOf(INCH) > 0) {
+                retValue = Double.parseDouble(value.substring(0, value.length() - 2));
+                retValue *= 72000;
+            }
+            else if (value.toLowerCase().indexOf(CM) > 0) {
+                retValue = Double.parseDouble(value.substring(0, value.length() - 2));
+                retValue *= 28346.4567;
+            }
+            else if (value.toLowerCase().indexOf(MM) > 0) {
+                retValue = Double.parseDouble(value.substring(0, value.length() - 2));
+                retValue *= 2834.64567;
+            }
+            else if (value.toLowerCase().indexOf(MPT) > 0) {
+                retValue = Double.parseDouble(value.substring(0, value.length() - 3));
+            }
+            else if (value.toLowerCase().indexOf(POINT) > 0) {
+                retValue = Double.parseDouble(value.substring(0, value.length() - 2));
+                retValue *= 1000;
+            }
+            else if (value.toLowerCase().indexOf(PICA) > 0) {
+                retValue = Double.parseDouble(value.substring(0, value.length() - 2));
+                retValue *= 12000;
+            }
+        }
+        return (int)retValue;
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: commits-help@xmlgraphics.apache.org


Mime
View raw message