1 | /* | |
2 | * Copyright 2004 by 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 | ||
48 | package com.lowagie.text.pdf; | |
49 | ||
50 | import java.util.ArrayList; | |
51 | import com.lowagie.text.error_messages.MessageLocalization; | |
52 | /** | |
53 | * An optional content group is a dictionary representing a collection of graphics | |
54 | * that can be made visible or invisible dynamically by users of viewer applications. | |
55 | * In iText they are referenced as layers. | |
56 | * | |
57 | * @author Paulo Soares (psoares@consiste.pt) | |
58 | */ | |
59 | public class PdfLayer extends PdfDictionary implements PdfOCG { | |
60 | protected PdfIndirectReference ref; | |
61 | protected ArrayList<PdfLayer> children; | |
62 | protected PdfLayer parent; | |
63 | protected String title; | |
64 | ||
65 | /** | |
66 | * Holds value of property on. | |
67 | */ | |
68 | private boolean on = true; | |
69 | | |
70 | /** | |
71 | * Holds value of property onPanel. | |
72 | */ | |
73 | private boolean onPanel = true; | |
74 | | |
75 | PdfLayer(String title) { | |
76 | this.title = title; | |
77 | } | |
78 | | |
79 | /** | |
80 | * Creates a title layer. A title layer is not really a layer but a collection of layers | |
81 | * under the same title heading. | |
82 | * @param title the title text | |
83 | * @param writer the <CODE>PdfWriter</CODE> | |
84 | * @return the title layer | |
85 | */ | |
86 | public static PdfLayer createTitle(String title, PdfWriter writer) { | |
87 |
1
1. createTitle : negated conditional → NO_COVERAGE |
if (title == null) |
88 | throw new NullPointerException(MessageLocalization.getComposedMessage("title.cannot.be.null")); | |
89 | PdfLayer layer = new PdfLayer(title); | |
90 |
1
1. createTitle : removed call to com/lowagie/text/pdf/PdfWriter::registerLayer → NO_COVERAGE |
writer.registerLayer(layer); |
91 |
1
1. createTitle : mutated return of Object value for com/lowagie/text/pdf/PdfLayer::createTitle to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return layer; |
92 | } | |
93 | /** | |
94 | * Creates a new layer. | |
95 | * @param name the name of the layer | |
96 | * @param writer the writer | |
97 | */ | |
98 | public PdfLayer(String name, PdfWriter writer) { | |
99 | super(PdfName.OCG); | |
100 |
1
1. |
setName(name); |
101 | ref = writer.getPdfIndirectReference(); | |
102 |
1
1. |
writer.registerLayer(this); |
103 | } | |
104 | | |
105 | String getTitle() { | |
106 | return title; | |
107 | } | |
108 | | |
109 | /** | |
110 | * Adds a child layer. Nested layers can only have one parent. | |
111 | * @param child the child layer | |
112 | */ | |
113 | public void addChild(PdfLayer child) { | |
114 |
1
1. addChild : negated conditional → NO_COVERAGE |
if (child.parent != null) |
115 | throw new IllegalArgumentException(MessageLocalization.getComposedMessage("the.layer.1.already.has.a.parent", ((PdfString)child.get(PdfName.NAME)).toUnicodeString())); | |
116 | child.parent = this; | |
117 |
1
1. addChild : negated conditional → NO_COVERAGE |
if (children == null) |
118 | children = new ArrayList<>(); | |
119 | children.add(child); | |
120 | } | |
121 | ||
122 | | |
123 | /** | |
124 | * Gets the parent layer. | |
125 | * @return the parent layer or <CODE>null</CODE> if the layer has no parent | |
126 | */ | |
127 | public PdfLayer getParent() { | |
128 | return parent; | |
129 | } | |
130 | | |
131 | /** | |
132 | * Gets the children layers. | |
133 | * @return the children layers or <CODE>null</CODE> if the layer has no children | |
134 | */ | |
135 | public ArrayList<PdfLayer> getChildren() { | |
136 | return children; | |
137 | } | |
138 | | |
139 | /** | |
140 | * Gets the <CODE>PdfIndirectReference</CODE> that represents this layer. | |
141 | * @return the <CODE>PdfIndirectReference</CODE> that represents this layer | |
142 | */ | |
143 | public PdfIndirectReference getRef() { | |
144 | return ref; | |
145 | } | |
146 | | |
147 | /** | |
148 | * Sets the <CODE>PdfIndirectReference</CODE> that represents this layer. | |
149 | * This can only be done from PdfStamperImp. | |
150 | * @param ref The reference to the OCG object | |
151 | * @since 2.1.2 | |
152 | */ | |
153 | void setRef(PdfIndirectReference ref) { | |
154 | this.ref = ref; | |
155 | } | |
156 | | |
157 | /** | |
158 | * Sets the name of this layer. | |
159 | * @param name the name of this layer | |
160 | */ | |
161 | public void setName(String name) { | |
162 |
1
1. setName : removed call to com/lowagie/text/pdf/PdfLayer::put → NO_COVERAGE |
put(PdfName.NAME, new PdfString(name, PdfObject.TEXT_UNICODE)); |
163 | } | |
164 | | |
165 | /** | |
166 | * Gets the dictionary representing the layer. It just returns <CODE>this</CODE>. | |
167 | * @return the dictionary representing the layer | |
168 | */ | |
169 | public PdfObject getPdfObject() { | |
170 |
1
1. getPdfObject : mutated return of Object value for com/lowagie/text/pdf/PdfLayer::getPdfObject to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return this; |
171 | } | |
172 | | |
173 | /** | |
174 | * Gets the initial visibility of the layer. | |
175 | * @return the initial visibility of the layer | |
176 | */ | |
177 | public boolean isOn() { | |
178 | return this.on; | |
179 | } | |
180 | | |
181 | /** | |
182 | * Sets the initial visibility of the layer. | |
183 | * @param on the initial visibility of the layer | |
184 | */ | |
185 | public void setOn(boolean on) { | |
186 | this.on = on; | |
187 | } | |
188 | | |
189 | private PdfDictionary getUsage() { | |
190 | PdfDictionary usage = (PdfDictionary)get(PdfName.USAGE); | |
191 |
1
1. getUsage : negated conditional → NO_COVERAGE |
if (usage == null) { |
192 | usage = new PdfDictionary(); | |
193 |
1
1. getUsage : removed call to com/lowagie/text/pdf/PdfLayer::put → NO_COVERAGE |
put(PdfName.USAGE, usage); |
194 | } | |
195 |
1
1. getUsage : mutated return of Object value for com/lowagie/text/pdf/PdfLayer::getUsage to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return usage; |
196 | } | |
197 | | |
198 | /** | |
199 | * Used by the creating application to store application-specific | |
200 | * data associated with this optional content group. | |
201 | * @param creator a text string specifying the application that created the group | |
202 | * @param subtype a string defining the type of content controlled by the group. Suggested | |
203 | * values include but are not limited to <B>Artwork</B>, for graphic-design or publishing | |
204 | * applications, and <B>Technical</B>, for technical designs such as building plans or | |
205 | * schematics | |
206 | */ | |
207 | public void setCreatorInfo(String creator, String subtype) { | |
208 | PdfDictionary usage = getUsage(); | |
209 | PdfDictionary dic = new PdfDictionary(); | |
210 |
1
1. setCreatorInfo : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
dic.put(PdfName.CREATOR, new PdfString(creator, PdfObject.TEXT_UNICODE)); |
211 |
1
1. setCreatorInfo : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
dic.put(PdfName.SUBTYPE, new PdfName(subtype)); |
212 |
1
1. setCreatorInfo : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
usage.put(PdfName.CREATORINFO, dic); |
213 | } | |
214 | | |
215 | /** | |
216 | * Specifies the language of the content controlled by this | |
217 | * optional content group | |
218 | * @param lang a language string which specifies a language and possibly a locale | |
219 | * (for example, <B>es-MX</B> represents Mexican Spanish) | |
220 | * @param preferred used by viewer applications when there is a partial match but no exact | |
221 | * match between the system language and the language strings in all usage dictionaries | |
222 | */ | |
223 | public void setLanguage(String lang, boolean preferred) { | |
224 | PdfDictionary usage = getUsage(); | |
225 | PdfDictionary dic = new PdfDictionary(); | |
226 |
1
1. setLanguage : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
dic.put(PdfName.LANG, new PdfString(lang, PdfObject.TEXT_UNICODE)); |
227 |
1
1. setLanguage : negated conditional → NO_COVERAGE |
if (preferred) |
228 |
1
1. setLanguage : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
dic.put(PdfName.PREFERRED, PdfName.ON); |
229 |
1
1. setLanguage : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
usage.put(PdfName.LANGUAGE, dic); |
230 | } | |
231 | | |
232 | /** | |
233 | * Specifies the recommended state for content in this | |
234 | * group when the document (or part of it) is saved by a viewer application to a format | |
235 | * that does not support optional content (for example, an earlier version of | |
236 | * PDF or a raster image format). | |
237 | * @param export the export state | |
238 | */ | |
239 | public void setExport(boolean export) { | |
240 | PdfDictionary usage = getUsage(); | |
241 | PdfDictionary dic = new PdfDictionary(); | |
242 |
2
1. setExport : negated conditional → NO_COVERAGE 2. setExport : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
dic.put(PdfName.EXPORTSTATE, export ? PdfName.ON : PdfName.OFF); |
243 |
1
1. setExport : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
usage.put(PdfName.EXPORT, dic); |
244 | } | |
245 | | |
246 | /** | |
247 | * Specifies a range of magnifications at which the content | |
248 | * in this optional content group is best viewed. | |
249 | * @param min the minimum recommended magnification factors at which the group | |
250 | * should be ON. A negative value will set the default to 0 | |
251 | * @param max the maximum recommended magnification factor at which the group | |
252 | * should be ON. A negative value will set the largest possible magnification supported by the | |
253 | * viewer application | |
254 | */ | |
255 | public void setZoom(float min, float max) { | |
256 |
4
1. setZoom : changed conditional boundary → NO_COVERAGE 2. setZoom : changed conditional boundary → NO_COVERAGE 3. setZoom : negated conditional → NO_COVERAGE 4. setZoom : negated conditional → NO_COVERAGE |
if (min <= 0 && max < 0) |
257 | return; | |
258 | PdfDictionary usage = getUsage(); | |
259 | PdfDictionary dic = new PdfDictionary(); | |
260 |
2
1. setZoom : changed conditional boundary → NO_COVERAGE 2. setZoom : negated conditional → NO_COVERAGE |
if (min > 0) |
261 |
1
1. setZoom : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
dic.put(PdfName.MIN_LOWER_CASE, new PdfNumber(min)); |
262 |
2
1. setZoom : changed conditional boundary → NO_COVERAGE 2. setZoom : negated conditional → NO_COVERAGE |
if (max >= 0) |
263 |
1
1. setZoom : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
dic.put(PdfName.MAX_LOWER_CASE, new PdfNumber(max)); |
264 |
1
1. setZoom : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
usage.put(PdfName.ZOOM, dic); |
265 | } | |
266 | ||
267 | /** | |
268 | * Specifies that the content in this group is intended for | |
269 | * use in printing | |
270 | * @param subtype a name specifying the kind of content controlled by the group; | |
271 | * for example, <B>Trapping</B>, <B>PrintersMarks</B> and <B>Watermark</B> | |
272 | * @param printstate indicates that the group should be | |
273 | * set to that state when the document is printed from a viewer application | |
274 | */ | |
275 | public void setPrint(String subtype, boolean printstate) { | |
276 | PdfDictionary usage = getUsage(); | |
277 | PdfDictionary dic = new PdfDictionary(); | |
278 |
1
1. setPrint : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
dic.put(PdfName.SUBTYPE, new PdfName(subtype)); |
279 |
2
1. setPrint : negated conditional → NO_COVERAGE 2. setPrint : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
dic.put(PdfName.PRINTSTATE, printstate ? PdfName.ON : PdfName.OFF); |
280 |
1
1. setPrint : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
usage.put(PdfName.PRINT, dic); |
281 | } | |
282 | ||
283 | /** | |
284 | * Indicates that the group should be set to that state when the | |
285 | * document is opened in a viewer application. | |
286 | * @param view the view state | |
287 | */ | |
288 | public void setView(boolean view) { | |
289 | PdfDictionary usage = getUsage(); | |
290 | PdfDictionary dic = new PdfDictionary(); | |
291 |
2
1. setView : negated conditional → NO_COVERAGE 2. setView : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
dic.put(PdfName.VIEWSTATE, view ? PdfName.ON : PdfName.OFF); |
292 |
1
1. setView : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
usage.put(PdfName.VIEW, dic); |
293 | } | |
294 | | |
295 | /** | |
296 | * Gets the layer visibility in Acrobat's layer panel | |
297 | * @return the layer visibility in Acrobat's layer panel | |
298 | */ | |
299 | public boolean isOnPanel() { | |
300 | return this.onPanel; | |
301 | } | |
302 | | |
303 | /** | |
304 | * Sets the visibility of the layer in Acrobat's layer panel. If <CODE>false</CODE> | |
305 | * the layer cannot be directly manipulated by the user. Note that any children layers will | |
306 | * also be absent from the panel. | |
307 | * @param onPanel the visibility of the layer in Acrobat's layer panel | |
308 | */ | |
309 | public void setOnPanel(boolean onPanel) { | |
310 | this.onPanel = onPanel; | |
311 | } | |
312 | | |
313 | } | |
Mutations | ||
87 |
1.1 |
|
90 |
1.1 |
|
91 |
1.1 |
|
100 |
1.1 |
|
102 |
1.1 |
|
114 |
1.1 |
|
117 |
1.1 |
|
162 |
1.1 |
|
170 |
1.1 |
|
191 |
1.1 |
|
193 |
1.1 |
|
195 |
1.1 |
|
210 |
1.1 |
|
211 |
1.1 |
|
212 |
1.1 |
|
226 |
1.1 |
|
227 |
1.1 |
|
228 |
1.1 |
|
229 |
1.1 |
|
242 |
1.1 2.2 |
|
243 |
1.1 |
|
256 |
1.1 2.2 3.3 4.4 |
|
260 |
1.1 2.2 |
|
261 |
1.1 |
|
262 |
1.1 2.2 |
|
263 |
1.1 |
|
264 |
1.1 |
|
278 |
1.1 |
|
279 |
1.1 2.2 |
|
280 |
1.1 |
|
291 |
1.1 2.2 |
|
292 |
1.1 |