KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > faceless > pdf > SpotColorSpace


1 // $Id: SpotColorSpace.java,v 1.4 2005/07/29 11:32:50 mike Exp $
2

3 package org.faceless.pdf;
4
5 import java.awt.color.*;
6 import java.awt.*;
7
8 /**
9  * <p>
10  * A type of <tt>ColorSpace</tt> dealing with Separation ("Spot") Colors.
11  * </p><p>
12  * Spot colors are used to define an <i>exact</i> color in the printed
13  * output. This is usually done by printing these colors using a matching
14  * ink onto a separate film, ink which may be outside the gamut of the normal
15  * CMYK printing process. Commonly used Spot colors include those from the
16  * PANTONE&trade; and Focoltone&trade; range of colors.
17  * </p><p>
18  * Every Spot colorspace has a name, which is the name used by the printer
19  * to identify the ink. Because not every output device may have the specified
20  * ink available (displaying the PDF on screen for example), every Spot color
21  * must have a "fallback" color specified as a process color (RGB or CMYK)
22  * as well. Remembering that not every spot color can be reproduced in CMYK,
23  * the fallback color is often just a close match.
24  * </p><p>
25  * Like normal colorspaces (RGB, CMYK and so on), different colors can be
26  * specified within this space, although they will all be just a different
27  * intensity of the specified ink - ranging from zero (no ink is applied)
28  * to one (the full intensity of the specified color is applied).
29  * </p><p>
30  * Here's an example showing how to use the PANTONE&trade; color "PANTONE
31  * Reflex Blue" to print a line of text.
32  * </p><pre>
33  * Color fallback = CYMKColorSpace.getColor(1.0, 0.72, 0, 0.06);
34  * SpotColorSpace blueink = new SpotColorSpace("PANTONE Reflex Blue CVC", fallback);
35  * Color logoblue = blueink.getColor(1);
36  *
37  * PDFStyle style = new PDFStyle();
38  * style.setFillColor(logoblue);
39  * page.setStyle(style);
40  * page.drawText("This is in PANTONE Reflex Blue CVC", 100, 100);
41  * </pre><p>
42  * Note the three stages. First we create the fallback color, specified in
43  * CMYK. As it happens this spot color is outside the gamut of the CMYK
44  * colorspace, so our fallback is an approximation only. Then we create the
45  * colorspace, and finally we select a color which is this ink at 100%
46  * intensity. From there we can just use the color as normal.
47  * </p>
48  * In the PDF specification Spot color is referred to as a "Separation" color.
49  * </p>
50  * @since 1.1.5
51  * @version $Revision: 1.4 $
52  */

53 public class SpotColorSpace extends ColorSpace
54 {
55     private org.faceless.pdf2.SpotColorSpace cspace;
56     private Color fallback;
57
58     /**
59      * Create a new SpotColorSpace representing a single custom ink.
60      * @param name the name of the ink
61      * @param color the color to use as a fallback color if this ink is
62      * not available. Must be from either an RGB, CMYK or Grayscale
63      * ColorSpace, or an <tt>IllegalArgumentException</tt> is thrown.
64      */

65     public SpotColorSpace(String JavaDoc name, Color color)
66     {
67     super(color.getColorSpace().getType(), 1);
68     cspace = new org.faceless.pdf2.SpotColorSpace(name, color);
69         this.fallback = fallback;
70     }
71
72     public float[] toCIEXYZ(float[] comp)
73     {
74     return cspace.toCIEXYZ(comp);
75     }
76     public float[] fromCIEXYZ(float[] comp)
77     {
78     return cspace.fromCIEXYZ(comp);
79     }
80     public float[] toRGB(float[] comp)
81     {
82     return cspace.toRGB(comp);
83     }
84     public float[] fromRGB(float[] comp)
85     {
86     return cspace.fromRGB(comp);
87     }
88
89     /**
90      * Get the name of this colorspace
91      */

92     public String JavaDoc getName()
93     {
94         return cspace.getName();
95     }
96
97     /**
98      * Get the fallback color to use if this ink is not available
99      */

100     public Color getFallbackColor()
101     {
102     return fallback;
103     }
104
105     /**
106      * A convenience method to return a color from this ColorSpace.
107      * @param amt the intensity of the color. Any value between zero and
108      * one, where zero means no ink at all and one means the full intensity.
109      * If the number is outside this range, an <tt>IllegalArgumentException</tt>
110      * is thrown
111      * @throws IllegalArgumentException
112      */

113     public Color getColor(float amt)
114     {
115     return cspace.getColor(amt);
116     }
117
118     /**
119      * A convenience method returning the color specified by the full intensity
120      * of this colorspace. Equivalent to <tt>getColor(1)</tt>.
121      */

122     public Color getColor()
123     {
124     return cspace.getColor();
125     }
126 }
127
Popular Tags