git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1903096 13f79535-47bb-0310-9956-ffa450edef68tags/REL_5_2_3
// We can't easily (is it even possible?) set a separate xfrm for the text on the openxml CTShape. | // 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. | // Instead, we create a separate textbox shape with the same xfrm. | ||||
org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties textShapeProps = textShapeCT.addNewSpPr(); | org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties textShapeProps = textShapeCT.addNewSpPr(); | ||||
textShapeProps.setXfrm(msShapeCt.getTxXfrm()); | |||||
textShapeCT.setTxBody(msShapeCt.getTxBody()); | textShapeCT.setTxBody(msShapeCt.getTxBody()); | ||||
textShapeCT.setStyle(msShapeCt.getStyle()); | textShapeCT.setStyle(msShapeCt.getStyle()); | ||||
textShapeCT.setNvSpPr((CTShapeNonVisual) nonVisualCt.copy()); | textShapeCT.setNvSpPr((CTShapeNonVisual) nonVisualCt.copy()); | ||||
textShapeCT.getNvSpPr().getCNvSpPr().setTxBox(true); | 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; | return textShapeCT; | ||||
} | } | ||||
public class TestXSLFDiagram { | public class TestXSLFDiagram { | ||||
private static final String SIMPLE_DIAGRAM = "smartart-simple.pptx"; | 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) { | private static List<XSLFDiagram> extractDiagrams(XMLSlideShow slideShow) { | ||||
return slideShow.getSlides() | return slideShow.getSlides() | ||||
assertEquals(ContentTypes.IMAGE_JPEG, texturePaint.getContentType()); | 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); | |||||
} | |||||
} | |||||
} | } |