1 2 17 18 19 20 package org.apache.poi.hwpf.model; 21 22 23 import org.apache.poi.util.LittleEndian; 24 25 import org.apache.poi.hwpf.usermodel.ParagraphProperties; 26 import org.apache.poi.hwpf.sprm.ParagraphSprmUncompressor; 27 import org.apache.poi.hwpf.sprm.SprmBuffer; 28 import org.apache.poi.hwpf.sprm.SprmOperation; 29 30 35 36 public class PAPX extends PropertyNode 37 { 38 39 private ParagraphHeight _phe; 40 private int _hugeGrpprlOffset = -1; 41 42 public PAPX(int fcStart, int fcEnd, byte[] papx, ParagraphHeight phe, byte[] dataStream) 43 { 44 super(fcStart, fcEnd, new SprmBuffer(papx)); 45 _phe = phe; 46 SprmBuffer buf = findHuge(new SprmBuffer(papx), dataStream); 47 if(buf != null) 48 _buf = buf; 49 } 50 51 public PAPX(int fcStart, int fcEnd, SprmBuffer buf, byte[] dataStream) 52 { 53 super(fcStart, fcEnd, buf); 54 _phe = new ParagraphHeight(); 55 buf = findHuge(buf, dataStream); 56 if(buf != null) 57 _buf = buf; 58 } 59 60 private SprmBuffer findHuge(SprmBuffer buf, byte[] datastream) 61 { 62 byte[] grpprl = buf.toByteArray(); 63 if(grpprl.length==8 && datastream!=null) { 65 SprmOperation sprm = new SprmOperation(grpprl, 2); 66 if ((sprm.getOperation()==0x45 || sprm.getOperation()==0x46) 67 && sprm.getSizeCode() == 3) 68 { 69 int hugeGrpprlOffset = sprm.getOperand(); 70 if(hugeGrpprlOffset+1 < datastream.length) 71 { 72 int grpprlSize = LittleEndian.getShort(datastream, hugeGrpprlOffset); 73 if( hugeGrpprlOffset+grpprlSize < datastream.length) 74 { 75 byte[] hugeGrpprl = new byte[grpprlSize + 2]; 76 hugeGrpprl[0] = grpprl[0]; hugeGrpprl[1] = grpprl[1]; 78 System.arraycopy(datastream, hugeGrpprlOffset + 2, hugeGrpprl, 2, 80 grpprlSize); 81 _hugeGrpprlOffset = hugeGrpprlOffset; 83 return new SprmBuffer(hugeGrpprl); 84 } 85 } 86 } 87 } 88 return null; 89 } 90 91 92 public ParagraphHeight getParagraphHeight() 93 { 94 return _phe; 95 } 96 97 public byte[] getGrpprl() 98 { 99 return ((SprmBuffer)_buf).toByteArray(); 100 } 101 102 public int getHugeGrpprlOffset() 103 { 104 return _hugeGrpprlOffset; 105 } 106 107 public short getIstd() 108 { 109 byte[] buf = getGrpprl(); 110 if (buf.length == 0) 111 { 112 return 0; 113 } 114 else 115 { 116 return LittleEndian.getShort(buf); 117 } 118 } 119 120 public SprmBuffer getSprmBuf() 121 { 122 return (SprmBuffer)_buf; 123 } 124 125 public ParagraphProperties getParagraphProperties(StyleSheet ss) 126 { 127 short istd = getIstd(); 128 ParagraphProperties baseStyle = ss.getParagraphStyle(istd); 129 ParagraphProperties props = ParagraphSprmUncompressor.uncompressPAP(baseStyle, getGrpprl(), 2); 130 return props; 131 } 132 133 public boolean equals(Object o) 134 { 135 if (super.equals(o)) 136 { 137 return _phe.equals(((PAPX)o)._phe); 138 } 139 return false; 140 } 141 } 142 | Popular Tags |