poi-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject cvs commit: jakarta-poi/src/scratchpad/src/org/apache/poi/hslf/record StyleTextPropAtom.java
Date Mon, 01 Aug 2005 17:36:52 GMT
nick        2005/08/01 10:36:52

  Modified:    src/scratchpad/src/org/apache/poi/hslf/record
                        StyleTextPropAtom.java
  Log:
  Add support for setting some of the style properties
  
  Revision  Changes    Path
  1.2       +89 -10    jakarta-poi/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java
  
  Index: StyleTextPropAtom.java
  ===================================================================
  RCS file: /home/cvs/jakarta-poi/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- StyleTextPropAtom.java	31 Jul 2005 18:06:26 -0000	1.1
  +++ StyleTextPropAtom.java	1 Aug 2005 17:36:52 -0000	1.2
  @@ -25,9 +25,10 @@
   import java.util.Vector;
   
   /**
  - * A StyleTextPropAtom (type 4001). Holds character properties (font type,
  - *  font size, colour, bold, italic etc) and paragraph properties
  - *  (alignment, line spacing etc) for a block of text
  + * A StyleTextPropAtom (type 4001). Holds basic character properties 
  + *  (bold, italic, underline, possibly more?) and paragraph properties
  + *  (alignment, line spacing etc) for the block of text (TextBytesAtom
  + *  or TextCharsAtom) that this record follows
    *
    * @author Nick Burch
    */
  @@ -55,6 +56,15 @@
   		return charStyles;
   	}
   
  +	/** 
  +	 * Set the number of characters covered by these text styles.
  +	 * This must equal the number of characters in the Text record
  +	 *  that precedes this record, or things won't behave properly
  +	 */
  +	public void setParagraphStyleCharactersCoveredLength(int len) {
  +		paraStyleLen = (short)len;
  +	}
  +
   
   	/* *************** record code follows ********************** */
   
  @@ -110,6 +120,25 @@
   		System.arraycopy(source,start+8+10+cpos,reserved,0,reserved.length);
   	}
   
  +	/** 
  +	 * A new set of text style properties for some text without any
  +	 */
  +	public StyleTextPropAtom() {
  +		_header = new byte[8];
  +		reserved = new byte[0];
  +		charStyles = new CharacterStyle[0];
  +
  +		// Set our type
  +		LittleEndian.putInt(_header,2,(short)_type);
  +		// Our initial size is 10
  +		LittleEndian.putInt(_header,4,10);
  +
  +		// Blank paragraph style
  +		paraStyleLen = 0;
  +		paraStyle1 = 0;
  +		paraStyle2 = 0;
  +	}
  +
   	/**
   	 * We are of type 4001
   	 */
  @@ -159,6 +188,13 @@
   		private int style2;
   		private short style3;
   
  +		// style1 0x00010000
  +		private static final int BOLD_STYLE = 65536;
  +		// style1 0x00020000
  +		private static final int ITALIC_STYLE = 131072;
  +		// style1 0x00040000
  +		private static final int UNDERLINED_STYLE = 262144;
  +
   		/** Create a new Character Style from on-disk data */
   		protected CharacterStyle(short len, int s1, int s2, short s3) {
   			styleLen = len;
  @@ -183,30 +219,73 @@
   			}
   		}
   
  -		/** Return the number of characters covered by these properties */
  +
  +		/** 
  +		 * Return the number of characters covered by these properties. 
  +		 * If it's the last CharacterStyle of a StyleTextPropAtom, it 
  +		 *  will normally be 0, indicating it applies to all the remaining
  +		 *  text.
  +		 */
   		public int getCharactersCoveredLength() {
   			return styleLen;
   		}
   
  +		/** 
  +		 * Set the number of characters covered by these properties.
  +		 * If this is the last CharacterStyle of a StyleTextPropAtom, then
  +		 *  a value of 0 should be used
  +		 */
  +		public void setCharactersCoveredLength(int len) {
  +			styleLen = (short)len;
  +		}
  +
  +
   		/** Checks to see if the text is bold */
   		public boolean isBold() {
  -			// style1 0x00010000
  -			if ((style1 & 65536) == 65536) { return true; }
  +			if ((style1 & BOLD_STYLE) == BOLD_STYLE) { return true; }
   			return false;
   		}
   
   		/** Checks to see if the text is italic */
   		public boolean isItalic() {
  -			// style1 0x00020000
  -			if ((style1 & 131072) == 131072) { return true; }
  +			if ((style1 & ITALIC_STYLE) == ITALIC_STYLE) { return true; }
   			return false;
   		}
   
   		/** Checks to see if the text is underlined */
   		public boolean isUnderlined() {
  -			// style1 0x00040000
  -			if ((style1 & 262144) == 262144) { return true; }
  +			if ((style1 & UNDERLINED_STYLE) == UNDERLINED_STYLE) { return true; }
   			return false;
   		}
  +
  +		/** Sets the text to be bold/not bold */
  +		public void setBold(boolean bold) {
  +			if(bold == isBold()) { return; }
  +			if(bold) {
  +				style1 += BOLD_STYLE;
  +			} else {
  +				style1 -= BOLD_STYLE;
  +			}
  +		}
  +
  +		/** Sets the text to be italic/not italic */
  +		public void setItalic(boolean italic) {
  +			if(italic == isItalic()) { return; }
  +			if(italic) {
  +				style1 += ITALIC_STYLE;
  +			} else {
  +				style1 -= ITALIC_STYLE;
  +			}
  +		}
  +
  +		/** Sets the text to be underlined/not underlined */
  +		public void setUnderlined(boolean underlined) {
  +			if(underlined == isUnderlined()) { return; }
  +			if(underlined) {
  +				style1 += UNDERLINED_STYLE;
  +			} else {
  +				style1 -= UNDERLINED_STYLE;
  +			}
  +		}
   	}
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: poi-dev-unsubscribe@jakarta.apache.org
Mailing List:    http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta POI Project: http://jakarta.apache.org/poi/


Mime
View raw message