From 5c518687f598be7696de7c424f1e5fbb69617a1e Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Mon, 15 Jan 2007 17:00:41 +0000 Subject: [PATCH] Refactor the TextPropCollection and TextProp classes into their own model package. Some of the logic in StyleTextPropAtom should probably be refactored out too, but that's still to do git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@496405 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/hslf/dev/TextStyleListing.java | 3 + .../apache/poi/hslf/model/SlideMaster.java | 2 + .../org/apache/poi/hslf/model/TextRun.java | 2 +- .../textproperties/AlignmentTextProp.java | 34 ++ .../model/textproperties/BitMaskTextProp.java | 103 +++++ .../textproperties/CharFlagsTextProp.java | 53 +++ .../hslf/model/textproperties/TextProp.java | 89 +++++ .../textproperties/TextPropCollection.java | 190 +++++++++ .../poi/hslf/record/StyleTextPropAtom.java | 377 +----------------- .../poi/hslf/record/TxMasterStyleAtom.java | 16 +- .../poi/hslf/usermodel/RichTextRun.java | 6 +- .../poi/hslf/model/TestSlideMaster.java | 1 + .../apache/poi/hslf/model/TestTextRun.java | 2 +- .../hslf/record/TestStyleTextPropAtom.java | 3 + .../hslf/record/TestTxMasterStyleAtom.java | 2 + 15 files changed, 503 insertions(+), 380 deletions(-) create mode 100644 src/scratchpad/src/org/apache/poi/hslf/model/textproperties/AlignmentTextProp.java create mode 100644 src/scratchpad/src/org/apache/poi/hslf/model/textproperties/BitMaskTextProp.java create mode 100644 src/scratchpad/src/org/apache/poi/hslf/model/textproperties/CharFlagsTextProp.java create mode 100644 src/scratchpad/src/org/apache/poi/hslf/model/textproperties/TextProp.java create mode 100644 src/scratchpad/src/org/apache/poi/hslf/model/textproperties/TextPropCollection.java diff --git a/src/scratchpad/src/org/apache/poi/hslf/dev/TextStyleListing.java b/src/scratchpad/src/org/apache/poi/hslf/dev/TextStyleListing.java index 3b1edbcfb5..fa19398d27 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/dev/TextStyleListing.java +++ b/src/scratchpad/src/org/apache/poi/hslf/dev/TextStyleListing.java @@ -21,6 +21,9 @@ package org.apache.poi.hslf.dev; import org.apache.poi.hslf.*; +import org.apache.poi.hslf.model.textproperties.BitMaskTextProp; +import org.apache.poi.hslf.model.textproperties.TextProp; +import org.apache.poi.hslf.model.textproperties.TextPropCollection; import org.apache.poi.hslf.record.*; import org.apache.poi.hslf.record.StyleTextPropAtom.*; diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/SlideMaster.java b/src/scratchpad/src/org/apache/poi/hslf/model/SlideMaster.java index 2c444d514e..5489e4bfde 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/SlideMaster.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/SlideMaster.java @@ -17,6 +17,8 @@ package org.apache.poi.hslf.model; +import org.apache.poi.hslf.model.textproperties.TextProp; +import org.apache.poi.hslf.model.textproperties.TextPropCollection; import org.apache.poi.hslf.record.*; import org.apache.poi.hslf.usermodel.SlideShow; import org.apache.poi.hslf.record.StyleTextPropAtom.*; diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/TextRun.java b/src/scratchpad/src/org/apache/poi/hslf/model/TextRun.java index c12e791a2e..8e6ae61627 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/TextRun.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/TextRun.java @@ -23,8 +23,8 @@ package org.apache.poi.hslf.model; import java.util.LinkedList; import java.util.Vector; +import org.apache.poi.hslf.model.textproperties.TextPropCollection; import org.apache.poi.hslf.record.*; -import org.apache.poi.hslf.record.StyleTextPropAtom.TextPropCollection; import org.apache.poi.hslf.usermodel.RichTextRun; import org.apache.poi.hslf.usermodel.SlideShow; import org.apache.poi.util.StringUtil; diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/textproperties/AlignmentTextProp.java b/src/scratchpad/src/org/apache/poi/hslf/model/textproperties/AlignmentTextProp.java new file mode 100644 index 0000000000..c4c2729bf4 --- /dev/null +++ b/src/scratchpad/src/org/apache/poi/hslf/model/textproperties/AlignmentTextProp.java @@ -0,0 +1,34 @@ +/* ==================================================================== + 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.hslf.model.textproperties; + +/** + * Definition for the alignment text property. + */ +public class AlignmentTextProp extends TextProp { + public static final int LEFT = 0; + public static final int CENTER = 1; + public static final int RIGHT = 2; + public static final int JUSTIFY = 3; + public static final int THAIDISTRIBUTED = 5; + public static final int JUSTIFYLOW = 6; + + public AlignmentTextProp() { + super(2, 0x800, "alignment"); + } +} \ No newline at end of file diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/textproperties/BitMaskTextProp.java b/src/scratchpad/src/org/apache/poi/hslf/model/textproperties/BitMaskTextProp.java new file mode 100644 index 0000000000..cf25eb6cd1 --- /dev/null +++ b/src/scratchpad/src/org/apache/poi/hslf/model/textproperties/BitMaskTextProp.java @@ -0,0 +1,103 @@ +/* ==================================================================== + 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.hslf.model.textproperties; + +/** + * Definition of a special kind of property of some text, or its + * paragraph. For these properties, a flag in the "contains" header + * field tells you the data property family will exist. The value + * of the property is itself a mask, encoding several different + * (but related) properties + */ +public class BitMaskTextProp extends TextProp implements Cloneable { + private String[] subPropNames; + private int[] subPropMasks; + private boolean[] subPropMatches; + + /** Fetch the list of the names of the sub properties */ + public String[] getSubPropNames() { return subPropNames; } + /** Fetch the list of if the sub properties match or not */ + public boolean[] getSubPropMatches() { return subPropMatches; } + + public BitMaskTextProp(int sizeOfDataBlock, int maskInHeader, String overallName, String[] subPropNames) { + super(sizeOfDataBlock,maskInHeader,"bitmask"); + this.subPropNames = subPropNames; + this.propName = overallName; + subPropMasks = new int[subPropNames.length]; + subPropMatches = new boolean[subPropNames.length]; + + // Initialise the masks list + for(int i=0; i curProp.getMask()) { + pos++; + } + } + textPropList.add(pos, textProp); + return textProp; + } + + /** + * 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 + */ + public int buildTextPropList(int containsField, TextProp[] potentialProperties, byte[] data, int dataOffset) { + int bytesPassed = 0; + + // For each possible entry, see if we match the mask + // If we do, decode that, save it, and shuffle on + for(int i=0; i= data.length) { + // Out of data, can't be any more properties to go + return bytesPassed; + } + + // Check if this property is found in the mask + if((containsField & potentialProperties[i].getMask()) != 0) { + // Bingo, data contains this property + TextProp prop = (TextProp)potentialProperties[i].clone(); + int val = 0; + if(prop.getSize() == 2) { + val = LittleEndian.getShort(data,dataOffset+bytesPassed); + } else { + val = LittleEndian.getInt(data,dataOffset+bytesPassed); + } + prop.setValue(val); + bytesPassed += prop.getSize(); + textPropList.add(prop); + } + } + + // Return how many bytes were used + return bytesPassed; + } + + /** + * 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(); + } + + /** + * Create a new collection of text properties (be they paragraph + * or character) for a run of text without any + */ + public TextPropCollection(int textSize) { + charactersCovered = textSize; + reservedField = -1; + textPropList = new LinkedList(); + } + + /** + * Update the size of the text that this set of properties + * applies to + */ + public void updateTextSize(int textSize) { + charactersCovered = textSize; + } + + /** + * Writes out to disk the header, and then all the properties + */ + public void writeOut(OutputStream o) throws IOException { + // First goes the number of characters we affect + StyleTextPropAtom.writeLittleEndian(charactersCovered,o); + + // Then we have the reserved field if required + if(reservedField > -1) { + StyleTextPropAtom.writeLittleEndian(reservedField,o); + } + + // The the mask field + int mask = 0; + for(int i=0; i curProp.getMask()) { - pos++; - } - } - textPropList.add(pos, textProp); - return textProp; - } - - /** - * 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 - */ - public int buildTextPropList(int containsField, TextProp[] potentialProperties, byte[] data, int dataOffset) { - int bytesPassed = 0; - - // For each possible entry, see if we match the mask - // If we do, decode that, save it, and shuffle on - for(int i=0; i= data.length) { - // Out of data, can't be any more properties to go - return bytesPassed; - } - - // Check if this property is found in the mask - if((containsField & potentialProperties[i].getMask()) != 0) { - // Bingo, data contains this property - TextProp prop = (TextProp)potentialProperties[i].clone(); - int val = 0; - if(prop.getSize() == 2) { - val = LittleEndian.getShort(data,dataOffset+bytesPassed); - } else { - val = LittleEndian.getInt(data,dataOffset+bytesPassed); - } - prop.setValue(val); - bytesPassed += prop.getSize(); - textPropList.add(prop); - } - } - - // Return how many bytes were used - 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) { - charactersCovered = textSize; - reservedField = -1; - textPropList = new LinkedList(); - } - - /** - * Update the size of the text that this set of properties - * applies to - */ - public void updateTextSize(int textSize) { - charactersCovered = textSize; - } - - /** - * Writes out to disk the header, and then all the properties - */ - protected void writeOut(OutputStream o) throws IOException { - // First goes the number of characters we affect - writeLittleEndian(charactersCovered,o); - - // Then we have the reserved field if required - if(reservedField > -1) { - writeLittleEndian(reservedField,o); - } - - // The the mask field - int mask = 0; - for(int i=0; iStringBuffer * * @return the string representation of the record data diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/TxMasterStyleAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/TxMasterStyleAtom.java index 95605ec0a6..12c8c1f6e2 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/TxMasterStyleAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/TxMasterStyleAtom.java @@ -22,7 +22,11 @@ import org.apache.poi.util.LittleEndian; import java.io.OutputStream; import java.io.IOException; -import org.apache.poi.hslf.record.StyleTextPropAtom.*; + +import org.apache.poi.hslf.model.textproperties.BitMaskTextProp; +import org.apache.poi.hslf.model.textproperties.CharFlagsTextProp; +import org.apache.poi.hslf.model.textproperties.TextProp; +import org.apache.poi.hslf.model.textproperties.TextPropCollection; /** * TxMasterStyleAtom atom (4003). @@ -163,7 +167,10 @@ public class TxMasterStyleAtom extends RecordAtom { } /** - * Paragraph properties for the specified text type and indent level + * Paragraph properties for the specified text type and + * indent level + * Depending on the level and type, it may be our special + * ones, or the standard StyleTextPropAtom ones */ protected TextProp[] getParagraphProps(int type, int level){ if (level != 0 || type >= MAX_INDENT){ @@ -194,7 +201,10 @@ public class TxMasterStyleAtom extends RecordAtom { } /** - * Character properties for the specified text type and indent level + * Character properties for the specified text type and + * indent level. + * Depending on the level and type, it may be our special + * ones, or the standard StyleTextPropAtom ones */ protected TextProp[] getCharacterProps(int type, int level){ if (level != 0 || type >= MAX_INDENT){ diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/RichTextRun.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/RichTextRun.java index 6d2227be49..4954b7e7b2 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/RichTextRun.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/RichTextRun.java @@ -23,9 +23,9 @@ package org.apache.poi.hslf.usermodel; import org.apache.poi.hslf.model.TextRun; import org.apache.poi.hslf.model.Sheet; import org.apache.poi.hslf.model.SlideMaster; -import org.apache.poi.hslf.record.StyleTextPropAtom.CharFlagsTextProp; -import org.apache.poi.hslf.record.StyleTextPropAtom.TextProp; -import org.apache.poi.hslf.record.StyleTextPropAtom.TextPropCollection; +import org.apache.poi.hslf.model.textproperties.CharFlagsTextProp; +import org.apache.poi.hslf.model.textproperties.TextProp; +import org.apache.poi.hslf.model.textproperties.TextPropCollection; import org.apache.poi.hslf.record.ColorSchemeAtom; import java.awt.*; diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSlideMaster.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSlideMaster.java index 77cf9bd551..3a5d61ea57 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSlideMaster.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSlideMaster.java @@ -21,6 +21,7 @@ import junit.framework.TestCase; import org.apache.poi.hslf.usermodel.SlideShow; import org.apache.poi.hslf.usermodel.RichTextRun; import org.apache.poi.hslf.HSLFSlideShow; +import org.apache.poi.hslf.model.textproperties.CharFlagsTextProp; import org.apache.poi.hslf.record.*; import org.apache.poi.hslf.record.StyleTextPropAtom.*; diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTextRun.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTextRun.java index 7b8fe525a5..7b75c3676c 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTextRun.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTextRun.java @@ -24,10 +24,10 @@ package org.apache.poi.hslf.model; import junit.framework.TestCase; import org.apache.poi.hslf.HSLFSlideShow; +import org.apache.poi.hslf.model.textproperties.TextPropCollection; import org.apache.poi.hslf.record.TextBytesAtom; import org.apache.poi.hslf.record.TextCharsAtom; import org.apache.poi.hslf.record.TextHeaderAtom; -import org.apache.poi.hslf.record.StyleTextPropAtom.TextPropCollection; import org.apache.poi.hslf.usermodel.RichTextRun; import org.apache.poi.hslf.usermodel.SlideShow; diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestStyleTextPropAtom.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestStyleTextPropAtom.java index 8ce9c833cd..ce804ae9ea 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestStyleTextPropAtom.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestStyleTextPropAtom.java @@ -21,6 +21,9 @@ package org.apache.poi.hslf.record; import org.apache.poi.hslf.HSLFSlideShow; +import org.apache.poi.hslf.model.textproperties.CharFlagsTextProp; +import org.apache.poi.hslf.model.textproperties.TextProp; +import org.apache.poi.hslf.model.textproperties.TextPropCollection; import org.apache.poi.hslf.record.StyleTextPropAtom.*; import org.apache.poi.hslf.usermodel.SlideShow; diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestTxMasterStyleAtom.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestTxMasterStyleAtom.java index 2f6a03c195..82c3008aff 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestTxMasterStyleAtom.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestTxMasterStyleAtom.java @@ -19,6 +19,8 @@ package org.apache.poi.hslf.record; import junit.framework.TestCase; import org.apache.poi.hslf.usermodel.SlideShow; +import org.apache.poi.hslf.model.textproperties.TextProp; +import org.apache.poi.hslf.model.textproperties.TextPropCollection; import org.apache.poi.hslf.record.StyleTextPropAtom.*; import java.util.ArrayList; -- 2.39.5