Class DeviceNColorSpace.Builder

  • Enclosing class:
    DeviceNColorSpace

    public static class DeviceNColorSpace.Builder
    extends Object

    The Builder subclass allows the creation of a custom DeviceN ColorSpace, by specifying first the fallback ColorSpace, then the individual inks. For example, to create a linear gradient from "PANTONE Warm Red C" to "PANTONE Reflex Blue C", you could do the following:

     DeviceNColorSpace.Builder builder = new DeviceNColorSpace();
     builder.setFallback(CMYKColorSpace.getInstance());
     builder.addInk("PANTONE Warm Red C", new float[] { 0, 0.75f, 0.9f, 0 }, 1);
     builder.addInk("PANTONE Reflex Blue C", new float[] { 1, 0.723f, 0, 0.02f }, 1);
     DeviceNColorSpace dn = builder.create();
     Color red = new Color(dn, new float[] { 1, 0 }, 1);  // 100% Warm Red
     Color blue = new Color(dn, new float[] { 0, 1 }, 1);  // 100% Reflex Blue
    
     PDFStyle gradient = new PDFStyle();
     gradient.setLineColor(Color.black);
     gradient.setFillColor(new GradientPaint(50, 100, red, 500, 100, blue));
     page.setStyle(gradient);
     page.drawRectangle(50, 100, 500, 200);
     

    The ColorSpace can theoretically be any space, but in practise should be a CMYK space, either CMYKColorSpace or an ICCColorSpace if you prefer. The blending will be unlikely to work as expected if LabColorSpace is used.

    Since:
    2.23.1
    • Constructor Detail

      • Builder

        public Builder()
        Create a new DeviceNColorSpace.Builder
      • Builder

        public Builder​(ColorSpace cs)
        Create a new DeviceNColorSpace.Builder and initialize it with the components from the supplied ColorSpace
        Since:
        2.28.3
    • Method Detail

      • setColorSpace

        public void setColorSpace​(ColorSpace cs)
        Set the ColorSpace which is used to define the inks. This should normally be a CMYK based ColorSpace. This method must be called before any Inks are added.
      • getColorSpace

        public ColorSpace getColorSpace()
        Return the ColorSpace set on this Builder
        Since:
        2.28.3
      • getInk

        public SpotColorSpace getInk​(int component)
        Return the SpotColorSpace representing the specified component
        Parameters:
        component - the component
        Since:
        2.28.3
      • removeInk

        public void removeInk​(int component)
        Remove an Ink that has been previously added from the builder.
        Parameters:
        component - the component
        Since:
        2.28.3
      • addInk

        public void addInk​(SpotColorSpace scs)
        Add an ink to this ColorSpace. The supplied SpotColorSpace must use the same fallback ColorSpace as this builder.
        Parameters:
        scs - the SpotColorSpace defining the ink.
        Since:
        2.24.3
      • addInk

        public void addInk​(String name,
                           float[] comps,
                           float gamma)
        Add an ink to this ColorSpace. The ink can be a spot color, it can be the name of one of the process colors that make up the ColorSpace for this object, or it can be the string "None" - which is the only name that doesn't have to be unique.
        Parameters:
        name - the name of the ink, eg "PANTONE Warm Red C"
        comps - the components in this builder's ColorSpace that define that ink.
        gamma - the gamma value. Currently this must be always be one.
      • create

        public DeviceNColorSpace create()
        Create a DeviceNColorSpace from this builder