From 2784b5044ae1f7de14a79456869456030b615401 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Sat, 1 Feb 2014 21:52:19 +0000 Subject: [PATCH] Expose the StyleIndex of CharacterRuns, and expand the range style tests to cover this + related git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1563486 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/hwpf/usermodel/CharacterRun.java | 20 +++++++++- .../apache/poi/hwpf/usermodel/Paragraph.java | 10 ++++- .../hwpf/usermodel/TestRangeProperties.java | 39 ++++++++++++++++--- 3 files changed, 59 insertions(+), 10 deletions(-) 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 97875ee248..41c0b8ad68 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/CharacterRun.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/CharacterRun.java @@ -85,8 +85,9 @@ public final class CharacterRun public final static short SPRM_FELID = 0x486E; public final static short SPRM_IDCTHINT = 0x286F; - SprmBuffer _chpx; - CharacterProperties _props; + protected short _istd; + protected SprmBuffer _chpx; + protected CharacterProperties _props; /** * @@ -100,6 +101,7 @@ public final class CharacterRun super(Math.max(parent._start, chpx.getStart()), Math.min(parent._end, chpx.getEnd()), parent); _props = chpx.getCharacterProperties(ss, istd); _chpx = chpx.getSprmBuf(); + _istd = istd; } /** @@ -630,6 +632,20 @@ public final class CharacterRun return _props.getLidDefault(); } + /** + * Returns the index of the base style which applies to + * this Run. Details of the style can be looked up + * from the {@link StyleSheet}, via + * {@link StyleSheet#getStyleDescription(int)}. + * Note that runs typically override some of the style + * properties from the base, so normally style information + * should be fetched directly from the {@link CharacterRun} + * itself. + */ + public short getStyleIndex() { + return _istd; + } + public String toString() { String text = text(); return "CharacterRun of " + text.length() + " characters - " + text; 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 65f907691b..d292396d15 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Paragraph.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Paragraph.java @@ -204,9 +204,15 @@ public class Paragraph extends Range implements Cloneable _istd = papx.getIstd(); } -public short getStyleIndex() + /** + * Returns the index of the style which applies to this + * Paragraph. Details of the style can be looked up + * from the {@link StyleSheet}, via + * {@link StyleSheet#getStyleDescription(int)} + */ + public short getStyleIndex() { - return _istd; + return _istd; } @Deprecated diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeProperties.java b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeProperties.java index facdbee89f..e1dfd0386e 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeProperties.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeProperties.java @@ -20,9 +20,11 @@ package org.apache.poi.hwpf.usermodel; import java.util.List; import junit.framework.TestCase; + import org.apache.poi.hwpf.HWPFDocument; import org.apache.poi.hwpf.HWPFTestDataSamples; import org.apache.poi.hwpf.model.PAPX; +import org.apache.poi.hwpf.model.StyleSheet; /** * Tests to ensure that our ranges end up with @@ -145,10 +147,20 @@ public final class TestRangeProperties extends TestCase { // Ensure none of the paragraphs refer to one that isn't there, // and none of their character runs either + // Also check all use the default style + StyleSheet ss = a.getStyleSheet(); for(int i=0; i