Search in sources :

Example 16 with CTColor

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

the class TestXSLFColor method testSRgb.

@Test
public void testSRgb() {
    CTColor xml = CTColor.Factory.newInstance();
    xml.addNewSrgbClr().setVal(new byte[] { (byte) 0xFF, (byte) 0xFF, 0 });
    XSLFColor color = new XSLFColor(xml, null, null);
    assertEquals(new Color(0xFF, 0xFF, 0), color.getColor());
}
Also used : Color(java.awt.Color) CTColor(org.openxmlformats.schemas.drawingml.x2006.main.CTColor) 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) CTColor(org.openxmlformats.schemas.drawingml.x2006.main.CTColor) Test(org.junit.Test)

Example 17 with CTColor

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

the class TestXSLFColor method testSys.

@Test
public void testSys() {
    CTColor xml = CTColor.Factory.newInstance();
    CTSystemColor sys = xml.addNewSysClr();
    sys.setVal(STSystemColorVal.CAPTION_TEXT);
    XSLFColor color = new XSLFColor(xml, null, null);
    assertEquals(Color.black, color.getColor());
    xml = CTColor.Factory.newInstance();
    sys = xml.addNewSysClr();
    sys.setLastClr(new byte[] { (byte) 0xFF, 0, 0 });
    color = new XSLFColor(xml, null, null);
    assertEquals(Color.red, color.getColor());
}
Also used : CTSystemColor(org.openxmlformats.schemas.drawingml.x2006.main.CTSystemColor) CTColor(org.openxmlformats.schemas.drawingml.x2006.main.CTColor) Test(org.junit.Test)

Example 18 with CTColor

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

the class TestXSLFColor method testGetters.

@Test
public void testGetters() {
    CTColor xml = CTColor.Factory.newInstance();
    CTSRgbColor c = xml.addNewSrgbClr();
    c.setVal(new byte[] { (byte) 0xFF, 0, 0 });
    XSLFColor color = new XSLFColor(xml, null, null);
    assertEquals(-1, color.getAlpha());
    c.addNewAlpha().setVal(50000);
    assertEquals(50, color.getAlpha());
    assertEquals(-1, color.getAlphaMod());
    c.addNewAlphaMod().setVal(50000);
    assertEquals(50, color.getAlphaMod());
    assertEquals(-1, color.getAlphaOff());
    c.addNewAlphaOff().setVal(50000);
    assertEquals(50, color.getAlphaOff());
    assertEquals(-1, color.getLumMod());
    c.addNewLumMod().setVal(50000);
    assertEquals(50, color.getLumMod());
    assertEquals(-1, color.getLumOff());
    c.addNewLumOff().setVal(50000);
    assertEquals(50, color.getLumOff());
    assertEquals(-1, color.getSat());
    c.addNewSat().setVal(50000);
    assertEquals(50, color.getSat());
    assertEquals(-1, color.getSatMod());
    c.addNewSatMod().setVal(50000);
    assertEquals(50, color.getSatMod());
    assertEquals(-1, color.getSatOff());
    c.addNewSatOff().setVal(50000);
    assertEquals(50, color.getSatOff());
    assertEquals(-1, color.getRed());
    c.addNewRed().setVal(50000);
    assertEquals(50, color.getRed());
    assertEquals(-1, color.getGreen());
    c.addNewGreen().setVal(50000);
    assertEquals(50, color.getGreen());
    assertEquals(-1, color.getBlue());
    c.addNewBlue().setVal(50000);
    assertEquals(50, color.getRed());
    assertEquals(-1, color.getShade());
    c.addNewShade().setVal(50000);
    assertEquals(50, color.getShade());
    assertEquals(-1, color.getTint());
    c.addNewTint().setVal(50000);
    assertEquals(50, color.getTint());
}
Also used : CTSRgbColor(org.openxmlformats.schemas.drawingml.x2006.main.CTSRgbColor) CTColor(org.openxmlformats.schemas.drawingml.x2006.main.CTColor) Test(org.junit.Test)

Example 19 with CTColor

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

the class TestXSLFColor method testPresetColor.

@Test
public void testPresetColor() {
    CTColor xml = CTColor.Factory.newInstance();
    xml.addNewPrstClr().setVal(STPresetColorVal.AQUAMARINE);
    XSLFColor color = new XSLFColor(xml, null, null);
    assertEquals(new Color(127, 255, 212), color.getColor());
    for (PresetColor pc : PresetColor.values()) {
        if (pc.ooxmlId == null)
            continue;
        xml = CTColor.Factory.newInstance();
        STPresetColorVal.Enum preVal = STPresetColorVal.Enum.forString(pc.ooxmlId);
        STSystemColorVal.Enum sysVal = STSystemColorVal.Enum.forString(pc.ooxmlId);
        assertTrue(pc.ooxmlId, preVal != null || sysVal != null);
        if (preVal != null) {
            xml.addNewPrstClr().setVal(preVal);
        } else {
            xml.addNewSysClr().setVal(sysVal);
        }
        color = new XSLFColor(xml, null, null);
        assertEquals(pc.color, color.getColor());
    }
}
Also used : STPresetColorVal(org.openxmlformats.schemas.drawingml.x2006.main.STPresetColorVal) STSystemColorVal(org.openxmlformats.schemas.drawingml.x2006.main.STSystemColorVal) Color(java.awt.Color) CTColor(org.openxmlformats.schemas.drawingml.x2006.main.CTColor) 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) PresetColor(org.apache.poi.sl.usermodel.PresetColor) CTColor(org.openxmlformats.schemas.drawingml.x2006.main.CTColor) Test(org.junit.Test)

Example 20 with CTColor

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

the class TestThemesTable method testThemesTableColors.

@Test
public void testThemesTableColors() throws Exception {
    // Load our two test workbooks
    XSSFWorkbook simple = XSSFTestDataSamples.openSampleWorkbook(testFileSimple);
    XSSFWorkbook complex = XSSFTestDataSamples.openSampleWorkbook(testFileComplex);
    // Save and re-load them, to check for stability across that
    XSSFWorkbook simpleRS = XSSFTestDataSamples.writeOutAndReadBack(simple);
    XSSFWorkbook complexRS = XSSFTestDataSamples.writeOutAndReadBack(complex);
    // Fetch fresh copies to test with
    simple = XSSFTestDataSamples.openSampleWorkbook(testFileSimple);
    complex = XSSFTestDataSamples.openSampleWorkbook(testFileComplex);
    // Files and descriptions
    Map<String, XSSFWorkbook> workbooks = new LinkedHashMap<String, XSSFWorkbook>();
    workbooks.put(testFileSimple, simple);
    workbooks.put("Re-Saved_" + testFileSimple, simpleRS);
    workbooks.put(testFileComplex, complex);
    workbooks.put("Re-Saved_" + testFileComplex, complexRS);
    // Sanity check
    assertEquals(rgbExpected.length, rgbExpected.length);
    // For offline testing
    boolean createFiles = false;
    //  for the theme-applied cells in Column A are correct
    for (String whatWorkbook : workbooks.keySet()) {
        XSSFWorkbook workbook = workbooks.get(whatWorkbook);
        XSSFSheet sheet = workbook.getSheetAt(0);
        int startRN = 0;
        if (whatWorkbook.endsWith(testFileComplex))
            startRN++;
        for (int rn = startRN; rn < rgbExpected.length + startRN; rn++) {
            XSSFRow row = sheet.getRow(rn);
            assertNotNull("Missing row " + rn + " in " + whatWorkbook, row);
            String ref = (new CellReference(rn, 0)).formatAsString();
            XSSFCell cell = row.getCell(0);
            assertNotNull("Missing cell " + ref + " in " + whatWorkbook, cell);
            int expectedThemeIdx = rn - startRN;
            ThemeElement themeElem = ThemeElement.byId(expectedThemeIdx);
            assertEquals("Wrong theme at " + ref + " in " + whatWorkbook, themeElem.name.toLowerCase(Locale.ROOT), cell.getStringCellValue());
            // Fonts are theme-based in their colours
            XSSFFont font = cell.getCellStyle().getFont();
            CTColor ctColor = font.getCTFont().getColorArray(0);
            assertNotNull(ctColor);
            assertEquals(true, ctColor.isSetTheme());
            assertEquals(themeElem.idx, ctColor.getTheme());
            // Get the colour, via the theme
            XSSFColor color = font.getXSSFColor();
            // Theme colours aren't tinted
            assertEquals(false, color.hasTint());
            // Check the RGB part (no tint)
            assertEquals("Wrong theme colour " + themeElem.name + " on " + whatWorkbook, rgbExpected[expectedThemeIdx], Hex.encodeHexString(color.getRGB()));
            long themeIdx = font.getCTFont().getColorArray(0).getTheme();
            assertEquals("Wrong theme index " + expectedThemeIdx + " on " + whatWorkbook, expectedThemeIdx, themeIdx);
            if (createFiles) {
                XSSFCellStyle cs = row.getSheet().getWorkbook().createCellStyle();
                cs.setFillForegroundColor(color);
                cs.setFillPattern(CellStyle.SOLID_FOREGROUND);
                row.createCell(1).setCellStyle(cs);
            }
        }
        if (createFiles) {
            FileOutputStream fos = new FileOutputStream("Generated_" + whatWorkbook);
            workbook.write(fos);
            fos.close();
        }
    }
}
Also used : CellReference(org.apache.poi.ss.util.CellReference) CTColor(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor) LinkedHashMap(java.util.LinkedHashMap) ThemeElement(org.apache.poi.xssf.model.ThemesTable.ThemeElement) XSSFColor(org.apache.poi.xssf.usermodel.XSSFColor) XSSFSheet(org.apache.poi.xssf.usermodel.XSSFSheet) XSSFCellStyle(org.apache.poi.xssf.usermodel.XSSFCellStyle) XSSFRow(org.apache.poi.xssf.usermodel.XSSFRow) XSSFFont(org.apache.poi.xssf.usermodel.XSSFFont) FileOutputStream(java.io.FileOutputStream) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) XSSFCell(org.apache.poi.xssf.usermodel.XSSFCell) Test(org.junit.Test)

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