Search in sources :

Example 11 with EscherSpRecord

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

the class HSLFShape method setFlipHorizontal.

public void setFlipHorizontal(boolean flip) {
    EscherSpRecord spRecord = getEscherChild(EscherSpRecord.RECORD_ID);
    int flag = spRecord.getFlags() | EscherSpRecord.FLAG_FLIPHORIZ;
    spRecord.setFlags(flag);
}
Also used : EscherSpRecord(org.apache.poi.ddf.EscherSpRecord)

Example 12 with EscherSpRecord

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

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

the class HSLFShapeFactory method createSimpleShape.

public static HSLFShape createSimpleShape(EscherContainerRecord spContainer, ShapeContainer<HSLFShape, HSLFTextParagraph> parent) {
    HSLFShape shape = null;
    EscherSpRecord spRecord = spContainer.getChildById(EscherSpRecord.RECORD_ID);
    ShapeType type = ShapeType.forId(spRecord.getShapeType(), false);
    switch(type) {
        case TEXT_BOX:
            shape = new HSLFTextBox(spContainer, parent);
            break;
        case HOST_CONTROL:
        case FRAME:
            shape = createFrame(spContainer, parent);
            break;
        case LINE:
            shape = new HSLFLine(spContainer, parent);
            break;
        case NOT_PRIMITIVE:
            shape = createNonPrimitive(spContainer, parent);
            break;
        default:
            if (parent instanceof HSLFTable) {
                EscherTextboxRecord etr = spContainer.getChildById(EscherTextboxRecord.RECORD_ID);
                if (etr == null) {
                    logger.log(POILogger.WARN, "invalid ppt - add EscherTextboxRecord to cell");
                    etr = new EscherTextboxRecord();
                    etr.setRecordId(EscherTextboxRecord.RECORD_ID);
                    etr.setOptions((short) 15);
                    spContainer.addChildRecord(etr);
                }
                shape = new HSLFTableCell(spContainer, (HSLFTable) parent);
            } else {
                shape = new HSLFAutoShape(spContainer, parent);
            }
            break;
    }
    return shape;
}
Also used : EscherSpRecord(org.apache.poi.ddf.EscherSpRecord) ShapeType(org.apache.poi.sl.usermodel.ShapeType) EscherTextboxRecord(org.apache.poi.ddf.EscherTextboxRecord)

Example 14 with EscherSpRecord

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

the class TestCloneSheet method testCloneComment.

@Test
public void testCloneComment() throws IOException {
    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFSheet sh = wb.createSheet();
    HSSFPatriarch p = sh.createDrawingPatriarch();
    HSSFComment c = p.createComment(new HSSFClientAnchor(0, 0, 100, 100, (short) 0, 0, (short) 5, 5));
    c.setColumn(1);
    c.setRow(2);
    c.setString(new HSSFRichTextString("qwertyuio"));
    HSSFSheet sh2 = wb.cloneSheet(0);
    HSSFPatriarch p2 = sh2.getDrawingPatriarch();
    HSSFComment c2 = (HSSFComment) p2.getChildren().get(0);
    assertEquals(c.getString(), c2.getString());
    assertEquals(c.getRow(), c2.getRow());
    assertEquals(c.getColumn(), c2.getColumn());
    // The ShapeId is not equal? 
    // assertEquals(c.getNoteRecord().getShapeId(), c2.getNoteRecord().getShapeId());
    assertArrayEquals(c2.getTextObjectRecord().serialize(), c.getTextObjectRecord().serialize());
    // ShapeId is different
    CommonObjectDataSubRecord subRecord = (CommonObjectDataSubRecord) c2.getObjRecord().getSubRecords().get(0);
    subRecord.setObjectId(1025);
    assertArrayEquals(c2.getObjRecord().serialize(), c.getObjRecord().serialize());
    // ShapeId is different
    c2.getNoteRecord().setShapeId(1025);
    assertArrayEquals(c2.getNoteRecord().serialize(), c.getNoteRecord().serialize());
    //everything except spRecord.shapeId must be the same
    assertFalse(Arrays.equals(c2.getEscherContainer().serialize(), c.getEscherContainer().serialize()));
    EscherSpRecord sp = (EscherSpRecord) c2.getEscherContainer().getChild(0);
    sp.setShapeId(1025);
    assertArrayEquals(c2.getEscherContainer().serialize(), c.getEscherContainer().serialize());
    wb.close();
}
Also used : CommonObjectDataSubRecord(org.apache.poi.hssf.record.CommonObjectDataSubRecord) EscherSpRecord(org.apache.poi.ddf.EscherSpRecord) Test(org.junit.Test)

Example 15 with EscherSpRecord

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

the class TestPolygon method testPolygonType.

@Test
public void testPolygonType() throws IOException {
    HSSFWorkbook wb1 = new HSSFWorkbook();
    HSSFSheet sh = wb1.createSheet();
    HSSFPatriarch patriarch = sh.createDrawingPatriarch();
    HSSFPolygon polygon = patriarch.createPolygon(new HSSFClientAnchor());
    polygon.setPolygonDrawArea(102, 101);
    polygon.setPoints(new int[] { 1, 2, 3 }, new int[] { 4, 5, 6 });
    HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1);
    wb1.close();
    sh = wb2.getSheetAt(0);
    patriarch = sh.getDrawingPatriarch();
    HSSFPolygon polygon1 = patriarch.createPolygon(new HSSFClientAnchor());
    polygon1.setPolygonDrawArea(102, 101);
    polygon1.setPoints(new int[] { 1, 2, 3 }, new int[] { 4, 5, 6 });
    EscherSpRecord spRecord = polygon1.getEscherContainer().getChildById(EscherSpRecord.RECORD_ID);
    spRecord.setShapeType((short) 77);
    HSSFWorkbook wb3 = HSSFTestDataSamples.writeOutAndReadBack(wb2);
    wb2.close();
    sh = wb3.getSheetAt(0);
    patriarch = sh.getDrawingPatriarch();
    assertEquals(patriarch.getChildren().size(), 2);
    assertTrue(patriarch.getChildren().get(0) instanceof HSSFPolygon);
    assertTrue(patriarch.getChildren().get(1) instanceof HSSFPolygon);
    wb3.close();
}
Also used : EscherSpRecord(org.apache.poi.ddf.EscherSpRecord) Test(org.junit.Test)

Aggregations

EscherSpRecord (org.apache.poi.ddf.EscherSpRecord)31 EscherContainerRecord (org.apache.poi.ddf.EscherContainerRecord)17 EscherClientAnchorRecord (org.apache.poi.ddf.EscherClientAnchorRecord)5 EscherDgRecord (org.apache.poi.ddf.EscherDgRecord)5 EscherOptRecord (org.apache.poi.ddf.EscherOptRecord)5 CommonObjectDataSubRecord (org.apache.poi.hssf.record.CommonObjectDataSubRecord)5 AbstractEscherOptRecord (org.apache.poi.ddf.AbstractEscherOptRecord)4 EscherChildAnchorRecord (org.apache.poi.ddf.EscherChildAnchorRecord)4 EscherRecord (org.apache.poi.ddf.EscherRecord)4 EscherTextboxRecord (org.apache.poi.ddf.EscherTextboxRecord)4 Test (org.junit.Test)4 EscherSimpleProperty (org.apache.poi.ddf.EscherSimpleProperty)3 EscherSpgrRecord (org.apache.poi.ddf.EscherSpgrRecord)3 HSLFEscherClientDataRecord (org.apache.poi.hslf.record.HSLFEscherClientDataRecord)3 EscherBoolProperty (org.apache.poi.ddf.EscherBoolProperty)2 EscherClientDataRecord (org.apache.poi.ddf.EscherClientDataRecord)2 EscherDggRecord (org.apache.poi.ddf.EscherDggRecord)2 EscherRGBProperty (org.apache.poi.ddf.EscherRGBProperty)2 ExObjRefAtom (org.apache.poi.hslf.record.ExObjRefAtom)2 Record (org.apache.poi.hslf.record.Record)2