use of org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties in project poi by apache.
the class XSLFTextRun method fetchCharacterProperty.
private boolean fetchCharacterProperty(CharacterPropertyFetcher<?> fetcher) {
XSLFTextShape shape = _p.getParentShape();
XSLFSheet sheet = shape.getSheet();
CTTextCharacterProperties rPr = getRPr(false);
if (rPr != null && fetcher.fetch(rPr)) {
return true;
}
if (shape.fetchShapeProperty(fetcher)) {
return true;
}
CTPlaceholder ph = shape.getCTPlaceholder();
if (ph == null) {
// if it is a plain text box then take defaults from presentation.xml
@SuppressWarnings("resource") XMLSlideShow ppt = sheet.getSlideShow();
// TODO: determine master shape
CTTextParagraphProperties themeProps = ppt.getDefaultParagraphStyle(_p.getIndentLevel());
if (themeProps != null && fetcher.fetch(themeProps)) {
return true;
}
}
// TODO: determine master shape
CTTextParagraphProperties defaultProps = _p.getDefaultMasterStyle();
if (defaultProps != null && fetcher.fetch(defaultProps)) {
return true;
}
return false;
}
use of org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties in project poi by apache.
the class XSLFTextShape method appendText.
@Override
public XSLFTextRun appendText(String text, boolean newParagraph) {
if (text == null)
return null;
// copy properties from last paragraph / textrun or paragraph end marker
CTTextParagraphProperties otherPPr = null;
CTTextCharacterProperties otherRPr = null;
boolean firstPara;
XSLFTextParagraph para;
if (_paragraphs.isEmpty()) {
firstPara = false;
para = null;
} else {
firstPara = !newParagraph;
para = _paragraphs.get(_paragraphs.size() - 1);
CTTextParagraph ctp = para.getXmlObject();
otherPPr = ctp.getPPr();
List<XSLFTextRun> runs = para.getTextRuns();
if (!runs.isEmpty()) {
XSLFTextRun r0 = runs.get(runs.size() - 1);
otherRPr = r0.getRPr(false);
if (otherRPr == null) {
otherRPr = ctp.getEndParaRPr();
}
}
// don't copy endParaRPr to the run in case there aren't any other runs
// this is the case when setText() was called initially
// otherwise the master style will be overridden/ignored
}
XSLFTextRun run = null;
for (String lineTxt : text.split("\\r\\n?|\\n")) {
if (!firstPara) {
if (para != null) {
CTTextParagraph ctp = para.getXmlObject();
CTTextCharacterProperties unexpectedRPr = ctp.getEndParaRPr();
if (unexpectedRPr != null && unexpectedRPr != otherRPr) {
ctp.unsetEndParaRPr();
}
}
para = addNewTextParagraph();
if (otherPPr != null) {
para.getXmlObject().setPPr(otherPPr);
}
}
boolean firstRun = true;
for (String runText : lineTxt.split("[]")) {
if (!firstRun) {
para.addLineBreak();
}
run = para.addNewTextRun();
run.setText(runText);
if (otherRPr != null) {
run.getRPr(true).set(otherRPr);
}
firstRun = false;
}
firstPara = false;
}
assert (run != null);
return run;
}
use of org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties in project poi by apache.
the class XSSFTextRun method getFontSize.
/**
* @return font size in points or -1 if font size is not set.
*/
public double getFontSize() {
double scale = 1;
// default font size
double size = XSSFFont.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;
}
use of org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties in project poi by apache.
the class XSSFTextRun method setFontFamily.
public void setFontFamily(String typeface, byte charset, byte pictAndFamily, boolean isSymbol) {
CTTextCharacterProperties rPr = getRPr();
if (typeface == null) {
if (rPr.isSetLatin())
rPr.unsetLatin();
if (rPr.isSetCs())
rPr.unsetCs();
if (rPr.isSetSym())
rPr.unsetSym();
} else {
if (isSymbol) {
CTTextFont font = rPr.isSetSym() ? rPr.getSym() : rPr.addNewSym();
font.setTypeface(typeface);
} else {
CTTextFont latin = rPr.isSetLatin() ? rPr.getLatin() : rPr.addNewLatin();
latin.setTypeface(typeface);
if (charset != -1)
latin.setCharset(charset);
if (pictAndFamily != -1)
latin.setPitchFamily(pictAndFamily);
}
}
}
use of org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties in project poi by apache.
the class XSSFTextRun method getFontFamily.
/**
* @return font family or null if not set
*/
public String getFontFamily() {
CTTextCharacterProperties rPr = getRPr();
CTTextFont font = rPr.getLatin();
if (font != null) {
return font.getTypeface();
}
return XSSFFont.DEFAULT_FONT_NAME;
}
Aggregations