Search in sources :

Example 26 with CTColor

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

the class TestXSSFFont method testColor.

@Test
public void testColor() {
    CTFont ctFont = CTFont.Factory.newInstance();
    CTColor color = ctFont.addNewColor();
    color.setIndexed(XSSFFont.DEFAULT_FONT_COLOR);
    ctFont.setColorArray(0, color);
    XSSFFont xssfFont = new XSSFFont(ctFont);
    assertEquals(IndexedColors.BLACK.getIndex(), xssfFont.getColor());
    xssfFont.setColor(IndexedColors.RED.getIndex());
    assertEquals(IndexedColors.RED.getIndex(), ctFont.getColorArray(0).getIndexed());
}
Also used : CTFont(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont) CTColor(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor) Test(org.junit.Test)

Example 27 with CTColor

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

the class TestXSSFFont method testRgbColor.

@Test
public void testRgbColor() {
    CTFont ctFont = CTFont.Factory.newInstance();
    CTColor color = ctFont.addNewColor();
    color.setRgb(Integer.toHexString(0xFFFFFF).getBytes(LocaleUtil.CHARSET_1252));
    ctFont.setColorArray(0, color);
    XSSFFont xssfFont = new XSSFFont(ctFont);
    assertEquals(ctFont.getColorArray(0).getRgb()[0], xssfFont.getXSSFColor().getRGB()[0]);
    assertEquals(ctFont.getColorArray(0).getRgb()[1], xssfFont.getXSSFColor().getRGB()[1]);
    assertEquals(ctFont.getColorArray(0).getRgb()[2], xssfFont.getXSSFColor().getRGB()[2]);
    assertEquals(ctFont.getColorArray(0).getRgb()[3], xssfFont.getXSSFColor().getRGB()[3]);
    xssfFont.setColor((short) 23);
    byte[] bytes = Integer.toHexString(0xF1F1F1).getBytes(LocaleUtil.CHARSET_1252);
    color.setRgb(bytes);
    XSSFColor newColor = new XSSFColor(color, null);
    xssfFont.setColor(newColor);
    assertEquals(ctFont.getColorArray(0).getRgb()[2], newColor.getRGB()[2]);
    assertArrayEquals(bytes, xssfFont.getXSSFColor().getRGB());
    assertEquals(0, xssfFont.getColor());
}
Also used : CTFont(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont) CTColor(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor) Test(org.junit.Test)

Example 28 with CTColor

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

the class TestXSLFColor method testSchemeColor.

@Test
public void testSchemeColor() throws IOException {
    XMLSlideShow ppt = new XMLSlideShow();
    XSLFTheme theme = ppt.createSlide().getTheme();
    CTColor xml = CTColor.Factory.newInstance();
    xml.addNewSchemeClr().setVal(STSchemeColorVal.ACCENT_2);
    XSLFColor color = new XSLFColor(xml, theme, null);
    // accent2 is theme1.xml is <a:srgbClr val="C0504D"/>
    assertEquals(Color.decode("0xC0504D"), color.getColor());
    xml = CTColor.Factory.newInstance();
    xml.addNewSchemeClr().setVal(STSchemeColorVal.LT_1);
    color = new XSLFColor(xml, theme, null);
    // <a:sysClr val="window" lastClr="FFFFFF"/>
    assertEquals(Color.decode("0xFFFFFF"), color.getColor());
    xml = CTColor.Factory.newInstance();
    xml.addNewSchemeClr().setVal(STSchemeColorVal.DK_1);
    color = new XSLFColor(xml, theme, null);
    // <a:sysClr val="windowText" lastClr="000000"/>
    assertEquals(Color.decode("0x000000"), color.getColor());
    ppt.close();
}
Also used : CTColor(org.openxmlformats.schemas.drawingml.x2006.main.CTColor) Test(org.junit.Test)

Example 29 with CTColor

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

the class TestXSLFColor method testHSL.

@Test
public void testHSL() {
    CTColor xml = CTColor.Factory.newInstance();
    CTHslColor c = xml.addNewHslClr();
    c.setHue2(14400000);
    c.setSat2(100000);
    c.setLum2(50000);
    XSLFColor color = new XSLFColor(xml, null, null);
    assertEquals(Color.BLUE, color.getColor());
}
Also used : CTColor(org.openxmlformats.schemas.drawingml.x2006.main.CTColor) CTHslColor(org.openxmlformats.schemas.drawingml.x2006.main.CTHslColor) Test(org.junit.Test)

Example 30 with CTColor

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

the class XWPFRun method setColor.

/**
     * Set text color.
     *
     * @param rgbStr - the desired color, in the hex form "RRGGBB".
     */
public void setColor(String rgbStr) {
    CTRPr pr = run.isSetRPr() ? run.getRPr() : run.addNewRPr();
    CTColor color = pr.isSetColor() ? pr.getColor() : pr.addNewColor();
    color.setVal(rgbStr);
}
Also used : CTRPr(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRPr) CTColor(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTColor)

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