\r
package org.apache.poi.sl.usermodel;\r
\r
-import java.awt.Graphics2D;\r
import java.util.List;\r
\r
public interface TextShape<\r
* (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
* @return the text placeholder\r
*/\r
TextPlaceholder getTextPlaceholder();\r
-}\r
+}
\ No newline at end of file
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
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
\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
}\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
@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