1 16 17 18 package org.apache.poi.hssf.model; 19 20 import org.apache.poi.ddf.*; 21 import org.apache.poi.hssf.record.*; 22 import org.apache.poi.hssf.usermodel.*; 23 24 30 public class TextboxShape 31 extends AbstractShape 32 { 33 private EscherContainerRecord spContainer; 34 private TextObjectRecord textObjectRecord; 35 private ObjRecord objRecord; 36 private EscherTextboxRecord escherTextbox; 37 38 44 TextboxShape( HSSFTextbox hssfShape, int shapeId ) 45 { 46 spContainer = createSpContainer( hssfShape, shapeId ); 47 objRecord = createObjRecord( hssfShape, shapeId ); 48 textObjectRecord = createTextObjectRecord( hssfShape, shapeId ); 49 } 50 51 54 private ObjRecord createObjRecord( HSSFTextbox hssfShape, int shapeId ) 55 { 56 HSSFShape shape = hssfShape; 57 58 ObjRecord obj = new ObjRecord(); 59 CommonObjectDataSubRecord c = new CommonObjectDataSubRecord(); 60 c.setObjectType( (short) ( (HSSFSimpleShape) shape ).getShapeType() ); 61 c.setObjectId( (short) ( shapeId ) ); 62 c.setLocked( true ); 63 c.setPrintable( true ); 64 c.setAutofill( true ); 65 c.setAutoline( true ); 66 EndSubRecord e = new EndSubRecord(); 67 68 obj.addSubRecord( c ); 69 obj.addSubRecord( e ); 70 71 return obj; 72 } 73 74 81 private EscherContainerRecord createSpContainer( HSSFTextbox hssfShape, int shapeId ) 82 { 83 HSSFTextbox shape = hssfShape; 84 85 EscherContainerRecord spContainer = new EscherContainerRecord(); 86 EscherSpRecord sp = new EscherSpRecord(); 87 EscherOptRecord opt = new EscherOptRecord(); 88 EscherRecord anchor = new EscherClientAnchorRecord(); 89 EscherClientDataRecord clientData = new EscherClientDataRecord(); 90 escherTextbox = new EscherTextboxRecord(); 91 92 spContainer.setRecordId( EscherContainerRecord.SP_CONTAINER ); 93 spContainer.setOptions( (short) 0x000F ); 94 sp.setRecordId( EscherSpRecord.RECORD_ID ); 95 sp.setOptions( (short) ( ( EscherAggregate.ST_TEXTBOX << 4 ) | 0x2 ) ); 96 97 sp.setShapeId( shapeId ); 98 sp.setFlags( EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HASSHAPETYPE ); 99 opt.setRecordId( EscherOptRecord.RECORD_ID ); 100 opt.addEscherProperty( new EscherSimpleProperty( EscherProperties.TEXT__TEXTID, 0 ) ); 102 opt.addEscherProperty( new EscherSimpleProperty( EscherProperties.TEXT__TEXTLEFT, shape.getMarginLeft() ) ); 103 opt.addEscherProperty( new EscherSimpleProperty( EscherProperties.TEXT__TEXTRIGHT, shape.getMarginRight() ) ); 104 opt.addEscherProperty( new EscherSimpleProperty( EscherProperties.TEXT__TEXTBOTTOM, shape.getMarginBottom() ) ); 105 opt.addEscherProperty( new EscherSimpleProperty( EscherProperties.TEXT__TEXTTOP, shape.getMarginTop() ) ); 106 addStandardOptions( shape, opt ); 107 HSSFAnchor userAnchor = shape.getAnchor(); 108 anchor = createAnchor( userAnchor ); 113 clientData.setRecordId( EscherClientDataRecord.RECORD_ID ); 114 clientData.setOptions( (short) 0x0000 ); 115 escherTextbox.setRecordId( EscherTextboxRecord.RECORD_ID ); 116 escherTextbox.setOptions( (short) 0x0000 ); 117 118 spContainer.addChildRecord( sp ); 119 spContainer.addChildRecord( opt ); 120 spContainer.addChildRecord( anchor ); 121 spContainer.addChildRecord( clientData ); 122 spContainer.addChildRecord( escherTextbox ); 123 124 return spContainer; 125 } 126 127 131 private TextObjectRecord createTextObjectRecord( HSSFTextbox hssfShape, int shapeId ) 132 { 133 HSSFTextbox shape = hssfShape; 134 135 TextObjectRecord obj = new TextObjectRecord(); 136 obj.setHorizontalTextAlignment( TextObjectRecord.HORIZONTAL_TEXT_ALIGNMENT_LEFT_ALIGNED ); 137 obj.setVerticalTextAlignment( TextObjectRecord.VERTICAL_TEXT_ALIGNMENT_TOP ); 138 obj.setTextLocked( true ); 139 obj.setTextOrientation( TextObjectRecord.TEXT_ORIENTATION_NONE ); 140 int frLength = ( shape.getString().numFormattingRuns() + 1 ) * 8; 141 obj.setFormattingRunLength( (short) frLength ); 142 obj.setTextLength( (short) shape.getString().length() ); 143 obj.setStr( shape.getString() ); 144 obj.setReserved7( 0 ); 145 146 return obj; 147 } 148 149 public EscherContainerRecord getSpContainer() 150 { 151 return spContainer; 152 } 153 154 public ObjRecord getObjRecord() 155 { 156 return objRecord; 157 } 158 159 public TextObjectRecord getTextObjectRecord() 160 { 161 return textObjectRecord; 162 } 163 164 public EscherRecord getEscherTextbox() 165 { 166 return escherTextbox; 167 } 168 } 169 | Popular Tags |