]> source.dussan.org Git - poi.git/commitdiff
fix result of multiplication cast to wider type
authorAlain Béarez <abearez@apache.org>
Tue, 21 May 2019 00:14:12 +0000 (00:14 +0000)
committerAlain Béarez <abearez@apache.org>
Tue, 21 May 2019 00:14:12 +0000 (00:14 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1859595 13f79535-47bb-0310-9956-ffa450edef68

20 files changed:
src/examples/src/org/apache/poi/hssf/usermodel/examples/BigExample.java
src/examples/src/org/apache/poi/hssf/usermodel/examples/HSSFReadWrite.java
src/java/org/apache/poi/poifs/filesystem/POIFSFileSystem.java
src/java/org/apache/poi/ss/formula/atp/YearFracCalculator.java
src/java/org/apache/poi/ss/formula/functions/Days360.java
src/java/org/apache/poi/ss/usermodel/DateUtil.java
src/java/org/apache/poi/ss/usermodel/ExcelStyleDateFormatter.java
src/java/org/apache/poi/ss/util/ImageUtils.java
src/java/org/apache/poi/ss/util/cellwalk/CellWalk.java
src/java/org/apache/poi/util/StringUtil.java
src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfComment.java
src/scratchpad/src/org/apache/poi/hpbf/model/qcbits/QCTextBit.java
src/scratchpad/src/org/apache/poi/hslf/record/CurrentUserAtom.java
src/scratchpad/src/org/apache/poi/hslf/record/MasterTextPropAtom.java
src/scratchpad/src/org/apache/poi/hslf/record/TextCharsAtom.java
src/scratchpad/src/org/apache/poi/hslf/record/TextSpecInfoRun.java
src/scratchpad/src/org/apache/poi/hwmf/record/HwmfDraw.java
src/scratchpad/src/org/apache/poi/hwpf/converter/WordToHtmlConverter.java
src/scratchpad/src/org/apache/poi/hwpf/sprm/SprmUtils.java
src/scratchpad/src/org/apache/poi/hwpf/sprm/TableSprmCompressor.java

index d00bd9c87c606c195f22c4e7f8be0f34d861717a..a1e84efba518d40299f3c334d4390e7da122f86f 100644 (file)
@@ -102,9 +102,9 @@ public class BigExample {
                     // create a numeric cell
                     c = r.createCell(cellnum);
                     // do some goofy math to demonstrate decimals
-                    c.setCellValue(rownum * 10000 + cellnum
-                            + (((double) rownum / 1000)
-                            + ((double) cellnum / 10000)));
+                    c.setCellValue((rownum * 10000.0) + cellnum
+                            + (rownum / 1000.0)
+                            + (cellnum / 10000.0));
 
                     // on every other row
                     if ((rownum % 2) == 0) {
index 6e6fc5b3694381b4f9c7a907d0650c50d0ddcbe3..0484d6feefeab00f363338bf18e87bb783514614 100644 (file)
@@ -87,8 +87,8 @@ public final class HSSFReadWrite {
 
                                for (int cellnum = 0; cellnum < 50; cellnum += 2) {
                                        HSSFCell c = r.createCell(cellnum);
-                                       c.setCellValue(rownum * 10000 + cellnum
-                                                       + (((double) rownum / 1000) + ((double) cellnum / 10000)));
+                                       c.setCellValue((rownum * 10000.0) + cellnum
+                                                       + (rownum / 1000.0) + (cellnum / 10000.0));
                                        if ((rownum % 2) == 0) {
                                                c.setCellStyle(cs);
                                        }
index e68f5d96869972f8cdf0522683cc389db1cfb67b..12e408ee6346862aad81b7ee2b47b1f1f3c1529c 100644 (file)
@@ -759,6 +759,7 @@ public class POIFSFileSystem extends BlockStore
      * and buffers. After this, you will be unable to read or
      * write from the FileSystem.
      */
+    @Override
     public void close() throws IOException {
         _data.close();
     }
@@ -834,6 +835,7 @@ public class POIFSFileSystem extends BlockStore
      *
      * @return an array of Object; may not be null, but may be empty
      */
+    @Override
     public Object[] getViewableArray() {
         if (preferArray()) {
             return getRoot().getViewableArray();
@@ -850,6 +852,7 @@ public class POIFSFileSystem extends BlockStore
      * back end store
      */
 
+    @Override
     public Iterator<Object> getViewableIterator() {
         if (!preferArray()) {
             return getRoot().getViewableIterator();
@@ -866,6 +869,7 @@ public class POIFSFileSystem extends BlockStore
      * a viewer should call getViewableIterator
      */
 
+    @Override
     public boolean preferArray() {
         return getRoot().preferArray();
     }
@@ -877,6 +881,7 @@ public class POIFSFileSystem extends BlockStore
      * @return short description
      */
 
+    @Override
     public String getShortDescription() {
         return "POIFS FileSystem";
     }
@@ -949,4 +954,3 @@ public class POIFSFileSystem extends BlockStore
     }
 
 }
-
index 52cdbd7e0bf2725fff94999cef04383319170eab..7a31656aedc473c790023cf239801948215ac5d5 100644 (file)
@@ -27,7 +27,7 @@ import org.apache.poi.util.LocaleUtil;
 
 /**
  * Internal calculation methods for Excel 'Analysis ToolPak' function YEARFRAC()<br>
- *  
+ *
  * Algorithm inspired by www.dwheeler.com/yearfrac
  */
 final class YearFracCalculator {
@@ -61,7 +61,7 @@ final class YearFracCalculator {
                int startDateVal = (int) Math.floor(pStartDateVal);
                int endDateVal = (int) Math.floor(pEndDateVal);
                if (startDateVal == endDateVal) {
-                       // when dates are equal, result is zero 
+                       // when dates are equal, result is zero
                        return 0;
                }
                // swap start and end if out of order
@@ -92,7 +92,7 @@ final class YearFracCalculator {
                int date1day = startDate.day;
                int date2day = endDate.day;
 
-               // basis zero has funny adjustments to the day-of-month fields when at end-of-month 
+               // basis zero has funny adjustments to the day-of-month fields when at end-of-month
                if (date1day == LONG_MONTH_LEN && date2day == LONG_MONTH_LEN) {
                        date1day = SHORT_MONTH_LEN;
                        date2day = SHORT_MONTH_LEN;
@@ -155,7 +155,7 @@ final class YearFracCalculator {
                int date2day = endDate.day;
 
 
-               // basis four has funny adjustments to the day-of-month fields when at end-of-month 
+               // basis four has funny adjustments to the day-of-month fields when at end-of-month
                if (date1day == LONG_MONTH_LEN) {
                        date1day = SHORT_MONTH_LEN;
                }
@@ -169,10 +169,10 @@ final class YearFracCalculator {
 
        private static double calculateAdjusted(SimpleDate startDate, SimpleDate endDate, int date1day,
                        int date2day) {
-               double dayCount 
-                       = (endDate.year - startDate.year) * 360
-                       + (endDate.month - startDate.month) * SHORT_MONTH_LEN
-                       + (date2day - date1day) * 1;
+               double dayCount
+                       = (endDate.year - startDate.year) * 360.0
+                       + (endDate.month - startDate.month) * (double)SHORT_MONTH_LEN
+                       + (date2day - date1day) * 1.0;
                return dayCount / 360;
        }
 
@@ -223,7 +223,7 @@ final class YearFracCalculator {
                        }
                        return false;
                }
-               
+
                if (isLeapYear(end.year)) {
                        switch (end.month) {
                                case SimpleDate.JANUARY:
@@ -245,14 +245,14 @@ final class YearFracCalculator {
        private static int dateDiff(long startDateMS, long endDateMS) {
                long msDiff = endDateMS - startDateMS;
 
-               // some extra checks to make sure we don't hide some other bug with the rounding 
+               // some extra checks to make sure we don't hide some other bug with the rounding
                int remainderHours = (int) ((msDiff % MS_PER_DAY) / MS_PER_HOUR);
                switch (remainderHours) {
                        case 0:  // normal case
                                break;
                        case 1:  // transition from normal time to daylight savings adjusted
                        case 23: // transition from daylight savings adjusted to normal time
-                               // Unexpected since we are using UTC_TIME_ZONE 
+                               // Unexpected since we are using UTC_TIME_ZONE
                        default:
                                throw new RuntimeException("Unexpected date diff between " + startDateMS + " and " + endDateMS);
 
index 6a5dabcf490d5688496cba9b0e34fcf21eb6bacb..e86b23be896fdce91a97f742ba53d4d0b5cfc477 100644 (file)
@@ -30,17 +30,17 @@ import org.apache.poi.util.LocaleUtil;
  * (twelve 30-day months), which is used in some accounting calculations. Use
  * this function to help compute payments if your accounting system is based on
  * twelve 30-day months.<p>
- * 
+ *
  * {@code DAYS360(start_date,end_date,[method])}
- * 
+ *
  * <ul>
  * <li>Start_date, end_date (required):<br>
  * The two dates between which you want to know the number of days.<br>
  * If start_date occurs after end_date, the DAYS360 function returns a negative number.</li>
- * 
+ *
  * <li>Method (optional):<br>
  * A logical value that specifies whether to use the U.S. or European method in the calculation</li>
- * 
+ *
  * <li>Method set to false or omitted:<br>
  * the DAYS360 function uses the U.S. (NASD) method. If the starting date is the 31st of a month,
  * it becomes equal to the 30th of the same month. If the ending date is the 31st of a month and
@@ -51,7 +51,7 @@ import org.apache.poi.util.LocaleUtil;
  * because the DAYS360 function ignores the extra days added to February.<br>
  * On a leap year the function {@code =DAYS360("2/29/96","3/1/96", FALSE)} returns 1 day for
  * the same reason.</li>
- * 
+ *
  * <li>Method Set to true:<br>
  * When you set the method parameter to TRUE, the DAYS360 function uses the European method.
  * Starting dates or ending dates that occur on the 31st of a month become equal to the 30th of
@@ -62,10 +62,11 @@ import org.apache.poi.util.LocaleUtil;
  * On a leap year the function {@code =DAYS360("2/29/96", "3/1/96", TRUE)} returns
  * 2 days for the same reason.</li>
  * </ul>
- * 
+ *
  * @see <a href="https://support.microsoft.com/en-us/kb/235575">DAYS360 Function Produces Different Values Depending on the Version of Excel</a>
  */
 public class Days360 extends Var2or3ArgFunction {
+    @Override
     public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0, ValueEval arg1) {
         try {
             double d0 = NumericFunction.singleOperandEvaluate(arg0, srcRowIndex, srcColumnIndex);
@@ -76,6 +77,7 @@ public class Days360 extends Var2or3ArgFunction {
         }
     }
 
+    @Override
     public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0, ValueEval arg1,
             ValueEval arg2) {
         try {
@@ -95,8 +97,8 @@ public class Days360 extends Var2or3ArgFunction {
         int[] startingDate = getStartingDate(realStart, method);
         int[] endingDate = getEndingDate(realEnd, startingDate, method);
         return
-            (endingDate[0]*360+endingDate[1]*30+endingDate[2])-
-            (startingDate[0]*360+startingDate[1]*30+startingDate[2]);
+            (endingDate[0]*360.0+endingDate[1]*30.0+endingDate[2])-
+            (startingDate[0]*360.0+startingDate[1]*30.0+startingDate[2]);
     }
 
     private static Calendar getDate(double date) {
@@ -109,9 +111,11 @@ public class Days360 extends Var2or3ArgFunction {
         int yyyy = realStart.get(Calendar.YEAR);
         int mm = realStart.get(Calendar.MONTH);
         int dd = Math.min(30, realStart.get(Calendar.DAY_OF_MONTH));
-        
-        if (!method && isLastDayOfMonth(realStart)) dd = 30;
-        
+
+        if (!method && isLastDayOfMonth(realStart)) {
+            dd = 30;
+        }
+
         return new int[]{yyyy,mm,dd};
     }
 
@@ -134,7 +138,7 @@ public class Days360 extends Var2or3ArgFunction {
 
         return new int[]{yyyy,mm,dd};
     }
-    
+
     private static boolean isLastDayOfMonth(Calendar date) {
         int dayOfMonth = date.get(Calendar.DAY_OF_MONTH);
         int lastDayOfMonth = date.getActualMaximum(Calendar.DAY_OF_MONTH);
index a46a94c68442062baeac7b1ef65d1a7da26232a7..fbf34b7ae7483ac74206a2b2071ed9d3425d9cec 100644 (file)
@@ -62,7 +62,7 @@ public class DateUtil {
     private static final Pattern date_ptrn3b = Pattern.compile("^[\\[\\]yYmMdDhHsS\\-T/\u5e74\u6708\u65e5,. :\"\\\\]+0*[ampAMP/]*$");
     //  elapsed time patterns: [h],[m] and [s]
     private static final Pattern date_ptrn4 = Pattern.compile("^\\[([hH]+|[mM]+|[sS]+)\\]");
-    
+
     // for format which start with "[DBNum1]" or "[DBNum2]" or "[DBNum3]" could be a Chinese date
     private static final Pattern date_ptrn5 = Pattern.compile("^\\[DBNum(1|2|3)\\]");
 
@@ -124,11 +124,11 @@ public class DateUtil {
         // be 4 hours.
         // E.g. 2004-03-28 04:00 CEST - 2004-03-28 00:00 CET is 3 hours
         // and 2004-10-31 04:00 CET - 2004-10-31 00:00 CEST is 5 hours
-        double fraction = (((date.get(Calendar.HOUR_OF_DAY) * 60
+        double fraction = (((date.get(Calendar.HOUR_OF_DAY) * 60.0
                              + date.get(Calendar.MINUTE)
-                            ) * 60 + date.get(Calendar.SECOND)
-                           ) * 1000 + date.get(Calendar.MILLISECOND)
-                          ) / ( double ) DAY_MILLISECONDS;
+                            ) * 60.0 + date.get(Calendar.SECOND)
+                           ) * 1000.0 + date.get(Calendar.MILLISECOND)
+                          ) / DAY_MILLISECONDS;
         Calendar calStart = dayStart(date);
 
         double value = fraction + absoluteDay(calStart, use1904windowing);
@@ -145,12 +145,12 @@ public class DateUtil {
     /**
      *  Given an Excel date with using 1900 date windowing, and
      *  converts it to a java.util.Date.
-     *  
-     *  Excel Dates and Times are stored without any timezone 
-     *  information. If you know (through other means) that your file 
+     *
+     *  Excel Dates and Times are stored without any timezone
+     *  information. If you know (through other means) that your file
      *  uses a different TimeZone to the system default, you can use
      *  this version of the getJavaDate() method to handle it.
-     *   
+     *
      *  @param date  The Excel date.
      *  @param tz The TimeZone to evaluate the date in
      *  @return Java representation of the date, or null if date is not a valid Excel date
@@ -182,12 +182,12 @@ public class DateUtil {
     /**
      *  Given an Excel date with either 1900 or 1904 date windowing,
      *  converts it to a java.util.Date.
-     *  
-     *  Excel Dates and Times are stored without any timezone 
-     *  information. If you know (through other means) that your file 
+     *
+     *  Excel Dates and Times are stored without any timezone
+     *  information. If you know (through other means) that your file
      *  uses a different TimeZone to the system default, you can use
      *  this version of the getJavaDate() method to handle it.
-     *   
+     *
      *  @param date  The Excel date.
      *  @param tz The TimeZone to evaluate the date in
      *  @param use1904windowing  true if date uses 1904 windowing,
@@ -197,16 +197,16 @@ public class DateUtil {
     public static Date getJavaDate(double date, boolean use1904windowing, TimeZone tz) {
         return getJavaDate(date, use1904windowing, tz, false);
     }
-    
+
     /**
      *  Given an Excel date with either 1900 or 1904 date windowing,
      *  converts it to a java.util.Date.
-     *  
-     *  Excel Dates and Times are stored without any timezone 
-     *  information. If you know (through other means) that your file 
+     *
+     *  Excel Dates and Times are stored without any timezone
+     *  information. If you know (through other means) that your file
      *  uses a different TimeZone to the system default, you can use
      *  this version of the getJavaDate() method to handle it.
-     *   
+     *
      *  @param date  The Excel date.
      *  @param tz The TimeZone to evaluate the date in
      *  @param use1904windowing  true if date uses 1904 windowing,
@@ -218,7 +218,7 @@ public class DateUtil {
         Calendar calendar = getJavaCalendar(date, use1904windowing, tz, roundSeconds);
         return calendar == null ? null : calendar.getTime();
     }
-    
+
     /**
      *  Given an Excel date with either 1900 or 1904 date windowing,
      *  converts it to a java.util.Date.
@@ -314,7 +314,7 @@ public class DateUtil {
     public static Calendar getJavaCalendar(double date, boolean use1904windowing, TimeZone timeZone) {
         return getJavaCalendar(date, use1904windowing, timeZone, false);
     }
-        
+
     /**
      * Get EXCEL date as Java Calendar with given time zone.
      * @param date  The Excel date.
@@ -345,13 +345,14 @@ public class DateUtil {
     // string represents a date format if the same string is passed multiple times.
     // see https://issues.apache.org/bugzilla/show_bug.cgi?id=55611
     private static ThreadLocal<Integer> lastFormatIndex = new ThreadLocal<Integer>() {
+        @Override
         protected Integer initialValue() {
             return -1;
         }
     };
     private static ThreadLocal<String> lastFormatString = new ThreadLocal<>();
     private static ThreadLocal<Boolean> lastCachedResult = new ThreadLocal<>();
-    
+
     private static boolean isCached(String formatString, int formatIndex) {
         String cachedFormatString = lastFormatString.get();
         return cachedFormatString != null && formatIndex == lastFormatIndex.get()
@@ -378,12 +379,14 @@ public class DateUtil {
      * @see #isInternalDateFormat(int)
      */
     public static boolean isADateFormat(ExcelNumberFormat numFmt) {
-        
-        if (numFmt == null) return false;
-        
+
+        if (numFmt == null) {
+            return false;
+        }
+
         return isADateFormat(numFmt.getIdx(), numFmt.getFormat());
     }
-        
+
     /**
      * Given a format ID and its format String, will check to see if the
      *  format represents a date format or not.
@@ -399,7 +402,7 @@ public class DateUtil {
      * @see #isInternalDateFormat(int)
      */
     public static boolean isADateFormat(int formatIndex, String formatString) {
-        
+
         // First up, is this an internal date format?
         if(isInternalDateFormat(formatIndex)) {
             cache(formatString, formatIndex, true);
@@ -469,7 +472,7 @@ public class DateUtil {
             return true;
         }
         // If it starts with [DBNum1] or [DBNum2] or [DBNum3]
-        // then it could be a Chinese date 
+        // then it could be a Chinese date
         fs = date_ptrn5.matcher(fs).replaceAll("");
         // If it starts with [$-...], then could be a date, but
         //  who knows what that starting bit is all about
@@ -490,7 +493,7 @@ public class DateUtil {
         if (! date_ptrn3a.matcher(fs).find()) {
            return false;
         }
-        
+
         // If we get here, check it's only made up, in any case, of:
         //  y m d h s - \ / , . : [ ] T
         // optionally followed by AM/PM
@@ -530,7 +533,7 @@ public class DateUtil {
      *  Check if a cell contains a date
      *  Since dates are stored internally in Excel as double values
      *  we infer it is a date if it is formatted as such.
-     * @param cell 
+     * @param cell
      * @return true if it looks like a date
      *  @see #isADateFormat(int, String)
      *  @see #isInternalDateFormat(int)
@@ -538,32 +541,36 @@ public class DateUtil {
     public static boolean isCellDateFormatted(Cell cell) {
         return isCellDateFormatted(cell, null);
     }
-    
+
     /**
      *  Check if a cell contains a date
      *  Since dates are stored internally in Excel as double values
      *  we infer it is a date if it is formatted as such.
      *  Format is determined from applicable conditional formatting, if
      *  any, or cell style.
-     * @param cell 
+     * @param cell
      * @param cfEvaluator if available, or null
      * @return true if it looks like a date
      *  @see #isADateFormat(int, String)
      *  @see #isInternalDateFormat(int)
      */
     public static boolean isCellDateFormatted(Cell cell, ConditionalFormattingEvaluator cfEvaluator) {
-        if (cell == null) return false;
+        if (cell == null) {
+            return false;
+        }
         boolean bDate = false;
 
         double d = cell.getNumericCellValue();
         if ( DateUtil.isValidExcelDate(d) ) {
             ExcelNumberFormat nf = ExcelNumberFormat.from(cell, cfEvaluator);
-            if(nf==null) return false;
+            if(nf==null) {
+                return false;
+            }
             bDate = isADateFormat(nf);
         }
         return bDate;
     }
-    
+
     /**
      *  Check if a cell contains a date, checking only for internal
      *   excel date formats.
@@ -573,7 +580,9 @@ public class DateUtil {
      *  @see #isInternalDateFormat(int)
      */
     public static boolean isCellInternalDateFormatted(Cell cell) {
-        if (cell == null) return false;
+        if (cell == null) {
+            return false;
+        }
         boolean bDate = false;
 
         double d = cell.getNumericCellValue();
@@ -691,7 +700,7 @@ public class DateUtil {
         int minutes = parseInt(minStr, "minute", MINUTES_PER_HOUR);
         int seconds = parseInt(secStr, "second", SECONDS_PER_MINUTE);
 
-        double totalSeconds = seconds + (minutes + (hours) * 60) * 60;
+        double totalSeconds = seconds + (minutes + (hours * 60.0)) * 60.0;
         return totalSeconds / (SECONDS_PER_DAY);
     }
     /**
index 82fef17e2410496acbd07f9773dcbaba5d3882e7..c5684b1c4d1d4e7a2912a24fc46fceb031b87bac 100644 (file)
 ==================================================================== */
 package org.apache.poi.ss.usermodel;
 
-import java.util.*;
+import java.math.RoundingMode;
+import java.text.DateFormatSymbols;
+import java.text.DecimalFormat;
+import java.text.DecimalFormatSymbols;
+import java.text.FieldPosition;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Locale;
 
 import org.apache.poi.util.LocaleUtil;
 
-import java.math.RoundingMode;
-import java.text.*;
-
 /**
  * A wrapper around a {@link SimpleDateFormat} instance,
  * which handles a few Excel-style extensions that
@@ -60,7 +64,7 @@ public class ExcelStyleDateFormatter extends SimpleDateFormat {
         DataFormatter.setExcelStyleRoundingMode(format3digit);
         DataFormatter.setExcelStyleRoundingMode(format4digits);
     }
-    
+
     {
         setTimeZone(LocaleUtil.getUserTimeZone());
     }
@@ -152,7 +156,7 @@ public class ExcelStyleDateFormatter extends SimpleDateFormat {
         }
         if (s.indexOf(S_BRACKET_SYMBOL) != -1 ||
                 s.indexOf(SS_BRACKET_SYMBOL) != -1) {
-            float seconds = (float) (dateToBeFormatted * 24.0 * 60.0 * 60.0);
+            float seconds = (float) (dateToBeFormatted * 24 * 60 * 60);
             s = s.replaceAll(
                     String.valueOf(S_BRACKET_SYMBOL),
                     format1digit.format(seconds)
@@ -165,15 +169,15 @@ public class ExcelStyleDateFormatter extends SimpleDateFormat {
 
         if (s.indexOf(L_BRACKET_SYMBOL) != -1 ||
                 s.indexOf(LL_BRACKET_SYMBOL) != -1) {
-            float millisTemp = (float) ((dateToBeFormatted - Math.floor(dateToBeFormatted)) * 24.0 * 60.0 * 60.0);
+            float millisTemp = (float) ((dateToBeFormatted - Math.floor(dateToBeFormatted)) * 24 * 60 * 60);
             float millis = (millisTemp - (int) millisTemp);
             s = s.replaceAll(
                     String.valueOf(L_BRACKET_SYMBOL),
-                    format3digit.format(millis * 10)
+                    format3digit.format(millis * 10.0)
             );
             s = s.replaceAll(
                     String.valueOf(LL_BRACKET_SYMBOL),
-                    format4digits.format(millis * 100)
+                    format4digits.format(millis * 100.0)
             );
         }
 
@@ -185,11 +189,11 @@ public class ExcelStyleDateFormatter extends SimpleDateFormat {
         if (!(o instanceof ExcelStyleDateFormatter)) {
             return false;
         }
-        
+
         ExcelStyleDateFormatter other = (ExcelStyleDateFormatter) o;
         return dateToBeFormatted == other.dateToBeFormatted;
     }
-    
+
     @Override
     public int hashCode() {
         return Double.valueOf(dateToBeFormatted).hashCode();
index 9a2b1778c7e1a38b4aaf831c7ab54777ebd040f1..3a3b6efd5bf9e544a0497ae8c3cf91407bd1b245 100644 (file)
@@ -122,10 +122,14 @@ public class ImageUtils {
         NodeList lst;
         Element node = (Element)r.getImageMetadata(0).getAsTree("javax_imageio_1.0");
         lst = node.getElementsByTagName("HorizontalPixelSize");
-        if(lst != null && lst.getLength() == 1) hdpi = (int)(mm2inch/Float.parseFloat(((Element)lst.item(0)).getAttribute("value")));
+        if(lst != null && lst.getLength() == 1) {
+            hdpi = (int)(mm2inch/Float.parseFloat(((Element)lst.item(0)).getAttribute("value")));
+        }
 
         lst = node.getElementsByTagName("VerticalPixelSize");
-        if(lst != null && lst.getLength() == 1) vdpi = (int)(mm2inch/Float.parseFloat(((Element)lst.item(0)).getAttribute("value")));
+        if(lst != null && lst.getLength() == 1) {
+            vdpi = (int)(mm2inch/Float.parseFloat(((Element)lst.item(0)).getAttribute("value")));
+        }
 
         return new int[]{hdpi, vdpi};
     }
@@ -142,7 +146,7 @@ public class ImageUtils {
         boolean isHSSF = (anchor instanceof HSSFClientAnchor);
         PictureData data = picture.getPictureData();
         Sheet sheet = picture.getSheet();
-        
+
         // in pixel
         Dimension imgSize = getImageDimension(new ByteArrayInputStream(data.getData()), data.getPictureType());
         // in emus
@@ -163,11 +167,11 @@ public class ImageUtils {
         } else {
             w -= anchor.getDx1()/(double)EMU_PER_PIXEL;
         }
-        
+
         while(w < scaledWidth){
             w += sheet.getColumnWidthInPixels(col2++);
         }
-        
+
         if(w > scaledWidth) {
             //calculate dx2, offset in the rightmost cell
             double cw = sheet.getColumnWidthInPixels(--col2);
@@ -177,7 +181,9 @@ public class ImageUtils {
             } else {
                 dx2 = (int)((cw-delta)*EMU_PER_PIXEL);
             }
-            if (dx2 < 0) dx2 = 0;
+            if (dx2 < 0) {
+                dx2 = 0;
+            }
         }
         anchor.setCol2(col2);
         anchor.setDx2(dx2);
@@ -185,7 +191,7 @@ public class ImageUtils {
         double h = 0;
         int row2 = anchor.getRow1();
         int dy2 = 0;
-        
+
         h = getRowHeightInPixels(sheet,row2++);
         if (isHSSF) {
             h *= 1 - anchor.getDy1()/256d;
@@ -196,7 +202,7 @@ public class ImageUtils {
         while(h < scaledHeight){
             h += getRowHeightInPixels(sheet,row2++);
         }
-        
+
         if(h > scaledHeight) {
             double ch = getRowHeightInPixels(sheet,--row2);
             double delta = h - scaledHeight;
@@ -205,7 +211,9 @@ public class ImageUtils {
             } else {
                 dy2 = (int)((ch-delta)*EMU_PER_PIXEL);
             }
-            if (dy2 < 0) dy2 = 0;
+            if (dy2 < 0) {
+                dy2 = 0;
+            }
         }
 
         anchor.setRow2(row2);
@@ -238,20 +246,20 @@ public class ImageUtils {
         } else {
             w -= anchor.getDx1()/(double)EMU_PER_PIXEL;
         }
-        
+
         while(col2 < anchor.getCol2()){
             w += sheet.getColumnWidthInPixels(col2++);
         }
-        
+
         if (isHSSF) {
-            w += sheet.getColumnWidthInPixels(col2) * anchor.getDx2()/1024d;
+            w += anchor.getDx2()/1024d * sheet.getColumnWidthInPixels(col2);
         } else {
             w += anchor.getDx2()/(double)EMU_PER_PIXEL;
         }
 
         double h = 0;
         int row2 = anchor.getRow1();
-        
+
         h = getRowHeightInPixels(sheet,row2++);
         if (isHSSF) {
             h *= 1 - anchor.getDy1()/256d;
@@ -262,7 +270,7 @@ public class ImageUtils {
         while(row2 < anchor.getRow2()){
             h += getRowHeightInPixels(sheet,row2++);
         }
-        
+
         if (isHSSF) {
             h += getRowHeightInPixels(sheet,row2) * anchor.getDy2()/256;
         } else {
@@ -271,11 +279,11 @@ public class ImageUtils {
 
         w *= EMU_PER_PIXEL;
         h *= EMU_PER_PIXEL;
-        
+
         return new Dimension((int)Math.rint(w), (int)Math.rint(h));
     }
-    
-    
+
+
     public static double getRowHeightInPixels(Sheet sheet, int rowNum) {
         Row r = sheet.getRow(rowNum);
         double points = (r == null) ? sheet.getDefaultRowHeightInPoints() : r.getHeightInPoints();
index 9ab0e530fc96646808b24912b9972171a715f8fc..2826cc3323cdf4303c73f01e4f55f081caf6e216 100644 (file)
@@ -5,9 +5,9 @@
    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.
@@ -116,14 +116,17 @@ public class CellWalk {
         public int rowNumber;
         public int colNumber;
 
+        @Override
         public long getOrdinalNumber() {
             return ordinalNumber;
         }
 
+        @Override
         public int getRowNumber() {
             return rowNumber;
         }
 
+        @Override
         public int getColumnNumber() {
             return colNumber;
         }
index d8b4837931aeb5b9b30cb966fe2b4ec1bc6d2a93..fb69fbd538f0abd19ef8d5d608a2500b62c9fa5b 100644 (file)
@@ -263,7 +263,7 @@ public class StringUtil {
     }
 
     public static String readUnicodeLE(LittleEndianInput in, int nChars) {
-        byte[] bytes = IOUtils.safelyAllocate(nChars * 2, MAX_RECORD_LENGTH);
+        byte[] bytes = IOUtils.safelyAllocate(nChars * 2L, MAX_RECORD_LENGTH);
         in.readFully(bytes);
         return new String(bytes, UTF16LE);
     }
index eee11cfc9f269be4a16c6a6d4ff3bca928328a3f..a2cc75886c4918687c10a6f3605b78cb56cb5e83 100644 (file)
@@ -69,7 +69,9 @@ public class HemfComment {
 
         public static HemfCommentRecordType getById(long id, boolean isEmfPublic) {
             for (HemfCommentRecordType wrt : values()) {
-                if (wrt.id == id && wrt.isEmfPublic == isEmfPublic) return wrt;
+                if (wrt.id == id && wrt.isEmfPublic == isEmfPublic) {
+                    return wrt;
+                }
             }
             return emfGeneric;
         }
@@ -277,7 +279,7 @@ public class HemfComment {
             // The number of Unicode characters in the optional description string that follows.
             int nDescription = (int)leis.readUInt();
 
-            byte[] buf = IOUtils.safelyAllocate(nDescription*2, MAX_RECORD_LENGTH);
+            byte[] buf = IOUtils.safelyAllocate(nDescription * 2L, MAX_RECORD_LENGTH);
             leis.readFully(buf);
             description = new String(buf, StandardCharsets.UTF_16LE);
 
@@ -373,7 +375,9 @@ public class HemfComment {
 
         public static EmfFormatSignature getById(int id) {
             for (EmfFormatSignature wrt : values()) {
-                if (wrt.id == id) return wrt;
+                if (wrt.id == id) {
+                    return wrt;
+                }
             }
             return null;
         }
index 330c948fb2d9f92ea018ad3d1921a2c169167340..cc153708bbb809de1512222a5738ccb1838e2c0b 100644 (file)
@@ -41,7 +41,7 @@ public final class QCTextBit extends QCBit {
        }
 
        public void setText(String text) {
-        byte[] data = IOUtils.safelyAllocate(text.length() * 2, MAX_RECORD_LENGTH);
+        byte[] data = IOUtils.safelyAllocate(text.length() * 2L, MAX_RECORD_LENGTH);
                StringUtil.putUnicodeLE(text, data, 0);
                setData(data);
        }
index 26ba59d2c62c3e009fb3c8ff3394c5b4deee8aeb..2c673a22e8192c5686c38678ee486f701dbb619e 100644 (file)
@@ -15,7 +15,7 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 ==================================================================== */
-        
+
 
 
 package org.apache.poi.hslf.record;
@@ -73,7 +73,7 @@ public class CurrentUserAtom
 
        /** Only correct after reading in or writing out */
        private byte[] _contents;
-       
+
        /** Flag for encryption state of the whole file */
        private boolean isEncrypted;
 
@@ -96,7 +96,7 @@ public class CurrentUserAtom
 
        public boolean isEncrypted() { return isEncrypted; }
        public void setEncrypted(boolean isEncrypted) { this.isEncrypted = isEncrypted; }
-       
+
 
        /* ********************* real code follows *************************** */
 
@@ -117,19 +117,19 @@ public class CurrentUserAtom
        }
 
 
-       /** 
+       /**
         * Find the Current User in the filesystem, and create from that
         */
        public CurrentUserAtom(DirectoryNode dir) throws IOException {
                // Decide how big it is
                DocumentEntry docProps =
                        (DocumentEntry)dir.getEntry("Current User");
-               
+
                // If it's clearly junk, bail out
                if(docProps.getSize() > 131072) {
                        throw new CorruptPowerPointFileException("The Current User stream is implausably long. It's normally 28-200 bytes long, but was " + docProps.getSize() + " bytes");
                }
-               
+
                // Grab the contents
                int len = docProps.getSize();
                _contents = IOUtils.safelyAllocate(len, MAX_RECORD_LENGTH);
@@ -140,8 +140,8 @@ public class CurrentUserAtom
         if (len != readLen) {
             throw new IOException("Current User input stream ended prematurely - expected "+len+" bytes - received "+readLen+" bytes");
         }
-               
-               
+
+
                // See how long it is. If it's under 28 bytes long, we can't
                //  read it
                if(_contents.length < 28) {
@@ -169,9 +169,9 @@ public class CurrentUserAtom
        private void init() {
                // First up is the size, in 4 bytes, which is fixed
                // Then is the header
-               
-           isEncrypted = (LittleEndian.getInt(encHeaderToken) == LittleEndian.getInt(_contents,12)); 
-           
+
+           isEncrypted = (LittleEndian.getInt(encHeaderToken) == LittleEndian.getInt(_contents,12));
+
                // Grab the edit offset
                currentEditOffset = LittleEndian.getUInt(_contents,16);
 
@@ -188,7 +188,7 @@ public class CurrentUserAtom
                        usernameLen = 0;
                }
 
-               // Now we know the length of the username, 
+               // Now we know the length of the username,
                //  use this to grab the revision
                if(_contents.length >= 28+(int)usernameLen + 4) {
                        releaseVersion = LittleEndian.getUInt(_contents,28+(int)usernameLen);
@@ -227,7 +227,7 @@ public class CurrentUserAtom
                _contents = IOUtils.safelyAllocate(size, MAX_RECORD_LENGTH);
 
                // First we have a 8 byte atom header
-               System.arraycopy(atomHeader,0,_contents,0,4);   
+               System.arraycopy(atomHeader,0,_contents,0,4);
                // Size is 20+user len + revision len(4)
                int atomSize = 20+4+lastEditUser.length();
                LittleEndian.putInt(_contents,4,atomSize);
@@ -241,14 +241,14 @@ public class CurrentUserAtom
                // Now the current edit offset
                LittleEndian.putInt(_contents,16,(int)currentEditOffset);
 
-               // The username gets stored twice, once as US 
+               // The username gets stored twice, once as US
                //  ascii, and again as unicode laster on
                byte[] asciiUN = IOUtils.safelyAllocate(lastEditUser.length(), MAX_RECORD_LENGTH);
                StringUtil.putCompressedUnicode(lastEditUser,asciiUN,0);
-               
+
                // Now we're able to do the length of the last edited user
                LittleEndian.putShort(_contents,20,(short)asciiUN.length);
-               
+
                // Now the file versions, 2+1+1
                LittleEndian.putShort(_contents,22,(short)docFinalVersion);
                _contents[24] = docMajorNo;
@@ -265,7 +265,7 @@ public class CurrentUserAtom
                LittleEndian.putInt(_contents,28+asciiUN.length,(int)releaseVersion);
 
                // username in unicode
-               byte [] ucUN = IOUtils.safelyAllocate(lastEditUser.length()*2, MAX_RECORD_LENGTH);
+               byte [] ucUN = IOUtils.safelyAllocate(lastEditUser.length() * 2L, MAX_RECORD_LENGTH);
                StringUtil.putUnicodeLE(lastEditUser,ucUN,0);
                System.arraycopy(ucUN,0,_contents,28+asciiUN.length+4,ucUN.length);
 
@@ -280,7 +280,7 @@ public class CurrentUserAtom
                // Grab contents
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                writeOut(baos);
-               ByteArrayInputStream bais = 
+               ByteArrayInputStream bais =
                        new ByteArrayInputStream(baos.toByteArray());
 
                // Write out
index d754a10b3c0eece4cc694d81476889df77dd7c5a..9d76556e86eec786007b5b50e523db6cb299fa85 100644 (file)
@@ -59,7 +59,7 @@ public final class MasterTextPropAtom extends RecordAtom {
 
         LittleEndian.putShort(_header, 2, (short)getRecordType());
         LittleEndian.putInt(_header, 4, _data.length);
-        
+
         indents = new ArrayList<>();
     }
 
@@ -92,6 +92,7 @@ public final class MasterTextPropAtom extends RecordAtom {
      *
      * @return the record type.
      */
+    @Override
     public long getRecordType() {
         return RecordTypes.MasterTextPropAtom.typeID;
     }
@@ -103,12 +104,13 @@ public final class MasterTextPropAtom extends RecordAtom {
      * @param out the output stream to write to.
      * @throws java.io.IOException if an error occurs.
      */
+    @Override
     public void writeOut(OutputStream out) throws IOException {
         write();
         out.write(_header);
         out.write(_data);
     }
-    
+
     /**
      * Write the internal variables to the record bytes
      */
@@ -129,7 +131,7 @@ public final class MasterTextPropAtom extends RecordAtom {
     private void read() {
         int pos = 0;
         indents = new ArrayList<>(_data.length / 6);
-        
+
         while (pos <= _data.length - 6) {
             int count = LittleEndian.getInt(_data, pos);
             short indent = LittleEndian.getShort(_data, pos+4);
@@ -137,7 +139,7 @@ public final class MasterTextPropAtom extends RecordAtom {
             pos += 6;
         }
     }
-    
+
     /**
      * Returns the indent that applies at the given text offset
      */
@@ -151,7 +153,7 @@ public final class MasterTextPropAtom extends RecordAtom {
         }
         return -1;
     }
-    
+
     public List<IndentProp> getIndents() {
         return Collections.unmodifiableList(indents);
     }
index 570506b719aba9f6bd023f5287749fe7cf475f37..349ee8166b4101e0857113d53a43a85456989bd4 100644 (file)
@@ -48,7 +48,7 @@ public final class TextCharsAtom extends RecordAtom {
        /** Updates the text in the Atom. */
        public void setText(String text) {
                // Convert to little endian unicode
-               _text = IOUtils.safelyAllocate(text.length()*2, MAX_RECORD_LENGTH);
+               _text = IOUtils.safelyAllocate(text.length() * 2L, MAX_RECORD_LENGTH);
                StringUtil.putUnicodeLE(text,_text,0);
 
                // Update the size (header bytes 5-8)
index 3b35258ace8003d22c35bc5c614bfda648f1ea51..8a046c1613d79b897f40dacab1b6e09c13fb35ad 100644 (file)
@@ -20,7 +20,10 @@ package org.apache.poi.hslf.record;
 import java.io.IOException;
 import java.io.OutputStream;
 
-import org.apache.poi.util.*;
+import org.apache.poi.util.BitField;
+import org.apache.poi.util.IOUtils;
+import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.LittleEndianByteArrayInputStream;
 
 public class TextSpecInfoRun {
 
@@ -39,14 +42,14 @@ public class TextSpecInfoRun {
         grammar(new BitField(4)),
         /** the text is spelled correct */
         correct(new BitField(0));
-        
+
         final BitField bitField;
-        
+
         SpellInfoEnum(BitField bitField) {
             this.bitField = bitField;
         }
     }
-    
+
     /** A bit that specifies whether the spellInfo field exists. */
     private static final BitField spellFld    = new BitField(0X00000001);
     /** A bit that specifies whether the lid field exists. */
@@ -62,7 +65,7 @@ public class TextSpecInfoRun {
     // reserved1 - MUST be zero and MUST be ignored.
     /** A bit that specifies whether the smartTags field exists. */
     private static final BitField smartTagFld = new BitField(0X00000200);
-    // reserved2 - MUST be zero and MUST be ignored. 
+    // reserved2 - MUST be zero and MUST be ignored.
 
     /**
      * An optional unsigned integer that specifies an identifier for a character
@@ -76,7 +79,7 @@ public class TextSpecInfoRun {
      * only if fPp10ext is TRUE.
      **/
     private static final BitField grammarErrorFld = new BitField(0X80000000);
-    
+
     //Length of special info run.
     private int length;
 
@@ -97,7 +100,7 @@ public class TextSpecInfoRun {
      * reserved (13 bits): MUST be zero and MUST be ignored.
      */
     private short spellInfo = -1;
-    
+
     /**
      * An optional TxLCID that specifies the language identifier of this text.
      * It MUST exist if and only if lang is TRUE.
@@ -108,13 +111,13 @@ public class TextSpecInfoRun {
      * &gt; 0x0400 = A valid LCID as specified by [MS-LCID].
      */
     private short langId = -1;
-    
+
     /**
      * An optional TxLCID that specifies the alternate language identifier of this text.
      * It MUST exist if and only if altLang is TRUE.
      */
     private short altLangId = -1;
-    
+
     /**
      * An optional signed integer that specifies whether the text contains bidirectional
      * characters. It MUST exist if and only if fBidi is TRUE.
@@ -122,7 +125,7 @@ public class TextSpecInfoRun {
      * 0x0001 = Contains bidirectional characters.
      */
     private short bidi = -1;
-    
+
     private int pp10extMask = -1;
     private byte[] smartTagsBytes;
 
@@ -135,7 +138,7 @@ public class TextSpecInfoRun {
         setLength(len);
         setLangId((short)0);
     }
-    
+
     public TextSpecInfoRun(LittleEndianByteArrayInputStream source) {
         length = source.readInt();
         mask = source.readInt();
@@ -157,7 +160,7 @@ public class TextSpecInfoRun {
         if (smartTagFld.isSet(mask)) {
             // An unsigned integer specifies the count of items in rgSmartTagIndex.
             int count = source.readInt();
-            smartTagsBytes = IOUtils.safelyAllocate(4+count*4, MAX_RECORD_LENGTH);
+            smartTagsBytes = IOUtils.safelyAllocate(4 + count * 4L, MAX_RECORD_LENGTH);
             LittleEndian.putInt(smartTagsBytes, 0, count);
             // An array of SmartTagIndex that specifies the indices.
             // The count of items in the array is specified by count.
@@ -186,11 +189,13 @@ public class TextSpecInfoRun {
                 pp10extFld, pp10extMask, "pp10 extension field",
                 smartTagFld, smartTagsBytes, "smart tags"
         };
-        
+
         for (int i=0; i<flds.length-1; i+=3) {
             BitField fld = (BitField)flds[i+0];
             Object valO = flds[i+1];
-            if (!fld.isSet(mask)) continue;
+            if (!fld.isSet(mask)) {
+                continue;
+            }
             boolean valid;
             if (valO instanceof byte[]) {
                 byte[] bufB = (byte[]) valO;
@@ -214,15 +219,19 @@ public class TextSpecInfoRun {
                 throw new IOException(fval + " is activated, but its value is invalid");
             }
         }
-    }        
-    
+    }
+
     /**
      * @return Spelling status of this text. null if not defined.
      */
     public SpellInfoEnum getSpellInfo(){
-        if (spellInfo == -1) return null;
+        if (spellInfo == -1) {
+            return null;
+        }
         for (SpellInfoEnum si : new SpellInfoEnum[]{SpellInfoEnum.clean,SpellInfoEnum.error,SpellInfoEnum.grammar}) {
-            if (si.bitField.isSet(spellInfo)) return si;
+            if (si.bitField.isSet(spellInfo)) {
+                return si;
+            }
         }
         return SpellInfoEnum.correct;
     }
@@ -236,7 +245,7 @@ public class TextSpecInfoRun {
             : (short)spellInfo.bitField.set(0);
         mask = spellFld.setBoolean(mask, spellInfo != null);
     }
-    
+
     /**
      * Windows LANGID for this text.
      *
@@ -253,7 +262,7 @@ public class TextSpecInfoRun {
         this.langId = langId;
         mask = langFld.setBoolean(mask, langId != -1);
     }
-    
+
     /**
      * Alternate Windows LANGID of this text;
      * must be a valid non-East Asian LANGID if the text has an East Asian language,
@@ -313,15 +322,15 @@ public class TextSpecInfoRun {
         this.smartTagsBytes = (smartTagsBytes == null) ? null : smartTagsBytes.clone();
         mask = smartTagFld.setBoolean(mask, smartTagsBytes != null);
     }
-    
+
     /**
      * @return an identifier for a character run that contains StyleTextProp11 data.
      */
     public int getPP10RunId() {
         return (pp10extMask == -1 || !pp10extFld.isSet(mask)) ? -1 : pp10runidFld.getValue(pp10extMask);
-        
+
     }
-    
+
     /**
      * @param pp10RunId an identifier for a character run that contains StyleTextProp11 data, -1 to unset
      */
@@ -334,11 +343,11 @@ public class TextSpecInfoRun {
         // if both parameters are invalid, remove the extension mask
         mask = pp10extFld.setBoolean(mask, pp10extMask != -1);
     }
-    
+
     public Boolean getGrammarError() {
         return (pp10extMask == -1 || !pp10extFld.isSet(mask)) ? null : grammarErrorFld.isSet(pp10extMask);
     }
-    
+
     public void getGrammarError(Boolean grammarError) {
         if (grammarError == null) {
             pp10extMask = (getPP10RunId() == -1) ? -1 : grammarErrorFld.clear(pp10extMask);
index 17cd3c83d800074648e4f361f8347e17a3da2f35..733d0fca062c1ac1f6cd252bf2fa29ba6b2006dc 100644 (file)
@@ -108,7 +108,7 @@ public class HwmfDraw {
     public static class WmfPolygon implements HwmfRecord {
 
         protected Path2D poly;
-        
+
         @Override
         public HwmfRecordType getWmfRecordType() {
             return HwmfRecordType.polygon;
@@ -266,8 +266,8 @@ public class HwmfDraw {
             Rectangle2D inner = ctx.getProperties().getRegion().getBounds();
             double x = inner.getX()-width;
             double y = inner.getY()-height;
-            double w = inner.getWidth()+2*width;
-            double h = inner.getHeight()+2*height;
+            double w = inner.getWidth()+2.0*width;
+            double h = inner.getHeight()+2.0*height;
             Rectangle2D outer = new Rectangle2D.Double(x,y,w,h);
             Area frame = new Area(outer);
             frame.subtract(new Area(inner));
@@ -283,7 +283,7 @@ public class HwmfDraw {
     public static class WmfPolyPolygon implements HwmfRecord {
 
         protected final List<Path2D> polyList = new ArrayList<>();
-        
+
         @Override
         public HwmfRecordType getWmfRecordType() {
             return HwmfRecordType.polyPolygon;
@@ -577,7 +577,6 @@ public class HwmfDraw {
                 startAngle += 360;
             }
 
-            boolean fillShape;
             int arcClosure;
             switch (getWmfRecordType()) {
                 default:
@@ -671,7 +670,7 @@ public class HwmfDraw {
             return "{ index: "+objectIndex +" }";
         }
     }
-    
+
     static int readBounds(LittleEndianInputStream leis, Rectangle2D bounds) {
         /**
          * The 16-bit signed integers that defines the corners of the bounding rectangle.
index 42fe7fd30d0f005010513b97eecfbf074fb797ec..91de8b1b406b65568301acf05a610efe9d748c94 100644 (file)
@@ -92,7 +92,7 @@ public class WordToHtmlConverter extends AbstractWordConverter
     /**
      * Creates new instance of {@link WordToHtmlConverter}. Can be used for
      * output several {@link HWPFDocument}s into single HTML document.
-     * 
+     *
      * @param document XML DOM Document used as HTML document
      */
     public WordToHtmlConverter( Document document ) {
@@ -102,7 +102,7 @@ public class WordToHtmlConverter extends AbstractWordConverter
     public WordToHtmlConverter( HtmlDocumentFacade htmlDocumentFacade ) {
         this.htmlDocumentFacade = htmlDocumentFacade;
     }
-    
+
     private static String getSectionStyle( Section section )
     {
         float leftMargin = section.getMarginLeft() / TWIPS_PER_INCH;
@@ -132,9 +132,9 @@ public class WordToHtmlConverter extends AbstractWordConverter
 
     /**
      * Java main() interface to interact with {@link WordToHtmlConverter}<p>
-     * 
+     *
      * Usage: WordToHtmlConverter infile outfile<p>
-     * 
+     *
      * Where infile is an input .doc file ( Word 95-2007) which will be rendered
      * as HTML into outfile
      */
@@ -344,11 +344,11 @@ public class WordToHtmlConverter extends AbstractWordConverter
 
         if ( aspectRatioX > 0 )
         {
-            imageWidth = picture.getDxaGoal() * aspectRatioX / 1000.f
+            imageWidth = aspectRatioX / 1000.f * picture.getDxaGoal()
                     / TWIPS_PER_INCH;
-            cropRight = picture.getDxaCropRight() * aspectRatioX / 1000.f
+            cropRight = aspectRatioX / 1000.f * picture.getDxaCropRight()
                     / TWIPS_PER_INCH;
-            cropLeft = picture.getDxaCropLeft() * aspectRatioX / 1000.f
+            cropLeft = aspectRatioX / 1000.f * picture.getDxaCropLeft()
                     / TWIPS_PER_INCH;
         }
         else
@@ -360,11 +360,11 @@ public class WordToHtmlConverter extends AbstractWordConverter
 
         if ( aspectRatioY > 0 )
         {
-            imageHeight = picture.getDyaGoal() * aspectRatioY / 1000.f
+            imageHeight = aspectRatioY / 1000.f * picture.getDyaGoal()
                     / TWIPS_PER_INCH;
-            cropTop = picture.getDyaCropTop() * aspectRatioY / 1000.f
+            cropTop = aspectRatioY / 1000.f * picture.getDyaCropTop()
                     / TWIPS_PER_INCH;
-            cropBottom = picture.getDyaCropBottom() * aspectRatioY / 1000.f
+            cropBottom = aspectRatioY / 1000.f * picture.getDyaCropBottom()
                     / TWIPS_PER_INCH;
         }
         else
index 83b9ce488837f6800ed6506906124360328c6377..e47f95651230bae3b8d3d7c14dc4b429247893f6 100644 (file)
@@ -37,7 +37,7 @@ public final class SprmUtils
 
     public static byte[] shortArrayToByteArray(short[] convert)
     {
-        byte[] buf = IOUtils.safelyAllocate(convert.length * LittleEndian.SHORT_SIZE, MAX_RECORD_LENGTH);
+        byte[] buf = IOUtils.safelyAllocate(convert.length * (long)LittleEndian.SHORT_SIZE, MAX_RECORD_LENGTH);
 
         for (int x = 0; x < convert.length; x++)
         {
@@ -102,7 +102,7 @@ public final class SprmUtils
                 break;
             default:
                 //should never happen
-                throw new RuntimeException("Invalid sprm type"); 
+                throw new RuntimeException("Invalid sprm type");
         }
         LittleEndian.putShort(sprm, 0, instruction);
         list.add(sprm);
index 875b81b7fecf38ff6942ff670565c8666cd3c958..cbef3587ce3d136879ecddce06c9aa4256065a60 100644 (file)
@@ -81,7 +81,9 @@ public final class TableSprmCompressor
     {
       int itcMac = newTAP.getItcMac();
       byte[] buf = IOUtils.safelyAllocate(
-              1 + (LittleEndian.SHORT_SIZE*(itcMac + 1)) + (TableCellDescriptor.SIZE*itcMac),
+              1
+                + (LittleEndian.SHORT_SIZE*((long)itcMac + 1))
+                + (TableCellDescriptor.SIZE*(long)itcMac),
               MAX_RECORD_LENGTH);
       buf[0] = (byte)itcMac;