/** * Add a new run of text * * @return a new run of text */ public XSSFTextRun addNewTextRun(){ CTRegularTextRun r = _p.addNewR(); CTTextCharacterProperties rPr = r.addNewRPr(); rPr.setLang("en-US"); XSSFTextRun run = new XSSFTextRun(r, this); _runs.add(run); return run; }
/** * @return font size in points or -1 if font size is not set. */ public double getFontSize(){ double scale = 1; double size = XSSFFont.DEFAULT_FONT_SIZE; // default font size CTTextNormalAutofit afit = getParentParagraph().getParentShape().getTxBody().getBodyPr().getNormAutofit(); if(afit != null) scale = (double)afit.getFontScale() / 100000; CTTextCharacterProperties rPr = getRPr(); if(rPr.isSetSz()){ size = rPr.getSz()*0.01; } return size * scale; }
@Override public String toString(){ return "[" + getClass() + "]" + getText(); } }
/** * @param underline whether this run of text is formatted as underlined text */ public void setUnderline(boolean underline) { getRPr().setU(underline ? STTextUnderlineType.SNG : STTextUnderlineType.NONE); }
/** * Add a new paragraph run to this shape, set to the provided string * * @return created paragraph run */ public XSSFTextParagraph addNewTextParagraph(String text) { XSSFTextParagraph paragraph = addNewTextParagraph(); paragraph.addNewTextRun().setText(text); return paragraph; }
/** * Set whether the text in this run is formatted as subscript. * Default base line offset is -25%. * * @see #setBaselineOffset(double) */ public void setSubscript(boolean flag){ setBaselineOffset(flag ? -25.0 : 0.); }
/** * Specifies the typeface, or name of the font that is to be used for this text run. * * @param typeface the font to apply to this text run. * The value of <code>null</code> unsets the Typeface attribute from the underlying xml. */ public void setFont(String typeface){ setFontFamily(typeface, (byte)-1, (byte)-1, false); }
/** * Set the baseline for both the superscript and subscript fonts. * <p> * The size is specified using a percentage. * Positive values indicate superscript, negative values indicate subscript. * </p> * * @param baselineOffset */ public void setBaselineOffset(double baselineOffset){ getRPr().setBaseline((int) baselineOffset * 1000); }
/** * Set a single paragraph of text on the shape. Note this will replace all * existing paragraphs created on the shape. * * @param text * string representing the paragraph text */ public void setText(String text) { clearText(); addNewTextParagraph().addNewTextRun().setText(text); }
/** * Set whether the text in this run is formatted as superscript. * Default base line offset is 30% * * @see #setBaselineOffset(double) */ public void setSuperscript(boolean flag){ setBaselineOffset(flag ? 30. : 0.); }
/** * Specifies the typeface, or name of the font that is to be used for this text run. * * @param typeface the font to apply to this text run. * The value of <code>null</code> unsets the Typeface attribute from the underlying xml. */ public void setFont(String typeface){ setFontFamily(typeface, (byte)-1, (byte)-1, false); }
/** * Specifies whether a run of text will be formatted as strikethrough text. * * @param strike whether a run of text will be formatted as strikethrough text. */ public void setStrikethrough(boolean strike) { getRPr().setStrike(strike ? STTextStrikeType.SNG_STRIKE : STTextStrikeType.NO_STRIKE); }
/** * @return font size in points or -1 if font size is not set. */ public double getFontSize(){ double scale = 1; double size = XSSFFont.DEFAULT_FONT_SIZE; // default font size CTTextNormalAutofit afit = getParentParagraph().getParentShape().getTxBody().getBodyPr().getNormAutofit(); if(afit != null) scale = (double)afit.getFontScale() / 100000; CTTextCharacterProperties rPr = getRPr(); if(rPr.isSetSz()){ size = rPr.getSz()*0.01; } return size * scale; }
/** * Add a new paragraph run to this shape, set to the provided string * * @return created paragraph run */ public XSSFTextParagraph addNewTextParagraph(String text) { XSSFTextParagraph paragraph = addNewTextParagraph(); paragraph.addNewTextRun().setText(text); return paragraph; }
public String getText(){ StringBuilder out = new StringBuilder(); for (XSSFTextRun r : _runs) { out.append(r.getText()); } return out.toString(); }
/** * Set whether the text in this run is formatted as superscript. * Default base line offset is 30% * * @see #setBaselineOffset(double) */ public void setSuperscript(boolean flag){ setBaselineOffset(flag ? 30. : 0.); }
XSSFTextParagraph(CTTextParagraph p, CTShape ctShape){ _p = p; _shape = ctShape; _runs = new ArrayList<>(); for(XmlObject ch : _p.selectPath("*")){ if(ch instanceof CTRegularTextRun){ CTRegularTextRun r = (CTRegularTextRun)ch; _runs.add(new XSSFTextRun(r, this)); } else if (ch instanceof CTTextLineBreak){ CTTextLineBreak br = (CTTextLineBreak)ch; CTRegularTextRun r = CTRegularTextRun.Factory.newInstance(); r.setRPr(br.getRPr()); r.setT("\n"); _runs.add(new XSSFTextRun(r, this)); } else if (ch instanceof CTTextField){ CTTextField f = (CTTextField)ch; CTRegularTextRun r = CTRegularTextRun.Factory.newInstance(); r.setRPr(f.getRPr()); r.setT(f.getT()); _runs.add(new XSSFTextRun(r, this)); } } }
/** * Specifies whether this run of text will be formatted as bold text * * @param bold whether this run of text will be formatted as bold text */ public void setBold(boolean bold){ getRPr().setB(bold); }
/** * Set a single paragraph of text on the shape. Note this will replace all * existing paragraphs created on the shape. * * @param text * string representing the paragraph text */ public void setText(String text) { clearText(); addNewTextParagraph().addNewTextRun().setText(text); }
@Override public String toString(){ return "[" + getClass() + "]" + getText(); } }