// 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) {
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);
}
* and buffers. After this, you will be unable to read or
* write from the FileSystem.
*/
+ @Override
public void close() throws IOException {
_data.close();
}
*
* @return an array of Object; may not be null, but may be empty
*/
+ @Override
public Object[] getViewableArray() {
if (preferArray()) {
return getRoot().getViewableArray();
* back end store
*/
+ @Override
public Iterator<Object> getViewableIterator() {
if (!preferArray()) {
return getRoot().getViewableIterator();
* a viewer should call getViewableIterator
*/
+ @Override
public boolean preferArray() {
return getRoot().preferArray();
}
* @return short description
*/
+ @Override
public String getShortDescription() {
return "POIFS FileSystem";
}
}
}
-
/**
* Internal calculation methods for Excel 'Analysis ToolPak' function YEARFRAC()<br>
- *
+ *
* Algorithm inspired by www.dwheeler.com/yearfrac
*/
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
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;
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;
}
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;
}
}
return false;
}
-
+
if (isLeapYear(end.year)) {
switch (end.month) {
case SimpleDate.JANUARY:
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);
* (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
* 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
* 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);
}
}
+ @Override
public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0, ValueEval arg1,
ValueEval arg2) {
try {
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) {
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};
}
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);
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)\\]");
// 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);
/**
* 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
/**
* 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,
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,
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.
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.
// 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()
* @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.
* @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);
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
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
* 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)
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.
* @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();
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);
}
/**
==================================================================== */
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
DataFormatter.setExcelStyleRoundingMode(format3digit);
DataFormatter.setExcelStyleRoundingMode(format4digits);
}
-
+
{
setTimeZone(LocaleUtil.getUserTimeZone());
}
}
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)
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)
);
}
if (!(o instanceof ExcelStyleDateFormatter)) {
return false;
}
-
+
ExcelStyleDateFormatter other = (ExcelStyleDateFormatter) o;
return dateToBeFormatted == other.dateToBeFormatted;
}
-
+
@Override
public int hashCode() {
return Double.valueOf(dateToBeFormatted).hashCode();
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};
}
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
} 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);
} else {
dx2 = (int)((cw-delta)*EMU_PER_PIXEL);
}
- if (dx2 < 0) dx2 = 0;
+ if (dx2 < 0) {
+ dx2 = 0;
+ }
}
anchor.setCol2(col2);
anchor.setDx2(dx2);
double h = 0;
int row2 = anchor.getRow1();
int dy2 = 0;
-
+
h = getRowHeightInPixels(sheet,row2++);
if (isHSSF) {
h *= 1 - anchor.getDy1()/256d;
while(h < scaledHeight){
h += getRowHeightInPixels(sheet,row2++);
}
-
+
if(h > scaledHeight) {
double ch = getRowHeightInPixels(sheet,--row2);
double delta = h - scaledHeight;
} else {
dy2 = (int)((ch-delta)*EMU_PER_PIXEL);
}
- if (dy2 < 0) dy2 = 0;
+ if (dy2 < 0) {
+ dy2 = 0;
+ }
}
anchor.setRow2(row2);
} 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;
while(row2 < anchor.getRow2()){
h += getRowHeightInPixels(sheet,row2++);
}
-
+
if (isHSSF) {
h += getRowHeightInPixels(sheet,row2) * anchor.getDy2()/256;
} else {
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();
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.
public int rowNumber;
public int colNumber;
+ @Override
public long getOrdinalNumber() {
return ordinalNumber;
}
+ @Override
public int getRowNumber() {
return rowNumber;
}
+ @Override
public int getColumnNumber() {
return colNumber;
}
}
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);
}
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;
}
// 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);
public static EmfFormatSignature getById(int id) {
for (EmfFormatSignature wrt : values()) {
- if (wrt.id == id) return wrt;
+ if (wrt.id == id) {
+ return wrt;
+ }
}
return null;
}
}
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);
}
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
+
package org.apache.poi.hslf.record;
/** Only correct after reading in or writing out */
private byte[] _contents;
-
+
/** Flag for encryption state of the whole file */
private boolean isEncrypted;
public boolean isEncrypted() { return isEncrypted; }
public void setEncrypted(boolean isEncrypted) { this.isEncrypted = isEncrypted; }
-
+
/* ********************* real code follows *************************** */
}
- /**
+ /**
* 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);
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) {
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);
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);
_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);
// 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;
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);
// Grab contents
ByteArrayOutputStream baos = new ByteArrayOutputStream();
writeOut(baos);
- ByteArrayInputStream bais =
+ ByteArrayInputStream bais =
new ByteArrayInputStream(baos.toByteArray());
// Write out
LittleEndian.putShort(_header, 2, (short)getRecordType());
LittleEndian.putInt(_header, 4, _data.length);
-
+
indents = new ArrayList<>();
}
*
* @return the record type.
*/
+ @Override
public long getRecordType() {
return RecordTypes.MasterTextPropAtom.typeID;
}
* @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
*/
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);
pos += 6;
}
}
-
+
/**
* Returns the indent that applies at the given text offset
*/
}
return -1;
}
-
+
public List<IndentProp> getIndents() {
return Collections.unmodifiableList(indents);
}
/** 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)
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 {
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. */
// 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
* only if fPp10ext is TRUE.
**/
private static final BitField grammarErrorFld = new BitField(0X80000000);
-
+
//Length of special info run.
private int length;
* 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.
* > 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.
* 0x0001 = Contains bidirectional characters.
*/
private short bidi = -1;
-
+
private int pp10extMask = -1;
private byte[] smartTagsBytes;
setLength(len);
setLangId((short)0);
}
-
+
public TextSpecInfoRun(LittleEndianByteArrayInputStream source) {
length = source.readInt();
mask = source.readInt();
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.
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;
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;
}
: (short)spellInfo.bitField.set(0);
mask = spellFld.setBoolean(mask, spellInfo != null);
}
-
+
/**
* Windows LANGID for this text.
*
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,
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
*/
// 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);
public static class WmfPolygon implements HwmfRecord {
protected Path2D poly;
-
+
@Override
public HwmfRecordType getWmfRecordType() {
return HwmfRecordType.polygon;
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));
public static class WmfPolyPolygon implements HwmfRecord {
protected final List<Path2D> polyList = new ArrayList<>();
-
+
@Override
public HwmfRecordType getWmfRecordType() {
return HwmfRecordType.polyPolygon;
startAngle += 360;
}
- boolean fillShape;
int arcClosure;
switch (getWmfRecordType()) {
default:
return "{ index: "+objectIndex +" }";
}
}
-
+
static int readBounds(LittleEndianInputStream leis, Rectangle2D bounds) {
/**
* The 16-bit signed integers that defines the corners of the bounding rectangle.
/**
* 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 ) {
public WordToHtmlConverter( HtmlDocumentFacade htmlDocumentFacade ) {
this.htmlDocumentFacade = htmlDocumentFacade;
}
-
+
private static String getSectionStyle( Section section )
{
float leftMargin = section.getMarginLeft() / TWIPS_PER_INCH;
/**
* 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
*/
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
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
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++)
{
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);
{
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;