You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by fa...@apache.org on 2022/07/29 08:10:51 UTC

svn commit: r1903096 - in /poi/trunk: poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFDiagram.java poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestXSLFDiagram.java test-data/slideshow/smartart-rotated-text.pptx

Author: fanningpj
Date: Fri Jul 29 08:10:51 2022
New Revision: 1903096

URL: http://svn.apache.org/viewvc?rev=1903096&view=rev
Log:
code to handle smart art rotations

Added:
    poi/trunk/test-data/slideshow/smartart-rotated-text.pptx   (with props)
Modified:
    poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFDiagram.java
    poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestXSLFDiagram.java

Modified: poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFDiagram.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFDiagram.java?rev=1903096&r1=1903095&r2=1903096&view=diff
==============================================================================
--- poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFDiagram.java (original)
+++ poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFDiagram.java Fri Jul 29 08:10:51 2022
@@ -172,7 +172,6 @@ public class XSLFDiagram extends XSLFGra
         // We can't easily (is it even possible?) set a separate xfrm for the text on the openxml CTShape.
         // Instead, we create a separate textbox shape with the same xfrm.
         org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties textShapeProps = textShapeCT.addNewSpPr();
-        textShapeProps.setXfrm(msShapeCt.getTxXfrm());
 
         textShapeCT.setTxBody(msShapeCt.getTxBody());
         textShapeCT.setStyle(msShapeCt.getStyle());
@@ -182,6 +181,16 @@ public class XSLFDiagram extends XSLFGra
         textShapeCT.setNvSpPr((CTShapeNonVisual) nonVisualCt.copy());
         textShapeCT.getNvSpPr().getCNvSpPr().setTxBox(true);
 
+        textShapeProps.setXfrm(msShapeCt.getTxXfrm());
+        int shapeRotation = msShapeCt.getSpPr().getXfrm().getRot();
+        int textRotation = msShapeCt.getTxXfrm().getRot();
+        if (textRotation != 0) {
+            // SmartArt diagrams (e.g. hexagon) have rotated shapes and the txXfrm can change the rotation for visual
+            // reasons. We perform that same calculation here again and calculate a new rotation for the text box.
+            int resolvedRotation = shapeRotation + textRotation;
+            textShapeProps.getXfrm().setRot(resolvedRotation);
+        }
+
         return textShapeCT;
     }
 

Modified: poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestXSLFDiagram.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestXSLFDiagram.java?rev=1903096&r1=1903095&r2=1903096&view=diff
==============================================================================
--- poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestXSLFDiagram.java (original)
+++ poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestXSLFDiagram.java Fri Jul 29 08:10:51 2022
@@ -35,6 +35,7 @@ import static org.junit.jupiter.api.Asse
 public class TestXSLFDiagram {
 
     private static final String SIMPLE_DIAGRAM = "smartart-simple.pptx";
+    private static final String ROTATED_TEXT_DIAGRAM = "smartart-rotated-text.pptx";
 
     private static List<XSLFDiagram> extractDiagrams(XMLSlideShow slideShow) {
         return slideShow.getSlides()
@@ -149,4 +150,30 @@ public class TestXSLFDiagram {
             assertEquals(ContentTypes.IMAGE_JPEG, texturePaint.getContentType());
         }
     }
+
+    @Test
+    public void testTextRotationOnShape() throws IOException {
+        try (XMLSlideShow inputPptx = XSLFTestDataSamples.openSampleDocument(ROTATED_TEXT_DIAGRAM)) {
+            List<XSLFDiagram> diagrams = extractDiagrams(inputPptx);
+            assertEquals(1, diagrams.size());
+
+            XSLFDiagram diagram = diagrams.get(0);
+            XSLFGroupShape groupShape = diagram.getGroupShape();
+
+            List<XSLFShape> shapes = groupShape.getShapes();
+
+            // Text shapes have separate rotation calculation
+            XSLFTextBox abcText = (XSLFTextBox) shapes.get(1);
+            assertEquals(-41.3187, abcText.getRotation(), 1E-4);
+
+            XSLFTextBox defText = (XSLFTextBox) shapes.get(5);
+            assertEquals(49.1812, defText.getRotation(), 1E-4);
+
+            XSLFTextBox ghiText = (XSLFTextBox) shapes.get(9);
+            assertEquals(0.0, ghiText.getRotation(), 1E-4);
+
+            XSLFTextBox jklText = (XSLFTextBox) shapes.get(11);
+            assertEquals(0.0, jklText.getRotation(), 1E-4);
+        }
+    }
 }

Added: poi/trunk/test-data/slideshow/smartart-rotated-text.pptx
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/slideshow/smartart-rotated-text.pptx?rev=1903096&view=auto
==============================================================================
Binary file - no diff available.

Propchange: poi/trunk/test-data/slideshow/smartart-rotated-text.pptx
------------------------------------------------------------------------------
--- svn:mime-type (added)
+++ svn:mime-type Fri Jul 29 08:10:51 2022
@@ -0,0 +1 @@
+application/vnd.openxmlformats-officedocument.presentationml.presentation



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org