From 4f3bb9841efa1f568400c9f2be7cf3de0680d5e2 Mon Sep 17 00:00:00 2001 From: Yegor Kozlov Date: Fri, 19 Jun 2009 16:49:39 +0000 Subject: [PATCH] fixed SimpleShape#getLineWidth to handle default line width, see Bugzilla #46392 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@786577 13f79535-47bb-0310-9956-ffa450edef68 --- src/documentation/content/xdocs/status.xml | 1 + .../org/apache/poi/hslf/model/ShapePainter.java | 1 - .../org/apache/poi/hslf/model/SimpleShape.java | 5 ++++- .../org/apache/poi/hslf/model/TestShapes.java | 17 +++++++++++++++-- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index c4762c7537..2357a17095 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -33,6 +33,7 @@ + 46793 - fixed SimpleShape#getLineWidth to handle default line width 47356 - removed unused private fields in HWPF BorderCode 47355 - Improved HWPF TableCell to expose TableCellDescriptor 46610 - Improved HWPF to better handle unicode diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/ShapePainter.java b/src/scratchpad/src/org/apache/poi/hslf/model/ShapePainter.java index 15a727af71..09474a0b8c 100755 --- a/src/scratchpad/src/org/apache/poi/hslf/model/ShapePainter.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/ShapePainter.java @@ -74,7 +74,6 @@ public final class ShapePainter { if (lineColor != null){ graphics.setPaint(lineColor); float width = (float)shape.getLineWidth(); - if(width == 0) width = 0.75f; int dashing = shape.getLineDashing(); //TODO: implement more dashing styles diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/SimpleShape.java b/src/scratchpad/src/org/apache/poi/hslf/model/SimpleShape.java index 13a2835b22..ee2d8f98e5 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/SimpleShape.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/SimpleShape.java @@ -40,6 +40,8 @@ import org.apache.poi.util.LittleEndian; */ public abstract class SimpleShape extends Shape { + public final static double DEFAULT_LINE_WIDTH = 0.75; + /** * Records stored in EscherClientDataRecord */ @@ -101,7 +103,8 @@ public abstract class SimpleShape extends Shape { public double getLineWidth(){ EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID); EscherSimpleProperty prop = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.LINESTYLE__LINEWIDTH); - return prop == null ? 0 : (double)prop.getPropertyValue()/EMU_PER_POINT; + double width = prop == null ? DEFAULT_LINE_WIDTH : (double)prop.getPropertyValue()/EMU_PER_POINT; + return width; } /** diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java index 77e2efa08a..565445f7b4 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java @@ -21,8 +21,7 @@ import junit.framework.TestCase; import org.apache.poi.hslf.usermodel.SlideShow; import org.apache.poi.hslf.usermodel.RichTextRun; import org.apache.poi.hslf.HSLFSlideShow; -import org.apache.poi.ddf.EscherDggRecord; -import org.apache.poi.ddf.EscherDgRecord; +import org.apache.poi.ddf.*; import java.awt.*; import java.awt.Rectangle; @@ -311,6 +310,20 @@ public final class TestShapes extends TestCase { assertEquals("expected 0 shaped in " + file, 0, sl.getShapes().length); } + public void testLineWidth() throws IOException { + SimpleShape sh = new AutoShape(ShapeTypes.RightTriangle); + + EscherOptRecord opt = (EscherOptRecord)SimpleShape.getEscherChild(sh.getSpContainer(), EscherOptRecord.RECORD_ID); + EscherSimpleProperty prop = (EscherSimpleProperty)SimpleShape.getEscherProperty(opt, EscherProperties.LINESTYLE__LINEWIDTH); + assertNull(prop); + assertEquals(SimpleShape.DEFAULT_LINE_WIDTH, sh.getLineWidth()); + + sh.setLineWidth(1.0); + prop = (EscherSimpleProperty)SimpleShape.getEscherProperty(opt, EscherProperties.LINESTYLE__LINEWIDTH); + assertNotNull(prop); + assertEquals(1.0, sh.getLineWidth()); + } + public void testShapeId() throws IOException { SlideShow ppt = new SlideShow(); Slide slide = ppt.createSlide(); -- 2.39.5