1 16 17 package org.apache.poi.hssf.model; 18 19 import org.apache.poi.ddf.*; 20 import org.apache.poi.hssf.record.ObjRecord; 21 import org.apache.poi.hssf.record.EscherAggregate; 22 import org.apache.poi.hssf.record.CommonObjectDataSubRecord; 23 import org.apache.poi.hssf.record.EndSubRecord; 24 import org.apache.poi.hssf.usermodel.HSSFSimpleShape; 25 import org.apache.poi.hssf.usermodel.HSSFShape; 26 27 public class SimpleFilledShape 28 extends AbstractShape 29 { 30 private EscherContainerRecord spContainer; 31 private ObjRecord objRecord; 32 33 39 SimpleFilledShape( HSSFSimpleShape hssfShape, int shapeId ) 40 { 41 spContainer = createSpContainer( hssfShape, shapeId ); 42 objRecord = createObjRecord( hssfShape, shapeId ); 43 } 44 45 52 private EscherContainerRecord createSpContainer( HSSFSimpleShape hssfShape, int shapeId ) 53 { 54 HSSFShape shape = hssfShape; 55 56 EscherContainerRecord spContainer = new EscherContainerRecord(); 57 EscherSpRecord sp = new EscherSpRecord(); 58 EscherOptRecord opt = new EscherOptRecord(); 59 EscherClientDataRecord clientData = new EscherClientDataRecord(); 60 61 spContainer.setRecordId( EscherContainerRecord.SP_CONTAINER ); 62 spContainer.setOptions( (short) 0x000F ); 63 sp.setRecordId( EscherSpRecord.RECORD_ID ); 64 short shapeType = objTypeToShapeType( hssfShape.getShapeType() ); 65 sp.setOptions( (short) ( ( shapeType << 4 ) | 0x2 ) ); 66 sp.setShapeId( shapeId ); 67 sp.setFlags( EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HASSHAPETYPE ); 68 opt.setRecordId( EscherOptRecord.RECORD_ID ); 69 addStandardOptions(shape, opt); 70 EscherRecord anchor = createAnchor( shape.getAnchor() ); 71 clientData.setRecordId( EscherClientDataRecord.RECORD_ID ); 72 clientData.setOptions( (short) 0x0000 ); 73 74 spContainer.addChildRecord( sp ); 75 spContainer.addChildRecord( opt ); 76 spContainer.addChildRecord( anchor ); 77 spContainer.addChildRecord( clientData ); 78 79 return spContainer; 80 } 81 82 private short objTypeToShapeType( int objType ) 83 { 84 short shapeType; 85 if (objType == HSSFSimpleShape.OBJECT_TYPE_OVAL) 86 shapeType = EscherAggregate.ST_ELLIPSE; 87 else if (objType == HSSFSimpleShape.OBJECT_TYPE_RECTANGLE) 88 shapeType = EscherAggregate.ST_RECTANGLE; 89 else 90 throw new IllegalArgumentException ("Unable to handle an object of this type"); 91 return shapeType; 92 } 93 94 97 private ObjRecord createObjRecord( HSSFShape hssfShape, int shapeId ) 98 { 99 HSSFShape shape = hssfShape; 100 101 ObjRecord obj = new ObjRecord(); 102 CommonObjectDataSubRecord c = new CommonObjectDataSubRecord(); 103 c.setObjectType( (short) ( (HSSFSimpleShape) shape ).getShapeType() ); 104 c.setObjectId( (short) ( shapeId ) ); 105 c.setLocked( true ); 106 c.setPrintable( true ); 107 c.setAutofill( true ); 108 c.setAutoline( true ); 109 EndSubRecord e = new EndSubRecord(); 110 111 obj.addSubRecord( c ); 112 obj.addSubRecord( e ); 113 114 return obj; 115 } 116 117 public EscherContainerRecord getSpContainer() 118 { 119 return spContainer; 120 } 121 122 public ObjRecord getObjRecord() 123 { 124 return objRecord; 125 } 126 127 } 128 | Popular Tags |