use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRElt in project poi by apache.
the class XSSFRichTextString method append.
/**
* Append new text to this text run and apply the specify font to it
*
* @param text the text to append
* @param font the font to apply to the appended text or <code>null</code> if no formatting is required
*/
public void append(String text, XSSFFont font) {
if (st.sizeOfRArray() == 0 && st.isSetT()) {
//convert <t>string</t> into a text run: <r><t>string</t></r>
CTRElt lt = st.addNewR();
lt.setT(st.getT());
preserveSpaces(lt.xgetT());
st.unsetT();
}
CTRElt lt = st.addNewR();
lt.setT(text);
preserveSpaces(lt.xgetT());
if (font != null) {
CTRPrElt pr = lt.addNewRPr();
setRunAttributes(font.getCTFont(), pr);
}
}
use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRElt in project poi by apache.
the class XSSFRichTextString method getFontOfFormattingRun.
/**
* Gets a copy of the font used in a particular formatting run.
*
* @param index the index of the formatting run
* @return A copy of the font used or null if no formatting is applied to the specified text run.
*/
public XSSFFont getFontOfFormattingRun(int index) {
if (st.sizeOfRArray() == 0 || index >= st.sizeOfRArray()) {
return null;
}
CTRElt r = st.getRArray(index);
if (r.getRPr() != null) {
XSSFFont fnt = new XSSFFont(toCTFont(r.getRPr()));
fnt.setThemesTable(getThemesTable());
return fnt;
}
return null;
}
use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRElt in project poi by apache.
the class XSSFSimpleShape method setText.
/**
* Set a single paragraph of text on the shape. Note this will replace all existing paragraphs created on the shape.
* @param str rich text string representing the paragraph text
*/
public void setText(XSSFRichTextString str) {
XSSFWorkbook wb = (XSSFWorkbook) getDrawing().getParent().getParent();
str.setStylesTableReference(wb.getStylesSource());
CTTextParagraph p = CTTextParagraph.Factory.newInstance();
if (str.numFormattingRuns() == 0) {
CTRegularTextRun r = p.addNewR();
CTTextCharacterProperties rPr = r.addNewRPr();
rPr.setLang("en-US");
rPr.setSz(1100);
r.setT(str.getString());
} else {
for (int i = 0; i < str.getCTRst().sizeOfRArray(); i++) {
CTRElt lt = str.getCTRst().getRArray(i);
CTRPrElt ltPr = lt.getRPr();
if (ltPr == null)
ltPr = lt.addNewRPr();
CTRegularTextRun r = p.addNewR();
CTTextCharacterProperties rPr = r.addNewRPr();
rPr.setLang("en-US");
applyAttributes(ltPr, rPr);
r.setT(lt.getT());
}
}
clearText();
ctShape.getTxBody().setPArray(new CTTextParagraph[] { p });
_paragraphs.add(new XSSFTextParagraph(ctShape.getTxBody().getPArray(0), ctShape));
}
use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRElt in project poi by apache.
the class XSSFRichTextString method setStylesTableReference.
protected void setStylesTableReference(StylesTable tbl) {
styles = tbl;
if (st.sizeOfRArray() > 0) {
//noinspection deprecation - for performance reasons!
for (CTRElt r : st.getRArray()) {
CTRPrElt pr = r.getRPr();
if (pr != null && pr.sizeOfRFontArray() > 0) {
String fontName = pr.getRFontArray(0).getVal();
if (fontName.startsWith("#")) {
int idx = Integer.parseInt(fontName.substring(1));
XSSFFont font = styles.getFontAt(idx);
pr.removeRFont(0);
setRunAttributes(font.getCTFont(), pr);
}
}
}
}
}
use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRElt in project poi by apache.
the class XSSFRichTextString method buildCTRst.
CTRst buildCTRst(String text, TreeMap<Integer, CTRPrElt> formats) {
if (text.length() != formats.lastKey()) {
throw new IllegalArgumentException("Text length was " + text.length() + " but the last format index was " + formats.lastKey());
}
CTRst stf = CTRst.Factory.newInstance();
int runStartIdx = 0;
for (Map.Entry<Integer, CTRPrElt> me : formats.entrySet()) {
int runEndIdx = me.getKey();
CTRElt run = stf.addNewR();
String fragment = text.substring(runStartIdx, runEndIdx);
run.setT(fragment);
preserveSpaces(run.xgetT());
CTRPrElt fmt = me.getValue();
if (fmt != null) {
run.setRPr(fmt);
}
runStartIdx = runEndIdx;
}
return stf;
}
Aggregations