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:
parent
f3b0f86095
commit
d875a88d28
@ -80,20 +80,36 @@ public class TextRun
|
||||
_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());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -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 @@ public class RichTextRun
|
||||
/** 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 class RichTextRun
|
||||
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; }
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user