Class DeviceNColorSpace.Builder

  • Enclosing class:

    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.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.setFillColor(new GradientPaint(50, 100, red, 500, 100, blue));
     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.

    • Constructor Detail

      • Builder

        public Builder()
    • 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.
      • addInk

        public void addInk​(SpotColorSpace scs)
        Add an ink to this ColorSpace. The supplied SpotColorSpace must use the same fallback ColorSpace as this builder.
        scs - the SpotColorSpace defining the ink.
      • 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.
        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