001: /*
002: * Copyright (c) 2007, intarsys consulting GmbH
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions are met:
006: *
007: * - Redistributions of source code must retain the above copyright notice,
008: * this list of conditions and the following disclaimer.
009: *
010: * - Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: *
014: * - Neither the name of intarsys nor the names of its contributors may be used
015: * to endorse or promote products derived from this software without specific
016: * prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
020: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
021: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
022: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
023: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
024: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
025: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
026: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
027: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
028: * POSSIBILITY OF SUCH DAMAGE.
029: */
030: package de.intarsys.pdf.pd;
031:
032: import java.io.ByteArrayOutputStream;
033: import java.io.IOException;
034: import java.io.InputStream;
035:
036: import de.intarsys.pdf.cos.COSInteger;
037: import de.intarsys.pdf.cos.COSName;
038: import de.intarsys.pdf.cos.COSObject;
039: import de.intarsys.pdf.cos.COSStream;
040: import de.intarsys.pdf.filter.Filter;
041: import de.intarsys.tools.stream.StreamTools;
042:
043: /**
044: * The output intent for the associated object.
045: *
046: */
047: public class PDOutputIntent extends PDObject {
048: /**
049: * The meta class implementation
050: */
051: public static class MetaClass extends PDObject.MetaClass {
052: protected MetaClass(Class instanceClass) {
053: super (instanceClass);
054: }
055:
056: protected boolean isIndirect() {
057: return false;
058: }
059: }
060:
061: /** The meta class instance */
062: public static final MetaClass META = new MetaClass(MetaClass.class
063: .getDeclaringClass());
064:
065: /** who am i */
066: public static final COSName DK_OutputIntent = COSName
067: .constant("OutputIntent");
068:
069: public static final COSName DK_S = COSName.constant("S");
070:
071: public static final COSName DK_OutputCondition = COSName
072: .constant("OutputCondition");
073:
074: public static final COSName DK_OutputConditionIdentifier = COSName
075: .constant("OutputConditionIdentifier");
076:
077: public static final COSName DK_RegistryName = COSName
078: .constant("RegistryName");
079:
080: public static final COSName DK_Info = COSName.constant("Info");
081:
082: public static final COSName DK_DestOutputProfile = COSName
083: .constant("DestOutputProfile");
084:
085: protected PDOutputIntent(COSObject object) {
086: super (object);
087: }
088:
089: /*
090: * (non-Javadoc)
091: *
092: * @see de.intarsys.pdf.pd.PDObject#cosGetExpectedType()
093: */
094: protected COSName cosGetExpectedType() {
095: return DK_OutputIntent;
096: }
097:
098: public COSStream cosGetOutputProfile() {
099: return cosGetDict().get(DK_DestOutputProfile).asStream();
100: }
101:
102: public boolean importRGB_ICCProfile() {
103: InputStream defaultICC = this .getClass().getResourceAsStream(
104: "sRGB_IEC61966-2-1_noBPC.icc");
105: return importICCProfile(defaultICC, 3);
106: }
107:
108: public boolean importCMYK_ICCProfile() {
109: InputStream defaultICC = this .getClass().getResourceAsStream(
110: "ISOcoated_v2_eci.icc");
111: return importICCProfile(defaultICC, 4);
112: }
113:
114: public boolean importICCProfile(InputStream is, int numComponents) {
115: try {
116: ByteArrayOutputStream bos = new ByteArrayOutputStream();
117: StreamTools.copyStream(is, bos);
118: COSStream profile = COSStream.create(null);
119: profile.setEncodedBytes(bos.toByteArray());
120: profile.addFilter(Filter.CN_Filter_FlateDecode);
121: profile.getDict().put(PDCSICCBased.DK_N,
122: COSInteger.create(numComponents));
123: cosSetField(DK_DestOutputProfile, profile);
124: } catch (IOException e) {
125: return false;
126: }
127: return true;
128: }
129: }
|