]> source.dussan.org Git - poi.git/commitdiff
TextShape.getMarginLeft() returned incorrect value. Added a unit test for text margins.
authorYegor Kozlov <yegor@apache.org>
Mon, 16 Jun 2008 18:38:59 +0000 (18:38 +0000)
committerYegor Kozlov <yegor@apache.org>
Mon, 16 Jun 2008 18:38:59 +0000 (18:38 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@668257 13f79535-47bb-0310-9956-ffa450edef68

src/scratchpad/src/org/apache/poi/hslf/model/TextShape.java
src/scratchpad/testcases/org/apache/poi/hslf/data/text-margins.ppt [new file with mode: 0755]
src/scratchpad/testcases/org/apache/poi/hslf/model/TestTextShape.java

index d1a84a5e44416f130975697e268d71ddc5c2d8bd..44cb2b2412124828b8618e19bf732606cc3fef8c 100755 (executable)
@@ -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 (executable)
index 0000000..cf539ae
Binary files /dev/null and b/src/scratchpad/testcases/org/apache/poi/hslf/data/text-margins.ppt differ
index 25a8db918713d495b1fd1c50f204b61399ba63ea..7fc878756741ae720e8086962eaf050917a16108 100755 (executable)
@@ -23,6 +23,7 @@ import junit.framework.TestCase;
 \r
 import java.io.*;\r
 import java.util.ArrayList;\r
+import java.util.HashMap;\r
 \r
 import org.apache.poi.hslf.usermodel.SlideShow;\r
 import org.apache.poi.hslf.record.TextHeaderAtom;\r
@@ -157,4 +158,46 @@ public class TestTextShape extends TestCase {
         assertEquals("Testing TextShape", shape1.getTextRun().getText());\r
     }\r
 \r
+    public void testMargins() throws IOException {\r
+        FileInputStream is = new FileInputStream(new File(cwd, "text-margins.ppt"));\r
+        SlideShow ppt = new SlideShow(is);\r
+        is.close();\r
+\r
+        Slide slide = ppt.getSlides()[0];\r
+\r
+        HashMap map = new HashMap();\r
+        Shape[] shape = slide.getShapes();\r
+        for (int i = 0; i < shape.length; i++) {\r
+            if(shape[i] instanceof TextShape){\r
+                TextShape tx = (TextShape)shape[i];\r
+                map.put(tx.getText(), tx);\r
+            }\r
+        }\r
+\r
+        TextShape tx;\r
+\r
+        tx = (TextShape)map.get("TEST1");\r
+        assertEquals(0.1, tx.getMarginLeft()*Shape.EMU_PER_POINT/Shape.EMU_PER_INCH, 0.01);\r
+        assertEquals(0.1, tx.getMarginRight()*Shape.EMU_PER_POINT/Shape.EMU_PER_INCH, 0.01);\r
+        assertEquals(0.39, tx.getMarginTop()*Shape.EMU_PER_POINT/Shape.EMU_PER_INCH, 0.01);\r
+        assertEquals(0.05, tx.getMarginBottom()*Shape.EMU_PER_POINT/Shape.EMU_PER_INCH, 0.01);\r
+\r
+        tx = (TextShape)map.get("TEST2");\r
+        assertEquals(0.1, tx.getMarginLeft()*Shape.EMU_PER_POINT/Shape.EMU_PER_INCH, 0.01);\r
+        assertEquals(0.1, tx.getMarginRight()*Shape.EMU_PER_POINT/Shape.EMU_PER_INCH, 0.01);\r
+        assertEquals(0.05, tx.getMarginTop()*Shape.EMU_PER_POINT/Shape.EMU_PER_INCH, 0.01);\r
+        assertEquals(0.39, tx.getMarginBottom()*Shape.EMU_PER_POINT/Shape.EMU_PER_INCH, 0.01);\r
+\r
+        tx = (TextShape)map.get("TEST3");\r
+        assertEquals(0.39, tx.getMarginLeft()*Shape.EMU_PER_POINT/Shape.EMU_PER_INCH, 0.01);\r
+        assertEquals(0.1, tx.getMarginRight()*Shape.EMU_PER_POINT/Shape.EMU_PER_INCH, 0.01);\r
+        assertEquals(0.05, tx.getMarginTop()*Shape.EMU_PER_POINT/Shape.EMU_PER_INCH, 0.01);\r
+        assertEquals(0.05, tx.getMarginBottom()*Shape.EMU_PER_POINT/Shape.EMU_PER_INCH, 0.01);\r
+\r
+        tx = (TextShape)map.get("TEST4");\r
+        assertEquals(0.1, tx.getMarginLeft()*Shape.EMU_PER_POINT/Shape.EMU_PER_INCH, 0.01);\r
+        assertEquals(0.39, tx.getMarginRight()*Shape.EMU_PER_POINT/Shape.EMU_PER_INCH, 0.01);\r
+        assertEquals(0.05, tx.getMarginTop()*Shape.EMU_PER_POINT/Shape.EMU_PER_INCH, 0.01);\r
+        assertEquals(0.05, tx.getMarginBottom()*Shape.EMU_PER_POINT/Shape.EMU_PER_INCH, 0.01);\r
+    }\r
 }\r