// default colors for theme-depending colors taken from ... (last post):\r
// https://social.technet.microsoft.com/Forums/windows/en-US/ac76cc56-6ff2-4778-b260-8141d7170a3b/windows-7-highlight-text-color-or-selected-text-color-in-aero\r
\r
+ // see ST_SystemColorVal for system color names\r
+ \r
/** The system-defined color of the active window's border. */\r
- ActiveBorder (0xffb4b4b4, 1, null),\r
+ ActiveBorder (0xffb4b4b4, 1, "activeBorder"),\r
/** The system-defined color of the background of the active window's title bar. */\r
- ActiveCaption (0xff99b4d1, 2, null),\r
+ ActiveCaption (0xff99b4d1, 2, "activeCaption"),\r
/** The system-defined color of the text in the active window's title bar. */\r
- ActiveCaptionText (0xff000000, 3, null),\r
+ ActiveCaptionText (0xff000000, 3, "captionText"),\r
/** The application workspace is the area in a multiple-document view that is not being occupied by documents. */\r
- AppWorkspace (0xffababab, 4, null),\r
+ AppWorkspace (0xffababab, 4, "appWorkspace"),\r
/** The system-defined face color of a 3-D element. */\r
- Control (0xfff0f0f0, 5, null),\r
+ Control (0xfff0f0f0, 5, "btnFace"),\r
/** The system-defined shadow color of a 3-D element. The shadow color is applied to parts of a 3-D element that face away from the light source. */\r
- ControlDark (0xff696969, 6, null),\r
+ ControlDark (0xff696969, 6, "btnShadow"),\r
/** The system-defined color that is the dark shadow color of a 3-D element. The dark shadow color is applied to the parts of a 3-D element that are the darkest color. */\r
- ControlDarkDark (0xff000000, 7, null),\r
+ ControlDarkDark (0xff000000, 7, "3dDkShadow"),\r
/** The system-defined color that is the light color of a 3-D element. The light color is applied to parts of a 3-D element that face the light source. */\r
- ControlLight (0xffe3e3e3, 8, null),\r
+ ControlLight (0xffe3e3e3, 8, "btnHighlight"),\r
/** The system-defined highlight color of a 3-D element. The highlight color is applied to the parts of a 3-D element that are the lightest color. */\r
- ControlLightLight (0xffe3e3e3, 9, null),\r
+ ControlLightLight (0xffe3e3e3, 9, "3dLight"),\r
/** The system-defined color of text in a 3-D element. */\r
- ControlText (0xff000000, 10, null),\r
+ ControlText (0xff000000, 10, "btnText"),\r
/** The system-defined color of the desktop. */\r
- Desktop (0xff000000, 11, null),\r
+ Desktop (0xff000000, 11, "background"),\r
/** The system-defined color of dimmed text. Items in a list that are disabled are displayed in dimmed text. */\r
- GrayText (0xff6d6d6d, 12, null),\r
+ GrayText (0xff6d6d6d, 12, "grayText"),\r
/** The system-defined color of the background of selected items. This includes selected menu items as well as selected text. */\r
- Highlight (0xff3399ff, 13, null),\r
+ Highlight (0xff3399ff, 13, "highlight"),\r
/** The system-defined color of the text of selected items. */\r
- HighlightText (0xffffffff, 14, null),\r
+ HighlightText (0xffffffff, 14, "highlightText"),\r
/** The system-defined color used to designate a hot-tracked item. Single-clicking a hot-tracked item executes the item. */\r
- HotTrack (0xff0066cc, 15, null),\r
+ HotTrack (0xff0066cc, 15, "hotLight"),\r
/** The system-defined color of an inactive window's border. */\r
- InactiveBorder (0xfff4f7fc, 16, null),\r
+ InactiveBorder (0xfff4f7fc, 16, "inactiveBorder"),\r
/** The system-defined color of the background of an inactive window's title bar. */\r
- InactiveCaption (0xffbfcddb, 17, null),\r
+ InactiveCaption (0xffbfcddb, 17, "inactiveCaption"),\r
/** The system-defined color of the text in an inactive window's title bar. */\r
- InactiveCaptionText (0xff000000, 18, null),\r
+ InactiveCaptionText (0xff000000, 18, "inactiveCaptionText"),\r
/** The system-defined color of the background of a ToolTip. */\r
- Info (0xffffffe1, 19, null),\r
+ Info (0xffffffe1, 19, "infoBk"),\r
/** The system-defined color of the text of a ToolTip. */\r
- InfoText (0xff000000, 20, null),\r
+ InfoText (0xff000000, 20, "infoText"),\r
/** The system-defined color of a menu's background. */\r
- Menu (0xfff0f0f0, 21, null),\r
+ Menu (0xfff0f0f0, 21, "menu"),\r
/** The system-defined color of a menu's text. */\r
- MenuText (0xff000000, 22, null),\r
+ MenuText (0xff000000, 22, "menuText"),\r
/** The system-defined color of the background of a scroll bar. */\r
- ScrollBar (0xffc8c8c8, 23, null),\r
+ ScrollBar (0xffc8c8c8, 23, "scrollBar"),\r
/** The system-defined color of the background in the client area of a window. */\r
- Window (0xffffffff, 24, null),\r
+ Window (0xffffffff, 24, "window"),\r
/** The system-defined color of a window frame. */\r
- WindowFrame (0xff646464, 25, null),\r
+ WindowFrame (0xff646464, 25, "windowFrame"),\r
/** The system-defined color of the text in the client area of a window. */\r
- WindowText (0xff000000, 26, null),\r
+ WindowText (0xff000000, 26, "windowText"),\r
Transparent (0x00ffffff, 27, null),\r
AliceBlue (0xfff0f8ff, 28, "aliceBlue"),\r
AntiqueWhite (0xfffaebd7, 29, "antiqueWhite"),\r
/** The system-defined color that is the shadow color of a 3-D element. This color is applied to parts of a 3-D element that face away from the light source. */\r
ButtonShadow (0xffa0a0a0, 170, null),\r
/** The system-defined color of the lightest color in the color gradient of an active window's title bar. */\r
- GradientActiveCaption (0xffb9d1ea, 171, null),\r
+ GradientActiveCaption (0xffb9d1ea, 171, "gradientActiveCaption"),\r
/** The system-defined color of the lightest color in the color gradient of an inactive window's title bar. */\r
- GradientInactiveCaption (0xffd7e4f2, 172, null),\r
+ GradientInactiveCaption (0xffd7e4f2, 172, "gradientInactiveCaption"),\r
/** The system-defined color of the background of a menu bar. */\r
- MenuBar (0xfff0f0f0, 173, null),\r
+ MenuBar (0xfff0f0f0, 173, "menuBar"),\r
/** The system-defined color used to highlight menu items when the menu appears as a flat menu. */\r
- MenuHighlight (0xff3399ff, 174, null)\r
+ MenuHighlight (0xff3399ff, 174, "menuHighlight")\r
;\r
\r
public Color color;\r
import org.apache.poi.sl.usermodel.PresetColor;\r
import org.apache.poi.util.Beta;\r
import org.apache.poi.util.Internal;\r
+import org.apache.poi.util.POILogFactory;\r
+import org.apache.poi.util.POILogger;\r
import org.apache.xmlbeans.XmlObject;\r
import org.openxmlformats.schemas.drawingml.x2006.main.CTColor;\r
import org.openxmlformats.schemas.drawingml.x2006.main.CTHslColor;\r
import org.openxmlformats.schemas.drawingml.x2006.main.CTSRgbColor;\r
import org.openxmlformats.schemas.drawingml.x2006.main.CTScRgbColor;\r
import org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor;\r
+import org.openxmlformats.schemas.drawingml.x2006.main.CTSolidColorFillProperties;\r
import org.openxmlformats.schemas.drawingml.x2006.main.CTSystemColor;\r
import org.w3c.dom.Node;\r
\r
/**\r
* Encapsulates logic to read color definitions from DrawingML and convert them to java.awt.Color\r
- *\r
- * @author Yegor Kozlov\r
*/\r
@Beta\r
@Internal\r
public class XSLFColor {\r
+ private static POILogger LOGGER = POILogFactory.getLogger(XSLFColor.class);\r
+ \r
private XmlObject _xmlObject;\r
private Color _color;\r
private CTSchemeColor _phClr;\r
byte[] val = sys.getLastClr();\r
color = new Color(0xFF & val[0], 0xFF & val[1], 0xFF & val[2]);\r
} else {\r
- // YK: color is a string like "menuText" or "windowText", we return black for such cases\r
- @SuppressWarnings("unused")\r
String colorName = sys.getVal().toString();\r
- color = Color.black;\r
+ PresetColor pc = PresetColor.valueOfOoxmlId(colorName);\r
+ if (pc != null) {\r
+ color = pc.color;\r
+ }\r
+ if (color == null) {\r
+ color = Color.black;\r
+ }\r
}\r
} else {\r
throw new IllegalArgumentException("Unexpected color choice: " + ch.getClass());\r
return color;\r
}\r
\r
+ /**\r
+ * Sets the solid color\r
+ *\r
+ * @param color solid color\r
+ */\r
+ @Internal\r
+ protected void setColor(Color color) {\r
+ if (!(_xmlObject instanceof CTSolidColorFillProperties)) {\r
+ LOGGER.log(POILogger.ERROR, "XSLFColor.setColor currently only supports CTSolidColorFillProperties");\r
+ return;\r
+ }\r
+ CTSolidColorFillProperties fill = (CTSolidColorFillProperties)_xmlObject;\r
+ if (fill.isSetSrgbClr()) {\r
+ fill.unsetSrgbClr();\r
+ }\r
+ \r
+ CTSRgbColor rgb = fill.addNewSrgbClr();\r
+ \r
+ float[] rgbaf = color.getRGBComponents(null);\r
+ int r = color.getRed(), g = color.getGreen(), b = color.getBlue();\r
+ if (rgbaf[0]*255f == r && rgbaf[1]*255f == g && rgbaf[2]*255f == b) {\r
+ rgb.setVal(new byte[]{(byte)r, (byte)g, (byte)b });\r
+ } else {\r
+ rgb.addNewRed().setVal((int)(100000 * rgbaf[0]));\r
+ rgb.addNewGreen().setVal((int)(100000 * rgbaf[1]));\r
+ rgb.addNewBlue().setVal((int)(100000 * rgbaf[2]));\r
+ }\r
+\r
+ // alpha (%)\r
+ if (rgbaf.length == 4 && rgbaf[3] < 1f) {\r
+ rgb.addNewAlpha().setVal((int)(100000 * rgbaf[3]));\r
+ }\r
+\r
+ if (fill.isSetHslClr()) {\r
+ fill.unsetHslClr();\r
+ }\r
+ \r
+ if (fill.isSetPrstClr()) {\r
+ fill.unsetPrstClr();\r
+ }\r
+ \r
+ if (fill.isSetSchemeClr()) {\r
+ fill.unsetSchemeClr();\r
+ }\r
+ \r
+ if (fill.isSetScrgbClr()) {\r
+ fill.unsetScrgbClr();\r
+ }\r
+ \r
+ if (fill.isSetSysClr()) {\r
+ fill.unsetSysClr();\r
+ }\r
+ }\r
+ \r
private int getRawValue(String elem) {\r
String query = "declare namespace a='http://schemas.openxmlformats.org/drawingml/2006/main' $this//a:" + elem;\r
\r
import org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D;\r
import org.openxmlformats.schemas.drawingml.x2006.main.CTPresetGeometry2D;\r
import org.openxmlformats.schemas.drawingml.x2006.main.CTPresetLineDashProperties;\r
-import org.openxmlformats.schemas.drawingml.x2006.main.CTSRgbColor;\r
import org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor;\r
import org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties;\r
import org.openxmlformats.schemas.drawingml.x2006.main.CTShapeStyle;\r
*/\r
public void setLineColor(Color color) {\r
CTShapeProperties spPr = getSpPr();\r
+ CTLineProperties ln = spPr.getLn();\r
if (color == null) {\r
- if (spPr.isSetLn() && spPr.getLn().isSetSolidFill())\r
- spPr.getLn().unsetSolidFill();\r
+ if (ln == null) {\r
+ return;\r
+ }\r
+ \r
+ if (ln.isSetSolidFill()) {\r
+ ln.unsetSolidFill();\r
+ }\r
+ \r
+ if (!ln.isSetNoFill()) {\r
+ ln.addNewNoFill();\r
+ }\r
} else {\r
- CTLineProperties ln = spPr.isSetLn() ? spPr.getLn() : spPr\r
- .addNewLn();\r
-\r
- CTSRgbColor rgb = CTSRgbColor.Factory.newInstance();\r
- rgb.setVal(new byte[]{(byte) color.getRed(),\r
- (byte) color.getGreen(), (byte) color.getBlue()});\r
+ if (ln == null) {\r
+ ln = spPr.addNewLn();\r
+ }\r
+ if (ln.isSetNoFill()) {\r
+ ln.unsetNoFill();\r
+ }\r
+ \r
+ CTSolidColorFillProperties fill = ln.isSetSolidFill() ? ln.getSolidFill() : ln.addNewSolidFill();\r
\r
- CTSolidColorFillProperties fill = ln.isSetSolidFill() ? ln\r
- .getSolidFill() : ln.addNewSolidFill();\r
- fill.setSrgbClr(rgb);\r
- if(fill.isSetHslClr()) fill.unsetHslClr();\r
- if(fill.isSetPrstClr()) fill.unsetPrstClr();\r
- if(fill.isSetSchemeClr()) fill.unsetSchemeClr();\r
- if(fill.isSetScrgbClr()) fill.unsetScrgbClr();\r
- if(fill.isSetSysClr()) fill.unsetSysClr();\r
+ XSLFColor col = new XSLFColor(fill, getSheet().getTheme(), fill.getSchemeClr());\r
+ col.setColor(color);\r
}\r
}\r
\r
public void setFillColor(Color color) {\r
CTShapeProperties spPr = getSpPr();\r
if (color == null) {\r
- if (spPr.isSetSolidFill()) spPr.unsetSolidFill();\r
+ if (spPr.isSetSolidFill()) {\r
+ spPr.unsetSolidFill();\r
+ }\r
\r
- if (!spPr.isSetNoFill()) spPr.addNewNoFill();\r
+ if (!spPr.isSetNoFill()) {\r
+ spPr.addNewNoFill();\r
+ }\r
} else {\r
- if (spPr.isSetNoFill()) spPr.unsetNoFill();\r
-\r
- CTSolidColorFillProperties fill = spPr.isSetSolidFill() ? spPr\r
- .getSolidFill() : spPr.addNewSolidFill();\r
-\r
- CTSRgbColor rgb = CTSRgbColor.Factory.newInstance();\r
- rgb.setVal(new byte[]{(byte) color.getRed(),\r
- (byte) color.getGreen(), (byte) color.getBlue()});\r
+ if (spPr.isSetNoFill()) {\r
+ spPr.unsetNoFill();\r
+ }\r
\r
- fill.setSrgbClr(rgb);\r
- if(fill.isSetHslClr()) fill.unsetHslClr();\r
- if(fill.isSetPrstClr()) fill.unsetPrstClr();\r
- if(fill.isSetSchemeClr()) fill.unsetSchemeClr();\r
- if(fill.isSetScrgbClr()) fill.unsetScrgbClr();\r
- if(fill.isSetSysClr()) fill.unsetSysClr();\r
+ CTSolidColorFillProperties fill = spPr.isSetSolidFill() ? spPr.getSolidFill() : spPr.addNewSolidFill();\r
+ \r
+ XSLFColor col = new XSLFColor(fill, getSheet().getTheme(), fill.getSchemeClr());\r
+ col.setColor(color);\r
}\r
}\r
\r
throw new IllegalArgumentException("Currently only SolidPaint is supported!");\r
}\r
SolidPaint sp = (SolidPaint)color;\r
+ Color c = DrawPaint.applyColorTransform(sp.getSolidColor());\r
\r
CTTextCharacterProperties rPr = getRPr();\r
CTSolidColorFillProperties fill = rPr.isSetSolidFill() ? rPr.getSolidFill() : rPr.addNewSolidFill();\r
- CTSRgbColor clr = fill.isSetSrgbClr() ? fill.getSrgbClr() : fill.addNewSrgbClr();\r
- Color c = DrawPaint.applyColorTransform(sp.getSolidColor());\r
- clr.setVal(new byte[]{(byte)c.getRed(), (byte)c.getGreen(), (byte)c.getBlue()});\r
-\r
- if(fill.isSetHslClr()) fill.unsetHslClr();\r
- if(fill.isSetPrstClr()) fill.unsetPrstClr();\r
- if(fill.isSetSchemeClr()) fill.unsetSchemeClr();\r
- if(fill.isSetScrgbClr()) fill.unsetScrgbClr();\r
- if(fill.isSetSysClr()) fill.unsetSysClr();\r
-\r
+ \r
+ XSLFColor col = new XSLFColor(fill, getParentParagraph().getParentShape().getSheet().getTheme(), fill.getSchemeClr());\r
+ col.setColor(c);\r
}\r
\r
@Override\r
==================================================================== */
package org.apache.poi.xslf;
-import static junit.framework.TestCase.assertEquals;
import static org.apache.poi.POITestCase.assertContains;
import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import org.apache.poi.POIDataSamples;
import org.apache.poi.POIXMLDocumentPart;
import org.apache.poi.POIXMLDocumentPart.RelationPart;
+import org.apache.poi.sl.usermodel.PaintStyle.SolidPaint;
import org.apache.poi.sl.usermodel.PictureData;
import org.apache.poi.sl.usermodel.PictureData.PictureType;
+import org.apache.poi.sl.usermodel.ShapeType;
import org.apache.poi.xslf.usermodel.DrawingParagraph;
import org.apache.poi.xslf.usermodel.DrawingTextBody;
import org.apache.poi.xslf.usermodel.XMLSlideShow;
+import org.apache.poi.xslf.usermodel.XSLFAutoShape;
import org.apache.poi.xslf.usermodel.XSLFHyperlink;
import org.apache.poi.xslf.usermodel.XSLFPictureData;
import org.apache.poi.xslf.usermodel.XSLFPictureShape;
ppt2.close();
}
+
+ @Test
+ public void bug58217() throws IOException {
+ XMLSlideShow ppt1 = new XMLSlideShow();
+ XSLFSlide sl = ppt1.createSlide();
+ XSLFAutoShape as = sl.createAutoShape();
+ as.setShapeType(ShapeType.STAR_10);
+ as.setAnchor(new Rectangle2D.Double(100,100,300,300));
+ as.setFillColor(new Color(1f,1f,0f,0.1f));
+ as.setLineColor(new Color(1f,1f,0f,0.4f));
+ as.setText("Alpha");
+ as.getTextParagraphs().get(0).getTextRuns().get(0).setFontColor(new Color(1f,1f,0f,0.6f));
+ XMLSlideShow ppt2 = XSLFTestDataSamples.writeOutAndReadBack(ppt1);
+ ppt1.close();
+ sl = ppt2.getSlides().get(0);
+ as = (XSLFAutoShape)sl.getShapes().get(0);
+ SolidPaint ps = (SolidPaint)as.getFillStyle().getPaint();
+ assertEquals(10000, ps.getSolidColor().getAlpha());
+ ps = (SolidPaint)as.getStrokeStyle().getPaint();
+ assertEquals(40000, ps.getSolidColor().getAlpha());
+ ps = (SolidPaint)as.getTextParagraphs().get(0).getTextRuns().get(0).getFontColor();
+ assertEquals(60000, ps.getSolidColor().getAlpha());
+ ppt2.close();
+ }
}
package org.apache.poi.xslf.usermodel;\r
\r
import static org.junit.Assert.assertEquals;\r
-import static org.junit.Assert.assertNotNull;\r
+import static org.junit.Assert.assertTrue;\r
\r
import java.awt.Color;\r
import java.io.IOException;\r
for(PresetColor pc : PresetColor.values()) {\r
if (pc.ooxmlId == null) continue;\r
xml = CTColor.Factory.newInstance();\r
- STPresetColorVal.Enum val = STPresetColorVal.Enum.forString(pc.ooxmlId);\r
- assertNotNull(pc.ooxmlId, val);\r
- xml.addNewPrstClr().setVal(val);\r
+ STPresetColorVal.Enum preVal = STPresetColorVal.Enum.forString(pc.ooxmlId);\r
+ STSystemColorVal.Enum sysVal = STSystemColorVal.Enum.forString(pc.ooxmlId);\r
+ assertTrue(pc.ooxmlId, preVal != null || sysVal != null);\r
+ if (preVal != null) {\r
+ xml.addNewPrstClr().setVal(preVal);\r
+ } else {\r
+ xml.addNewSysClr().setVal(sysVal);\r
+ }\r
color = new XSLFColor(xml, null, null);\r
assertEquals(pc.color, color.getColor());\r
}\r
public void testSys() {\r
CTColor xml = CTColor.Factory.newInstance();\r
CTSystemColor sys = xml.addNewSysClr();\r
- sys.setVal(STSystemColorVal.GRAY_TEXT);\r
+ sys.setVal(STSystemColorVal.CAPTION_TEXT);\r
XSLFColor color = new XSLFColor(xml, null, null);\r
assertEquals(Color.black, color.getColor());\r
\r