001: /* ====================================================================
002: Licensed to the Apache Software Foundation (ASF) under one or more
003: contributor license agreements. See the NOTICE file distributed with
004: this work for additional information regarding copyright ownership.
005: The ASF licenses this file to You under the Apache License, Version 2.0
006: (the "License"); you may not use this file except in compliance with
007: the License. You may obtain a copy of the License at
008:
009: http://www.apache.org/licenses/LICENSE-2.0
010:
011: Unless required by applicable law or agreed to in writing, software
012: distributed under the License is distributed on an "AS IS" BASIS,
013: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: See the License for the specific language governing permissions and
015: limitations under the License.
016: ==================================================================== */
017:
018: package org.apache.poi.hwpf.sprm;
019:
020: import org.apache.poi.hwpf.usermodel.SectionProperties;
021: import org.apache.poi.hwpf.usermodel.BorderCode;
022:
023: public class SectionSprmUncompressor extends SprmUncompressor {
024: public SectionSprmUncompressor() {
025: }
026:
027: public static SectionProperties uncompressSEP(byte[] grpprl,
028: int offset) {
029: SectionProperties newProperties = new SectionProperties();
030:
031: SprmIterator sprmIt = new SprmIterator(grpprl, offset);
032:
033: while (sprmIt.hasNext()) {
034: SprmOperation sprm = (SprmOperation) sprmIt.next();
035: unCompressSEPOperation(newProperties, sprm);
036: }
037:
038: return newProperties;
039: }
040:
041: /**
042: * Used in decompression of a sepx. This performs an operation defined by
043: * a single sprm.
044: *
045: * @param newSEP The SectionProperty to perfrom the operation on.
046: * @param operand The operation to perform.
047: * @param param The operation's parameter.
048: * @param varParam The operation variable length parameter.
049: */
050: static void unCompressSEPOperation(SectionProperties newSEP,
051: SprmOperation sprm) {
052: switch (sprm.getOperation()) {
053: case 0:
054: newSEP.setCnsPgn((byte) sprm.getOperand());
055: break;
056: case 0x1:
057: newSEP.setIHeadingPgn((byte) sprm.getOperand());
058: break;
059: case 0x2:
060: byte[] buf = new byte[sprm.size() - 3];
061: System.arraycopy(sprm.getGrpprl(), sprm.getGrpprlOffset(),
062: buf, 0, buf.length);
063: newSEP.setOlstAnm(buf);
064: break;
065: case 0x3:
066: //not quite sure
067: break;
068: case 0x4:
069: //not quite sure
070: break;
071: case 0x5:
072: newSEP.setFEvenlySpaced(getFlag(sprm.getOperand()));
073: break;
074: case 0x6:
075: newSEP.setFUnlocked(getFlag(sprm.getOperand()));
076: break;
077: case 0x7:
078: newSEP.setDmBinFirst((short) sprm.getOperand());
079: break;
080: case 0x8:
081: newSEP.setDmBinOther((short) sprm.getOperand());
082: break;
083: case 0x9:
084: newSEP.setBkc((byte) sprm.getOperand());
085: break;
086: case 0xa:
087: newSEP.setFTitlePage(getFlag(sprm.getOperand()));
088: break;
089: case 0xb:
090: newSEP.setCcolM1((short) sprm.getOperand());
091: break;
092: case 0xc:
093: newSEP.setDxaColumns(sprm.getOperand());
094: break;
095: case 0xd:
096: newSEP.setFAutoPgn(getFlag(sprm.getOperand()));
097: break;
098: case 0xe:
099: newSEP.setNfcPgn((byte) sprm.getOperand());
100: break;
101: case 0xf:
102: newSEP.setDyaPgn((short) sprm.getOperand());
103: break;
104: case 0x10:
105: newSEP.setDxaPgn((short) sprm.getOperand());
106: break;
107: case 0x11:
108: newSEP.setFPgnRestart(getFlag(sprm.getOperand()));
109: break;
110: case 0x12:
111: newSEP.setFEndNote(getFlag(sprm.getOperand()));
112: break;
113: case 0x13:
114: newSEP.setLnc((byte) sprm.getOperand());
115: break;
116: case 0x14:
117: newSEP.setGrpfIhdt((byte) sprm.getOperand());
118: break;
119: case 0x15:
120: newSEP.setNLnnMod((short) sprm.getOperand());
121: break;
122: case 0x16:
123: newSEP.setDxaLnn(sprm.getOperand());
124: break;
125: case 0x17:
126: newSEP.setDyaHdrTop(sprm.getOperand());
127: break;
128: case 0x18:
129: newSEP.setDyaHdrBottom(sprm.getOperand());
130: break;
131: case 0x19:
132: newSEP.setFLBetween(getFlag(sprm.getOperand()));
133: break;
134: case 0x1a:
135: newSEP.setVjc((byte) sprm.getOperand());
136: break;
137: case 0x1b:
138: newSEP.setLnnMin((short) sprm.getOperand());
139: break;
140: case 0x1c:
141: newSEP.setPgnStart((short) sprm.getOperand());
142: break;
143: case 0x1d:
144: newSEP.setDmOrientPage((byte) sprm.getOperand());
145: break;
146: case 0x1e:
147:
148: //nothing
149: break;
150: case 0x1f:
151: newSEP.setXaPage(sprm.getOperand());
152: break;
153: case 0x20:
154: newSEP.setYaPage(sprm.getOperand());
155: break;
156: case 0x21:
157: newSEP.setDxaLeft(sprm.getOperand());
158: break;
159: case 0x22:
160: newSEP.setDxaRight(sprm.getOperand());
161: break;
162: case 0x23:
163: newSEP.setDyaTop(sprm.getOperand());
164: break;
165: case 0x24:
166: newSEP.setDyaBottom(sprm.getOperand());
167: break;
168: case 0x25:
169: newSEP.setDzaGutter(sprm.getOperand());
170: break;
171: case 0x26:
172: newSEP.setDmPaperReq((short) sprm.getOperand());
173: break;
174: case 0x27:
175: newSEP.setFPropMark(getFlag(sprm.getOperand()));
176: break;
177: case 0x28:
178: break;
179: case 0x29:
180: break;
181: case 0x2a:
182: break;
183: case 0x2b:
184: newSEP.setBrcTop(new BorderCode(sprm.getGrpprl(), sprm
185: .getGrpprlOffset()));
186: break;
187: case 0x2c:
188: newSEP.setBrcLeft(new BorderCode(sprm.getGrpprl(), sprm
189: .getGrpprlOffset()));
190: break;
191: case 0x2d:
192: newSEP.setBrcBottom(new BorderCode(sprm.getGrpprl(), sprm
193: .getGrpprlOffset()));
194: break;
195: case 0x2e:
196: newSEP.setBrcRight(new BorderCode(sprm.getGrpprl(), sprm
197: .getGrpprlOffset()));
198: break;
199: case 0x2f:
200: newSEP.setPgbProp(sprm.getOperand());
201: break;
202: case 0x30:
203: newSEP.setDxtCharSpace(sprm.getOperand());
204: break;
205: case 0x31:
206: newSEP.setDyaLinePitch(sprm.getOperand());
207: break;
208: case 0x33:
209: newSEP.setWTextFlow((short) sprm.getOperand());
210: break;
211: default:
212: break;
213: }
214:
215: }
216:
217: }
|