Search in sources :

Example 6 with EscherProperty

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

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

the class HSSFPatriarch method containsChart.

/**
     * Does this HSSFPatriarch contain a chart?
     * (Technically a reference to a chart, since they
     * get stored in a different block of records)
     * FIXME - detect chart in all cases (only seems
     * to work on some charts so far)
     */
public boolean containsChart() {
    // TODO - support charts properly in usermodel
    // We're looking for a EscherOptRecord
    EscherOptRecord optRecord = (EscherOptRecord) _boundAggregate.findFirstWithId(EscherOptRecord.RECORD_ID);
    if (optRecord == null) {
        // No opt record, can't have chart
        return false;
    }
    for (Iterator<EscherProperty> it = optRecord.getEscherProperties().iterator(); it.hasNext(); ) {
        EscherProperty prop = it.next();
        if (prop.getPropertyNumber() == 896 && prop.isComplex()) {
            EscherComplexProperty cp = (EscherComplexProperty) prop;
            String str = StringUtil.getFromUnicodeLE(cp.getComplexData());
            if (str.equals("Chart 1\0")) {
                return true;
            }
        }
    }
    return false;
}
Also used : EscherComplexProperty(org.apache.poi.ddf.EscherComplexProperty) EscherOptRecord(org.apache.poi.ddf.EscherOptRecord) EscherProperty(org.apache.poi.ddf.EscherProperty)

Aggregations

EscherProperty (org.apache.poi.ddf.EscherProperty)7 EscherOptRecord (org.apache.poi.ddf.EscherOptRecord)3 AbstractEscherOptRecord (org.apache.poi.ddf.AbstractEscherOptRecord)2 EscherComplexProperty (org.apache.poi.ddf.EscherComplexProperty)2 EscherContainerRecord (org.apache.poi.ddf.EscherContainerRecord)2 EscherRecord (org.apache.poi.ddf.EscherRecord)2 EscherSimpleProperty (org.apache.poi.ddf.EscherSimpleProperty)2 Map (java.util.Map)1 EscherClientDataRecord (org.apache.poi.ddf.EscherClientDataRecord)1 EscherPropertyFactory (org.apache.poi.ddf.EscherPropertyFactory)1 CommonObjectDataSubRecord (org.apache.poi.hssf.record.CommonObjectDataSubRecord)1 ObjRecord (org.apache.poi.hssf.record.ObjRecord)1 TextObjectRecord (org.apache.poi.hssf.record.TextObjectRecord)1 Shadow (org.apache.poi.sl.usermodel.Shadow)1 RecordFormatException (org.apache.poi.util.RecordFormatException)1