From: Andreas Beeker Date: Wed, 4 May 2016 22:09:10 +0000 (+0000) Subject: #59327 - Setting text direction on a table cell has no effect X-Git-Tag: REL_3_15_BETA2~276 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=4a4e60d1346926c079259652d38267c42267e8d1;p=poi.git #59327 - Setting text direction on a table cell has no effect git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1742338 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/poi/sl/usermodel/TextShape.java b/src/java/org/apache/poi/sl/usermodel/TextShape.java index a4a61824d3..45bd63e0d9 100644 --- a/src/java/org/apache/poi/sl/usermodel/TextShape.java +++ b/src/java/org/apache/poi/sl/usermodel/TextShape.java @@ -17,7 +17,6 @@ package org.apache.poi.sl.usermodel; -import java.awt.Graphics2D; import java.util.List; public interface TextShape< @@ -44,11 +43,13 @@ public interface TextShape< * (each line is 270 degrees rotated clockwise, so it goes * from bottom to top; each next line is to the right from * the previous one). + * For HSLF: always interpreted by Powerpoint as HORIZONTAL. */ VERTICAL_270, /** * Determines if all of the text is vertical * ("one letter on top of another"). + * For HSLF: not supported */ STACKED } @@ -254,4 +255,4 @@ public interface TextShape< * @return the text placeholder */ TextPlaceholder getTextPlaceholder(); -} +} \ No newline at end of file diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTableCell.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTableCell.java index b5dcc8e0f5..d4c3822fe5 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTableCell.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTableCell.java @@ -45,6 +45,7 @@ import org.openxmlformats.schemas.drawingml.x2006.main.STLineEndWidth; import org.openxmlformats.schemas.drawingml.x2006.main.STPenAlignment; import org.openxmlformats.schemas.drawingml.x2006.main.STPresetLineDashVal; import org.openxmlformats.schemas.drawingml.x2006.main.STTextAnchoringType; +import org.openxmlformats.schemas.drawingml.x2006.main.STTextVerticalType; /** * Represents a cell of a table in a .pptx presentation @@ -429,4 +430,65 @@ public class XSLFTableCell extends XSLFTextShape implements TableCell ppt1 = (i == 0) ? new HSLFSlideShow() : new XMLSlideShow(); + TableShape tbl1 = ppt1.createSlide().createTable(1, 3); + tbl1.setAnchor(new Rectangle2D.Double(50, 50, 200, 200)); + + int col = 0; + for (TextDirection td : tds) { + TableCell c = tbl1.getCell(0, col++); + c.setTextDirection(td); + c.setText("bla"); + } + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + ppt1.write(bos); + ppt1.close(); + + InputStream is = new ByteArrayInputStream(bos.toByteArray()); + SlideShow ppt2 = SlideShowFactory.create(is); + TableShape tbl2 = (TableShape)ppt2.getSlides().get(0).getShapes().get(0); + + col = 0; + for (TextDirection td : tds) { + TableCell c = tbl2.getCell(0, col++); + assertEquals(td, c.getTextDirection()); + } + ppt2.close(); + } + } } diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextShape.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextShape.java index 4f78bd6c8f..b26b3dfa24 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextShape.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextShape.java @@ -660,15 +660,51 @@ implements TextShape { @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