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/usermodel RichTextRun.java
Date Tue, 29 Nov 2005 21:18:59 GMT
nick        2005/11/29 13:18:59

  Modified:    src/scratchpad/src/org/apache/poi/hslf/model TextRun.java
               src/scratchpad/src/org/apache/poi/hslf/usermodel
                        RichTextRun.java
  Log:
  Get a bit further with building up RichTextRuns
  
  Revision  Changes    Path
  1.7       +17 -1     jakarta-poi/src/scratchpad/src/org/apache/poi/hslf/model/TextRun.java
  
  Index: TextRun.java
  ===================================================================
  RCS file: /home/cvs/jakarta-poi/src/scratchpad/src/org/apache/poi/hslf/model/TextRun.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- TextRun.java	13 Nov 2005 13:28:34 -0000	1.6
  +++ TextRun.java	29 Nov 2005 21:18:58 -0000	1.7
  @@ -80,20 +80,36 @@
   			_charAtom = tca;
   			_isUnicode = true;
   		}
  +		String runRawText = getText();
   		
   		// Figure out the rich text runs
   		// TODO: Handle when paragraph style and character styles don't match up
   		LinkedList pStyles = new LinkedList();
   		LinkedList cStyles = new LinkedList();
   		if(_styleAtom != null) {
  +			_styleAtom.setParentTextSize(runRawText.length());
   			pStyles = _styleAtom.getParagraphStyles();
   			cStyles = _styleAtom.getCharacterStyles();
   		}
   		if(pStyles.size() != cStyles.size()) {
   			throw new RuntimeException("Don't currently handle case of overlapping styles");
   		}
  +		
  +		int pos = 0;
   		_rtRuns = new RichTextRun[pStyles.size()];
  -		//for(int i=0; i<)
  +		for(int i=0; i<_rtRuns.length; i++) {
  +			TextPropCollection pProps = (TextPropCollection)pStyles.get(i);
  +			TextPropCollection cProps = (TextPropCollection)cStyles.get(i);
  +			int len = cProps.getCharactersCovered();
  +			_rtRuns[i] = new RichTextRun(this, pos, len, pProps, cProps);
  +			pos += len;
  +		}
  +		
  +		// Handle case of no current style, with a default
  +		if(_rtRuns.length == 0) {
  +			_rtRuns = new RichTextRun[1];
  +			_rtRuns[0] = new RichTextRun(this, 0, runRawText.length());
  +		}
   	}
   	
   	
  
  
  
  1.2       +37 -2     jakarta-poi/src/scratchpad/src/org/apache/poi/hslf/usermodel/RichTextRun.java
  
  Index: RichTextRun.java
  ===================================================================
  RCS file: /home/cvs/jakarta-poi/src/scratchpad/src/org/apache/poi/hslf/usermodel/RichTextRun.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- RichTextRun.java	7 Nov 2005 22:24:15 -0000	1.1
  +++ RichTextRun.java	29 Nov 2005 21:18:59 -0000	1.2
  @@ -20,6 +20,7 @@
   package org.apache.poi.hslf.usermodel;
   
   import org.apache.poi.hslf.model.TextRun;
  +import org.apache.poi.hslf.record.StyleTextPropAtom.TextPropCollection;
   
   /**
    * Represents a run of text, all with the same style
  @@ -40,18 +41,39 @@
   	/** How long a string (in the parent TextRun) we represent */
   	private int length;
   	
  -	/** Our paragraph and character style */
  +	/** 
  +	 * Our paragraph and character style.
  +	 * Note - we may share the Paragraph style with another RichTextRun
  +	 *  (the Character style should be ours alone) 
  +	 */
  +	private TextPropCollection paragraphStyle;
  +	private TextPropCollection characterStyle;
   	
   	/**
  -	 * Create a new wrapper around a rich text string
  +	 * Create a new wrapper around a (currently not)
  +	 *  rich text string
   	 * @param parent
   	 * @param startAt
   	 * @param len
   	 */
   	public RichTextRun(TextRun parent, int startAt, int len) {
  +		this(parent, startAt, len, null, null);
  +	}
  +	/**
  +	 * Create a new wrapper around a rich text string
  +	 * @param parent The parent TextRun
  +	 * @param startAt The start position of this run
  +	 * @param len The length of this run
  +	 * @param pStyle The paragraph style property collection
  +	 * @param cStyle The character style property collection
  +	 */
  +	public RichTextRun(TextRun parent, int startAt, int len, 
  +	TextPropCollection pStyle,  TextPropCollection cStyle) {
   		parentRun = parent;
   		startPos = startAt;
   		length = len;
  +		paragraphStyle = pStyle;
  +		characterStyle = cStyle;
   	}
   	
   	/**
  @@ -82,4 +104,17 @@
   	public void updateStartPosition(int startAt) {
   		startPos = startAt;
   	}
  +	
  +	
  +	
  +	/**
  +	 * Unit Testing Only - get the underlying paragraph style collection.
  +	 * For normal use, use the friendly setters and getters 
  +	 */
  +	public TextPropCollection _getRawParagraphStyle() { return paragraphStyle; }
  +	/**
  +	 * Unit Testing Only - get the underlying character style collection.
  +	 * For normal use, use the friendly setters and getters 
  +	 */
  +	public TextPropCollection _getRawCharacterStyle() { return characterStyle; }
   }
  
  
  

---------------------------------------------------------------------
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