Author: fanningpj
Date: Sun May 11 13:45:31 2025
New Revision: 1925502
URL: http://svn.apache.org/viewvc?rev=1925502&view=rev
Log:
try to avoid class cast issues
Added:
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/ooxml/util/NumberHelper.java
(with props)
Modified:
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFTextParagraph.java
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFTextRun.java
Added:
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/ooxml/util/NumberHelper.java
URL:
http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/main/java/org/apache/poi/ooxml/util/NumberHelper.java?rev=1925502&view=auto
==============================================================================
---
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/ooxml/util/NumberHelper.java
(added)
+++
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/ooxml/util/NumberHelper.java
Sun May 11 13:45:31 2025
@@ -0,0 +1,49 @@
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.ooxml.util;
+
+import org.apache.poi.util.Internal;
+
+/**
+ * Helper class for number related operations.
+ * <p>Note: This class is for internal POI usage only.</p>
+ *
+ * @since POI 5.4.2
+ */
+@Internal
+public class NumberHelper {
+ private NumberHelper() {
+ // no instances of this class
+ }
+
+ /**
+ * @param number the number to convert
+ * @return the double representation of the number
+ * @throws IllegalArgumentException if the number cannot be converted
+ */
+ public static double toDouble(Object number) {
+ if (number instanceof Number) {
+ return ((Number) number).doubleValue();
+ } else if (number instanceof String) {
+ return Double.parseDouble((String) number);
+ }
+ throw new IllegalArgumentException("Cannot convert of class" +
number.getClass().getName() +
+ " to double");
+ }
+
+}
Propchange:
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/ooxml/util/NumberHelper.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFTextParagraph.java
URL:
http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFTextParagraph.java?rev=1925502&r1=1925501&r2=1925502&view=diff
==============================================================================
---
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFTextParagraph.java
(original)
+++
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFTextParagraph.java
Sun May 11 13:45:31 2025
@@ -22,6 +22,7 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
+import org.apache.poi.ooxml.util.NumberHelper;
import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.util.Internal;
import org.apache.poi.util.Units;
@@ -579,15 +580,8 @@ public class XSSFTextParagraph implement
// check if the percentage value is scaled
CTTextNormalAutofit normAutofit =
_shape.getTxBody().getBodyPr().getNormAutofit();
if(normAutofit != null && normAutofit.isSetLnSpcReduction()) {
- final Object lnSpcReduction = normAutofit.getLnSpcReduction();
- final int divisor = 100000;
- if (lnSpcReduction instanceof Number) {
- double scale = 1 - ((Number) lnSpcReduction).doubleValue()
/ divisor;
- lnSpc *= scale;
- } else if (lnSpcReduction instanceof String) {
- double scale = 1 - Double.parseDouble((String)
lnSpcReduction) / divisor;
- lnSpc *= scale;
- }
+ double scale = 1 -
NumberHelper.toDouble(normAutofit.getLnSpcReduction()) / 100000;
+ lnSpc *= scale;
}
}
Modified:
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFTextRun.java
URL:
http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFTextRun.java?rev=1925502&r1=1925501&r2=1925502&view=diff
==============================================================================
---
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFTextRun.java
(original)
+++
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFTextRun.java
Sun May 11 13:45:31 2025
@@ -16,6 +16,7 @@
==================================================================== */
package org.apache.poi.xssf.usermodel;
+import org.apache.poi.ooxml.util.NumberHelper;
import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.util.Units;
import org.openxmlformats.schemas.drawingml.x2006.main.CTRegularTextRun;
@@ -131,13 +132,7 @@ public class XSSFTextRun {
double size = XSSFFont.DEFAULT_FONT_SIZE; // default font size
CTTextNormalAutofit afit =
getParentParagraph().getParentShape().getTxBody().getBodyPr().getNormAutofit();
if (afit != null && afit.isSetFontScale()) {
- final Object fs = afit.getFontScale();
- final int divisor = 100000;
- if (fs instanceof Number) {
- scale = ((Number) fs).doubleValue() / divisor;
- } else if (fs instanceof String) {
- scale = Double.parseDouble((String) fs) / divisor;
- }
+ scale = NumberHelper.toDouble(afit.getFontScale()) / 100000;
}
CTTextCharacterProperties rPr = getRPrOrNull();
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]