Search in sources :

Example 6 with CTGroupTransform2D

use of org.openxmlformats.schemas.drawingml.x2006.main.CTGroupTransform2D in project poi by apache.

the class XSSFShapeGroup method setCoordinates.

/**
     * Sets the coordinate space of this group.  All children are constrained
     * to these coordinates.
     */
public void setCoordinates(int x1, int y1, int x2, int y2) {
    CTGroupTransform2D t2d = ctGroup.getGrpSpPr().getXfrm();
    CTPoint2D off = t2d.getOff();
    off.setX(x1);
    off.setY(y1);
    CTPositiveSize2D ext = t2d.getExt();
    ext.setCx(x2);
    ext.setCy(y2);
    CTPoint2D chOff = t2d.getChOff();
    chOff.setX(x1);
    chOff.setY(y1);
    CTPositiveSize2D chExt = t2d.getChExt();
    chExt.setCx(x2);
    chExt.setCy(y2);
}
Also used : CTPoint2D(org.openxmlformats.schemas.drawingml.x2006.main.CTPoint2D) CTGroupTransform2D(org.openxmlformats.schemas.drawingml.x2006.main.CTGroupTransform2D) CTPositiveSize2D(org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D)

Example 7 with CTGroupTransform2D

use of org.openxmlformats.schemas.drawingml.x2006.main.CTGroupTransform2D in project poi by apache.

the class TestXSSFDrawing method testGroupShape.

@Test
public void testGroupShape() throws Exception {
    XSSFWorkbook wb1 = new XSSFWorkbook();
    XSSFSheet sheet = wb1.createSheet();
    XSSFDrawing drawing = sheet.createDrawingPatriarch();
    XSSFSimpleShape s0 = drawing.createSimpleShape(drawing.createAnchor(0, 0, Units.pixelToEMU(30), Units.pixelToEMU(30), 1, 1, 10, 10));
    s0.setShapeType(ShapeTypes.RECT);
    s0.setLineStyleColor(100, 0, 0);
    XSSFShapeGroup g1 = drawing.createGroup(drawing.createAnchor(0, 0, 300, 300, 1, 1, 10, 10));
    CTGroupTransform2D xfrmG1 = g1.getCTGroupShape().getGrpSpPr().getXfrm();
    XSSFSimpleShape s1 = g1.createSimpleShape(new XSSFChildAnchor((int) (xfrmG1.getChExt().getCx() * 0.1), (int) (xfrmG1.getChExt().getCy() * 0.1), (int) (xfrmG1.getChExt().getCx() * 0.9), (int) (xfrmG1.getChExt().getCy() * 0.9)));
    s1.setShapeType(ShapeTypes.RECT);
    s1.setLineStyleColor(0, 100, 0);
    XSSFShapeGroup g2 = g1.createGroup(new XSSFChildAnchor((int) (xfrmG1.getChExt().getCx() * 0.2), (int) (xfrmG1.getChExt().getCy() * 0.2), (int) (xfrmG1.getChExt().getCx() * 0.8), (int) (xfrmG1.getChExt().getCy() * 0.8)));
    CTGroupTransform2D xfrmG2 = g2.getCTGroupShape().getGrpSpPr().getXfrm();
    XSSFSimpleShape s2 = g2.createSimpleShape(new XSSFChildAnchor((int) (xfrmG2.getChExt().getCx() * 0.1), (int) (xfrmG2.getChExt().getCy() * 0.1), (int) (xfrmG2.getChExt().getCx() * 0.9), (int) (xfrmG2.getChExt().getCy() * 0.9)));
    s2.setShapeType(ShapeTypes.RECT);
    s2.setLineStyleColor(0, 0, 100);
    XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(wb1);
    wb1.close();
    XSSFDrawing draw = wb2.getSheetAt(0).getDrawingPatriarch();
    List<XSSFShape> shapes = draw.getShapes();
    assertEquals(2, shapes.size());
    assertTrue(shapes.get(0) instanceof XSSFSimpleShape);
    assertTrue(shapes.get(1) instanceof XSSFShapeGroup);
    shapes = draw.getShapes((XSSFShapeGroup) shapes.get(1));
    assertEquals(2, shapes.size());
    assertTrue(shapes.get(0) instanceof XSSFSimpleShape);
    assertTrue(shapes.get(1) instanceof XSSFShapeGroup);
    shapes = draw.getShapes((XSSFShapeGroup) shapes.get(1));
    assertEquals(1, shapes.size());
    assertTrue(shapes.get(0) instanceof XSSFSimpleShape);
    wb2.close();
}
Also used : CTGroupTransform2D(org.openxmlformats.schemas.drawingml.x2006.main.CTGroupTransform2D) Test(org.junit.Test)

Example 8 with CTGroupTransform2D

use of org.openxmlformats.schemas.drawingml.x2006.main.CTGroupTransform2D in project poi by apache.

the class XSLFSlide method prototype.

private static CTSlide prototype() {
    CTSlide ctSlide = CTSlide.Factory.newInstance();
    CTCommonSlideData cSld = ctSlide.addNewCSld();
    CTGroupShape spTree = cSld.addNewSpTree();
    CTGroupShapeNonVisual nvGrpSpPr = spTree.addNewNvGrpSpPr();
    CTNonVisualDrawingProps cnvPr = nvGrpSpPr.addNewCNvPr();
    cnvPr.setId(1);
    cnvPr.setName("");
    nvGrpSpPr.addNewCNvGrpSpPr();
    nvGrpSpPr.addNewNvPr();
    CTGroupShapeProperties grpSpr = spTree.addNewGrpSpPr();
    CTGroupTransform2D xfrm = grpSpr.addNewXfrm();
    CTPoint2D off = xfrm.addNewOff();
    off.setX(0);
    off.setY(0);
    CTPositiveSize2D ext = xfrm.addNewExt();
    ext.setCx(0);
    ext.setCy(0);
    CTPoint2D choff = xfrm.addNewChOff();
    choff.setX(0);
    choff.setY(0);
    CTPositiveSize2D chExt = xfrm.addNewChExt();
    chExt.setCx(0);
    chExt.setCy(0);
    ctSlide.addNewClrMapOvr().addNewMasterClrMapping();
    return ctSlide;
}
Also used : CTCommonSlideData(org.openxmlformats.schemas.presentationml.x2006.main.CTCommonSlideData) CTPoint2D(org.openxmlformats.schemas.drawingml.x2006.main.CTPoint2D) CTGroupTransform2D(org.openxmlformats.schemas.drawingml.x2006.main.CTGroupTransform2D) CTGroupShapeNonVisual(org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShapeNonVisual) CTNonVisualDrawingProps(org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps) CTGroupShapeProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTGroupShapeProperties) CTSlide(org.openxmlformats.schemas.presentationml.x2006.main.CTSlide) CTPositiveSize2D(org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D) CTGroupShape(org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShape)

Example 9 with CTGroupTransform2D

use of org.openxmlformats.schemas.drawingml.x2006.main.CTGroupTransform2D in project poi by apache.

the class XSSFDrawing method createGroup.

/**
     * Creates a simple shape.  This includes such shapes as lines, rectangles,
     * and ovals.
     *
     * @param anchor    the client anchor describes how this group is attached
     *                  to the sheet.
     * @return  the newly created shape.
     */
public XSSFShapeGroup createGroup(XSSFClientAnchor anchor) {
    CTTwoCellAnchor ctAnchor = createTwoCellAnchor(anchor);
    CTGroupShape ctGroup = ctAnchor.addNewGrpSp();
    ctGroup.set(XSSFShapeGroup.prototype());
    CTTransform2D xfrm = createXfrm(anchor);
    CTGroupTransform2D grpXfrm = ctGroup.getGrpSpPr().getXfrm();
    grpXfrm.setOff(xfrm.getOff());
    grpXfrm.setExt(xfrm.getExt());
    grpXfrm.setChExt(xfrm.getExt());
    XSSFShapeGroup shape = new XSSFShapeGroup(this, ctGroup);
    shape.anchor = anchor;
    return shape;
}
Also used : CTTransform2D(org.openxmlformats.schemas.drawingml.x2006.main.CTTransform2D) CTGroupTransform2D(org.openxmlformats.schemas.drawingml.x2006.main.CTGroupTransform2D) CTTwoCellAnchor(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTTwoCellAnchor) CTGroupShape(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTGroupShape)

Example 10 with CTGroupTransform2D

use of org.openxmlformats.schemas.drawingml.x2006.main.CTGroupTransform2D in project poi by apache.

the class XSSFShapeGroup method createGroup.

/**
     * Creates a group shape.
     *
     * @param anchor       the client anchor describes how this group is attached to the group.
     * @return the newly created group shape.
     */
public XSSFShapeGroup createGroup(XSSFChildAnchor anchor) {
    CTGroupShape ctShape = ctGroup.addNewGrpSp();
    ctShape.set(prototype());
    XSSFShapeGroup shape = new XSSFShapeGroup(getDrawing(), ctShape);
    shape.parent = this;
    shape.anchor = anchor;
    // TODO: calculate bounding rectangle on anchor and set off/ext correctly
    CTGroupTransform2D xfrm = shape.getCTGroupShape().getGrpSpPr().getXfrm();
    CTTransform2D t2 = anchor.getCTTransform2D();
    xfrm.setOff(t2.getOff());
    xfrm.setExt(t2.getExt());
    // child offset is left to 0,0
    xfrm.setChExt(t2.getExt());
    xfrm.setFlipH(t2.getFlipH());
    xfrm.setFlipV(t2.getFlipV());
    return shape;
}
Also used : CTTransform2D(org.openxmlformats.schemas.drawingml.x2006.main.CTTransform2D) CTGroupTransform2D(org.openxmlformats.schemas.drawingml.x2006.main.CTGroupTransform2D) CTGroupShape(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTGroupShape)

Aggregations

CTGroupTransform2D (org.openxmlformats.schemas.drawingml.x2006.main.CTGroupTransform2D)10 CTPoint2D (org.openxmlformats.schemas.drawingml.x2006.main.CTPoint2D)7 CTPositiveSize2D (org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D)7 CTGroupShape (org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTGroupShape)3 CTGroupShapeProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTGroupShapeProperties)2 CTNonVisualDrawingProps (org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps)2 CTTransform2D (org.openxmlformats.schemas.drawingml.x2006.main.CTTransform2D)2 Test (org.junit.Test)1 CTGroupShapeNonVisual (org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTGroupShapeNonVisual)1 CTTwoCellAnchor (org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTTwoCellAnchor)1 CTCommonSlideData (org.openxmlformats.schemas.presentationml.x2006.main.CTCommonSlideData)1 CTGroupShape (org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShape)1 CTGroupShapeNonVisual (org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShapeNonVisual)1 CTSlide (org.openxmlformats.schemas.presentationml.x2006.main.CTSlide)1