]> source.dussan.org Git - poi.git/commitdiff
#59327 - Setting text direction on a table cell has no effect
authorAndreas Beeker <kiwiwings@apache.org>
Wed, 4 May 2016 22:09:10 +0000 (22:09 +0000)
committerAndreas Beeker <kiwiwings@apache.org>
Wed, 4 May 2016 22:09:10 +0000 (22:09 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1742338 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/sl/usermodel/TextShape.java
src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTableCell.java
src/ooxml/testcases/org/apache/poi/sl/TestTable.java
src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextShape.java

index a4a61824d30faa68faf652b774a50e663513d657..45bd63e0d985ea4aac0c42c63c5dc5c8e25657f3 100644 (file)
@@ -17,7 +17,6 @@
 \r
 package org.apache.poi.sl.usermodel;\r
 \r
-import java.awt.Graphics2D;\r
 import java.util.List;\r
 \r
 public interface TextShape<\r
@@ -44,11 +43,13 @@ public interface TextShape<
          * (each line is 270 degrees rotated clockwise, so it goes\r
          * from bottom to top; each next line is to the right from\r
          * the previous one).\r
+         * For HSLF: always interpreted by Powerpoint as HORIZONTAL.\r
          */\r
         VERTICAL_270,\r
         /**\r
          * Determines if all of the text is vertical\r
          * ("one letter on top of another").\r
+         * For HSLF: not supported\r
          */\r
         STACKED\r
     }\r
@@ -254,4 +255,4 @@ public interface TextShape<
      * @return the text placeholder\r
      */\r
     TextPlaceholder getTextPlaceholder();\r
-}\r
+}
\ No newline at end of file
index b5dcc8e0f5726909d802bf94aa911bd0a4e9bb4a..d4c3822fe54e41f9fd9c1322137bf64399ffd681 100644 (file)
@@ -45,6 +45,7 @@ import org.openxmlformats.schemas.drawingml.x2006.main.STLineEndWidth;
 import org.openxmlformats.schemas.drawingml.x2006.main.STPenAlignment;\r
 import org.openxmlformats.schemas.drawingml.x2006.main.STPresetLineDashVal;\r
 import org.openxmlformats.schemas.drawingml.x2006.main.STTextAnchoringType;\r
+import org.openxmlformats.schemas.drawingml.x2006.main.STTextVerticalType;\r
 \r
 /**\r
  * Represents a cell of a table in a .pptx presentation\r
@@ -429,4 +430,65 @@ public class XSLFTableCell extends XSLFTextShape implements TableCell<XSLFShape,
         return align;\r
      }\r
 \r
+    /**\r
+     * @since POI 3.15-beta2\r
+     */\r
+    @Override\r
+    public void setTextDirection(TextDirection orientation) {\r
+        CTTableCellProperties cellProps = getCellProperties(true);\r
+        if(orientation == null) {\r
+            if (cellProps.isSetVert()) {\r
+                cellProps.unsetVert();\r
+            }\r
+        } else {\r
+            STTextVerticalType.Enum vt;\r
+            switch (orientation) {\r
+            default:\r
+            case HORIZONTAL:\r
+                vt = STTextVerticalType.HORZ;\r
+                break;\r
+            case VERTICAL:\r
+                vt = STTextVerticalType.VERT;\r
+                break;\r
+            case VERTICAL_270:\r
+                vt = STTextVerticalType.VERT_270;\r
+                break;\r
+            case STACKED:\r
+                vt = STTextVerticalType.WORD_ART_VERT;\r
+                break;\r
+            }\r
+            \r
+            cellProps.setVert(vt);\r
+        }\r
+    }\r
+\r
+    /**\r
+     * @since POI 3.15-beta2\r
+     */\r
+    @Override\r
+    public TextDirection getTextDirection() {\r
+        CTTableCellProperties cellProps = getCellProperties(false);\r
+\r
+        STTextVerticalType.Enum orientation;\r
+        if (cellProps != null && cellProps.isSetVert()) {\r
+            orientation = cellProps.getVert();\r
+        } else {\r
+            orientation = STTextVerticalType.HORZ;\r
+        }\r
+                \r
+        switch (orientation.intValue()) {\r
+            default:\r
+            case STTextVerticalType.INT_HORZ:\r
+                return TextDirection.HORIZONTAL;\r
+            case STTextVerticalType.INT_VERT:\r
+            case STTextVerticalType.INT_EA_VERT:\r
+            case STTextVerticalType.INT_MONGOLIAN_VERT:\r
+                return TextDirection.VERTICAL;\r
+            case STTextVerticalType.INT_VERT_270:\r
+                return TextDirection.VERTICAL_270;\r
+            case STTextVerticalType.INT_WORD_ART_VERT:\r
+            case STTextVerticalType.INT_WORD_ART_VERT_RTL:\r
+                return TextDirection.STACKED;\r
+        }\r
+    }\r
 }\r
index 2d123cb56aa0079f42be7076781b35c6c604ebdf..1dec172dea1a1a844046e5418b1cd9806e659ee1 100644 (file)
@@ -21,14 +21,19 @@ package org.apache.poi.sl;
 \r
 import static org.junit.Assert.assertEquals;\r
 \r
+import java.awt.geom.Rectangle2D;\r
+import java.io.ByteArrayInputStream;\r
+import java.io.ByteArrayOutputStream;\r
 import java.io.IOException;\r
 import java.io.InputStream;\r
 \r
 import org.apache.poi.POIDataSamples;\r
+import org.apache.poi.hslf.usermodel.HSLFSlideShow;\r
 import org.apache.poi.sl.usermodel.SlideShow;\r
 import org.apache.poi.sl.usermodel.SlideShowFactory;\r
+import org.apache.poi.sl.usermodel.TableCell;\r
 import org.apache.poi.sl.usermodel.TableShape;\r
-import org.apache.poi.xslf.XSLFTestDataSamples;\r
+import org.apache.poi.sl.usermodel.TextShape.TextDirection;\r
 import org.apache.poi.xslf.usermodel.XMLSlideShow;\r
 import org.junit.Test;\r
 \r
@@ -89,4 +94,42 @@ public class TestTable {
         }\r
     }\r
 \r
+    @Test\r
+    public void testTextDirection() throws IOException {\r
+        \r
+        TextDirection tds[] = {\r
+            TextDirection.HORIZONTAL,\r
+            TextDirection.VERTICAL,\r
+            TextDirection.VERTICAL_270,\r
+            // TextDirection.STACKED is not supported on HSLF\r
+        };\r
+        \r
+        for (int i=0; i<2; i++) {\r
+            SlideShow<?,?> ppt1 = (i == 0) ? new HSLFSlideShow() : new XMLSlideShow();\r
+            TableShape<?,?> tbl1 = ppt1.createSlide().createTable(1, 3);\r
+            tbl1.setAnchor(new Rectangle2D.Double(50, 50, 200, 200));\r
+        \r
+            int col = 0;\r
+            for (TextDirection td : tds) {\r
+                TableCell<?,?> c = tbl1.getCell(0, col++);\r
+                c.setTextDirection(td);\r
+                c.setText("bla");\r
+            }\r
+            \r
+            ByteArrayOutputStream bos = new ByteArrayOutputStream();\r
+            ppt1.write(bos);\r
+            ppt1.close();\r
+            \r
+            InputStream is = new ByteArrayInputStream(bos.toByteArray());\r
+            SlideShow<?,?> ppt2 = SlideShowFactory.create(is);\r
+            TableShape<?,?> tbl2 = (TableShape<?,?>)ppt2.getSlides().get(0).getShapes().get(0);\r
+            \r
+            col = 0;\r
+            for (TextDirection td : tds) {\r
+                TableCell<?,?> c = tbl2.getCell(0, col++);\r
+                assertEquals(td, c.getTextDirection());\r
+            }\r
+            ppt2.close();\r
+        }\r
+    }\r
 }\r
index 4f78bd6c8fa41ec8f4c60fe457c96adde14bfe00..b26b3dfa2421adeb7e77f4e910533ad0d01d4383 100644 (file)
@@ -660,15 +660,51 @@ implements TextShape<HSLFShape,HSLFTextParagraph> {
 
     @Override
     public TextDirection getTextDirection() {
-        // TODO: determine vertical text setting
-        // see 2.3.22.10 Geometry Text Boolean Properties
-        return TextDirection.HORIZONTAL;
+        // see 2.4.5 MSOTXFL
+        AbstractEscherOptRecord opt = getEscherOptRecord();
+        EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.TEXT__TEXTFLOW);
+        int msotxfl = (prop == null) ? 0 : prop.getPropertyValue();
+        switch (msotxfl) {
+            default:
+            case 0: // msotxflHorzN
+            case 4: // msotxflHorzA
+                return TextDirection.HORIZONTAL;
+            case 1: // msotxflTtoBA
+            case 3: // msotxflTtoBN
+            case 5: // msotxflVertN
+                return TextDirection.VERTICAL;
+            case 2: // msotxflBtoT
+                return TextDirection.VERTICAL_270;
+            // TextDirection.STACKED is not supported
+        }
     }
 
     @Override
     public void setTextDirection(TextDirection orientation) {
-        // TODO: determine vertical text setting
-        // see 2.3.22.10 Geometry Text Boolean Properties / gtextFVertical [MS-ODRAW]
+        AbstractEscherOptRecord opt = getEscherOptRecord();
+        int msotxfl;
+        if (orientation == null) {
+            msotxfl = -1;
+        } else {
+            switch (orientation) {
+                default:
+                case STACKED:
+                    // not supported -> remove
+                    msotxfl = -1;
+                    break;
+                case HORIZONTAL:
+                    msotxfl = 0;
+                    break;
+                case VERTICAL:
+                    msotxfl = 1;
+                    break;
+                case VERTICAL_270:
+                    // always interpreted as horizontal
+                    msotxfl = 2;
+                    break;
+            }
+        }
+        setEscherProperty(opt, EscherProperties.TEXT__TEXTFLOW, msotxfl);
     }
     
     @Override