use of org.openxmlformats.schemas.drawingml.x2006.main.CTHslColor 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());
}
use of org.openxmlformats.schemas.drawingml.x2006.main.CTHslColor 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;
}
Aggregations