Author: nick Date: Fri Apr 21 06:43:53 2006 New Revision: 395880 URL: http://svn.apache.org/viewcvs?rev=395880&view=rev Log: Bug fix for newly created bitmask values (part of bug 39324). A few enhancements to make adding new TextPropCollections easier
Modified: jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java Modified: jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java URL: http://svn.apache.org/viewcvs/jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java?rev=395880&r1=395879&r2=395880&view=diff ============================================================================== --- jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java (original) +++ jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java Fri Apr 21 06:43:53 2006 @@ -173,10 +173,12 @@ 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 @@ // 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 @@ 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 @@ * 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; @@ -373,17 +401,6 @@ } /** - * 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. * @return the number of bytes that were used encoding the properties list @@ -415,9 +432,20 @@ /** * 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 @@ /** * 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 @@ this.sizeOfDataBlock = sizeOfDataBlock; this.maskInHeader = maskInHeader; this.propName = propName; + this.dataValue = 0; } /** @@ -557,6 +586,11 @@ this.propName = overallName; subPropMasks = new int[subPropNames.length]; subPropMatches = new boolean[subPropNames.length]; + + // Initialise the masks list + for(int i=0; i<subPropMasks.length; i++) { + subPropMasks[i] = (1 << i); + } } /** @@ -576,7 +610,6 @@ // Figure out the values of the sub properties for(int i=0; i< subPropMatches.length; i++) { - subPropMasks[i] = (1 << i); subPropMatches[i] = false; if((dataValue & subPropMasks[i]) != 0) { subPropMatches[i] = true; --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] Mailing List: http://jakarta.apache.org/site/mail2.html#poi The Apache Jakarta POI Project: http://jakarta.apache.org/poi/