diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/AutoSizeColumnTracker.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/AutoSizeColumnTracker.java index 9df140d4144..88020e3448c 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/AutoSizeColumnTracker.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/AutoSizeColumnTracker.java @@ -47,7 +47,7 @@ Licensed to the Apache Software Foundation (ASF) under one or more */ @Internal /*package*/ class AutoSizeColumnTracker { - private final int defaultCharWidth; + private final double defaultCharWidth; private final DataFormatter dataFormatter = new DataFormatter(); // map of tracked columns, with values containing the best-fit width for the column diff --git a/poi/src/main/java/org/apache/poi/ss/util/SheetUtil.java b/poi/src/main/java/org/apache/poi/ss/util/SheetUtil.java index 2ced5742b70..b621adbaf02 100644 --- a/poi/src/main/java/org/apache/poi/ss/util/SheetUtil.java +++ b/poi/src/main/java/org/apache/poi/ss/util/SheetUtil.java @@ -118,7 +118,7 @@ public void evaluateAll() {} * @param useMergedCells whether to use merged cells * @return the width in pixels or -1 if cell is empty */ - public static double getCellWidth(Cell cell, int defaultCharWidth, DataFormatter formatter, boolean useMergedCells) { + public static double getCellWidth(Cell cell, double defaultCharWidth, DataFormatter formatter, boolean useMergedCells) { List mergedRegions = cell.getSheet().getMergedRegions(); return getCellWidth(cell, defaultCharWidth, formatter, useMergedCells, mergedRegions); } @@ -137,7 +137,7 @@ public static double getCellWidth(Cell cell, int defaultCharWidth, DataFormatter * @param mergedRegions The list of merged regions as received via cell.getSheet().getMergedRegions() * @return the width in pixels or -1 if cell is empty */ - public static double getCellWidth(Cell cell, int defaultCharWidth, DataFormatter formatter, boolean useMergedCells, + public static double getCellWidth(Cell cell, double defaultCharWidth, DataFormatter formatter, boolean useMergedCells, List mergedRegions) { Sheet sheet = cell.getSheet(); Workbook wb = sheet.getWorkbook(); @@ -219,7 +219,7 @@ public static double getCellWidth(Cell cell, int defaultCharWidth, DataFormatter * @param str the text contained in the cell * @return the best fit cell width */ - private static double getCellWidth(int defaultCharWidth, int colspan, + private static double getCellWidth(double defaultCharWidth, int colspan, CellStyle style, double minWidth, AttributedString str) { TextLayout layout = new TextLayout(str.getIterator(), fontRenderContext); final Rectangle2D bounds; @@ -270,7 +270,7 @@ public static double getColumnWidth(Sheet sheet, int column, boolean useMergedCe */ public static double getColumnWidth(Sheet sheet, int column, boolean useMergedCells, int firstRow, int lastRow){ DataFormatter formatter = new DataFormatter(); - int defaultCharWidth = getDefaultCharWidth(sheet.getWorkbook()); + double defaultCharWidth = getDefaultCharWidth(sheet.getWorkbook()); List mergedRegions = sheet.getMergedRegions(); double width = -1; @@ -292,14 +292,14 @@ public static double getColumnWidth(Sheet sheet, int column, boolean useMergedCe * @return default character width in pixels */ @Internal - public static int getDefaultCharWidth(final Workbook wb) { + public static double getDefaultCharWidth(final Workbook wb) { Font defaultFont = wb.getFontAt( 0); AttributedString str = new AttributedString(String.valueOf(defaultChar)); copyAttributes(defaultFont, str, 0, 1); try { TextLayout layout = new TextLayout(str.getIterator(), fontRenderContext); - return Math.round(layout.getAdvance()); + return layout.getAdvance(); } catch (UnsatisfiedLinkError | NoClassDefFoundError | InternalError e) { if (ignoreMissingFontSystem) { return DEFAULT_CHAR_WIDTH; @@ -321,7 +321,7 @@ public static int getDefaultCharWidth(final Workbook wb) { * @return the width in pixels or -1 if cell is empty */ private static double getColumnWidthForRow( - Row row, int column, int defaultCharWidth, DataFormatter formatter, boolean useMergedCells, + Row row, int column, double defaultCharWidth, DataFormatter formatter, boolean useMergedCells, List mergedRegions) { if( row == null ) { return -1;