001: /*
002: Copyright © 2006,2007 Stefano Chizzolini. http://clown.stefanochizzolini.it
003:
004: Contributors:
005: * Stefano Chizzolini (original code developer, http://www.stefanochizzolini.it):
006: contributed code is Copyright © 2006,2007 by Stefano Chizzolini.
007:
008: This file should be part of the source code distribution of "PDF Clown library"
009: (the Program): see the accompanying README files for more info.
010:
011: This Program is free software; you can redistribute it and/or modify it under
012: the terms of the GNU General Public License as published by the Free Software
013: Foundation; either version 2 of the License, or (at your option) any later version.
014:
015: This Program is distributed in the hope that it will be useful, but WITHOUT ANY
016: WARRANTY, either expressed or implied; without even the implied warranty of
017: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the License for more details.
018:
019: You should have received a copy of the GNU General Public License along with this
020: Program (see README files); if not, go to the GNU website (http://www.gnu.org/).
021:
022: Redistribution and use, with or without modification, are permitted provided that such
023: redistributions retain the above copyright notice, license and disclaimer, along with
024: this list of conditions.
025: */
026:
027: package it.stefanochizzolini.clown.documents.contents.colorSpaces;
028:
029: import it.stefanochizzolini.clown.documents.Document;
030: import it.stefanochizzolini.clown.files.File;
031: import it.stefanochizzolini.clown.objects.PdfArray;
032: import it.stefanochizzolini.clown.objects.PdfDataObject;
033: import it.stefanochizzolini.clown.objects.PdfDirectObject;
034: import it.stefanochizzolini.clown.objects.PdfIndirectObject;
035: import it.stefanochizzolini.clown.objects.PdfName;
036: import it.stefanochizzolini.clown.objects.PdfObjectWrapper;
037: import it.stefanochizzolini.clown.objects.PdfReference;
038:
039: /**
040: Color space [PDF:1.6:4.5].
041: @version 0.0.4
042: */
043: public abstract class ColorSpace extends
044: PdfObjectWrapper<PdfDirectObject> {
045: // <class>
046: // <static>
047: // <interface>
048: // <public>
049: /**
050: Wraps a color space reference into a color space object.
051: @param reference Reference to a color space object.
052: @return Color space object associated to the reference.
053: */
054: public static ColorSpace wrap(PdfReference reference) {
055: return wrap(reference, null);
056: }
057:
058: /**
059: Wraps a color space base object into a color space object.
060: @param baseObject Base object of a color space object.
061: @param container Indirect object possibly containing the color space
062: base object.
063: @return Color space object associated to the base object.
064: */
065: public static ColorSpace wrap(PdfDirectObject baseObject,
066: PdfIndirectObject container) {
067: /*
068: NOTE: This is a factory method for any ColorSpace-derived object.
069: */
070: if (baseObject == null)
071: return null;
072:
073: PdfName name;
074: // Get the data object corresponding to the color space!
075: PdfDataObject baseDataObject = File.resolve(baseObject);
076: // Is it an array?
077: /*
078: NOTE: [PDF:1.6:4.5.2] A color space is defined by an array object whose
079: first element is a name object identifying the color space family. For
080: families that do not require parameters, the color space CAN be specified
081: simply by the family name itself instead of an array.
082: */
083: if (baseDataObject instanceof PdfArray) // PdfArray.
084: {
085: name = (PdfName) ((PdfArray) baseDataObject).get(0);
086: } else // PdfName (by definition).
087: {
088: name = (PdfName) baseDataObject;
089: }
090:
091: if (name.equals(PdfName.DeviceRGB))
092: return new DeviceRGBColorSpace(baseObject, container);
093: else if (name.equals(PdfName.DeviceCMYK))
094: return new DeviceCMYKColorSpace(baseObject, container);
095: else if (name.equals(PdfName.DeviceGray))
096: return new DeviceGrayColorSpace(baseObject, container);
097: else if (name.equals(PdfName.CalRGB))
098: return new CalRGBColorSpace(baseObject, container);
099: else if (name.equals(PdfName.CalGray))
100: return new CalGrayColorSpace(baseObject, container);
101: else if (name.equals(PdfName.Lab))
102: return new LabColorSpace(baseObject, container);
103: else if (name.equals(PdfName.ICCBased))
104: return new ICCBasedColorSpace(baseObject, container);
105: else
106: return null; // Should never happen.
107: }
108:
109: // </public>
110: // </interface>
111: // </static>
112:
113: // <dynamic>
114: // <constructors>
115: protected ColorSpace(Document context,
116: PdfDirectObject baseDataObject) {
117: super (context.getFile(), baseDataObject);
118: }
119:
120: protected ColorSpace(PdfDirectObject baseObject,
121: PdfIndirectObject container) {
122: super (baseObject, container);
123: }
124:
125: // </constructors>
126:
127: // <interface>
128: // <internal>
129: public abstract Color getColor(PdfDirectObject[] components);
130:
131: public abstract Color getDefaultColor();
132: // </internal>
133: // </interface>
134: // </dynamic>
135: // </class>
136: }
|