1 | /* | |
2 | * $Id: PageResources.java 3117 2008-01-31 05:53:22Z xlv $ | |
3 | * | |
4 | * Copyright 2003-2005 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 | package com.lowagie.text.pdf; | |
50 | ||
51 | import java.util.HashMap; | |
52 | ||
53 | class PageResources { | |
54 | | |
55 | protected PdfDictionary fontDictionary = new PdfDictionary(); | |
56 | protected PdfDictionary xObjectDictionary = new PdfDictionary(); | |
57 | protected PdfDictionary colorDictionary = new PdfDictionary(); | |
58 | protected PdfDictionary patternDictionary = new PdfDictionary(); | |
59 | protected PdfDictionary shadingDictionary = new PdfDictionary(); | |
60 | protected PdfDictionary extGStateDictionary = new PdfDictionary(); | |
61 | protected PdfDictionary propertyDictionary = new PdfDictionary(); | |
62 | protected HashMap forbiddenNames; | |
63 | protected PdfDictionary originalResources; | |
64 | protected int[] namePtr = {0}; | |
65 | protected HashMap usedNames; | |
66 | ||
67 | PageResources() { | |
68 | } | |
69 | | |
70 | void setOriginalResources(PdfDictionary resources, int[] newNamePtr) { | |
71 |
1
1. setOriginalResources : negated conditional → NO_COVERAGE |
if (newNamePtr != null) |
72 | namePtr = newNamePtr; | |
73 | forbiddenNames = new HashMap(); | |
74 | usedNames = new HashMap(); | |
75 |
1
1. setOriginalResources : negated conditional → NO_COVERAGE |
if (resources == null) |
76 | return; | |
77 | originalResources = new PdfDictionary(); | |
78 |
1
1. setOriginalResources : removed call to com/lowagie/text/pdf/PdfDictionary::merge → NO_COVERAGE |
originalResources.merge(resources); |
79 | for (PdfName key : resources.getKeys()) { | |
80 | PdfObject sub = PdfReader.getPdfObject(resources.get(key)); | |
81 |
2
1. setOriginalResources : negated conditional → NO_COVERAGE 2. setOriginalResources : negated conditional → NO_COVERAGE |
if (sub != null && sub.isDictionary()) { |
82 | PdfDictionary dic = (PdfDictionary) sub; | |
83 | for (PdfName pdfName : dic.getKeys()) { | |
84 | forbiddenNames.put(pdfName, null); | |
85 | } | |
86 | PdfDictionary dic2 = new PdfDictionary(); | |
87 |
1
1. setOriginalResources : removed call to com/lowagie/text/pdf/PdfDictionary::merge → NO_COVERAGE |
dic2.merge(dic); |
88 |
1
1. setOriginalResources : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
originalResources.put(key, dic2); |
89 | } | |
90 | } | |
91 | } | |
92 | | |
93 | PdfName translateName(PdfName name) { | |
94 | PdfName translated = name; | |
95 |
1
1. translateName : negated conditional → NO_COVERAGE |
if (forbiddenNames != null) { |
96 | translated = (PdfName)usedNames.get(name); | |
97 |
1
1. translateName : negated conditional → NO_COVERAGE |
if (translated == null) { |
98 | do { | |
99 |
1
1. translateName : Replaced integer addition with subtraction → NO_COVERAGE |
translated = new PdfName("Xi" + (namePtr[0]++)); |
100 |
1
1. translateName : negated conditional → NO_COVERAGE |
} while (forbiddenNames.containsKey(translated)); |
101 | usedNames.put(name, translated); | |
102 | } | |
103 | } | |
104 |
1
1. translateName : mutated return of Object value for com/lowagie/text/pdf/PageResources::translateName to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return translated; |
105 | } | |
106 | | |
107 | PdfName addFont(PdfName name, PdfIndirectReference reference) { | |
108 | name = translateName(name); | |
109 |
1
1. addFont : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
fontDictionary.put(name, reference); |
110 |
1
1. addFont : mutated return of Object value for com/lowagie/text/pdf/PageResources::addFont to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return name; |
111 | } | |
112 | ||
113 | PdfName addXObject(PdfName name, PdfIndirectReference reference) { | |
114 | name = translateName(name); | |
115 |
1
1. addXObject : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
xObjectDictionary.put(name, reference); |
116 |
1
1. addXObject : mutated return of Object value for com/lowagie/text/pdf/PageResources::addXObject to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return name; |
117 | } | |
118 | ||
119 | PdfName addColor(PdfName name, PdfIndirectReference reference) { | |
120 | name = translateName(name); | |
121 |
1
1. addColor : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
colorDictionary.put(name, reference); |
122 |
1
1. addColor : mutated return of Object value for com/lowagie/text/pdf/PageResources::addColor to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return name; |
123 | } | |
124 | ||
125 | void addDefaultColor(PdfName name, PdfObject obj) { | |
126 |
2
1. addDefaultColor : negated conditional → NO_COVERAGE 2. addDefaultColor : negated conditional → NO_COVERAGE |
if (obj == null || obj.isNull()) |
127 |
1
1. addDefaultColor : removed call to com/lowagie/text/pdf/PdfDictionary::remove → NO_COVERAGE |
colorDictionary.remove(name); |
128 | else | |
129 |
1
1. addDefaultColor : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
colorDictionary.put(name, obj); |
130 | } | |
131 | ||
132 | void addDefaultColor(PdfDictionary dic) { | |
133 | colorDictionary.merge(dic); | |
134 | } | |
135 | ||
136 | void addDefaultColorDiff(PdfDictionary dic) { | |
137 | colorDictionary.mergeDifferent(dic); | |
138 | } | |
139 | ||
140 | PdfName addShading(PdfName name, PdfIndirectReference reference) { | |
141 | name = translateName(name); | |
142 |
1
1. addShading : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
shadingDictionary.put(name, reference); |
143 |
1
1. addShading : mutated return of Object value for com/lowagie/text/pdf/PageResources::addShading to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return name; |
144 | } | |
145 | | |
146 | PdfName addPattern(PdfName name, PdfIndirectReference reference) { | |
147 | name = translateName(name); | |
148 |
1
1. addPattern : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
patternDictionary.put(name, reference); |
149 |
1
1. addPattern : mutated return of Object value for com/lowagie/text/pdf/PageResources::addPattern to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return name; |
150 | } | |
151 | ||
152 | PdfName addExtGState(PdfName name, PdfIndirectReference reference) { | |
153 | name = translateName(name); | |
154 |
1
1. addExtGState : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
extGStateDictionary.put(name, reference); |
155 |
1
1. addExtGState : mutated return of Object value for com/lowagie/text/pdf/PageResources::addExtGState to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return name; |
156 | } | |
157 | ||
158 | PdfName addProperty(PdfName name, PdfIndirectReference reference) { | |
159 | name = translateName(name); | |
160 |
1
1. addProperty : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
propertyDictionary.put(name, reference); |
161 |
1
1. addProperty : mutated return of Object value for com/lowagie/text/pdf/PageResources::addProperty to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return name; |
162 | } | |
163 | ||
164 | PdfDictionary getResources() { | |
165 | PdfResources resources = new PdfResources(); | |
166 |
1
1. getResources : negated conditional → NO_COVERAGE |
if (originalResources != null) |
167 |
1
1. getResources : removed call to com/lowagie/text/pdf/PdfResources::putAll → NO_COVERAGE |
resources.putAll(originalResources); |
168 |
1
1. getResources : removed call to com/lowagie/text/pdf/PdfResources::put → NO_COVERAGE |
resources.put(PdfName.PROCSET, new PdfLiteral("[/PDF /Text /ImageB /ImageC /ImageI]")); |
169 |
1
1. getResources : removed call to com/lowagie/text/pdf/PdfResources::add → NO_COVERAGE |
resources.add(PdfName.FONT, fontDictionary); |
170 |
1
1. getResources : removed call to com/lowagie/text/pdf/PdfResources::add → NO_COVERAGE |
resources.add(PdfName.XOBJECT, xObjectDictionary); |
171 |
1
1. getResources : removed call to com/lowagie/text/pdf/PdfResources::add → NO_COVERAGE |
resources.add(PdfName.COLORSPACE, colorDictionary); |
172 |
1
1. getResources : removed call to com/lowagie/text/pdf/PdfResources::add → NO_COVERAGE |
resources.add(PdfName.PATTERN, patternDictionary); |
173 |
1
1. getResources : removed call to com/lowagie/text/pdf/PdfResources::add → NO_COVERAGE |
resources.add(PdfName.SHADING, shadingDictionary); |
174 |
1
1. getResources : removed call to com/lowagie/text/pdf/PdfResources::add → NO_COVERAGE |
resources.add(PdfName.EXTGSTATE, extGStateDictionary); |
175 |
1
1. getResources : removed call to com/lowagie/text/pdf/PdfResources::add → NO_COVERAGE |
resources.add(PdfName.PROPERTIES, propertyDictionary); |
176 |
1
1. getResources : mutated return of Object value for com/lowagie/text/pdf/PageResources::getResources to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return resources; |
177 | } | |
178 | | |
179 | boolean hasResources() { | |
180 |
3
1. hasResources : changed conditional boundary → NO_COVERAGE 2. hasResources : negated conditional → NO_COVERAGE 3. hasResources : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return (fontDictionary.size() > 0 |
181 |
2
1. hasResources : changed conditional boundary → NO_COVERAGE 2. hasResources : negated conditional → NO_COVERAGE |
|| xObjectDictionary.size() > 0 |
182 |
2
1. hasResources : changed conditional boundary → NO_COVERAGE 2. hasResources : negated conditional → NO_COVERAGE |
|| colorDictionary.size() > 0 |
183 |
2
1. hasResources : changed conditional boundary → NO_COVERAGE 2. hasResources : negated conditional → NO_COVERAGE |
|| patternDictionary.size() > 0 |
184 |
2
1. hasResources : changed conditional boundary → NO_COVERAGE 2. hasResources : negated conditional → NO_COVERAGE |
|| shadingDictionary.size() > 0 |
185 |
2
1. hasResources : changed conditional boundary → NO_COVERAGE 2. hasResources : negated conditional → NO_COVERAGE |
|| extGStateDictionary.size() > 0 |
186 |
2
1. hasResources : changed conditional boundary → NO_COVERAGE 2. hasResources : negated conditional → NO_COVERAGE |
|| propertyDictionary.size() > 0); |
187 | } | |
188 | } | |
Mutations | ||
71 |
1.1 |
|
75 |
1.1 |
|
78 |
1.1 |
|
81 |
1.1 2.2 |
|
87 |
1.1 |
|
88 |
1.1 |
|
95 |
1.1 |
|
97 |
1.1 |
|
99 |
1.1 |
|
100 |
1.1 |
|
104 |
1.1 |
|
109 |
1.1 |
|
110 |
1.1 |
|
115 |
1.1 |
|
116 |
1.1 |
|
121 |
1.1 |
|
122 |
1.1 |
|
126 |
1.1 2.2 |
|
127 |
1.1 |
|
129 |
1.1 |
|
142 |
1.1 |
|
143 |
1.1 |
|
148 |
1.1 |
|
149 |
1.1 |
|
154 |
1.1 |
|
155 |
1.1 |
|
160 |
1.1 |
|
161 |
1.1 |
|
166 |
1.1 |
|
167 |
1.1 |
|
168 |
1.1 |
|
169 |
1.1 |
|
170 |
1.1 |
|
171 |
1.1 |
|
172 |
1.1 |
|
173 |
1.1 |
|
174 |
1.1 |
|
175 |
1.1 |
|
176 |
1.1 |
|
180 |
1.1 2.2 3.3 |
|
181 |
1.1 2.2 |
|
182 |
1.1 2.2 |
|
183 |
1.1 2.2 |
|
184 |
1.1 2.2 |
|
185 |
1.1 2.2 |
|
186 |
1.1 2.2 |