1 | /* | |
2 | * $Id: PdfXConformanceImp.java 4065 2009-09-16 23:09:11Z psoares33 $ | |
3 | * | |
4 | * Copyright 2006 Bruno Lowagie (based on code by Paulo Soares) | |
5 | * | |
6 | * The contents of this file are subject to the Mozilla Public License Version 1.1 | |
7 | * (the "License"); you may not use this file except in compliance with the License. | |
8 | * You may obtain a copy of the License at http://www.mozilla.org/MPL/ | |
9 | * | |
10 | * Software distributed under the License is distributed on an "AS IS" basis, | |
11 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | |
12 | * for the specific language governing rights and limitations under the License. | |
13 | * | |
14 | * The Original Code is 'iText, a free JAVA-PDF library'. | |
15 | * | |
16 | * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by | |
17 | * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie. | |
18 | * All Rights Reserved. | |
19 | * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer | |
20 | * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved. | |
21 | * | |
22 | * Contributor(s): all the names of the contributors are added in the source code | |
23 | * where applicable. | |
24 | * | |
25 | * Alternatively, the contents of this file may be used under the terms of the | |
26 | * LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the | |
27 | * provisions of LGPL are applicable instead of those above. If you wish to | |
28 | * allow use of your version of this file only under the terms of the LGPL | |
29 | * License and not to allow others to use your version of this file under | |
30 | * the MPL, indicate your decision by deleting the provisions above and | |
31 | * replace them with the notice and other provisions required by the LGPL. | |
32 | * If you do not delete the provisions above, a recipient may use your version | |
33 | * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE. | |
34 | * | |
35 | * This library is free software; you can redistribute it and/or modify it | |
36 | * under the terms of the MPL as stated above or under the terms of the GNU | |
37 | * Library General Public License as published by the Free Software Foundation; | |
38 | * either version 2 of the License, or any later version. | |
39 | * | |
40 | * This library is distributed in the hope that it will be useful, but WITHOUT | |
41 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | |
42 | * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more | |
43 | * details. | |
44 | * | |
45 | * If you didn't download this code from the following link, you should check if | |
46 | * you aren't using an obsolete version: | |
47 | * http://www.lowagie.com/iText/ | |
48 | */ | |
49 | ||
50 | package com.lowagie.text.pdf.internal; | |
51 | ||
52 | import java.awt.Color; | |
53 | import com.lowagie.text.error_messages.MessageLocalization; | |
54 | ||
55 | import com.lowagie.text.pdf.BaseFont; | |
56 | import com.lowagie.text.pdf.ExtendedColor; | |
57 | import com.lowagie.text.pdf.PatternColor; | |
58 | import com.lowagie.text.pdf.PdfArray; | |
59 | import com.lowagie.text.pdf.PdfDictionary; | |
60 | import com.lowagie.text.pdf.PdfGState; | |
61 | import com.lowagie.text.pdf.PdfImage; | |
62 | import com.lowagie.text.pdf.PdfName; | |
63 | import com.lowagie.text.pdf.PdfNumber; | |
64 | import com.lowagie.text.pdf.PdfObject; | |
65 | import com.lowagie.text.pdf.PdfString; | |
66 | import com.lowagie.text.pdf.PdfWriter; | |
67 | import com.lowagie.text.pdf.PdfXConformanceException; | |
68 | import com.lowagie.text.pdf.ShadingColor; | |
69 | import com.lowagie.text.pdf.SpotColor; | |
70 | import com.lowagie.text.pdf.interfaces.PdfXConformance; | |
71 | ||
72 | public class PdfXConformanceImp implements PdfXConformance { | |
73 | ||
74 | /** A key for an aspect that can be checked for PDF/X Conformance. */ | |
75 | public static final int PDFXKEY_COLOR = 1; | |
76 | /** A key for an aspect that can be checked for PDF/X Conformance. */ | |
77 | public static final int PDFXKEY_CMYK = 2; | |
78 | /** A key for an aspect that can be checked for PDF/X Conformance. */ | |
79 | public static final int PDFXKEY_RGB = 3; | |
80 | /** A key for an aspect that can be checked for PDF/X Conformance. */ | |
81 | public static final int PDFXKEY_FONT = 4; | |
82 | /** A key for an aspect that can be checked for PDF/X Conformance. */ | |
83 | public static final int PDFXKEY_IMAGE = 5; | |
84 | /** A key for an aspect that can be checked for PDF/X Conformance. */ | |
85 | public static final int PDFXKEY_GSTATE = 6; | |
86 | /** A key for an aspect that can be checked for PDF/X Conformance. */ | |
87 | public static final int PDFXKEY_LAYER = 7; | |
88 | | |
89 | /** | |
90 | * The value indicating if the PDF has to be in conformance with PDF/X. | |
91 | */ | |
92 | protected int pdfxConformance = PdfWriter.PDFXNONE; | |
93 | | |
94 | /** | |
95 | * @see com.lowagie.text.pdf.interfaces.PdfXConformance#setPDFXConformance(int) | |
96 | */ | |
97 | public void setPDFXConformance(int pdfxConformance) { | |
98 | this.pdfxConformance = pdfxConformance; | |
99 | } | |
100 | ||
101 | /** | |
102 | * @see com.lowagie.text.pdf.interfaces.PdfXConformance#getPDFXConformance() | |
103 | */ | |
104 | public int getPDFXConformance() { | |
105 | return pdfxConformance; | |
106 | } | |
107 | | |
108 | /** | |
109 | * Checks if the PDF/X Conformance is necessary. | |
110 | * @return true if the PDF has to be in conformance with any of the PDF/X specifications | |
111 | */ | |
112 | public boolean isPdfX() { | |
113 |
2
1. isPdfX : negated conditional → NO_COVERAGE 2. isPdfX : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return pdfxConformance != PdfWriter.PDFXNONE; |
114 | } | |
115 | /** | |
116 | * Checks if the PDF has to be in conformance with PDF/X-1a:2001 | |
117 | * @return true of the PDF has to be in conformance with PDF/X-1a:2001 | |
118 | */ | |
119 | public boolean isPdfX1A2001() { | |
120 |
2
1. isPdfX1A2001 : negated conditional → NO_COVERAGE 2. isPdfX1A2001 : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return pdfxConformance == PdfWriter.PDFX1A2001; |
121 | } | |
122 | /** | |
123 | * Checks if the PDF has to be in conformance with PDF/X-3:2002 | |
124 | * @return true of the PDF has to be in conformance with PDF/X-3:2002 | |
125 | */ | |
126 | public boolean isPdfX32002() { | |
127 |
2
1. isPdfX32002 : negated conditional → NO_COVERAGE 2. isPdfX32002 : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return pdfxConformance == PdfWriter.PDFX32002; |
128 | } | |
129 | | |
130 | /** | |
131 | * Checks if the PDF has to be in conformance with PDFA1 | |
132 | * @return true of the PDF has to be in conformance with PDFA1 | |
133 | */ | |
134 | public boolean isPdfA1() { | |
135 |
3
1. isPdfA1 : negated conditional → NO_COVERAGE 2. isPdfA1 : negated conditional → NO_COVERAGE 3. isPdfA1 : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return pdfxConformance == PdfWriter.PDFA1A || pdfxConformance == PdfWriter.PDFA1B; |
136 | } | |
137 | | |
138 | /** | |
139 | * Checks if the PDF has to be in conformance with PDFA1A | |
140 | * @return true of the PDF has to be in conformance with PDFA1A | |
141 | */ | |
142 | public boolean isPdfA1A() { | |
143 |
2
1. isPdfA1A : negated conditional → NO_COVERAGE 2. isPdfA1A : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return pdfxConformance == PdfWriter.PDFA1A; |
144 | } | |
145 | | |
146 | public void completeInfoDictionary(PdfDictionary info) { | |
147 |
2
1. completeInfoDictionary : negated conditional → NO_COVERAGE 2. completeInfoDictionary : negated conditional → NO_COVERAGE |
if (isPdfX() && !isPdfA1()) { |
148 |
1
1. completeInfoDictionary : negated conditional → NO_COVERAGE |
if (info.get(PdfName.GTS_PDFXVERSION) == null) { |
149 |
1
1. completeInfoDictionary : negated conditional → NO_COVERAGE |
if (isPdfX1A2001()) { |
150 |
1
1. completeInfoDictionary : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
info.put(PdfName.GTS_PDFXVERSION, new PdfString("PDF/X-1:2001")); |
151 |
1
1. completeInfoDictionary : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
info.put(new PdfName("GTS_PDFXConformance"), new PdfString("PDF/X-1a:2001")); |
152 | } | |
153 |
1
1. completeInfoDictionary : negated conditional → NO_COVERAGE |
else if (isPdfX32002()) |
154 |
1
1. completeInfoDictionary : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
info.put(PdfName.GTS_PDFXVERSION, new PdfString("PDF/X-3:2002")); |
155 | } | |
156 |
1
1. completeInfoDictionary : negated conditional → NO_COVERAGE |
if (info.get(PdfName.TITLE) == null) { |
157 |
1
1. completeInfoDictionary : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
info.put(PdfName.TITLE, new PdfString("Pdf document")); |
158 | } | |
159 |
1
1. completeInfoDictionary : negated conditional → NO_COVERAGE |
if (info.get(PdfName.CREATOR) == null) { |
160 |
1
1. completeInfoDictionary : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
info.put(PdfName.CREATOR, new PdfString("Unknown")); |
161 | } | |
162 |
1
1. completeInfoDictionary : negated conditional → NO_COVERAGE |
if (info.get(PdfName.TRAPPED) == null) { |
163 |
1
1. completeInfoDictionary : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
info.put(PdfName.TRAPPED, new PdfName("False")); |
164 | } | |
165 | } | |
166 | } | |
167 | | |
168 | public void completeExtraCatalog(PdfDictionary extraCatalog) { | |
169 |
2
1. completeExtraCatalog : negated conditional → NO_COVERAGE 2. completeExtraCatalog : negated conditional → NO_COVERAGE |
if (isPdfX() && !isPdfA1()) { |
170 |
1
1. completeExtraCatalog : negated conditional → NO_COVERAGE |
if (extraCatalog.get(PdfName.OUTPUTINTENTS) == null) { |
171 | PdfDictionary out = new PdfDictionary(PdfName.OUTPUTINTENT); | |
172 |
1
1. completeExtraCatalog : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
out.put(PdfName.OUTPUTCONDITION, new PdfString("SWOP CGATS TR 001-1995")); |
173 |
1
1. completeExtraCatalog : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
out.put(PdfName.OUTPUTCONDITIONIDENTIFIER, new PdfString("CGATS TR 001")); |
174 |
1
1. completeExtraCatalog : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
out.put(PdfName.REGISTRYNAME, new PdfString("http://www.color.org")); |
175 |
1
1. completeExtraCatalog : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
out.put(PdfName.INFO, new PdfString("")); |
176 |
1
1. completeExtraCatalog : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
out.put(PdfName.S, PdfName.GTS_PDFX); |
177 |
1
1. completeExtraCatalog : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
extraCatalog.put(PdfName.OUTPUTINTENTS, new PdfArray(out)); |
178 | } | |
179 | } | |
180 | } | |
181 | | |
182 | /** | |
183 | * Business logic that checks if a certain object is in conformance with PDF/X. | |
184 | * @param writer the writer that is supposed to write the PDF/X file | |
185 | * @param key the type of PDF/X conformance that has to be checked | |
186 | * @param obj1 the object that is checked for conformance | |
187 | */ | |
188 | public static void checkPDFXConformance(PdfWriter writer, int key, Object obj1) { | |
189 |
2
1. checkPDFXConformance : negated conditional → NO_COVERAGE 2. checkPDFXConformance : negated conditional → NO_COVERAGE |
if (writer == null || !writer.isPdfX()) |
190 | return; | |
191 | int conf = writer.getPDFXConformance(); | |
192 | switch (key) { | |
193 | case PDFXKEY_COLOR: | |
194 | switch (conf) { | |
195 | case PdfWriter.PDFX1A2001: | |
196 |
1
1. checkPDFXConformance : negated conditional → NO_COVERAGE |
if (obj1 instanceof ExtendedColor) { |
197 | ExtendedColor ec = (ExtendedColor)obj1; | |
198 | switch (ec.getType()) { | |
199 | case ExtendedColor.TYPE_CMYK: | |
200 | case ExtendedColor.TYPE_GRAY: | |
201 | return; | |
202 | case ExtendedColor.TYPE_RGB: | |
203 | throw new PdfXConformanceException(MessageLocalization.getComposedMessage("colorspace.rgb.is.not.allowed")); | |
204 | case ExtendedColor.TYPE_SEPARATION: | |
205 | SpotColor sc = (SpotColor)ec; | |
206 |
1
1. checkPDFXConformance : removed call to com/lowagie/text/pdf/internal/PdfXConformanceImp::checkPDFXConformance → NO_COVERAGE |
checkPDFXConformance(writer, PDFXKEY_COLOR, sc.getPdfSpotColor().getAlternativeCS()); |
207 | break; | |
208 | case ExtendedColor.TYPE_SHADING: | |
209 | ShadingColor xc = (ShadingColor)ec; | |
210 |
1
1. checkPDFXConformance : removed call to com/lowagie/text/pdf/internal/PdfXConformanceImp::checkPDFXConformance → NO_COVERAGE |
checkPDFXConformance(writer, PDFXKEY_COLOR, xc.getPdfShadingPattern().getShading().getColorSpace()); |
211 | break; | |
212 | case ExtendedColor.TYPE_PATTERN: | |
213 | PatternColor pc = (PatternColor)ec; | |
214 |
1
1. checkPDFXConformance : removed call to com/lowagie/text/pdf/internal/PdfXConformanceImp::checkPDFXConformance → NO_COVERAGE |
checkPDFXConformance(writer, PDFXKEY_COLOR, pc.getPainter().getDefaultColor()); |
215 | break; | |
216 | } | |
217 | } | |
218 |
1
1. checkPDFXConformance : negated conditional → NO_COVERAGE |
else if (obj1 instanceof Color) |
219 | throw new PdfXConformanceException(MessageLocalization.getComposedMessage("colorspace.rgb.is.not.allowed")); | |
220 | break; | |
221 | } | |
222 | break; | |
223 | case PDFXKEY_CMYK: | |
224 | break; | |
225 | case PDFXKEY_RGB: | |
226 |
1
1. checkPDFXConformance : negated conditional → NO_COVERAGE |
if (conf == PdfWriter.PDFX1A2001) |
227 | throw new PdfXConformanceException(MessageLocalization.getComposedMessage("colorspace.rgb.is.not.allowed")); | |
228 | break; | |
229 | case PDFXKEY_FONT: | |
230 |
1
1. checkPDFXConformance : negated conditional → NO_COVERAGE |
if (!((BaseFont)obj1).isEmbedded()) |
231 | throw new PdfXConformanceException(MessageLocalization.getComposedMessage("all.the.fonts.must.be.embedded.this.one.isn.t.1", ((BaseFont)obj1).getPostscriptFontName())); | |
232 | break; | |
233 | case PDFXKEY_IMAGE: | |
234 | PdfImage image = (PdfImage)obj1; | |
235 |
1
1. checkPDFXConformance : negated conditional → NO_COVERAGE |
if (image.get(PdfName.SMASK) != null) |
236 | throw new PdfXConformanceException(MessageLocalization.getComposedMessage("the.smask.key.is.not.allowed.in.images")); | |
237 | switch (conf) { | |
238 | case PdfWriter.PDFX1A2001: | |
239 | PdfObject cs = image.get(PdfName.COLORSPACE); | |
240 |
1
1. checkPDFXConformance : negated conditional → NO_COVERAGE |
if (cs == null) |
241 | return; | |
242 |
1
1. checkPDFXConformance : negated conditional → NO_COVERAGE |
if (cs.isName()) { |
243 |
1
1. checkPDFXConformance : negated conditional → NO_COVERAGE |
if (PdfName.DEVICERGB.equals(cs)) |
244 | throw new PdfXConformanceException(MessageLocalization.getComposedMessage("colorspace.rgb.is.not.allowed")); | |
245 | } | |
246 |
1
1. checkPDFXConformance : negated conditional → NO_COVERAGE |
else if (cs.isArray()) { |
247 |
1
1. checkPDFXConformance : negated conditional → NO_COVERAGE |
if (PdfName.CALRGB.equals(((PdfArray)cs).getPdfObject(0))) |
248 | throw new PdfXConformanceException(MessageLocalization.getComposedMessage("colorspace.calrgb.is.not.allowed")); | |
249 | } | |
250 | break; | |
251 | } | |
252 | break; | |
253 | case PDFXKEY_GSTATE: | |
254 | PdfDictionary gs = (PdfDictionary)obj1; | |
255 | PdfObject obj = gs.get(PdfName.BM); | |
256 |
3
1. checkPDFXConformance : negated conditional → NO_COVERAGE 2. checkPDFXConformance : negated conditional → NO_COVERAGE 3. checkPDFXConformance : negated conditional → NO_COVERAGE |
if (obj != null && !PdfGState.BM_NORMAL.equals(obj) && !PdfGState.BM_COMPATIBLE.equals(obj)) |
257 | throw new PdfXConformanceException(MessageLocalization.getComposedMessage("blend.mode.1.not.allowed", obj.toString())); | |
258 | obj = gs.get(PdfName.CA); | |
259 | double v = 0.0; | |
260 |
2
1. checkPDFXConformance : negated conditional → NO_COVERAGE 2. checkPDFXConformance : negated conditional → NO_COVERAGE |
if (obj != null && (v = ((PdfNumber)obj).doubleValue()) != 1.0) |
261 | throw new PdfXConformanceException(MessageLocalization.getComposedMessage("transparency.is.not.allowed.ca.eq.1", String.valueOf(v))); | |
262 | obj = gs.get(PdfName.ca); | |
263 | v = 0.0; | |
264 |
2
1. checkPDFXConformance : negated conditional → NO_COVERAGE 2. checkPDFXConformance : negated conditional → NO_COVERAGE |
if (obj != null && (v = ((PdfNumber)obj).doubleValue()) != 1.0) |
265 | throw new PdfXConformanceException(MessageLocalization.getComposedMessage("transparency.is.not.allowed.ca.eq.1", String.valueOf(v))); | |
266 | break; | |
267 | case PDFXKEY_LAYER: | |
268 | throw new PdfXConformanceException(MessageLocalization.getComposedMessage("layers.are.not.allowed")); | |
269 | } | |
270 | } | |
271 | } | |
Mutations | ||
113 |
1.1 2.2 |
|
120 |
1.1 2.2 |
|
127 |
1.1 2.2 |
|
135 |
1.1 2.2 3.3 |
|
143 |
1.1 2.2 |
|
147 |
1.1 2.2 |
|
148 |
1.1 |
|
149 |
1.1 |
|
150 |
1.1 |
|
151 |
1.1 |
|
153 |
1.1 |
|
154 |
1.1 |
|
156 |
1.1 |
|
157 |
1.1 |
|
159 |
1.1 |
|
160 |
1.1 |
|
162 |
1.1 |
|
163 |
1.1 |
|
169 |
1.1 2.2 |
|
170 |
1.1 |
|
172 |
1.1 |
|
173 |
1.1 |
|
174 |
1.1 |
|
175 |
1.1 |
|
176 |
1.1 |
|
177 |
1.1 |
|
189 |
1.1 2.2 |
|
196 |
1.1 |
|
206 |
1.1 |
|
210 |
1.1 |
|
214 |
1.1 |
|
218 |
1.1 |
|
226 |
1.1 |
|
230 |
1.1 |
|
235 |
1.1 |
|
240 |
1.1 |
|
242 |
1.1 |
|
243 |
1.1 |
|
246 |
1.1 |
|
247 |
1.1 |
|
256 |
1.1 2.2 3.3 |
|
260 |
1.1 2.2 |
|
264 |
1.1 2.2 |