From: Yegor Kozlov Date: Mon, 16 Jun 2008 18:38:59 +0000 (+0000) Subject: TextShape.getMarginLeft() returned incorrect value. Added a unit test for text margins. X-Git-Tag: REL_3_2_FINAL~285 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=0276e8cad18ab0f48d75ba881fd1951f7c89ce9d;p=poi.git TextShape.getMarginLeft() returned incorrect value. Added a unit test for text margins. git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@668257 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/TextShape.java b/src/scratchpad/src/org/apache/poi/hslf/model/TextShape.java index d1a84a5e44..44cb2b2412 100755 --- a/src/scratchpad/src/org/apache/poi/hslf/model/TextShape.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/TextShape.java @@ -355,7 +355,7 @@ public abstract class TextShape extends SimpleShape { */ public float getMarginLeft(){ EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID); - EscherSimpleProperty prop = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.TEXT__TEXTBOTTOM); + EscherSimpleProperty prop = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.TEXT__TEXTLEFT); int val = prop == null ? EMU_PER_INCH/10 : prop.getPropertyValue(); return (float)val/EMU_PER_POINT; } diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/data/text-margins.ppt b/src/scratchpad/testcases/org/apache/poi/hslf/data/text-margins.ppt new file mode 100755 index 0000000000..cf539aea74 Binary files /dev/null and b/src/scratchpad/testcases/org/apache/poi/hslf/data/text-margins.ppt differ diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTextShape.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTextShape.java index 25a8db9187..7fc8787567 100755 --- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTextShape.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTextShape.java @@ -23,6 +23,7 @@ import junit.framework.TestCase; import java.io.*; import java.util.ArrayList; +import java.util.HashMap; import org.apache.poi.hslf.usermodel.SlideShow; import org.apache.poi.hslf.record.TextHeaderAtom; @@ -157,4 +158,46 @@ public class TestTextShape extends TestCase { assertEquals("Testing TextShape", shape1.getTextRun().getText()); } + public void testMargins() throws IOException { + FileInputStream is = new FileInputStream(new File(cwd, "text-margins.ppt")); + SlideShow ppt = new SlideShow(is); + is.close(); + + Slide slide = ppt.getSlides()[0]; + + HashMap map = new HashMap(); + Shape[] shape = slide.getShapes(); + for (int i = 0; i < shape.length; i++) { + if(shape[i] instanceof TextShape){ + TextShape tx = (TextShape)shape[i]; + map.put(tx.getText(), tx); + } + } + + TextShape tx; + + tx = (TextShape)map.get("TEST1"); + assertEquals(0.1, tx.getMarginLeft()*Shape.EMU_PER_POINT/Shape.EMU_PER_INCH, 0.01); + assertEquals(0.1, tx.getMarginRight()*Shape.EMU_PER_POINT/Shape.EMU_PER_INCH, 0.01); + assertEquals(0.39, tx.getMarginTop()*Shape.EMU_PER_POINT/Shape.EMU_PER_INCH, 0.01); + assertEquals(0.05, tx.getMarginBottom()*Shape.EMU_PER_POINT/Shape.EMU_PER_INCH, 0.01); + + tx = (TextShape)map.get("TEST2"); + assertEquals(0.1, tx.getMarginLeft()*Shape.EMU_PER_POINT/Shape.EMU_PER_INCH, 0.01); + assertEquals(0.1, tx.getMarginRight()*Shape.EMU_PER_POINT/Shape.EMU_PER_INCH, 0.01); + assertEquals(0.05, tx.getMarginTop()*Shape.EMU_PER_POINT/Shape.EMU_PER_INCH, 0.01); + assertEquals(0.39, tx.getMarginBottom()*Shape.EMU_PER_POINT/Shape.EMU_PER_INCH, 0.01); + + tx = (TextShape)map.get("TEST3"); + assertEquals(0.39, tx.getMarginLeft()*Shape.EMU_PER_POINT/Shape.EMU_PER_INCH, 0.01); + assertEquals(0.1, tx.getMarginRight()*Shape.EMU_PER_POINT/Shape.EMU_PER_INCH, 0.01); + assertEquals(0.05, tx.getMarginTop()*Shape.EMU_PER_POINT/Shape.EMU_PER_INCH, 0.01); + assertEquals(0.05, tx.getMarginBottom()*Shape.EMU_PER_POINT/Shape.EMU_PER_INCH, 0.01); + + tx = (TextShape)map.get("TEST4"); + assertEquals(0.1, tx.getMarginLeft()*Shape.EMU_PER_POINT/Shape.EMU_PER_INCH, 0.01); + assertEquals(0.39, tx.getMarginRight()*Shape.EMU_PER_POINT/Shape.EMU_PER_INCH, 0.01); + assertEquals(0.05, tx.getMarginTop()*Shape.EMU_PER_POINT/Shape.EMU_PER_INCH, 0.01); + assertEquals(0.05, tx.getMarginBottom()*Shape.EMU_PER_POINT/Shape.EMU_PER_INCH, 0.01); + } }