initial check in

git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@353442 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Said Ryan Ackley 2003-11-10 11:55:11 +00:00
parent bfc44119e9
commit e3bff5f91b
26 changed files with 4352 additions and 0 deletions

View File

@ -0,0 +1,291 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache POI" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache POI", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.poi.hwpf;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.hwpf.usermodel.SectionRange;
import org.apache.poi.hwpf.usermodel.CharacterRange;
import org.apache.poi.hwpf.usermodel.ParagraphRange;
import org.apache.poi.hwpf.usermodel.CharacterProperties;
import org.apache.poi.hwpf.usermodel.ParagraphProperties;
import org.apache.poi.hwpf.usermodel.SectionProperties;
import org.apache.poi.hwpf.model.hdftypes.PropertyNode;
import org.apache.poi.hwpf.model.hdftypes.StyleSheet;
import org.apache.poi.hwpf.model.hdftypes.StyleDescription;
import org.apache.poi.hwpf.model.hdftypes.CHPBinTable;
import org.apache.poi.hwpf.model.hdftypes.CHPX;
import org.apache.poi.hwpf.model.hdftypes.PAPX;
import org.apache.poi.hwpf.model.hdftypes.SEPX;
import org.apache.poi.hwpf.model.hdftypes.PAPBinTable;
import org.apache.poi.hwpf.model.hdftypes.SectionTable;
import org.apache.poi.hwpf.model.hdftypes.TextPieceTable;
import org.apache.poi.hwpf.model.hdftypes.TextPiece;
import org.apache.poi.hwpf.sprm.CharacterSprmUncompressor;
import org.apache.poi.hwpf.sprm.SectionSprmUncompressor;
import org.apache.poi.hwpf.sprm.ParagraphSprmUncompressor;
import java.util.List;
import java.util.ArrayList;
import java.io.UnsupportedEncodingException;
import java.lang.ref.SoftReference;
public class Range
{
private int _start;
private int _end;
private HWPFDocument _doc;
private List _parentSections;
private List _parentParagraphs;
private List _parentCharacters;
private List _parentText;
private List _sections;
private List _paragraphs;
private List _characters;
private List _text;
protected Range(int start, int end, HWPFDocument doc)
{
_start = start;
_end = end;
_doc = doc;
_parentSections = _doc.getSectionTable().getSections();
_parentParagraphs = _doc.getParagraphTable().getParagraphs();
_parentCharacters = _doc.getCharacterTable().getTextRuns();
_parentText = _doc.getTextTable().getTextPieces();
}
protected Range(int start, int end, Range parent)
{
_start = start;
_end = end;
_doc = parent._doc;
_parentSections = parent._parentSections;
_parentParagraphs = parent._parentParagraphs;
_parentCharacters = parent._parentCharacters;
_parentText = parent._parentText;
}
public String text()
throws UnsupportedEncodingException
{
if (_text == null)
{
_text = initRangedList(_parentText, _start, _end);
}
StringBuffer sb = new StringBuffer();
int size = _text.size();
for (int x = 0; x < size; x++)
{
TextPiece tp = (TextPiece)_text.get(x);
String encoding = "Cp1252";
if (tp.usesUnicode())
{
encoding = "UTF-16LE";
}
String str = new String (tp.getBuf(), Math.max(_start, tp.getStart()), Math.min(_end, tp.getEnd()), encoding);
sb.append(str);
}
return sb.toString();
}
public int numSections()
{
if (_sections == null)
{
_sections = initRangedList(_parentSections, _start, _end);
}
return _sections.size();
}
public int numParagraphs()
{
if (_paragraphs == null)
{
_paragraphs = initRangedList(_parentParagraphs, _start, _end);
}
return _paragraphs.size();
}
public int numCharacterRuns()
{
if (_characters == null)
{
_characters = initRangedList(_parentCharacters, _start, _end);
}
return _characters.size();
}
public CharacterProperties getCharacterRun(int index)
{
CHPX chpx = (CHPX)_characters.get(index);
CharacterProperties chp = (CharacterProperties)chpx.getCacheContents();
if (chp == null)
{
List paragraphList = initRangedList(_paragraphs, chpx.getStart(),
chpx.getEnd());
PAPX papx = (PAPX)paragraphList.get(0);
short istd = LittleEndian.getShort(papx.getBuf());
StyleSheet sd = _doc.getStyleSheet();
CharacterProperties baseStyle = sd.getCharacterStyle(istd);
chp = CharacterSprmUncompressor.uncompressCHP(baseStyle, chpx.getBuf(), 0);
chpx.fillCache(chp);
}
return chp;
}
public SectionProperties getSection(int index)
{
SEPX sepx = (SEPX)_sections.get(index);
SectionProperties sep = (SectionProperties)sepx.getCacheContents();
if (sep == null)
{
sep = SectionSprmUncompressor.uncompressSEP(new SectionProperties(), sepx.getBuf(), 0);
sepx.fillCache(sep);
}
return sep;
}
public ParagraphProperties getParagraph(int index)
{
PAPX papx = (PAPX)_sections.get(index);
ParagraphProperties pap = (ParagraphProperties)papx.getCacheContents();
if (pap == null)
{
short istd = LittleEndian.getShort(papx.getBuf());
StyleSheet sd = _doc.getStyleSheet();
ParagraphProperties baseStyle = sd.getParagraphStyle(istd);
pap = ParagraphSprmUncompressor.uncompressPAP(baseStyle, papx.getBuf(), 2);
papx.fillCache(pap);
}
return pap;
}
public SectionRange getSectionRange(int index)
{
if (_sections == null)
{
_sections = initRangedList(_doc.getSectionTable().getSections(), _start, _end);
}
PropertyNode node = (PropertyNode)_sections.get(index);
return new SectionRange(Math.max(_start, node.getStart()),
Math.min(_end, node.getEnd()), this);
}
public ParagraphRange getParagraphRange(int index)
{
if (_paragraphs == null)
{
_paragraphs = initRangedList(_doc.getParagraphTable().getParagraphs(), _start, _end);
}
PropertyNode node = (PropertyNode)_paragraphs.get(index);
return new ParagraphRange(Math.max(_start, node.getStart()),
Math.min(_end, node.getEnd()),this);
}
public CharacterRange getCharacterRange(int index)
{
if (_characters == null)
{
_characters = initRangedList(_doc.getCharacterTable().getTextRuns(), _start, _end);
}
PropertyNode node = (PropertyNode)_characters.get(index);
return new CharacterRange(Math.max(_start, node.getStart()),
Math.min(_end, node.getEnd()), this);
}
public SectionRange sections()
{
return new SectionRange(_start, _end, _doc);
}
public ParagraphRange paragraphs()
{
return new ParagraphRange(_start, _end, _doc);
}
public CharacterRange characterRuns()
{
return new CharacterRange(_start, _end, _doc);
}
private List initRangedList(List rpl, int start, int end)
{
int x = 0;
PropertyNode node = (PropertyNode)rpl.get(x);
while(node.getStart() < start)
{
x++;
node = (PropertyNode)rpl.get(x);
}
int y = x;
node = (PropertyNode)rpl.get(y);
while(node.getEnd() > end)
{
y++;
node = (PropertyNode)rpl.get(y);
}
return rpl.subList(x, y + 1);
}
}

View File

@ -0,0 +1,116 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache POI" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache POI", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.poi.hwpf.model.hdftypes;
import org.apache.poi.util.LittleEndian;
public class ListFormatOverride
{
int _lsid;
int _reserved1;
int _reserved2;
byte _clfolvl;
byte[] _reserved3 = new byte[3];
ListFormatOverrideLevel[] _levelOverrides;
public ListFormatOverride(byte[] buf, int offset)
{
_lsid = LittleEndian.getInt(buf, offset);
offset += LittleEndian.INT_SIZE;
_reserved1 = LittleEndian.getInt(buf, offset);
offset += LittleEndian.INT_SIZE;
_reserved2 = LittleEndian.getInt(buf, offset);
offset += LittleEndian.INT_SIZE;
_clfolvl = buf[offset++];
System.arraycopy(buf, offset, _reserved3, 0, _reserved3.length);
_levelOverrides = new ListFormatOverrideLevel[_clfolvl];
}
public int numOverrides()
{
return _clfolvl;
}
public int getLsid()
{
return _lsid;
}
public ListFormatOverrideLevel[] getLevelOverrides()
{
return _levelOverrides;
}
public void setOverride(int index, ListFormatOverrideLevel lfolvl)
{
_levelOverrides[index] = lfolvl;
}
public byte[] toByteArray()
{
byte[] buf = new byte[16];
int offset = 0;
LittleEndian.putInt(buf, offset, _lsid);
offset += LittleEndian.INT_SIZE;
LittleEndian.putInt(buf, offset, _reserved1);
offset += LittleEndian.INT_SIZE;
LittleEndian.putInt(buf, offset, _reserved2);
offset += LittleEndian.INT_SIZE;
buf[offset++] = _clfolvl;
System.arraycopy(_reserved3, 0, buf, offset, 3);
return buf;
}
}

View File

@ -0,0 +1,106 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache POI" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache POI", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.poi.hwpf.model.hdftypes;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.BitField;
public class ListFormatOverrideLevel
{
private static final int BASE_SIZE = 8;
int _iStartAt;
byte _info;
private static BitField _ilvl = new BitField(0xf);
private static BitField _fStartAt = new BitField(0x10);
private static BitField _fFormatting = new BitField(0x20);
byte[] _reserved = new byte[3];
ListLevel _lvl;
public ListFormatOverrideLevel(byte[] buf, int offset)
{
_iStartAt = LittleEndian.getInt(buf, offset);
offset += LittleEndian.INT_SIZE;
_info = buf[offset++];
System.arraycopy(buf, offset, _reserved, 0, _reserved.length);
offset += _reserved.length;
if (_fFormatting.getValue(_info) > 0)
{
_lvl = new ListLevel(buf, offset);
}
}
public int getSizeInBytes()
{
return (_lvl == null ? BASE_SIZE : BASE_SIZE + _lvl.getSizeInBytes());
}
public byte[] toByteArray()
{
byte[] buf = new byte[getSizeInBytes()];
int offset = 0;
LittleEndian.putInt(buf, _iStartAt);
offset += LittleEndian.INT_SIZE;
buf[offset++] = _info;
System.arraycopy(_reserved, 0, buf, offset, 3);
byte[] levelBuf = _lvl.toByteArray();
System.arraycopy(levelBuf, 0, buf, offset, levelBuf.length);
return buf;
}
}

View File

@ -0,0 +1,159 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache POI" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache POI", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.poi.hwpf.model.hdftypes;
import org.apache.poi.util.BitField;
import org.apache.poi.util.LittleEndian;
public class ListLevel
{
private int _iStartAt;
private byte _nfc;
private byte _info;
private static BitField _jc;
private static BitField _fLegal;
private static BitField _fNoRestart;
private static BitField _fPrev;
private static BitField _fPrevSpace;
private static BitField _fWord6;
private byte[] _rgbxchNums;
private byte _ixchFollow;
private int _dxaSpace;
private int _dxaIndent;
private int _cbGrpprlChpx;
private int _cbGrpprlPapx;
private byte _reserved;
private byte[] _grpprlPapx;
private byte[] _grpprlChpx;
private char[] _numberText;
public ListLevel(byte[] buf, int offset)
{
_iStartAt = LittleEndian.getInt(buf, offset);
offset += LittleEndian.INT_SIZE;
_nfc = buf[offset++];
_info = buf[offset++];
_rgbxchNums = new byte[9];
for (int x = 0; x < 9; x++)
{
_rgbxchNums[x] = buf[offset++];
}
_ixchFollow = buf[offset++];
_dxaSpace = LittleEndian.getInt(buf, offset);
offset += LittleEndian.INT_SIZE;
_dxaIndent = LittleEndian.getInt(buf, offset);
offset += LittleEndian.INT_SIZE;
_cbGrpprlChpx = LittleEndian.getUnsignedByte(buf, offset++);
_cbGrpprlPapx = LittleEndian.getUnsignedByte(buf, offset++);
_reserved = buf[offset++];
_grpprlPapx = new byte[_cbGrpprlPapx];
_grpprlChpx = new byte[_cbGrpprlChpx];
System.arraycopy(buf, offset, _grpprlPapx, 0, _cbGrpprlPapx);
offset += _cbGrpprlPapx;
System.arraycopy(buf, offset, _grpprlChpx, 0, _cbGrpprlChpx);
offset += _cbGrpprlChpx;
int numberTextLength = LittleEndian.getShort(buf, offset);
_numberText = new char[numberTextLength];
offset += LittleEndian.SHORT_SIZE;
for (int x = 0; x < numberTextLength; x++)
{
_numberText[x] = (char)LittleEndian.getShort(buf, offset);
offset += LittleEndian.SHORT_SIZE;
}
}
public byte[] toByteArray()
{
byte[] buf = new byte[getSizeInBytes()];
int offset = 0;
LittleEndian.putInt(buf, offset, _iStartAt);
offset += LittleEndian.INT_SIZE;
buf[offset++] = _nfc;
buf[offset++] = _info;
System.arraycopy(_rgbxchNums, 0, buf, offset, _rgbxchNums.length);
offset += _rgbxchNums.length;
buf[offset++] = _ixchFollow;
LittleEndian.putInt(buf, offset, _dxaSpace);
offset += LittleEndian.INT_SIZE;
LittleEndian.putInt(buf, offset, _dxaIndent);
offset += LittleEndian.INT_SIZE;
LittleEndian.putInt(buf, offset, _cbGrpprlChpx);
offset += LittleEndian.INT_SIZE;
LittleEndian.putInt(buf, offset, _cbGrpprlPapx);
offset += LittleEndian.INT_SIZE;
System.arraycopy(_grpprlPapx, 0, buf, offset, _cbGrpprlPapx);
offset += _cbGrpprlPapx;
System.arraycopy(_grpprlChpx, 0, buf, offset, _cbGrpprlChpx);
offset += _cbGrpprlChpx;
LittleEndian.putShort(buf, offset, (short)_numberText.length);
offset += LittleEndian.SHORT_SIZE;
for (int x = 0; x < _numberText.length; x++)
{
LittleEndian.putShort(buf, offset, (short)_numberText[x]);
offset += LittleEndian.SHORT_SIZE;
}
return buf;
}
public int getSizeInBytes()
{
return 28 + _cbGrpprlChpx + _cbGrpprlPapx + _numberText.length + 2;
}
}

View File

@ -0,0 +1,164 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache POI" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache POI", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.poi.hwpf.model.hdftypes;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.hwpf.model.io.*;
import java.util.HashMap;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
public class ListTables
{
private static final int LIST_DATA_SIZE = 28;
private static final int LIST_FORMAT_OVERRIDE_SIZE = 16;
HashMap listMap = new HashMap();
HashMap overrideMap = new HashMap();
public ListTables(byte[] tableStream, int lstOffset, int lfoOffset)
{
// get the list data
int length = LittleEndian.getShort(tableStream, lstOffset);
lstOffset += LittleEndian.SHORT_SIZE;
int levelOffset = lstOffset + (length * LIST_DATA_SIZE);
for (int x = 0; x < length; x++)
{
ListData lst = new ListData(tableStream, lstOffset);
listMap.put(new Integer(lst.getLsid()), lst);
lstOffset += LIST_DATA_SIZE;
int num = lst.numLevels();
for (int y = 0; y < num; y++)
{
ListLevel lvl = new ListLevel(tableStream, levelOffset);
lst.setLevel(y, lvl);
levelOffset += lvl.getSizeInBytes();
}
}
// now get the list format overrides. The size is an int unlike the LST size
length = LittleEndian.getInt(tableStream, lfoOffset);
lfoOffset += LittleEndian.INT_SIZE;
int lfolvlOffset = LIST_FORMAT_OVERRIDE_SIZE * length + 4;
for (int x = 0; x < length; x++)
{
ListFormatOverride lfo = new ListFormatOverride(tableStream, lfoOffset);
lfoOffset += LIST_FORMAT_OVERRIDE_SIZE;
int num = lfo.numOverrides();
for (int y = 0; y < num; y++)
{
ListFormatOverrideLevel lfolvl = new ListFormatOverrideLevel(tableStream, lfolvlOffset);
lfo.setOverride(y, lfolvl);
lfolvlOffset += lfolvl.getSizeInBytes();
}
overrideMap.put(new Integer(lfo.getLsid()), lfo);
}
}
public void writeListDataTo(HWPFOutputStream tableStream)
throws IOException
{
Integer[] intList = (Integer[])listMap.keySet().toArray(new Integer[0]);
// use this stream as a buffer for the levels since their size varies.
ByteArrayOutputStream levelBuf = new ByteArrayOutputStream();
// use a byte array for the lists because we know their size.
byte[] listBuf = new byte[intList.length * LIST_DATA_SIZE];
for (int x = 0; x < intList.length; x++)
{
ListData lst = (ListData)listMap.get(intList[x]);
tableStream.write(lst.toByteArray());
ListLevel[] lvls = lst.getLevels();
for (int y = 0; y < lvls.length; y++)
{
levelBuf.write(lvls[y].toByteArray());
}
}
tableStream.write(levelBuf.toByteArray());
}
public void writeListOverridesTo(HWPFOutputStream tableStream)
throws IOException
{
Integer[] intList = (Integer[])overrideMap.keySet().toArray(new Integer[0]);
// use this stream as a buffer for the levels since their size varies.
ByteArrayOutputStream levelBuf = new ByteArrayOutputStream();
// use a byte array for the lists because we know their size.
byte[] overrideBuf = new byte[intList.length * LIST_FORMAT_OVERRIDE_SIZE];
for (int x = 0; x < intList.length; x++)
{
ListFormatOverride lfo = (ListFormatOverride)overrideMap.get(intList[x]);
tableStream.write(lfo.toByteArray());
ListFormatOverrideLevel[] lfolvls = lfo.getLevelOverrides();
for (int y = 0; y < lfolvls.length; y++)
{
levelBuf.write(lfolvls[y].toByteArray());
}
}
tableStream.write(levelBuf.toByteArray());
}
}

View File

@ -0,0 +1,82 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache POI" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache POI", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.poi.hwpf.model.hdftypes;
import java.util.Arrays;
public class UPX
{
private byte[] _upx;
public UPX(byte[] upx)
{
_upx = upx;
}
public byte[] getUPX()
{
return _upx;
}
public int size()
{
return _upx.length;
}
public boolean equals(Object o)
{
UPX upx = (UPX)o;
return Arrays.equals(_upx, upx._upx);
}
}

View File

@ -0,0 +1,640 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache POI" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache POI", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.poi.hwpf.sprm;
import org.apache.poi.hwpf.usermodel.CharacterProperties;
import org.apache.poi.hwpf.usermodel.DateAndTime;
import org.apache.poi.hwpf.usermodel.BorderCode;
import org.apache.poi.hwpf.usermodel.ShadingDescriptor;
import org.apache.poi.hwpf.model.hdftypes.StyleSheet;
import org.apache.poi.util.LittleEndian;
public class CharacterSprmUncompressor
{
public CharacterSprmUncompressor()
{
}
public static CharacterProperties uncompressCHP(CharacterProperties parent,
byte[] grpprl,
int offset)
{
CharacterProperties newProperties = null;
try
{
newProperties = (CharacterProperties) parent.clone();
}
catch (CloneNotSupportedException cnse)
{
throw new RuntimeException("There is no way this exception should happen!!");
}
SprmIterator sprmIt = new SprmIterator(grpprl, offset);
while (sprmIt.hasNext())
{
SprmOperation sprm = (SprmOperation)sprmIt.next();
unCompressCHPOperation(parent, newProperties, sprm);
}
return newProperties;
}
/**
* Used in decompression of a chpx. This performs an operation defined by
* a single sprm.
*
* @param oldCHP The base CharacterProperties.
* @param newCHP The current CharacterProperties.
* @param operand The operand defined by the sprm (See Word file format spec)
* @param param The parameter defined by the sprm (See Word file format spec)
* @param varParam The variable length parameter defined by the sprm. (See
* Word file format spec)
* @param grpprl The entire chpx that this operation is a part of.
* @param offset The offset in the grpprl of the next sprm
* @param styleSheet The StyleSheet for this document.
*/
static void unCompressCHPOperation (CharacterProperties oldCHP,
CharacterProperties newCHP,
SprmOperation sprm)
{
switch (sprm.getOperation())
{
case 0:
newCHP.setFRMarkDel (getFlag (sprm.getOperand()));
break;
case 0x1:
newCHP.setFRMark (getFlag (sprm.getOperand()));
break;
case 0x2:
newCHP.setFFldVanish (getFlag (sprm.getOperand()));
break;
case 0x3:
newCHP.setFcPic (sprm.getOperand());
newCHP.setFSpec (true);
break;
case 0x4:
newCHP.setIbstRMark ((short) sprm.getOperand());
break;
case 0x5:
newCHP.setDttmRMark (new DateAndTime(sprm.getGrpprl(), sprm.getGrpprlOffset()));
break;
case 0x6:
newCHP.setFData (getFlag (sprm.getOperand()));
break;
case 0x7:
//don't care about this
break;
case 0x8:
//short chsDiff = (short)((param & 0xff0000) >>> 16);
int operand =sprm.getOperand();
short chsDiff = (short) (operand & 0x0000ff);
newCHP.setFChsDiff (getFlag (chsDiff));
newCHP.setChse ((short) (operand & 0xffff00));
break;
case 0x9:
newCHP.setFSpec (true);
newCHP.setFtcSym ((short) LittleEndian.getShort (sprm.getGrpprl(), sprm.getGrpprlOffset()));
newCHP.setXchSym ((short) LittleEndian.getShort (sprm.getGrpprl(), sprm.getGrpprlOffset() + 2));
break;
case 0xa:
newCHP.setFOle2 (getFlag (sprm.getOperand()));
break;
case 0xb:
// Obsolete
break;
case 0xc:
newCHP.setIcoHighlight ((byte) sprm.getOperand());
newCHP.setFHighlight (getFlag (sprm.getOperand()));
break;
case 0xd:
// undocumented
break;
case 0xe:
newCHP.setFcObj (sprm.getOperand());
break;
case 0xf:
// undocumented
break;
case 0x10:
// undocumented
break;
// undocumented till 0x30
case 0x11:
break;
case 0x12:
break;
case 0x13:
break;
case 0x14:
break;
case 0x15:
break;
case 0x16:
break;
case 0x17:
break;
case 0x18:
break;
case 0x19:
break;
case 0x1a:
break;
case 0x1b:
break;
case 0x1c:
break;
case 0x1d:
break;
case 0x1e:
break;
case 0x1f:
break;
case 0x20:
break;
case 0x21:
break;
case 0x22:
break;
case 0x23:
break;
case 0x24:
break;
case 0x25:
break;
case 0x26:
break;
case 0x27:
break;
case 0x28:
break;
case 0x29:
break;
case 0x2a:
break;
case 0x2b:
break;
case 0x2c:
break;
case 0x2d:
break;
case 0x2e:
break;
case 0x2f:
break;
case 0x30:
newCHP.setIstd (sprm.getOperand());
break;
case 0x31:
//permutation vector for fast saves, who cares!
break;
case 0x32:
newCHP.setFBold (false);
newCHP.setFItalic (false);
newCHP.setFOutline (false);
newCHP.setFStrike (false);
newCHP.setFShadow (false);
newCHP.setFSmallCaps (false);
newCHP.setFCaps (false);
newCHP.setFVanish (false);
newCHP.setKul ((byte) 0);
newCHP.setIco ((byte) 0);
break;
case 0x33:
try
{
// preserve the fSpec setting from the original CHP
boolean fSpec = newCHP.isFSpec ();
newCHP = (CharacterProperties) oldCHP.clone ();
newCHP.setFSpec (fSpec);
}
catch (CloneNotSupportedException e)
{
//do nothing
}
return;
case 0x34:
// undocumented
break;
case 0x35:
newCHP.setFBold (getCHPFlag ((byte) sprm.getOperand(), oldCHP.isFBold ()));
break;
case 0x36:
newCHP.setFItalic (getCHPFlag ((byte) sprm.getOperand(), oldCHP.isFItalic ()));
break;
case 0x37:
newCHP.setFStrike (getCHPFlag ((byte) sprm.getOperand(), oldCHP.isFStrike ()));
break;
case 0x38:
newCHP.setFOutline (getCHPFlag ((byte) sprm.getOperand(), oldCHP.isFOutline ()));
break;
case 0x39:
newCHP.setFShadow (getCHPFlag ((byte) sprm.getOperand(), oldCHP.isFShadow ()));
break;
case 0x3a:
newCHP.setFSmallCaps (getCHPFlag ((byte) sprm.getOperand(), oldCHP.isFSmallCaps ()));
break;
case 0x3b:
newCHP.setFCaps (getCHPFlag ((byte) sprm.getOperand(), oldCHP.isFCaps ()));
break;
case 0x3c:
newCHP.setFVanish (getCHPFlag ((byte) sprm.getOperand(), oldCHP.isFVanish ()));
break;
case 0x3d:
newCHP.setFtcAscii ((short) sprm.getOperand());
break;
case 0x3e:
newCHP.setKul ((byte) sprm.getOperand());
break;
case 0x3f:
operand = sprm.getOperand();
int hps = operand & 0xff;
if (hps != 0)
{
newCHP.setHps (hps);
}
//byte cInc = (byte)(((byte)(param & 0xfe00) >>> 4) >> 1);
byte cInc = (byte) ((operand & 0xff00) >>> 8);
cInc = (byte) (cInc >>> 1);
if (cInc != 0)
{
newCHP.setHps (Math.max (newCHP.getHps () + (cInc * 2), 2));
}
//byte hpsPos = (byte)((param & 0xff0000) >>> 8);
byte hpsPos = (byte) ((operand & 0xff0000) >>> 16);
if (hpsPos != 0x80)
{
newCHP.setHpsPos (hpsPos);
}
boolean fAdjust = (operand & 0x0100) > 0;
if (fAdjust && hpsPos != 128 && hpsPos != 0 && oldCHP.getHpsPos () == 0)
{
newCHP.setHps (Math.max (newCHP.getHps () + ( -2), 2));
}
if (fAdjust && hpsPos == 0 && oldCHP.getHpsPos () != 0)
{
newCHP.setHps (Math.max (newCHP.getHps () + 2, 2));
}
break;
case 0x40:
newCHP.setDxaSpace (sprm.getOperand());
break;
case 0x41:
newCHP.setLidDefault ((short) sprm.getOperand());
break;
case 0x42:
newCHP.setIco ((byte) sprm.getOperand());
break;
case 0x43:
newCHP.setHps (sprm.getOperand());
break;
case 0x44:
byte hpsLvl = (byte) sprm.getOperand();
newCHP.setHps (Math.max (newCHP.getHps () + (hpsLvl * 2), 2));
break;
case 0x45:
newCHP.setHpsPos ((short) sprm.getOperand());
break;
case 0x46:
if (sprm.getOperand() != 0)
{
if (oldCHP.getHpsPos () == 0)
{
newCHP.setHps (Math.max (newCHP.getHps () + ( -2), 2));
}
}
else
{
if (oldCHP.getHpsPos () != 0)
{
newCHP.setHps (Math.max (newCHP.getHps () + 2, 2));
}
}
break;
case 0x47:
/*CharacterProperties genCHP = new CharacterProperties ();
genCHP.setFtcAscii (4);
genCHP = (CharacterProperties) unCompressProperty (varParam, genCHP,
styleSheet);
CharacterProperties styleCHP = styleSheet.getStyleDescription (oldCHP.
getBaseIstd ()).getCHP ();
if (genCHP.isFBold () == newCHP.isFBold ())
{
newCHP.setFBold (styleCHP.isFBold ());
}
if (genCHP.isFItalic () == newCHP.isFItalic ())
{
newCHP.setFItalic (styleCHP.isFItalic ());
}
if (genCHP.isFSmallCaps () == newCHP.isFSmallCaps ())
{
newCHP.setFSmallCaps (styleCHP.isFSmallCaps ());
}
if (genCHP.isFVanish () == newCHP.isFVanish ())
{
newCHP.setFVanish (styleCHP.isFVanish ());
}
if (genCHP.isFStrike () == newCHP.isFStrike ())
{
newCHP.setFStrike (styleCHP.isFStrike ());
}
if (genCHP.isFCaps () == newCHP.isFCaps ())
{
newCHP.setFCaps (styleCHP.isFCaps ());
}
if (genCHP.getFtcAscii () == newCHP.getFtcAscii ())
{
newCHP.setFtcAscii (styleCHP.getFtcAscii ());
}
if (genCHP.getFtcFE () == newCHP.getFtcFE ())
{
newCHP.setFtcFE (styleCHP.getFtcFE ());
}
if (genCHP.getFtcOther () == newCHP.getFtcOther ())
{
newCHP.setFtcOther (styleCHP.getFtcOther ());
}
if (genCHP.getHps () == newCHP.getHps ())
{
newCHP.setHps (styleCHP.getHps ());
}
if (genCHP.getHpsPos () == newCHP.getHpsPos ())
{
newCHP.setHpsPos (styleCHP.getHpsPos ());
}
if (genCHP.getKul () == newCHP.getKul ())
{
newCHP.setKul (styleCHP.getKul ());
}
if (genCHP.getDxaSpace () == newCHP.getDxaSpace ())
{
newCHP.setDxaSpace (styleCHP.getDxaSpace ());
}
if (genCHP.getIco () == newCHP.getIco ())
{
newCHP.setIco (styleCHP.getIco ());
}
if (genCHP.getLidDefault () == newCHP.getLidDefault ())
{
newCHP.setLidDefault (styleCHP.getLidDefault ());
}
if (genCHP.getLidFE () == newCHP.getLidFE ())
{
newCHP.setLidFE (styleCHP.getLidFE ());
}*/
break;
case 0x48:
newCHP.setIss ((byte) sprm.getOperand());
break;
case 0x49:
newCHP.setHps (LittleEndian.getShort (sprm.getGrpprl(), sprm.getGrpprlOffset()));
break;
case 0x4a:
int increment = LittleEndian.getShort (sprm.getGrpprl(), sprm.getGrpprlOffset());
newCHP.setHps (Math.max (newCHP.getHps () + increment, 8));
break;
case 0x4b:
newCHP.setHpsKern (sprm.getOperand());
break;
case 0x4c:
// unCompressCHPOperation (oldCHP, newCHP, 0x47, param, varParam,
// styleSheet, opSize);
break;
case 0x4d:
float percentage = (float) sprm.getOperand() / 100.0f;
int add = (int) ((float) percentage * (float) newCHP.getHps ());
newCHP.setHps (newCHP.getHps () + add);
break;
case 0x4e:
newCHP.setYsr ((byte) sprm.getOperand());
break;
case 0x4f:
newCHP.setFtcAscii ((short) sprm.getOperand());
break;
case 0x50:
newCHP.setFtcFE ((short) sprm.getOperand());
break;
case 0x51:
newCHP.setFtcOther ((short) sprm.getOperand());
break;
case 0x52:
// undocumented
break;
case 0x53:
newCHP.setFDStrike (getFlag (sprm.getOperand()));
break;
case 0x54:
newCHP.setFImprint (getFlag (sprm.getOperand()));
break;
case 0x55:
newCHP.setFSpec (getFlag (sprm.getOperand()));
break;
case 0x56:
newCHP.setFObj (getFlag (sprm.getOperand()));
break;
case 0x57:
byte[] buf = sprm.getGrpprl();
int offset = sprm.getGrpprlOffset();
newCHP.setFPropMark (buf[offset]);
newCHP.setIbstPropRMark ((short) LittleEndian.getShort (buf, offset + 1));
newCHP.setDttmPropRMark (new DateAndTime(buf, offset +3));
break;
case 0x58:
newCHP.setFEmboss (getFlag (sprm.getOperand()));
break;
case 0x59:
newCHP.setSfxtText ((byte) sprm.getOperand());
break;
// undocumented till 0x61
case 0x5a:
break;
case 0x5b:
break;
case 0x5c:
break;
case 0x5d:
break;
case 0x5e:
break;
case 0x5f:
break;
case 0x60:
break;
case 0x61:
break;
case 0x62:
byte[] xstDispFldRMark = new byte[32];
buf = sprm.getGrpprl();
offset = sprm.getGrpprlOffset();
newCHP.setFDispFldRMark (buf[offset]);
newCHP.setIbstDispFldRMark ((short) LittleEndian.getShort (buf, offset + 1));
newCHP.setDttmDispFldRMark (new DateAndTime(buf, offset + 3));
System.arraycopy (buf, offset + 7, xstDispFldRMark, 0, 32);
newCHP.setXstDispFldRMark (xstDispFldRMark);
break;
case 0x63:
newCHP.setIbstRMarkDel ((short) sprm.getOperand());
break;
case 0x64:
newCHP.setDttmRMarkDel (new DateAndTime(sprm.getGrpprl(), sprm.getGrpprlOffset()));
break;
case 0x65:
newCHP.setBrc (new BorderCode(sprm.getGrpprl(), sprm.getGrpprlOffset()));
break;
case 0x66:
newCHP.setShd (new ShadingDescriptor(sprm.getGrpprl(), sprm.getGrpprlOffset()));
break;
case 0x67:
// Obsolete
break;
case 0x68:
break;
// undocumented till 0x6c
case 0x69:
break;
case 0x6a:
break;
case 0x6b:
break;
case 0x6c:
break;
case 0x6d:
newCHP.setLidDefault ((short) sprm.getOperand());
break;
case 0x6e:
newCHP.setLidFE ((short) sprm.getOperand());
break;
case 0x6f:
newCHP.setIdctHint ((byte) sprm.getOperand());
break;
}
}
/**
* Converts an int into a boolean. If the int is non-zero, it returns true.
* Otherwise it returns false.
*
* @param x The int to convert.
*
* @return A boolean whose value depends on x.
*/
public static boolean getFlag (int x)
{
if (x != 0)
{
return true;
}
else
{
return false;
}
}
private static boolean getCHPFlag (byte x, boolean oldVal)
{
/*
switch(x)
{
case 0:
return false;
case 1:
return true;
case (byte)0x80:
return oldVal;
case (byte)0x81:
return !oldVal;
default:
return false;
}
*/
if (x == 0)
{
return false;
}
else if (x == 1)
{
return true;
}
else if ((x & 0x80) == 0x80)
{
return oldVal;
}
else if ((x & 0x81) == 0x81)
{
return!oldVal;
}
else
{
return false;
}
}
}

View File

@ -0,0 +1,515 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache POI" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache POI", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.poi.hwpf.sprm;
import org.apache.poi.hwpf.usermodel.ParagraphProperties;
import org.apache.poi.hwpf.usermodel.BorderCode;
import org.apache.poi.hwpf.usermodel.DateAndTime;
import org.apache.poi.hwpf.usermodel.LineSpacingDescriptor;
import org.apache.poi.util.LittleEndian;
import java.util.HashMap;
import java.util.Set;
import java.util.Iterator;
import java.util.Collections;
import java.util.ArrayList;
public class ParagraphSprmUncompressor
extends SprmUncompressor
{
public ParagraphSprmUncompressor()
{
}
public static ParagraphProperties uncompressPAP(ParagraphProperties parent,
byte[] grpprl,
int offset)
{
ParagraphProperties newProperties = null;
try
{
newProperties = (ParagraphProperties) parent.clone();
}
catch (CloneNotSupportedException cnse)
{
throw new RuntimeException("There is no way this exception should happen!!");
}
SprmIterator sprmIt = new SprmIterator(grpprl, offset);
while (sprmIt.hasNext())
{
SprmOperation sprm = (SprmOperation)sprmIt.next();
unCompressPAPOperation(newProperties, sprm);
}
return newProperties;
}
/**
* Performs an operation on a ParagraphProperties object. Used to uncompress
* from a papx.
*
* @param newPAP The ParagraphProperties object to perform the operation on.
* @param operand The operand that defines the operation.
* @param param The operation's parameter.
* @param varParam The operation's variable length parameter.
* @param grpprl The original papx.
* @param offset The current offset in the papx.
* @param spra A part of the sprm that defined this operation.
*/
static void unCompressPAPOperation (ParagraphProperties newPAP, SprmOperation sprm)
{
switch (sprm.getOperation())
{
case 0:
newPAP.setIstd (sprm.getOperand());
break;
case 0x1:
// Used only for piece table grpprl's not for PAPX
// int istdFirst = LittleEndian.getShort (varParam, 2);
// int istdLast = LittleEndian.getShort (varParam, 4);
// if ((newPAP.getIstd () > istdFirst) || (newPAP.getIstd () <= istdLast))
// {
// permuteIstd (newPAP, varParam, opSize);
// }
break;
case 0x2:
if (newPAP.getIstd () <= 9 || newPAP.getIstd () >= 1)
{
byte paramTmp = (byte) sprm.getOperand();
newPAP.setIstd (newPAP.getIstd () + paramTmp);
newPAP.setLvl ((byte) (newPAP.getLvl () + paramTmp));
if (((paramTmp >> 7) & 0x01) == 1)
{
newPAP.setIstd (Math.max (newPAP.getIstd (), 1));
}
else
{
newPAP.setIstd (Math.min (newPAP.getIstd (), 9));
}
}
break;
case 0x3:
newPAP.setJc ((byte) sprm.getOperand());
break;
case 0x4:
newPAP.setFSideBySide ((byte) sprm.getOperand());
break;
case 0x5:
newPAP.setFKeep ((byte) sprm.getOperand());
break;
case 0x6:
newPAP.setFKeepFollow ((byte) sprm.getOperand());
break;
case 0x7:
newPAP.setFPageBreakBefore ((byte) sprm.getOperand());
break;
case 0x8:
newPAP.setBrcl ((byte) sprm.getOperand());
break;
case 0x9:
newPAP.setBrcp ((byte) sprm.getOperand());
break;
case 0xa:
newPAP.setIlvl ((byte) sprm.getOperand());
break;
case 0xb:
newPAP.setIlfo (sprm.getOperand());
break;
case 0xc:
newPAP.setFNoLnn ((byte) sprm.getOperand());
break;
case 0xd:
/**handle tabs . variable parameter. seperate processing needed*/
handleTabs(newPAP, sprm);
break;
case 0xe:
newPAP.setDxaRight (sprm.getOperand());
break;
case 0xf:
newPAP.setDxaLeft (sprm.getOperand());
break;
case 0x10:
// sprmPNest is only stored in grpprls linked to a piece table.
newPAP.setDxaLeft (newPAP.getDxaLeft () + sprm.getOperand());
newPAP.setDxaLeft (Math.max (0, newPAP.getDxaLeft ()));
break;
case 0x11:
newPAP.setDxaLeft1 (sprm.getOperand());
break;
case 0x12:
newPAP.setLspd(new LineSpacingDescriptor(sprm.getGrpprl(), sprm.getGrpprlOffset()));
break;
case 0x13:
newPAP.setDyaBefore (sprm.getOperand());
break;
case 0x14:
newPAP.setDyaAfter (sprm.getOperand());
break;
case 0x15:
// fast saved only
//applySprmPChgTabs (newPAP, varParam, opSize);
break;
case 0x16:
newPAP.setFInTable ((byte) sprm.getOperand());
break;
case 0x17:
newPAP.setFTtp ((byte) sprm.getOperand());
break;
case 0x18:
newPAP.setDxaAbs (sprm.getOperand());
break;
case 0x19:
newPAP.setDyaAbs (sprm.getOperand());
break;
case 0x1a:
newPAP.setDxaWidth (sprm.getOperand());
break;
case 0x1b:
byte param = (byte)sprm.getOperand();
/** @todo handle paragraph postioning*/
byte pcVert = (byte) ((param & 0x0c) >> 2);
byte pcHorz = (byte) (param & 0x03);
if (pcVert != 3)
{
newPAP.setPcVert (pcVert);
}
if (pcHorz != 3)
{
newPAP.setPcHorz (pcHorz);
}
break;
// BrcXXX1 is older Version. Brc is used
case 0x1c:
//newPAP.setBrcTop1((short)param);
break;
case 0x1d:
//newPAP.setBrcLeft1((short)param);
break;
case 0x1e:
//newPAP.setBrcBottom1((short)param);
break;
case 0x1f:
//newPAP.setBrcRight1((short)param);
break;
case 0x20:
//newPAP.setBrcBetween1((short)param);
break;
case 0x21:
//newPAP.setBrcBar1((byte)param);
break;
case 0x22:
newPAP.setDxaFromText (sprm.getOperand());
break;
case 0x23:
newPAP.setWr((byte)sprm.getOperand());
break;
case 0x24:
newPAP.setBrcTop(new BorderCode(sprm.getGrpprl(), sprm.getGrpprlOffset()));
break;
case 0x25:
newPAP.setBrcLeft(new BorderCode(sprm.getGrpprl(), sprm.getGrpprlOffset()));
break;
case 0x26:
newPAP.setBrcBottom (new BorderCode(sprm.getGrpprl(), sprm.getGrpprlOffset()));
break;
case 0x27:
newPAP.setBrcRight (new BorderCode(sprm.getGrpprl(), sprm.getGrpprlOffset()));
break;
case 0x28:
newPAP.setBrcBetween (new BorderCode(sprm.getGrpprl(), sprm.getGrpprlOffset()));
break;
case 0x29:
newPAP.setBrcBar (new BorderCode(sprm.getGrpprl(), sprm.getGrpprlOffset()));
break;
case 0x2a:
newPAP.setFNoAutoHyph ((byte) sprm.getOperand());
break;
case 0x2b:
newPAP.setDyaHeight (sprm.getOperand());
break;
case 0x2c:
newPAP.setDcs ((short) sprm.getOperand());
break;
case 0x2d:
newPAP.setShd ((short) sprm.getOperand());
break;
case 0x2e:
newPAP.setDyaFromText (sprm.getOperand());
break;
case 0x2f:
newPAP.setDxaFromText (sprm.getOperand());
break;
case 0x30:
newPAP.setFLocked ((byte) sprm.getOperand());
break;
case 0x31:
newPAP.setFWidowControl ((byte) sprm.getOperand());
break;
case 0x32:
//undocumented
break;
case 0x33:
newPAP.setFKinsoku ((byte) sprm.getOperand());
break;
case 0x34:
newPAP.setFWordWrap ((byte) sprm.getOperand());
break;
case 0x35:
newPAP.setFOverflowPunct ((byte) sprm.getOperand());
break;
case 0x36:
newPAP.setFTopLinePunct ((byte) sprm.getOperand());
break;
case 0x37:
newPAP.setFAutoSpaceDE ((byte) sprm.getOperand());
break;
case 0x38:
newPAP.setFAutoSpaceDN ((byte) sprm.getOperand());
break;
case 0x39:
newPAP.setWAlignFont (sprm.getOperand());
break;
case 0x3a:
newPAP.setFontAlign ((short) sprm.getOperand());
break;
case 0x3b:
//obsolete
break;
case 0x3e:
{
byte[] buf = new byte[sprm.size() - 3];
System.arraycopy(buf, 0, sprm.getGrpprl(), sprm.getGrpprlOffset(),
buf.length);
newPAP.setAnld(buf);
break;
}
case 0x3f:
//don't really need this. spec is confusing regarding this
//sprm
try
{
byte[] varParam = sprm.getGrpprl();
int offset = sprm.getGrpprlOffset();
newPAP.setFPropRMark ((int) varParam[offset]);
newPAP.setIbstPropRMark ((int) LittleEndian.getShort (varParam, offset + 1));
newPAP.setDttmPropRMark (new DateAndTime(varParam, offset + 3));
}
catch (Exception e)
{
e.printStackTrace ();
}
break;
case 0x40:
//newPAP._lvl = param;
if (newPAP.getIstd () >= 1 && newPAP.getIstd () <= 9)
{
newPAP.setIlvl ((byte) sprm.getOperand());
}
break;
case 0x41:
// undocumented
break;
case 0x43:
//pap.fNumRMIns
newPAP.setFNumRMIns ((byte) sprm.getOperand());
break;
case 0x44:
//undocumented
break;
case 0x45:
if (sprm.getSizeCode() == 6)
{
byte[] buf = new byte[sprm.size() - 3];
System.arraycopy(buf, 0, sprm.getGrpprl(), sprm.getGrpprlOffset(), buf.length);
newPAP.setNumrm (buf);
}
else
{
/**@todo handle large PAPX from data stream*/
}
break;
case 0x47:
newPAP.setFUsePgsuSettings ((byte) sprm.getOperand());
break;
case 0x48:
newPAP.setFAdjustRight ((byte) sprm.getOperand());
break;
default:
break;
}
}
private static void handleTabs(ParagraphProperties pap, SprmOperation sprm)
{
byte[] grpprl = sprm.getGrpprl();
int offset = sprm.getGrpprlOffset();
int delSize = grpprl[offset++];
int[] tabPositions = pap.getRgdxaTab();
byte[] tabDescriptors = pap.getRgtbd();
HashMap tabMap = new HashMap();
for (int x = 0; x < tabPositions.length; x++)
{
tabMap.put(new Integer(tabPositions[x]), new Byte(tabDescriptors[x]));
}
for (int x = 0; x < delSize; x++)
{
tabMap.remove(new Integer(LittleEndian.getInt(grpprl, offset)));
offset += LittleEndian.INT_SIZE;;
}
int addSize = grpprl[offset++];
for (int x = 0; x < addSize; x++)
{
Integer key = new Integer(LittleEndian.getInt(grpprl, offset));
Byte val = new Byte(grpprl[(LittleEndian.INT_SIZE * (addSize - x)) + x]);
tabMap.put(key, val);
offset += LittleEndian.INT_SIZE;
}
tabPositions = new int[tabMap.size()];
tabDescriptors = new byte[tabPositions.length];
ArrayList list = new ArrayList();
Iterator keyIT = tabMap.keySet().iterator();
while (keyIT.hasNext())
{
list.add(keyIT.next());
}
Collections.sort(list);
for (int x = 0; x < tabPositions.length; x++)
{
Integer key = ((Integer)list.get(x));
tabPositions[x] = key.intValue();
tabDescriptors[x] = ((Byte)tabMap.get(key)).byteValue();
}
pap.setRgdxaTab(tabPositions);
pap.setRgtbd(tabDescriptors);
}
// private static void handleTabsAgain(ParagraphProperties pap, SprmOperation sprm)
// {
// byte[] grpprl = sprm.getGrpprl();
// int offset = sprm.getGrpprlOffset();
// int delSize = grpprl[offset++];
// int[] tabPositions = pap.getRgdxaTab();
// byte[] tabDescriptors = pap.getRgtbd();
//
// HashMap tabMap = new HashMap();
// for (int x = 0; x < tabPositions.length; x++)
// {
// tabMap.put(new Integer(tabPositions[x]), new Byte(tabDescriptors[x]));
// }
//
// for (int x = 0; x < delSize; x++)
// {
// tabMap.remove(new Integer(LittleEndian.getInt(grpprl, offset)));
// offset += LittleEndian.INT_SIZE;;
// }
//
// int addSize = grpprl[offset++];
// for (int x = 0; x < addSize; x++)
// {
// Integer key = new Integer(LittleEndian.getInt(grpprl, offset));
// Byte val = new Byte(grpprl[(LittleEndian.INT_SIZE * (addSize - x)) + x]);
// tabMap.put(key, val);
// offset += LittleEndian.INT_SIZE;
// }
//
// tabPositions = new int[tabMap.size()];
// tabDescriptors = new byte[tabPositions.length];
// ArrayList list = new ArrayList();
//
// Iterator keyIT = tabMap.keySet().iterator();
// while (keyIT.hasNext())
// {
// list.add(keyIT.next());
// }
// Collections.sort(list);
//
// for (int x = 0; x < tabPositions.length; x++)
// {
// Integer key = ((Integer)list.get(x));
// tabPositions[x] = key.intValue();
// tabDescriptors[x] = ((Byte)tabMap.get(key)).byteValue();
// }
//
// pap.setRgdxaTab(tabPositions);
// pap.setRgtbd(tabDescriptors);
// }
}

View File

@ -0,0 +1,272 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache POI" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache POI", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.poi.hwpf.sprm;
import java.util.ArrayList;
import java.util.Arrays;
import org.apache.poi.hwpf.model.hdftypes.definitions.SEPAbstractType;
import org.apache.poi.hwpf.usermodel.SectionProperties;
import org.apache.poi.util.LittleEndian;
public class SectionSprmCompressor
{
private final static SectionProperties DEFAULT_SEP = new SectionProperties();
public SectionSprmCompressor()
{
}
public static byte[] compressSectionProperty(SectionProperties newSEP,
SectionProperties oldSEP)
{
int size = 0;
ArrayList sprmList = new ArrayList();
if (newSEP.getCnsPgn() != DEFAULT_SEP.getCnsPgn())
{
size += SprmUtils.addSprm((short)0x3000, newSEP.getCnsPgn(), null, sprmList);
}
if (newSEP.getIHeadingPgn() != DEFAULT_SEP.getIHeadingPgn())
{
size += SprmUtils.addSprm((short)0x3001, newSEP.getIHeadingPgn(), null, sprmList);
}
if (!Arrays.equals(newSEP.getOlstAnm(), DEFAULT_SEP.getOlstAnm()))
{
size += SprmUtils.addSprm((short)0xD202, 0, newSEP.getOlstAnm(), sprmList);
}
if (newSEP.getFEvenlySpaced() != DEFAULT_SEP.getFEvenlySpaced())
{
size += SprmUtils.addSprm((short)0x3005, newSEP.getFEvenlySpaced() ? 1 : 0, null, sprmList);
}
if (newSEP.getFUnlocked() != DEFAULT_SEP.getFUnlocked())
{
size += SprmUtils.addSprm((short)0x3006, newSEP.getFUnlocked() ? 1 :0, null, sprmList);
}
if (newSEP.getDmBinFirst() != DEFAULT_SEP.getDmBinFirst())
{
size += SprmUtils.addSprm((short)0x5007, newSEP.getDmBinFirst(), null, sprmList);
}
if (newSEP.getDmBinOther() != DEFAULT_SEP.getDmBinOther())
{
size += SprmUtils.addSprm((short)0x5008, newSEP.getDmBinOther(), null, sprmList);
}
if (newSEP.getBkc() != DEFAULT_SEP.getBkc())
{
size += SprmUtils.addSprm((short)0x3009, newSEP.getBkc(), null, sprmList);
}
if (newSEP.getFTitlePage() != DEFAULT_SEP.getFTitlePage())
{
size += SprmUtils.addSprm((short)0x300A, newSEP.getFTitlePage() ? 1 : 0, null, sprmList);
}
if (newSEP.getCcolM1() != DEFAULT_SEP.getCcolM1())
{
size += SprmUtils.addSprm((short)0x500B, newSEP.getCcolM1(), null, sprmList);
}
if (newSEP.getDxaColumns() != DEFAULT_SEP.getDxaColumns())
{
size += SprmUtils.addSprm((short)0x900C, newSEP.getDxaColumns(), null, sprmList);
}
if (newSEP.getFAutoPgn() != DEFAULT_SEP.getFAutoPgn())
{
size += SprmUtils.addSprm((short)0x300D, newSEP.getFAutoPgn() ? 1 : 0, null, sprmList);
}
if (newSEP.getNfcPgn() != DEFAULT_SEP.getNfcPgn())
{
size += SprmUtils.addSprm((short)0x300E, newSEP.getNfcPgn(), null, sprmList);
}
if (newSEP.getDyaPgn() != DEFAULT_SEP.getDyaPgn())
{
size += SprmUtils.addSprm((short)0xB00F, newSEP.getDyaPgn(), null, sprmList);
}
if (newSEP.getDxaPgn() != DEFAULT_SEP.getDxaPgn())
{
size += SprmUtils.addSprm((short)0xB010, newSEP.getDxaPgn(), null, sprmList);
}
if (newSEP.getFPgnRestart() != DEFAULT_SEP.getFPgnRestart())
{
size += SprmUtils.addSprm((short)0x3011, newSEP.getFPgnRestart() ? 1 : 0, null, sprmList);
}
if (newSEP.getFEndNote() != DEFAULT_SEP.getFEndNote())
{
size += SprmUtils.addSprm((short)0x3012, newSEP.getFEndNote() ? 1 : 0, null, sprmList);
}
if (newSEP.getLnc() != DEFAULT_SEP.getLnc())
{
size += SprmUtils.addSprm((short)0x3013, newSEP.getLnc(), null, sprmList);
}
if (newSEP.getGrpfIhdt() != DEFAULT_SEP.getGrpfIhdt())
{
size += SprmUtils.addSprm((short)0x3014, newSEP.getGrpfIhdt(), null, sprmList);
}
if (newSEP.getNLnnMod() != DEFAULT_SEP.getNLnnMod())
{
size += SprmUtils.addSprm((short)0x5015, newSEP.getNLnnMod(), null, sprmList);
}
if (newSEP.getDxaLnn() != DEFAULT_SEP.getDxaLnn())
{
size += SprmUtils.addSprm((short)0x9016, newSEP.getDxaLnn(), null, sprmList);
}
if (newSEP.getDyaHdrTop() != DEFAULT_SEP.getDyaHdrTop())
{
size += SprmUtils.addSprm((short)0xB017, newSEP.getDyaHdrTop(), null, sprmList);
}
if (newSEP.getDyaHdrBottom() != DEFAULT_SEP.getDyaHdrBottom())
{
size += SprmUtils.addSprm((short)0xB018, newSEP.getDyaHdrBottom(), null, sprmList);
}
if (newSEP.getFLBetween() != DEFAULT_SEP.getFLBetween())
{
size += SprmUtils.addSprm((short)0x3019, newSEP.getFLBetween() ? 1 : 0, null, sprmList);
}
if (newSEP.getVjc() != DEFAULT_SEP.getVjc())
{
size += SprmUtils.addSprm((short)0x301A, newSEP.getVjc(), null, sprmList);
}
if (newSEP.getLnnMin() != DEFAULT_SEP.getLnnMin())
{
size += SprmUtils.addSprm((short)0x501B, newSEP.getLnnMin(), null, sprmList);
}
if (newSEP.getPgnStart() != DEFAULT_SEP.getPgnStart())
{
size += SprmUtils.addSprm((short)0x501C, newSEP.getPgnStart(), null, sprmList);
}
if (newSEP.getDmOrientPage() != DEFAULT_SEP.getDmOrientPage())
{
size += SprmUtils.addSprm((short)0x301D, newSEP.getDmOrientPage(), null, sprmList);
}
if (newSEP.getXaPage() != DEFAULT_SEP.getXaPage())
{
size += SprmUtils.addSprm((short)0xB01F, newSEP.getXaPage(), null, sprmList);
}
if (newSEP.getYaPage() != DEFAULT_SEP.getYaPage())
{
size += SprmUtils.addSprm((short)0xB020, newSEP.getYaPage(), null, sprmList);
}
if (newSEP.getDxaLeft() != DEFAULT_SEP.getDxaLeft())
{
size += SprmUtils.addSprm((short)0xB021, newSEP.getDxaLeft(), null, sprmList);
}
if (newSEP.getDxaRight() != DEFAULT_SEP.getDxaRight())
{
size += SprmUtils.addSprm((short)0xB022, newSEP.getDxaRight(), null, sprmList);
}
if (newSEP.getDyaTop() != DEFAULT_SEP.getDyaTop())
{
size += SprmUtils.addSprm((short)0x9023, newSEP.getDyaTop(), null, sprmList);
}
if (newSEP.getDyaBottom() != DEFAULT_SEP.getDyaBottom())
{
size += SprmUtils.addSprm((short)0x9024, newSEP.getDyaBottom(), null, sprmList);
}
if (newSEP.getDzaGutter() != DEFAULT_SEP.getDzaGutter())
{
size += SprmUtils.addSprm((short)0xB025, newSEP.getDzaGutter(), null, sprmList);
}
if (newSEP.getDmPaperReq() != DEFAULT_SEP.getDmPaperReq())
{
size += SprmUtils.addSprm((short)0x5026, newSEP.getDmPaperReq(), null, sprmList);
}
if (newSEP.getFPropMark() != DEFAULT_SEP.getFPropMark() ||
newSEP.getIbstPropRMark() != DEFAULT_SEP.getIbstPropRMark() ||
newSEP.getDttmPropRMark() != DEFAULT_SEP.getDttmPropRMark())
{
byte[] buf = new byte[7];
buf[0] = (byte)(newSEP.getFPropMark() ? 1 : 0);
int offset = LittleEndian.BYTE_SIZE;
LittleEndian.putShort(buf, (short)newSEP.getIbstPropRMark());
offset += LittleEndian.SHORT_SIZE;
LittleEndian.putInt(buf, newSEP.getDttmPropRMark());
size += SprmUtils.addSprm((short)0xD227, -1, buf, sprmList);
}
if (!Arrays.equals(newSEP.getBrcTop(), DEFAULT_SEP.getBrcTop()))
{
size += SprmUtils.addSprm((short)0x702B, SprmUtils.convertBrcToInt(newSEP.getBrcTop()), null, sprmList);
}
if (!Arrays.equals(newSEP.getBrcLeft(), DEFAULT_SEP.getBrcLeft()))
{
size += SprmUtils.addSprm((short)0x702C, SprmUtils.convertBrcToInt(newSEP.getBrcLeft()), null, sprmList);
}
if (!Arrays.equals(newSEP.getBrcBottom(), DEFAULT_SEP.getBrcBottom()))
{
size += SprmUtils.addSprm((short)0x702D, SprmUtils.convertBrcToInt(newSEP.getBrcBottom()), null, sprmList);
}
if (!Arrays.equals(newSEP.getBrcRight(), DEFAULT_SEP.getBrcRight()))
{
size += SprmUtils.addSprm((short)0x702E, SprmUtils.convertBrcToInt(newSEP.getBrcRight()), null, sprmList);
}
if (newSEP.getPgbProp() != DEFAULT_SEP.getPgbProp())
{
size += SprmUtils.addSprm((short)0x522F, newSEP.getPgbProp(), null, sprmList);
}
if (newSEP.getDxtCharSpace() != DEFAULT_SEP.getDxtCharSpace())
{
size += SprmUtils.addSprm((short)0x7030, newSEP.getDxtCharSpace(), null, sprmList);
}
if (newSEP.getDyaLinePitch() != DEFAULT_SEP.getDyaLinePitch())
{
size += SprmUtils.addSprm((short)0x9031, newSEP.getDyaLinePitch(), null, sprmList);
}
if (newSEP.getClm() != DEFAULT_SEP.getClm())
{
size += SprmUtils.addSprm((short)0x5032, newSEP.getClm(), null, sprmList);
}
if (newSEP.getWTextFlow() != DEFAULT_SEP.getWTextFlow())
{
size += SprmUtils.addSprm((short)0x5033, newSEP.getWTextFlow(), null, sprmList);
}
return SprmUtils.getGrpprl(sprmList, size);
}
}

View File

@ -0,0 +1,262 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache POI" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache POI", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.poi.hwpf.sprm;
import org.apache.poi.hwpf.usermodel.SectionProperties;
import org.apache.poi.hwpf.usermodel.BorderCode;
public class SectionSprmUncompressor extends SprmUncompressor
{
public SectionSprmUncompressor()
{
}
public static SectionProperties uncompressSEP(SectionProperties parent,
byte[] grpprl,
int offset)
{
SectionProperties newProperties = null;
try
{
newProperties = (SectionProperties) parent.clone();
}
catch (CloneNotSupportedException cnse)
{
throw new RuntimeException("There is no way this exception should happen!!");
}
SprmIterator sprmIt = new SprmIterator(grpprl, offset);
while (sprmIt.hasNext())
{
SprmOperation sprm = (SprmOperation)sprmIt.next();
unCompressSEPOperation(newProperties, sprm);
}
return newProperties;
}
/**
* Used in decompression of a sepx. This performs an operation defined by
* a single sprm.
*
* @param newSEP The SectionProperty to perfrom the operation on.
* @param operand The operation to perform.
* @param param The operation's parameter.
* @param varParam The operation variable length parameter.
*/
static void unCompressSEPOperation (SectionProperties newSEP, SprmOperation sprm)
{
switch (sprm.getOperation())
{
case 0:
newSEP.setCnsPgn ((byte) sprm.getOperand());
break;
case 0x1:
newSEP.setIHeadingPgn ((byte) sprm.getOperand());
break;
case 0x2:
byte[] buf = new byte[sprm.size() - 3];
System.arraycopy(sprm.getGrpprl(), sprm.getGrpprlOffset(), buf, 0, buf.length);
newSEP.setOlstAnm (buf);
break;
case 0x3:
//not quite sure
break;
case 0x4:
//not quite sure
break;
case 0x5:
newSEP.setFEvenlySpaced (getFlag (sprm.getOperand()));
break;
case 0x6:
newSEP.setFUnlocked (getFlag (sprm.getOperand()));
break;
case 0x7:
newSEP.setDmBinFirst ((short) sprm.getOperand());
break;
case 0x8:
newSEP.setDmBinOther ((short) sprm.getOperand());
break;
case 0x9:
newSEP.setBkc ((byte) sprm.getOperand());
break;
case 0xa:
newSEP.setFTitlePage (getFlag (sprm.getOperand()));
break;
case 0xb:
newSEP.setCcolM1 ((short) sprm.getOperand());
break;
case 0xc:
newSEP.setDxaColumns (sprm.getOperand());
break;
case 0xd:
newSEP.setFAutoPgn (getFlag (sprm.getOperand()));
break;
case 0xe:
newSEP.setNfcPgn ((byte) sprm.getOperand());
break;
case 0xf:
newSEP.setDyaPgn ((short) sprm.getOperand());
break;
case 0x10:
newSEP.setDxaPgn ((short) sprm.getOperand());
break;
case 0x11:
newSEP.setFPgnRestart (getFlag (sprm.getOperand()));
break;
case 0x12:
newSEP.setFEndNote (getFlag (sprm.getOperand()));
break;
case 0x13:
newSEP.setLnc ((byte) sprm.getOperand());
break;
case 0x14:
newSEP.setGrpfIhdt ((byte) sprm.getOperand());
break;
case 0x15:
newSEP.setNLnnMod ((short) sprm.getOperand());
break;
case 0x16:
newSEP.setDxaLnn (sprm.getOperand());
break;
case 0x17:
newSEP.setDyaHdrTop (sprm.getOperand());
break;
case 0x18:
newSEP.setDyaHdrBottom (sprm.getOperand());
break;
case 0x19:
newSEP.setFLBetween (getFlag (sprm.getOperand()));
break;
case 0x1a:
newSEP.setVjc ((byte) sprm.getOperand());
break;
case 0x1b:
newSEP.setLnnMin ((short) sprm.getOperand());
break;
case 0x1c:
newSEP.setPgnStart ((short) sprm.getOperand());
break;
case 0x1d:
newSEP.setDmOrientPage ((byte) sprm.getOperand());
break;
case 0x1e:
//nothing
break;
case 0x1f:
newSEP.setXaPage (sprm.getOperand());
break;
case 0x20:
newSEP.setYaPage (sprm.getOperand());
break;
case 0x21:
newSEP.setDxaLeft (sprm.getOperand());
break;
case 0x22:
newSEP.setDxaRight (sprm.getOperand());
break;
case 0x23:
newSEP.setDyaTop (sprm.getOperand());
break;
case 0x24:
newSEP.setDyaBottom (sprm.getOperand());
break;
case 0x25:
newSEP.setDzaGutter (sprm.getOperand());
break;
case 0x26:
newSEP.setDmPaperReq ((short) sprm.getOperand());
break;
case 0x27:
newSEP.setFPropMark (getFlag (sprm.getOperand()));
break;
case 0x28:
break;
case 0x29:
break;
case 0x2a:
break;
case 0x2b:
newSEP.setBrcTop(new BorderCode(sprm.getGrpprl(), sprm.getGrpprlOffset()));
break;
case 0x2c:
newSEP.setBrcLeft(new BorderCode(sprm.getGrpprl(), sprm.getGrpprlOffset()));
break;
case 0x2d:
newSEP.setBrcBottom(new BorderCode(sprm.getGrpprl(), sprm.getGrpprlOffset()));
break;
case 0x2e:
newSEP.setBrcRight(new BorderCode(sprm.getGrpprl(), sprm.getGrpprlOffset()));
break;
case 0x2f:
newSEP.setPgbProp (sprm.getOperand());
break;
case 0x30:
newSEP.setDxtCharSpace (sprm.getOperand());
break;
case 0x31:
newSEP.setDyaLinePitch (sprm.getOperand());
break;
case 0x33:
newSEP.setWTextFlow ((short) sprm.getOperand());
break;
default:
break;
}
}
}

View File

@ -0,0 +1,120 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache POI" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache POI", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.poi.hwpf.sprm;
import org.apache.poi.util.LittleEndian;
public class SprmBuffer
{
byte[] _buf;
int _offset;
public SprmBuffer(byte[] buf)
{
_offset = _buf.length;
}
public void addSprm(short opcode, byte operand)
{
int addition = LittleEndian.SHORT_SIZE + LittleEndian.BYTE_SIZE;
ensureCapacity(addition);
LittleEndian.putShort(_buf, _offset, opcode);
_offset += LittleEndian.SHORT_SIZE;
_buf[_offset++] = operand;
}
public void addSprm(short opcode, short operand)
{
int addition = LittleEndian.SHORT_SIZE + LittleEndian.SHORT_SIZE;
ensureCapacity(addition);
LittleEndian.putShort(_buf, _offset, opcode);
_offset += LittleEndian.SHORT_SIZE;
LittleEndian.putShort(_buf, _offset, operand);
_offset += LittleEndian.SHORT_SIZE;
}
public void addSprm(short opcode, int operand)
{
int addition = LittleEndian.SHORT_SIZE + LittleEndian.INT_SIZE;
ensureCapacity(addition);
LittleEndian.putShort(_buf, _offset, opcode);
_offset += LittleEndian.SHORT_SIZE;
LittleEndian.putInt(_buf, _offset, operand);
_offset += LittleEndian.INT_SIZE;
}
public void addSprm(short opcode, byte[] operand)
{
int addition = LittleEndian.SHORT_SIZE + LittleEndian.BYTE_SIZE + operand.length;
ensureCapacity(addition);
LittleEndian.putShort(_buf, _offset, opcode);
_offset += LittleEndian.SHORT_SIZE;
_buf[_offset++] = (byte)operand.length;
System.arraycopy(operand, 0, _buf, _offset, operand.length);
}
public byte[] toByteArray()
{
return _buf;
}
private void ensureCapacity(int addition)
{
if (_offset + addition >= _buf.length)
{
// add 6 more than they need for use the next iteration
byte[] newBuf = new byte[_offset + addition + 6];
System.arraycopy(_buf, 0, newBuf, 0, _buf.length);
}
}
}

View File

@ -0,0 +1,88 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache POI" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache POI", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.poi.hwpf.sprm;
/**
* This class is used to iterate through a list of sprms from a Word 97/2000/XP
* document.
* @author Ryan Ackley
* @version 1.0
*/
public class SprmIterator
{
private byte[] _grpprl;
int _offset;
public SprmIterator(byte[] grpprl, int offset)
{
_grpprl = grpprl;
_offset = offset;
}
public boolean hasNext()
{
return _offset < _grpprl.length;
}
public SprmOperation next()
{
SprmOperation op = new SprmOperation(_grpprl, _offset);
_offset += op.size();
return op;
}
}

View File

@ -0,0 +1,164 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache POI" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache POI", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.poi.hwpf.sprm;
import org.apache.poi.util.BitField;
import org.apache.poi.util.LittleEndian;
/**
* This class is used to represent a sprm operation from a Word 97/2000/XP
* document.
* @author Ryan Ackley
* @version 1.0
*/
public class SprmOperation
{
final static private BitField OP_BITFIELD = new BitField(0x1ff);
final static private BitField SPECIAL_BITFIELD = new BitField(0x200);
final static private BitField TYPE_BITFIELD = new BitField(0x1c00);
final static private BitField SIZECODE_BITFIELD = new BitField(0xe000);
private int _type;
private int _operation;
private int _gOffset;
private byte[] _grpprl;
private int _sizeCode;
public SprmOperation(byte[] grpprl, int offset)
{
_grpprl = grpprl;
short sprmStart = LittleEndian.getShort(grpprl, offset);
_gOffset = offset + 2;
_operation = OP_BITFIELD.getValue(sprmStart);
_type = TYPE_BITFIELD.getValue(sprmStart);
_sizeCode = SIZECODE_BITFIELD.getValue(sprmStart);
}
public int getType()
{
return _type;
}
public int getOperation()
{
return _operation;
}
public int getGrpprlOffset()
{
return _gOffset;
}
public int getOperand()
{
switch (_sizeCode)
{
case 0:
case 1:
return _grpprl[_gOffset];
case 2:
case 4:
case 5:
return LittleEndian.getShort(_grpprl, _gOffset);
case 3:
return LittleEndian.getInt(_grpprl, _gOffset);
case 6:
throw new UnsupportedOperationException("This SPRM contains a variable length operand");
case 7:
byte threeByteInt[] = new byte[4];
threeByteInt[0] = _grpprl[_gOffset];
threeByteInt[1] = _grpprl[_gOffset + 1];
threeByteInt[2] = _grpprl[_gOffset + 2];
threeByteInt[3] = (byte)0;
return LittleEndian.getInt(threeByteInt, 0);
default:
throw new IllegalArgumentException("SPRM contains an invalid size code");
}
}
public int getSizeCode()
{
return _sizeCode;
}
public int size()
{
switch (_sizeCode)
{
case 0:
case 1:
return 3;
case 2:
case 4:
case 5:
return 4;
case 3:
return 6;
case 6:
return _grpprl[_gOffset] + 3;
case 7:
return 5;
default:
throw new IllegalArgumentException("SPRM contains an invalid size code");
}
}
public byte[] getGrpprl()
{
return _grpprl;
}
}

View File

@ -0,0 +1,86 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache POI" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache POI", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.poi.hwpf.sprm;
public class SprmUncompressor
{
public SprmUncompressor()
{
}
/**
* Converts an int into a boolean. If the int is non-zero, it returns true.
* Otherwise it returns false.
*
* @param x The int to convert.
*
* @return A boolean whose value depends on x.
*/
public static boolean getFlag (int x)
{
if (x != 0)
{
return true;
}
else
{
return false;
}
}
}

View File

@ -0,0 +1,147 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache POI" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache POI", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.poi.hwpf.sprm;
import org.apache.poi.hwpf.usermodel.TableProperties;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.hwpf.usermodel.TableCellDescriptor;
import org.apache.poi.hwpf.usermodel.ShadingDescriptor;
import org.apache.poi.hwpf.usermodel.BorderCode;
import java.util.ArrayList;
import java.util.Arrays;
public class TableSprmCompressor
{
public TableSprmCompressor()
{
}
public static byte[] compressTableProperty(TableProperties newTAP)
{
int size = 0;
ArrayList sprmList = new ArrayList();
if (newTAP.getJc() != 0)
{
size += SprmUtils.addSprm((short)0x5400, newTAP.getJc(), null, sprmList);
}
if (newTAP.getFCantSplit())
{
size += SprmUtils.addSprm((short)0x3403, 1, null, sprmList);
}
if (newTAP.getFTableHeader())
{
size += SprmUtils.addSprm((short)0x3404, 1, null, sprmList);
}
byte[] brcBuf = new byte[6 * BorderCode.SIZE];
int offset = 0;
newTAP.getBrcTop().serialize(brcBuf, offset);
offset += BorderCode.SIZE;
newTAP.getBrcLeft().serialize(brcBuf, offset);
offset += BorderCode.SIZE;
newTAP.getBrcBottom().serialize(brcBuf, offset);
offset += BorderCode.SIZE;
newTAP.getBrcRight().serialize(brcBuf, offset);
offset += BorderCode.SIZE;
newTAP.getBrcHorizontal().serialize(brcBuf, offset);
offset += BorderCode.SIZE;
newTAP.getBrcVertical().serialize(brcBuf, offset);
byte[] compare = new byte[6 * BorderCode.SIZE];
if (!Arrays.equals(brcBuf, compare))
{
size += SprmUtils.addSprm((short)0xD605, 0, brcBuf, sprmList);
}
if (newTAP.getDyaRowHeight() != 0)
{
size += SprmUtils.addSprm((short)0x9407, newTAP.getDyaRowHeight(), null, sprmList);
}
if (newTAP.getItcMac() > 0)
{
int itcMac = newTAP.getItcMac();
byte[] buf = new byte[1 + (LittleEndian.SHORT_SIZE*(itcMac + 1)) + (TableCellDescriptor.SIZE*itcMac)];
buf[0] = (byte)itcMac;
short[] dxaCenters = newTAP.getRgdxaCenter();
for (int x = 0; x < dxaCenters.length; x++)
{
LittleEndian.putShort(buf, 1 + (x * LittleEndian.SHORT_SIZE),
dxaCenters[x]);
}
TableCellDescriptor[] cellDescriptors = newTAP.getRgtc();
for (int x = 0; x < cellDescriptors.length; x++)
{
cellDescriptors[x].serialize(buf,
1+((itcMac+1)*LittleEndian.SHORT_SIZE)+(x*TableCellDescriptor.SIZE));
}
size += SprmUtils.addSprm((short)0xD608, 0, buf, sprmList);
buf = new byte[(itcMac * ShadingDescriptor.SIZE) + 1];
buf[0] = (byte)itcMac;
ShadingDescriptor[] shds = newTAP.getRgshd();
for (int x = 0; x < itcMac; x++)
{
shds[x].serialize(buf, 1 + (x * ShadingDescriptor.SIZE));
}
size += SprmUtils.addSprm((short)0xD608, 0, buf, sprmList);
}
if (newTAP.getTlp() != 0)
{
size += SprmUtils.addSprm((short)0x740a, newTAP.getTlp(), null, sprmList);
}
return SprmUtils.getGrpprl(sprmList, size);
}
}

View File

@ -0,0 +1,285 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache POI" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache POI", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.poi.hwpf.sprm;
import org.apache.poi.hwpf.usermodel.TableProperties;
import org.apache.poi.hwpf.usermodel.TableCellDescriptor;
import org.apache.poi.hwpf.usermodel.BorderCode;
import org.apache.poi.util.LittleEndian;
public class TableSprmUncompressor
extends SprmUncompressor
{
public TableSprmUncompressor()
{
}
public static TableProperties uncompressTAP(TableProperties parent,
byte[] grpprl,
int offset)
{
TableProperties newProperties = null;
try
{
newProperties = (TableProperties) parent.clone();
}
catch (CloneNotSupportedException cnse)
{
throw new RuntimeException("There is no way this exception should happen!!");
}
SprmIterator sprmIt = new SprmIterator(grpprl, offset);
while (sprmIt.hasNext())
{
SprmOperation sprm = (SprmOperation)sprmIt.next();
unCompressTAPOperation(newProperties, sprm);
}
return newProperties;
}
/**
* Used to uncompress a table property. Performs an operation defined
* by a sprm stored in a tapx.
*
* @param newTAP The TableProperties object to perform the operation on.
* @param operand The operand that defines this operation.
* @param param The parameter for this operation.
* @param varParam Variable length parameter for this operation.
*/
static void unCompressTAPOperation (TableProperties newTAP, SprmOperation sprm)
{
switch (sprm.getOperation())
{
case 0:
newTAP.setJc ((short) sprm.getOperand());
break;
case 0x01:
{
short[] rgdxaCenter = newTAP.getRgdxaCenter ();
short itcMac = newTAP.getItcMac ();
int adjust = sprm.getOperand() - (rgdxaCenter[0] + newTAP.getDxaGapHalf ());
for (int x = 0; x < itcMac; x++)
{
rgdxaCenter[x] += adjust;
}
break;
}
case 0x02:
{
short[] rgdxaCenter = newTAP.getRgdxaCenter ();
if (rgdxaCenter != null)
{
int adjust = newTAP.getDxaGapHalf () - sprm.getOperand();
rgdxaCenter[0] += adjust;
}
newTAP.setDxaGapHalf (sprm.getOperand());
break;
}
case 0x03:
newTAP.setFCantSplit (getFlag(sprm.getOperand()));
break;
case 0x04:
newTAP.setFTableHeader (getFlag (sprm.getOperand()));
break;
case 0x05:
{
byte[] buf = sprm.getGrpprl();
int offset = sprm.getGrpprlOffset();
newTAP.setBrcTop(new BorderCode(buf, offset));
offset += BorderCode.SIZE;
newTAP.setBrcLeft(new BorderCode(buf, offset));
offset += BorderCode.SIZE;
newTAP.setBrcBottom(new BorderCode(buf, offset));
offset += BorderCode.SIZE;
newTAP.setBrcRight(new BorderCode(buf, offset));
offset += BorderCode.SIZE;
newTAP.setBrcHorizontal(new BorderCode(buf, offset));
offset += BorderCode.SIZE;
newTAP.setBrcVertical(new BorderCode(buf, offset));
break;
}
case 0x06:
//obsolete, used in word 1.x
break;
case 0x07:
newTAP.setDyaRowHeight (sprm.getOperand());
break;
case 0x08:
{
byte[] grpprl = sprm.getGrpprl();
int offset = sprm.getGrpprlOffset();
short itcMac = grpprl[offset];
short[] rgdxaCenter = new short[itcMac + 1];
TableCellDescriptor[] rgtc = new TableCellDescriptor[itcMac];
//I use varParam[0] and newTAP._itcMac interchangably
newTAP.setItcMac (itcMac);
newTAP.setRgdxaCenter (rgdxaCenter);
newTAP.setRgtc (rgtc);
for (int x = 0; x < itcMac; x++)
{
rgdxaCenter[x] = LittleEndian.getShort (grpprl, offset + (1 + (x * 2)));
rgtc[x] = TableCellDescriptor.convertBytesToTC (grpprl,
offset + (1 + ((itcMac + 1) * 2) + (x * 20)));
}
rgdxaCenter[itcMac] = LittleEndian.getShort (grpprl, offset + (1 + (itcMac * 2)));
break;
}
case 0x09:
/** @todo handle cell shading*/
break;
case 0x0a:
/** @todo handle word defined table styles*/
break;
case 0x20:
// {
// TableCellDescriptor[] rgtc = newTAP.getRgtc();
//
// for (int x = varParam[0]; x < varParam[1]; x++)
// {
//
// if ((varParam[2] & 0x08) > 0)
// {
// short[] brcRight = rgtc[x].getBrcRight ();
// brcRight[0] = LittleEndian.getShort (varParam, 6);
// brcRight[1] = LittleEndian.getShort (varParam, 8);
// }
// else if ((varParam[2] & 0x04) > 0)
// {
// short[] brcBottom = rgtc[x].getBrcBottom ();
// brcBottom[0] = LittleEndian.getShort (varParam, 6);
// brcBottom[1] = LittleEndian.getShort (varParam, 8);
// }
// else if ((varParam[2] & 0x02) > 0)
// {
// short[] brcLeft = rgtc[x].getBrcLeft ();
// brcLeft[0] = LittleEndian.getShort (varParam, 6);
// brcLeft[1] = LittleEndian.getShort (varParam, 8);
// }
// else if ((varParam[2] & 0x01) > 0)
// {
// short[] brcTop = rgtc[x].getBrcTop ();
// brcTop[0] = LittleEndian.getShort (varParam, 6);
// brcTop[1] = LittleEndian.getShort (varParam, 8);
// }
// }
// break;
// }
break;
case 0x21:
{
int param = sprm.getOperand();
int index = (param & 0xff000000) >> 24;
int count = (param & 0x00ff0000) >> 16;
int width = (param & 0x0000ffff);
int itcMac = newTAP.getItcMac();
short[] rgdxaCenter = new short[itcMac + count + 1];
TableCellDescriptor[] rgtc = new TableCellDescriptor[itcMac + count];
if (index >= itcMac)
{
index = itcMac;
System.arraycopy(newTAP.getRgdxaCenter(), 0, rgdxaCenter, 0,
itcMac + 1);
System.arraycopy(newTAP.getRgtc(), 0, rgtc, 0, itcMac);
}
else
{
//copy rgdxaCenter
System.arraycopy(newTAP.getRgdxaCenter(), 0, rgdxaCenter, 0,
index + 1);
System.arraycopy(newTAP.getRgdxaCenter(), index + 1, rgdxaCenter,
index + count, itcMac - (index));
//copy rgtc
System.arraycopy(newTAP.getRgtc(), 0, rgtc, 0, index);
System.arraycopy(newTAP.getRgtc(), index, rgtc, index + count,
itcMac - index);
}
for (int x = index; x < index + count; x++)
{
rgtc[x] = new TableCellDescriptor();
rgdxaCenter[x] = (short)(rgdxaCenter[x - 1] + width);
}
rgdxaCenter[index +
count] = (short)(rgdxaCenter[(index + count) - 1] + width);
break;
}
/**@todo handle table sprms from complex files*/
case 0x22:
case 0x23:
case 0x24:
case 0x25:
case 0x26:
case 0x27:
case 0x28:
case 0x29:
case 0x2a:
case 0x2b:
case 0x2c:
break;
default:
break;
}
}
}

View File

@ -0,0 +1,99 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache POI" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache POI", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.poi.hwpf.usermodel;
import org.apache.poi.util.BitField;
import org.apache.poi.util.LittleEndian;
public class BorderCode
implements Cloneable
{
public static final int SIZE = 4;
private short _info;
private final static BitField _dptLineWidth = new BitField(0xff);
private final static BitField _brcType = new BitField(0xff00);
private short _info2;
private final static BitField _ico = new BitField(0xff);
private final static BitField _dptDpace = new BitField(0x1f00);
private final static BitField _fShadow = new BitField(0x2000);
private final static BitField _fFrame = new BitField(0x4000);
public BorderCode()
{
}
public BorderCode(byte[] buf, int offset)
{
_info = LittleEndian.getShort(buf, offset);
_info2 = LittleEndian.getShort(buf, offset + LittleEndian.SHORT_SIZE);
}
public void serialize(byte[] buf, int offset)
{
LittleEndian.putShort(buf, offset, _info);
LittleEndian.putShort(buf, offset + LittleEndian.SHORT_SIZE, _info2);
}
public boolean isEmpty()
{
return _info == 0 && _info2 == 0;
}
public Object clone()
throws CloneNotSupportedException
{
return super.clone();
}
}

View File

@ -0,0 +1,73 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache POI" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache POI", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.poi.hwpf.usermodel;
import org.apache.poi.hwpf.*;
import java.util.List;
public class CharacterRange extends Range
{
public CharacterRange(int start, int end, HWPFDocument doc)
{
super(start, end, doc);
}
public CharacterRange(int start, int end, Range parent)
{
super(start, end, parent);
}
}

View File

@ -0,0 +1,94 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache POI" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache POI", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.poi.hwpf.usermodel;
import org.apache.poi.util.BitField;
import org.apache.poi.util.LittleEndian;
public class DateAndTime
implements Cloneable
{
public static final int SIZE = 4;
private short _info;
private static final BitField _minutes = new BitField(0x3f);
private static final BitField _hours = new BitField(0x7c0);
private static final BitField _dom = new BitField(0xf800);
private short _info2;
private static final BitField _months = new BitField(0xf);
private static final BitField _years = new BitField(0x1ff0);
private static final BitField _weekday = new BitField(0xe000);
public DateAndTime()
{
}
public DateAndTime(byte[] buf, int offset)
{
_info = LittleEndian.getShort(buf, offset);
_info2 = LittleEndian.getShort(buf, offset + LittleEndian.SHORT_SIZE);
}
public void serialize(byte[] buf, int offset)
{
LittleEndian.putShort(buf, offset, _info);
LittleEndian.putShort(buf, offset + LittleEndian.SHORT_SIZE, _info2);
}
public Object clone()
throws CloneNotSupportedException
{
return super.clone();
}
}

View File

@ -0,0 +1,90 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache POI" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache POI", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.poi.hwpf.usermodel;
import org.apache.poi.util.LittleEndian;
public class LineSpacingDescriptor
implements Cloneable
{
short _dyaLine;
short _fMultiLinespace;
public LineSpacingDescriptor()
{
}
public LineSpacingDescriptor(byte[] buf, int offset)
{
_dyaLine = LittleEndian.getShort(buf, offset);
_fMultiLinespace = LittleEndian.getShort(buf, offset + LittleEndian.SHORT_SIZE);
}
public Object clone()
throws CloneNotSupportedException
{
return super.clone();
}
public void setMultiLinespace(short fMultiLinespace)
{
_fMultiLinespace = fMultiLinespace;
}
public void setDyaLine(short dyaLine)
{
_dyaLine = dyaLine;
}
}

View File

@ -0,0 +1,72 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache POI" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache POI", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.poi.hwpf.usermodel;
import org.apache.poi.hwpf.*;
import java.util.List;
public class ParagraphRange extends Range
{
public ParagraphRange(int start, int end, HWPFDocument doc)
{
super(start, end, doc);
}
public ParagraphRange(int start, int end, Range parent)
{
super(start, end, parent);
}
}

View File

@ -0,0 +1,84 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache POI" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache POI", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.poi.hwpf.usermodel;
import org.apache.poi.hwpf.model.hdftypes.definitions.SEPAbstractType;
public class SectionProperties
extends SEPAbstractType
{
public SectionProperties()
{
field_20_brcTop = new BorderCode();
field_21_brcLeft = new BorderCode();
field_22_brcBottom = new BorderCode();
field_23_brcRight = new BorderCode();
field_26_dttmPropRMark = new DateAndTime();
}
public Object clone()
throws CloneNotSupportedException
{
SectionProperties copy = (SectionProperties)super.clone();
copy.field_20_brcTop = (BorderCode)field_20_brcTop.clone();
copy.field_21_brcLeft = (BorderCode)field_21_brcLeft.clone();
copy.field_22_brcBottom = (BorderCode)field_22_brcBottom.clone();
copy.field_23_brcRight = (BorderCode)field_23_brcRight.clone();
copy.field_26_dttmPropRMark = (DateAndTime)field_26_dttmPropRMark.clone();
return copy;
}
}

View File

@ -0,0 +1,72 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache POI" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache POI", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.poi.hwpf.usermodel;
import org.apache.poi.hwpf.*;
import java.util.List;
public class SectionRange extends Range
{
public SectionRange(int start, int end, HWPFDocument doc)
{
super(start, end, doc);
}
public SectionRange(int start, int end, Range parent)
{
super(start, end, parent);
}
}

View File

@ -0,0 +1,94 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache POI" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache POI", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.poi.hwpf.usermodel;
import org.apache.poi.util.BitField;
import org.apache.poi.util.LittleEndian;
public class ShadingDescriptor
implements Cloneable
{
public static final int SIZE = 2;
private short _info;
private final static BitField _icoFore = new BitField(0x1f);
private final static BitField _icoBack = new BitField(0x3e0);
private final static BitField _ipat = new BitField(0xfc00);
public ShadingDescriptor()
{
}
public ShadingDescriptor(byte[] buf, int offset)
{
_info = LittleEndian.getShort(buf, offset);
}
public short toShort()
{
return _info;
}
public void serialize(byte[] buf, int offset)
{
LittleEndian.putShort(buf, offset, _info);
}
public Object clone()
throws CloneNotSupportedException
{
return super.clone();
}
}

View File

@ -0,0 +1,86 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache POI" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache POI", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.poi.hwpf.usermodel;
import org.apache.poi.hwpf.model.hdftypes.definitions.TCAbstractType;
public class TableCellDescriptor
extends TCAbstractType
{
public static final int SIZE = 20;
public TableCellDescriptor()
{
}
public Object clone()
throws CloneNotSupportedException
{
TableCellDescriptor tc = (TableCellDescriptor)super.clone();
tc.field_3_brcTop = (BorderCode)field_3_brcTop.clone();
tc.field_4_brcLeft = (BorderCode)field_4_brcLeft.clone();
tc.field_5_brcBottom = (BorderCode)field_5_brcBottom.clone();
tc.field_6_brcRight = (BorderCode)field_6_brcRight.clone();
return tc;
}
public static TableCellDescriptor convertBytesToTC(byte[] buf, int offset)
{
TableCellDescriptor tc = new TableCellDescriptor();
tc.fillFields(buf, offset);
return tc;
}
}

View File

@ -0,0 +1,91 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache POI" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache POI", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.poi.hwpf.usermodel;
import org.apache.poi.hwpf.model.hdftypes.definitions.TAPAbstractType;
public class TableProperties
extends TAPAbstractType
implements Cloneable
{
public TableProperties()
{
}
public Object clone()
throws CloneNotSupportedException
{
TableProperties tap = (TableProperties)super.clone();
tap.field_10_rgshd = new ShadingDescriptor[field_10_rgshd.length];
for (int x = 0; x < field_10_rgshd.length; x++)
{
tap.field_10_rgshd[x] = (ShadingDescriptor)field_10_rgshd[x].clone();
}
tap.field_11_brcBottom = (BorderCode)field_11_brcBottom.clone();
tap.field_12_brcTop = (BorderCode)field_12_brcTop.clone();
tap.field_13_brcLeft = (BorderCode)field_13_brcLeft.clone();
tap.field_14_brcRight = (BorderCode)field_14_brcRight.clone();
tap.field_15_brcVertical = (BorderCode)field_15_brcVertical.clone();
tap.field_16_brcHorizontal = (BorderCode)field_16_brcHorizontal.clone();
tap.field_8_rgdxaCenter = (short[])field_8_rgdxaCenter.clone();
tap.field_9_rgtc = new TableCellDescriptor[field_9_rgtc.length];
for (int x = 0; x < field_9_rgtc.length; x++)
{
tap.field_9_rgtc[x] = (TableCellDescriptor)field_9_rgtc[x].clone();
}
return tap;
}
}