From 56c7b61cc2a0b2accd4fe5038d4d282323f255ac Mon Sep 17 00:00:00 2001 From: Dominik Stadler Date: Wed, 22 Jul 2015 14:03:11 +0000 Subject: [PATCH] Still more checks to track down why canComputeColumnWidth() returns true, but width is still returned 0 on freebsd... git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1692278 13f79535-47bb-0310-9956-ffa450edef68 --- .../ss/usermodel/BaseTestBugzillaIssues.java | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java index a51e9f8fb..e94a4d025 100644 --- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java +++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java @@ -372,11 +372,14 @@ public abstract class BaseTestBugzillaIssues { double widthBeforeCell = SheetUtil.getCellWidth(cell0, 8, null, false); double widthBeforeCol = SheetUtil.getColumnWidth(sheet, 0, false); - assertTrue("Expected to have cell width > 0 when computing manually, but had " + widthManual + "/" + widthBeforeCell + "/" + widthBeforeCol, + assertTrue("Expected to have cell width > 0 when computing manually, but had " + widthManual + "/" + widthBeforeCell + "/" + widthBeforeCol + "/" + + SheetUtil.canComputeColumnWidht(font) + "/" + computeCellWidthFixed(cell0, font, "1") + "/" + computeCellWidthFixed(cell0, font, longValue), widthManual > 0); - assertTrue("Expected to have cell width > 0 BEFORE auto-size, but had " + widthManual + "/" + widthBeforeCell + "/" + widthBeforeCol, + assertTrue("Expected to have cell width > 0 BEFORE auto-size, but had " + widthManual + "/" + widthBeforeCell + "/" + widthBeforeCol + "/" + + SheetUtil.canComputeColumnWidht(font) + "/" + computeCellWidthFixed(cell0, font, "1") + "/" + computeCellWidthFixed(cell0, font, longValue), widthBeforeCell > 0); - assertTrue("Expected to have column width > 0 BEFORE auto-size, but had " + widthManual + "/" + widthBeforeCell + "/" + widthBeforeCol, + assertTrue("Expected to have column width > 0 BEFORE auto-size, but had " + widthManual + "/" + widthBeforeCell + "/" + widthBeforeCol + "/" + + SheetUtil.canComputeColumnWidht(font) + "/" + computeCellWidthFixed(cell0, font, "1") + "/" + computeCellWidthFixed(cell0, font, longValue), widthBeforeCol > 0); sheet.autoSizeColumn(0); @@ -391,7 +394,6 @@ public abstract class BaseTestBugzillaIssues { } private double computeCellWidthManually(Cell cell0, Font font) { - double width; final FontRenderContext fontRenderContext = new FontRenderContext(null, true, true); RichTextString rt = cell0.getRichStringCellValue(); String[] lines = rt.getString().split("\\n"); @@ -406,8 +408,16 @@ public abstract class BaseTestBugzillaIssues { } TextLayout layout = new TextLayout(str.getIterator(), fontRenderContext); - width = ((layout.getBounds().getWidth() / 1) / 8); - return width; + return ((layout.getBounds().getWidth() / 1) / 8); + } + + private double computeCellWidthFixed(Cell cell0, Font font, String txt) { + final FontRenderContext fontRenderContext = new FontRenderContext(null, true, true); + AttributedString str = new AttributedString(txt); + copyAttributes(font, str, 0, txt.length()); + + TextLayout layout = new TextLayout(str.getIterator(), fontRenderContext); + return ((layout.getBounds().getWidth() / 1) / 8); } private static void copyAttributes(Font font, AttributedString str, int startIdx, int endIdx) {