Class GssFunctions.MakeContrastingColor
- java.lang.Object
-
- com.google.common.css.compiler.gssfunctions.GssFunctions.MakeContrastingColor
-
- All Implemented Interfaces:
GssFunction
- Enclosing class:
- GssFunctions
public static class GssFunctions.MakeContrastingColor extends java.lang.Object implements GssFunction
The "makeContrastingColor" function generates a contrasting color with the same hue as the input color. The generated color passes (or almost passes) the contrast test described in the W3C accessibility evaluation working draft "http://www.w3.org/TR/AERT#color-contrast".The function takes two parameters:
- The input color to find the contrasting color for,
- the similarity value (a float between 0.0 - 1.0) which tells how similar the computed color should be to the input color.
The algorithm for the contrasting color generation is as follows:
- First a base contrasting color is chosen. It is either black or white, as one of these colors is guaranteed to be in contrast with any given color. Additionally both of these colors are "hue-neutral", so choosing the contrasting color in between the input color and black or white should give pleasant results.
- A closest required contrasting color is found. This is a color in
between the input color and the base contrasting color. It has the same
hue as the input color. This color is found in HSB color space, by a
bisection of a line between the input color and the base contrasting
color. To improve function performance, a limited number of the
bisection steps (
NUM_ITERATIONS) is performed. This gives a constant expected time of function execution. At the same time the color that is found may not pass the contrast test, but is guaranteed to be close to the "contrast boundary". - The output color of the function is an interpolation of the closest contrasting color and the base contrasting color. The interpolation is controlled using the "similarity" parameter. If similarity is set to 1, it means that the result is the closest contrasting color. If similarity is set to 0, it means that the result is the base contrasting color.
-
-
Constructor Summary
Constructors Constructor Description MakeContrastingColor()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.List<CssValueNode>getCallResultNodes(java.util.List<CssValueNode> args, ErrorManager errorManager)Processes a list of function call arguments and returns a list of CssNodes representing this call's output, which replace the input nodes in the AST.java.lang.StringgetCallResultString(java.util.List<java.lang.String> args)Processes a list of strings as function arguments and returns a string result.java.lang.IntegergetNumExpectedArguments()Returns the number of parsed arguments that this function takes, ornullif the number of arguments may vary.protected java.lang.StringmakeContrastingColor(java.lang.String inputColorStr, java.lang.String similarityStr)
-
-
-
Method Detail
-
getNumExpectedArguments
public java.lang.Integer getNumExpectedArguments()
Description copied from interface:GssFunctionReturns the number of parsed arguments that this function takes, ornullif the number of arguments may vary.- Specified by:
getNumExpectedArgumentsin interfaceGssFunction
-
getCallResultNodes
public java.util.List<CssValueNode> getCallResultNodes(java.util.List<CssValueNode> args, ErrorManager errorManager)
Description copied from interface:GssFunctionProcesses a list of function call arguments and returns a list of CssNodes representing this call's output, which replace the input nodes in the AST. Errors will be reported to the ErrorManager.- Specified by:
getCallResultNodesin interfaceGssFunction
-
getCallResultString
public java.lang.String getCallResultString(java.util.List<java.lang.String> args)
Description copied from interface:GssFunctionProcesses a list of strings as function arguments and returns a string result. Errors are reported by throwingGssFunctionException.- Specified by:
getCallResultStringin interfaceGssFunction
-
makeContrastingColor
protected java.lang.String makeContrastingColor(java.lang.String inputColorStr, java.lang.String similarityStr)
-
-