1 2 17 18 19 20 package org.apache.poi.hdf.model.hdftypes; 21 22 import org.apache.poi.util.LittleEndian; 23 28 29 public class StyleDescription implements HDFType 30 { 31 32 private static int PARAGRAPH_STYLE = 1; 33 private static int CHARACTER_STYLE = 2; 34 35 int _baseStyleIndex; 36 int _styleTypeCode; 37 int _numUPX; 38 byte[] _papx; 39 byte[] _chpx; 40 ParagraphProperties _pap; 41 CharacterProperties _chp; 42 43 public StyleDescription() 44 { 45 _pap = new ParagraphProperties(); 46 _chp = new CharacterProperties(); 47 } 48 public StyleDescription(byte[] std, int baseLength, boolean word9) 49 { 50 int infoShort = LittleEndian.getShort(std, 2); 51 _styleTypeCode = (infoShort & 0xf); 52 _baseStyleIndex = (infoShort & 0xfff0) >> 4; 53 54 infoShort = LittleEndian.getShort(std, 4); 55 _numUPX = infoShort & 0xf; 56 57 int nameLength = 0; 60 int multiplier = 1; 61 if(word9) 62 { 63 nameLength = LittleEndian.getShort(std, baseLength); 64 multiplier = 2; 65 } 66 else 67 { 68 nameLength = std[baseLength]; 69 } 70 int grupxStart = multiplier + ((nameLength + 1) * multiplier) + baseLength; 72 73 int offset = 0; 74 for(int x = 0; x < _numUPX; x++) 75 { 76 int upxSize = LittleEndian.getShort(std, grupxStart + offset); 77 if(_styleTypeCode == PARAGRAPH_STYLE) 78 { 79 if(x == 0) 80 { 81 _papx = new byte[upxSize]; 82 System.arraycopy(std, grupxStart + offset + 2, _papx, 0, upxSize); 83 } 84 else if(x == 1) 85 { 86 _chpx = new byte[upxSize]; 87 System.arraycopy(std, grupxStart + offset + 2, _chpx, 0, upxSize); 88 } 89 } 90 else if(_styleTypeCode == CHARACTER_STYLE && x == 0) 91 { 92 _chpx = new byte[upxSize]; 93 System.arraycopy(std, grupxStart + offset + 2, _chpx, 0, upxSize); 94 } 95 96 if(upxSize % 2 == 1) 97 { 98 ++upxSize; 99 } 100 offset += 2 + upxSize; 101 } 102 103 104 105 } 106 public int getBaseStyle() 107 { 108 return _baseStyleIndex; 109 } 110 public byte[] getCHPX() 111 { 112 return _chpx; 113 } 114 public byte[] getPAPX() 115 { 116 return _papx; 117 } 118 public ParagraphProperties getPAP() 119 { 120 return _pap; 121 } 122 public CharacterProperties getCHP() 123 { 124 return _chp; 125 } 126 public void setPAP(ParagraphProperties pap) 127 { 128 _pap = pap; 129 } 130 public void setCHP(CharacterProperties chp) 131 { 132 _chp = chp; 133 } 134 } 135 | Popular Tags |