Search in sources :

Example 6 with EscherClientAnchorRecord

use of org.apache.poi.ddf.EscherClientAnchorRecord in project poi by apache.

the class HSLFGroupShape method getAnchor.

/**
     * Returns the anchor (the bounding box rectangle) of this shape group.
     * All coordinates are expressed in points (72 dpi).
     *
     * @return the anchor of this shape group
     */
@Override
public Rectangle2D getAnchor() {
    EscherClientAnchorRecord clientAnchor = getEscherChild(EscherClientAnchorRecord.RECORD_ID);
    int x1, y1, x2, y2;
    if (clientAnchor == null) {
        LOG.log(POILogger.INFO, "EscherClientAnchorRecord was not found for shape group. Searching for EscherChildAnchorRecord.");
        EscherChildAnchorRecord rec = getEscherChild(EscherChildAnchorRecord.RECORD_ID);
        x1 = rec.getDx1();
        y1 = rec.getDy1();
        x2 = rec.getDx2();
        y2 = rec.getDy2();
    } else {
        x1 = clientAnchor.getCol1();
        y1 = clientAnchor.getFlag();
        x2 = clientAnchor.getDx1();
        y2 = clientAnchor.getRow1();
    }
    Rectangle2D anchor = new Rectangle2D.Double((x1 == -1 ? -1 : Units.masterToPoints(x1)), (y1 == -1 ? -1 : Units.masterToPoints(y1)), (x2 == -1 ? -1 : Units.masterToPoints(x2 - x1)), (y2 == -1 ? -1 : Units.masterToPoints(y2 - y1)));
    return anchor;
}
Also used : EscherChildAnchorRecord(org.apache.poi.ddf.EscherChildAnchorRecord) EscherClientAnchorRecord(org.apache.poi.ddf.EscherClientAnchorRecord) Rectangle2D(java.awt.geom.Rectangle2D)

Example 7 with EscherClientAnchorRecord

use of org.apache.poi.ddf.EscherClientAnchorRecord in project poi by apache.

the class HSLFShape method setAnchor.

/**
     * Sets the anchor (the bounding box rectangle) of this shape.
     * All coordinates should be expressed in points (72 dpi).
     *
     * @param anchor new anchor
     */
public void setAnchor(Rectangle2D anchor) {
    int x = Units.pointsToMaster(anchor.getX());
    int y = Units.pointsToMaster(anchor.getY());
    int w = Units.pointsToMaster(anchor.getWidth() + anchor.getX());
    int h = Units.pointsToMaster(anchor.getHeight() + anchor.getY());
    EscherSpRecord spRecord = getEscherChild(EscherSpRecord.RECORD_ID);
    int flags = spRecord.getFlags();
    if ((flags & EscherSpRecord.FLAG_CHILD) != 0) {
        EscherChildAnchorRecord rec = (EscherChildAnchorRecord) getEscherChild(EscherChildAnchorRecord.RECORD_ID);
        rec.setDx1(x);
        rec.setDy1(y);
        rec.setDx2(w);
        rec.setDy2(h);
    } else {
        EscherClientAnchorRecord rec = (EscherClientAnchorRecord) getEscherChild(EscherClientAnchorRecord.RECORD_ID);
        rec.setCol1((short) x);
        rec.setFlag((short) y);
        rec.setDx1((short) w);
        rec.setRow1((short) h);
    }
}
Also used : EscherChildAnchorRecord(org.apache.poi.ddf.EscherChildAnchorRecord) EscherSpRecord(org.apache.poi.ddf.EscherSpRecord) EscherClientAnchorRecord(org.apache.poi.ddf.EscherClientAnchorRecord)

Example 8 with EscherClientAnchorRecord

use of org.apache.poi.ddf.EscherClientAnchorRecord in project poi by apache.

the class HSLFGroupShape method setExteriorAnchor.

protected void setExteriorAnchor(Rectangle2D anchor) {
    EscherClientAnchorRecord clientAnchor = getEscherChild(EscherClientAnchorRecord.RECORD_ID);
    //hack. internal variable EscherClientAnchorRecord.shortRecord can be
    //initialized only in fillFields(). We need to set shortRecord=false;
    byte[] header = new byte[16];
    LittleEndian.putUShort(header, 0, 0);
    LittleEndian.putUShort(header, 2, 0);
    LittleEndian.putInt(header, 4, 8);
    clientAnchor.fillFields(header, 0, null);
    // All coordinates need to be converted to Master units (576 dpi)
    clientAnchor.setFlag((short) Units.pointsToMaster(anchor.getY()));
    clientAnchor.setCol1((short) Units.pointsToMaster(anchor.getX()));
    clientAnchor.setDx1((short) Units.pointsToMaster(anchor.getWidth() + anchor.getX()));
    clientAnchor.setRow1((short) Units.pointsToMaster(anchor.getHeight() + anchor.getY()));
    // TODO: does this make sense?
    setInteriorAnchor(anchor);
}
Also used : EscherClientAnchorRecord(org.apache.poi.ddf.EscherClientAnchorRecord)

Example 9 with EscherClientAnchorRecord

use of org.apache.poi.ddf.EscherClientAnchorRecord in project poi by apache.

the class HSLFSimpleShape method createSpContainer.

/**
     * Create a new Shape
     *
     * @param isChild   <code>true</code> if the Line is inside a group, <code>false</code> otherwise
     * @return the record container which holds this shape
     */
@Override
protected EscherContainerRecord createSpContainer(boolean isChild) {
    EscherContainerRecord ecr = super.createSpContainer(isChild);
    ecr.setRecordId(EscherContainerRecord.SP_CONTAINER);
    EscherSpRecord sp = new EscherSpRecord();
    int flags = EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HASSHAPETYPE;
    if (isChild) {
        flags |= EscherSpRecord.FLAG_CHILD;
    }
    sp.setFlags(flags);
    ecr.addChildRecord(sp);
    AbstractEscherOptRecord opt = new EscherOptRecord();
    opt.setRecordId(EscherOptRecord.RECORD_ID);
    ecr.addChildRecord(opt);
    EscherRecord anchor;
    if (isChild) {
        anchor = new EscherChildAnchorRecord();
    } else {
        anchor = new EscherClientAnchorRecord();
        //hack. internal variable EscherClientAnchorRecord.shortRecord can be
        //initialized only in fillFields(). We need to set shortRecord=false;
        byte[] header = new byte[16];
        LittleEndian.putUShort(header, 0, 0);
        LittleEndian.putUShort(header, 2, 0);
        LittleEndian.putInt(header, 4, 8);
        anchor.fillFields(header, 0, null);
    }
    ecr.addChildRecord(anchor);
    return ecr;
}
Also used : EscherChildAnchorRecord(org.apache.poi.ddf.EscherChildAnchorRecord) EscherSpRecord(org.apache.poi.ddf.EscherSpRecord) EscherClientAnchorRecord(org.apache.poi.ddf.EscherClientAnchorRecord) EscherContainerRecord(org.apache.poi.ddf.EscherContainerRecord) EscherRecord(org.apache.poi.ddf.EscherRecord) AbstractEscherOptRecord(org.apache.poi.ddf.AbstractEscherOptRecord) DrawPaint(org.apache.poi.sl.draw.DrawPaint) SolidPaint(org.apache.poi.sl.usermodel.PaintStyle.SolidPaint) AbstractEscherOptRecord(org.apache.poi.ddf.AbstractEscherOptRecord) EscherOptRecord(org.apache.poi.ddf.EscherOptRecord)

Example 10 with EscherClientAnchorRecord

use of org.apache.poi.ddf.EscherClientAnchorRecord in project poi by apache.

the class HSSFShape method setAnchor.

/**
     * Sets a particular anchor.  A top-level shape must have an anchor of
     * HSSFClientAnchor.  A child anchor must have an anchor of HSSFChildAnchor
     *
     * @param anchor the anchor to use.
     * @throws IllegalArgumentException when the wrong anchor is used for
     *                                  this particular shape.
     * @see HSSFChildAnchor
     * @see HSSFClientAnchor
     */
public void setAnchor(HSSFAnchor anchor) {
    int i = 0;
    int recordId = -1;
    if (parent == null) {
        if (anchor instanceof HSSFChildAnchor)
            throw new IllegalArgumentException("Must use client anchors for shapes directly attached to sheet.");
        EscherClientAnchorRecord anch = _escherContainer.getChildById(EscherClientAnchorRecord.RECORD_ID);
        if (null != anch) {
            for (i = 0; i < _escherContainer.getChildRecords().size(); i++) {
                if (_escherContainer.getChild(i).getRecordId() == EscherClientAnchorRecord.RECORD_ID) {
                    if (i != _escherContainer.getChildRecords().size() - 1) {
                        recordId = _escherContainer.getChild(i + 1).getRecordId();
                    }
                }
            }
            _escherContainer.removeChildRecord(anch);
        }
    } else {
        if (anchor instanceof HSSFClientAnchor)
            throw new IllegalArgumentException("Must use child anchors for shapes attached to groups.");
        EscherChildAnchorRecord anch = _escherContainer.getChildById(EscherChildAnchorRecord.RECORD_ID);
        if (null != anch) {
            for (i = 0; i < _escherContainer.getChildRecords().size(); i++) {
                if (_escherContainer.getChild(i).getRecordId() == EscherChildAnchorRecord.RECORD_ID) {
                    if (i != _escherContainer.getChildRecords().size() - 1) {
                        recordId = _escherContainer.getChild(i + 1).getRecordId();
                    }
                }
            }
            _escherContainer.removeChildRecord(anch);
        }
    }
    if (-1 == recordId) {
        _escherContainer.addChildRecord(anchor.getEscherAnchor());
    } else {
        _escherContainer.addChildBefore(anchor.getEscherAnchor(), recordId);
    }
    this.anchor = anchor;
}
Also used : EscherChildAnchorRecord(org.apache.poi.ddf.EscherChildAnchorRecord) EscherClientAnchorRecord(org.apache.poi.ddf.EscherClientAnchorRecord)

Aggregations

EscherClientAnchorRecord (org.apache.poi.ddf.EscherClientAnchorRecord)10 EscherChildAnchorRecord (org.apache.poi.ddf.EscherChildAnchorRecord)6 EscherSpRecord (org.apache.poi.ddf.EscherSpRecord)4 Rectangle2D (java.awt.geom.Rectangle2D)2 EscherContainerRecord (org.apache.poi.ddf.EscherContainerRecord)2 AbstractEscherOptRecord (org.apache.poi.ddf.AbstractEscherOptRecord)1 EscherOptRecord (org.apache.poi.ddf.EscherOptRecord)1 EscherRecord (org.apache.poi.ddf.EscherRecord)1 EscherSpgrRecord (org.apache.poi.ddf.EscherSpgrRecord)1 HSSFChildAnchor (org.apache.poi.hssf.usermodel.HSSFChildAnchor)1 HSSFClientAnchor (org.apache.poi.hssf.usermodel.HSSFClientAnchor)1 DrawPaint (org.apache.poi.sl.draw.DrawPaint)1 SolidPaint (org.apache.poi.sl.usermodel.PaintStyle.SolidPaint)1