use of org.apache.poi.sl.usermodel.PaintStyle in project poi by apache.
the class XSLFShape method selectPaint.
protected static PaintStyle selectPaint(CTStyleMatrixReference fillRef, final XSLFTheme theme, boolean isLineStyle, boolean hasPlaceholder) {
if (fillRef == null)
return null;
// The idx attribute refers to the index of a fill style or
// background fill style within the presentation's style matrix, defined by the fmtScheme element.
// value of 0 or 1000 indicates no background,
// values 1-999 refer to the index of a fill style within the fillStyleLst element
// values 1001 and above refer to the index of a background fill style within the bgFillStyleLst element.
int idx = (int) fillRef.getIdx();
CTStyleMatrix matrix = theme.getXmlObject().getThemeElements().getFmtScheme();
final XmlObject styleLst;
int childIdx;
if (idx >= 1 && idx <= 999) {
childIdx = idx - 1;
styleLst = (isLineStyle) ? matrix.getLnStyleLst() : matrix.getFillStyleLst();
} else if (idx >= 1001) {
childIdx = idx - 1001;
styleLst = matrix.getBgFillStyleLst();
} else {
return null;
}
XmlCursor cur = styleLst.newCursor();
XSLFFillProperties fp = null;
if (cur.toChild(childIdx)) {
fp = XSLFPropertiesDelegate.getFillDelegate(cur.getObject());
}
cur.dispose();
CTSchemeColor phClr = fillRef.getSchemeClr();
PaintStyle res = selectPaint(fp, phClr, theme.getPackagePart(), theme, hasPlaceholder);
// see http://officeopenxml.com/prSlide-color.php - "Color Placeholders within Themes"
if (res != null || hasPlaceholder) {
return res;
}
XSLFColor col = new XSLFColor(fillRef, theme, phClr);
return DrawPaint.createSolidPaint(col.getColorStyle());
}
use of org.apache.poi.sl.usermodel.PaintStyle in project poi by apache.
the class XSLFTableCell method getFillPaint.
@SuppressWarnings("resource")
@Override
public PaintStyle getFillPaint() {
XSLFSheet sheet = getSheet();
XSLFTheme theme = sheet.getTheme();
final boolean hasPlaceholder = getPlaceholder() != null;
XmlObject props = getCellProperties(false);
XSLFFillProperties fp = XSLFPropertiesDelegate.getFillDelegate(props);
if (fp != null) {
PaintStyle paint = selectPaint(fp, null, sheet.getPackagePart(), theme, hasPlaceholder);
if (paint != null) {
return paint;
}
}
CTTablePartStyle tps = getTablePartStyle(null);
if (tps == null || !tps.isSetTcStyle()) {
tps = getTablePartStyle(TablePartStyle.wholeTbl);
if (tps == null || !tps.isSetTcStyle()) {
return null;
}
}
XMLSlideShow slideShow = sheet.getSlideShow();
CTTableStyleCellStyle tcStyle = tps.getTcStyle();
if (tcStyle.isSetFill()) {
props = tcStyle.getFill();
} else if (tcStyle.isSetFillRef()) {
props = tcStyle.getFillRef();
} else {
return null;
}
fp = XSLFPropertiesDelegate.getFillDelegate(props);
if (fp != null) {
PaintStyle paint = XSLFShape.selectPaint(fp, null, slideShow.getPackagePart(), theme, hasPlaceholder);
if (paint != null) {
return paint;
}
}
return null;
}
use of org.apache.poi.sl.usermodel.PaintStyle in project poi by apache.
the class XSLFTextParagraph method copy.
void copy(XSLFTextParagraph other) {
if (other == this)
return;
CTTextParagraph thisP = getXmlObject();
CTTextParagraph otherP = other.getXmlObject();
if (thisP.isSetPPr())
thisP.unsetPPr();
if (thisP.isSetEndParaRPr())
thisP.unsetEndParaRPr();
_runs.clear();
for (int i = thisP.sizeOfBrArray(); i > 0; i--) {
thisP.removeBr(i - 1);
}
for (int i = thisP.sizeOfRArray(); i > 0; i--) {
thisP.removeR(i - 1);
}
for (int i = thisP.sizeOfFldArray(); i > 0; i--) {
thisP.removeFld(i - 1);
}
XmlCursor thisC = thisP.newCursor();
thisC.toEndToken();
XmlCursor otherC = otherP.newCursor();
otherC.copyXmlContents(thisC);
otherC.dispose();
thisC.dispose();
List<XSLFTextRun> otherRs = other.getTextRuns();
int i = 0;
for (CTRegularTextRun rtr : thisP.getRArray()) {
XSLFTextRun run = newTextRun(rtr);
run.copy(otherRs.get(i++));
_runs.add(run);
}
// set properties again, in case we are based on a different
// template
TextAlign srcAlign = other.getTextAlign();
if (srcAlign != getTextAlign()) {
setTextAlign(srcAlign);
}
boolean isBullet = other.isBullet();
if (isBullet != isBullet()) {
setBullet(isBullet);
if (isBullet) {
String buFont = other.getBulletFont();
if (buFont != null && !buFont.equals(getBulletFont())) {
setBulletFont(buFont);
}
String buChar = other.getBulletCharacter();
if (buChar != null && !buChar.equals(getBulletCharacter())) {
setBulletCharacter(buChar);
}
PaintStyle buColor = other.getBulletFontColor();
if (buColor != null && !buColor.equals(getBulletFontColor())) {
setBulletFontColor(buColor);
}
Double buSize = other.getBulletFontSize();
if (!doubleEquals(buSize, getBulletFontSize())) {
setBulletFontSize(buSize);
}
}
}
Double leftMargin = other.getLeftMargin();
if (!doubleEquals(leftMargin, getLeftMargin())) {
setLeftMargin(leftMargin);
}
Double indent = other.getIndent();
if (!doubleEquals(indent, getIndent())) {
setIndent(indent);
}
Double spaceAfter = other.getSpaceAfter();
if (!doubleEquals(spaceAfter, getSpaceAfter())) {
setSpaceAfter(spaceAfter);
}
Double spaceBefore = other.getSpaceBefore();
if (!doubleEquals(spaceBefore, getSpaceBefore())) {
setSpaceBefore(spaceBefore);
}
Double lineSpacing = other.getLineSpacing();
if (!doubleEquals(lineSpacing, getLineSpacing())) {
setLineSpacing(lineSpacing);
}
}
use of org.apache.poi.sl.usermodel.PaintStyle in project poi by apache.
the class XSLFTextRun method copy.
void copy(XSLFTextRun r) {
String srcFontFamily = r.getFontFamily();
if (srcFontFamily != null && !srcFontFamily.equals(getFontFamily())) {
setFontFamily(srcFontFamily);
}
PaintStyle srcFontColor = r.getFontColor();
if (srcFontColor != null && !srcFontColor.equals(getFontColor())) {
setFontColor(srcFontColor);
}
double srcFontSize = r.getFontSize();
if (srcFontSize != getFontSize()) {
setFontSize(srcFontSize);
}
boolean bold = r.isBold();
if (bold != isBold())
setBold(bold);
boolean italic = r.isItalic();
if (italic != isItalic())
setItalic(italic);
boolean underline = r.isUnderlined();
if (underline != isUnderlined())
setUnderlined(underline);
boolean strike = r.isStrikethrough();
if (strike != isStrikethrough())
setStrikethrough(strike);
}
use of org.apache.poi.sl.usermodel.PaintStyle in project poi by apache.
the class TestXSLFBugs method bug55714.
@Test
public void bug55714() throws IOException {
XMLSlideShow srcPptx = XSLFTestDataSamples.openSampleDocument("pptx2svg.pptx");
XMLSlideShow newPptx = new XMLSlideShow();
XSLFSlide srcSlide = srcPptx.getSlides().get(0);
XSLFSlide newSlide = newPptx.createSlide();
XSLFSlideLayout srcSlideLayout = srcSlide.getSlideLayout();
XSLFSlideLayout newSlideLayout = newSlide.getSlideLayout();
newSlideLayout.importContent(srcSlideLayout);
XSLFSlideMaster srcSlideMaster = srcSlide.getSlideMaster();
XSLFSlideMaster newSlideMaster = newSlide.getSlideMaster();
newSlideMaster.importContent(srcSlideMaster);
newSlide.importContent(srcSlide);
XMLSlideShow rwPptx = XSLFTestDataSamples.writeOutAndReadBack(newPptx);
PaintStyle ps = rwPptx.getSlides().get(0).getBackground().getFillStyle().getPaint();
assertTrue(ps instanceof TexturePaint);
rwPptx.close();
newPptx.close();
srcPptx.close();
}
Aggregations