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