1 | /* | |
2 | * Copyright 2002 Paulo Soares | |
3 | * | |
4 | * The contents of this file are subject to the Mozilla Public License Version 1.1 | |
5 | * (the "License"); you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at http://www.mozilla.org/MPL/ | |
7 | * | |
8 | * Software distributed under the License is distributed on an "AS IS" basis, | |
9 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | |
10 | * for the specific language governing rights and limitations under the License. | |
11 | * | |
12 | * The Original Code is 'iText, a free JAVA-PDF library'. | |
13 | * | |
14 | * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by | |
15 | * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie. | |
16 | * All Rights Reserved. | |
17 | * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer | |
18 | * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved. | |
19 | * | |
20 | * Contributor(s): all the names of the contributors are added in the source code | |
21 | * where applicable. | |
22 | * | |
23 | * Alternatively, the contents of this file may be used under the terms of the | |
24 | * LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the | |
25 | * provisions of LGPL are applicable instead of those above. If you wish to | |
26 | * allow use of your version of this file only under the terms of the LGPL | |
27 | * License and not to allow others to use your version of this file under | |
28 | * the MPL, indicate your decision by deleting the provisions above and | |
29 | * replace them with the notice and other provisions required by the LGPL. | |
30 | * If you do not delete the provisions above, a recipient may use your version | |
31 | * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE. | |
32 | * | |
33 | * This library is free software; you can redistribute it and/or modify it | |
34 | * under the terms of the MPL as stated above or under the terms of the GNU | |
35 | * Library General Public License as published by the Free Software Foundation; | |
36 | * either version 2 of the License, or any later version. | |
37 | * | |
38 | * This library is distributed in the hope that it will be useful, but WITHOUT | |
39 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | |
40 | * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more | |
41 | * details. | |
42 | * | |
43 | * If you didn't download this code from the following link, you should check if | |
44 | * you aren't using an obsolete version: | |
45 | * http://www.lowagie.com/iText/ | |
46 | */ | |
47 | package com.lowagie.text.pdf; | |
48 | ||
49 | import java.awt.Color; | |
50 | import java.io.IOException; | |
51 | import com.lowagie.text.error_messages.MessageLocalization; | |
52 | /** Implements the shading dictionary (or stream). | |
53 | * | |
54 | * @author Paulo Soares (psoares@consiste.pt) | |
55 | */ | |
56 | public class PdfShading { | |
57 | ||
58 | protected PdfDictionary shading; | |
59 | | |
60 | protected PdfWriter writer; | |
61 | | |
62 | protected int shadingType; | |
63 | | |
64 | protected ColorDetails colorDetails; | |
65 | | |
66 | protected PdfName shadingName; | |
67 | | |
68 | protected PdfIndirectReference shadingReference; | |
69 | | |
70 | private Color cspace; | |
71 | | |
72 | /** Holds value of property bBox. */ | |
73 | protected float[] bBox; | |
74 | | |
75 | /** Holds value of property antiAlias. */ | |
76 | protected boolean antiAlias = false; | |
77 | | |
78 | /** Creates new PdfShading */ | |
79 | protected PdfShading(PdfWriter writer) { | |
80 | this.writer = writer; | |
81 | } | |
82 | | |
83 | protected void setColorSpace(Color color) { | |
84 | cspace = color; | |
85 | int type = ExtendedColor.getType(color); | |
86 | PdfObject colorSpace = null; | |
87 | switch (type) { | |
88 | case ExtendedColor.TYPE_GRAY: { | |
89 | colorSpace = PdfName.DEVICEGRAY; | |
90 | break; | |
91 | } | |
92 | case ExtendedColor.TYPE_CMYK: { | |
93 | colorSpace = PdfName.DEVICECMYK; | |
94 | break; | |
95 | } | |
96 | case ExtendedColor.TYPE_SEPARATION: { | |
97 | SpotColor spot = (SpotColor)color; | |
98 | colorDetails = writer.addSimple(spot.getPdfSpotColor()); | |
99 | colorSpace = colorDetails.getIndirectReference(); | |
100 | break; | |
101 | } | |
102 | case ExtendedColor.TYPE_PATTERN: | |
103 | case ExtendedColor.TYPE_SHADING: { | |
104 |
1
1. setColorSpace : removed call to com/lowagie/text/pdf/PdfShading::throwColorSpaceError → NO_COVERAGE |
throwColorSpaceError(); |
105 | } | |
106 | default: | |
107 | colorSpace = PdfName.DEVICERGB; | |
108 | break; | |
109 | } | |
110 |
1
1. setColorSpace : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
shading.put(PdfName.COLORSPACE, colorSpace); |
111 | } | |
112 | | |
113 | public Color getColorSpace() { | |
114 | return cspace; | |
115 | } | |
116 | | |
117 | public static void throwColorSpaceError() { | |
118 | throw new IllegalArgumentException(MessageLocalization.getComposedMessage("a.tiling.or.shading.pattern.cannot.be.used.as.a.color.space.in.a.shading.pattern")); | |
119 | } | |
120 | | |
121 | public static void checkCompatibleColors(Color c1, Color c2) { | |
122 | int type1 = ExtendedColor.getType(c1); | |
123 | int type2 = ExtendedColor.getType(c2); | |
124 |
1
1. checkCompatibleColors : negated conditional → NO_COVERAGE |
if (type1 != type2) |
125 | throw new IllegalArgumentException(MessageLocalization.getComposedMessage("both.colors.must.be.of.the.same.type")); | |
126 |
2
1. checkCompatibleColors : negated conditional → NO_COVERAGE 2. checkCompatibleColors : negated conditional → NO_COVERAGE |
if (type1 == ExtendedColor.TYPE_SEPARATION && ((SpotColor)c1).getPdfSpotColor() != ((SpotColor)c2).getPdfSpotColor()) |
127 | throw new IllegalArgumentException(MessageLocalization.getComposedMessage("the.spot.color.must.be.the.same.only.the.tint.can.vary")); | |
128 |
2
1. checkCompatibleColors : negated conditional → NO_COVERAGE 2. checkCompatibleColors : negated conditional → NO_COVERAGE |
if (type1 == ExtendedColor.TYPE_PATTERN || type1 == ExtendedColor.TYPE_SHADING) |
129 |
1
1. checkCompatibleColors : removed call to com/lowagie/text/pdf/PdfShading::throwColorSpaceError → NO_COVERAGE |
throwColorSpaceError(); |
130 | } | |
131 | | |
132 | public static float[] getColorArray(Color color) { | |
133 | int type = ExtendedColor.getType(color); | |
134 | switch (type) { | |
135 | case ExtendedColor.TYPE_GRAY: { | |
136 |
1
1. getColorArray : mutated return of Object value for com/lowagie/text/pdf/PdfShading::getColorArray to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return new float[]{((GrayColor)color).getGray()}; |
137 | } | |
138 | case ExtendedColor.TYPE_CMYK: { | |
139 | CMYKColor cmyk = (CMYKColor)color; | |
140 |
1
1. getColorArray : mutated return of Object value for com/lowagie/text/pdf/PdfShading::getColorArray to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return new float[]{cmyk.getCyan(), cmyk.getMagenta(), cmyk.getYellow(), cmyk.getBlack()}; |
141 | } | |
142 | case ExtendedColor.TYPE_SEPARATION: { | |
143 |
1
1. getColorArray : mutated return of Object value for com/lowagie/text/pdf/PdfShading::getColorArray to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return new float[]{((SpotColor)color).getTint()}; |
144 | } | |
145 | case ExtendedColor.TYPE_RGB: { | |
146 |
4
1. getColorArray : Replaced float division with multiplication → NO_COVERAGE 2. getColorArray : Replaced float division with multiplication → NO_COVERAGE 3. getColorArray : Replaced float division with multiplication → NO_COVERAGE 4. getColorArray : mutated return of Object value for com/lowagie/text/pdf/PdfShading::getColorArray to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return new float[]{color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f}; |
147 | } | |
148 | } | |
149 |
1
1. getColorArray : removed call to com/lowagie/text/pdf/PdfShading::throwColorSpaceError → NO_COVERAGE |
throwColorSpaceError(); |
150 |
1
1. getColorArray : mutated return of Object value for com/lowagie/text/pdf/PdfShading::getColorArray to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return null; |
151 | } | |
152 | ||
153 | public static PdfShading type1(PdfWriter writer, Color colorSpace, float[] domain, float[] tMatrix, PdfFunction function) { | |
154 | PdfShading sp = new PdfShading(writer); | |
155 | sp.shading = new PdfDictionary(); | |
156 | sp.shadingType = 1; | |
157 |
1
1. type1 : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
sp.shading.put(PdfName.SHADINGTYPE, new PdfNumber(sp.shadingType)); |
158 |
1
1. type1 : removed call to com/lowagie/text/pdf/PdfShading::setColorSpace → NO_COVERAGE |
sp.setColorSpace(colorSpace); |
159 |
1
1. type1 : negated conditional → NO_COVERAGE |
if (domain != null) |
160 |
1
1. type1 : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
sp.shading.put(PdfName.DOMAIN, new PdfArray(domain)); |
161 |
1
1. type1 : negated conditional → NO_COVERAGE |
if (tMatrix != null) |
162 |
1
1. type1 : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
sp.shading.put(PdfName.MATRIX, new PdfArray(tMatrix)); |
163 |
1
1. type1 : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
sp.shading.put(PdfName.FUNCTION, function.getReference()); |
164 |
1
1. type1 : mutated return of Object value for com/lowagie/text/pdf/PdfShading::type1 to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return sp; |
165 | } | |
166 | | |
167 | public static PdfShading type2(PdfWriter writer, Color colorSpace, float[] coords, float[] domain, PdfFunction function, boolean[] extend) { | |
168 | PdfShading sp = new PdfShading(writer); | |
169 | sp.shading = new PdfDictionary(); | |
170 | sp.shadingType = 2; | |
171 |
1
1. type2 : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
sp.shading.put(PdfName.SHADINGTYPE, new PdfNumber(sp.shadingType)); |
172 |
1
1. type2 : removed call to com/lowagie/text/pdf/PdfShading::setColorSpace → NO_COVERAGE |
sp.setColorSpace(colorSpace); |
173 |
1
1. type2 : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
sp.shading.put(PdfName.COORDS, new PdfArray(coords)); |
174 |
1
1. type2 : negated conditional → NO_COVERAGE |
if (domain != null) |
175 |
1
1. type2 : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
sp.shading.put(PdfName.DOMAIN, new PdfArray(domain)); |
176 |
1
1. type2 : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
sp.shading.put(PdfName.FUNCTION, function.getReference()); |
177 |
3
1. type2 : negated conditional → NO_COVERAGE 2. type2 : negated conditional → NO_COVERAGE 3. type2 : negated conditional → NO_COVERAGE |
if (extend != null && (extend[0] || extend[1])) { |
178 |
1
1. type2 : negated conditional → NO_COVERAGE |
PdfArray array = new PdfArray(extend[0] ? PdfBoolean.PDFTRUE : PdfBoolean.PDFFALSE); |
179 |
1
1. type2 : negated conditional → NO_COVERAGE |
array.add(extend[1] ? PdfBoolean.PDFTRUE : PdfBoolean.PDFFALSE); |
180 |
1
1. type2 : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
sp.shading.put(PdfName.EXTEND, array); |
181 | } | |
182 |
1
1. type2 : mutated return of Object value for com/lowagie/text/pdf/PdfShading::type2 to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return sp; |
183 | } | |
184 | ||
185 | public static PdfShading type3(PdfWriter writer, Color colorSpace, float[] coords, float[] domain, PdfFunction function, boolean[] extend) { | |
186 | PdfShading sp = type2(writer, colorSpace, coords, domain, function, extend); | |
187 | sp.shadingType = 3; | |
188 |
1
1. type3 : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
sp.shading.put(PdfName.SHADINGTYPE, new PdfNumber(sp.shadingType)); |
189 |
1
1. type3 : mutated return of Object value for com/lowagie/text/pdf/PdfShading::type3 to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return sp; |
190 | } | |
191 | | |
192 | public static PdfShading simpleAxial(PdfWriter writer, float x0, float y0, float x1, float y1, Color startColor, Color endColor, boolean extendStart, boolean extendEnd) { | |
193 |
1
1. simpleAxial : removed call to com/lowagie/text/pdf/PdfShading::checkCompatibleColors → NO_COVERAGE |
checkCompatibleColors(startColor, endColor); |
194 | PdfFunction function = PdfFunction.type2(writer, new float[]{0, 1}, null, getColorArray(startColor), | |
195 | getColorArray(endColor), 1); | |
196 |
1
1. simpleAxial : mutated return of Object value for com/lowagie/text/pdf/PdfShading::simpleAxial to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return type2(writer, startColor, new float[]{x0, y0, x1, y1}, null, function, new boolean[]{extendStart, extendEnd}); |
197 | } | |
198 | | |
199 | public static PdfShading simpleAxial(PdfWriter writer, float x0, float y0, float x1, float y1, Color startColor, Color endColor) { | |
200 |
1
1. simpleAxial : mutated return of Object value for com/lowagie/text/pdf/PdfShading::simpleAxial to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return simpleAxial(writer, x0, y0, x1, y1, startColor, endColor, true, true); |
201 | } | |
202 | | |
203 | public static PdfShading simpleRadial(PdfWriter writer, float x0, float y0, float r0, float x1, float y1, float r1, Color startColor, Color endColor, boolean extendStart, boolean extendEnd) { | |
204 |
1
1. simpleRadial : removed call to com/lowagie/text/pdf/PdfShading::checkCompatibleColors → NO_COVERAGE |
checkCompatibleColors(startColor, endColor); |
205 | PdfFunction function = PdfFunction.type2(writer, new float[]{0, 1}, null, getColorArray(startColor), | |
206 | getColorArray(endColor), 1); | |
207 |
1
1. simpleRadial : mutated return of Object value for com/lowagie/text/pdf/PdfShading::simpleRadial to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return type3(writer, startColor, new float[]{x0, y0, r0, x1, y1, r1}, null, function, new boolean[]{extendStart, extendEnd}); |
208 | } | |
209 | ||
210 | public static PdfShading simpleRadial(PdfWriter writer, float x0, float y0, float r0, float x1, float y1, float r1, Color startColor, Color endColor) { | |
211 |
1
1. simpleRadial : mutated return of Object value for com/lowagie/text/pdf/PdfShading::simpleRadial to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return simpleRadial(writer, x0, y0, r0, x1, y1, r1, startColor, endColor, true, true); |
212 | } | |
213 | ||
214 | PdfName getShadingName() { | |
215 | return shadingName; | |
216 | } | |
217 | | |
218 | PdfIndirectReference getShadingReference() { | |
219 |
1
1. getShadingReference : negated conditional → NO_COVERAGE |
if (shadingReference == null) |
220 | shadingReference = writer.getPdfIndirectReference(); | |
221 |
1
1. getShadingReference : mutated return of Object value for com/lowagie/text/pdf/PdfShading::getShadingReference to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return shadingReference; |
222 | } | |
223 | | |
224 | void setName(int number) { | |
225 | shadingName = new PdfName("Sh" + number); | |
226 | } | |
227 | | |
228 | void addToBody() throws IOException { | |
229 |
1
1. addToBody : negated conditional → NO_COVERAGE |
if (bBox != null) |
230 |
1
1. addToBody : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
shading.put(PdfName.BBOX, new PdfArray(bBox)); |
231 |
1
1. addToBody : negated conditional → NO_COVERAGE |
if (antiAlias) |
232 |
1
1. addToBody : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
shading.put(PdfName.ANTIALIAS, PdfBoolean.PDFTRUE); |
233 | writer.addToBody(shading, getShadingReference()); | |
234 | } | |
235 | | |
236 | PdfWriter getWriter() { | |
237 | return writer; | |
238 | } | |
239 | | |
240 | ColorDetails getColorDetails() { | |
241 | return colorDetails; | |
242 | } | |
243 | | |
244 | public float[] getBBox() { | |
245 | return bBox; | |
246 | } | |
247 | | |
248 | public void setBBox(float[] bBox) { | |
249 |
1
1. setBBox : negated conditional → NO_COVERAGE |
if (bBox.length != 4) |
250 | throw new IllegalArgumentException(MessageLocalization.getComposedMessage("bbox.must.be.a.4.element.array")); | |
251 | this.bBox = bBox; | |
252 | } | |
253 | | |
254 | public boolean isAntiAlias() { | |
255 | return antiAlias; | |
256 | } | |
257 | | |
258 | public void setAntiAlias(boolean antiAlias) { | |
259 | this.antiAlias = antiAlias; | |
260 | } | |
261 | | |
262 | } | |
Mutations | ||
104 |
1.1 |
|
110 |
1.1 |
|
124 |
1.1 |
|
126 |
1.1 2.2 |
|
128 |
1.1 2.2 |
|
129 |
1.1 |
|
136 |
1.1 |
|
140 |
1.1 |
|
143 |
1.1 |
|
146 |
1.1 2.2 3.3 4.4 |
|
149 |
1.1 |
|
150 |
1.1 |
|
157 |
1.1 |
|
158 |
1.1 |
|
159 |
1.1 |
|
160 |
1.1 |
|
161 |
1.1 |
|
162 |
1.1 |
|
163 |
1.1 |
|
164 |
1.1 |
|
171 |
1.1 |
|
172 |
1.1 |
|
173 |
1.1 |
|
174 |
1.1 |
|
175 |
1.1 |
|
176 |
1.1 |
|
177 |
1.1 2.2 3.3 |
|
178 |
1.1 |
|
179 |
1.1 |
|
180 |
1.1 |
|
182 |
1.1 |
|
188 |
1.1 |
|
189 |
1.1 |
|
193 |
1.1 |
|
196 |
1.1 |
|
200 |
1.1 |
|
204 |
1.1 |
|
207 |
1.1 |
|
211 |
1.1 |
|
219 |
1.1 |
|
221 |
1.1 |
|
229 |
1.1 |
|
230 |
1.1 |
|
231 |
1.1 |
|
232 |
1.1 |
|
249 |
1.1 |