summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--xmerge/source/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/ColumnStyle.java13
-rw-r--r--xmerge/source/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/RowStyle.java14
-rw-r--r--xmerge/source/xmerge/java/org/openoffice/xmerge/util/TwipsConverter.java29
3 files changed, 27 insertions, 29 deletions
diff --git a/xmerge/source/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/ColumnStyle.java b/xmerge/source/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/ColumnStyle.java
index bd33a30b3821..68c689f9976b 100644
--- a/xmerge/source/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/ColumnStyle.java
+++ b/xmerge/source/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/ColumnStyle.java
@@ -125,18 +125,7 @@ public class ColumnStyle extends Style implements Cloneable {
* @return The twips equivalent.
*/
private int parseColWidth(String value) {
-
- int width = 255; // Default value
-
- if(value.indexOf("cm")!=-1) {
- float widthCM = Float.parseFloat(value.substring(0,value.indexOf('c')));
- width = TwipsConverter.cm2twips(widthCM);
- } else if(value.indexOf("inch")!=-1) {
- float widthInch = Float.parseFloat(value.substring(0,value.indexOf('i')));
- width = TwipsConverter.inches2twips(widthInch);
- }
-
- return (width);
+ return TwipsConverter.convert2twips(value, 255);
}
/**
diff --git a/xmerge/source/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/RowStyle.java b/xmerge/source/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/RowStyle.java
index e8cd0e08f298..3f8075c2ce50 100644
--- a/xmerge/source/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/RowStyle.java
+++ b/xmerge/source/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/RowStyle.java
@@ -124,19 +124,7 @@ public class RowStyle extends Style implements Cloneable {
* @return The twips equivalent.
*/
private int parseRowHeight(String value) {
-
- int height = 255; // Default value
-
- if(value.indexOf("cm")!=-1) {
- float heightCM = Float.parseFloat(value.substring(0,value.indexOf('c')));
- height = TwipsConverter.cm2twips(heightCM);
- } else if(value.indexOf("inch")!=-1) {
- float heightInch = Float.parseFloat(value.substring(0,value.indexOf('i')));
- height = TwipsConverter.inches2twips(heightInch);
- }
-
- return (height);
-
+ return TwipsConverter.convert2twips(value, 255);
}
/**
diff --git a/xmerge/source/xmerge/java/org/openoffice/xmerge/util/TwipsConverter.java b/xmerge/source/xmerge/java/org/openoffice/xmerge/util/TwipsConverter.java
index 5ae1139aead0..8ab83be1c4ae 100644
--- a/xmerge/source/xmerge/java/org/openoffice/xmerge/util/TwipsConverter.java
+++ b/xmerge/source/xmerge/java/org/openoffice/xmerge/util/TwipsConverter.java
@@ -39,8 +39,7 @@ public class TwipsConverter {
/**
* Convert from cm's to twips.
*
- * @param value {@code byte} array containing the LE representation of
- * the value.
+ * @param value {@code float} containing the representation of the value.
*
* @return {@code int} containing the converted value.
*/
@@ -52,12 +51,34 @@ public class TwipsConverter {
/**
* Convert from cm's to twips.
*
- * @param value {@code byte} array containing the LE representation of
- * the value.
+ * @param value {@code float} containing the representation of the value.
*
* @return {@code int} containing the converted value.
*/
public static int inches2twips(float value) {
return (int) (value*1440);
}
+
+ /**
+ * Convert {@code String} to twips.
+ *
+ * @param value {@code String} in the form {@literal "1.234cm"} or
+ * {@literal "1.234inch"}.
+ * @param defaultValue the default value.
+ * @return the converted value if {@code value} is a well-formatted {@code
+ * String}, {@code defaultValue} otherwise.
+ */
+ public static int convert2twips(String value, int defaultValue) {
+ int posi;
+
+ if ((posi = value.indexOf("cm")) != -1) {
+ float cm = Float.parseFloat(value.substring(0,posi));
+ return cm2twips(cm);
+ } else if ((posi = value.indexOf("inch")) != -1) {
+ float inches = Float.parseFloat(value.substring(0,posi));
+ return inches2twips(inches);
+ }
+
+ return defaultValue;
+ }
} \ No newline at end of file