diff --git a/src/scratchpad/src/org/apache/poi/hwpf/Range.java b/src/scratchpad/src/org/apache/poi/hwpf/Range.java index 1854893b3..1fcf0f365 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/Range.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/Range.java @@ -60,9 +60,9 @@ 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.usermodel.CharacterRun; +import org.apache.poi.hwpf.usermodel.Paragraph; +import org.apache.poi.hwpf.usermodel.Section; import org.apache.poi.hwpf.model.hdftypes.PropertyNode; import org.apache.poi.hwpf.model.hdftypes.StyleSheet; @@ -91,14 +91,22 @@ public class Range private int _start; private int _end; private HWPFDocument _doc; - private List _parentSections; - private List _parentParagraphs; - private List _parentCharacters; - private List _parentText; + boolean _sectionRangeFound; private List _sections; + int _sectionStart; + int _sectionEnd; + boolean _parRangeFound; private List _paragraphs; + int _parStart; + int _parEnd; + boolean _charRangeFound; private List _characters; + int _charStart; + int _charEnd; + boolean _textRangeFound; private List _text; + int _textStart; + int _textEnd; protected Range(int start, int end, HWPFDocument doc) @@ -106,10 +114,10 @@ public class Range _start = start; _end = end; _doc = doc; - _parentSections = _doc.getSectionTable().getSections(); - _parentParagraphs = _doc.getParagraphTable().getParagraphs(); - _parentCharacters = _doc.getCharacterTable().getTextRuns(); - _parentText = _doc.getTextTable().getTextPieces(); + _sections = _doc.getSectionTable().getSections(); + _paragraphs = _doc.getParagraphTable().getParagraphs(); + _characters = _doc.getCharacterTable().getTextRuns(); + _text = _doc.getTextTable().getTextPieces(); } protected Range(int start, int end, Range parent) @@ -117,18 +125,21 @@ public class Range _start = start; _end = end; _doc = parent._doc; - _parentSections = parent._parentSections; - _parentParagraphs = parent._parentParagraphs; - _parentCharacters = parent._parentCharacters; - _parentText = parent._parentText; + _sections = parent._sections; + _paragraphs = parent._paragraphs; + _characters = parent._characters; + _text = parent._text; } public String text() throws UnsupportedEncodingException { - if (_text == null) + if (!_textRangeFound) { - _text = initRangedList(_parentText, _start, _end); + int[] point = findRange(_text, _textStart, _start, _end); + _textStart = point[0]; + _textEnd = point[1]; + _textRangeFound = true; } StringBuffer sb = new StringBuffer(); @@ -149,71 +160,97 @@ public class Range public int numSections() { - if (_sections == null) - { - _sections = initRangedList(_parentSections, _start, _end); - } + initSections(); return _sections.size(); } public int numParagraphs() { - if (_paragraphs == null) - { - _paragraphs = initRangedList(_parentParagraphs, _start, _end); - } + initParagraphs(); return _paragraphs.size(); } public int numCharacterRuns() { - if (_characters == null) - { - _characters = initRangedList(_parentCharacters, _start, _end); - } + initCharacterRuns(); return _characters.size(); } - public CharacterProperties getCharacterRun(int index) + public CharacterRange insertBefore(String text) { - CHPX chpx = (CHPX)_characters.get(index); - CharacterProperties chp = (CharacterProperties)chpx.getCacheContents(); + return null; + } + + public CharacterRange insertAfter(String text) + { + return null; + } + + public CharacterRange insertBefore(String text, CharacterRun cr) + { + return null; + } + + public CharacterRange insertAfter(String text, CharacterRun cr) + { + return null; + } + + public ParagraphRange insertBefore(Paragraph paragraph) + { + return null; + } + + public ParagraphRange insertAfter(Paragraph paragraph) + { + return null; + } + + + public CharacterRun getCharacterRun(int index) + { + initCharacterRuns(); + CHPX chpx = (CHPX)_characters.get(index + _charStart); + CharacterRun chp = (CharacterRun)chpx.getCacheContents(); if (chp == null) { - List paragraphList = initRangedList(_paragraphs, chpx.getStart(), - chpx.getEnd()); + int[] point = findRange(_paragraphs, _parStart, chpx.getStart(), + chpx.getEnd()); + List paragraphList = _paragraphs.subList(point[0], point[1]); PAPX papx = (PAPX)paragraphList.get(0); short istd = LittleEndian.getShort(papx.getBuf()); StyleSheet sd = _doc.getStyleSheet(); - CharacterProperties baseStyle = sd.getCharacterStyle(istd); + CharacterRun baseStyle = sd.getCharacterStyle(istd); chp = CharacterSprmUncompressor.uncompressCHP(baseStyle, chpx.getBuf(), 0); chpx.fillCache(chp); } return chp; } - public SectionProperties getSection(int index) + public Section getSection(int index) { - SEPX sepx = (SEPX)_sections.get(index); - SectionProperties sep = (SectionProperties)sepx.getCacheContents(); + initSections(); + SEPX sepx = (SEPX)_sections.get(index + _sectionStart); + Section sep = (Section)sepx.getCacheContents(); if (sep == null) { - sep = SectionSprmUncompressor.uncompressSEP(new SectionProperties(), sepx.getBuf(), 0); + sep = SectionSprmUncompressor.uncompressSEP(new Section(), sepx.getBuf(), 0); sepx.fillCache(sep); } return sep; } - public ParagraphProperties getParagraph(int index) + public Paragraph getParagraph(int index) { - PAPX papx = (PAPX)_sections.get(index); - ParagraphProperties pap = (ParagraphProperties)papx.getCacheContents(); + initParagraphs(); + PAPX papx = (PAPX)_sections.get(index + _parStart); + Paragraph pap = (Paragraph)papx.getCacheContents(); if (pap == null) { short istd = LittleEndian.getShort(papx.getBuf()); StyleSheet sd = _doc.getStyleSheet(); - ParagraphProperties baseStyle = sd.getParagraphStyle(istd); + Paragraph baseStyle = sd.getParagraphStyle(istd); pap = ParagraphSprmUncompressor.uncompressPAP(baseStyle, papx.getBuf(), 2); papx.fillCache(pap); } @@ -222,37 +259,26 @@ public class Range public SectionRange getSectionRange(int index) { - if (_sections == null) - { - _sections = initRangedList(_doc.getSectionTable().getSections(), _start, _end); - } - PropertyNode node = (PropertyNode)_sections.get(index); + initSections(); + PropertyNode node = (PropertyNode)_sections.get(index + _sectionStart); 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); + initParagraphs(); + PropertyNode node = (PropertyNode)_paragraphs.get(index + _parStart); 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); + initCharacterRuns(); + PropertyNode node = (PropertyNode)_characters.get(index + _charStart); return new CharacterRange(Math.max(_start, node.getStart()), Math.min(_end, node.getEnd()), this); - } public SectionRange sections() @@ -269,9 +295,42 @@ public class Range return new CharacterRange(_start, _end, _doc); } - private List initRangedList(List rpl, int start, int end) + private void initParagraphs() { - int x = 0; + if (!_parRangeFound) + { + int[] point = findRange(_paragraphs, _parStart, _start, _end); + _parStart = point[0]; + _parEnd = point[1]; + _parRangeFound = true; + } + } + + private void initCharacterRuns() + { + if (!_charRangeFound) + { + int[] point = findRange(_characters, _charStart, _start, _end); + _charStart = point[0]; + _charEnd = point[1]; + _charRangeFound = true; + } + } + + private void initSections() + { + if (!_sectionRangeFound) + { + int[] point = findRange(_sections, _sectionStart, _start, _end); + _sectionStart = point[0]; + _sectionEnd = point[1]; + _sectionRangeFound = true; + } + } + + private int[] findRange(List rpl, int min, int start, int end) + { + int x = min; PropertyNode node = (PropertyNode)rpl.get(x); while(node.getStart() < start) { @@ -286,6 +345,6 @@ public class Range y++; node = (PropertyNode)rpl.get(y); } - return rpl.subList(x, y + 1); + return new int[]{x, y + 1}; } } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/StyleDescription.java b/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/StyleDescription.java index 68f1bdb9b..b4902e231 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/StyleDescription.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/StyleDescription.java @@ -59,8 +59,8 @@ package org.apache.poi.hwpf.model.hdftypes; import java.io.UnsupportedEncodingException; import java.util.Arrays; -import org.apache.poi.hwpf.usermodel.CharacterProperties; -import org.apache.poi.hwpf.usermodel.ParagraphProperties; +import org.apache.poi.hwpf.usermodel.CharacterRun; +import org.apache.poi.hwpf.usermodel.Paragraph; import org.apache.poi.util.LittleEndian; import org.apache.poi.util.BitField; /** @@ -96,8 +96,8 @@ public class StyleDescription implements HDFType UPX[] _upxs; String _name; - ParagraphProperties _pap; - CharacterProperties _chp; + Paragraph _pap; + CharacterRun _chp; public StyleDescription() { @@ -203,19 +203,19 @@ public class StyleDescription implements HDFType return null; } } - public ParagraphProperties getPAP() + public Paragraph getPAP() { return _pap; } - public CharacterProperties getCHP() + public CharacterRun getCHP() { return _chp; } - void setPAP(ParagraphProperties pap) + void setPAP(Paragraph pap) { _pap = pap; } - void setCHP(CharacterProperties chp) + void setCHP(CharacterRun chp) { _chp = chp; } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/StyleSheet.java b/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/StyleSheet.java index 89a87c059..2d597180f 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/StyleSheet.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/StyleSheet.java @@ -62,8 +62,8 @@ import java.io.IOException; import org.apache.poi.util.LittleEndian; import org.apache.poi.hwpf.model.io.HWPFOutputStream; -import org.apache.poi.hwpf.usermodel.CharacterProperties; -import org.apache.poi.hwpf.usermodel.ParagraphProperties; +import org.apache.poi.hwpf.usermodel.CharacterRun; +import org.apache.poi.hwpf.usermodel.Paragraph; import org.apache.poi.hwpf.sprm.ParagraphSprmUncompressor; import org.apache.poi.hwpf.sprm.CharacterSprmUncompressor; @@ -248,12 +248,12 @@ public class StyleSheet implements HDFType private void createPap(int istd) { StyleDescription sd = _styleDescriptions[istd]; - ParagraphProperties pap = sd.getPAP(); + Paragraph pap = sd.getPAP(); byte[] papx = sd.getPAPX(); int baseIndex = sd.getBaseStyle(); if(pap == null && papx != null) { - ParagraphProperties parentPAP = new ParagraphProperties(); + Paragraph parentPAP = new Paragraph(); if(baseIndex != NIL_STYLE) { @@ -266,7 +266,7 @@ public class StyleSheet implements HDFType } - pap = (ParagraphProperties)ParagraphSprmUncompressor.uncompressPAP(parentPAP, papx, 2); + pap = (Paragraph)ParagraphSprmUncompressor.uncompressPAP(parentPAP, papx, 2); sd.setPAP(pap); } } @@ -283,12 +283,12 @@ public class StyleSheet implements HDFType private void createChp(int istd) { StyleDescription sd = _styleDescriptions[istd]; - CharacterProperties chp = sd.getCHP(); + CharacterRun chp = sd.getCHP(); byte[] chpx = sd.getCHPX(); int baseIndex = sd.getBaseStyle(); if(chp == null && chpx != null) { - CharacterProperties parentCHP = new CharacterProperties(); + CharacterRun parentCHP = new CharacterRun(); if(baseIndex != NIL_STYLE) { @@ -301,7 +301,7 @@ public class StyleSheet implements HDFType } - chp = (CharacterProperties)CharacterSprmUncompressor.uncompressCHP(parentCHP, chpx, 0); + chp = (CharacterRun)CharacterSprmUncompressor.uncompressCHP(parentCHP, chpx, 0); sd.setCHP(chp); } } @@ -316,12 +316,12 @@ public class StyleSheet implements HDFType return _styleDescriptions[x]; } - public CharacterProperties getCharacterStyle(int x) + public CharacterRun getCharacterStyle(int x) { return (_styleDescriptions[x] != null ? _styleDescriptions[x].getCHP() : null); } - public ParagraphProperties getParagraphStyle(int x) + public Paragraph getParagraphStyle(int x) { return (_styleDescriptions[x] != null ? _styleDescriptions[x].getPAP() : null); } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/sprm/CharacterSprmCompresser.java b/src/scratchpad/src/org/apache/poi/hwpf/sprm/CharacterSprmCompresser.java index 004923c82..85857ada0 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/sprm/CharacterSprmCompresser.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/sprm/CharacterSprmCompresser.java @@ -58,7 +58,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Arrays; -import org.apache.poi.hwpf.usermodel.CharacterProperties; +import org.apache.poi.hwpf.usermodel.CharacterRun; import org.apache.poi.util.LittleEndian; public class CharacterSprmCompresser @@ -66,7 +66,7 @@ public class CharacterSprmCompresser public CharacterSprmCompresser() { } - public static byte[] compressCharacterProperty(CharacterProperties newCHP, CharacterProperties oldCHP) + public static byte[] compressCharacterProperty(CharacterRun newCHP, CharacterRun oldCHP) { ArrayList sprmList = new ArrayList(); int size = 0; @@ -108,13 +108,10 @@ public class CharacterSprmCompresser { size += SprmUtils.addSprm((short)0x4804, newCHP.getIbstRMark(), null, sprmList); } - if (!Arrays.equals(newCHP.getDttmRMark(), oldCHP.getDttmRMark())) + if (!newCHP.getDttmRMark().equals(oldCHP.getDttmRMark())) { - // Create an int for the sprm - short[] dttmMark = newCHP.getDttmRMark(); byte[] buf = new byte[4]; - LittleEndian.putShort(buf, dttmMark[0]); - LittleEndian.putShort(buf, 2, dttmMark[1]); + newCHP.getDttmRMark().serialize(buf, 0); size += SprmUtils.addSprm((short)0x6805, LittleEndian.getInt(buf), null, sprmList); } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/sprm/CharacterSprmUncompressor.java b/src/scratchpad/src/org/apache/poi/hwpf/sprm/CharacterSprmUncompressor.java index 05c3a724c..8c2027f6a 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/sprm/CharacterSprmUncompressor.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/sprm/CharacterSprmUncompressor.java @@ -54,7 +54,7 @@ package org.apache.poi.hwpf.sprm; -import org.apache.poi.hwpf.usermodel.CharacterProperties; +import org.apache.poi.hwpf.usermodel.CharacterRun; import org.apache.poi.hwpf.usermodel.DateAndTime; import org.apache.poi.hwpf.usermodel.BorderCode; import org.apache.poi.hwpf.usermodel.ShadingDescriptor; @@ -67,14 +67,14 @@ public class CharacterSprmUncompressor { } - public static CharacterProperties uncompressCHP(CharacterProperties parent, + public static CharacterRun uncompressCHP(CharacterRun parent, byte[] grpprl, int offset) { - CharacterProperties newProperties = null; + CharacterRun newProperties = null; try { - newProperties = (CharacterProperties) parent.clone(); + newProperties = (CharacterRun) parent.clone(); } catch (CloneNotSupportedException cnse) { @@ -105,8 +105,8 @@ public class CharacterSprmUncompressor * @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, + static void unCompressCHPOperation (CharacterRun oldCHP, + CharacterRun newCHP, SprmOperation sprm) { @@ -264,7 +264,7 @@ public class CharacterSprmUncompressor { // preserve the fSpec setting from the original CHP boolean fSpec = newCHP.isFSpec (); - newCHP = (CharacterProperties) oldCHP.clone (); + newCHP = (CharacterRun) oldCHP.clone (); newCHP.setFSpec (fSpec); } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/sprm/ParagraphSprmCompressor.java b/src/scratchpad/src/org/apache/poi/hwpf/sprm/ParagraphSprmCompressor.java index 71a2bcf2a..846c85a17 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/sprm/ParagraphSprmCompressor.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/sprm/ParagraphSprmCompressor.java @@ -60,7 +60,7 @@ import java.util.Arrays; import org.apache.poi.util.LittleEndian; -import org.apache.poi.hwpf.usermodel.ParagraphProperties; +import org.apache.poi.hwpf.usermodel.Paragraph; public class ParagraphSprmCompressor { @@ -68,8 +68,8 @@ public class ParagraphSprmCompressor { } - public static byte[] compressParagraphProperty(ParagraphProperties newPAP, - ParagraphProperties oldPAP) + public static byte[] compressParagraphProperty(Paragraph newPAP, + Paragraph oldPAP) { ArrayList sprmList = new ArrayList(); int size = 0; @@ -126,22 +126,23 @@ public class ParagraphSprmCompressor !Arrays.equals(newPAP.getRgdxaTab(), oldPAP.getRgdxaTab()) || !Arrays.equals(newPAP.getRgtbd(), oldPAP.getRgtbd())) { - byte[] oldTabArray = oldPAP.getRgdxaTab(); - byte[] newTabArray = newPAP.getRgdxaTab(); - byte[] newTabDescriptors = newPAP.getRgtbd(); - byte[] varParam = new byte[2 + oldTabArray.length + newTabArray.length + - newTabDescriptors.length]; - varParam[0] = (byte)(oldTabArray.length/2); - int offset = 1; - System.arraycopy(oldTabArray, 0, varParam, offset, oldTabArray.length); - offset += oldTabArray.length; - varParam[offset] = (byte)(newTabArray.length/2); - offset += 1; - System.arraycopy(newTabArray, 0, varParam, offset, newTabArray.length); - offset += newTabArray.length; - System.arraycopy(newTabDescriptors, 0, varParam, offset, newTabDescriptors.length); - - size += SprmUtils.addSprm((short)0xC60D, 0, varParam, sprmList); + /** @todo revisit this */ +// byte[] oldTabArray = oldPAP.getRgdxaTab(); +// byte[] newTabArray = newPAP.getRgdxaTab(); +// byte[] newTabDescriptors = newPAP.getRgtbd(); +// byte[] varParam = new byte[2 + oldTabArray.length + newTabArray.length + +// newTabDescriptors.length]; +// varParam[0] = (byte)(oldTabArray.length/2); +// int offset = 1; +// System.arraycopy(oldTabArray, 0, varParam, offset, oldTabArray.length); +// offset += oldTabArray.length; +// varParam[offset] = (byte)(newTabArray.length/2); +// offset += 1; +// System.arraycopy(newTabArray, 0, varParam, offset, newTabArray.length); +// offset += newTabArray.length; +// System.arraycopy(newTabDescriptors, 0, varParam, offset, newTabDescriptors.length); +// +// size += SprmUtils.addSprm((short)0xC60D, 0, varParam, sprmList); } if (newPAP.getDxaRight() != oldPAP.getDxaRight()) { @@ -155,12 +156,10 @@ public class ParagraphSprmCompressor { size += SprmUtils.addSprm((short)0x8411, newPAP.getDxaLeft1(), null, sprmList); } - if (!Arrays.equals(newPAP.getLspd(), oldPAP.getLspd())) + if (!newPAP.getLspd().equals(oldPAP.getLspd())) { - short[] lspd = newPAP.getLspd(); byte[] buf = new byte[4]; - LittleEndian.putShort(buf, 0, lspd[0]); - LittleEndian.putShort(buf, 2, lspd[1]); + newPAP.getLspd().serialize(buf, 0); size += SprmUtils.addSprm((short)0x6412, LittleEndian.getInt(buf), null, sprmList); } @@ -255,29 +254,29 @@ public class ParagraphSprmCompressor { size += SprmUtils.addSprm((short)0x841A, newPAP.getDxaWidth(), null, sprmList); } - if (!Arrays.equals(newPAP.getBrcTop(), oldPAP.getBrcTop())) + if (!newPAP.getBrcTop().equals(oldPAP.getBrcTop())) { - int brc = SprmUtils.convertBrcToInt(newPAP.getBrcTop()); + int brc = newPAP.getBrcTop().toInt(); size += SprmUtils.addSprm((short)0x6424, brc, null, sprmList); } - if (!Arrays.equals(newPAP.getBrcLeft(), oldPAP.getBrcLeft())) + if (!newPAP.getBrcLeft().equals(oldPAP.getBrcLeft())) { - int brc = SprmUtils.convertBrcToInt(newPAP.getBrcLeft()); + int brc = newPAP.getBrcLeft().toInt(); size += SprmUtils.addSprm((short)0x6425, brc, null, sprmList); } - if (!Arrays.equals(newPAP.getBrcBottom(), oldPAP.getBrcBottom())) + if (!newPAP.getBrcBottom().equals(oldPAP.getBrcBottom())) { - int brc = SprmUtils.convertBrcToInt(newPAP.getBrcBottom()); + int brc = newPAP.getBrcBottom().toInt(); size += SprmUtils.addSprm((short)0x6426, brc, null, sprmList); } - if (!Arrays.equals(newPAP.getBrcRight(), oldPAP.getBrcRight())) + if (!newPAP.getBrcRight().equals(oldPAP.getBrcRight())) { - int brc = SprmUtils.convertBrcToInt(newPAP.getBrcRight()); + int brc = newPAP.getBrcRight().toInt(); size += SprmUtils.addSprm((short)0x6427, brc, null, sprmList); } - if (!Arrays.equals(newPAP.getBrcBar(), oldPAP.getBrcBar())) + if (newPAP.getBrcBar().equals(oldPAP.getBrcBar())) { - int brc = SprmUtils.convertBrcToInt(newPAP.getBrcBar()); + int brc = newPAP.getBrcBar().toInt(); size += SprmUtils.addSprm((short)0x6428, brc, null, sprmList); } if (newPAP.getDxaFromText() != oldPAP.getDxaFromText()) @@ -316,12 +315,12 @@ public class ParagraphSprmCompressor } if (newPAP.getFPropRMark() != oldPAP.getFPropRMark() || newPAP.getIbstPropRMark() != oldPAP.getIbstPropRMark() || - !Arrays.equals(newPAP.getDttmPropRMark(), oldPAP.getDttmPropRMark())) + !newPAP.getDttmPropRMark().equals(oldPAP.getDttmPropRMark())) { byte[] buf = new byte[7]; buf[0] = (byte)newPAP.getFPropRMark(); LittleEndian.putShort(buf, 1, (short)newPAP.getIbstPropRMark()); - System.arraycopy(newPAP.getDttmPropRMark(), 0, buf, 3, 4); + newPAP.getDttmPropRMark().serialize(buf, 3); size += SprmUtils.addSprm((short)0xC63F, 0, buf, sprmList); } if (!Arrays.equals(newPAP.getNumrm(), oldPAP.getNumrm())) diff --git a/src/scratchpad/src/org/apache/poi/hwpf/sprm/ParagraphSprmUncompressor.java b/src/scratchpad/src/org/apache/poi/hwpf/sprm/ParagraphSprmUncompressor.java index a2a8e2d62..ff87a0c7d 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/sprm/ParagraphSprmUncompressor.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/sprm/ParagraphSprmUncompressor.java @@ -54,7 +54,7 @@ package org.apache.poi.hwpf.sprm; -import org.apache.poi.hwpf.usermodel.ParagraphProperties; +import org.apache.poi.hwpf.usermodel.Paragraph; import org.apache.poi.hwpf.usermodel.BorderCode; import org.apache.poi.hwpf.usermodel.DateAndTime; import org.apache.poi.hwpf.usermodel.LineSpacingDescriptor; @@ -73,14 +73,14 @@ public class ParagraphSprmUncompressor { } - public static ParagraphProperties uncompressPAP(ParagraphProperties parent, + public static Paragraph uncompressPAP(Paragraph parent, byte[] grpprl, int offset) { - ParagraphProperties newProperties = null; + Paragraph newProperties = null; try { - newProperties = (ParagraphProperties) parent.clone(); + newProperties = (Paragraph) parent.clone(); } catch (CloneNotSupportedException cnse) { @@ -109,7 +109,7 @@ public class ParagraphSprmUncompressor * @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) + static void unCompressPAPOperation (Paragraph newPAP, SprmOperation sprm) { switch (sprm.getOperation()) { @@ -410,7 +410,7 @@ public class ParagraphSprmUncompressor } } - private static void handleTabs(ParagraphProperties pap, SprmOperation sprm) + private static void handleTabs(Paragraph pap, SprmOperation sprm) { byte[] grpprl = sprm.getGrpprl(); int offset = sprm.getGrpprlOffset(); diff --git a/src/scratchpad/src/org/apache/poi/hwpf/sprm/SectionSprmCompressor.java b/src/scratchpad/src/org/apache/poi/hwpf/sprm/SectionSprmCompressor.java index 55457c770..ab0768a84 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/sprm/SectionSprmCompressor.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/sprm/SectionSprmCompressor.java @@ -58,18 +58,18 @@ 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.hwpf.usermodel.Section; import org.apache.poi.util.LittleEndian; public class SectionSprmCompressor { - private final static SectionProperties DEFAULT_SEP = new SectionProperties(); + private final static Section DEFAULT_SEP = new Section(); public SectionSprmCompressor() { } - public static byte[] compressSectionProperty(SectionProperties newSEP, - SectionProperties oldSEP) + public static byte[] compressSectionProperty(Section newSEP, + Section oldSEP) { int size = 0; ArrayList sprmList = new ArrayList(); @@ -220,31 +220,31 @@ public class SectionSprmCompressor } if (newSEP.getFPropMark() != DEFAULT_SEP.getFPropMark() || newSEP.getIbstPropRMark() != DEFAULT_SEP.getIbstPropRMark() || - newSEP.getDttmPropRMark() != DEFAULT_SEP.getDttmPropRMark()) + !newSEP.getDttmPropRMark().equals(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()); + newSEP.getDttmPropRMark().serialize(buf, offset); size += SprmUtils.addSprm((short)0xD227, -1, buf, sprmList); } - if (!Arrays.equals(newSEP.getBrcTop(), DEFAULT_SEP.getBrcTop())) + if (!newSEP.getBrcTop().equals( DEFAULT_SEP.getBrcTop())) { - size += SprmUtils.addSprm((short)0x702B, SprmUtils.convertBrcToInt(newSEP.getBrcTop()), null, sprmList); + size += SprmUtils.addSprm((short)0x702B, newSEP.getBrcTop().toInt(), null, sprmList); } - if (!Arrays.equals(newSEP.getBrcLeft(), DEFAULT_SEP.getBrcLeft())) + if (!newSEP.getBrcLeft().equals(DEFAULT_SEP.getBrcLeft())) { - size += SprmUtils.addSprm((short)0x702C, SprmUtils.convertBrcToInt(newSEP.getBrcLeft()), null, sprmList); + size += SprmUtils.addSprm((short)0x702C, newSEP.getBrcLeft().toInt(), null, sprmList); } - if (!Arrays.equals(newSEP.getBrcBottom(), DEFAULT_SEP.getBrcBottom())) + if (!newSEP.getBrcBottom().equals(DEFAULT_SEP.getBrcBottom())) { - size += SprmUtils.addSprm((short)0x702D, SprmUtils.convertBrcToInt(newSEP.getBrcBottom()), null, sprmList); + size += SprmUtils.addSprm((short)0x702D, newSEP.getBrcBottom().toInt(), null, sprmList); } - if (!Arrays.equals(newSEP.getBrcRight(), DEFAULT_SEP.getBrcRight())) + if (!newSEP.getBrcRight().equals(DEFAULT_SEP.getBrcRight())) { - size += SprmUtils.addSprm((short)0x702E, SprmUtils.convertBrcToInt(newSEP.getBrcRight()), null, sprmList); + size += SprmUtils.addSprm((short)0x702E, newSEP.getBrcRight().toInt(), null, sprmList); } if (newSEP.getPgbProp() != DEFAULT_SEP.getPgbProp()) { diff --git a/src/scratchpad/src/org/apache/poi/hwpf/sprm/SectionSprmUncompressor.java b/src/scratchpad/src/org/apache/poi/hwpf/sprm/SectionSprmUncompressor.java index 0ffc0e843..71ceaab14 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/sprm/SectionSprmUncompressor.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/sprm/SectionSprmUncompressor.java @@ -54,7 +54,7 @@ package org.apache.poi.hwpf.sprm; -import org.apache.poi.hwpf.usermodel.SectionProperties; +import org.apache.poi.hwpf.usermodel.Section; import org.apache.poi.hwpf.usermodel.BorderCode; public class SectionSprmUncompressor extends SprmUncompressor @@ -62,14 +62,14 @@ public class SectionSprmUncompressor extends SprmUncompressor public SectionSprmUncompressor() { } - public static SectionProperties uncompressSEP(SectionProperties parent, + public static Section uncompressSEP(Section parent, byte[] grpprl, int offset) { - SectionProperties newProperties = null; + Section newProperties = null; try { - newProperties = (SectionProperties) parent.clone(); + newProperties = (Section) parent.clone(); } catch (CloneNotSupportedException cnse) { @@ -95,7 +95,7 @@ public class SectionSprmUncompressor extends SprmUncompressor * @param param The operation's parameter. * @param varParam The operation variable length parameter. */ - static void unCompressSEPOperation (SectionProperties newSEP, SprmOperation sprm) + static void unCompressSEPOperation (Section newSEP, SprmOperation sprm) { switch (sprm.getOperation()) { diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/BorderCode.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/BorderCode.java index 386d78e0a..539e2664a 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/BorderCode.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/BorderCode.java @@ -86,11 +86,24 @@ public class BorderCode LittleEndian.putShort(buf, offset + LittleEndian.SHORT_SIZE, _info2); } + public int toInt() + { + byte[] buf = new byte[4]; + serialize(buf, 0); + return LittleEndian.getInt(buf); + } + public boolean isEmpty() { return _info == 0 && _info2 == 0; } + public boolean equals(Object o) + { + BorderCode brc = (BorderCode)o; + return _info == brc._info && _info2 == brc._info2; + } + public Object clone() throws CloneNotSupportedException { diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/CharacterRun.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/CharacterRun.java new file mode 100644 index 000000000..8a9d66682 --- /dev/null +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/CharacterRun.java @@ -0,0 +1,335 @@ +/* ==================================================================== + * 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 + * . + */ + +package org.apache.poi.hwpf.usermodel; + +import org.apache.poi.hwpf.model.hdftypes.definitions.CHPAbstractType; +import org.apache.poi.hwpf.model.hdftypes.StyleDescription; + +import org.apache.poi.hwpf.sprm.SprmBuffer; + +public class CharacterRun + extends CHPAbstractType implements Cloneable +{ + public final static short SPRM_FRMARKDEL = (short)0x0800; + public final static short SPRM_FRMARK = 0x0801; + public final static short SPRM_FFLDVANISH = 0x0802; + public final static short SPRM_PICLOCATION = 0x6A03; + public final static short SPRM_IBSTRMARK = 0x4804; + public final static short SPRM_DTTMRMARK = 0x6805; + public final static short SPRM_FDATA = 0x0806; + public final static short SPRM_SYMBOL = 0x6A09; + public final static short SPRM_FOLE2 = 0x080A; + public final static short SPRM_HIGHLIGHT = 0x2A0C; + public final static short SPRM_OBJLOCATION = 0x680E; + public final static short SPRM_ISTD = 0x4A30; + public final static short SPRM_FBOLD = 0x0835; + public final static short SPRM_FITALIC = 0x0836; + public final static short SPRM_FSTRIKE = 0x0837; + public final static short SPRM_FOUTLINE = 0x0838; + public final static short SPRM_FSHADOW = 0x0839; + public final static short SPRM_FSMALLCAPS = 0x083A; + public final static short SPRM_FCAPS = 0x083B; + public final static short SPRM_FVANISH = 0x083C; + public final static short SPRM_KUL = 0x2A3E; + public final static short SPRM_DXASPACE = (short)0x8840; + public final static short SPRM_LID = 0x4A41; + public final static short SPRM_ICO = 0x2A42; + public final static short SPRM_HPS = 0x4A43; + public final static short SPRM_HPSPOS = 0x4845; + public final static short SPRM_ISS = 0x2A48; + public final static short SPRM_HPSKERN = 0x484B; + public final static short SPRM_YSRI = 0x484E; + public final static short SPRM_RGFTCASCII = 0x4A4F; + public final static short SPRM_RGFTCFAREAST = 0x4A50; + public final static short SPRM_RGFTCNOTFAREAST = 0x4A51; + public final static short SPRM_CHARSCALE = 0x4852; + public final static short SPRM_FDSTRIKE = 0x2A53; + public final static short SPRM_FIMPRINT = 0x0854; + public final static short SPRM_FSPEC = 0x0855; + public final static short SPRM_FOBJ = 0x0856; + public final static short SPRM_PROPRMARK = (short)0xCA57; + public final static short SPRM_FEMBOSS = 0x0858; + public final static short SPRM_SFXTEXT = 0x2859; + public final static short SPRM_DISPFLDRMARK = (short)0xCA62; + public final static short SPRM_IBSTRMARKDEL = 0x4863; + public final static short SPRM_DTTMRMARKDEL = 0x6864; + public final static short SPRM_BRC = 0x6865; + public final static short SPRM_SHD = 0x4866; + public final static short SPRM_IDSIRMARKDEL = 0x4867; + public final static short SPRM_CPG = 0x486B; + public final static short SPRM_NONFELID = 0x486D; + public final static short SPRM_FELID = 0x486E; + public final static short SPRM_IDCTHINT = 0x286F; + + + StyleDescription _baseStyle; + SprmBuffer _chpx; + + public CharacterRun() + { + field_17_fcPic = -1; + field_22_dttmRMark = new DateAndTime(); + field_23_dttmRMarkDel = new DateAndTime(); + field_36_dttmPropRMark = new DateAndTime(); + field_40_dttmDispFldRMark = new DateAndTime(); + field_41_xstDispFldRMark = new byte[36]; + field_42_shd = new ShadingDescriptor(); + field_43_brc = new BorderCode(); + field_7_hps = 20; + field_24_istd = 10; + field_16_wCharScale = 100; + field_13_lidDefault = 0x0400; + field_14_lidFE = 0x0400; + } + + public boolean isMarkedDeleted() + { + return isFRMarkDel(); + } + + public void markDeleted(boolean mark) + { + if (mark != isFRMarkDel() && mark != _baseStyle.getCHP().isFRMarkDel()) + { + byte newVal = (byte)(mark ? 1 : 0); + _chpx.addSprm(SPRM_FRMARKDEL, newVal); + super.setFRMarkDel(mark); + } + } + + public boolean isBold() + { + return isFBold(); + } + + public void setBold(boolean bold) + { + if (bold != isFBold() && bold != _baseStyle.getCHP().isFBold()) + { + byte newVal = (byte)(bold ? 1 : 0); + _chpx.addSprm(SPRM_FBOLD, newVal); + super.setFBold(bold); + } + } + + public boolean isItalic() + { + return isFItalic(); + } + + public void setItalic(boolean italic) + { + if (italic != isFItalic() && italic != _baseStyle.getCHP().isFItalic()) + { + byte newVal = (byte)(italic ? 1 : 0); + _chpx.addSprm(SPRM_FITALIC, newVal); + super.setFItalic(italic); + } + } + + public boolean isOutlined() + { + return isFOutline(); + } + + public void setOutline(boolean outlined) + { + if (outlined != isFOutline() && outlined != _baseStyle.getCHP().isFOutline()) + { + byte newVal = (byte)(outlined ? 1 : 0); + _chpx.addSprm(SPRM_FOUTLINE, newVal); + super.setFOutline(outlined); + } + + } + + public boolean isFldVanished() + { + return isFFldVanish(); + } + + public void setFldVanish(boolean fldVanish) + { + if (fldVanish != isFFldVanish() && fldVanish != _baseStyle.getCHP().isFFldVanish()) + { + byte newVal = (byte)(fldVanish ? 1 : 0); + _chpx.addSprm(SPRM_FFLDVANISH, newVal); + super.setFFldVanish(fldVanish); + } + + } + public boolean isSmallCaps() + { + return isFSmallCaps(); + } + + public void setSmallCaps(boolean smallCaps) + { + if (smallCaps != isFSmallCaps() && smallCaps != _baseStyle.getCHP().isFSmallCaps()) + { + byte newVal = (byte)(smallCaps ? 1 : 0); + _chpx.addSprm(SPRM_FSMALLCAPS, newVal); + super.setFSmallCaps(smallCaps); + } + } + public boolean isCapitalized() + { + return isFCaps(); + } + + public void setCapitalized(boolean caps) + { + if (caps != isFCaps() && caps != _baseStyle.getCHP().isFCaps()) + { + byte newVal = (byte)(caps ? 1 : 0); + _chpx.addSprm(SPRM_FCAPS, newVal); + super.setFCaps(caps); + } + } + + public boolean isVanished() + { + return isFVanish(); + } + + public void setVanished(boolean vanish) + { + if (vanish != isFVanish() && vanish != _baseStyle.getCHP().isFVanish()) + { + byte newVal = (byte)(vanish ? 1 : 0); + _chpx.addSprm(SPRM_FVANISH, newVal); + super.setFVanish(vanish); + } + + } + public boolean isMarkedInserted() + { + return isFRMark(); + } + + public void markInserted(boolean mark) + { + if (mark != isFRMark() && mark != _baseStyle.getCHP().isFRMark()) + { + byte newVal = (byte)(mark ? 1 : 0); + _chpx.addSprm(SPRM_FRMARK, newVal); + super.setFRMark(mark); + } + } + + public boolean isStrikeThrough() + { + return isFStrike(); + } + + public void strikeThrough(boolean strike) + { + if (strike != isFStrike() && strike != _baseStyle.getCHP().isFStrike()) + { + byte newVal = (byte)(strike ? 1 : 0); + _chpx.addSprm(SPRM_FSTRIKE, newVal); + super.setFStrike(strike); + } + + } + public boolean isShadowed() + { + return isFShadow(); + } + + public void setShadow(boolean shadow) + { + if (shadow != isFShadow() && shadow != _baseStyle.getCHP().isFShadow()) + { + byte newVal = (byte)(shadow ? 1 : 0); + _chpx.addSprm(SPRM_FSHADOW, newVal); + super.setFShadow(shadow); + } + + } + + public boolean isEmbossed() + { + return isFEmboss(); + } + + public void setEmbossed(boolean emboss) + { + if (emboss != isFEmboss() && emboss != _baseStyle.getCHP().isFEmboss()) + { + byte newVal = (byte)(emboss ? 1 : 0); + _chpx.addSprm(SPRM_FEMBOSS, newVal); + super.setFEmboss(emboss); + } + + } + + + public Object clone() + throws CloneNotSupportedException + { + CharacterRun cp = (CharacterRun)super.clone(); + cp.field_22_dttmRMark = (DateAndTime)field_22_dttmRMark.clone(); + cp.field_23_dttmRMarkDel = (DateAndTime)field_23_dttmRMarkDel.clone(); + cp.field_36_dttmPropRMark = (DateAndTime)field_36_dttmPropRMark.clone(); + cp.field_40_dttmDispFldRMark = (DateAndTime)field_40_dttmDispFldRMark.clone(); + cp.field_41_xstDispFldRMark = (byte[])field_41_xstDispFldRMark.clone(); + cp.field_42_shd = (ShadingDescriptor)field_42_shd.clone(); + + return cp; + } + + +} diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/DateAndTime.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/DateAndTime.java index ccb2d3530..aae16ddb6 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/DateAndTime.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/DateAndTime.java @@ -86,6 +86,12 @@ public class DateAndTime LittleEndian.putShort(buf, offset + LittleEndian.SHORT_SIZE, _info2); } + public boolean equals(Object o) + { + DateAndTime dttm = (DateAndTime)o; + return _info == dttm._info && _info2 == dttm._info2; + } + public Object clone() throws CloneNotSupportedException { diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/LineSpacingDescriptor.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/LineSpacingDescriptor.java index d660a6f41..556f681a5 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/LineSpacingDescriptor.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/LineSpacingDescriptor.java @@ -83,8 +83,20 @@ public class LineSpacingDescriptor _fMultiLinespace = fMultiLinespace; } + public void serialize(byte[] buf, int offset) + { + LittleEndian.putShort(buf, offset, _dyaLine); + LittleEndian.putShort(buf, offset + LittleEndian.SHORT_SIZE, _fMultiLinespace); + } + public void setDyaLine(short dyaLine) { _dyaLine = dyaLine; } + public boolean equals(Object o) + { + LineSpacingDescriptor lspd = (LineSpacingDescriptor)o; + + return _dyaLine == lspd._dyaLine && _fMultiLinespace == lspd._fMultiLinespace; + } } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Paragraph.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Paragraph.java new file mode 100644 index 000000000..a7ba08537 --- /dev/null +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Paragraph.java @@ -0,0 +1,161 @@ +/* ==================================================================== + * 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 + * . + */ + +package org.apache.poi.hwpf.usermodel; + +import org.apache.poi.hwpf.model.hdftypes.definitions.PAPAbstractType; +import org.apache.poi.hwpf.model.hdftypes.StyleDescription; + +import org.apache.poi.hwpf.sprm.SprmBuffer; + +public class Paragraph + extends PAPAbstractType + implements Cloneable +{ + public final static short SPRM_JC = 0x2403; + public final static short SPRM_FSIDEBYSIDE = 0x2404; + public final static short SPRM_FKEEP = 0x2405; + public final static short SPRM_FKEEPFOLLOW = 0x2406; + public final static short SPRM_FPAGEBREAKBEFORE = 0x2407; + public final static short SPRM_BRCL = 0x2408; + public final static short SPRM_BRCP = 0x2409; + public final static short SPRM_ILVL = 0x260A; + public final static short SPRM_ILFO = 0x460B; + public final static short SPRM_FNOLINENUMB = 0x240C; + public final static short SPRM_CHGTABSPAPX = (short)0xC60D; + public final static short SPRM_DXARIGHT = (short)0x840E; + public final static short SPRM_DXALEFT = (short)0x840F; + public final static short SPRM_DXALEFT1 = (short)0x8411; + public final static short SPRM_DYALINE = 0x6412; + public final static short SPRM_DYABEFORE = (short)0xA413; + public final static short SPRM_DYAAFTER = (short)0xA414; + public final static short SPRM_CHGTABS = (short)0xC615; + public final static short SPRM_FINTABLE = 0x2416; + public final static short SPRM_FTTP = 0x2417; + public final static short SPRM_DXAABS = (short)0x8418; + public final static short SPRM_DYAABS = (short)0x8419; + public final static short SPRM_DXAWIDTH = (short)0x841A; + public final static short SPRM_PC = 0x261B; + public final static short SPRM_WR = 0x2423; + public final static short SPRM_BRCTOP = 0x6424; + public final static short SPRM_BRCLEFT = 0x6425; + public final static short SPRM_BRCBOTTOM = 0x6426; + public final static short SPRM_BRCRIGHT = 0x6427; + public final static short SPRM_BRCBAR = 0x6629; + public final static short SPRM_FNOAUTOHYPH = 0x242A; + public final static short SPRM_WHEIGHTABS = 0x442B; + public final static short SPRM_DCS = 0x442C; + public final static short SPRM_SHD = 0x442D; + public final static short SPRM_DYAFROMTEXT = (short)0x842E; + public final static short SPRM_DXAFROMTEXT = (short)0x842F; + public final static short SPRM_FLOCKED = 0x2430; + public final static short SPRM_FWIDOWCONTROL = 0x2431; + public final static short SPRM_RULER = (short)0xC632; + public final static short SPRM_FKINSOKU = 0x2433; + public final static short SPRM_FWORDWRAP = 0x2434; + public final static short SPRM_FOVERFLOWPUNCT = 0x2435; + public final static short SPRM_FTOPLINEPUNCT = 0x2436; + public final static short SPRM_AUTOSPACEDE = 0x2437; + public final static short SPRM_AUTOSPACEDN = 0x2438; + public final static short SPRM_WALIGNFONT = 0x4439; + public final static short SPRM_FRAMETEXTFLOW = 0x443A; + public final static short SPRM_ANLD = (short)0xC63E; + public final static short SPRM_PROPRMARK = (short)0xC63F; + public final static short SPRM_OUTLVL = 0x2640; + public final static short SPRM_FBIDI = 0x2441; + public final static short SPRM_FNUMRMLNS = 0x2443; + public final static short SPRM_CRLF = 0x2444; + public final static short SPRM_NUMRM = (short)0xC645; + public final static short SPRM_USEPGSUSETTINGS = 0x2447; + public final static short SPRM_FADJUSTRIGHT = 0x2448; + + + private StyleDescription _baseStyle; + private SprmBuffer _papx; + + public Paragraph() + { + field_21_lspd = new LineSpacingDescriptor(); + field_24_phe = new byte[12]; + field_46_brcTop = new BorderCode(); + field_47_brcLeft = new BorderCode(); + field_48_brcBottom = new BorderCode(); + field_49_brcRight = new BorderCode(); + field_50_brcBetween = new BorderCode(); + field_51_brcBar = new BorderCode(); + field_60_anld = new byte[84]; + this.field_17_fWidowControl = 1; + this.field_21_lspd.setMultiLinespace((short)1); + this.field_21_lspd.setDyaLine((short)240); + this.field_12_ilvl = (byte)9; + + } + + public Object clone() + throws CloneNotSupportedException + { + Paragraph pp = (Paragraph)super.clone(); + pp.field_21_lspd = (LineSpacingDescriptor)field_21_lspd.clone(); + pp.field_24_phe = (byte[])field_24_phe.clone(); + pp.field_46_brcTop = (BorderCode)field_46_brcTop.clone(); + pp.field_47_brcLeft = (BorderCode)field_47_brcLeft.clone(); + pp.field_48_brcBottom = (BorderCode)field_48_brcBottom.clone(); + pp.field_49_brcRight = (BorderCode)field_49_brcRight.clone(); + pp.field_50_brcBetween = (BorderCode)field_50_brcBetween.clone(); + pp.field_51_brcBar = (BorderCode)field_51_brcBar.clone(); + pp.field_60_anld = (byte[])field_60_anld.clone(); + return pp; + } + +} diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Section.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Section.java new file mode 100644 index 000000000..76b932ac7 --- /dev/null +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Section.java @@ -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 + * . + */ + +package org.apache.poi.hwpf.usermodel; + +import org.apache.poi.hwpf.model.hdftypes.definitions.SEPAbstractType; + +public class Section + extends SEPAbstractType +{ + public Section() + { + 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 + { + Section copy = (Section)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; + } + +}