Search in sources :

Example 36 with EscherContainerRecord

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

the class HSLFSlideShow method addPicture.

@Override
public HSLFPictureData addPicture(byte[] data, PictureType format) throws IOException {
    if (format == null || format.nativeId == -1) {
        throw new IllegalArgumentException("Unsupported picture format: " + format);
    }
    HSLFPictureData pd = findPictureData(data);
    if (pd != null) {
        // identical picture was already added to the SlideShow
        return pd;
    }
    EscherContainerRecord bstore;
    EscherContainerRecord dggContainer = _documentRecord.getPPDrawingGroup().getDggContainer();
    bstore = (EscherContainerRecord) HSLFShape.getEscherChild(dggContainer, EscherContainerRecord.BSTORE_CONTAINER);
    if (bstore == null) {
        bstore = new EscherContainerRecord();
        bstore.setRecordId(EscherContainerRecord.BSTORE_CONTAINER);
        dggContainer.addChildBefore(bstore, EscherOptRecord.RECORD_ID);
    }
    HSLFPictureData pict = HSLFPictureData.create(format);
    pict.setData(data);
    int offset = _hslfSlideShow.addPicture(pict);
    EscherBSERecord bse = new EscherBSERecord();
    bse.setRecordId(EscherBSERecord.RECORD_ID);
    bse.setOptions((short) (0x0002 | (format.nativeId << 4)));
    bse.setSize(pict.getRawData().length + 8);
    byte[] uid = HSLFPictureData.getChecksum(data);
    bse.setUid(uid);
    bse.setBlipTypeMacOS((byte) format.nativeId);
    bse.setBlipTypeWin32((byte) format.nativeId);
    if (format == PictureType.EMF) {
        bse.setBlipTypeMacOS((byte) PictureType.PICT.nativeId);
    } else if (format == PictureType.WMF) {
        bse.setBlipTypeMacOS((byte) PictureType.PICT.nativeId);
    } else if (format == PictureType.PICT) {
        bse.setBlipTypeWin32((byte) PictureType.WMF.nativeId);
    }
    bse.setRef(0);
    bse.setOffset(offset);
    bse.setRemainingData(new byte[0]);
    bstore.addChildRecord(bse);
    int count = bstore.getChildRecords().size();
    bstore.setOptions((short) ((count << 4) | 0xF));
    return pict;
}
Also used : EscherContainerRecord(org.apache.poi.ddf.EscherContainerRecord) EscherBSERecord(org.apache.poi.ddf.EscherBSERecord)

Example 37 with EscherContainerRecord

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

the class HSLFTableCell method createSpContainer.

@Override
protected EscherContainerRecord createSpContainer(boolean isChild) {
    EscherContainerRecord ecr = super.createSpContainer(isChild);
    AbstractEscherOptRecord opt = getEscherOptRecord();
    setEscherProperty(opt, EscherProperties.TEXT__TEXTID, 0);
    setEscherProperty(opt, EscherProperties.TEXT__SIZE_TEXT_TO_FIT_SHAPE, 0x20000);
    setEscherProperty(opt, EscherProperties.FILL__NOFILLHITTEST, 0x150001);
    setEscherProperty(opt, EscherProperties.SHADOWSTYLE__SHADOWOBSURED, 0x20000);
    setEscherProperty(opt, EscherProperties.PROTECTION__LOCKAGAINSTGROUPING, 0x40000);
    return ecr;
}
Also used : EscherContainerRecord(org.apache.poi.ddf.EscherContainerRecord) AbstractEscherOptRecord(org.apache.poi.ddf.AbstractEscherOptRecord)

Example 38 with EscherContainerRecord

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

the class HSLFTextBox method createSpContainer.

/**
     * Create a new TextBox and initialize its internal structures
     *
     * @return the created <code>EscherContainerRecord</code> which holds shape data
     */
@Override
protected EscherContainerRecord createSpContainer(boolean isChild) {
    EscherContainerRecord ecr = super.createSpContainer(isChild);
    setShapeType(ShapeType.TEXT_BOX);
    //set default properties for a TextBox
    setEscherProperty(EscherProperties.FILL__FILLCOLOR, 0x8000004);
    setEscherProperty(EscherProperties.FILL__FILLBACKCOLOR, 0x8000000);
    setEscherProperty(EscherProperties.FILL__NOFILLHITTEST, 0x100000);
    setEscherProperty(EscherProperties.LINESTYLE__COLOR, 0x8000001);
    setEscherProperty(EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x80000);
    setEscherProperty(EscherProperties.SHADOWSTYLE__COLOR, 0x8000002);
    // init paragraphs
    getTextParagraphs();
    return ecr;
}
Also used : EscherContainerRecord(org.apache.poi.ddf.EscherContainerRecord)

Example 39 with EscherContainerRecord

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

the class HSSFShapeFactory method createShapeTree.

/**
     * build shape tree from escher container
     * @param container root escher container from which escher records must be taken
     * @param agg - EscherAggregate
     * @param out - shape container to which shapes must be added
     * @param root - node to create HSSFObjectData shapes
     */
public static void createShapeTree(EscherContainerRecord container, EscherAggregate agg, HSSFShapeContainer out, DirectoryNode root) {
    if (container.getRecordId() == EscherContainerRecord.SPGR_CONTAINER) {
        ObjRecord obj = null;
        EscherClientDataRecord clientData = ((EscherContainerRecord) container.getChild(0)).getChildById(EscherClientDataRecord.RECORD_ID);
        if (null != clientData) {
            obj = (ObjRecord) agg.getShapeToObjMapping().get(clientData);
        }
        HSSFShapeGroup group = new HSSFShapeGroup(container, obj);
        List<EscherContainerRecord> children = container.getChildContainers();
        // skip the first child record, it is group descriptor
        for (int i = 0; i < children.size(); i++) {
            EscherContainerRecord spContainer = children.get(i);
            if (i != 0) {
                createShapeTree(spContainer, agg, group, root);
            }
        }
        out.addShape(group);
    } else if (container.getRecordId() == EscherContainerRecord.SP_CONTAINER) {
        Map<EscherRecord, Record> shapeToObj = agg.getShapeToObjMapping();
        ObjRecord objRecord = null;
        TextObjectRecord txtRecord = null;
        for (EscherRecord record : container) {
            switch(record.getRecordId()) {
                case EscherClientDataRecord.RECORD_ID:
                    objRecord = (ObjRecord) shapeToObj.get(record);
                    break;
                case EscherTextboxRecord.RECORD_ID:
                    txtRecord = (TextObjectRecord) shapeToObj.get(record);
                    break;
                default:
                    break;
            }
        }
        if (objRecord == null) {
            throw new RecordFormatException("EscherClientDataRecord can't be found.");
        }
        if (isEmbeddedObject(objRecord)) {
            HSSFObjectData objectData = new HSSFObjectData(container, objRecord, root);
            out.addShape(objectData);
            return;
        }
        CommonObjectDataSubRecord cmo = (CommonObjectDataSubRecord) objRecord.getSubRecords().get(0);
        final HSSFShape shape;
        switch(cmo.getObjectType()) {
            case CommonObjectDataSubRecord.OBJECT_TYPE_PICTURE:
                shape = new HSSFPicture(container, objRecord);
                break;
            case CommonObjectDataSubRecord.OBJECT_TYPE_RECTANGLE:
                shape = new HSSFSimpleShape(container, objRecord, txtRecord);
                break;
            case CommonObjectDataSubRecord.OBJECT_TYPE_LINE:
                shape = new HSSFSimpleShape(container, objRecord);
                break;
            case CommonObjectDataSubRecord.OBJECT_TYPE_COMBO_BOX:
                shape = new HSSFCombobox(container, objRecord);
                break;
            case CommonObjectDataSubRecord.OBJECT_TYPE_MICROSOFT_OFFICE_DRAWING:
                EscherOptRecord optRecord = container.getChildById(EscherOptRecord.RECORD_ID);
                if (optRecord == null) {
                    shape = new HSSFSimpleShape(container, objRecord, txtRecord);
                } else {
                    EscherProperty property = optRecord.lookup(EscherProperties.GEOMETRY__VERTICES);
                    if (null != property) {
                        shape = new HSSFPolygon(container, objRecord, txtRecord);
                    } else {
                        shape = new HSSFSimpleShape(container, objRecord, txtRecord);
                    }
                }
                break;
            case CommonObjectDataSubRecord.OBJECT_TYPE_TEXT:
                shape = new HSSFTextbox(container, objRecord, txtRecord);
                break;
            case CommonObjectDataSubRecord.OBJECT_TYPE_COMMENT:
                shape = new HSSFComment(container, objRecord, txtRecord, agg.getNoteRecordByObj(objRecord));
                break;
            default:
                shape = new HSSFSimpleShape(container, objRecord, txtRecord);
        }
        out.addShape(shape);
    }
}
Also used : TextObjectRecord(org.apache.poi.hssf.record.TextObjectRecord) CommonObjectDataSubRecord(org.apache.poi.hssf.record.CommonObjectDataSubRecord) EscherRecord(org.apache.poi.ddf.EscherRecord) EscherOptRecord(org.apache.poi.ddf.EscherOptRecord) EscherProperty(org.apache.poi.ddf.EscherProperty) RecordFormatException(org.apache.poi.util.RecordFormatException) ObjRecord(org.apache.poi.hssf.record.ObjRecord) EscherClientDataRecord(org.apache.poi.ddf.EscherClientDataRecord) EscherContainerRecord(org.apache.poi.ddf.EscherContainerRecord) Map(java.util.Map)

Example 40 with EscherContainerRecord

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

the class TestOfficeDrawings method testWatermark.

/**
     * Tests watermark text extraction
     */
public void testWatermark() throws Exception {
    HWPFDocument hwpfDocument = HWPFTestDataSamples.openSampleFile("watermark.doc");
    OfficeDrawing drawing = hwpfDocument.getOfficeDrawingsHeaders().getOfficeDrawings().iterator().next();
    EscherContainerRecord escherContainerRecord = drawing.getOfficeArtSpContainer();
    EscherOptRecord officeArtFOPT = escherContainerRecord.getChildById((short) 0xF00B);
    EscherComplexProperty gtextUNICODE = (EscherComplexProperty) officeArtFOPT.lookup(0x00c0);
    String text = StringUtil.getFromUnicodeLE(gtextUNICODE.getComplexData());
    assertEquals("DRAFT CONTRACT\0", text);
}
Also used : HWPFDocument(org.apache.poi.hwpf.HWPFDocument) EscherContainerRecord(org.apache.poi.ddf.EscherContainerRecord) EscherComplexProperty(org.apache.poi.ddf.EscherComplexProperty) EscherOptRecord(org.apache.poi.ddf.EscherOptRecord)

Aggregations

EscherContainerRecord (org.apache.poi.ddf.EscherContainerRecord)53 EscherRecord (org.apache.poi.ddf.EscherRecord)17 EscherSpRecord (org.apache.poi.ddf.EscherSpRecord)17 EscherOptRecord (org.apache.poi.ddf.EscherOptRecord)11 EscherBSERecord (org.apache.poi.ddf.EscherBSERecord)8 EscherSimpleProperty (org.apache.poi.ddf.EscherSimpleProperty)8 AbstractEscherOptRecord (org.apache.poi.ddf.AbstractEscherOptRecord)6 EscherDgRecord (org.apache.poi.ddf.EscherDgRecord)6 DefaultEscherRecordFactory (org.apache.poi.ddf.DefaultEscherRecordFactory)5 ObjRecord (org.apache.poi.hssf.record.ObjRecord)5 EscherDggRecord (org.apache.poi.ddf.EscherDggRecord)4 EscherSpgrRecord (org.apache.poi.ddf.EscherSpgrRecord)4 EscherTextboxRecord (org.apache.poi.ddf.EscherTextboxRecord)4 Document (org.apache.poi.hslf.record.Document)4 PPDrawing (org.apache.poi.hslf.record.PPDrawing)4 LinkedList (java.util.LinkedList)3 EscherBoolProperty (org.apache.poi.ddf.EscherBoolProperty)3 EscherClientDataRecord (org.apache.poi.ddf.EscherClientDataRecord)3 EscherRGBProperty (org.apache.poi.ddf.EscherRGBProperty)3 ExObjRefAtom (org.apache.poi.hslf.record.ExObjRefAtom)3