Search in sources :

Example 36 with CTColor

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

the class XSLFTheme method initialize.

private void initialize() {
    CTBaseStyles elems = _theme.getThemeElements();
    CTColorScheme scheme = elems.getClrScheme();
    // The color scheme is responsible for defining a list of twelve colors. 
    _schemeColors = new HashMap<String, CTColor>(12);
    for (XmlObject o : scheme.selectPath("*")) {
        CTColor c = (CTColor) o;
        String name = c.getDomNode().getLocalName();
        _schemeColors.put(name, c);
    }
}
Also used : CTColorScheme(org.openxmlformats.schemas.drawingml.x2006.main.CTColorScheme) CTBaseStyles(org.openxmlformats.schemas.drawingml.x2006.main.CTBaseStyles) XmlObject(org.apache.xmlbeans.XmlObject) CTColor(org.openxmlformats.schemas.drawingml.x2006.main.CTColor)

Example 37 with CTColor

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

the class XSSFRichTextString method setRunAttributes.

/**
     * Copy font attributes from CTFont bean into CTRPrElt bean
     */
private void setRunAttributes(CTFont ctFont, CTRPrElt pr) {
    if (ctFont.sizeOfBArray() > 0)
        pr.addNewB().setVal(ctFont.getBArray(0).getVal());
    if (ctFont.sizeOfUArray() > 0)
        pr.addNewU().setVal(ctFont.getUArray(0).getVal());
    if (ctFont.sizeOfIArray() > 0)
        pr.addNewI().setVal(ctFont.getIArray(0).getVal());
    if (ctFont.sizeOfColorArray() > 0) {
        CTColor c1 = ctFont.getColorArray(0);
        CTColor c2 = pr.addNewColor();
        if (c1.isSetAuto())
            c2.setAuto(c1.getAuto());
        if (c1.isSetIndexed())
            c2.setIndexed(c1.getIndexed());
        if (c1.isSetRgb())
            c2.setRgb(c1.getRgb());
        if (c1.isSetTheme())
            c2.setTheme(c1.getTheme());
        if (c1.isSetTint())
            c2.setTint(c1.getTint());
    }
    if (ctFont.sizeOfSzArray() > 0)
        pr.addNewSz().setVal(ctFont.getSzArray(0).getVal());
    if (ctFont.sizeOfNameArray() > 0)
        pr.addNewRFont().setVal(ctFont.getNameArray(0).getVal());
    if (ctFont.sizeOfFamilyArray() > 0)
        pr.addNewFamily().setVal(ctFont.getFamilyArray(0).getVal());
    if (ctFont.sizeOfSchemeArray() > 0)
        pr.addNewScheme().setVal(ctFont.getSchemeArray(0).getVal());
    if (ctFont.sizeOfCharsetArray() > 0)
        pr.addNewCharset().setVal(ctFont.getCharsetArray(0).getVal());
    if (ctFont.sizeOfCondenseArray() > 0)
        pr.addNewCondense().setVal(ctFont.getCondenseArray(0).getVal());
    if (ctFont.sizeOfExtendArray() > 0)
        pr.addNewExtend().setVal(ctFont.getExtendArray(0).getVal());
    if (ctFont.sizeOfVertAlignArray() > 0)
        pr.addNewVertAlign().setVal(ctFont.getVertAlignArray(0).getVal());
    if (ctFont.sizeOfOutlineArray() > 0)
        pr.addNewOutline().setVal(ctFont.getOutlineArray(0).getVal());
    if (ctFont.sizeOfShadowArray() > 0)
        pr.addNewShadow().setVal(ctFont.getShadowArray(0).getVal());
    if (ctFont.sizeOfStrikeArray() > 0)
        pr.addNewStrike().setVal(ctFont.getStrikeArray(0).getVal());
}
Also used : CTColor(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor)

Example 38 with CTColor

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

the class XSSFRichTextString method toCTFont.

/**
     *
     * CTRPrElt --> CTFont adapter
     */
protected static CTFont toCTFont(CTRPrElt pr) {
    CTFont ctFont = CTFont.Factory.newInstance();
    // Bug 58315: there are files where there is no pr-entry for a RichTextString
    if (pr == null) {
        return ctFont;
    }
    if (pr.sizeOfBArray() > 0)
        ctFont.addNewB().setVal(pr.getBArray(0).getVal());
    if (pr.sizeOfUArray() > 0)
        ctFont.addNewU().setVal(pr.getUArray(0).getVal());
    if (pr.sizeOfIArray() > 0)
        ctFont.addNewI().setVal(pr.getIArray(0).getVal());
    if (pr.sizeOfColorArray() > 0) {
        CTColor c1 = pr.getColorArray(0);
        CTColor c2 = ctFont.addNewColor();
        if (c1.isSetAuto())
            c2.setAuto(c1.getAuto());
        if (c1.isSetIndexed())
            c2.setIndexed(c1.getIndexed());
        if (c1.isSetRgb())
            c2.setRgb(c1.getRgb());
        if (c1.isSetTheme())
            c2.setTheme(c1.getTheme());
        if (c1.isSetTint())
            c2.setTint(c1.getTint());
    }
    if (pr.sizeOfSzArray() > 0)
        ctFont.addNewSz().setVal(pr.getSzArray(0).getVal());
    if (pr.sizeOfRFontArray() > 0)
        ctFont.addNewName().setVal(pr.getRFontArray(0).getVal());
    if (pr.sizeOfFamilyArray() > 0)
        ctFont.addNewFamily().setVal(pr.getFamilyArray(0).getVal());
    if (pr.sizeOfSchemeArray() > 0)
        ctFont.addNewScheme().setVal(pr.getSchemeArray(0).getVal());
    if (pr.sizeOfCharsetArray() > 0)
        ctFont.addNewCharset().setVal(pr.getCharsetArray(0).getVal());
    if (pr.sizeOfCondenseArray() > 0)
        ctFont.addNewCondense().setVal(pr.getCondenseArray(0).getVal());
    if (pr.sizeOfExtendArray() > 0)
        ctFont.addNewExtend().setVal(pr.getExtendArray(0).getVal());
    if (pr.sizeOfVertAlignArray() > 0)
        ctFont.addNewVertAlign().setVal(pr.getVertAlignArray(0).getVal());
    if (pr.sizeOfOutlineArray() > 0)
        ctFont.addNewOutline().setVal(pr.getOutlineArray(0).getVal());
    if (pr.sizeOfShadowArray() > 0)
        ctFont.addNewShadow().setVal(pr.getShadowArray(0).getVal());
    if (pr.sizeOfStrikeArray() > 0)
        ctFont.addNewStrike().setVal(pr.getStrikeArray(0).getVal());
    return ctFont;
}
Also used : CTFont(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont) CTColor(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor)

Example 39 with CTColor

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

CTColor (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor)27 Test (org.junit.Test)12 CTColor (org.openxmlformats.schemas.drawingml.x2006.main.CTColor)10 CTPatternFill (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPatternFill)6 CTSRgbColor (org.openxmlformats.schemas.drawingml.x2006.main.CTSRgbColor)5 Color (java.awt.Color)4 XSSFColor (org.apache.poi.xssf.usermodel.XSSFColor)4 CTHslColor (org.openxmlformats.schemas.drawingml.x2006.main.CTHslColor)4 CTSystemColor (org.openxmlformats.schemas.drawingml.x2006.main.CTSystemColor)4 CTFont (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont)4 PresetColor (org.apache.poi.sl.usermodel.PresetColor)3 XmlObject (org.apache.xmlbeans.XmlObject)2 CTColorScheme (org.openxmlformats.schemas.drawingml.x2006.main.CTColorScheme)2 CTFill (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFill)2 CTColor (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTColor)2 CTRPr (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRPr)2 FileOutputStream (java.io.FileOutputStream)1 LinkedHashMap (java.util.LinkedHashMap)1 DrawPaint (org.apache.poi.sl.draw.DrawPaint)1 SolidPaint (org.apache.poi.sl.usermodel.PaintStyle.SolidPaint)1