use of org.openxmlformats.schemas.drawingml.x2006.main.CTStyleMatrixReference 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.openxmlformats.schemas.drawingml.x2006.main.CTStyleMatrixReference in project poi by apache.
the class XSLFSimpleShape method getDefaultLineProperties.
/**
* Get default line properties defined in the theme (if any).
* Used internally to resolve shape properties.
*
* @return line properties from the theme of null
*/
CTLineProperties getDefaultLineProperties() {
CTShapeStyle style = getSpStyle();
if (style == null) {
return null;
}
CTStyleMatrixReference lnRef = style.getLnRef();
if (lnRef == null) {
return null;
}
// 1-based index of a line style within the style matrix
int idx = (int) lnRef.getIdx();
XSLFTheme theme = getSheet().getTheme();
if (theme == null) {
return null;
}
CTBaseStyles styles = theme.getXmlObject().getThemeElements();
if (styles == null) {
return null;
}
CTStyleMatrix styleMatrix = styles.getFmtScheme();
if (styleMatrix == null) {
return null;
}
CTLineStyleList lineStyles = styleMatrix.getLnStyleLst();
if (lineStyles == null || lineStyles.sizeOfLnArray() < idx) {
return null;
}
return lineStyles.getLnArray(idx - 1);
}
use of org.openxmlformats.schemas.drawingml.x2006.main.CTStyleMatrixReference 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.openxmlformats.schemas.drawingml.x2006.main.CTStyleMatrixReference in project poi by apache.
the class XSLFPropertiesDelegate method getDelegate.
@SuppressWarnings("unchecked")
private static <T> T getDelegate(Class<T> clazz, XmlObject props) {
Object obj = null;
if (props == null) {
return null;
} else if (props instanceof CTShapeProperties) {
obj = new ShapeDelegate((CTShapeProperties) props);
} else if (props instanceof CTBackgroundProperties) {
obj = new BackgroundDelegate((CTBackgroundProperties) props);
} else if (props instanceof CTStyleMatrixReference) {
obj = new StyleMatrixDelegate((CTStyleMatrixReference) props);
} else if (props instanceof CTTableCellProperties) {
obj = new TableCellDelegate((CTTableCellProperties) props);
} else if (props instanceof CTNoFillProperties || props instanceof CTSolidColorFillProperties || props instanceof CTGradientFillProperties || props instanceof CTBlipFillProperties || props instanceof CTPatternFillProperties || props instanceof CTGroupFillProperties) {
obj = new FillPartDelegate(props);
} else if (props instanceof CTFillProperties) {
obj = new FillDelegate((CTFillProperties) props);
} else if (props instanceof CTLineProperties) {
obj = new LineStyleDelegate((CTLineProperties) props);
} else if (props instanceof CTTextCharacterProperties) {
obj = new TextCharDelegate((CTTextCharacterProperties) props);
} else {
LOG.log(POILogger.ERROR, props.getClass() + " is an unknown properties type");
return null;
}
if (clazz.isInstance(obj)) {
return (T) obj;
}
LOG.log(POILogger.WARN, obj.getClass() + " doesn't implement " + clazz);
return null;
}
use of org.openxmlformats.schemas.drawingml.x2006.main.CTStyleMatrixReference in project poi by apache.
the class XSSFConnector method prototype.
/**
* Initialize default structure of a new auto-shape
*
*/
protected static CTConnector prototype() {
if (prototype == null) {
CTConnector shape = CTConnector.Factory.newInstance();
CTConnectorNonVisual nv = shape.addNewNvCxnSpPr();
CTNonVisualDrawingProps nvp = nv.addNewCNvPr();
nvp.setId(1);
nvp.setName("Shape 1");
nv.addNewCNvCxnSpPr();
CTShapeProperties sp = shape.addNewSpPr();
CTTransform2D t2d = sp.addNewXfrm();
CTPositiveSize2D p1 = t2d.addNewExt();
p1.setCx(0);
p1.setCy(0);
CTPoint2D p2 = t2d.addNewOff();
p2.setX(0);
p2.setY(0);
CTPresetGeometry2D geom = sp.addNewPrstGeom();
geom.setPrst(STShapeType.LINE);
geom.addNewAvLst();
CTShapeStyle style = shape.addNewStyle();
CTSchemeColor scheme = style.addNewLnRef().addNewSchemeClr();
scheme.setVal(STSchemeColorVal.ACCENT_1);
style.getLnRef().setIdx(1);
CTStyleMatrixReference fillref = style.addNewFillRef();
fillref.setIdx(0);
fillref.addNewSchemeClr().setVal(STSchemeColorVal.ACCENT_1);
CTStyleMatrixReference effectRef = style.addNewEffectRef();
effectRef.setIdx(0);
effectRef.addNewSchemeClr().setVal(STSchemeColorVal.ACCENT_1);
CTFontReference fontRef = style.addNewFontRef();
fontRef.setIdx(STFontCollectionIndex.MINOR);
fontRef.addNewSchemeClr().setVal(STSchemeColorVal.TX_1);
prototype = shape;
}
return prototype;
}
Aggregations