Search in sources :

Example 1 with CTColorScheme

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

the class ThemesTable method getThemeColor.

/**
     * Convert a theme "index" (as used by fonts etc) into a color.
     * @param idx A theme "index"
     * @return The mapped XSSFColor, or null if not mapped.
     */
public XSSFColor getThemeColor(int idx) {
    // Theme color references are NOT positional indices into the color scheme,
    // i.e. these keys are NOT the same as the order in which theme colors appear
    // in theme1.xml. They are keys to a mapped color.
    CTColorScheme colorScheme = theme.getTheme().getThemeElements().getClrScheme();
    CTColor ctColor;
    switch(ThemeElement.byId(idx)) {
        case LT1:
            ctColor = colorScheme.getLt1();
            break;
        case DK1:
            ctColor = colorScheme.getDk1();
            break;
        case LT2:
            ctColor = colorScheme.getLt2();
            break;
        case DK2:
            ctColor = colorScheme.getDk2();
            break;
        case ACCENT1:
            ctColor = colorScheme.getAccent1();
            break;
        case ACCENT2:
            ctColor = colorScheme.getAccent2();
            break;
        case ACCENT3:
            ctColor = colorScheme.getAccent3();
            break;
        case ACCENT4:
            ctColor = colorScheme.getAccent4();
            break;
        case ACCENT5:
            ctColor = colorScheme.getAccent5();
            break;
        case ACCENT6:
            ctColor = colorScheme.getAccent6();
            break;
        case HLINK:
            ctColor = colorScheme.getHlink();
            break;
        case FOLHLINK:
            ctColor = colorScheme.getFolHlink();
            break;
        default:
            return null;
    }
    byte[] rgb = null;
    if (ctColor.isSetSrgbClr()) {
        // Color is a regular one
        rgb = ctColor.getSrgbClr().getVal();
    } else if (ctColor.isSetSysClr()) {
        // Color is a tint of white or black
        rgb = ctColor.getSysClr().getLastClr();
    } else {
        return null;
    }
    return new XSSFColor(rgb, colorMap);
}
Also used : XSSFColor(org.apache.poi.xssf.usermodel.XSSFColor) CTColorScheme(org.openxmlformats.schemas.drawingml.x2006.main.CTColorScheme) CTColor(org.openxmlformats.schemas.drawingml.x2006.main.CTColor)

Example 2 with CTColorScheme

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

Aggregations

CTColor (org.openxmlformats.schemas.drawingml.x2006.main.CTColor)2 CTColorScheme (org.openxmlformats.schemas.drawingml.x2006.main.CTColorScheme)2 XSSFColor (org.apache.poi.xssf.usermodel.XSSFColor)1 XmlObject (org.apache.xmlbeans.XmlObject)1 CTBaseStyles (org.openxmlformats.schemas.drawingml.x2006.main.CTBaseStyles)1