From: Nick Burch Date: Fri, 21 Apr 2006 13:43:53 +0000 (+0000) Subject: Bug fix for newly created bitmask values (part of bug 39324). A few enhancements... X-Git-Tag: REL_3_0_ALPHA3~115 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=43d7696efdbd5be8cc062441617cb7e0153f53be;p=poi.git Bug fix for newly created bitmask values (part of bug 39324). A few enhancements to make adding new TextPropCollections easier git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@395880 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java index 8ef16c9164..cf86b0eba1 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java @@ -173,10 +173,12 @@ public class StyleTextPropAtom extends RecordAtom paragraphStyles = new LinkedList(); charStyles = new LinkedList(); - TextPropCollection defaultParagraphTextProps = new TextPropCollection(parentTextSize, (short)0); + TextPropCollection defaultParagraphTextProps = + new TextPropCollection(parentTextSize, (short)0); paragraphStyles.add(defaultParagraphTextProps); - TextPropCollection defaultCharacterTextProps = new TextPropCollection(parentTextSize); + TextPropCollection defaultCharacterTextProps = + new TextPropCollection(parentTextSize); charStyles.add(defaultCharacterTextProps); // Set us as now initialised @@ -271,6 +273,11 @@ public class StyleTextPropAtom extends RecordAtom // Save this properties set charStyles.add(thisCollection); + + // Handle extra 1 char styles at the end + if(pos < rawContents.length && textHandled == size) { + size++; + } } // Handle anything left over @@ -309,6 +316,27 @@ public class StyleTextPropAtom extends RecordAtom rawContents = baos.toByteArray(); } + + /** + * Create a new Paragraph TextPropCollection, and add it to the list + * @param charactersCovered The number of characters this TextPropCollection will cover + * @return the new TextPropCollection, which will then be in the list + */ + public TextPropCollection addParagraphTextPropCollection(int charactersCovered) { + TextPropCollection tpc = new TextPropCollection(charactersCovered, (short)0); + paragraphStyles.add(tpc); + return tpc; + } + /** + * Create a new Character TextPropCollection, and add it to the list + * @param charactersCovered The number of characters this TextPropCollection will cover + * @return the new TextPropCollection, which will then be in the list + */ + public TextPropCollection addCharacterTextPropCollection(int charactersCovered) { + TextPropCollection tpc = new TextPropCollection(charactersCovered); + charStyles.add(tpc); + return tpc; + } /* ************************************************************************ */ @@ -320,7 +348,7 @@ public class StyleTextPropAtom extends RecordAtom * Used to hold the number of characters affected, the list of active * properties, and the random reserved field if required. */ - public static class TextPropCollection { + public class TextPropCollection { private int charactersCovered; private short reservedField; private LinkedList textPropList; @@ -372,17 +400,6 @@ public class StyleTextPropAtom extends RecordAtom return textProp; } - /** - * Create a new collection of text properties (be they paragraph - * or character) which will be groked via a subsequent call to - * buildTextPropList(). - */ - public TextPropCollection(int charactersCovered, short reservedField) { - this.charactersCovered = charactersCovered; - this.reservedField = reservedField; - textPropList = new LinkedList(); - } - /** * For an existing set of text properties, build the list of * properties coded for in a given run of properties. @@ -413,11 +430,22 @@ public class StyleTextPropAtom extends RecordAtom return bytesPassed; } + /** + * Create a new collection of text properties (be they paragraph + * or character) which will be groked via a subsequent call to + * buildTextPropList(). + */ + private TextPropCollection(int charactersCovered, short reservedField) { + this.charactersCovered = charactersCovered; + this.reservedField = reservedField; + textPropList = new LinkedList(); + } + /** * Create a new collection of text properties (be they paragraph * or character) for a run of text without any */ - public TextPropCollection(int textSize) { + private TextPropCollection(int textSize) { charactersCovered = textSize; reservedField = -1; textPropList = new LinkedList(); @@ -434,7 +462,7 @@ public class StyleTextPropAtom extends RecordAtom /** * Writes out to disk the header, and then all the properties */ - private void writeOut(OutputStream o) throws IOException { + protected void writeOut(OutputStream o) throws IOException { // First goes the number of characters we affect writeLittleEndian(charactersCovered,o); @@ -487,6 +515,7 @@ public class StyleTextPropAtom extends RecordAtom this.sizeOfDataBlock = sizeOfDataBlock; this.maskInHeader = maskInHeader; this.propName = propName; + this.dataValue = 0; } /** @@ -557,6 +586,11 @@ public class StyleTextPropAtom extends RecordAtom this.propName = overallName; subPropMasks = new int[subPropNames.length]; subPropMatches = new boolean[subPropNames.length]; + + // Initialise the masks list + for(int i=0; i