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());
}
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());
}
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());
}
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());
}
}
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();
}
}
}
Aggregations