use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor 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);
}
}
use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor in project poi by apache.
the class XSSFRichTextString method setRunAttributes.
/**
* Copy font attributes from CTFont bean into CTRPrElt bean
*/
private void setRunAttributes(CTFont ctFont, CTRPrElt pr) {
if (ctFont.sizeOfBArray() > 0)
pr.addNewB().setVal(ctFont.getBArray(0).getVal());
if (ctFont.sizeOfUArray() > 0)
pr.addNewU().setVal(ctFont.getUArray(0).getVal());
if (ctFont.sizeOfIArray() > 0)
pr.addNewI().setVal(ctFont.getIArray(0).getVal());
if (ctFont.sizeOfColorArray() > 0) {
CTColor c1 = ctFont.getColorArray(0);
CTColor c2 = pr.addNewColor();
if (c1.isSetAuto())
c2.setAuto(c1.getAuto());
if (c1.isSetIndexed())
c2.setIndexed(c1.getIndexed());
if (c1.isSetRgb())
c2.setRgb(c1.getRgb());
if (c1.isSetTheme())
c2.setTheme(c1.getTheme());
if (c1.isSetTint())
c2.setTint(c1.getTint());
}
if (ctFont.sizeOfSzArray() > 0)
pr.addNewSz().setVal(ctFont.getSzArray(0).getVal());
if (ctFont.sizeOfNameArray() > 0)
pr.addNewRFont().setVal(ctFont.getNameArray(0).getVal());
if (ctFont.sizeOfFamilyArray() > 0)
pr.addNewFamily().setVal(ctFont.getFamilyArray(0).getVal());
if (ctFont.sizeOfSchemeArray() > 0)
pr.addNewScheme().setVal(ctFont.getSchemeArray(0).getVal());
if (ctFont.sizeOfCharsetArray() > 0)
pr.addNewCharset().setVal(ctFont.getCharsetArray(0).getVal());
if (ctFont.sizeOfCondenseArray() > 0)
pr.addNewCondense().setVal(ctFont.getCondenseArray(0).getVal());
if (ctFont.sizeOfExtendArray() > 0)
pr.addNewExtend().setVal(ctFont.getExtendArray(0).getVal());
if (ctFont.sizeOfVertAlignArray() > 0)
pr.addNewVertAlign().setVal(ctFont.getVertAlignArray(0).getVal());
if (ctFont.sizeOfOutlineArray() > 0)
pr.addNewOutline().setVal(ctFont.getOutlineArray(0).getVal());
if (ctFont.sizeOfShadowArray() > 0)
pr.addNewShadow().setVal(ctFont.getShadowArray(0).getVal());
if (ctFont.sizeOfStrikeArray() > 0)
pr.addNewStrike().setVal(ctFont.getStrikeArray(0).getVal());
}
use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor in project poi by apache.
the class XSSFRichTextString method toCTFont.
/**
*
* CTRPrElt --> CTFont adapter
*/
protected static CTFont toCTFont(CTRPrElt pr) {
CTFont ctFont = CTFont.Factory.newInstance();
// Bug 58315: there are files where there is no pr-entry for a RichTextString
if (pr == null) {
return ctFont;
}
if (pr.sizeOfBArray() > 0)
ctFont.addNewB().setVal(pr.getBArray(0).getVal());
if (pr.sizeOfUArray() > 0)
ctFont.addNewU().setVal(pr.getUArray(0).getVal());
if (pr.sizeOfIArray() > 0)
ctFont.addNewI().setVal(pr.getIArray(0).getVal());
if (pr.sizeOfColorArray() > 0) {
CTColor c1 = pr.getColorArray(0);
CTColor c2 = ctFont.addNewColor();
if (c1.isSetAuto())
c2.setAuto(c1.getAuto());
if (c1.isSetIndexed())
c2.setIndexed(c1.getIndexed());
if (c1.isSetRgb())
c2.setRgb(c1.getRgb());
if (c1.isSetTheme())
c2.setTheme(c1.getTheme());
if (c1.isSetTint())
c2.setTint(c1.getTint());
}
if (pr.sizeOfSzArray() > 0)
ctFont.addNewSz().setVal(pr.getSzArray(0).getVal());
if (pr.sizeOfRFontArray() > 0)
ctFont.addNewName().setVal(pr.getRFontArray(0).getVal());
if (pr.sizeOfFamilyArray() > 0)
ctFont.addNewFamily().setVal(pr.getFamilyArray(0).getVal());
if (pr.sizeOfSchemeArray() > 0)
ctFont.addNewScheme().setVal(pr.getSchemeArray(0).getVal());
if (pr.sizeOfCharsetArray() > 0)
ctFont.addNewCharset().setVal(pr.getCharsetArray(0).getVal());
if (pr.sizeOfCondenseArray() > 0)
ctFont.addNewCondense().setVal(pr.getCondenseArray(0).getVal());
if (pr.sizeOfExtendArray() > 0)
ctFont.addNewExtend().setVal(pr.getExtendArray(0).getVal());
if (pr.sizeOfVertAlignArray() > 0)
ctFont.addNewVertAlign().setVal(pr.getVertAlignArray(0).getVal());
if (pr.sizeOfOutlineArray() > 0)
ctFont.addNewOutline().setVal(pr.getOutlineArray(0).getVal());
if (pr.sizeOfShadowArray() > 0)
ctFont.addNewShadow().setVal(pr.getShadowArray(0).getVal());
if (pr.sizeOfStrikeArray() > 0)
ctFont.addNewStrike().setVal(pr.getStrikeArray(0).getVal());
return ctFont;
}
use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor 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