diff options
author | Nick Burch <nick@apache.org> | 2010-09-20 11:45:53 +0000 |
---|---|---|
committer | Nick Burch <nick@apache.org> | 2010-09-20 11:45:53 +0000 |
commit | d71e92ace2cd7fe60d6368caa95e8d21cd5b6e5e (patch) | |
tree | 9b61a89072d4f211ce29b07802583afc1bdbdb2a | |
parent | 76a609d1477ec021959e3de6e73ef2153d16a5ff (diff) | |
download | poi-d71e92ace2cd7fe60d6368caa95e8d21cd5b6e5e.tar.gz poi-d71e92ace2cd7fe60d6368caa95e8d21cd5b6e5e.zip |
Apply patch from bug #49820 - Fix HWPF paragraph levels, so that outline levels can be properly fetched
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@998897 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | src/documentation/content/xdocs/status.xml | 1 | ||||
-rw-r--r-- | src/scratchpad/src/org/apache/poi/hwpf/sprm/ParagraphSprmUncompressor.java | 9 | ||||
-rw-r--r-- | src/scratchpad/src/org/apache/poi/hwpf/usermodel/Paragraph.java | 15 | ||||
-rw-r--r-- | src/scratchpad/src/org/apache/poi/hwpf/usermodel/ParagraphProperties.java | 2 | ||||
-rw-r--r-- | src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBug49820.java | 63 | ||||
-rw-r--r-- | test-data/document/Bug49820.doc | bin | 0 -> 23552 bytes |
6 files changed, 80 insertions, 10 deletions
diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index 9123d65c13..f1b71436e1 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ <changes> <release version="3.7-beta3" date="2010-??-??"> + <action dev="poi-developers" type="fix">49820 - Fix HWPF paragraph levels, so that outline levels can be properly fetched</action> <action dev="poi-developers" type="fix">47271 - Avoid infinite loops on broken HWPF documents with a corrupt CHP style with a parent of itself</action> <action dev="poi-developers" type="fix">49936 - Handle HWPF documents with problematic HeaderStories better</action> <action dev="poi-developers" type="fix">49933 - Support sections in Word 6 and Word 95 files (HWPFOldDocument)</action> 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 a6b12ec2da..695de59646 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/sprm/ParagraphSprmUncompressor.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/sprm/ParagraphSprmUncompressor.java @@ -337,11 +337,12 @@ public final class ParagraphSprmUncompressor } break; case 0x40: - - //newPAP._lvl = param; - if (newPAP.getIstd () >= 1 && newPAP.getIstd () <= 9) + // This condition commented out, as Word seems to set outline levels even for + // paragraph with other styles than Heading 1..9, even though specification + // does not say so. See bug 49820 for discussion. + //if (newPAP.getIstd () < 1 && newPAP.getIstd () > 9) { - newPAP.setIlvl ((byte) sprm.getOperand()); + newPAP.setLvl ((byte) sprm.getOperand()); } break; case 0x41: 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 087c6c5c16..87fe4d7f1d 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Paragraph.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Paragraph.java @@ -435,14 +435,19 @@ public class Paragraph extends Range implements Cloneable { } public int getIlfo() - { + { return _props.getIlfo(); - } + } - public int getIlvl() - { + public int getIlvl() + { return _props.getIlvl(); - } + } + + public int getLvl() + { + return _props.getLvl(); + } void setTableRowEnd(TableProperties props) { diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/ParagraphProperties.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/ParagraphProperties.java index 8944eb0600..8ab3d904a1 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/ParagraphProperties.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/ParagraphProperties.java @@ -35,7 +35,7 @@ public final class ParagraphProperties extends PAPAbstractType implements Clonea 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; + this.field_58_lvl = (byte)9; this.field_66_rgdxaTab = new int[0]; this.field_67_rgtbd = new byte[0]; this.field_63_dttmPropRMark = new DateAndTime(); diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBug49820.java b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBug49820.java new file mode 100644 index 0000000000..4e96646f44 --- /dev/null +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBug49820.java @@ -0,0 +1,63 @@ +/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hwpf.usermodel;
+
+import java.io.IOException;
+import junit.framework.TestCase;
+
+import org.apache.poi.hwpf.HWPFDocument;
+import org.apache.poi.hwpf.HWPFTestDataSamples;
+import org.apache.poi.hwpf.model.StyleSheet;
+
+public final class TestBug49820 extends TestCase {
+
+ public void test() throws IOException {
+ HWPFDocument doc = HWPFTestDataSamples.openSampleFile("Bug49820.doc");
+
+ Range documentRange = doc.getRange();
+ StyleSheet styleSheet = doc.getStyleSheet();
+
+ // JUnit asserts
+ assertLevels(documentRange, styleSheet, 0, 0, 0);
+ assertLevels(documentRange, styleSheet, 1, 1, 1);
+ assertLevels(documentRange, styleSheet, 2, 2, 2);
+ assertLevels(documentRange, styleSheet, 3, 3, 3);
+ assertLevels(documentRange, styleSheet, 4, 4, 4);
+ assertLevels(documentRange, styleSheet, 5, 5, 5);
+ assertLevels(documentRange, styleSheet, 6, 6, 6);
+ assertLevels(documentRange, styleSheet, 7, 7, 7);
+ assertLevels(documentRange, styleSheet, 8, 8, 8);
+ assertLevels(documentRange, styleSheet, 9, 9, 9);
+ assertLevels(documentRange, styleSheet, 10, 9, 0);
+ assertLevels(documentRange, styleSheet, 11, 9, 4);
+
+ // output to console
+ /*for (int i=0; i<documentRange.numParagraphs(); i++) {
+ Paragraph par = documentRange.getParagraph(i);
+ int styleLvl = styleSheet.getParagraphStyle(par.getStyleIndex()).getLvl();
+ int parLvl = par.getLvl();
+ System.out.println("Style level: " + styleLvl + ", paragraph level: " + parLvl + ", text: " + par.text());
+ }*/
+ }
+
+ private void assertLevels(Range documentRange, StyleSheet styleSheet, int parIndex, int expectedStyleLvl, int expectedParLvl) {
+ Paragraph par = documentRange.getParagraph(parIndex);
+ assertEquals(expectedStyleLvl, styleSheet.getParagraphStyle(par.getStyleIndex()).getLvl());
+ assertEquals(expectedParLvl, par.getLvl());
+ }
+}
\ No newline at end of file diff --git a/test-data/document/Bug49820.doc b/test-data/document/Bug49820.doc Binary files differnew file mode 100644 index 0000000000..b3a4aea3f2 --- /dev/null +++ b/test-data/document/Bug49820.doc |