1 2 17 18 19 20 package org.apache.poi.hssf.record; 21 22 23 24 import org.apache.poi.util.*; 25 26 35 public class TextObjectBaseRecord 36 extends Record 37 { 38 public final static short sid = 0x1B6; 39 private short field_1_options; 40 private BitField reserved1 = new BitField(0x1); 41 private BitField HorizontalTextAlignment = new BitField(0x000E); 42 public final static short HORIZONTAL_TEXT_ALIGNMENT_LEFT_ALIGNED = 1; 43 public final static short HORIZONTAL_TEXT_ALIGNMENT_CENTERED = 2; 44 public final static short HORIZONTAL_TEXT_ALIGNMENT_RIGHT_ALIGNED = 3; 45 public final static short HORIZONTAL_TEXT_ALIGNMENT_JUSTIFIED = 4; 46 private BitField VerticalTextAlignment = new BitField(0x0070); 47 public final static short VERTICAL_TEXT_ALIGNMENT_TOP = 1; 48 public final static short VERTICAL_TEXT_ALIGNMENT_CENTER = 2; 49 public final static short VERTICAL_TEXT_ALIGNMENT_BOTTOM = 3; 50 public final static short VERTICAL_TEXT_ALIGNMENT_JUSTIFY = 4; 51 private BitField reserved2 = new BitField(0x0180); 52 private BitField textLocked = new BitField(0x200); 53 private BitField reserved3 = new BitField(0xFC00); 54 private short field_2_textOrientation; 55 public final static short TEXT_ORIENTATION_NONE = 0; 56 public final static short TEXT_ORIENTATION_TOP_TO_BOTTOM = 1; 57 public final static short TEXT_ORIENTATION_ROT_RIGHT = 2; 58 public final static short TEXT_ORIENTATION_ROT_LEFT = 3; 59 private short field_3_reserved4; 60 private short field_4_reserved5; 61 private short field_5_reserved6; 62 private short field_6_textLength; 63 private short field_7_formattingRunLength; 64 private int field_8_reserved7; 65 66 67 public TextObjectBaseRecord() 68 { 69 70 } 71 72 80 81 public TextObjectBaseRecord(short id, short size, byte [] data) 82 { 83 super(id, size, data); 84 85 } 86 87 96 97 public TextObjectBaseRecord(short id, short size, byte [] data, int offset) 98 { 99 super(id, size, data, offset); 100 101 } 102 103 108 protected void validateSid(short id) 109 { 110 if (id != sid) 111 { 112 throw new RecordFormatException("Not a TextObjectBase record"); 113 } 114 } 115 116 protected void fillFields(byte [] data, short size, int offset) 117 { 118 119 int pos = 0; 120 field_1_options = LittleEndian.getShort(data, pos + 0x0 + offset); 121 field_2_textOrientation = LittleEndian.getShort(data, pos + 0x2 + offset); 122 field_3_reserved4 = LittleEndian.getShort(data, pos + 0x4 + offset); 123 field_4_reserved5 = LittleEndian.getShort(data, pos + 0x6 + offset); 124 field_5_reserved6 = LittleEndian.getShort(data, pos + 0x8 + offset); 125 field_6_textLength = LittleEndian.getShort(data, pos + 0xa + offset); 126 field_7_formattingRunLength = LittleEndian.getShort(data, pos + 0xc + offset); 127 field_8_reserved7 = LittleEndian.getInt(data, pos + 0xe + offset); 128 129 } 130 131 public String toString() 132 { 133 StringBuffer buffer = new StringBuffer (); 134 135 buffer.append("[TXO]\n"); 136 buffer.append(" .options = ") 137 .append("0x").append(HexDump.toHex( getOptions ())) 138 .append(" (").append( getOptions() ).append(" )"); 139 buffer.append(System.getProperty("line.separator")); 140 buffer.append(" .reserved1 = ").append(isReserved1()).append('\n'); 141 buffer.append(" .HorizontalTextAlignment = ").append(getHorizontalTextAlignment()).append('\n'); 142 buffer.append(" .VerticalTextAlignment = ").append(getVerticalTextAlignment()).append('\n'); 143 buffer.append(" .reserved2 = ").append(getReserved2()).append('\n'); 144 buffer.append(" .textLocked = ").append(isTextLocked()).append('\n'); 145 buffer.append(" .reserved3 = ").append(getReserved3()).append('\n'); 146 buffer.append(" .textOrientation = ") 147 .append("0x").append(HexDump.toHex( getTextOrientation ())) 148 .append(" (").append( getTextOrientation() ).append(" )"); 149 buffer.append(System.getProperty("line.separator")); 150 buffer.append(" .reserved4 = ") 151 .append("0x").append(HexDump.toHex( getReserved4 ())) 152 .append(" (").append( getReserved4() ).append(" )"); 153 buffer.append(System.getProperty("line.separator")); 154 buffer.append(" .reserved5 = ") 155 .append("0x").append(HexDump.toHex( getReserved5 ())) 156 .append(" (").append( getReserved5() ).append(" )"); 157 buffer.append(System.getProperty("line.separator")); 158 buffer.append(" .reserved6 = ") 159 .append("0x").append(HexDump.toHex( getReserved6 ())) 160 .append(" (").append( getReserved6() ).append(" )"); 161 buffer.append(System.getProperty("line.separator")); 162 buffer.append(" .textLength = ") 163 .append("0x").append(HexDump.toHex( getTextLength ())) 164 .append(" (").append( getTextLength() ).append(" )"); 165 buffer.append(System.getProperty("line.separator")); 166 buffer.append(" .formattingRunLength = ") 167 .append("0x").append(HexDump.toHex( getFormattingRunLength ())) 168 .append(" (").append( getFormattingRunLength() ).append(" )"); 169 buffer.append(System.getProperty("line.separator")); 170 buffer.append(" .reserved7 = ") 171 .append("0x").append(HexDump.toHex( getReserved7 ())) 172 .append(" (").append( getReserved7() ).append(" )"); 173 buffer.append(System.getProperty("line.separator")); 174 175 buffer.append("[/TXO]\n"); 176 return buffer.toString(); 177 } 178 179 public int serialize(int offset, byte[] data) 180 { 181 int pos = 0; 182 183 LittleEndian.putShort(data, 0 + offset, sid); 184 LittleEndian.putShort(data, 2 + offset, (short)(getRecordSize() - 4)); 185 186 LittleEndian.putShort(data, 4 + offset + pos, field_1_options); 187 LittleEndian.putShort(data, 6 + offset + pos, field_2_textOrientation); 188 LittleEndian.putShort(data, 8 + offset + pos, field_3_reserved4); 189 LittleEndian.putShort(data, 10 + offset + pos, field_4_reserved5); 190 LittleEndian.putShort(data, 12 + offset + pos, field_5_reserved6); 191 LittleEndian.putShort(data, 14 + offset + pos, field_6_textLength); 192 LittleEndian.putShort(data, 16 + offset + pos, field_7_formattingRunLength); 193 LittleEndian.putInt(data, 18 + offset + pos, field_8_reserved7); 194 195 return getRecordSize(); 196 } 197 198 201 public int getRecordSize() 202 { 203 return 4 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 4; 204 } 205 206 public short getSid() 207 { 208 return this.sid; 209 } 210 211 public Object clone() { 212 TextObjectBaseRecord rec = new TextObjectBaseRecord(); 213 214 rec.field_1_options = field_1_options; 215 rec.field_2_textOrientation = field_2_textOrientation; 216 rec.field_3_reserved4 = field_3_reserved4; 217 rec.field_4_reserved5 = field_4_reserved5; 218 rec.field_5_reserved6 = field_5_reserved6; 219 rec.field_6_textLength = field_6_textLength; 220 rec.field_7_formattingRunLength = field_7_formattingRunLength; 221 rec.field_8_reserved7 = field_8_reserved7; 222 return rec; 223 } 224 225 226 227 228 231 public short getOptions() 232 { 233 return field_1_options; 234 } 235 236 239 public void setOptions(short field_1_options) 240 { 241 this.field_1_options = field_1_options; 242 } 243 244 253 public short getTextOrientation() 254 { 255 return field_2_textOrientation; 256 } 257 258 268 public void setTextOrientation(short field_2_textOrientation) 269 { 270 this.field_2_textOrientation = field_2_textOrientation; 271 } 272 273 276 public short getReserved4() 277 { 278 return field_3_reserved4; 279 } 280 281 284 public void setReserved4(short field_3_reserved4) 285 { 286 this.field_3_reserved4 = field_3_reserved4; 287 } 288 289 292 public short getReserved5() 293 { 294 return field_4_reserved5; 295 } 296 297 300 public void setReserved5(short field_4_reserved5) 301 { 302 this.field_4_reserved5 = field_4_reserved5; 303 } 304 305 308 public short getReserved6() 309 { 310 return field_5_reserved6; 311 } 312 313 316 public void setReserved6(short field_5_reserved6) 317 { 318 this.field_5_reserved6 = field_5_reserved6; 319 } 320 321 324 public short getTextLength() 325 { 326 return field_6_textLength; 327 } 328 329 332 public void setTextLength(short field_6_textLength) 333 { 334 this.field_6_textLength = field_6_textLength; 335 } 336 337 340 public short getFormattingRunLength() 341 { 342 return field_7_formattingRunLength; 343 } 344 345 348 public void setFormattingRunLength(short field_7_formattingRunLength) 349 { 350 this.field_7_formattingRunLength = field_7_formattingRunLength; 351 } 352 353 356 public int getReserved7() 357 { 358 return field_8_reserved7; 359 } 360 361 364 public void setReserved7(int field_8_reserved7) 365 { 366 this.field_8_reserved7 = field_8_reserved7; 367 } 368 369 373 public void setReserved1(boolean value) 374 { 375 field_1_options = reserved1.setShortBoolean(field_1_options, value); 376 } 377 378 382 public boolean isReserved1() 383 { 384 return reserved1.isSet(field_1_options); 385 } 386 387 391 public void setHorizontalTextAlignment(short value) 392 { 393 field_1_options = HorizontalTextAlignment.setShortValue(field_1_options, value); 394 } 395 396 400 public short getHorizontalTextAlignment() 401 { 402 return HorizontalTextAlignment.getShortValue(field_1_options); 403 } 404 405 409 public void setVerticalTextAlignment(short value) 410 { 411 field_1_options = VerticalTextAlignment.setShortValue(field_1_options, value); 412 } 413 414 418 public short getVerticalTextAlignment() 419 { 420 return VerticalTextAlignment.getShortValue(field_1_options); 421 } 422 423 427 public void setReserved2(short value) 428 { 429 field_1_options = reserved2.setShortValue(field_1_options, value); 430 } 431 432 436 public short getReserved2() 437 { 438 return reserved2.getShortValue(field_1_options); 439 } 440 441 445 public void setTextLocked(boolean value) 446 { 447 field_1_options = textLocked.setShortBoolean(field_1_options, value); 448 } 449 450 454 public boolean isTextLocked() 455 { 456 return textLocked.isSet(field_1_options); 457 } 458 459 463 public void setReserved3(short value) 464 { 465 field_1_options = reserved3.setShortValue(field_1_options, value); 466 } 467 468 472 public short getReserved3() 473 { 474 return reserved3.getShortValue(field_1_options); 475 } 476 477 478 } 480 481 482 483 | Popular Tags |