From 74b4e4792ebed5efcdbacb70e73270b83c79b89c Mon Sep 17 00:00:00 2001 From: Said Ryan Ackley Date: Fri, 5 Mar 2004 13:07:57 +0000 Subject: [PATCH] git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@353534 13f79535-47bb-0310-9956-ffa450edef68 --- .../hwpf/sprm/CharacterSprmCompressor.java | 5 ++ .../hwpf/sprm/CharacterSprmUncompressor.java | 3 + .../hwpf/usermodel/CharacterProperties.java | 56 +++++++++++++++++++ .../poi/hwpf/usermodel/CharacterRun.java | 26 +++++++-- .../apache/poi/hwpf/usermodel/ListEntry.java | 5 ++ .../apache/poi/hwpf/usermodel/Paragraph.java | 7 ++- .../org/apache/poi/hwpf/usermodel/Range.java | 25 ++++++--- .../apache/poi/hwpf/usermodel/Section.java | 5 ++ .../org/apache/poi/hwpf/usermodel/Table.java | 7 ++- .../apache/poi/hwpf/usermodel/TableCell.java | 2 +- 10 files changed, 123 insertions(+), 18 deletions(-) diff --git a/src/scratchpad/src/org/apache/poi/hwpf/sprm/CharacterSprmCompressor.java b/src/scratchpad/src/org/apache/poi/hwpf/sprm/CharacterSprmCompressor.java index 74a8e0b81..8e6b2aeee 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/sprm/CharacterSprmCompressor.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/sprm/CharacterSprmCompressor.java @@ -313,6 +313,11 @@ public class CharacterSprmCompressor { size += SprmUtils.addSprm((short)0x2859, newCHP.getSfxtText(), null, sprmList); } + if (newCHP.getIco24() != oldCHP.getIco24()) + { + if(newCHP.getIco24() != -1) // don't add a sprm if we're looking at an ico = Auto + size += SprmUtils.addSprm((short)0x6870, newCHP.getIco24(), null, sprmList); + } return SprmUtils.getGrpprl(sprmList, size); } 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 56b1bd34a..2c69bde74 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/sprm/CharacterSprmUncompressor.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/sprm/CharacterSprmUncompressor.java @@ -575,6 +575,9 @@ public class CharacterSprmUncompressor case 0x6f: newCHP.setIdctHint ((byte) sprm.getOperand()); break; + case 0x70: + newCHP.setIco24 (sprm.getOperand()); + break; } } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/CharacterProperties.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/CharacterProperties.java index 675f06d4a..47add56d5 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/CharacterProperties.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/CharacterProperties.java @@ -113,6 +113,7 @@ public class CharacterProperties public final static short SPRM_FELID = 0x486E; public final static short SPRM_IDCTHINT = 0x286F; + int _ico24 = -1; // default to -1 so we can ignore it for word 97 files public CharacterProperties() { @@ -352,6 +353,61 @@ public class CharacterProperties super.setIcoHighlight(color); } + /** + * Get the ico24 field for the CHP record. + */ + public int getIco24() + { + if ( _ico24 == -1 ) + { + switch(field_11_ico) // convert word 97 colour numbers to 0xBBGGRR value + { + case 0: // auto + return -1; + case 1: // black + return 0x000000; + case 2: // blue + return 0xFF0000; + case 3: // cyan + return 0xFFFF00; + case 4: // green + return 0x00FF00; + case 5: // magenta + return 0xFF00FF; + case 6: // red + return 0x0000FF; + case 7: // yellow + return 0x00FFFF; + case 8: // white + return 0x0FFFFFF; + case 9: // dark blue + return 0x800000; + case 10: // dark cyan + return 0x808000; + case 11: // dark green + return 0x008000; + case 12: // dark magenta + return 0x800080; + case 13: // dark red + return 0x000080; + case 14: // dark yellow + return 0x008080; + case 15: // dark grey + return 0x808080; + case 16: // light grey + return 0xC0C0C0; + } + } + return _ico24; + } + + /** + * Set the ico24 field for the CHP record. + */ + public void setIco24(int colour24) + { + _ico24 = colour24 & 0xFFFFFF; // only keep the 24bit 0xBBGGRR colour + } 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 index 5ee4cfb7f..ca08bf578 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/CharacterRun.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/CharacterRun.java @@ -127,12 +127,10 @@ public class CharacterRun _chpx = chpx.getSprmBuf(); } -// SprmBuffer initProperties(CharacterProperties baseStyle) -// { -// byte[] grpprl = CharacterSprmCompressor.compressCharacterProperty(_props, baseStyle); -// _chpx = new SprmBuffer(grpprl); -// return _chpx; -// } + public int type() + { + return TYPE_CHARACTER; + } public boolean isMarkedDeleted() { @@ -449,6 +447,22 @@ public class CharacterRun _chpx.addSprm(SPRM_HIGHLIGHT, color); } + /** + * Get the ico24 field for the CHP record. + */ + public int getIco24() + { + return _props.getIco24(); + } + + /** + * Set the ico24 field for the CHP record. + */ + public void setIco24(int colour24) + { + _props.setIco24(colour24); + } + public Object clone() throws CloneNotSupportedException { diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/ListEntry.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/ListEntry.java index 94aafc3b2..7cc3a0dcd 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/ListEntry.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/ListEntry.java @@ -21,4 +21,9 @@ public class ListEntry _overrideLevel = override.getOverrideLevel(pap.getIlvl()); _level = tables.getLevel(override.getLsid(), pap.getIlvl()); } + + public int type() + { + return TYPE_LISTENTRY; + } } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Paragraph.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Paragraph.java index e8c01a053..32fccf420 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Paragraph.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Paragraph.java @@ -131,7 +131,7 @@ public class Paragraph protected Paragraph(int startIdx, int endIdx, Table parent) { - super(startIdx, endIdx, Range.PARAGRAPH_INDEX, parent); + super(startIdx, endIdx, Range.TYPE_PARAGRAPH, parent); PAPX papx = (PAPX)_paragraphs.get(_parEnd - 1); _props = papx.getParagraphProperties(_doc.getStyleSheet()); _papx = papx.getSprmBuf(); @@ -144,6 +144,11 @@ public class Paragraph _papx = papx; } + public int type() + { + return TYPE_PARAGRAPH; + } + public boolean isInTable() { return _props.getFInTable() != 0; diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Range.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Range.java index dd2534fa7..9df7ac4be 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Range.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Range.java @@ -95,10 +95,13 @@ import java.lang.ref.WeakReference; public class Range { - public static final int PARAGRAPH_INDEX = 0; - public static final int CHARACTER_INDEX = 1; - public static final int SECTION_INDEX = 2; - public static final int TEXT_INDEX = 3; + public static final int TYPE_PARAGRAPH = 0; + public static final int TYPE_CHARACTER= 1; + public static final int TYPE_SECTION = 2; + public static final int TYPE_TEXT = 3; + public static final int TYPE_LISTENTRY = 4; + public static final int TYPE_TABLE = 5; + public static final int TYPE_UNDEFINED = 6; private WeakReference _parent; protected int _start; @@ -121,7 +124,6 @@ public class Range int _textStart; int _textEnd; - // protected Range() // { // @@ -162,28 +164,28 @@ public class Range switch (idxType) { - case PARAGRAPH_INDEX: + case TYPE_PARAGRAPH: _parStart = parent._parStart + startIdx; _parEnd = parent._parStart + endIdx; _start = ((PropertyNode)_paragraphs.get(_parStart)).getStart(); _end = ((PropertyNode)_paragraphs.get(_parEnd)).getEnd(); _parRangeFound = true; break; - case CHARACTER_INDEX: + case TYPE_CHARACTER: _charStart = parent._charStart + startIdx; _charEnd = parent._charStart + endIdx; _start = ((PropertyNode)_characters.get(_charStart)).getStart(); _end = ((PropertyNode)_characters.get(_charEnd)).getEnd(); _charRangeFound = true; break; - case SECTION_INDEX: + case TYPE_SECTION: _sectionStart = parent._sectionStart + startIdx; _sectionEnd = parent._sectionStart + endIdx; _start = ((PropertyNode)_sections.get(_sectionStart)).getStart(); _end = ((PropertyNode)_sections.get(_sectionEnd)).getEnd(); _sectionRangeFound = true; break; - case TEXT_INDEX: + case TYPE_TEXT: _textStart = parent._textStart + startIdx; _textEnd = parent._textStart + endIdx; _start = ((PropertyNode)_text.get(_textStart)).getStart(); @@ -436,6 +438,11 @@ public class Range return pap; } + public int type() + { + return TYPE_UNDEFINED; + } + private void initAll() { initText(); diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Section.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Section.java index fdc086a64..e0f88d179 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Section.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Section.java @@ -68,6 +68,11 @@ public class Section _props = sepx.getSectionProperties(); } + public int type() + { + return TYPE_SECTION; + } + public Object clone() throws CloneNotSupportedException { diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Table.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Table.java index 20a3ff252..8bea1cab5 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Table.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Table.java @@ -9,7 +9,7 @@ public class Table Table(int startIdx, int endIdx, Range parent, int levelNum) { - super(startIdx, endIdx, Range.PARAGRAPH_INDEX, parent); + super(startIdx, endIdx, Range.TYPE_PARAGRAPH, parent); _rows = new ArrayList(); int numParagraphs = numParagraphs(); @@ -33,6 +33,11 @@ public class Table return _rows.size(); } + public int type() + { + return TYPE_TABLE; + } + public TableRow getRow(int index) { return (TableRow)_rows.get(index); diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/TableCell.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/TableCell.java index 6e0e3bbe4..9b67897f9 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/TableCell.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/TableCell.java @@ -8,7 +8,7 @@ public class TableCell public TableCell(int startIdx, int endIdx, TableRow parent, int levelNum, TableCellDescriptor tcd) { - super(startIdx, endIdx, Range.PARAGRAPH_INDEX, parent); + super(startIdx, endIdx, Range.TYPE_PARAGRAPH, parent); _levelNum = levelNum; }