/* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ package org.apache.poi.xslf.usermodel; import com.microsoft.schemas.office.drawing.x2008.diagram.CTGroupShape; import com.microsoft.schemas.office.drawing.x2008.diagram.CTShape; import org.apache.poi.ooxml.POIXMLDocumentPart; import org.apache.poi.util.Beta; import org.apache.xmlbeans.XmlObject; import org.openxmlformats.schemas.drawingml.x2006.diagram.CTRelIds; import org.openxmlformats.schemas.drawingml.x2006.main.CTGraphicalObjectData; import org.openxmlformats.schemas.drawingml.x2006.main.CTGroupShapeProperties; import org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraph; import org.openxmlformats.schemas.presentationml.x2006.main.CTApplicationNonVisualDrawingProps; import org.openxmlformats.schemas.presentationml.x2006.main.CTGraphicalObjectFrame; import org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShapeNonVisual; import org.openxmlformats.schemas.presentationml.x2006.main.CTShapeNonVisual; import javax.xml.namespace.QName; import java.awt.geom.Rectangle2D; import java.util.ArrayList; import java.util.List; /** * Representation of a DrawingML Diagram *
* This class converts the diagram to an {@link XSLFGroupShape} accessible via {@link #getGroupShape()}. The underlying * {@link XSLFDiagramDrawing} used to create the group shape is accessible via {@link #getDiagramDrawing()}. *
* In pptx files, these diagrams are generated by creating SmartArt. When a pptx has SmartArt, a directory with the * following structure is created: * *
* ppt/ * diagrams/ * data#.xml * drawing#.xml^ * colors#.xml * quickStyle#.xml * layout#.xml * rels/ * data#.xml.rels * drawing#.xml.rels **
* ^The `drawing#.xml` file is not in the OpenXML spec. It was added as an extension by Microsoft, namespace: * http://schemas.microsoft.com/office/drawing/2008/diagram *
* The drawing#.xml file contains the rendered output of the diagram. This class reads the underlying drawing#.xml and * converts it to a {@link XSLFGroupShape}. *
* The data, drawing, colors, and quickStyle files are in the OpenXML spec. These contain the instructions that define
* how to render the diagram. Rendering diagrams from these files is not trivial, they support for loops, if/elses, etc.
* Integrating such a change into POI would be quite sophisticated and challenging.
*
* @since POI 5.2.3
*/
@Beta
public class XSLFDiagram extends XSLFGraphicFrame {
public static final String DRAWINGML_DIAGRAM_URI = "http://schemas.openxmlformats.org/drawingml/2006/diagram";
private final XSLFDiagramDrawing _drawing;
private final XSLFDiagramGroupShape _groupShape;
/* package protected */ XSLFDiagram(CTGraphicalObjectFrame shape, XSLFSheet sheet) {
super(shape, sheet);
_drawing = readDiagramDrawing(shape, sheet);
_groupShape = initGroupShape();
}
private static boolean hasTextContent(CTShape msShapeCt) {
if (msShapeCt.getTxBody() == null || msShapeCt.getTxXfrm() == null) {
return false;
}
// A shape has text content when there is at least 1 paragraph with 1 paragraph run list
List
* NOTE: Modifying this drawing will not update the groupShape returned from {@link #getGroupShape()}.
*/
public XSLFDiagramDrawing getDiagramDrawing() {
return _drawing;
}
/**
* Returns the diagram represented as a grouped shape.
*/
public XSLFDiagramGroupShape getGroupShape() {
return _groupShape;
}
// If the shape has text, two XSLFShapes are created. One shape element and one textbox element.
private List
* Diagrams store relationships to media in `drawing#.xml.rels`. These relationships are accessible using
* {@link #getRelationById(String)}.
*/
public static class XSLFDiagramGroupShape extends XSLFGroupShape {
private XSLFDiagramDrawing diagramDrawing;
protected XSLFDiagramGroupShape(org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShape shape,
XSLFSheet sheet) {
super(shape, sheet);
}
private XSLFDiagramGroupShape(org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShape shape,
XSLFSheet sheet,
XSLFDiagramDrawing diagramDrawing) {
super(shape, sheet);
this.diagramDrawing = diagramDrawing;
}
public POIXMLDocumentPart getRelationById(String id) {
return diagramDrawing.getRelationById(id);
}
}
}