Top Description Inners Fields Constructors Methods
org.apache.poi.sl.draw

public Class DrawPaint

extends Object
Class Inheritance
Static Imports
org.apache.poi.sl.draw.geom.ArcToCommand.convertOoxml2AwtAngle

This class handles color transformations.
See Also
HSL code taken from Java Tips Weblog

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private static final Logger
protected PlaceableShape<?, ?>
private static final Color

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static Color
applyColorTransform(ColorStyle color)

Convert color transformations in ColorStyle to a Color instance

private static void
applyHslModOff(double[]
the hsl values
hsl
,
int
the hsl part to modify [0..2]
hslPart
,
int
the modulation adjustment
mod
,
int
the offset adjustment
off
)

Apply the modulation and offset adjustments to the given HSL part Example for lumMod/lumOff: The lumMod value is the percent luminance.

private static void
applyShade(double[] scRGB, ColorStyle fc)

Apply the shade For a shade, the equation is luminance * %tint.

private static void
applyTint(double[] scRGB, ColorStyle fc)

Apply the tint

private static BufferedImage

Returns:

the original image if no duotone was found, otherwise the colorized pattern
colorizePattern
(PaintStyle.TexturePaint fill, BufferedImage pattern)

In case a duotone element is specified, handle image as pattern and replace its color values with the corresponding percentile / linear value between fore- and background color

protected Paint
protected Paint
protected Paint
public static PaintStyle.SolidPaint
createSolidPaint(final Color color)

public static PaintStyle.SolidPaint
pack-priv static void
private static double
private static double
getCenterVal(double absMin, double absMax, double relMin, double relMax)

protected Paint
public Paint
getPaint(Graphics2D graphics, PaintStyle paint)

public Paint
private static double
getScale(double absMin, double absMax, double relMin, double relMax)

protected Paint
protected Paint
public static Color

Returns:

the RGB Color object
HSL2RGB
(double
Hue is specified as degrees in the range 0 - 360.
h
,
double
Saturation is specified as a percentage in the range 1 - 100.
s
,
double
Luminance is specified as a percentage in the range 1 - 100.
l
,
double
the alpha value between 0 - 1
alpha
)

Convert HSL values to a RGB Color.

private static double
HUE2RGB(double p, double q, double h)

private static int[]
linearBlendedColors(List<ColorStyle> duoTone, final int blendShades)

public static double[]

Returns:

an array containing the 3 HSL values.
RGB2HSL
(Color color)

Convert a RGB Color to it corresponding HSL values.

public static double[]
RGB2SCRGB(Color color)

Convert sRGB Color to scRGB [0..1] (0:red,1:green,2:blue).

private Paint
private static void
scaleShades(int[] samples, double ratio)

public static Color
SCRGB2RGB(double... scRGB)

Convert scRGB [0..1] components (0:red,1:green,2:blue) to sRGB Color.

private static float[]
toArray(Collection<Float> floatList)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

LOGback to summary
private static final Logger LOG
shapeback to summary
protected PlaceableShape<?, ?> shape
TRANSPARENTback to summary
private static final Color TRANSPARENT

Constructor Detail

DrawPaintback to summary
public DrawPaint(PlaceableShape<?, ?> shape)

Method Detail

applyColorTransformback to summary
public static Color applyColorTransform(ColorStyle color)

Convert color transformations in ColorStyle to a Color instance

See Also
Using Office Open XML to Customize Document Formatting in the 2007 Office System, saturation modulation (satMod)
applyHslModOffback to summary
private static void applyHslModOff(double[] hsl, int hslPart, int mod, int off)

Apply the modulation and offset adjustments to the given HSL part Example for lumMod/lumOff: The lumMod value is the percent luminance. A lumMod value of "60000", is 60% of the luminance of the original color. When the color is a shade of the original theme color, the lumMod attribute is the only one of the tags shown here that appears. The tag appears after the tag when the color is a tint of the original. The lumOff value always equals 1-lumMod, which is used in the tint calculation Despite having different ways to display the tint and shade percentages, all of the programs use the same method to calculate the resulting color. Convert the original RGB value to HSL ... and then adjust the luminance (L) with one of the following equations before converting the HSL value back to RGB. (The % tint in the following equations refers to the tint, themetint, themeshade, or lumMod values, as applicable.)

Parameters
hsl:double[]

the hsl values

hslPart:int

the hsl part to modify [0..2]

mod:int

the modulation adjustment

off:int

the offset adjustment

applyShadeback to summary
private static void applyShade(double[] scRGB, ColorStyle fc)

Apply the shade For a shade, the equation is luminance * %tint.

applyTintback to summary
private static void applyTint(double[] scRGB, ColorStyle fc)

Apply the tint

colorizePatternback to summary
private static BufferedImage colorizePattern(PaintStyle.TexturePaint fill, BufferedImage pattern)

In case a duotone element is specified, handle image as pattern and replace its color values with the corresponding percentile / linear value between fore- and background color

Returns:BufferedImage

the original image if no duotone was found, otherwise the colorized pattern

createLinearGradientPaintback to summary
protected Paint createLinearGradientPaint(PaintStyle.GradientPaint fill, Graphics2D graphics)
Annotations
@SuppressWarnings:WeakerAccess
createPathGradientPaintback to summary
protected Paint createPathGradientPaint(PaintStyle.GradientPaint fill, Graphics2D graphics)
Annotations
@SuppressWarnings:WeakerAccess, unused
createRadialGradientPaintback to summary
protected Paint createRadialGradientPaint(PaintStyle.GradientPaint fill, Graphics2D graphics)
Annotations
@SuppressWarnings:WeakerAccess
createSolidPaintback to summary
public static PaintStyle.SolidPaint createSolidPaint(final Color color)
createSolidPaintback to summary
public static PaintStyle.SolidPaint createSolidPaint(final ColorStyle color)
fillPaintWorkaroundback to summary
pack-priv static void fillPaintWorkaround(Graphics2D graphics, Shape shape)
getAlphaback to summary
private static double getAlpha(Color c, ColorStyle fc)
getCenterValback to summary
private static double getCenterVal(double absMin, double absMax, double relMin, double relMax)
getGradientPaintback to summary
protected Paint getGradientPaint(PaintStyle.GradientPaint fill, Graphics2D graphics)
Annotations
@SuppressWarnings:WeakerAccess
getPaintback to summary
public Paint getPaint(Graphics2D graphics, PaintStyle paint)
getPaintback to summary
public Paint getPaint(Graphics2D graphics, PaintStyle paint, PaintStyle.PaintModifier modifier)
getScaleback to summary
private static double getScale(double absMin, double absMax, double relMin, double relMax)
getSolidPaintback to summary
protected Paint getSolidPaint(PaintStyle.SolidPaint fill, Graphics2D graphics, final PaintStyle.PaintModifier modifier)
Annotations
@SuppressWarnings:WeakerAccess, unused
getTexturePaintback to summary
protected Paint getTexturePaint(PaintStyle.TexturePaint fill, Graphics2D graphics)
Annotations
@SuppressWarnings:WeakerAccess
HSL2RGBback to summary
public static Color HSL2RGB(double h, double s, double l, double alpha)

Convert HSL values to a RGB Color.

Parameters
h:double

Hue is specified as degrees in the range 0 - 360.

s:double

Saturation is specified as a percentage in the range 1 - 100.

l:double

Luminance is specified as a percentage in the range 1 - 100.

alpha:double

the alpha value between 0 - 1

Returns:Color

the RGB Color object

HUE2RGBback to summary
private static double HUE2RGB(double p, double q, double h)
linearBlendedColorsback to summary
private static int[] linearBlendedColors(List<ColorStyle> duoTone, final int blendShades)
RGB2HSLback to summary
public static double[] RGB2HSL(Color color)

Convert a RGB Color to it corresponding HSL values.

Returns:double[]

an array containing the 3 HSL values.

RGB2SCRGBback to summary
public static double[] RGB2SCRGB(Color color)

Convert sRGB Color to scRGB [0..1] (0:red,1:green,2:blue). Alpha needs to be handled separately.

See Also
.Net implementation sRgbToScRgb
safeFractionsback to summary
private Paint safeFractions(BiFunction<float[], Color[], Paint> init, PaintStyle.GradientPaint fill)
scaleShadesback to summary
private static void scaleShades(int[] samples, double ratio)
SCRGB2RGBback to summary
public static Color SCRGB2RGB(double... scRGB)

Convert scRGB [0..1] components (0:red,1:green,2:blue) to sRGB Color. Alpha needs to be handled separately.

See Also
.Net implementation ScRgbTosRgb
toArrayback to summary
private static float[] toArray(Collection<Float> floatList)
org.apache.poi.sl.draw back to summary

private Class DrawPaint.SimpleSolidPaint

extends Object
implements SolidPaint
Class Inheritance
All Implemented Interfaces
org.apache.poi.sl.usermodel.PaintStyle.SolidPaint, org.apache.poi.sl.usermodel.PaintStyle

Field Summary

Modifier and TypeField and Description
private final ColorStyle

Constructor Summary

AccessConstructor and Description
pack-priv
SimpleSolidPaint(final Color color)

pack-priv

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object
the reference object with which to compare.
o
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public ColorStyle
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

solidColorback to summary
private final ColorStyle solidColor

Constructor Detail

SimpleSolidPaintback to summary
pack-priv SimpleSolidPaint(final Color color)
SimpleSolidPaintback to summary
pack-priv SimpleSolidPaint(ColorStyle color)

Method Detail

equalsback to summary
public boolean equals(Object o)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
o:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getSolidColorback to summary
public ColorStyle getSolidColor()

Implements org.apache.poi.sl.usermodel.PaintStyle.SolidPaint.getSolidColor.

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override