Search in sources :

Example 6 with CTSchemeColor

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

the class XSLFShadow method getFillStyle.

@Override
public SolidPaint getFillStyle() {
    XSLFTheme theme = getSheet().getTheme();
    CTOuterShadowEffect ct = (CTOuterShadowEffect) getXmlObject();
    if (ct == null)
        return null;
    CTSchemeColor phClr = ct.getSchemeClr();
    final XSLFColor xc = new XSLFColor(ct, theme, phClr);
    return DrawPaint.createSolidPaint(xc.getColorStyle());
}
Also used : CTSchemeColor(org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor) CTOuterShadowEffect(org.openxmlformats.schemas.drawingml.x2006.main.CTOuterShadowEffect)

Example 7 with CTSchemeColor

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

the class XSLFShape method selectPaint.

protected static PaintStyle selectPaint(final CTGradientFillProperties gradFill, CTSchemeColor phClr, final XSLFTheme theme) {
    final CTGradientStop[] gs = gradFill.getGsLst().getGsArray();
    Arrays.sort(gs, new Comparator<CTGradientStop>() {

        public int compare(CTGradientStop o1, CTGradientStop o2) {
            Integer pos1 = o1.getPos();
            Integer pos2 = o2.getPos();
            return pos1.compareTo(pos2);
        }
    });
    final ColorStyle[] cs = new ColorStyle[gs.length];
    final float[] fractions = new float[gs.length];
    int i = 0;
    for (CTGradientStop cgs : gs) {
        CTSchemeColor phClrCgs = phClr;
        if (phClrCgs == null && cgs.isSetSchemeClr()) {
            phClrCgs = cgs.getSchemeClr();
        }
        cs[i] = new XSLFColor(cgs, theme, phClrCgs).getColorStyle();
        fractions[i] = cgs.getPos() / 100000.f;
        i++;
    }
    return new GradientPaint() {

        public double getGradientAngle() {
            return (gradFill.isSetLin()) ? gradFill.getLin().getAng() / 60000.d : 0;
        }

        public ColorStyle[] getGradientColors() {
            return cs;
        }

        public float[] getGradientFractions() {
            return fractions;
        }

        public boolean isRotatedWithShape() {
            return gradFill.getRotWithShape();
        }

        public GradientType getGradientType() {
            if (gradFill.isSetLin()) {
                return GradientType.linear;
            }
            if (gradFill.isSetPath()) {
                /* TODO: handle rect path */
                STPathShadeType.Enum ps = gradFill.getPath().getPath();
                if (ps == STPathShadeType.CIRCLE) {
                    return GradientType.circular;
                } else if (ps == STPathShadeType.SHAPE) {
                    return GradientType.shape;
                }
            }
            return GradientType.linear;
        }
    };
}
Also used : STPathShadeType(org.openxmlformats.schemas.drawingml.x2006.main.STPathShadeType) CTGradientStop(org.openxmlformats.schemas.drawingml.x2006.main.CTGradientStop) ColorStyle(org.apache.poi.sl.usermodel.ColorStyle) CTSchemeColor(org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor) GradientPaint(org.apache.poi.sl.usermodel.PaintStyle.GradientPaint) DrawPaint(org.apache.poi.sl.draw.DrawPaint) GradientPaint(org.apache.poi.sl.usermodel.PaintStyle.GradientPaint) TexturePaint(org.apache.poi.sl.usermodel.PaintStyle.TexturePaint)

Example 8 with CTSchemeColor

use of org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor 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)

Aggregations

CTSchemeColor (org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor)8 DrawPaint (org.apache.poi.sl.draw.DrawPaint)4 PaintStyle (org.apache.poi.sl.usermodel.PaintStyle)3 XSLFFillProperties (org.apache.poi.xslf.usermodel.XSLFPropertiesDelegate.XSLFFillProperties)3 CTShapeStyle (org.openxmlformats.schemas.drawingml.x2006.main.CTShapeStyle)3 Color (java.awt.Color)2 PackagePart (org.apache.poi.openxml4j.opc.PackagePart)2 GradientPaint (org.apache.poi.sl.usermodel.PaintStyle.GradientPaint)2 TexturePaint (org.apache.poi.sl.usermodel.PaintStyle.TexturePaint)2 XmlObject (org.apache.xmlbeans.XmlObject)2 CTFontReference (org.openxmlformats.schemas.drawingml.x2006.main.CTFontReference)2 CTStyleMatrixReference (org.openxmlformats.schemas.drawingml.x2006.main.CTStyleMatrixReference)2 ColorStyle (org.apache.poi.sl.usermodel.ColorStyle)1 SolidPaint (org.apache.poi.sl.usermodel.PaintStyle.SolidPaint)1 PresetColor (org.apache.poi.sl.usermodel.PresetColor)1 CharacterPropertyFetcher (org.apache.poi.xslf.model.CharacterPropertyFetcher)1 PropertyFetcher (org.apache.poi.xslf.model.PropertyFetcher)1 XmlCursor (org.apache.xmlbeans.XmlCursor)1 Test (org.junit.Test)1 CTColor (org.openxmlformats.schemas.drawingml.x2006.main.CTColor)1