KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > it > stefanochizzolini > clown > documents > contents > colorSpaces > ColorSpace


1 /*
2   Copyright 2006 Stefano Chizzolini. http://clown.stefanochizzolini.it
3
4   Contributors:
5     * Stefano Chizzolini (original code developer, info@stefanochizzolini.it):
6       contributed code is Copyright 2006 by Stefano Chizzolini.
7
8   This file should be part of the source code distribution of "PDF Clown library"
9   (the Program): see the accompanying README files for more info.
10
11   This Program is free software; you can redistribute it and/or modify it under
12   the terms of the GNU General Public License as published by the Free Software
13   Foundation; either version 2 of the License, or (at your option) any later version.
14
15   This Program is distributed in the hope that it will be useful, but WITHOUT ANY
16   WARRANTY, either expressed or implied; without even the implied warranty of
17   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the License for more details.
18
19   You should have received a copy of the GNU General Public License along with this
20   Program (see README files); if not, go to the GNU website (http://www.gnu.org/).
21
22   Redistribution and use, with or without modification, are permitted provided that such
23   redistributions retain the above copyright notice, license and disclaimer, along with
24   this list of conditions.
25 */

26
27 package it.stefanochizzolini.clown.documents.contents.colorSpaces;
28
29 import it.stefanochizzolini.clown.documents.Document;
30 import it.stefanochizzolini.clown.files.File;
31 import it.stefanochizzolini.clown.objects.PdfArray;
32 import it.stefanochizzolini.clown.objects.PdfDataObject;
33 import it.stefanochizzolini.clown.objects.PdfDirectObject;
34 import it.stefanochizzolini.clown.objects.PdfIndirectObject;
35 import it.stefanochizzolini.clown.objects.PdfName;
36 import it.stefanochizzolini.clown.objects.PdfObjectWrapper;
37 import it.stefanochizzolini.clown.objects.PdfReference;
38
39 /**
40   Color space [PDF:1.6:4.5].
41 */

42 public abstract class ColorSpace
43   extends PdfObjectWrapper<PdfDirectObject>
44 {
45   // <class>
46
// <static>
47
// <interface>
48
// <public>
49
/**
50     Wraps a color space reference into a color space object.
51     @param reference Reference to a color space object.
52     @return Color space object associated to the reference.
53   */

54   public static ColorSpace wrap(
55     PdfReference reference
56     )
57   {return wrap(reference,null);}
58
59   /**
60     Wraps a color space base object into a color space object.
61     @param baseObject Base object of a color space object.
62     @param container Indirect object possibly containing the color space
63     base object.
64     @return Color space object associated to the base object.
65   */

66   public static ColorSpace wrap(
67     PdfDirectObject baseObject,
68     PdfIndirectObject container
69     )
70   {
71     /*
72       NOTE: This is a factory method for any ColorSpace-derived object.
73     */

74     if(baseObject == null)
75       return null;
76
77     PdfName name;
78     // Get the data object corresponding to the color space!
79
PdfDataObject baseDataObject = File.resolve(baseObject);
80     // Is it an array?
81
/*
82       NOTE: [PDF:1.6:4.5.2] A color space is defined by an array object whose
83       first element is a name object identifying the color space family. For
84       families that do not require parameters, the color space CAN be specified
85       simply by the family name itself instead of an array.
86     */

87     if(baseDataObject instanceof PdfArray) // PdfArray.
88
{name = (PdfName)((PdfArray)baseDataObject).get(0);}
89     else // PdfName (by definition).
90
{name = (PdfName)baseDataObject;}
91
92     if(name.equals(PdfName.DeviceRGB))
93       return new DeviceRGBColorSpace(baseObject,container);
94     else if(name.equals(PdfName.DeviceCMYK))
95       return new DeviceCMYKColorSpace(baseObject,container);
96     else if(name.equals(PdfName.DeviceGray))
97       return new DeviceGrayColorSpace(baseObject,container);
98     else if(name.equals(PdfName.CalRGB))
99       return new CalRGBColorSpace(baseObject,container);
100     else if(name.equals(PdfName.CalGray))
101       return new CalGrayColorSpace(baseObject,container);
102     else if(name.equals(PdfName.Lab))
103       return new LabColorSpace(baseObject,container);
104     else if(name.equals(PdfName.ICCBased))
105       return new ICCBasedColorSpace(baseObject,container);
106     else
107       return null; // Should never happen.
108
}
109   // </public>
110
// </interface>
111
// </static>
112

113   // <dynamic>
114
// <constructors>
115
protected ColorSpace(
116     Document context,
117     PdfDirectObject baseDataObject
118     )
119   {
120     super(
121       context.getFile(),
122       baseDataObject
123       );
124   }
125
126   protected ColorSpace(
127     PdfDirectObject baseObject,
128     PdfIndirectObject container
129     )
130   {
131     super(
132       baseObject,
133       container
134       );
135   }
136   // </constructors>
137

138   // <interface>
139
// <internal>
140
/**
141     Gets the nonstroking operator associated to the color space [PDF:1.6:4.5.2].
142     <h3>Remarks</h3>
143     <p>For internal use only.</p>
144     @return Nonstroking operator.
145   */

146   public String JavaDoc getFillOperator(
147     )
148   {return "cs";}
149
150   /**
151     Gets the stroking operator associated to the color space [PDF:1.6:4.5.2].
152     <h3>Remarks</h3>
153     <p>For internal use only.</p>
154     @return Stroking operator.
155   */

156   public String JavaDoc getStrokeOperator(
157     )
158   {return "CS";}
159   // </internal>
160
// </interface>
161
// </dynamic>
162
// </class>
163
}
Popular Tags