001: /* ====================================================================
002: Licensed to the Apache Software Foundation (ASF) under one or more
003: contributor license agreements. See the NOTICE file distributed with
004: this work for additional information regarding copyright ownership.
005: The ASF licenses this file to You under the Apache License, Version 2.0
006: (the "License"); you may not use this file except in compliance with
007: the License. You may obtain a copy of the License at
008:
009: http://www.apache.org/licenses/LICENSE-2.0
010:
011: Unless required by applicable law or agreed to in writing, software
012: distributed under the License is distributed on an "AS IS" BASIS,
013: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: See the License for the specific language governing permissions and
015: limitations under the License.
016: ==================================================================== */
017:
018: package org.apache.poi.hssf.model;
019:
020: import org.apache.poi.ddf.*;
021: import org.apache.poi.hssf.record.*;
022: import org.apache.poi.hssf.usermodel.*;
023:
024: /**
025: * Represents a picture shape and creates all specific low level records.
026: *
027: * @author Glen Stampoultzis (glens at apache.org)
028: */
029: public class PictureShape extends AbstractShape {
030: private EscherContainerRecord spContainer;
031: private ObjRecord objRecord;
032:
033: /**
034: * Creates the line shape from the highlevel user shape. All low level
035: * records are created at this point.
036: *
037: * @param hssfShape The user model shape.
038: * @param shapeId The identifier to use for this shape.
039: */
040: PictureShape(HSSFSimpleShape hssfShape, int shapeId) {
041: spContainer = createSpContainer(hssfShape, shapeId);
042: objRecord = createObjRecord(hssfShape, shapeId);
043: }
044:
045: /**
046: * Creates the lowerlevel escher records for this shape.
047: */
048: private EscherContainerRecord createSpContainer(
049: HSSFSimpleShape hssfShape, int shapeId) {
050: HSSFPicture shape = (HSSFPicture) hssfShape;
051:
052: EscherContainerRecord spContainer = new EscherContainerRecord();
053: EscherSpRecord sp = new EscherSpRecord();
054: EscherOptRecord opt = new EscherOptRecord();
055: EscherRecord anchor;
056: EscherClientDataRecord clientData = new EscherClientDataRecord();
057:
058: spContainer.setRecordId(EscherContainerRecord.SP_CONTAINER);
059: spContainer.setOptions((short) 0x000F);
060: sp.setRecordId(EscherSpRecord.RECORD_ID);
061: sp
062: .setOptions((short) ((EscherAggregate.ST_PICTUREFRAME << 4) | 0x2));
063:
064: sp.setShapeId(shapeId);
065: sp.setFlags(EscherSpRecord.FLAG_HAVEANCHOR
066: | EscherSpRecord.FLAG_HASSHAPETYPE);
067: opt.setRecordId(EscherOptRecord.RECORD_ID);
068: // opt.addEscherProperty( new EscherBoolProperty( EscherProperties.PROTECTION__LOCKAGAINSTGROUPING, 0x00800080 ) );
069: opt.addEscherProperty(new EscherSimpleProperty(
070: EscherProperties.BLIP__BLIPTODISPLAY, false, true,
071: shape.getPictureIndex()));
072: // opt.addEscherProperty( new EscherComplexProperty( EscherProperties.BLIP__BLIPFILENAME, true, new byte[] { (byte)0x74, (byte)0x00, (byte)0x65, (byte)0x00, (byte)0x73, (byte)0x00, (byte)0x74, (byte)0x00, (byte)0x00, (byte)0x00 } ) );
073: // opt.addEscherProperty( new EscherSimpleProperty( EscherProperties.FILL__FILLTYPE, 0x00000003 ) );
074: addStandardOptions(shape, opt);
075: HSSFAnchor userAnchor = shape.getAnchor();
076: if (userAnchor.isHorizontallyFlipped())
077: sp.setFlags(sp.getFlags() | EscherSpRecord.FLAG_FLIPHORIZ);
078: if (userAnchor.isVerticallyFlipped())
079: sp.setFlags(sp.getFlags() | EscherSpRecord.FLAG_FLIPVERT);
080: anchor = createAnchor(userAnchor);
081: clientData.setRecordId(EscherClientDataRecord.RECORD_ID);
082: clientData.setOptions((short) 0x0000);
083:
084: spContainer.addChildRecord(sp);
085: spContainer.addChildRecord(opt);
086: spContainer.addChildRecord(anchor);
087: spContainer.addChildRecord(clientData);
088:
089: return spContainer;
090: }
091:
092: /**
093: * Creates the low level OBJ record for this shape.
094: */
095: private ObjRecord createObjRecord(HSSFShape hssfShape, int shapeId) {
096: HSSFShape shape = hssfShape;
097:
098: ObjRecord obj = new ObjRecord();
099: CommonObjectDataSubRecord c = new CommonObjectDataSubRecord();
100: c.setObjectType((short) ((HSSFSimpleShape) shape)
101: .getShapeType());
102: // c.setObjectId((short) ( 1 ));
103: c.setObjectId((short) (shapeId));
104: c.setLocked(true);
105: c.setPrintable(true);
106: c.setAutofill(true);
107: c.setAutoline(true);
108: // c.setReserved2( 0x012C0A84 );
109: c.setReserved2(0x0);
110: // UnknownRecord sub1 = new UnknownRecord( (short)0x7, (short)0x2, new byte[] { 0x09, 0x00 } );
111: // UnknownRecord sub2 = new UnknownRecord( (short)0x8, (short)0x2, new byte[] { 0x01, 0x00 } );
112: EndSubRecord e = new EndSubRecord();
113:
114: obj.addSubRecord(c);
115: // obj.addSubRecord( sub1 );
116: // obj.addSubRecord( sub2 );
117: obj.addSubRecord(e);
118:
119: return obj;
120: }
121:
122: public EscherContainerRecord getSpContainer() {
123: return spContainer;
124: }
125:
126: public ObjRecord getObjRecord() {
127: return objRecord;
128: }
129:
130: }
|