use of org.apache.poi.xslf.model.PropertyFetcher in project poi by apache.
the class XSLFSimpleShape method getLineCap.
/**
*
* @return the line end cap style
*/
public LineCap getLineCap() {
PropertyFetcher<LineCap> fetcher = new PropertyFetcher<LineCap>() {
@Override
public boolean fetch(XSLFShape shape) {
CTLineProperties ln = getLn(shape, false);
if (ln != null && ln.isSetCap()) {
setValue(LineCap.fromOoxmlId(ln.getCap().intValue()));
return true;
}
return false;
}
};
fetchShapeProperty(fetcher);
LineCap cap = fetcher.getValue();
if (cap == null) {
CTLineProperties defaultLn = getDefaultLineProperties();
if (defaultLn != null && defaultLn.isSetCap()) {
cap = LineCap.fromOoxmlId(defaultLn.getCap().intValue());
}
}
return cap;
}
use of org.apache.poi.xslf.model.PropertyFetcher in project poi by apache.
the class XSLFSimpleShape method getLineDash.
/**
* @return a preset line dashing scheme to stroke the shape outline
*/
public LineDash getLineDash() {
PropertyFetcher<LineDash> fetcher = new PropertyFetcher<LineDash>() {
@Override
public boolean fetch(XSLFShape shape) {
CTLineProperties ln = getLn(shape, false);
if (ln == null || !ln.isSetPrstDash()) {
return false;
}
setValue(LineDash.fromOoxmlId(ln.getPrstDash().getVal().intValue()));
return true;
}
};
fetchShapeProperty(fetcher);
LineDash dash = fetcher.getValue();
if (dash == null) {
CTLineProperties defaultLn = getDefaultLineProperties();
if (defaultLn != null && defaultLn.isSetPrstDash()) {
dash = LineDash.fromOoxmlId(defaultLn.getPrstDash().getVal().intValue());
}
}
return dash;
}
use of org.apache.poi.xslf.model.PropertyFetcher in project poi by apache.
the class XSLFSimpleShape method getLinePaint.
protected PaintStyle getLinePaint() {
XSLFSheet sheet = getSheet();
final XSLFTheme theme = sheet.getTheme();
final boolean hasPlaceholder = getPlaceholder() != null;
PropertyFetcher<PaintStyle> fetcher = new PropertyFetcher<PaintStyle>() {
@Override
public boolean fetch(XSLFShape shape) {
CTLineProperties spPr = getLn(shape, false);
XSLFFillProperties fp = XSLFPropertiesDelegate.getFillDelegate(spPr);
if (fp != null && fp.isSetNoFill()) {
setValue(null);
return true;
}
PackagePart pp = shape.getSheet().getPackagePart();
PaintStyle paint = selectPaint(fp, null, pp, theme, hasPlaceholder);
if (paint != null) {
setValue(paint);
return true;
}
CTShapeStyle style = shape.getSpStyle();
if (style != null) {
fp = XSLFPropertiesDelegate.getFillDelegate(style.getLnRef());
paint = selectPaint(fp, null, pp, theme, hasPlaceholder);
// line color was not found, check if it is defined in the theme
if (paint == null) {
paint = getThemePaint(style, pp);
}
}
if (paint != null) {
setValue(paint);
return true;
}
return false;
}
PaintStyle getThemePaint(CTShapeStyle style, PackagePart pp) {
// get a reference to a line style within the style matrix.
CTStyleMatrixReference lnRef = style.getLnRef();
if (lnRef == null) {
return null;
}
int idx = (int) lnRef.getIdx();
CTSchemeColor phClr = lnRef.getSchemeClr();
if (idx <= 0) {
return null;
}
CTLineProperties props = theme.getXmlObject().getThemeElements().getFmtScheme().getLnStyleLst().getLnArray(idx - 1);
XSLFFillProperties fp = XSLFPropertiesDelegate.getFillDelegate(props);
return selectPaint(fp, phClr, pp, theme, hasPlaceholder);
}
};
fetchShapeProperty(fetcher);
return fetcher.getValue();
}
use of org.apache.poi.xslf.model.PropertyFetcher in project poi by apache.
the class XSLFSimpleShape method getShadow.
/**
* @return shadow of this shape or null if shadow is disabled
*/
@Override
public XSLFShadow getShadow() {
PropertyFetcher<CTOuterShadowEffect> fetcher = new PropertyFetcher<CTOuterShadowEffect>() {
@Override
public boolean fetch(XSLFShape shape) {
XSLFEffectProperties ep = XSLFPropertiesDelegate.getEffectDelegate(shape.getShapeProperties());
if (ep != null && ep.isSetEffectLst()) {
CTOuterShadowEffect obj = ep.getEffectLst().getOuterShdw();
setValue(obj == null ? NO_SHADOW : obj);
return true;
}
return false;
}
};
fetchShapeProperty(fetcher);
CTOuterShadowEffect obj = fetcher.getValue();
if (obj == null) {
// fill color was not found, check if it is defined in the theme
CTShapeStyle style = getSpStyle();
if (style != null && style.getEffectRef() != null) {
// 1-based index of a shadow style within the style matrix
int idx = (int) style.getEffectRef().getIdx();
if (idx != 0) {
CTStyleMatrix styleMatrix = getSheet().getTheme().getXmlObject().getThemeElements().getFmtScheme();
CTEffectStyleItem ef = styleMatrix.getEffectStyleLst().getEffectStyleArray(idx - 1);
obj = ef.getEffectLst().getOuterShdw();
}
}
}
return (obj == null || obj == NO_SHADOW) ? null : new XSLFShadow(obj, this);
}
use of org.apache.poi.xslf.model.PropertyFetcher in project poi by apache.
the class XSLFSimpleShape method getXfrm.
protected CTTransform2D getXfrm(boolean create) {
PropertyFetcher<CTTransform2D> fetcher = new PropertyFetcher<CTTransform2D>() {
@Override
public boolean fetch(XSLFShape shape) {
XmlObject xo = shape.getShapeProperties();
if (xo instanceof CTShapeProperties && ((CTShapeProperties) xo).isSetXfrm()) {
setValue(((CTShapeProperties) xo).getXfrm());
return true;
}
return false;
}
};
fetchShapeProperty(fetcher);
CTTransform2D xfrm = fetcher.getValue();
if (!create || xfrm != null) {
return xfrm;
} else {
XmlObject xo = getShapeProperties();
if (xo instanceof CTShapeProperties) {
return ((CTShapeProperties) xo).addNewXfrm();
} else {
// ... group shapes have their own getXfrm()
LOG.log(POILogger.WARN, getClass() + " doesn't have xfrm element.");
return null;
}
}
}
Aggregations