From e89b0c26cb828449a85bfb72e61f040fd5280799 Mon Sep 17 00:00:00 2001 From: Javen O'Neal Date: Sat, 28 Nov 2015 11:53:22 +0000 Subject: [PATCH] javadocs git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1716947 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/poi/ss/util/SheetUtil.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/java/org/apache/poi/ss/util/SheetUtil.java b/src/java/org/apache/poi/ss/util/SheetUtil.java index 5ca5b39694..663cc02d2c 100644 --- a/src/java/org/apache/poi/ss/util/SheetUtil.java +++ b/src/java/org/apache/poi/ss/util/SheetUtil.java @@ -164,8 +164,19 @@ public class SheetUtil { return width; } + /** + * Calculate the best-fit width for a cell + * If a merged cell spans multiple columns, evenly distribute the column width among those columns + * + * @param defaultCharWidth the width of a character using the default font in a workbook + * @param colspan the number of columns that is spanned by the cell (1 if the cell is not part of a merged region) + * @param style the cell style, which contains text rotation and indention information needed to compute the cell width + * @param width the minimum best-fit width. This algorithm will only return values greater than or equal to the minimum width. + * @param str the text contained in the cell + * @return + */ private static double getCellWidth(int defaultCharWidth, int colspan, - CellStyle style, double width, AttributedString str) { + CellStyle style, double minWidth, AttributedString str) { TextLayout layout = new TextLayout(str.getIterator(), fontRenderContext); final Rectangle2D bounds; if(style.getRotation() != 0){ @@ -184,9 +195,9 @@ public class SheetUtil { } else { bounds = layout.getBounds(); } - // entireWidth accounts for leading spaces which is excluded from bounds.getWidth() + // frameWidth accounts for leading spaces which is excluded from bounds.getWidth() final double frameWidth = bounds.getX() + bounds.getWidth(); - width = Math.max(width, ((frameWidth / colspan) / defaultCharWidth) + style.getIndention()); + final double width = Math.max(minWidth, ((frameWidth / colspan) / defaultCharWidth) + style.getIndention()); return width; } -- 2.39.5