Search in sources :

Example 1 with EscherChildAnchorRecord

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

the class ConvertAnchor method createAnchor.

public static EscherRecord createAnchor(HSSFAnchor userAnchor) {
    if (userAnchor instanceof HSSFClientAnchor) {
        HSSFClientAnchor a = (HSSFClientAnchor) userAnchor;
        EscherClientAnchorRecord anchor = new EscherClientAnchorRecord();
        anchor.setRecordId(EscherClientAnchorRecord.RECORD_ID);
        anchor.setOptions((short) 0x0000);
        anchor.setFlag(a.getAnchorType().value);
        anchor.setCol1((short) Math.min(a.getCol1(), a.getCol2()));
        anchor.setDx1((short) a.getDx1());
        anchor.setRow1((short) Math.min(a.getRow1(), a.getRow2()));
        anchor.setDy1((short) a.getDy1());
        anchor.setCol2((short) Math.max(a.getCol1(), a.getCol2()));
        anchor.setDx2((short) a.getDx2());
        anchor.setRow2((short) Math.max(a.getRow1(), a.getRow2()));
        anchor.setDy2((short) a.getDy2());
        return anchor;
    }
    HSSFChildAnchor a = (HSSFChildAnchor) userAnchor;
    EscherChildAnchorRecord anchor = new EscherChildAnchorRecord();
    anchor.setRecordId(EscherChildAnchorRecord.RECORD_ID);
    anchor.setOptions((short) 0x0000);
    anchor.setDx1((short) Math.min(a.getDx1(), a.getDx2()));
    anchor.setDy1((short) Math.min(a.getDy1(), a.getDy2()));
    anchor.setDx2((short) Math.max(a.getDx2(), a.getDx1()));
    anchor.setDy2((short) Math.max(a.getDy2(), a.getDy1()));
    return anchor;
}
Also used : EscherChildAnchorRecord(org.apache.poi.ddf.EscherChildAnchorRecord) HSSFClientAnchor(org.apache.poi.hssf.usermodel.HSSFClientAnchor) EscherClientAnchorRecord(org.apache.poi.ddf.EscherClientAnchorRecord) HSSFChildAnchor(org.apache.poi.hssf.usermodel.HSSFChildAnchor)

Example 2 with EscherChildAnchorRecord

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

the class HSLFShape method getAnchor.

/**
     * Returns the anchor (the bounding box rectangle) of this shape.
     * All coordinates are expressed in points (72 dpi).
     *
     * @return the anchor of this shape
     */
@Override
public Rectangle2D getAnchor() {
    EscherSpRecord spRecord = getEscherChild(EscherSpRecord.RECORD_ID);
    int flags = spRecord.getFlags();
    int x1, y1, x2, y2;
    EscherChildAnchorRecord childRec = getEscherChild(EscherChildAnchorRecord.RECORD_ID);
    boolean useChildRec = ((flags & EscherSpRecord.FLAG_CHILD) != 0);
    if (useChildRec && childRec != null) {
        x1 = childRec.getDx1();
        y1 = childRec.getDy1();
        x2 = childRec.getDx2();
        y2 = childRec.getDy2();
    } else {
        if (useChildRec) {
            LOG.log(POILogger.WARN, "EscherSpRecord.FLAG_CHILD is set but EscherChildAnchorRecord was not found");
        }
        EscherClientAnchorRecord clientRec = getEscherChild(EscherClientAnchorRecord.RECORD_ID);
        x1 = clientRec.getCol1();
        y1 = clientRec.getFlag();
        x2 = clientRec.getDx1();
        y2 = clientRec.getRow1();
    }
    // TODO: find out where this -1 value comes from at #57820 (link to ms docs?)
    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) EscherSpRecord(org.apache.poi.ddf.EscherSpRecord) EscherClientAnchorRecord(org.apache.poi.ddf.EscherClientAnchorRecord) Rectangle2D(java.awt.geom.Rectangle2D)

Example 3 with EscherChildAnchorRecord

use of org.apache.poi.ddf.EscherChildAnchorRecord 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 4 with EscherChildAnchorRecord

use of org.apache.poi.ddf.EscherChildAnchorRecord 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 5 with EscherChildAnchorRecord

use of org.apache.poi.ddf.EscherChildAnchorRecord 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)

Aggregations

EscherChildAnchorRecord (org.apache.poi.ddf.EscherChildAnchorRecord)6 EscherClientAnchorRecord (org.apache.poi.ddf.EscherClientAnchorRecord)6 EscherSpRecord (org.apache.poi.ddf.EscherSpRecord)3 Rectangle2D (java.awt.geom.Rectangle2D)2 AbstractEscherOptRecord (org.apache.poi.ddf.AbstractEscherOptRecord)1 EscherContainerRecord (org.apache.poi.ddf.EscherContainerRecord)1 EscherOptRecord (org.apache.poi.ddf.EscherOptRecord)1 EscherRecord (org.apache.poi.ddf.EscherRecord)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