org.apache.fop.util

## Class ColorUtil

- java.lang.Object
- - org.apache.fop.util.ColorUtil

-     public final class ColorUtil
      extends Object

  Generic Color helper class.

  This class supports parsing string values into color values and creating color values for strings. It provides a list of standard color names.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `ALPHA_PSEUDO_PROFILE`
    `static String` | `CMYK_PSEUDO_PROFILE` The name for the uncalibrated CMYK pseudo-profile
    `static String` | `SEPARATION_PSEUDO_PROFILE` The name for the Separation pseudo-profile used for spot colors

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static String` | `colorToString(Color color)` Creates a re-parsable string representation of the given color.
    `static boolean` | `isGray(Color col)` Indicates whether the color is a gray value.
    `static boolean` | `isPseudoProfile(String colorProfileName)` Indicates whether the given color profile name is one of the pseudo-profiles supported by FOP (ex.
    `static Color` | `lightenColor(Color col, float factor)` Lightens up a color for groove, ridge, inset and outset border effects.
    `static Color` | `parseColorString(FOUserAgent foUserAgent, String value)` Creates a color from a given string.
    `static Color` | `toCMYKGrayColor(float black)` Creates an uncalibrated CMYK color with the given gray value.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### CMYK_PSEUDO_PROFILE

          public static final String CMYK_PSEUDO_PROFILE

      The name for the uncalibrated CMYK pseudo-profile
      See Also:
        Constant Field Values

    - #### SEPARATION_PSEUDO_PROFILE

          public static final String SEPARATION_PSEUDO_PROFILE

      The name for the Separation pseudo-profile used for spot colors
      See Also:
        Constant Field Values

    - #### ALPHA_PSEUDO_PROFILE

          public static final String ALPHA_PSEUDO_PROFILE

      See Also:
        Constant Field Values

  - ### Method Detail

    - #### parseColorString

          public static Color parseColorString(FOUserAgent foUserAgent,
                                               String value)
                                        throws PropertyException

      Creates a color from a given string.

      This function supports a wide variety of inputs.

      - #RGB (hex 0..f)
      - #RGBA (hex 0..f)
      - #RRGGBB (hex 00..ff)
      - #RRGGBBAA (hex 00..ff)
      - rgb(r,g,b) (0..255 or 0%..100%)
      - java.awt.Color[r=r,g=g,b=b] (0..255)
      - system-color(colorname)
      - transparent
      - colorname
      - fop-rgb-icc(r,g,b,cs,cs-src,[num]+) (r/g/b: 0..1, num: 0..1)
      - cmyk(c,m,y,k) (0..1)
      Parameters:
        `foUserAgent` - FOUserAgent object
        `value` - the string to parse.
      Returns:
        a Color representing the string if possible
      Throws:
        `PropertyException` - if the string is not parsable or does not follow any of the given formats.

    - #### colorToString

          public static String colorToString(Color color)

      Creates a re-parsable string representation of the given color.

      First, the color will be converted into the sRGB colorspace. It will then be printed as #rrggbb, or as #rrrggbbaa if an alpha value is present.

      Parameters:
        `color` - the color to represent.
      Returns:
        a re-parsable string representadion.

    - #### lightenColor

          public static Color lightenColor(Color col,
                                           float factor)

      Lightens up a color for groove, ridge, inset and outset border effects.
      Parameters:
        `col` - the color to lighten up
        `factor` - factor by which to lighten up (negative values darken the color)
      Returns:
        the modified color

    - #### isPseudoProfile

          public static boolean isPseudoProfile(String colorProfileName)

      Indicates whether the given color profile name is one of the pseudo-profiles supported by FOP (ex. #CMYK).
      Parameters:
        `colorProfileName` - the color profile name to check
      Returns:
        true if the color profile name is of a built-in pseudo-profile

    - #### isGray

          public static boolean isGray(Color col)

      Indicates whether the color is a gray value.
      Parameters:
        `col` - the color
      Returns:
        true if it is a gray value

    - #### toCMYKGrayColor

          public static Color toCMYKGrayColor(float black)

      Creates an uncalibrated CMYK color with the given gray value.
      Parameters:
        `black` - the gray component (0 - 1)
      Returns:
        the CMYK color

Copyright © 2025 Apache Software Foundation. All rights reserved.