1 | /* | |
2 | * $Id: PdfAnnotation.java 4065 2009-09-16 23:09:11Z psoares33 $ | |
3 | * | |
4 | * Copyright 1999, 2000, 2001, 2002 Bruno Lowagie | |
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; | |
51 | ||
52 | import java.awt.Color; | |
53 | import java.io.IOException; | |
54 | import java.util.HashMap; | |
55 | import java.util.Map; | |
56 | ||
57 | import com.lowagie.text.error_messages.MessageLocalization; | |
58 | ||
59 | import com.lowagie.text.Rectangle; | |
60 | ||
61 | /** | |
62 | * A <CODE>PdfAnnotation</CODE> is a note that is associated with a page. | |
63 | * | |
64 | * @see PdfDictionary | |
65 | */ | |
66 | ||
67 | public class PdfAnnotation extends PdfDictionary { | |
68 | ||
69 | /** | |
70 | * highlight attributename | |
71 | */ | |
72 | public static final PdfName HIGHLIGHT_NONE = PdfName.N; | |
73 | /** | |
74 | * highlight attributename | |
75 | */ | |
76 | public static final PdfName HIGHLIGHT_INVERT = PdfName.I; | |
77 | /** | |
78 | * highlight attributename | |
79 | */ | |
80 | public static final PdfName HIGHLIGHT_OUTLINE = PdfName.O; | |
81 | /** | |
82 | * highlight attributename | |
83 | */ | |
84 | public static final PdfName HIGHLIGHT_PUSH = PdfName.P; | |
85 | /** | |
86 | * highlight attributename | |
87 | */ | |
88 | public static final PdfName HIGHLIGHT_TOGGLE = PdfName.T; | |
89 | /** | |
90 | * flagvalue | |
91 | */ | |
92 | public static final int FLAGS_INVISIBLE = 1; | |
93 | /** | |
94 | * flagvalue | |
95 | */ | |
96 | public static final int FLAGS_HIDDEN = 2; | |
97 | /** | |
98 | * flagvalue | |
99 | */ | |
100 | public static final int FLAGS_PRINT = 4; | |
101 | /** | |
102 | * flagvalue | |
103 | */ | |
104 | public static final int FLAGS_NOZOOM = 8; | |
105 | /** | |
106 | * flagvalue | |
107 | */ | |
108 | public static final int FLAGS_NOROTATE = 16; | |
109 | /** | |
110 | * flagvalue | |
111 | */ | |
112 | public static final int FLAGS_NOVIEW = 32; | |
113 | /** | |
114 | * flagvalue | |
115 | */ | |
116 | public static final int FLAGS_READONLY = 64; | |
117 | /** | |
118 | * flagvalue | |
119 | */ | |
120 | public static final int FLAGS_LOCKED = 128; | |
121 | /** | |
122 | * flagvalue | |
123 | */ | |
124 | public static final int FLAGS_TOGGLENOVIEW = 256; | |
125 | /** | |
126 | * appearance attributename | |
127 | */ | |
128 | public static final PdfName APPEARANCE_NORMAL = PdfName.N; | |
129 | /** | |
130 | * appearance attributename | |
131 | */ | |
132 | public static final PdfName APPEARANCE_ROLLOVER = PdfName.R; | |
133 | /** | |
134 | * appearance attributename | |
135 | */ | |
136 | public static final PdfName APPEARANCE_DOWN = PdfName.D; | |
137 | /** | |
138 | * attributevalue | |
139 | */ | |
140 | public static final PdfName AA_ENTER = PdfName.E; | |
141 | /** | |
142 | * attributevalue | |
143 | */ | |
144 | public static final PdfName AA_EXIT = PdfName.X; | |
145 | /** | |
146 | * attributevalue | |
147 | */ | |
148 | public static final PdfName AA_DOWN = PdfName.D; | |
149 | /** | |
150 | * attributevalue | |
151 | */ | |
152 | public static final PdfName AA_UP = PdfName.U; | |
153 | /** | |
154 | * attributevalue | |
155 | */ | |
156 | public static final PdfName AA_FOCUS = PdfName.FO; | |
157 | /** | |
158 | * attributevalue | |
159 | */ | |
160 | public static final PdfName AA_BLUR = PdfName.BL; | |
161 | /** | |
162 | * attributevalue | |
163 | */ | |
164 | public static final PdfName AA_JS_KEY = PdfName.K; | |
165 | /** | |
166 | * attributevalue | |
167 | */ | |
168 | public static final PdfName AA_JS_FORMAT = PdfName.F; | |
169 | /** | |
170 | * attributevalue | |
171 | */ | |
172 | public static final PdfName AA_JS_CHANGE = PdfName.V; | |
173 | /** | |
174 | * attributevalue | |
175 | */ | |
176 | public static final PdfName AA_JS_OTHER_CHANGE = PdfName.C; | |
177 | /** | |
178 | * attributevalue | |
179 | */ | |
180 | public static final int MARKUP_HIGHLIGHT = 0; | |
181 | /** | |
182 | * attributevalue | |
183 | */ | |
184 | public static final int MARKUP_UNDERLINE = 1; | |
185 | /** | |
186 | * attributevalue | |
187 | */ | |
188 | public static final int MARKUP_STRIKEOUT = 2; | |
189 | /** | |
190 | * attributevalue | |
191 | * | |
192 | * @since 2.1.3 | |
193 | */ | |
194 | public static final int MARKUP_SQUIGGLY = 3; | |
195 | ||
196 | protected PdfWriter writer; | |
197 | /** | |
198 | * Reference to this annotation. | |
199 | * | |
200 | * @since 2.1.6; was removed in 2.1.5, but restored in 2.1.6 | |
201 | */ | |
202 | protected PdfIndirectReference reference; | |
203 | protected Map<PdfTemplate, Object> templates; | |
204 | protected boolean form = false; | |
205 | protected boolean annotation = true; | |
206 | ||
207 | /** | |
208 | * Holds value of property used. | |
209 | */ | |
210 | protected boolean used = false; | |
211 | ||
212 | /** | |
213 | * Holds value of property placeInPage. | |
214 | */ | |
215 | private int placeInPage = -1; | |
216 | ||
217 | // constructors | |
218 | public PdfAnnotation(PdfWriter writer, Rectangle rect) { | |
219 | this.writer = writer; | |
220 |
1
1. |
if (rect != null) { |
221 |
1
1. |
put(PdfName.RECT, new PdfRectangle(rect)); |
222 | } | |
223 | } | |
224 | ||
225 | /** | |
226 | * Constructs a new <CODE>PdfAnnotation</CODE> of subtype text. | |
227 | */ | |
228 | ||
229 | public PdfAnnotation(PdfWriter writer, float llx, float lly, float urx, float ury, PdfString title, PdfString content) { | |
230 | this.writer = writer; | |
231 |
1
1. |
put(PdfName.SUBTYPE, PdfName.TEXT); |
232 |
1
1. |
put(PdfName.T, title); |
233 |
1
1. |
put(PdfName.RECT, new PdfRectangle(llx, lly, urx, ury)); |
234 |
1
1. |
put(PdfName.CONTENTS, content); |
235 | } | |
236 | ||
237 | /** | |
238 | * Constructs a new <CODE>PdfAnnotation</CODE> of subtype link (Action). | |
239 | */ | |
240 | ||
241 | public PdfAnnotation(PdfWriter writer, float llx, float lly, float urx, float ury, PdfAction action) { | |
242 | this.writer = writer; | |
243 |
1
1. |
put(PdfName.SUBTYPE, PdfName.LINK); |
244 |
1
1. |
put(PdfName.RECT, new PdfRectangle(llx, lly, urx, ury)); |
245 |
1
1. |
put(PdfName.A, action); |
246 |
1
1. |
put(PdfName.BORDER, new PdfBorderArray(0, 0, 0)); |
247 |
1
1. |
put(PdfName.C, new PdfColor(0x00, 0x00, 0xFF)); |
248 | } | |
249 | ||
250 | /** | |
251 | * Creates a screen PdfAnnotation | |
252 | * | |
253 | * @return a screen PdfAnnotation | |
254 | */ | |
255 | public static PdfAnnotation createScreen(PdfWriter writer, Rectangle rect, String clipTitle, PdfFileSpecification fs, | |
256 | String mimeType, boolean playOnDisplay) throws IOException { | |
257 | PdfAnnotation ann = new PdfAnnotation(writer, rect); | |
258 |
1
1. createScreen : removed call to com/lowagie/text/pdf/PdfAnnotation::put → NO_COVERAGE |
ann.put(PdfName.SUBTYPE, PdfName.SCREEN); |
259 |
1
1. createScreen : removed call to com/lowagie/text/pdf/PdfAnnotation::put → NO_COVERAGE |
ann.put(PdfName.F, new PdfNumber(FLAGS_PRINT)); |
260 |
1
1. createScreen : removed call to com/lowagie/text/pdf/PdfAnnotation::put → NO_COVERAGE |
ann.put(PdfName.TYPE, PdfName.ANNOT); |
261 |
1
1. createScreen : removed call to com/lowagie/text/pdf/PdfAnnotation::setPage → NO_COVERAGE |
ann.setPage(); |
262 | PdfIndirectReference ref = ann.getIndirectReference(); | |
263 | PdfAction action = PdfAction.rendition(clipTitle, fs, mimeType, ref); | |
264 | PdfIndirectReference actionRef = writer.addToBody(action).getIndirectReference(); | |
265 | // for play on display add trigger event | |
266 |
1
1. createScreen : negated conditional → NO_COVERAGE |
if (playOnDisplay) { |
267 | PdfDictionary aa = new PdfDictionary(); | |
268 |
1
1. createScreen : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
aa.put(new PdfName("PV"), actionRef); |
269 |
1
1. createScreen : removed call to com/lowagie/text/pdf/PdfAnnotation::put → NO_COVERAGE |
ann.put(PdfName.AA, aa); |
270 | } | |
271 |
1
1. createScreen : removed call to com/lowagie/text/pdf/PdfAnnotation::put → NO_COVERAGE |
ann.put(PdfName.A, actionRef); |
272 |
1
1. createScreen : mutated return of Object value for com/lowagie/text/pdf/PdfAnnotation::createScreen to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return ann; |
273 | } | |
274 | ||
275 | /** | |
276 | * Returns an indirect reference to the annotation | |
277 | * | |
278 | * @return the indirect reference | |
279 | */ | |
280 | public PdfIndirectReference getIndirectReference() { | |
281 |
1
1. getIndirectReference : negated conditional → NO_COVERAGE |
if (reference == null) { |
282 | reference = writer.getPdfIndirectReference(); | |
283 | } | |
284 |
1
1. getIndirectReference : mutated return of Object value for com/lowagie/text/pdf/PdfAnnotation::getIndirectReference to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return reference; |
285 | } | |
286 | ||
287 | /** | |
288 | * @return a PdfAnnotation | |
289 | */ | |
290 | public static PdfAnnotation createText(PdfWriter writer, Rectangle rect, String title, String contents, boolean open, String icon) { | |
291 | PdfAnnotation annot = new PdfAnnotation(writer, rect); | |
292 |
1
1. createText : removed call to com/lowagie/text/pdf/PdfAnnotation::put → NO_COVERAGE |
annot.put(PdfName.SUBTYPE, PdfName.TEXT); |
293 |
1
1. createText : negated conditional → NO_COVERAGE |
if (title != null) { |
294 |
1
1. createText : removed call to com/lowagie/text/pdf/PdfAnnotation::put → NO_COVERAGE |
annot.put(PdfName.T, new PdfString(title, PdfObject.TEXT_UNICODE)); |
295 | } | |
296 |
1
1. createText : negated conditional → NO_COVERAGE |
if (contents != null) { |
297 |
1
1. createText : removed call to com/lowagie/text/pdf/PdfAnnotation::put → NO_COVERAGE |
annot.put(PdfName.CONTENTS, new PdfString(contents, PdfObject.TEXT_UNICODE)); |
298 | } | |
299 |
1
1. createText : negated conditional → NO_COVERAGE |
if (open) { |
300 |
1
1. createText : removed call to com/lowagie/text/pdf/PdfAnnotation::put → NO_COVERAGE |
annot.put(PdfName.OPEN, PdfBoolean.PDFTRUE); |
301 | } | |
302 |
1
1. createText : negated conditional → NO_COVERAGE |
if (icon != null) { |
303 |
1
1. createText : removed call to com/lowagie/text/pdf/PdfAnnotation::put → NO_COVERAGE |
annot.put(PdfName.NAME, new PdfName(icon)); |
304 | } | |
305 |
1
1. createText : mutated return of Object value for com/lowagie/text/pdf/PdfAnnotation::createText to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return annot; |
306 | } | |
307 | ||
308 | /** | |
309 | * Creates a link. | |
310 | * | |
311 | * @return A PdfAnnotation | |
312 | */ | |
313 | protected static PdfAnnotation createLink(PdfWriter writer, Rectangle rect, PdfName highlight) { | |
314 | PdfAnnotation annot = new PdfAnnotation(writer, rect); | |
315 |
1
1. createLink : removed call to com/lowagie/text/pdf/PdfAnnotation::put → NO_COVERAGE |
annot.put(PdfName.SUBTYPE, PdfName.LINK); |
316 |
1
1. createLink : negated conditional → NO_COVERAGE |
if (!highlight.equals(HIGHLIGHT_INVERT)) { |
317 |
1
1. createLink : removed call to com/lowagie/text/pdf/PdfAnnotation::put → NO_COVERAGE |
annot.put(PdfName.H, highlight); |
318 | } | |
319 |
1
1. createLink : mutated return of Object value for com/lowagie/text/pdf/PdfAnnotation::createLink to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return annot; |
320 | } | |
321 | ||
322 | /** | |
323 | * Creates an Annotation with an Action. | |
324 | * | |
325 | * @return A PdfAnnotation | |
326 | */ | |
327 | public static PdfAnnotation createLink(PdfWriter writer, Rectangle rect, PdfName highlight, PdfAction action) { | |
328 | PdfAnnotation annot = createLink(writer, rect, highlight); | |
329 |
1
1. createLink : removed call to com/lowagie/text/pdf/PdfAnnotation::putEx → NO_COVERAGE |
annot.putEx(PdfName.A, action); |
330 |
1
1. createLink : mutated return of Object value for com/lowagie/text/pdf/PdfAnnotation::createLink to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return annot; |
331 | } | |
332 | ||
333 | /** | |
334 | * Creates an Annotation with an local destination. | |
335 | * | |
336 | * @return A PdfAnnotation | |
337 | */ | |
338 | public static PdfAnnotation createLink(PdfWriter writer, Rectangle rect, PdfName highlight, String namedDestination) { | |
339 | PdfAnnotation annot = createLink(writer, rect, highlight); | |
340 |
1
1. createLink : removed call to com/lowagie/text/pdf/PdfAnnotation::put → NO_COVERAGE |
annot.put(PdfName.DEST, new PdfString(namedDestination)); |
341 |
1
1. createLink : mutated return of Object value for com/lowagie/text/pdf/PdfAnnotation::createLink to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return annot; |
342 | } | |
343 | ||
344 | /** | |
345 | * Creates an Annotation with a PdfDestination. | |
346 | * | |
347 | * @return A PdfAnnotation | |
348 | */ | |
349 | public static PdfAnnotation createLink(PdfWriter writer, Rectangle rect, PdfName highlight, int page, PdfDestination dest) { | |
350 | PdfAnnotation annot = createLink(writer, rect, highlight); | |
351 | PdfIndirectReference ref = writer.getPageReference(page); | |
352 | dest.addPage(ref); | |
353 |
1
1. createLink : removed call to com/lowagie/text/pdf/PdfAnnotation::put → NO_COVERAGE |
annot.put(PdfName.DEST, dest); |
354 |
1
1. createLink : mutated return of Object value for com/lowagie/text/pdf/PdfAnnotation::createLink to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return annot; |
355 | } | |
356 | ||
357 | /** | |
358 | * Add some free text to the document. | |
359 | * | |
360 | * @return A PdfAnnotation | |
361 | */ | |
362 | public static PdfAnnotation createFreeText(PdfWriter writer, Rectangle rect, String contents, PdfContentByte defaultAppearance) { | |
363 | PdfAnnotation annot = new PdfAnnotation(writer, rect); | |
364 |
1
1. createFreeText : removed call to com/lowagie/text/pdf/PdfAnnotation::put → NO_COVERAGE |
annot.put(PdfName.SUBTYPE, PdfName.FREETEXT); |
365 |
1
1. createFreeText : removed call to com/lowagie/text/pdf/PdfAnnotation::put → NO_COVERAGE |
annot.put(PdfName.CONTENTS, new PdfString(contents, PdfObject.TEXT_UNICODE)); |
366 |
1
1. createFreeText : removed call to com/lowagie/text/pdf/PdfAnnotation::setDefaultAppearanceString → NO_COVERAGE |
annot.setDefaultAppearanceString(defaultAppearance); |
367 |
1
1. createFreeText : mutated return of Object value for com/lowagie/text/pdf/PdfAnnotation::createFreeText to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return annot; |
368 | } | |
369 | ||
370 | /** | |
371 | * Adds a line to the document. Move over the line and a tooltip is shown. | |
372 | * | |
373 | * @return A PdfAnnotation | |
374 | */ | |
375 | public static PdfAnnotation createLine(PdfWriter writer, Rectangle rect, String contents, float x1, float y1, float x2, float y2) { | |
376 | PdfAnnotation annot = new PdfAnnotation(writer, rect); | |
377 |
1
1. createLine : removed call to com/lowagie/text/pdf/PdfAnnotation::put → NO_COVERAGE |
annot.put(PdfName.SUBTYPE, PdfName.LINE); |
378 |
1
1. createLine : removed call to com/lowagie/text/pdf/PdfAnnotation::put → NO_COVERAGE |
annot.put(PdfName.CONTENTS, new PdfString(contents, PdfObject.TEXT_UNICODE)); |
379 | PdfArray array = new PdfArray(new PdfNumber(x1)); | |
380 | array.add(new PdfNumber(y1)); | |
381 | array.add(new PdfNumber(x2)); | |
382 | array.add(new PdfNumber(y2)); | |
383 |
1
1. createLine : removed call to com/lowagie/text/pdf/PdfAnnotation::put → NO_COVERAGE |
annot.put(PdfName.L, array); |
384 |
1
1. createLine : mutated return of Object value for com/lowagie/text/pdf/PdfAnnotation::createLine to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return annot; |
385 | } | |
386 | ||
387 | /** | |
388 | * Adds a circle or a square that shows a tooltip when you pass over it. | |
389 | * | |
390 | * @param contents The tooltip | |
391 | * @param square true if you want a square, false if you want a circle | |
392 | * @return A PdfAnnotation | |
393 | */ | |
394 | public static PdfAnnotation createSquareCircle(PdfWriter writer, Rectangle rect, String contents, boolean square) { | |
395 | PdfAnnotation annot = new PdfAnnotation(writer, rect); | |
396 |
1
1. createSquareCircle : negated conditional → NO_COVERAGE |
if (square) { |
397 |
1
1. createSquareCircle : removed call to com/lowagie/text/pdf/PdfAnnotation::put → NO_COVERAGE |
annot.put(PdfName.SUBTYPE, PdfName.SQUARE); |
398 | } else { | |
399 |
1
1. createSquareCircle : removed call to com/lowagie/text/pdf/PdfAnnotation::put → NO_COVERAGE |
annot.put(PdfName.SUBTYPE, PdfName.CIRCLE); |
400 | } | |
401 |
1
1. createSquareCircle : removed call to com/lowagie/text/pdf/PdfAnnotation::put → NO_COVERAGE |
annot.put(PdfName.CONTENTS, new PdfString(contents, PdfObject.TEXT_UNICODE)); |
402 |
1
1. createSquareCircle : mutated return of Object value for com/lowagie/text/pdf/PdfAnnotation::createSquareCircle to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return annot; |
403 | } | |
404 | ||
405 | public static PdfAnnotation createMarkup(PdfWriter writer, Rectangle rect, String contents, int type, float[] quadPoints) { | |
406 | PdfAnnotation annot = new PdfAnnotation(writer, rect); | |
407 | PdfName name = PdfName.HIGHLIGHT; | |
408 | switch (type) { | |
409 | case MARKUP_UNDERLINE: | |
410 | name = PdfName.UNDERLINE; | |
411 | break; | |
412 | case MARKUP_STRIKEOUT: | |
413 | name = PdfName.STRIKEOUT; | |
414 | break; | |
415 | case MARKUP_SQUIGGLY: | |
416 | name = PdfName.SQUIGGLY; | |
417 | break; | |
418 | } | |
419 |
1
1. createMarkup : removed call to com/lowagie/text/pdf/PdfAnnotation::put → NO_COVERAGE |
annot.put(PdfName.SUBTYPE, name); |
420 |
1
1. createMarkup : removed call to com/lowagie/text/pdf/PdfAnnotation::put → NO_COVERAGE |
annot.put(PdfName.CONTENTS, new PdfString(contents, PdfObject.TEXT_UNICODE)); |
421 | PdfArray array = new PdfArray(); | |
422 | for (float quadPoint : quadPoints) { | |
423 | array.add(new PdfNumber(quadPoint)); | |
424 | } | |
425 |
1
1. createMarkup : removed call to com/lowagie/text/pdf/PdfAnnotation::put → NO_COVERAGE |
annot.put(PdfName.QUADPOINTS, array); |
426 |
1
1. createMarkup : mutated return of Object value for com/lowagie/text/pdf/PdfAnnotation::createMarkup to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return annot; |
427 | } | |
428 | ||
429 | /** | |
430 | * Adds a Stamp to your document. Move over the stamp and a tooltip is shown | |
431 | * | |
432 | * @return A PdfAnnotation | |
433 | */ | |
434 | public static PdfAnnotation createStamp(PdfWriter writer, Rectangle rect, String contents, String name) { | |
435 | PdfAnnotation annot = new PdfAnnotation(writer, rect); | |
436 |
1
1. createStamp : removed call to com/lowagie/text/pdf/PdfAnnotation::put → NO_COVERAGE |
annot.put(PdfName.SUBTYPE, PdfName.STAMP); |
437 |
1
1. createStamp : removed call to com/lowagie/text/pdf/PdfAnnotation::put → NO_COVERAGE |
annot.put(PdfName.CONTENTS, new PdfString(contents, PdfObject.TEXT_UNICODE)); |
438 |
1
1. createStamp : removed call to com/lowagie/text/pdf/PdfAnnotation::put → NO_COVERAGE |
annot.put(PdfName.NAME, new PdfName(name)); |
439 |
1
1. createStamp : mutated return of Object value for com/lowagie/text/pdf/PdfAnnotation::createStamp to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return annot; |
440 | } | |
441 | ||
442 | public static PdfAnnotation createInk(PdfWriter writer, Rectangle rect, String contents, float[][] inkList) { | |
443 | PdfAnnotation annot = new PdfAnnotation(writer, rect); | |
444 |
1
1. createInk : removed call to com/lowagie/text/pdf/PdfAnnotation::put → NO_COVERAGE |
annot.put(PdfName.SUBTYPE, PdfName.INK); |
445 |
1
1. createInk : removed call to com/lowagie/text/pdf/PdfAnnotation::put → NO_COVERAGE |
annot.put(PdfName.CONTENTS, new PdfString(contents, PdfObject.TEXT_UNICODE)); |
446 | PdfArray outer = new PdfArray(); | |
447 |
1
1. createInk : Changed increment from 1 to -1 → NO_COVERAGE |
for (float[] floats : inkList) { |
448 | PdfArray inner = new PdfArray(); | |
449 | float[] deep = floats; | |
450 | for (float v : deep) { | |
451 | inner.add(new PdfNumber(v)); | |
452 | } | |
453 | outer.add(inner); | |
454 | } | |
455 |
1
1. createInk : removed call to com/lowagie/text/pdf/PdfAnnotation::put → NO_COVERAGE |
annot.put(PdfName.INKLIST, outer); |
456 |
1
1. createInk : mutated return of Object value for com/lowagie/text/pdf/PdfAnnotation::createInk to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return annot; |
457 | } | |
458 | ||
459 | /** | |
460 | * Creates a file attachment annotation. | |
461 | * | |
462 | * @param writer the <CODE>PdfWriter</CODE> | |
463 | * @param rect the dimensions in the page of the annotation | |
464 | * @param contents the file description | |
465 | * @param fileStore an array with the file. If it's <CODE>null</CODE> the file will be read from the disk | |
466 | * @param file the path to the file. It will only be used if | |
467 | * <CODE>fileStore</CODE> is not <CODE>null</CODE> | |
468 | * @param fileDisplay the actual file name stored in the pdf | |
469 | * @return the annotation | |
470 | * @throws IOException on error | |
471 | */ | |
472 | public static PdfAnnotation createFileAttachment(PdfWriter writer, Rectangle rect, String contents, byte[] fileStore, String file, | |
473 | String fileDisplay) throws IOException { | |
474 |
1
1. createFileAttachment : mutated return of Object value for com/lowagie/text/pdf/PdfAnnotation::createFileAttachment to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return createFileAttachment(writer, rect, contents, PdfFileSpecification.fileEmbedded(writer, file, fileDisplay, fileStore)); |
475 | } | |
476 | ||
477 | /** | |
478 | * Creates a file attachment annotation | |
479 | * | |
480 | * @return the annotation | |
481 | */ | |
482 | public static PdfAnnotation createFileAttachment(PdfWriter writer, Rectangle rect, String contents, PdfFileSpecification fs) | |
483 | throws IOException { | |
484 | PdfAnnotation annot = new PdfAnnotation(writer, rect); | |
485 |
1
1. createFileAttachment : removed call to com/lowagie/text/pdf/PdfAnnotation::put → NO_COVERAGE |
annot.put(PdfName.SUBTYPE, PdfName.FILEATTACHMENT); |
486 |
1
1. createFileAttachment : negated conditional → NO_COVERAGE |
if (contents != null) { |
487 |
1
1. createFileAttachment : removed call to com/lowagie/text/pdf/PdfAnnotation::put → NO_COVERAGE |
annot.put(PdfName.CONTENTS, new PdfString(contents, PdfObject.TEXT_UNICODE)); |
488 | } | |
489 |
1
1. createFileAttachment : removed call to com/lowagie/text/pdf/PdfAnnotation::put → NO_COVERAGE |
annot.put(PdfName.FS, fs.getReference()); |
490 |
1
1. createFileAttachment : mutated return of Object value for com/lowagie/text/pdf/PdfAnnotation::createFileAttachment to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return annot; |
491 | } | |
492 | ||
493 | /** | |
494 | * Adds a popup to your document. | |
495 | * | |
496 | * @return A PdfAnnotation | |
497 | */ | |
498 | public static PdfAnnotation createPopup(PdfWriter writer, Rectangle rect, String contents, boolean open) { | |
499 | PdfAnnotation annot = new PdfAnnotation(writer, rect); | |
500 |
1
1. createPopup : removed call to com/lowagie/text/pdf/PdfAnnotation::put → NO_COVERAGE |
annot.put(PdfName.SUBTYPE, PdfName.POPUP); |
501 |
1
1. createPopup : negated conditional → NO_COVERAGE |
if (contents != null) { |
502 |
1
1. createPopup : removed call to com/lowagie/text/pdf/PdfAnnotation::put → NO_COVERAGE |
annot.put(PdfName.CONTENTS, new PdfString(contents, PdfObject.TEXT_UNICODE)); |
503 | } | |
504 |
1
1. createPopup : negated conditional → NO_COVERAGE |
if (open) { |
505 |
1
1. createPopup : removed call to com/lowagie/text/pdf/PdfAnnotation::put → NO_COVERAGE |
annot.put(PdfName.OPEN, PdfBoolean.PDFTRUE); |
506 | } | |
507 |
1
1. createPopup : mutated return of Object value for com/lowagie/text/pdf/PdfAnnotation::createPopup to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return annot; |
508 | } | |
509 | ||
510 | public void setDefaultAppearanceString(PdfContentByte cb) { | |
511 | byte[] b = cb.getInternalBuffer().toByteArray(); | |
512 | int len = b.length; | |
513 |
3
1. setDefaultAppearanceString : changed conditional boundary → NO_COVERAGE 2. setDefaultAppearanceString : Changed increment from 1 to -1 → NO_COVERAGE 3. setDefaultAppearanceString : negated conditional → NO_COVERAGE |
for (int k = 0; k < len; ++k) { |
514 |
1
1. setDefaultAppearanceString : negated conditional → NO_COVERAGE |
if (b[k] == '\n') { |
515 | b[k] = 32; | |
516 | } | |
517 | } | |
518 |
1
1. setDefaultAppearanceString : removed call to com/lowagie/text/pdf/PdfAnnotation::put → NO_COVERAGE |
put(PdfName.DA, new PdfString(b)); |
519 | } | |
520 | ||
521 | public void setFlags(int flags) { | |
522 |
1
1. setFlags : negated conditional → NO_COVERAGE |
if (flags == 0) { |
523 |
1
1. setFlags : removed call to com/lowagie/text/pdf/PdfAnnotation::remove → NO_COVERAGE |
remove(PdfName.F); |
524 | } else { | |
525 |
1
1. setFlags : removed call to com/lowagie/text/pdf/PdfAnnotation::put → NO_COVERAGE |
put(PdfName.F, new PdfNumber(flags)); |
526 | } | |
527 | } | |
528 | ||
529 | public void setBorder(PdfBorderArray border) { | |
530 |
1
1. setBorder : removed call to com/lowagie/text/pdf/PdfAnnotation::put → NO_COVERAGE |
put(PdfName.BORDER, border); |
531 | } | |
532 | ||
533 | public void setBorderStyle(PdfBorderDictionary border) { | |
534 |
1
1. setBorderStyle : removed call to com/lowagie/text/pdf/PdfAnnotation::put → NO_COVERAGE |
put(PdfName.BS, border); |
535 | } | |
536 | ||
537 | /** | |
538 | * Sets the annotation's highlighting mode. The values can be | |
539 | * <CODE>HIGHLIGHT_NONE</CODE>, <CODE>HIGHLIGHT_INVERT</CODE>, | |
540 | * <CODE>HIGHLIGHT_OUTLINE</CODE> and <CODE>HIGHLIGHT_PUSH</CODE>; | |
541 | * | |
542 | * @param highlight the annotation's highlighting mode | |
543 | */ | |
544 | public void setHighlighting(PdfName highlight) { | |
545 |
1
1. setHighlighting : negated conditional → NO_COVERAGE |
if (highlight.equals(HIGHLIGHT_INVERT)) { |
546 |
1
1. setHighlighting : removed call to com/lowagie/text/pdf/PdfAnnotation::remove → NO_COVERAGE |
remove(PdfName.H); |
547 | } else { | |
548 |
1
1. setHighlighting : removed call to com/lowagie/text/pdf/PdfAnnotation::put → NO_COVERAGE |
put(PdfName.H, highlight); |
549 | } | |
550 | } | |
551 | ||
552 | public void setAppearance(PdfName ap, PdfTemplate template) { | |
553 | PdfDictionary dic = (PdfDictionary) get(PdfName.AP); | |
554 |
1
1. setAppearance : negated conditional → NO_COVERAGE |
if (dic == null) { |
555 | dic = new PdfDictionary(); | |
556 | } | |
557 |
1
1. setAppearance : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
dic.put(ap, template.getIndirectReference()); |
558 |
1
1. setAppearance : removed call to com/lowagie/text/pdf/PdfAnnotation::put → NO_COVERAGE |
put(PdfName.AP, dic); |
559 |
1
1. setAppearance : negated conditional → NO_COVERAGE |
if (!form) { |
560 | return; | |
561 | } | |
562 |
1
1. setAppearance : negated conditional → NO_COVERAGE |
if (templates == null) { |
563 | templates = new HashMap<>(); | |
564 | } | |
565 | templates.put(template, null); | |
566 | } | |
567 | ||
568 | public void setAppearance(PdfName ap, String state, PdfTemplate template) { | |
569 | PdfDictionary dicAp = (PdfDictionary) get(PdfName.AP); | |
570 |
1
1. setAppearance : negated conditional → NO_COVERAGE |
if (dicAp == null) { |
571 | dicAp = new PdfDictionary(); | |
572 | } | |
573 | ||
574 | PdfDictionary dic; | |
575 | PdfObject obj = dicAp.get(ap); | |
576 |
2
1. setAppearance : negated conditional → NO_COVERAGE 2. setAppearance : negated conditional → NO_COVERAGE |
if (obj != null && obj.isDictionary()) { |
577 | dic = (PdfDictionary) obj; | |
578 | } else { | |
579 | dic = new PdfDictionary(); | |
580 | } | |
581 |
1
1. setAppearance : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
dic.put(new PdfName(state), template.getIndirectReference()); |
582 |
1
1. setAppearance : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
dicAp.put(ap, dic); |
583 |
1
1. setAppearance : removed call to com/lowagie/text/pdf/PdfAnnotation::put → NO_COVERAGE |
put(PdfName.AP, dicAp); |
584 |
1
1. setAppearance : negated conditional → NO_COVERAGE |
if (!form) { |
585 | return; | |
586 | } | |
587 |
1
1. setAppearance : negated conditional → NO_COVERAGE |
if (templates == null) { |
588 | templates = new HashMap<>(); | |
589 | } | |
590 | templates.put(template, null); | |
591 | } | |
592 | ||
593 | public void setAppearanceState(String state) { | |
594 |
1
1. setAppearanceState : negated conditional → NO_COVERAGE |
if (state == null) { |
595 |
1
1. setAppearanceState : removed call to com/lowagie/text/pdf/PdfAnnotation::remove → NO_COVERAGE |
remove(PdfName.AS); |
596 | return; | |
597 | } | |
598 |
1
1. setAppearanceState : removed call to com/lowagie/text/pdf/PdfAnnotation::put → NO_COVERAGE |
put(PdfName.AS, new PdfName(state)); |
599 | } | |
600 | ||
601 | public void setColor(Color color) { | |
602 |
1
1. setColor : removed call to com/lowagie/text/pdf/PdfAnnotation::put → NO_COVERAGE |
put(PdfName.C, new PdfColor(color)); |
603 | } | |
604 | ||
605 | public void setTitle(String title) { | |
606 |
1
1. setTitle : negated conditional → NO_COVERAGE |
if (title == null) { |
607 |
1
1. setTitle : removed call to com/lowagie/text/pdf/PdfAnnotation::remove → NO_COVERAGE |
remove(PdfName.T); |
608 | return; | |
609 | } | |
610 |
1
1. setTitle : removed call to com/lowagie/text/pdf/PdfAnnotation::put → NO_COVERAGE |
put(PdfName.T, new PdfString(title, PdfObject.TEXT_UNICODE)); |
611 | } | |
612 | ||
613 | public void setPopup(PdfAnnotation popup) { | |
614 |
1
1. setPopup : removed call to com/lowagie/text/pdf/PdfAnnotation::put → NO_COVERAGE |
put(PdfName.POPUP, popup.getIndirectReference()); |
615 |
1
1. setPopup : removed call to com/lowagie/text/pdf/PdfAnnotation::put → NO_COVERAGE |
popup.put(PdfName.PARENT, getIndirectReference()); |
616 | } | |
617 | ||
618 | public void setAction(PdfAction action) { | |
619 |
1
1. setAction : removed call to com/lowagie/text/pdf/PdfAnnotation::put → NO_COVERAGE |
put(PdfName.A, action); |
620 | } | |
621 | ||
622 | public void setAdditionalActions(PdfName key, PdfAction action) { | |
623 | PdfDictionary dic; | |
624 | PdfObject obj = get(PdfName.AA); | |
625 |
2
1. setAdditionalActions : negated conditional → NO_COVERAGE 2. setAdditionalActions : negated conditional → NO_COVERAGE |
if (obj != null && obj.isDictionary()) { |
626 | dic = (PdfDictionary) obj; | |
627 | } else { | |
628 | dic = new PdfDictionary(); | |
629 | } | |
630 |
1
1. setAdditionalActions : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
dic.put(key, action); |
631 |
1
1. setAdditionalActions : removed call to com/lowagie/text/pdf/PdfAnnotation::put → NO_COVERAGE |
put(PdfName.AA, dic); |
632 | } | |
633 | ||
634 | /** | |
635 | * Getter for property used. | |
636 | * | |
637 | * @return Value of property used. | |
638 | */ | |
639 | public boolean isUsed() { | |
640 | return used; | |
641 | } | |
642 | ||
643 | /** | |
644 | * Setter for property used. | |
645 | */ | |
646 | public void setUsed() { | |
647 | used = true; | |
648 | } | |
649 | ||
650 | public Map<PdfTemplate, Object> getTemplates() { | |
651 | return templates; | |
652 | } | |
653 | ||
654 | /** | |
655 | * Getter for property form. | |
656 | * | |
657 | * @return Value of property form. | |
658 | */ | |
659 | public boolean isForm() { | |
660 | return form; | |
661 | } | |
662 | ||
663 | /** | |
664 | * Getter for property annotation. | |
665 | * | |
666 | * @return Value of property annotation. | |
667 | */ | |
668 | public boolean isAnnotation() { | |
669 | return annotation; | |
670 | } | |
671 | ||
672 | public void setPage(int page) { | |
673 |
1
1. setPage : removed call to com/lowagie/text/pdf/PdfAnnotation::put → NO_COVERAGE |
put(PdfName.P, writer.getPageReference(page)); |
674 | } | |
675 | ||
676 | public void setPage() { | |
677 |
1
1. setPage : removed call to com/lowagie/text/pdf/PdfAnnotation::put → NO_COVERAGE |
put(PdfName.P, writer.getCurrentPage()); |
678 | } | |
679 | ||
680 | /** | |
681 | * Getter for property placeInPage. | |
682 | * | |
683 | * @return Value of property placeInPage. | |
684 | */ | |
685 | public int getPlaceInPage() { | |
686 | return placeInPage; | |
687 | } | |
688 | ||
689 | /** | |
690 | * Places the annotation in a specified page that must be greater or equal to the current one. With <code>PdfStamper</code> the page can | |
691 | * be any. The first page is 1. | |
692 | * | |
693 | * @param placeInPage New value of property placeInPage. | |
694 | */ | |
695 | public void setPlaceInPage(int placeInPage) { | |
696 | this.placeInPage = placeInPage; | |
697 | } | |
698 | ||
699 | public void setRotate(int v) { | |
700 |
1
1. setRotate : removed call to com/lowagie/text/pdf/PdfAnnotation::put → NO_COVERAGE |
put(PdfName.ROTATE, new PdfNumber(v)); |
701 | } | |
702 | ||
703 | PdfDictionary getMK() { | |
704 | PdfDictionary mk = (PdfDictionary) get(PdfName.MK); | |
705 |
1
1. getMK : negated conditional → NO_COVERAGE |
if (mk == null) { |
706 | mk = new PdfDictionary(); | |
707 |
1
1. getMK : removed call to com/lowagie/text/pdf/PdfAnnotation::put → NO_COVERAGE |
put(PdfName.MK, mk); |
708 | } | |
709 |
1
1. getMK : mutated return of Object value for com/lowagie/text/pdf/PdfAnnotation::getMK to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return mk; |
710 | } | |
711 | ||
712 | public void setMKRotation(int rotation) { | |
713 |
1
1. setMKRotation : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
getMK().put(PdfName.R, new PdfNumber(rotation)); |
714 | } | |
715 | ||
716 | public static PdfArray getMKColor(Color color) { | |
717 | PdfArray array = new PdfArray(); | |
718 | int type = ExtendedColor.getType(color); | |
719 | switch (type) { | |
720 | case ExtendedColor.TYPE_GRAY: { | |
721 | array.add(new PdfNumber(((GrayColor) color).getGray())); | |
722 | break; | |
723 | } | |
724 | case ExtendedColor.TYPE_CMYK: { | |
725 | CMYKColor cmyk = (CMYKColor) color; | |
726 | array.add(new PdfNumber(cmyk.getCyan())); | |
727 | array.add(new PdfNumber(cmyk.getMagenta())); | |
728 | array.add(new PdfNumber(cmyk.getYellow())); | |
729 | array.add(new PdfNumber(cmyk.getBlack())); | |
730 | break; | |
731 | } | |
732 | case ExtendedColor.TYPE_SEPARATION: | |
733 | case ExtendedColor.TYPE_PATTERN: | |
734 | case ExtendedColor.TYPE_SHADING: | |
735 | throw new RuntimeException( | |
736 | MessageLocalization.getComposedMessage("separations.patterns.and.shadings.are.not.allowed.in.mk.dictionary")); | |
737 | default: | |
738 |
1
1. getMKColor : Replaced float division with multiplication → NO_COVERAGE |
array.add(new PdfNumber(color.getRed() / 255f)); |
739 |
1
1. getMKColor : Replaced float division with multiplication → NO_COVERAGE |
array.add(new PdfNumber(color.getGreen() / 255f)); |
740 |
1
1. getMKColor : Replaced float division with multiplication → NO_COVERAGE |
array.add(new PdfNumber(color.getBlue() / 255f)); |
741 | } | |
742 |
1
1. getMKColor : mutated return of Object value for com/lowagie/text/pdf/PdfAnnotation::getMKColor to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return array; |
743 | } | |
744 | ||
745 | public void setMKBorderColor(Color color) { | |
746 |
1
1. setMKBorderColor : negated conditional → NO_COVERAGE |
if (color == null) { |
747 |
1
1. setMKBorderColor : removed call to com/lowagie/text/pdf/PdfDictionary::remove → NO_COVERAGE |
getMK().remove(PdfName.BC); |
748 | } else { | |
749 |
1
1. setMKBorderColor : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
getMK().put(PdfName.BC, getMKColor(color)); |
750 | } | |
751 | } | |
752 | ||
753 | public void setMKBackgroundColor(Color color) { | |
754 |
1
1. setMKBackgroundColor : negated conditional → NO_COVERAGE |
if (color == null) { |
755 |
1
1. setMKBackgroundColor : removed call to com/lowagie/text/pdf/PdfDictionary::remove → NO_COVERAGE |
getMK().remove(PdfName.BG); |
756 | } else { | |
757 |
1
1. setMKBackgroundColor : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
getMK().put(PdfName.BG, getMKColor(color)); |
758 | } | |
759 | } | |
760 | ||
761 | public void setMKNormalCaption(String caption) { | |
762 |
1
1. setMKNormalCaption : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
getMK().put(PdfName.CA, new PdfString(caption, PdfObject.TEXT_UNICODE)); |
763 | } | |
764 | ||
765 | public void setMKRolloverCaption(String caption) { | |
766 |
1
1. setMKRolloverCaption : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
getMK().put(PdfName.RC, new PdfString(caption, PdfObject.TEXT_UNICODE)); |
767 | } | |
768 | ||
769 | public void setMKAlternateCaption(String caption) { | |
770 |
1
1. setMKAlternateCaption : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
getMK().put(PdfName.AC, new PdfString(caption, PdfObject.TEXT_UNICODE)); |
771 | } | |
772 | ||
773 | public void setMKNormalIcon(PdfTemplate template) { | |
774 |
1
1. setMKNormalIcon : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
getMK().put(PdfName.I, template.getIndirectReference()); |
775 | } | |
776 | ||
777 | public void setMKRolloverIcon(PdfTemplate template) { | |
778 |
1
1. setMKRolloverIcon : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
getMK().put(PdfName.RI, template.getIndirectReference()); |
779 | } | |
780 | ||
781 | public void setMKAlternateIcon(PdfTemplate template) { | |
782 |
1
1. setMKAlternateIcon : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
getMK().put(PdfName.IX, template.getIndirectReference()); |
783 | } | |
784 | ||
785 | public void setMKIconFit(PdfName scale, PdfName scalingType, float leftoverLeft, float leftoverBottom, boolean fitInBounds) { | |
786 | PdfDictionary dic = new PdfDictionary(); | |
787 |
1
1. setMKIconFit : negated conditional → NO_COVERAGE |
if (!scale.equals(PdfName.A)) { |
788 |
1
1. setMKIconFit : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
dic.put(PdfName.SW, scale); |
789 | } | |
790 |
1
1. setMKIconFit : negated conditional → NO_COVERAGE |
if (!scalingType.equals(PdfName.P)) { |
791 |
1
1. setMKIconFit : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
dic.put(PdfName.S, scalingType); |
792 | } | |
793 |
2
1. setMKIconFit : negated conditional → NO_COVERAGE 2. setMKIconFit : negated conditional → NO_COVERAGE |
if (leftoverLeft != 0.5f || leftoverBottom != 0.5f) { |
794 | PdfArray array = new PdfArray(new PdfNumber(leftoverLeft)); | |
795 | array.add(new PdfNumber(leftoverBottom)); | |
796 |
1
1. setMKIconFit : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
dic.put(PdfName.A, array); |
797 | } | |
798 |
1
1. setMKIconFit : negated conditional → NO_COVERAGE |
if (fitInBounds) { |
799 |
1
1. setMKIconFit : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
dic.put(PdfName.FB, PdfBoolean.PDFTRUE); |
800 | } | |
801 |
1
1. setMKIconFit : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
getMK().put(PdfName.IF, dic); |
802 | } | |
803 | ||
804 | public void setMKTextPosition(int tp) { | |
805 |
1
1. setMKTextPosition : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
getMK().put(PdfName.TP, new PdfNumber(tp)); |
806 | } | |
807 | ||
808 | /** | |
809 | * Sets the layer this annotation belongs to. | |
810 | * | |
811 | * @param layer the layer this annotation belongs to | |
812 | */ | |
813 | public void setLayer(PdfOCG layer) { | |
814 |
1
1. setLayer : removed call to com/lowagie/text/pdf/PdfAnnotation::put → NO_COVERAGE |
put(PdfName.OC, layer.getRef()); |
815 | } | |
816 | ||
817 | /** | |
818 | * Sets the name of the annotation. With this name the annotation can be identified among all the annotations on a page (it has to be | |
819 | * unique). | |
820 | */ | |
821 | public void setName(String name) { | |
822 |
1
1. setName : removed call to com/lowagie/text/pdf/PdfAnnotation::put → NO_COVERAGE |
put(PdfName.NM, new PdfString(name)); |
823 | } | |
824 | ||
825 | /** | |
826 | * This class processes links from imported pages so that they may be active. The following example code reads a group of files and places | |
827 | * them all on the output PDF, four pages in a single page, keeping the links active. | |
828 | * <pre> | |
829 | * String[] files = new String[] {"input1.pdf", "input2.pdf"}; | |
830 | * String outputFile = "output.pdf"; | |
831 | * int firstPage=1; | |
832 | * Document document = new Document(); | |
833 | * PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(outputFile)); | |
834 | * document.setPageSize(PageSize.A4); | |
835 | * float W = PageSize.A4.getWidth() / 2; | |
836 | * float H = PageSize.A4.getHeight() / 2; | |
837 | * document.open(); | |
838 | * PdfContentByte cb = writer.getDirectContent(); | |
839 | * for (int i = 0; i < files.length; i++) { | |
840 | * PdfReader currentReader = new PdfReader(files[i]); | |
841 | * currentReader.consolidateNamedDestinations(); | |
842 | * for (int page = 1; page <= currentReader.getNumberOfPages(); page++) { | |
843 | * PdfImportedPage importedPage = writer.getImportedPage(currentReader, page); | |
844 | * float a = 0.5f; | |
845 | * float e = (page % 2 == 0) ? W : 0; | |
846 | * float f = (page % 4 == 1 || page % 4 == 2) ? H : 0; | |
847 | * ArrayList links = currentReader.getLinks(page); | |
848 | * cb.addTemplate(importedPage, a, 0, 0, a, e, f); | |
849 | * for (int j = 0; j < links.size(); j++) { | |
850 | * PdfAnnotation.PdfImportedLink link = (PdfAnnotation.PdfImportedLink)links.get(j); | |
851 | * if (link.isInternal()) { | |
852 | * int dPage = link.getDestinationPage(); | |
853 | * int newDestPage = (dPage-1)/4 + firstPage; | |
854 | * float ee = (dPage % 2 == 0) ? W : 0; | |
855 | * float ff = (dPage % 4 == 1 || dPage % 4 == 2) ? H : 0; | |
856 | * link.setDestinationPage(newDestPage); | |
857 | * link.transformDestination(a, 0, 0, a, ee, ff); | |
858 | * } | |
859 | * link.transformRect(a, 0, 0, a, e, f); | |
860 | * writer.addAnnotation(link.createAnnotation(writer)); | |
861 | * } | |
862 | * if (page % 4 == 0) | |
863 | * document.newPage(); | |
864 | * } | |
865 | * if (i < files.length - 1) | |
866 | * document.newPage(); | |
867 | * firstPage += (currentReader.getNumberOfPages()+3)/4; | |
868 | * } | |
869 | * document.close(); | |
870 | * </pre> | |
871 | */ | |
872 | public static class PdfImportedLink { | |
873 | ||
874 | float llx, lly, urx, ury; | |
875 | HashMap<PdfName, PdfObject> parameters = new HashMap<>(); | |
876 | PdfArray destination; | |
877 | int newPage = 0; | |
878 | ||
879 | PdfImportedLink(PdfDictionary annotation) { | |
880 |
1
1. |
parameters.putAll(annotation.hashMap); |
881 | try { | |
882 | destination = (PdfArray) parameters.remove(PdfName.DEST); | |
883 | } catch (ClassCastException ex) { | |
884 | throw new IllegalArgumentException( | |
885 | MessageLocalization.getComposedMessage("you.have.to.consolidate.the.named.destinations.of.your.reader")); | |
886 | } | |
887 |
1
1. |
if (destination != null) { |
888 | destination = new PdfArray(destination); | |
889 | } | |
890 | PdfArray rc = (PdfArray) parameters.remove(PdfName.RECT); | |
891 | llx = rc.getAsNumber(0).floatValue(); | |
892 | lly = rc.getAsNumber(1).floatValue(); | |
893 | urx = rc.getAsNumber(2).floatValue(); | |
894 | ury = rc.getAsNumber(3).floatValue(); | |
895 | } | |
896 | ||
897 | public boolean isInternal() { | |
898 |
2
1. isInternal : negated conditional → NO_COVERAGE 2. isInternal : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return destination != null; |
899 | } | |
900 | ||
901 | public int getDestinationPage() { | |
902 |
1
1. getDestinationPage : negated conditional → NO_COVERAGE |
if (!isInternal()) { |
903 |
1
1. getDestinationPage : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return 0; |
904 | } | |
905 | ||
906 | // here destination is something like | |
907 | // [132 0 R, /XYZ, 29.3898, 731.864502, null] | |
908 | PdfIndirectReference ref = destination.getAsIndirectObject(0); | |
909 | ||
910 | PRIndirectReference pr = (PRIndirectReference) ref; | |
911 | PdfReader r = pr.getReader(); | |
912 |
2
1. getDestinationPage : changed conditional boundary → NO_COVERAGE 2. getDestinationPage : negated conditional → NO_COVERAGE |
for (int i = 1; i <= r.getNumberOfPages(); i++) { |
913 | PRIndirectReference pp = r.getPageOrigRef(i); | |
914 |
2
1. getDestinationPage : negated conditional → NO_COVERAGE 2. getDestinationPage : negated conditional → NO_COVERAGE |
if (pp.getGeneration() == pr.getGeneration() && pp.getNumber() == pr.getNumber()) { |
915 |
1
1. getDestinationPage : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return i; |
916 | } | |
917 | } | |
918 | throw new IllegalArgumentException(MessageLocalization.getComposedMessage("page.not.found")); | |
919 | } | |
920 | ||
921 | public void setDestinationPage(int newPage) { | |
922 |
1
1. setDestinationPage : negated conditional → NO_COVERAGE |
if (!isInternal()) { |
923 | throw new IllegalArgumentException(MessageLocalization.getComposedMessage("cannot.change.destination.of.external.link")); | |
924 | } | |
925 | this.newPage = newPage; | |
926 | } | |
927 | ||
928 | public void transformDestination(float a, float b, float c, float d, float e, float f) { | |
929 |
1
1. transformDestination : negated conditional → NO_COVERAGE |
if (!isInternal()) { |
930 | throw new IllegalArgumentException(MessageLocalization.getComposedMessage("cannot.change.destination.of.external.link")); | |
931 | } | |
932 |
1
1. transformDestination : negated conditional → NO_COVERAGE |
if (destination.getAsName(1).equals(PdfName.XYZ)) { |
933 | float x = destination.getAsNumber(2).floatValue(); | |
934 | float y = destination.getAsNumber(3).floatValue(); | |
935 |
4
1. transformDestination : Replaced float multiplication with division → NO_COVERAGE 2. transformDestination : Replaced float multiplication with division → NO_COVERAGE 3. transformDestination : Replaced float addition with subtraction → NO_COVERAGE 4. transformDestination : Replaced float addition with subtraction → NO_COVERAGE |
float xx = x * a + y * c + e; |
936 |
4
1. transformDestination : Replaced float multiplication with division → NO_COVERAGE 2. transformDestination : Replaced float multiplication with division → NO_COVERAGE 3. transformDestination : Replaced float addition with subtraction → NO_COVERAGE 4. transformDestination : Replaced float addition with subtraction → NO_COVERAGE |
float yy = x * b + y * d + f; |
937 | destination.set(2, new PdfNumber(xx)); | |
938 | destination.set(3, new PdfNumber(yy)); | |
939 | } | |
940 | } | |
941 | ||
942 | public void transformRect(float a, float b, float c, float d, float e, float f) { | |
943 |
4
1. transformRect : Replaced float multiplication with division → NO_COVERAGE 2. transformRect : Replaced float multiplication with division → NO_COVERAGE 3. transformRect : Replaced float addition with subtraction → NO_COVERAGE 4. transformRect : Replaced float addition with subtraction → NO_COVERAGE |
float x = llx * a + lly * c + e; |
944 |
4
1. transformRect : Replaced float multiplication with division → NO_COVERAGE 2. transformRect : Replaced float multiplication with division → NO_COVERAGE 3. transformRect : Replaced float addition with subtraction → NO_COVERAGE 4. transformRect : Replaced float addition with subtraction → NO_COVERAGE |
float y = llx * b + lly * d + f; |
945 | llx = x; | |
946 | lly = y; | |
947 |
4
1. transformRect : Replaced float multiplication with division → NO_COVERAGE 2. transformRect : Replaced float multiplication with division → NO_COVERAGE 3. transformRect : Replaced float addition with subtraction → NO_COVERAGE 4. transformRect : Replaced float addition with subtraction → NO_COVERAGE |
x = urx * a + ury * c + e; |
948 |
4
1. transformRect : Replaced float multiplication with division → NO_COVERAGE 2. transformRect : Replaced float multiplication with division → NO_COVERAGE 3. transformRect : Replaced float addition with subtraction → NO_COVERAGE 4. transformRect : Replaced float addition with subtraction → NO_COVERAGE |
y = urx * b + ury * d + f; |
949 | urx = x; | |
950 | ury = y; | |
951 | } | |
952 | ||
953 | public PdfAnnotation createAnnotation(PdfWriter writer) { | |
954 | PdfAnnotation annotation = new PdfAnnotation(writer, new Rectangle(llx, lly, urx, ury)); | |
955 |
1
1. createAnnotation : negated conditional → NO_COVERAGE |
if (newPage != 0) { |
956 | PdfIndirectReference ref = writer.getPageReference(newPage); | |
957 | destination.set(0, ref); | |
958 | } | |
959 |
1
1. createAnnotation : negated conditional → NO_COVERAGE |
if (destination != null) { |
960 |
1
1. createAnnotation : removed call to com/lowagie/text/pdf/PdfAnnotation::put → NO_COVERAGE |
annotation.put(PdfName.DEST, destination); |
961 | } | |
962 |
1
1. createAnnotation : removed call to java/util/Map::putAll → NO_COVERAGE |
annotation.hashMap.putAll(parameters); |
963 |
1
1. createAnnotation : mutated return of Object value for com/lowagie/text/pdf/PdfAnnotation$PdfImportedLink::createAnnotation to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return annotation; |
964 | } | |
965 | ||
966 | /** | |
967 | * Returns a String representation of the link. | |
968 | * | |
969 | * @return a String representation of the imported link | |
970 | * @since 2.1.6 | |
971 | */ | |
972 | public String toString() { | |
973 | StringBuilder buf = new StringBuilder("Imported link: location ["); | |
974 | buf.append(llx); | |
975 | buf.append(' '); | |
976 | buf.append(lly); | |
977 | buf.append(' '); | |
978 | buf.append(urx); | |
979 | buf.append(' '); | |
980 | buf.append(ury); | |
981 | buf.append("] destination "); | |
982 | buf.append(destination); | |
983 | buf.append(" parameters "); | |
984 | buf.append(parameters); | |
985 | return buf.toString(); | |
986 | } | |
987 | } | |
988 | } | |
Mutations | ||
220 |
1.1 |
|
221 |
1.1 |
|
231 |
1.1 |
|
232 |
1.1 |
|
233 |
1.1 |
|
234 |
1.1 |
|
243 |
1.1 |
|
244 |
1.1 |
|
245 |
1.1 |
|
246 |
1.1 |
|
247 |
1.1 |
|
258 |
1.1 |
|
259 |
1.1 |
|
260 |
1.1 |
|
261 |
1.1 |
|
266 |
1.1 |
|
268 |
1.1 |
|
269 |
1.1 |
|
271 |
1.1 |
|
272 |
1.1 |
|
281 |
1.1 |
|
284 |
1.1 |
|
292 |
1.1 |
|
293 |
1.1 |
|
294 |
1.1 |
|
296 |
1.1 |
|
297 |
1.1 |
|
299 |
1.1 |
|
300 |
1.1 |
|
302 |
1.1 |
|
303 |
1.1 |
|
305 |
1.1 |
|
315 |
1.1 |
|
316 |
1.1 |
|
317 |
1.1 |
|
319 |
1.1 |
|
329 |
1.1 |
|
330 |
1.1 |
|
340 |
1.1 |
|
341 |
1.1 |
|
353 |
1.1 |
|
354 |
1.1 |
|
364 |
1.1 |
|
365 |
1.1 |
|
366 |
1.1 |
|
367 |
1.1 |
|
377 |
1.1 |
|
378 |
1.1 |
|
383 |
1.1 |
|
384 |
1.1 |
|
396 |
1.1 |
|
397 |
1.1 |
|
399 |
1.1 |
|
401 |
1.1 |
|
402 |
1.1 |
|
419 |
1.1 |
|
420 |
1.1 |
|
425 |
1.1 |
|
426 |
1.1 |
|
436 |
1.1 |
|
437 |
1.1 |
|
438 |
1.1 |
|
439 |
1.1 |
|
444 |
1.1 |
|
445 |
1.1 |
|
447 |
1.1 |
|
455 |
1.1 |
|
456 |
1.1 |
|
474 |
1.1 |
|
485 |
1.1 |
|
486 |
1.1 |
|
487 |
1.1 |
|
489 |
1.1 |
|
490 |
1.1 |
|
500 |
1.1 |
|
501 |
1.1 |
|
502 |
1.1 |
|
504 |
1.1 |
|
505 |
1.1 |
|
507 |
1.1 |
|
513 |
1.1 2.2 3.3 |
|
514 |
1.1 |
|
518 |
1.1 |
|
522 |
1.1 |
|
523 |
1.1 |
|
525 |
1.1 |
|
530 |
1.1 |
|
534 |
1.1 |
|
545 |
1.1 |
|
546 |
1.1 |
|
548 |
1.1 |
|
554 |
1.1 |
|
557 |
1.1 |
|
558 |
1.1 |
|
559 |
1.1 |
|
562 |
1.1 |
|
570 |
1.1 |
|
576 |
1.1 2.2 |
|
581 |
1.1 |
|
582 |
1.1 |
|
583 |
1.1 |
|
584 |
1.1 |
|
587 |
1.1 |
|
594 |
1.1 |
|
595 |
1.1 |
|
598 |
1.1 |
|
602 |
1.1 |
|
606 |
1.1 |
|
607 |
1.1 |
|
610 |
1.1 |
|
614 |
1.1 |
|
615 |
1.1 |
|
619 |
1.1 |
|
625 |
1.1 2.2 |
|
630 |
1.1 |
|
631 |
1.1 |
|
673 |
1.1 |
|
677 |
1.1 |
|
700 |
1.1 |
|
705 |
1.1 |
|
707 |
1.1 |
|
709 |
1.1 |
|
713 |
1.1 |
|
738 |
1.1 |
|
739 |
1.1 |
|
740 |
1.1 |
|
742 |
1.1 |
|
746 |
1.1 |
|
747 |
1.1 |
|
749 |
1.1 |
|
754 |
1.1 |
|
755 |
1.1 |
|
757 |
1.1 |
|
762 |
1.1 |
|
766 |
1.1 |
|
770 |
1.1 |
|
774 |
1.1 |
|
778 |
1.1 |
|
782 |
1.1 |
|
787 |
1.1 |
|
788 |
1.1 |
|
790 |
1.1 |
|
791 |
1.1 |
|
793 |
1.1 2.2 |
|
796 |
1.1 |
|
798 |
1.1 |
|
799 |
1.1 |
|
801 |
1.1 |
|
805 |
1.1 |
|
814 |
1.1 |
|
822 |
1.1 |
|
880 |
1.1 |
|
887 |
1.1 |
|
898 |
1.1 2.2 |
|
902 |
1.1 |
|
903 |
1.1 |
|
912 |
1.1 2.2 |
|
914 |
1.1 2.2 |
|
915 |
1.1 |
|
922 |
1.1 |
|
929 |
1.1 |
|
932 |
1.1 |
|
935 |
1.1 2.2 3.3 4.4 |
|
936 |
1.1 2.2 3.3 4.4 |
|
943 |
1.1 2.2 3.3 4.4 |
|
944 |
1.1 2.2 3.3 4.4 |
|
947 |
1.1 2.2 3.3 4.4 |
|
948 |
1.1 2.2 3.3 4.4 |
|
955 |
1.1 |
|
959 |
1.1 |
|
960 |
1.1 |
|
962 |
1.1 |
|
963 |
1.1 |