FileDocCategorySizeDatePackage
TextPropCollection.javaAPI DocApache Poi 3.0.16582Tue Jun 26 21:26:02 BST 2007org.apache.poi.hslf.model.textproperties

TextPropCollection

public class TextPropCollection extends Object
For a given run of characters, holds the properties (which could be paragraph properties or character properties). Used to hold the number of characters affected, the list of active properties, and the random reserved field if required.

Fields Summary
private int
charactersCovered
private short
reservedField
private LinkedList
textPropList
Constructors Summary
public TextPropCollection(int charactersCovered, short reservedField)
Create a new collection of text properties (be they paragraph or character) which will be groked via a subsequent call to buildTextPropList().

		this.charactersCovered = charactersCovered;
		this.reservedField = reservedField;
		textPropList = new LinkedList();
	
public TextPropCollection(int textSize)
Create a new collection of text properties (be they paragraph or character) for a run of text without any

		charactersCovered = textSize;
		reservedField = -1;
		textPropList = new LinkedList();
	
Methods Summary
public org.apache.poi.hslf.model.textproperties.TextPropaddWithName(java.lang.String name)
Add the TextProp with this name to the list

		// Find the base TextProp to base on
		TextProp base = null;
		for(int i=0; i < StyleTextPropAtom.characterTextPropTypes.length; i++) {
			if(StyleTextPropAtom.characterTextPropTypes[i].getName().equals(name)) {
				base = StyleTextPropAtom.characterTextPropTypes[i];
			}
		}
		for(int i=0; i < StyleTextPropAtom.paragraphTextPropTypes.length; i++) {
			if(StyleTextPropAtom.paragraphTextPropTypes[i].getName().equals(name)) {
				base = StyleTextPropAtom.paragraphTextPropTypes[i];
			}
		}
		if(base == null) {
			throw new IllegalArgumentException("No TextProp with name " + name + " is defined to add from");
		}
		
		// Add a copy of this property, in the right place to the list
		TextProp textProp = (TextProp)base.clone();
		int pos = 0;
		for(int i=0; i<textPropList.size(); i++) {
			TextProp curProp = (TextProp)textPropList.get(i);
			if(textProp.getMask() > curProp.getMask()) {
				pos++;
			}
		}
		textPropList.add(pos, textProp);
		return textProp;
	
public intbuildTextPropList(int containsField, org.apache.poi.hslf.model.textproperties.TextProp[] potentialProperties, byte[] data, int dataOffset)
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

		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<potentialProperties.length; i++) {
			// Check there's still data left to read
			if(dataOffset+bytesPassed >= 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;
	
public org.apache.poi.hslf.model.textproperties.TextPropfindByName(java.lang.String textPropName)
Fetch the TextProp with this name, or null if it isn't present

		for(int i=0; i<textPropList.size(); i++) {
			TextProp prop = (TextProp)textPropList.get(i);
			if(prop.getName().equals(textPropName)) {
				return prop;
			}
		}
		return null;
	
public intgetCharactersCovered()
Fetch the number of characters this styling applies to

 return charactersCovered; 
public shortgetReservedField()

        return reservedField;
    
public java.util.LinkedListgetTextPropList()
Fetch the TextProps that define this styling

 return textPropList; 
public voidsetReservedField(short val)

        reservedField = val;
    
public voidupdateTextSize(int textSize)
Update the size of the text that this set of properties applies to

		charactersCovered = textSize;
	
public voidwriteOut(java.io.OutputStream o)
Writes out to disk the header, and then all the properties

		// 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);
		}

		// Then the mask field
		int mask = 0;
		for(int i=0; i<textPropList.size(); i++) {
			TextProp textProp = (TextProp)textPropList.get(i);
            //sometimes header indicates that the bitmask is present but its value is 0
            if (textProp instanceof BitMaskTextProp)
                mask |= (textProp.getWriteMask() == 0 ? 1 : textProp.getWriteMask());
            else
                mask |= textProp.getWriteMask();
		}
		StyleTextPropAtom.writeLittleEndian(mask,o);

		// Then the contents of all the properties
		for(int i=0; i<textPropList.size(); i++) {
			TextProp textProp = (TextProp)textPropList.get(i);
			int val = textProp.getValue();
			if(textProp.getSize() == 2) {
				StyleTextPropAtom.writeLittleEndian((short)val,o);
			} else {
				StyleTextPropAtom.writeLittleEndian(val,o);
			}
		}