summaryrefslogtreecommitdiff
path: root/xmerge
diff options
context:
space:
mode:
authorRobert Antoni Buj i Gelonch <robert.buj@gmail.com>2014-10-01 19:41:50 +0200
committerNoel Grandin <noelgrandin@gmail.com>2014-10-02 08:52:44 +0000
commitca7899d64d8fc8b6902af33d50a2b50ca3c841ac (patch)
tree9ed988f39525aebf51d11273e29c20eb36bf76c6 /xmerge
parent08f33ca66559dfafd29ab0c6073232cf05a6d4e5 (diff)
xmerge: reuse the value of value.indexOf and remove duplicated code
Change-Id: I44d72f7d9f8c58436657ea1517d8eb76332abb4b Reviewed-on: https://gerrit.libreoffice.org/11747 Reviewed-by: Noel Grandin <noelgrandin@gmail.com> Tested-by: Noel Grandin <noelgrandin@gmail.com>
Diffstat (limited to 'xmerge')
-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