Search in sources :

Example 1 with EscherClientAnchorRecord

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

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

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

the class HSLFGroupShape method setAnchor.

@Override
public void setAnchor(Rectangle2D anchor) {
    EscherClientAnchorRecord clientAnchor = getEscherChild(EscherClientAnchorRecord.RECORD_ID);
    boolean isInitialized = !(clientAnchor.getDx1() == 0 && clientAnchor.getRow1() == 0);
    if (isInitialized) {
        moveAndScale(anchor);
    } else {
        setExteriorAnchor(anchor);
    }
}
Also used : EscherClientAnchorRecord(org.apache.poi.ddf.EscherClientAnchorRecord)

Example 4 with EscherClientAnchorRecord

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

the class HSLFGroupShape method createSpContainer.

/**
     * Create a new ShapeGroup and create an instance of <code>EscherSpgrContainer</code> which represents a group of shapes
     */
@Override
protected EscherContainerRecord createSpContainer(boolean isChild) {
    EscherContainerRecord ecr = super.createSpContainer(isChild);
    ecr.setRecordId(EscherContainerRecord.SPGR_CONTAINER);
    //The group itself is a shape, and always appears as the first EscherSpContainer in the group container.
    EscherContainerRecord spcont = new EscherContainerRecord();
    spcont.setRecordId(EscherContainerRecord.SP_CONTAINER);
    spcont.setOptions((short) 15);
    EscherSpgrRecord spg = new EscherSpgrRecord();
    spg.setOptions((short) 1);
    spcont.addChildRecord(spg);
    EscherSpRecord sp = new EscherSpRecord();
    short type = (short) ((ShapeType.NOT_PRIMITIVE.nativeId << 4) + 2);
    sp.setOptions(type);
    sp.setFlags(EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_GROUP);
    spcont.addChildRecord(sp);
    EscherClientAnchorRecord anchor = new EscherClientAnchorRecord();
    spcont.addChildRecord(anchor);
    ecr.addChildRecord(spcont);
    return ecr;
}
Also used : EscherSpgrRecord(org.apache.poi.ddf.EscherSpgrRecord) EscherSpRecord(org.apache.poi.ddf.EscherSpRecord) EscherClientAnchorRecord(org.apache.poi.ddf.EscherClientAnchorRecord) EscherContainerRecord(org.apache.poi.ddf.EscherContainerRecord)

Example 5 with EscherClientAnchorRecord

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

the class TestHSSFClientAnchor method testConvertAnchor.

/**
     * When HSSFClientAnchor is converted into EscherClientAnchorRecord
     * check that dx1, dx2, dy1 and dy2 are written "as is".
     * (Bug 42999 reported that dx1 and dx2 are swapped if dx1>dx2. It doesn't make sense for client anchors.)
     */
public void testConvertAnchor() {
    HSSFClientAnchor[] anchors = { new HSSFClientAnchor(0, 0, 0, 0, (short) 0, 1, (short) 1, 3), new HSSFClientAnchor(100, 0, 900, 255, (short) 0, 1, (short) 1, 3), new HSSFClientAnchor(900, 0, 100, 255, (short) 0, 1, (short) 1, 3) };
    for (HSSFClientAnchor anchor : anchors) {
        EscherClientAnchorRecord record = (EscherClientAnchorRecord) ConvertAnchor.createAnchor(anchor);
        assertEquals(anchor.getDx1(), record.getDx1());
        assertEquals(anchor.getDx2(), record.getDx2());
        assertEquals(anchor.getDy1(), record.getDy1());
        assertEquals(anchor.getDy2(), record.getDy2());
        assertEquals(anchor.getCol1(), record.getCol1());
        assertEquals(anchor.getCol2(), record.getCol2());
        assertEquals(anchor.getRow1(), record.getRow1());
        assertEquals(anchor.getRow2(), record.getRow2());
    }
}
Also used : 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