Search in sources :

Example 6 with CTPositiveSize2D

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

the class SXSSFPicture method getPreferredSize.

/**
     * Calculate the preferred size for this picture.
     *
     * @param scale the amount by which image dimensions are multiplied relative to the original size.
     * @return XSSFClientAnchor with the preferred size for this image
     */
public XSSFClientAnchor getPreferredSize(double scale) {
    XSSFClientAnchor anchor = getClientAnchor();
    XSSFPictureData data = getPictureData();
    Dimension size = getImageDimension(data.getPackagePart(), data.getPictureType());
    double scaledWidth = size.getWidth() * scale;
    double scaledHeight = size.getHeight() * scale;
    float w = 0;
    int col2 = anchor.getCol1() - 1;
    while (w <= scaledWidth) {
        w += getColumnWidthInPixels(++col2);
    }
    assert (w > scaledWidth);
    double cw = getColumnWidthInPixels(col2);
    double deltaW = w - scaledWidth;
    int dx2 = (int) (XSSFShape.EMU_PER_PIXEL * (cw - deltaW));
    anchor.setCol2(col2);
    anchor.setDx2(dx2);
    double h = 0;
    int row2 = anchor.getRow1() - 1;
    while (h <= scaledHeight) {
        h += getRowHeightInPixels(++row2);
    }
    assert (h > scaledHeight);
    double ch = getRowHeightInPixels(row2);
    double deltaH = h - scaledHeight;
    int dy2 = (int) (XSSFShape.EMU_PER_PIXEL * (ch - deltaH));
    anchor.setRow2(row2);
    anchor.setDy2(dy2);
    CTPositiveSize2D size2d = getCTPicture().getSpPr().getXfrm().getExt();
    size2d.setCx((long) (scaledWidth * XSSFShape.EMU_PER_PIXEL));
    size2d.setCy((long) (scaledHeight * XSSFShape.EMU_PER_PIXEL));
    return anchor;
}
Also used : XSSFPictureData(org.apache.poi.xssf.usermodel.XSSFPictureData) XSSFClientAnchor(org.apache.poi.xssf.usermodel.XSSFClientAnchor) Dimension(java.awt.Dimension) CTPositiveSize2D(org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D)

Example 7 with CTPositiveSize2D

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

the class XSLFSimpleShape method setAnchor.

@Override
public void setAnchor(Rectangle2D anchor) {
    CTTransform2D xfrm = getXfrm(true);
    if (xfrm == null) {
        return;
    }
    CTPoint2D off = xfrm.isSetOff() ? xfrm.getOff() : xfrm.addNewOff();
    long x = Units.toEMU(anchor.getX());
    long y = Units.toEMU(anchor.getY());
    off.setX(x);
    off.setY(y);
    CTPositiveSize2D ext = xfrm.isSetExt() ? xfrm.getExt() : xfrm.addNewExt();
    long cx = Units.toEMU(anchor.getWidth());
    long cy = Units.toEMU(anchor.getHeight());
    ext.setCx(cx);
    ext.setCy(cy);
}
Also used : CTTransform2D(org.openxmlformats.schemas.drawingml.x2006.main.CTTransform2D) CTPoint2D(org.openxmlformats.schemas.drawingml.x2006.main.CTPoint2D) CTPositiveSize2D(org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D)

Example 8 with CTPositiveSize2D

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

the class XSSFShapeGroup method prototype.

/**
     * Initialize default structure of a new shape group
     */
protected static CTGroupShape prototype() {
    if (prototype == null) {
        CTGroupShape shape = CTGroupShape.Factory.newInstance();
        CTGroupShapeNonVisual nv = shape.addNewNvGrpSpPr();
        CTNonVisualDrawingProps nvpr = nv.addNewCNvPr();
        nvpr.setId(0);
        nvpr.setName("Group 0");
        nv.addNewCNvGrpSpPr();
        CTGroupShapeProperties sp = shape.addNewGrpSpPr();
        CTGroupTransform2D t2d = sp.addNewXfrm();
        CTPositiveSize2D p1 = t2d.addNewExt();
        p1.setCx(0);
        p1.setCy(0);
        CTPoint2D p2 = t2d.addNewOff();
        p2.setX(0);
        p2.setY(0);
        CTPositiveSize2D p3 = t2d.addNewChExt();
        p3.setCx(0);
        p3.setCy(0);
        CTPoint2D p4 = t2d.addNewChOff();
        p4.setX(0);
        p4.setY(0);
        prototype = shape;
    }
    return prototype;
}
Also used : CTPoint2D(org.openxmlformats.schemas.drawingml.x2006.main.CTPoint2D) CTGroupTransform2D(org.openxmlformats.schemas.drawingml.x2006.main.CTGroupTransform2D) CTGroupShapeNonVisual(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTGroupShapeNonVisual) CTNonVisualDrawingProps(org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps) CTGroupShapeProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTGroupShapeProperties) CTPositiveSize2D(org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D) CTGroupShape(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTGroupShape)

Example 9 with CTPositiveSize2D

use of org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D 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 10 with CTPositiveSize2D

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

the class XSSFDrawing method createXfrm.

private CTTransform2D createXfrm(XSSFClientAnchor anchor) {
    CTTransform2D xfrm = CTTransform2D.Factory.newInstance();
    CTPoint2D off = xfrm.addNewOff();
    off.setX(anchor.getDx1());
    off.setY(anchor.getDy1());
    XSSFSheet sheet = getSheet();
    double widthPx = 0;
    for (int col = anchor.getCol1(); col < anchor.getCol2(); col++) {
        widthPx += sheet.getColumnWidthInPixels(col);
    }
    double heightPx = 0;
    for (int row = anchor.getRow1(); row < anchor.getRow2(); row++) {
        heightPx += ImageUtils.getRowHeightInPixels(sheet, row);
    }
    long width = Units.pixelToEMU((int) widthPx);
    long height = Units.pixelToEMU((int) heightPx);
    CTPositiveSize2D ext = xfrm.addNewExt();
    ext.setCx(width - anchor.getDx1() + anchor.getDx2());
    ext.setCy(height - anchor.getDy1() + anchor.getDy2());
    // TODO: handle vflip/hflip
    return xfrm;
}
Also used : CTTransform2D(org.openxmlformats.schemas.drawingml.x2006.main.CTTransform2D) CTPoint2D(org.openxmlformats.schemas.drawingml.x2006.main.CTPoint2D) CTPositiveSize2D(org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D)

Aggregations

CTPositiveSize2D (org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D)21 CTPoint2D (org.openxmlformats.schemas.drawingml.x2006.main.CTPoint2D)18 CTTransform2D (org.openxmlformats.schemas.drawingml.x2006.main.CTTransform2D)11 CTNonVisualDrawingProps (org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps)8 CTGroupTransform2D (org.openxmlformats.schemas.drawingml.x2006.main.CTGroupTransform2D)7 CTPresetGeometry2D (org.openxmlformats.schemas.drawingml.x2006.main.CTPresetGeometry2D)4 CTShapeProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties)4 Dimension (java.awt.Dimension)2 CTBlipFillProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTBlipFillProperties)2 CTGroupShapeProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTGroupShapeProperties)2 CTNonVisualPictureProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualPictureProperties)2 CTShape (org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShape)2 CTShapeNonVisual (org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShapeNonVisual)2 CTInline (org.openxmlformats.schemas.drawingml.x2006.wordprocessingDrawing.CTInline)2 CTGraphicalObjectFrame (org.openxmlformats.schemas.presentationml.x2006.main.CTGraphicalObjectFrame)2 Rectangle2D (java.awt.geom.Rectangle2D)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 QName (javax.xml.namespace.QName)1