Search in sources :

Example 1 with CTFontReference

use of org.openxmlformats.schemas.drawingml.x2006.main.CTFontReference in project poi by apache.

the class XSLFColor method toColor.

Color toColor(XmlObject obj, XSLFTheme theme) {
    Color color = null;
    for (XmlObject ch : obj.selectPath("*")) {
        if (ch instanceof CTHslColor) {
            CTHslColor hsl = (CTHslColor) ch;
            int h = hsl.getHue2();
            int s = hsl.getSat2();
            int l = hsl.getLum2();
            color = DrawPaint.HSL2RGB(h / 60000d, s / 1000d, l / 1000d, 1d);
        } else if (ch instanceof CTPresetColor) {
            CTPresetColor prst = (CTPresetColor) ch;
            String colorName = prst.getVal().toString();
            PresetColor pc = PresetColor.valueOfOoxmlId(colorName);
            if (pc != null) {
                color = pc.color;
            }
        } else if (ch instanceof CTSchemeColor) {
            CTSchemeColor schemeColor = (CTSchemeColor) ch;
            String colorRef = schemeColor.getVal().toString();
            if (_phClr != null) {
                // context color overrides the theme
                colorRef = _phClr.getVal().toString();
            }
            // find referenced CTColor in the theme and convert it to java.awt.Color via a recursive call
            CTColor ctColor = theme.getCTColor(colorRef);
            if (ctColor != null) {
                color = toColor(ctColor, null);
            }
        } else if (ch instanceof CTScRgbColor) {
            // color in percentage is in linear RGB color space, i.e. needs to be gamma corrected for AWT color
            CTScRgbColor scrgb = (CTScRgbColor) ch;
            color = new Color(DrawPaint.lin2srgb(scrgb.getR()), DrawPaint.lin2srgb(scrgb.getG()), DrawPaint.lin2srgb(scrgb.getB()));
        } else if (ch instanceof CTSRgbColor) {
            // color in sRGB color space, i.e. same as AWT Color
            CTSRgbColor srgb = (CTSRgbColor) ch;
            byte[] val = srgb.getVal();
            color = new Color(0xFF & val[0], 0xFF & val[1], 0xFF & val[2]);
        } else if (ch instanceof CTSystemColor) {
            CTSystemColor sys = (CTSystemColor) ch;
            if (sys.isSetLastClr()) {
                byte[] val = sys.getLastClr();
                color = new Color(0xFF & val[0], 0xFF & val[1], 0xFF & val[2]);
            } else {
                String colorName = sys.getVal().toString();
                PresetColor pc = PresetColor.valueOfOoxmlId(colorName);
                if (pc != null) {
                    color = pc.color;
                }
                if (color == null) {
                    color = Color.black;
                }
            }
        } else if (ch instanceof CTFontReference) {
            // try next ...
            continue;
        } else {
            throw new IllegalArgumentException("Unexpected color choice: " + ch.getClass());
        }
    }
    return color;
}
Also used : CTPresetColor(org.openxmlformats.schemas.drawingml.x2006.main.CTPresetColor) Color(java.awt.Color) CTColor(org.openxmlformats.schemas.drawingml.x2006.main.CTColor) CTPresetColor(org.openxmlformats.schemas.drawingml.x2006.main.CTPresetColor) CTScRgbColor(org.openxmlformats.schemas.drawingml.x2006.main.CTScRgbColor) CTHslColor(org.openxmlformats.schemas.drawingml.x2006.main.CTHslColor) CTSRgbColor(org.openxmlformats.schemas.drawingml.x2006.main.CTSRgbColor) CTSystemColor(org.openxmlformats.schemas.drawingml.x2006.main.CTSystemColor) PresetColor(org.apache.poi.sl.usermodel.PresetColor) CTSchemeColor(org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor) CTSchemeColor(org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor) CTScRgbColor(org.openxmlformats.schemas.drawingml.x2006.main.CTScRgbColor) CTFontReference(org.openxmlformats.schemas.drawingml.x2006.main.CTFontReference) CTHslColor(org.openxmlformats.schemas.drawingml.x2006.main.CTHslColor) DrawPaint(org.apache.poi.sl.draw.DrawPaint) CTColor(org.openxmlformats.schemas.drawingml.x2006.main.CTColor) CTSystemColor(org.openxmlformats.schemas.drawingml.x2006.main.CTSystemColor) XmlObject(org.apache.xmlbeans.XmlObject) CTPresetColor(org.openxmlformats.schemas.drawingml.x2006.main.CTPresetColor) PresetColor(org.apache.poi.sl.usermodel.PresetColor) CTSRgbColor(org.openxmlformats.schemas.drawingml.x2006.main.CTSRgbColor)

Example 2 with CTFontReference

use of org.openxmlformats.schemas.drawingml.x2006.main.CTFontReference 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;
}
Also used : CTTransform2D(org.openxmlformats.schemas.drawingml.x2006.main.CTTransform2D) CTPoint2D(org.openxmlformats.schemas.drawingml.x2006.main.CTPoint2D) CTShapeStyle(org.openxmlformats.schemas.drawingml.x2006.main.CTShapeStyle) CTConnector(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTConnector) CTShapeProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties) CTPresetGeometry2D(org.openxmlformats.schemas.drawingml.x2006.main.CTPresetGeometry2D) CTNonVisualDrawingProps(org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps) CTSchemeColor(org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor) CTStyleMatrixReference(org.openxmlformats.schemas.drawingml.x2006.main.CTStyleMatrixReference) CTPositiveSize2D(org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D) CTFontReference(org.openxmlformats.schemas.drawingml.x2006.main.CTFontReference) CTConnectorNonVisual(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTConnectorNonVisual)

Aggregations

CTFontReference (org.openxmlformats.schemas.drawingml.x2006.main.CTFontReference)2 CTSchemeColor (org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor)2 Color (java.awt.Color)1 DrawPaint (org.apache.poi.sl.draw.DrawPaint)1 PresetColor (org.apache.poi.sl.usermodel.PresetColor)1 XmlObject (org.apache.xmlbeans.XmlObject)1 CTColor (org.openxmlformats.schemas.drawingml.x2006.main.CTColor)1 CTHslColor (org.openxmlformats.schemas.drawingml.x2006.main.CTHslColor)1 CTNonVisualDrawingProps (org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps)1 CTPoint2D (org.openxmlformats.schemas.drawingml.x2006.main.CTPoint2D)1 CTPositiveSize2D (org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D)1 CTPresetColor (org.openxmlformats.schemas.drawingml.x2006.main.CTPresetColor)1 CTPresetGeometry2D (org.openxmlformats.schemas.drawingml.x2006.main.CTPresetGeometry2D)1 CTSRgbColor (org.openxmlformats.schemas.drawingml.x2006.main.CTSRgbColor)1 CTScRgbColor (org.openxmlformats.schemas.drawingml.x2006.main.CTScRgbColor)1 CTShapeProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties)1 CTShapeStyle (org.openxmlformats.schemas.drawingml.x2006.main.CTShapeStyle)1 CTStyleMatrixReference (org.openxmlformats.schemas.drawingml.x2006.main.CTStyleMatrixReference)1 CTSystemColor (org.openxmlformats.schemas.drawingml.x2006.main.CTSystemColor)1 CTTransform2D (org.openxmlformats.schemas.drawingml.x2006.main.CTTransform2D)1