*/\r
public SysIndexProcedure getSysIndexProcedure() {\r
if (!hasSysIndexFlag()) return null;\r
- int val = FLAG_RED.getValue(colorRef);\r
+ int val = FLAG_GREEN.getValue(colorRef);\r
for (SysIndexProcedure sip : SysIndexProcedure.values()) {\r
if (sip == SysIndexProcedure.INVERT_AFTER || sip == SysIndexProcedure.INVERT_HIGHBIT_AFTER) continue;\r
if (sip.mask.isSet(val)) return sip;\r
* @return index of current palette (color) or -1 if {@link #hasPaletteIndexFlag()} is {@code false}\r
*/\r
public int getPaletteIndex() {\r
- if (!hasPaletteIndexFlag()) return -1;\r
- return (FLAG_GREEN.getValue(colorRef) << 8) & FLAG_RED.getValue(colorRef);\r
+ return (hasPaletteIndexFlag()) ? getIndex() : -1;\r
+ }\r
+\r
+ /**\r
+ * @return index of system color table or -1 if {@link #hasSysIndexFlag()} is {@code false}\r
+ * \r
+ * @see org.apache.poi.sl.usermodel.PresetColor\r
+ */\r
+ public int getSysIndex() {\r
+ return (hasSysIndexFlag()) ? getIndex() : -1;\r
+ }\r
+ \r
+ private int getIndex() {\r
+ return (FLAG_GREEN.getValue(colorRef) << 8) | FLAG_RED.getValue(colorRef);\r
}\r
}\r
}\r
\r
// first dry-run to calculate the total height of the text\r
- double textHeight = s.getTextHeight();\r
+ double textHeight = getTextHeight(graphics);\r
\r
switch (s.getVerticalAlignment()){\r
default:\r
\r
/**\r
* Compute the cumulative height occupied by the text\r
+ * \r
+ * @return the height in points\r
*/\r
- public double getTextHeight(){\r
+ public double getTextHeight() {\r
+ return getTextHeight(null);\r
+ }\r
+ \r
+ /**\r
+ * Compute the cumulative height occupied by the text\r
+ *\r
+ * @param oldGraphics the graphics context, which properties are to be copied, may be null\r
+ * @return the height in points\r
+ */\r
+ protected double getTextHeight(Graphics2D oldGraphics) {\r
// dry-run in a 1x1 image and return the vertical advance\r
BufferedImage img = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);\r
Graphics2D graphics = img.createGraphics();\r
+ if (oldGraphics != null) {\r
+ graphics.addRenderingHints(oldGraphics.getRenderingHints());\r
+ graphics.setTransform(oldGraphics.getTransform());\r
+ }\r
DrawFactory.getInstance(graphics).fixFonts(graphics);\r
return drawParagraphs(graphics, 0, 0);\r
}\r
\r
// determine transparency\r
boolean opaque = true;\r
- for (int i = 0; i < colors.length; i++){\r
- opaque = opaque && (colors[i].getAlpha() == 0xff);\r
+ for (Color c : colors) {\r
+ if (c != null) {\r
+ opaque = opaque && (c.getAlpha() == 0xff);\r
+ }\r
}\r
this.transparency = opaque ? OPAQUE : TRANSLUCENT;\r
}\r
--- /dev/null
+/*\r
+ * ====================================================================\r
+ * Licensed to the Apache Software Foundation (ASF) under one or more\r
+ * contributor license agreements. See the NOTICE file distributed with\r
+ * this work for additional information regarding copyright ownership.\r
+ * The ASF licenses this file to You under the Apache License, Version 2.0\r
+ * (the "License"); you may not use this file except in compliance with\r
+ * the License. You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ====================================================================\r
+ */\r
+\r
+package org.apache.poi.sl.usermodel;\r
+\r
+import java.awt.Color;\r
+import java.util.HashMap;\r
+import java.util.Map;\r
+\r
+/**\r
+ * Preset colors defined in DrawingML aka known/system colors\r
+ * \r
+ * @see <a href="https://msdn.microsoft.com/library/system.drawing.knowncolor.aspx">KnownColor Enumeration</a>\r
+ * @see <a href="https://msdn.microsoft.com/library/system.windows.media.colors.aspx">Colors Class</a>\r
+ */\r
+public enum PresetColor {\r
+ // the order of this enum can be found in the definition of .net System.Drawing.KnownColor enumeration\r
+ // or by running the the program in the linked documentation\r
+ \r
+ // 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
+ /** The system-defined color of the active window's border. */\r
+ ActiveBorder (0xffb4b4b4, 1, null),\r
+ /** The system-defined color of the background of the active window's title bar. */\r
+ ActiveCaption (0xff99b4d1, 2, null),\r
+ /** The system-defined color of the text in the active window's title bar. */\r
+ ActiveCaptionText (0xff000000, 3, null),\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
+ /** The system-defined face color of a 3-D element. */\r
+ Control (0xfff0f0f0, 5, null),\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
+ /** 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
+ /** 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
+ /** 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
+ /** The system-defined color of text in a 3-D element. */\r
+ ControlText (0xff000000, 10, null),\r
+ /** The system-defined color of the desktop. */\r
+ Desktop (0xff000000, 11, null),\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
+ /** 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
+ /** The system-defined color of the text of selected items. */\r
+ HighlightText (0xffffffff, 14, null),\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
+ /** The system-defined color of an inactive window's border. */\r
+ InactiveBorder (0xfff4f7fc, 16, null),\r
+ /** The system-defined color of the background of an inactive window's title bar. */\r
+ InactiveCaption (0xffbfcddb, 17, null),\r
+ /** The system-defined color of the text in an inactive window's title bar. */\r
+ InactiveCaptionText (0xff000000, 18, null),\r
+ /** The system-defined color of the background of a ToolTip. */\r
+ Info (0xffffffe1, 19, null),\r
+ /** The system-defined color of the text of a ToolTip. */\r
+ InfoText (0xff000000, 20, null),\r
+ /** The system-defined color of a menu's background. */\r
+ Menu (0xfff0f0f0, 21, null),\r
+ /** The system-defined color of a menu's text. */\r
+ MenuText (0xff000000, 22, null),\r
+ /** The system-defined color of the background of a scroll bar. */\r
+ ScrollBar (0xffc8c8c8, 23, null),\r
+ /** The system-defined color of the background in the client area of a window. */\r
+ Window (0xffffffff, 24, null),\r
+ /** The system-defined color of a window frame. */\r
+ WindowFrame (0xff646464, 25, null),\r
+ /** The system-defined color of the text in the client area of a window. */\r
+ WindowText (0xff000000, 26, null),\r
+ Transparent (0x00ffffff, 27, null),\r
+ AliceBlue (0xfff0f8ff, 28, "aliceBlue"),\r
+ AntiqueWhite (0xfffaebd7, 29, "antiqueWhite"),\r
+ Aqua (0xff00ffff, 30, "aqua"),\r
+ Aquamarine (0xff7fffd4, 31, "aquamarine"),\r
+ Azure (0xfff0ffff, 32, "azure"),\r
+ Beige (0xfff5f5dc, 33, "beige"),\r
+ Bisque (0xffffe4c4, 34, "bisque"),\r
+ Black (0xff000000, 35, "black"),\r
+ BlanchedAlmond (0xffffebcd, 36, "blanchedAlmond"),\r
+ Blue (0xff0000ff, 37, "blue"),\r
+ BlueViolet (0xff8a2be2, 38, "blueViolet"),\r
+ Brown (0xffa52a2a, 39, "brown"),\r
+ BurlyWood (0xffdeb887, 40, "burlyWood"),\r
+ CadetBlue (0xff5f9ea0, 41, "cadetBlue"),\r
+ Chartreuse (0xff7fff00, 42, "chartreuse"),\r
+ Chocolate (0xffd2691e, 43, "chocolate"),\r
+ Coral (0xffff7f50, 44, "coral"),\r
+ CornflowerBlue (0xff6495ed, 45, "cornflowerBlue"),\r
+ Cornsilk (0xfffff8dc, 46, "cornsilk"),\r
+ Crimson (0xffdc143c, 47, "crimson"),\r
+ Cyan (0xff00ffff, 48, "cyan"),\r
+ DarkBlue (0xff00008b, 49, "dkBlue"),\r
+ DarkCyan (0xff008b8b, 50, "dkCyan"),\r
+ DarkGoldenrod (0xffb8860b, 51, "dkGoldenrod"),\r
+ DarkGray (0xffa9a9a9, 52, "dkGray"),\r
+ DarkGreen (0xff006400, 53, "dkGreen"),\r
+ DarkKhaki (0xffbdb76b, 54, "dkKhaki"),\r
+ DarkMagenta (0xff8b008b, 55, "dkMagenta"),\r
+ DarkOliveGreen (0xff556b2f, 56, "dkOliveGreen"),\r
+ DarkOrange (0xffff8c00, 57, "dkOrange"),\r
+ DarkOrchid (0xff9932cc, 58, "dkOrchid"),\r
+ DarkRed (0xff8b0000, 59, "dkRed"),\r
+ DarkSalmon (0xffe9967a, 60, "dkSalmon"),\r
+ DarkSeaGreen (0xff8fbc8b, 61, "dkSeaGreen"),\r
+ DarkSlateBlue (0xff483d8b, 62, "dkSlateBlue"),\r
+ DarkSlateGray (0xff2f4f4f, 63, "dkSlateGray"),\r
+ DarkTurquoise (0xff00ced1, 64, "dkTurquoise"),\r
+ DarkViolet (0xff9400d3, 65, "dkViolet"),\r
+ DeepPink (0xffff1493, 66, "deepPink"),\r
+ DeepSkyBlue (0xff00bfff, 67, "deepSkyBlue"),\r
+ DimGray (0xff696969, 68, "dimGray"),\r
+ DodgerBlue (0xff1e90ff, 69, "dodgerBlue"),\r
+ Firebrick (0xffb22222, 70, "firebrick"),\r
+ FloralWhite (0xfffffaf0, 71, "floralWhite"),\r
+ ForestGreen (0xff228b22, 72, "forestGreen"),\r
+ Fuchsia (0xffff00ff, 73, "fuchsia"),\r
+ Gainsboro (0xffdcdcdc, 74, "gainsboro"),\r
+ GhostWhite (0xfff8f8ff, 75, "ghostWhite"),\r
+ Gold (0xffffd700, 76, "gold"),\r
+ Goldenrod (0xffdaa520, 77, "goldenrod"),\r
+ Gray (0xff808080, 78, "gray"),\r
+ Green (0xff008000, 79, "green"),\r
+ GreenYellow (0xffadff2f, 80, "greenYellow"),\r
+ Honeydew (0xfff0fff0, 81, "honeydew"),\r
+ HotPink (0xffff69b4, 82, "hotPink"),\r
+ IndianRed (0xffcd5c5c, 83, "indianRed"),\r
+ Indigo (0xff4b0082, 84, "indigo"),\r
+ Ivory (0xfffffff0, 85, "ivory"),\r
+ Khaki (0xfff0e68c, 86, "khaki"),\r
+ Lavender (0xffe6e6fa, 87, "lavender"),\r
+ LavenderBlush (0xfffff0f5, 88, "lavenderBlush"),\r
+ LawnGreen (0xff7cfc00, 89, "lawnGreen"),\r
+ LemonChiffon (0xfffffacd, 90, "lemonChiffon"),\r
+ LightBlue (0xffadd8e6, 91, "ltBlue"),\r
+ LightCoral (0xfff08080, 92, "ltCoral"),\r
+ LightCyan (0xffe0ffff, 93, "ltCyan"),\r
+ LightGoldenrodYellow (0xfffafa78, 94, "ltGoldenrodYellow"),\r
+ LightGray (0xffd3d3d3, 95, "ltGray"),\r
+ LightGreen (0xff90ee90, 96, "ltGreen"),\r
+ LightPink (0xffffb6c1, 97, "ltPink"),\r
+ LightSalmon (0xffffa07a, 98, "ltSalmon"),\r
+ LightSeaGreen (0xff20b2aa, 99, "ltSeaGreen"),\r
+ LightSkyBlue (0xff87cefa, 100, "ltSkyBlue"),\r
+ LightSlateGray (0xff778899, 101, "ltSlateGray"),\r
+ LightSteelBlue (0xffb0c4de, 102, "ltSteelBlue"),\r
+ LightYellow (0xffffffe0, 103, "ltYellow"),\r
+ Lime (0xff00ff00, 104, "lime"),\r
+ LimeGreen (0xff32cd32, 105, "limeGreen"),\r
+ Linen (0xfffaf0e6, 106, "linen"),\r
+ Magenta (0xffff00ff, 107, "magenta"),\r
+ Maroon (0xff800000, 108, "maroon"),\r
+ MediumAquamarine (0xff66cdaa, 109, "medAquamarine"),\r
+ MediumBlue (0xff0000cd, 110, "medBlue"),\r
+ MediumOrchid (0xffba55d3, 111, "medOrchid"),\r
+ MediumPurple (0xff9370db, 112, "medPurple"),\r
+ MediumSeaGreen (0xff3cb371, 113, "medSeaGreen"),\r
+ MediumSlateBlue (0xff7b68ee, 114, "medSlateBlue"),\r
+ MediumSpringGreen (0xff00fa9a, 115, "medSpringGreen"),\r
+ MediumTurquoise (0xff48d1cc, 116, "medTurquoise"),\r
+ MediumVioletRed (0xffc71585, 117, "medVioletRed"),\r
+ MidnightBlue (0xff191970, 118, "midnightBlue"),\r
+ MintCream (0xfff5fffa, 119, "mintCream"),\r
+ MistyRose (0xffffe4e1, 120, "mistyRose"),\r
+ Moccasin (0xffffe4b5, 121, "moccasin"),\r
+ NavajoWhite (0xffffdead, 122, "navajoWhite"),\r
+ Navy (0xff000080, 123, "navy"),\r
+ OldLace (0xfffdf5e6, 124, "oldLace"),\r
+ Olive (0xff808000, 125, "olive"),\r
+ OliveDrab (0xff6b8e23, 126, "oliveDrab"),\r
+ Orange (0xffffa500, 127, "orange"),\r
+ OrangeRed (0xffff4500, 128, "orangeRed"),\r
+ Orchid (0xffda70d6, 129, "orchid"),\r
+ PaleGoldenrod (0xffeee8aa, 130, "paleGoldenrod"),\r
+ PaleGreen (0xff98fb98, 131, "paleGreen"),\r
+ PaleTurquoise (0xffafeeee, 132, "paleTurquoise"),\r
+ PaleVioletRed (0xffdb7093, 133, "paleVioletRed"),\r
+ PapayaWhip (0xffffefd5, 134, "papayaWhip"),\r
+ PeachPuff (0xffffdab9, 135, "peachPuff"),\r
+ Peru (0xffcd853f, 136, "peru"),\r
+ Pink (0xffffc0cb, 137, "pink"),\r
+ Plum (0xffdda0dd, 138, "plum"),\r
+ PowderBlue (0xffb0e0e6, 139, "powderBlue"),\r
+ Purple (0xff800080, 140, "purple"),\r
+ Red (0xffff0000, 141, "red"),\r
+ RosyBrown (0xffbc8f8f, 142, "rosyBrown"),\r
+ RoyalBlue (0xff4169e1, 143, "royalBlue"),\r
+ SaddleBrown (0xff8b4513, 144, "saddleBrown"),\r
+ Salmon (0xfffa8072, 145, "salmon"),\r
+ SandyBrown (0xfff4a460, 146, "sandyBrown"),\r
+ SeaGreen (0xff2e8b57, 147, "seaGreen"),\r
+ SeaShell (0xfffff5ee, 148, "seaShell"),\r
+ Sienna (0xffa0522d, 149, "sienna"),\r
+ Silver (0xffc0c0c0, 150, "silver"),\r
+ SkyBlue (0xff87ceeb, 151, "skyBlue"),\r
+ SlateBlue (0xff6a5acd, 152, "slateBlue"),\r
+ SlateGray (0xff708090, 153, "slateGray"),\r
+ Snow (0xfffffafa, 154, "snow"),\r
+ SpringGreen (0xff00ff7f, 155, "springGreen"),\r
+ SteelBlue (0xff4682b4, 156, "steelBlue"),\r
+ Tan (0xffd2b48c, 157, "tan"),\r
+ Teal (0xff008080, 158, "teal"),\r
+ Thistle (0xffd8bfd8, 159, "thistle"),\r
+ Tomato (0xffff6347, 160, "tomato"),\r
+ Turquoise (0xff40e0d0, 161, "turquoise"),\r
+ Violet (0xffee82ee, 162, "violet"),\r
+ Wheat (0xfff5deb3, 163, "wheat"),\r
+ White (0xffffffff, 164, "white"),\r
+ WhiteSmoke (0xfff5f5f5, 165, "whiteSmoke"),\r
+ Yellow (0xffffff00, 166, "yellow"),\r
+ YellowGreen (0xff9acd32, 167, "yellowGreen"),\r
+ /** The system-defined face color of a 3-D element. */\r
+ ButtonFace (0xfff0f0f0, 168, null),\r
+ /** The system-defined color that is the highlight color of a 3-D element. This color is applied to parts of a 3-D element that face the light source. */\r
+ ButtonHighlight (0xffffffff, 169, null),\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
+ /** 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
+ /** The system-defined color of the background of a menu bar. */\r
+ MenuBar (0xfff0f0f0, 173, null),\r
+ /** The system-defined color used to highlight menu items when the menu appears as a flat menu. */\r
+ MenuHighlight (0xff3399ff, 174, null)\r
+ ;\r
+\r
+ public Color color;\r
+ public int nativeId;\r
+ public String ooxmlId;\r
+\r
+ PresetColor(Integer rgb, int nativeId, String ooxmlId) {\r
+ this.color = (rgb == null) ? null : new Color(rgb, true);\r
+ this.nativeId = nativeId;\r
+ this.ooxmlId = ooxmlId;\r
+ }\r
+\r
+ private static final Map<String,PresetColor> lookupOoxmlId;\r
+\r
+ static {\r
+ lookupOoxmlId = new HashMap<String,PresetColor>();\r
+ for(PresetColor pc : PresetColor.values()) {\r
+ if (pc.ooxmlId != null) {\r
+ lookupOoxmlId.put(pc.ooxmlId, pc);\r
+ }\r
+ }\r
+ }\r
+ \r
+ public static PresetColor valueOfOoxmlId(String ooxmlId) {\r
+ return lookupOoxmlId.get(ooxmlId);\r
+ }\r
+ \r
+ public static PresetColor valueOfNativeId(int nativeId) {\r
+ PresetColor vals[] = values();\r
+ return (0 < nativeId && nativeId <= vals.length) ? vals[nativeId-1] : null;\r
+ }\r
+}\r
\r
package org.apache.poi.sl.usermodel;\r
\r
+import java.awt.Graphics2D;\r
import java.util.List;\r
\r
public interface TextShape<\r
* Compute the cumulative height occupied by the text\r
*/\r
double getTextHeight();\r
-\r
+ \r
/**\r
* Returns the type of vertical alignment for the text.\r
*\r
* @see <a href="http://msdn.microsoft.com/en-us/library/dd910765(v=office.12).aspx">[MS-OSHARED] - 2.2.1.6 FixedPoint</a>\r
*/\r
public static int doubleToFixedPoint(double floatPoint) {\r
- int i = (int)Math.floor(floatPoint);\r
- int f = (int)((floatPoint % 1d)*65536d);\r
+ double fractionalPart = floatPoint % 1d;\r
+ double integralPart = floatPoint - fractionalPart;\r
+ int i = (int)Math.floor(integralPart);\r
+ int f = (int)Math.rint(fractionalPart*65536d);\r
int fixedPoint = (i << 16) | (f & 0xFFFF);\r
return fixedPoint;\r
}\r
package org.apache.poi.xslf.usermodel;\r
\r
import java.awt.Color;\r
-import java.util.HashMap;\r
-import java.util.Map;\r
\r
import org.apache.poi.sl.draw.DrawPaint;\r
import org.apache.poi.sl.usermodel.ColorStyle;\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.xmlbeans.XmlObject;\r
} else if (ch instanceof CTPresetColor) {\r
CTPresetColor prst = (CTPresetColor)ch;\r
String colorName = prst.getVal().toString();\r
- color = presetColors.get(colorName);\r
+ PresetColor pc = PresetColor.valueOfOoxmlId(colorName);\r
+ if (pc != null) {\r
+ color = pc.color;\r
+ }\r
} else if (ch instanceof CTSchemeColor) {\r
CTSchemeColor schemeColor = (CTSchemeColor)ch;\r
String colorRef = schemeColor.getVal().toString();\r
public int getTint(){\r
return getPercentageValue("tint");\r
}\r
-\r
-\r
- /**\r
- * Preset colors defined in DrawingML\r
- */\r
- static final Map<String, Color> presetColors;\r
-\r
- static {\r
- presetColors = new HashMap<String, Color>(); \r
- presetColors.put("aliceBlue", new Color(240, 248, 255));\r
- presetColors.put("antiqueWhite", new Color(250, 235, 215));\r
- presetColors.put("aqua", new Color(0, 255, 255));\r
- presetColors.put("aquamarine", new Color(127, 255, 212));\r
- presetColors.put("azure", new Color(240, 255, 255));\r
- presetColors.put("beige", new Color(245, 245, 220));\r
- presetColors.put("bisque", new Color(255, 228, 196));\r
- presetColors.put("black", new Color(0, 0, 0));\r
- presetColors.put("blanchedAlmond", new Color(255, 235, 205));\r
- presetColors.put("blue", new Color(0, 0, 255));\r
- presetColors.put("blueViolet", new Color(138, 43, 226));\r
- presetColors.put("brown", new Color(165, 42, 42));\r
- presetColors.put("burlyWood", new Color(222, 184, 135));\r
- presetColors.put("cadetBlue", new Color(95, 158, 160));\r
- presetColors.put("chartreuse", new Color(127, 255, 0));\r
- presetColors.put("chocolate", new Color(210, 105, 30));\r
- presetColors.put("coral", new Color(255, 127, 80));\r
- presetColors.put("cornflowerBlue", new Color(100, 149, 237));\r
- presetColors.put("crimson", new Color(220, 20, 60));\r
- presetColors.put("cyan", new Color(0, 255, 255));\r
- presetColors.put("deepPink", new Color(255, 20, 147));\r
- presetColors.put("deepSkyBlue", new Color(0, 191, 255));\r
- presetColors.put("dimGray", new Color(105, 105, 105));\r
- presetColors.put("dkBlue", new Color(0, 0, 139));\r
- presetColors.put("dkCyan", new Color(0, 139, 139));\r
- presetColors.put("dkGoldenrod", new Color(184, 134, 11));\r
- presetColors.put("dkGray", new Color(169, 169, 169));\r
- presetColors.put("dkGreen", new Color(0, 100, 0));\r
- presetColors.put("dkKhaki", new Color(189, 183, 107));\r
- presetColors.put("dkMagenta", new Color(139, 0, 139));\r
- presetColors.put("dkOliveGreen", new Color(85, 107, 47));\r
- presetColors.put("dkOrange", new Color(255, 140, 0));\r
- presetColors.put("dkOrchid", new Color(153, 50, 204));\r
- presetColors.put("dkRed", new Color(139, 0, 0));\r
- presetColors.put("dkSalmon", new Color(233, 150, 122));\r
- presetColors.put("dkSeaGreen", new Color(143, 188, 139));\r
- presetColors.put("dkSlateBlue", new Color(72, 61, 139));\r
- presetColors.put("dkSlateGray", new Color(47, 79, 79));\r
- presetColors.put("dkTurquoise", new Color(0, 206, 209));\r
- presetColors.put("dkViolet", new Color(148, 0, 211));\r
- presetColors.put("dodgerBlue", new Color(30, 144, 255));\r
- presetColors.put("firebrick", new Color(178, 34, 34));\r
- presetColors.put("floralWhite", new Color(255, 250, 240));\r
- presetColors.put("forestGreen", new Color(34, 139, 34));\r
- presetColors.put("fuchsia", new Color(255, 0, 255));\r
- presetColors.put("gainsboro", new Color(220, 220, 220));\r
- presetColors.put("ghostWhite", new Color(248, 248, 255));\r
- presetColors.put("gold", new Color(255, 215, 0));\r
- presetColors.put("goldenrod", new Color(218, 165, 32));\r
- presetColors.put("gray", new Color(128, 128, 128));\r
- presetColors.put("green", new Color(0, 128, 0));\r
- presetColors.put("greenYellow", new Color(173, 255, 47));\r
- presetColors.put("honeydew", new Color(240, 255, 240));\r
- presetColors.put("hotPink", new Color(255, 105, 180));\r
- presetColors.put("indianRed", new Color(205, 92, 92));\r
- presetColors.put("indigo", new Color(75, 0, 130));\r
- presetColors.put("ivory", new Color(255, 255, 240));\r
- presetColors.put("khaki", new Color(240, 230, 140));\r
- presetColors.put("lavender", new Color(230, 230, 250));\r
- presetColors.put("lavenderBlush", new Color(255, 240, 245));\r
- presetColors.put("lawnGreen", new Color(124, 252, 0));\r
- presetColors.put("lemonChiffon", new Color(255, 250, 205));\r
- presetColors.put("lime", new Color(0, 255, 0));\r
- presetColors.put("limeGreen", new Color(50, 205, 50));\r
- presetColors.put("linen", new Color(250, 240, 230));\r
- presetColors.put("ltBlue", new Color(173, 216, 230));\r
- presetColors.put("ltCoral", new Color(240, 128, 128));\r
- presetColors.put("ltCyan", new Color(224, 255, 255));\r
- presetColors.put("ltGoldenrodYellow", new Color(250, 250, 120));\r
- presetColors.put("ltGray", new Color(211, 211, 211));\r
- presetColors.put("ltGreen", new Color(144, 238, 144));\r
- presetColors.put("ltPink", new Color(255, 182, 193));\r
- presetColors.put("ltSalmon", new Color(255, 160, 122));\r
- presetColors.put("ltSeaGreen", new Color(32, 178, 170));\r
- presetColors.put("ltSkyBlue", new Color(135, 206, 250));\r
- presetColors.put("ltSlateGray", new Color(119, 136, 153));\r
- presetColors.put("ltSteelBlue", new Color(176, 196, 222));\r
- presetColors.put("ltYellow", new Color(255, 255, 224));\r
- presetColors.put("magenta", new Color(255, 0, 255));\r
- presetColors.put("maroon", new Color(128, 0, 0));\r
- presetColors.put("medAquamarine", new Color(102, 205, 170));\r
- presetColors.put("medBlue", new Color(0, 0, 205));\r
- presetColors.put("medOrchid", new Color(186, 85, 211));\r
- presetColors.put("medPurple", new Color(147, 112, 219));\r
- presetColors.put("medSeaGreen", new Color(60, 179, 113));\r
- presetColors.put("medSlateBlue", new Color(123, 104, 238));\r
- presetColors.put("medSpringGreen", new Color(0, 250, 154));\r
- presetColors.put("medTurquoise", new Color(72, 209, 204));\r
- presetColors.put("medVioletRed", new Color(199, 21, 133));\r
- presetColors.put("midnightBlue", new Color(25, 25, 112));\r
- presetColors.put("mintCream", new Color(245, 255, 250));\r
- presetColors.put("mistyRose", new Color(255, 228, 225));\r
- presetColors.put("moccasin", new Color(255, 228, 181));\r
- presetColors.put("navajoWhite", new Color(255, 222, 173));\r
- presetColors.put("navy", new Color(0, 0, 128));\r
- presetColors.put("oldLace", new Color(253, 245, 230));\r
- presetColors.put("olive", new Color(128, 128, 0));\r
- presetColors.put("oliveDrab", new Color(107, 142, 35));\r
- presetColors.put("orange", new Color(255, 165, 0));\r
- presetColors.put("orangeRed", new Color(255, 69, 0));\r
- presetColors.put("orchid", new Color(218, 112, 214));\r
- presetColors.put("paleGoldenrod", new Color(238, 232, 170));\r
- presetColors.put("paleGreen", new Color(152, 251, 152));\r
- presetColors.put("paleTurquoise", new Color(175, 238, 238));\r
- presetColors.put("paleVioletRed", new Color(219, 112, 147));\r
- presetColors.put("papayaWhip", new Color(255, 239, 213));\r
- presetColors.put("peachPuff", new Color(255, 218, 185));\r
- presetColors.put("peru", new Color(205, 133, 63));\r
- presetColors.put("pink", new Color(255, 192, 203));\r
- presetColors.put("plum", new Color(221, 160, 221));\r
- presetColors.put("powderBlue", new Color(176, 224, 230));\r
- presetColors.put("purple", new Color(128, 0, 128));\r
- presetColors.put("red", new Color(255, 0, 0));\r
- presetColors.put("rosyBrown", new Color(188, 143, 143));\r
- presetColors.put("royalBlue", new Color(65, 105, 225));\r
- presetColors.put("saddleBrown", new Color(139, 69, 19));\r
- presetColors.put("salmon", new Color(250, 128, 114));\r
- presetColors.put("sandyBrown", new Color(244, 164, 96));\r
- presetColors.put("seaGreen", new Color(46, 139, 87));\r
- presetColors.put("seaShell", new Color(255, 245, 238));\r
- presetColors.put("sienna", new Color(160, 82, 45));\r
- presetColors.put("silver", new Color(192, 192, 192));\r
- presetColors.put("skyBlue", new Color(135, 206, 235));\r
- presetColors.put("slateBlue", new Color(106, 90, 205));\r
- presetColors.put("slateGray", new Color(112, 128, 144));\r
- presetColors.put("snow", new Color(255, 250, 250));\r
- presetColors.put("springGreen", new Color(0, 255, 127));\r
- presetColors.put("steelBlue", new Color(70, 130, 180));\r
- presetColors.put("tan", new Color(210, 180, 140));\r
- presetColors.put("teal", new Color(0, 128, 128));\r
- presetColors.put("thistle", new Color(216, 191, 216));\r
- presetColors.put("tomato", new Color(255, 99, 71));\r
- presetColors.put("turquoise", new Color(64, 224, 208));\r
- presetColors.put("violet", new Color(238, 130, 238));\r
- presetColors.put("wheat", new Color(245, 222, 179));\r
- presetColors.put("white", new Color(255, 255, 255));\r
- presetColors.put("whiteSmoke", new Color(245, 245, 245));\r
- presetColors.put("yellow", new Color(255, 255, 0));\r
- presetColors.put("yellowGreen", new Color(154, 205, 50));\r
- }\r
}\r
==================================================================== */\r
package org.apache.poi.xslf.usermodel;\r
\r
-import junit.framework.TestCase;\r
-import org.openxmlformats.schemas.drawingml.x2006.main.*;\r
+import static org.junit.Assert.assertEquals;\r
+import static org.junit.Assert.assertNotNull;\r
\r
import java.awt.Color;\r
+import java.io.IOException;\r
\r
-/**\r
- * @author Yegor Kozlov\r
- */\r
-public class TestXSLFColor extends TestCase {\r
+import org.apache.poi.sl.usermodel.PresetColor;\r
+import org.junit.Test;\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.CTSystemColor;\r
+import org.openxmlformats.schemas.drawingml.x2006.main.STPresetColorVal;\r
+import org.openxmlformats.schemas.drawingml.x2006.main.STSchemeColorVal;\r
+import org.openxmlformats.schemas.drawingml.x2006.main.STSystemColorVal;\r
\r
+public class TestXSLFColor {\r
+\r
+ @Test\r
public void testGetters() {\r
CTColor xml = CTColor.Factory.newInstance();\r
CTSRgbColor c = xml.addNewSrgbClr();\r
assertEquals(50, color.getTint());\r
}\r
\r
+ @Test\r
public void testHSL() {\r
CTColor xml = CTColor.Factory.newInstance();\r
CTHslColor c = xml.addNewHslClr();\r
assertEquals(new Color(128, 00, 00), color.getColor());\r
}\r
\r
+ @Test\r
public void testSRgb() {\r
CTColor xml = CTColor.Factory.newInstance();\r
xml.addNewSrgbClr().setVal(new byte[]{ (byte)0xFF, (byte)0xFF, 0});\r
assertEquals(new Color(0xFF, 0xFF, 0), color.getColor());\r
}\r
\r
- public void testSchemeColor() {\r
+ @Test\r
+ public void testSchemeColor() throws IOException {\r
XMLSlideShow ppt = new XMLSlideShow();\r
XSLFTheme theme = ppt.createSlide().getTheme();\r
\r
color = new XSLFColor(xml, theme, null);\r
// <a:sysClr val="windowText" lastClr="000000"/>\r
assertEquals(Color.decode("0x000000"), color.getColor());\r
+\r
+ ppt.close();\r
}\r
\r
+ @Test\r
public void testPresetColor() {\r
CTColor xml = CTColor.Factory.newInstance();\r
xml.addNewPrstClr().setVal(STPresetColorVal.AQUAMARINE);\r
assertEquals(new Color(127, 255, 212), color.getColor());\r
\r
\r
- for(String colorName : XSLFColor.presetColors.keySet()){\r
+ for(PresetColor pc : PresetColor.values()) {\r
+ if (pc.ooxmlId == null) continue;\r
xml = CTColor.Factory.newInstance();\r
- STPresetColorVal.Enum val = STPresetColorVal.Enum.forString(colorName);\r
- assertNotNull(colorName, val);\r
+ STPresetColorVal.Enum val = STPresetColorVal.Enum.forString(pc.ooxmlId);\r
+ assertNotNull(pc.ooxmlId, val);\r
xml.addNewPrstClr().setVal(val);\r
color = new XSLFColor(xml, null, null);\r
- assertEquals(XSLFColor.presetColors.get(colorName), color.getColor());\r
+ assertEquals(pc.color, color.getColor());\r
}\r
}\r
\r
+ @Test\r
public void testSys() {\r
CTColor xml = CTColor.Factory.newInstance();\r
CTSystemColor sys = xml.addNewSysClr();\r
color = new XSLFColor(xml, null, null);\r
assertEquals(Color.red, color.getColor());\r
}\r
-\r
}
\ No newline at end of file
public void setForegroundColor(Color color){
AbstractEscherOptRecord opt = shape.getEscherOptRecord();
if (color == null) {
+ opt.removeEscherProperty(EscherProperties.FILL__FILLCOLOR);
HSLFShape.setEscherProperty(opt, EscherProperties.FILL__NOFILLHITTEST, 0x150000);
}
else {
int rgb = new Color(color.getBlue(), color.getGreen(), color.getRed(), 0).getRGB();
HSLFShape.setEscherProperty(opt, EscherProperties.FILL__FILLCOLOR, rgb);
+ int alpha = color.getAlpha();
+ if (alpha == 255) {
+ opt.removeEscherProperty(EscherProperties.FILL__FILLOPACITY);
+ } else {
+ int alphaFP = Units.doubleToFixedPoint(alpha/255d);
+ HSLFShape.setEscherProperty(opt, EscherProperties.FILL__FILLOPACITY, alphaFP);
+ }
HSLFShape.setEscherProperty(opt, EscherProperties.FILL__NOFILLHITTEST, 0x150011);
}
}
import org.apache.poi.ddf.EscherChildAnchorRecord;
import org.apache.poi.ddf.EscherClientAnchorRecord;
import org.apache.poi.ddf.EscherColorRef;
+import org.apache.poi.ddf.EscherColorRef.SysIndexProcedure;
+import org.apache.poi.ddf.EscherColorRef.SysIndexSource;
import org.apache.poi.ddf.EscherContainerRecord;
import org.apache.poi.ddf.EscherProperties;
import org.apache.poi.ddf.EscherProperty;
import org.apache.poi.hslf.record.RecordTypes;
import org.apache.poi.sl.draw.DrawFactory;
import org.apache.poi.sl.usermodel.FillStyle;
+import org.apache.poi.sl.usermodel.PresetColor;
import org.apache.poi.sl.usermodel.Shape;
import org.apache.poi.sl.usermodel.ShapeContainer;
import org.apache.poi.sl.usermodel.ShapeType;
EscherColorRef ecr = new EscherColorRef(val);
Color col = getColor(ecr);
+ if (col == null) {
+ return null;
+ }
double alpha = getAlpha(opacityProperty);
return new Color(col.getRed(), col.getGreen(), col.getBlue(), (int)(alpha*255.0));
rgb[0] = (schemeColor >> 0) & 0xFF;
rgb[1] = (schemeColor >> 8) & 0xFF;
rgb[2] = (schemeColor >> 16) & 0xFF;
- } else if (fPaletteIndex){
- //TODO
- } else if (fPaletteRGB){
+ } else if (fPaletteIndex) {
//TODO
- } else if (fSystemRGB){
+ } else if (fPaletteRGB) {
//TODO
- } else if (fSysIndex){
+ } else if (fSystemRGB) {
//TODO
+ } else if (fSysIndex) {
+ Color col = getSysIndexColor(ecr);
+ col = applySysIndexProcedure(ecr, col);
+ return col;
}
return new Color(rgb[0], rgb[1], rgb[2]);
}
+ private Color getSysIndexColor(EscherColorRef ecr) {
+ SysIndexSource sis = ecr.getSysIndexSource();
+ if (sis == null) {
+ int sysIdx = ecr.getSysIndex();
+ PresetColor pc = PresetColor.valueOfNativeId(sysIdx);
+ return (pc != null) ? pc.color : null;
+ }
+
+ // TODO: check for recursive loops, when color getter also reference
+ // a different color type
+ switch (sis) {
+ case FILL_COLOR: {
+ return getFill().getForegroundColor();
+ }
+ case LINE_OR_FILL_COLOR: {
+ Color col = null;
+ if (this instanceof HSLFSimpleShape) {
+ col = ((HSLFSimpleShape)this).getLineColor();
+ }
+ if (col == null) {
+ col = getFill().getForegroundColor();
+ }
+ return col;
+ }
+ case LINE_COLOR: {
+ if (this instanceof HSLFSimpleShape) {
+ return ((HSLFSimpleShape)this).getLineColor();
+ }
+ break;
+ }
+ case SHADOW_COLOR: {
+ if (this instanceof HSLFSimpleShape) {
+ return ((HSLFSimpleShape)this).getShadowColor();
+ }
+ break;
+ }
+ case CURRENT_OR_LAST_COLOR: {
+ // TODO ... read from graphics context???
+ break;
+ }
+ case FILL_BACKGROUND_COLOR: {
+ return getFill().getBackgroundColor();
+ }
+ case LINE_BACKGROUND_COLOR: {
+ if (this instanceof HSLFSimpleShape) {
+ return ((HSLFSimpleShape)this).getLineBackgroundColor();
+ }
+ break;
+ }
+ case FILL_OR_LINE_COLOR: {
+ Color col = getFill().getForegroundColor();
+ if (col == null && this instanceof HSLFSimpleShape) {
+ col = ((HSLFSimpleShape)this).getLineColor();
+ }
+ return col;
+ }
+ default:
+ break;
+ }
+
+ return null;
+ }
+
+ private Color applySysIndexProcedure(EscherColorRef ecr, Color col) {
+
+ final SysIndexProcedure sip = ecr.getSysIndexProcedure();
+ if (col == null || sip == null) {
+ return col;
+ }
+
+ switch (sip) {
+ case DARKEN_COLOR: {
+ // see java.awt.Color#darken()
+ double FACTOR = (ecr.getRGB()[2])/255.;
+ int r = (int)Math.rint(col.getRed()*FACTOR);
+ int g = (int)Math.rint(col.getGreen()*FACTOR);
+ int b = (int)Math.rint(col.getBlue()*FACTOR);
+ return new Color(r,g,b);
+ }
+ case LIGHTEN_COLOR: {
+ double FACTOR = (0xFF-ecr.getRGB()[2])/255.;
+
+ int r = col.getRed();
+ int g = col.getGreen();
+ int b = col.getBlue();
+
+ r += Math.rint((0xFF-r)*FACTOR);
+ g += Math.rint((0xFF-g)*FACTOR);
+ b += Math.rint((0xFF-b)*FACTOR);
+
+ return new Color(r,g,b);
+ }
+ default:
+ // TODO ...
+ break;
+ }
+
+ return col;
+ }
+
double getAlpha(short opacityProperty) {
AbstractEscherOptRecord opt = getEscherOptRecord();
EscherSimpleProperty op = getEscherProperty(opt, opacityProperty);
return clr == null ? null : clr;
}
+ /**
+ * @return background color of the line. If color is not set returns {@code null}
+ */
+ public Color getLineBackgroundColor(){
+ AbstractEscherOptRecord opt = getEscherOptRecord();
+
+ EscherSimpleProperty p = getEscherProperty(opt, EscherProperties.LINESTYLE__NOLINEDRAWDASH);
+ if(p != null && (p.getPropertyValue() & 0x8) == 0) return null;
+
+ Color clr = getColor(EscherProperties.LINESTYLE__BACKCOLOR, EscherProperties.LINESTYLE__OPACITY, -1);
+ return clr == null ? null : clr;
+ }
+
+ /**
+ * Sets the background color of line
+ *
+ * @param color new background color of the line
+ */
+ public void setLineBackgroundColor(Color color){
+ AbstractEscherOptRecord opt = getEscherOptRecord();
+ if (color == null) {
+ setEscherProperty(opt, EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x80000);
+ opt.removeEscherProperty(EscherProperties.LINESTYLE__BACKCOLOR);
+ } else {
+ int rgb = new Color(color.getBlue(), color.getGreen(), color.getRed(), 0).getRGB();
+ setEscherProperty(opt, EscherProperties.LINESTYLE__BACKCOLOR, rgb);
+ setEscherProperty(opt, EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x180018);
+ }
+ }
+
/**
* Gets line cap.
*
import java.awt.Color;
import java.awt.Graphics2D;
+import java.awt.geom.Ellipse2D;
+import java.awt.geom.Path2D;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.File;
import org.apache.poi.sl.draw.DrawFactory;
import org.apache.poi.sl.draw.DrawPaint;
import org.apache.poi.sl.draw.DrawTextParagraph;
+import org.apache.poi.sl.usermodel.ColorStyle;
import org.apache.poi.sl.usermodel.PaintStyle;
import org.apache.poi.sl.usermodel.PaintStyle.SolidPaint;
import org.apache.poi.sl.usermodel.PictureData.PictureType;
}
@Test
+ @SuppressWarnings("resource")
public void bug57796() throws IOException {
HSLFSlideShow ppt = open("WithLinks.ppt");
HSLFSlide slide = ppt.getSlides().get(0);
sb.append(c);
attributes = iterator.getAttributes();
}
-
+
if ("Jakarta HSSF".equals(sb.toString())) {
// this is a test for a manually modified ppt, for real hyperlink label
// one would need to access the screen tip record
File sample = HSLFTestDataSamples.getSampleFile(fileName);
return (HSLFSlideShow)SlideShowFactory.create(sample);
}
+
+ @Test
+ public void bug55983() throws IOException {
+ HSLFSlideShow ppt1 = new HSLFSlideShow();
+ HSLFSlide sl = ppt1.createSlide();
+ sl.getBackground().getFill().setForegroundColor(Color.blue);
+ HSLFFreeformShape fs = sl.createFreeform();
+ Ellipse2D.Double el = new Ellipse2D.Double(0,0,300,200);
+ fs.setAnchor(new Rectangle2D.Double(100,100,300,200));
+ fs.setPath(new Path2D.Double(el));
+ Color cExp = new Color(50,100,150,200);
+ fs.setFillColor(cExp);
+
+ HSLFSlideShow ppt2 = HSLFTestDataSamples.writeOutAndReadBack(ppt1);
+ ppt1.close();
+
+ sl = ppt2.getSlides().get(0);
+ fs = (HSLFFreeformShape)sl.getShapes().get(0);
+ Color cAct = fs.getFillColor();
+ assertEquals(cExp.getRed(), cAct.getRed());
+ assertEquals(cExp.getGreen(), cAct.getGreen());
+ assertEquals(cExp.getBlue(), cAct.getBlue());
+ assertEquals(cExp.getAlpha(), cAct.getAlpha(), 1);
+
+ PaintStyle ps = fs.getFillStyle().getPaint();
+ assertTrue(ps instanceof SolidPaint);
+ ColorStyle cs = ((SolidPaint)ps).getSolidColor();
+ cAct = cs.getColor();
+ assertEquals(cExp.getRed(), cAct.getRed());
+ assertEquals(cExp.getGreen(), cAct.getGreen());
+ assertEquals(cExp.getBlue(), cAct.getBlue());
+ assertEquals(255, cAct.getAlpha());
+ assertEquals(cExp.getAlpha()*100000./255., cs.getAlpha(), 1);
+
+ ppt2.close();
+ }
}