Get a bit further with building up RichTextRuns

git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@353799 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2005-11-29 21:18:59 +00:00
parent 4bb61c4ce5
commit e8bda0b91a
2 changed files with 54 additions and 3 deletions

View File

@ -80,20 +80,36 @@ public class TextRun
_charAtom = tca; _charAtom = tca;
_isUnicode = true; _isUnicode = true;
} }
String runRawText = getText();
// Figure out the rich text runs // Figure out the rich text runs
// TODO: Handle when paragraph style and character styles don't match up // TODO: Handle when paragraph style and character styles don't match up
LinkedList pStyles = new LinkedList(); LinkedList pStyles = new LinkedList();
LinkedList cStyles = new LinkedList(); LinkedList cStyles = new LinkedList();
if(_styleAtom != null) { if(_styleAtom != null) {
_styleAtom.setParentTextSize(runRawText.length());
pStyles = _styleAtom.getParagraphStyles(); pStyles = _styleAtom.getParagraphStyles();
cStyles = _styleAtom.getCharacterStyles(); cStyles = _styleAtom.getCharacterStyles();
} }
if(pStyles.size() != cStyles.size()) { if(pStyles.size() != cStyles.size()) {
throw new RuntimeException("Don't currently handle case of overlapping styles"); throw new RuntimeException("Don't currently handle case of overlapping styles");
} }
int pos = 0;
_rtRuns = new RichTextRun[pStyles.size()]; _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());
}
} }

View File

@ -20,6 +20,7 @@
package org.apache.poi.hslf.usermodel; package org.apache.poi.hslf.usermodel;
import org.apache.poi.hslf.model.TextRun; 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 * Represents a run of text, all with the same style
@ -40,18 +41,39 @@ public class RichTextRun
/** How long a string (in the parent TextRun) we represent */ /** How long a string (in the parent TextRun) we represent */
private int length; 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 parent
* @param startAt * @param startAt
* @param len * @param len
*/ */
public RichTextRun(TextRun parent, int startAt, int 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; parentRun = parent;
startPos = startAt; startPos = startAt;
length = len; length = len;
paragraphStyle = pStyle;
characterStyle = cStyle;
} }
/** /**
@ -82,4 +104,17 @@ public class RichTextRun
public void updateStartPosition(int startAt) { public void updateStartPosition(int startAt) {
startPos = 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; }
} }