1 | /* | |
2 | * $Id: Chunk.java 4092 2009-11-11 17:58:16Z psoares33 $ | |
3 | * | |
4 | * Copyright 1999, 2000, 2001, 2002 by 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; | |
51 | ||
52 | import java.awt.Color; | |
53 | import java.net.URL; | |
54 | import java.util.ArrayList; | |
55 | import java.util.HashMap; | |
56 | import java.util.Map; | |
57 | ||
58 | import com.lowagie.text.error_messages.MessageLocalization; | |
59 | ||
60 | import com.lowagie.text.pdf.HyphenationEvent; | |
61 | import com.lowagie.text.pdf.PdfAction; | |
62 | import com.lowagie.text.pdf.PdfAnnotation; | |
63 | import com.lowagie.text.pdf.PdfContentByte; | |
64 | import com.lowagie.text.pdf.draw.DrawInterface; | |
65 | ||
66 | /** | |
67 | * This is the smallest significant part of text that can be added to a | |
68 | * document. | |
69 | * <P> | |
70 | * Most elements can be divided in one or more <CODE>Chunk</CODE>s. A chunk | |
71 | * is a <CODE>String</CODE> with a certain <CODE>Font</CODE>. All other | |
72 | * layout parameters should be defined in the object to which this chunk of text | |
73 | * is added. | |
74 | * <P> | |
75 | * Example: <BLOCKQUOTE> | |
76 | * | |
77 | * <PRE> | |
78 | * | |
79 | * <STRONG>Chunk chunk = new Chunk("Hello world", | |
80 | * FontFactory.getFont(FontFactory.COURIER, 20, Font.ITALIC, new Color(255, 0, | |
81 | * 0))); </STRONG> document.add(chunk); | |
82 | * | |
83 | * </PRE> | |
84 | * | |
85 | * </BLOCKQUOTE> | |
86 | */ | |
87 | ||
88 | public class Chunk implements Element { | |
89 | ||
90 | // public static membervariables | |
91 | ||
92 | /** The character stand in for an image or a separator. */ | |
93 | public static final String OBJECT_REPLACEMENT_CHARACTER = "\ufffc"; | |
94 | ||
95 | /** This is a Chunk containing a newline. */ | |
96 | public static final Chunk NEWLINE = new Chunk("\n"); | |
97 | ||
98 | /** This is a Chunk containing a newpage. */ | |
99 | public static final Chunk NEXTPAGE = new Chunk(""); | |
100 | static { | |
101 | NEXTPAGE.setNewPage(); | |
102 | } | |
103 | ||
104 | // member variables | |
105 | ||
106 | /** This is the content of this chunk of text. */ | |
107 | protected StringBuffer content = null; | |
108 | ||
109 | /** This is the <CODE>Font</CODE> of this chunk of text. */ | |
110 | protected Font font = null; | |
111 | ||
112 | /** Contains some of the attributes for this Chunk. */ | |
113 | protected Map<String, Object> attributes = null; | |
114 | ||
115 | // constructors | |
116 | ||
117 | /** | |
118 | * Empty constructor. | |
119 | */ | |
120 | public Chunk() { | |
121 | this.content = new StringBuffer(); | |
122 | this.font = new Font(); | |
123 | } | |
124 | ||
125 | /** | |
126 | * A <CODE>Chunk</CODE> copy constructor. | |
127 | * @param ck the <CODE>Chunk</CODE> to be copied | |
128 | */ | |
129 | public Chunk(Chunk ck) { | |
130 |
1
1. |
if (ck.content != null) { |
131 | content = new StringBuffer(ck.content.toString()); | |
132 | } | |
133 |
1
1. |
if (ck.font != null) { |
134 | font = new Font(ck.font); | |
135 | } | |
136 |
1
1. |
if (ck.attributes != null) { |
137 | attributes = new HashMap<>(ck.attributes); | |
138 | } | |
139 | } | |
140 | | |
141 | /** | |
142 | * Constructs a chunk of text with a certain content and a certain <CODE> | |
143 | * Font</CODE>. | |
144 | * | |
145 | * @param content | |
146 | * the content | |
147 | * @param font | |
148 | * the font | |
149 | */ | |
150 | public Chunk(String content, Font font) { | |
151 | this.content = new StringBuffer(content); | |
152 | this.font = font; | |
153 | } | |
154 | ||
155 | /** | |
156 | * Constructs a chunk of text with a certain content, without specifying a | |
157 | * <CODE>Font</CODE>. | |
158 | * | |
159 | * @param content | |
160 | * the content | |
161 | */ | |
162 | public Chunk(String content) { | |
163 | this(content, new Font()); | |
164 | } | |
165 | ||
166 | /** | |
167 | * Constructs a chunk of text with a char and a certain <CODE>Font</CODE>. | |
168 | * | |
169 | * @param c | |
170 | * the content | |
171 | * @param font | |
172 | * the font | |
173 | */ | |
174 | public Chunk(char c, Font font) { | |
175 | this.content = new StringBuffer(); | |
176 | this.content.append(c); | |
177 | this.font = font; | |
178 | } | |
179 | ||
180 | /** | |
181 | * Constructs a chunk of text with a char, without specifying a <CODE>Font | |
182 | * </CODE>. | |
183 | * | |
184 | * @param c | |
185 | * the content | |
186 | */ | |
187 | public Chunk(char c) { | |
188 | this(c, new Font()); | |
189 | } | |
190 | ||
191 | /** | |
192 | * Constructs a chunk containing an <CODE>Image</CODE>. | |
193 | * | |
194 | * @param image | |
195 | * the image | |
196 | * @param offsetX | |
197 | * the image offset in the x direction | |
198 | * @param offsetY | |
199 | * the image offset in the y direction | |
200 | */ | |
201 | public Chunk(Image image, float offsetX, float offsetY) { | |
202 | this(OBJECT_REPLACEMENT_CHARACTER, new Font()); | |
203 | Image copyImage = Image.getInstance(image); | |
204 |
1
1. |
copyImage.setAbsolutePosition(Float.NaN, Float.NaN); |
205 | setAttribute(IMAGE, new Object[] { copyImage, offsetX, | |
206 | offsetY, Boolean.FALSE }); | |
207 | } | |
208 | ||
209 | /** | |
210 | * Key for drawInterface of the Separator. | |
211 | * @since 2.1.2 | |
212 | */ | |
213 | public static final String SEPARATOR = "SEPARATOR"; | |
214 | | |
215 | /** | |
216 | * Creates a separator Chunk. | |
217 | * Note that separator chunks can't be used in combination with tab chunks! | |
218 | * @param separator the drawInterface to use to draw the separator. | |
219 | * @since 2.1.2 | |
220 | */ | |
221 | public Chunk(DrawInterface separator) { | |
222 | this(separator, false); | |
223 | } | |
224 | | |
225 | /** | |
226 | * Creates a separator Chunk. | |
227 | * Note that separator chunks can't be used in combination with tab chunks! | |
228 | * @param separator the drawInterface to use to draw the separator. | |
229 | * @param vertical true if this is a vertical separator | |
230 | * @since 2.1.2 | |
231 | */ | |
232 | public Chunk(DrawInterface separator, boolean vertical) { | |
233 | this(OBJECT_REPLACEMENT_CHARACTER, new Font()); | |
234 | setAttribute(SEPARATOR, new Object[] {separator, vertical}); | |
235 | } | |
236 | ||
237 | /** | |
238 | * Key for drawInterface of the tab. | |
239 | * @since 2.1.2 | |
240 | */ | |
241 | public static final String TAB = "TAB"; | |
242 | | |
243 | /** | |
244 | * Creates a tab Chunk. | |
245 | * Note that separator chunks can't be used in combination with tab chunks! | |
246 | * @param separator the drawInterface to use to draw the tab. | |
247 | * @param tabPosition an X coordinate that will be used as start position for the next Chunk. | |
248 | * @since 2.1.2 | |
249 | */ | |
250 | public Chunk(DrawInterface separator, float tabPosition) { | |
251 | this(separator, tabPosition, false); | |
252 | } | |
253 | | |
254 | /** | |
255 | * Creates a tab Chunk. | |
256 | * Note that separator chunks can't be used in combination with tab chunks! | |
257 | * @param separator the drawInterface to use to draw the tab. | |
258 | * @param tabPosition an X coordinate that will be used as start position for the next Chunk. | |
259 | * @param newline if true, a newline will be added if the tabPosition has already been reached. | |
260 | * @since 2.1.2 | |
261 | */ | |
262 | public Chunk(DrawInterface separator, float tabPosition, boolean newline) { | |
263 | this(OBJECT_REPLACEMENT_CHARACTER, new Font()); | |
264 |
2
1. 2. |
if (tabPosition < 0) { |
265 | throw new IllegalArgumentException(MessageLocalization.getComposedMessage("a.tab.position.may.not.be.lower.than.0.yours.is.1", String.valueOf(tabPosition))); | |
266 | } | |
267 | setAttribute(TAB, new Object[] {separator, tabPosition, newline, (float) 0}); | |
268 | } | |
269 | ||
270 | /** | |
271 | * Constructs a chunk containing an <CODE>Image</CODE>. | |
272 | * | |
273 | * @param image | |
274 | * the image | |
275 | * @param offsetX | |
276 | * the image offset in the x direction | |
277 | * @param offsetY | |
278 | * the image offset in the y direction | |
279 | * @param changeLeading | |
280 | * true if the leading has to be adapted to the image | |
281 | */ | |
282 | public Chunk(Image image, float offsetX, float offsetY, | |
283 | boolean changeLeading) { | |
284 | this(OBJECT_REPLACEMENT_CHARACTER, new Font()); | |
285 | setAttribute(IMAGE, new Object[] { image, offsetX, | |
286 | offsetY, changeLeading}); | |
287 | } | |
288 | ||
289 | // implementation of the Element-methods | |
290 | ||
291 | /** | |
292 | * Processes the element by adding it (or the different parts) to an <CODE> | |
293 | * ElementListener</CODE>. | |
294 | * | |
295 | * @param listener | |
296 | * an <CODE>ElementListener</CODE> | |
297 | * @return <CODE>true</CODE> if the element was processed successfully | |
298 | */ | |
299 | public boolean process(ElementListener listener) { | |
300 | try { | |
301 |
1
1. process : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return listener.add(this); |
302 | } catch (DocumentException de) { | |
303 |
1
1. process : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return false; |
304 | } | |
305 | } | |
306 | ||
307 | /** | |
308 | * Gets the type of the text element. | |
309 | * | |
310 | * @return a type | |
311 | */ | |
312 | public int type() { | |
313 | return Element.CHUNK; | |
314 | } | |
315 | ||
316 | /** | |
317 | * Gets all the chunks in this element. | |
318 | * | |
319 | * @return an <CODE>ArrayList</CODE> | |
320 | */ | |
321 | public ArrayList getChunks() { | |
322 | ArrayList tmp = new ArrayList(); | |
323 | tmp.add(this); | |
324 |
1
1. getChunks : mutated return of Object value for com/lowagie/text/Chunk::getChunks to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return tmp; |
325 | } | |
326 | ||
327 | // methods that change the member variables | |
328 | ||
329 | /** | |
330 | * appends some text to this <CODE>Chunk</CODE>. | |
331 | * | |
332 | * @param string | |
333 | * <CODE>String</CODE> | |
334 | * @return a <CODE>StringBuffer</CODE> | |
335 | */ | |
336 | public StringBuffer append(String string) { | |
337 | return content.append(string); | |
338 | } | |
339 | ||
340 | /** | |
341 | * Sets the font of this <CODE>Chunk</CODE>. | |
342 | * | |
343 | * @param font | |
344 | * a <CODE>Font</CODE> | |
345 | */ | |
346 | public void setFont(Font font) { | |
347 | this.font = font; | |
348 | } | |
349 | ||
350 | // methods to retrieve information | |
351 | ||
352 | /** | |
353 | * Gets the font of this <CODE>Chunk</CODE>. | |
354 | * | |
355 | * @return a <CODE>Font</CODE> | |
356 | */ | |
357 | public Font getFont() { | |
358 | return font; | |
359 | } | |
360 | ||
361 | /** | |
362 | * Returns the content of this <CODE>Chunk</CODE>. | |
363 | * | |
364 | * @return a <CODE>String</CODE> | |
365 | */ | |
366 | public String getContent() { | |
367 | return content.toString(); | |
368 | } | |
369 | ||
370 | /** | |
371 | * Returns the content of this <CODE>Chunk</CODE>. | |
372 | * | |
373 | * @return a <CODE>String</CODE> | |
374 | */ | |
375 | public String toString() { | |
376 | return getContent(); | |
377 | } | |
378 | ||
379 | /** | |
380 | * Checks is this <CODE>Chunk</CODE> is empty. | |
381 | * | |
382 | * @return <CODE>false</CODE> if the Chunk contains other characters than | |
383 | * space. | |
384 | */ | |
385 | public boolean isEmpty() { | |
386 |
2
1. isEmpty : negated conditional → SURVIVED 2. isEmpty : replaced return of integer sized value with (x == 0 ? 1 : 0) → SURVIVED |
return (content.toString().trim().length() == 0) |
387 |
2
1. isEmpty : negated conditional → SURVIVED 2. isEmpty : negated conditional → SURVIVED |
&& (!content.toString().contains("\n")) |
388 | && (attributes == null); | |
389 | } | |
390 | ||
391 | /** | |
392 | * Gets the width of the Chunk in points. | |
393 | * | |
394 | * @return a width in points | |
395 | */ | |
396 | public float getWidthPoint() { | |
397 |
1
1. getWidthPoint : negated conditional → NO_COVERAGE |
if (getImage() != null) { |
398 |
1
1. getWidthPoint : replaced return of float value with -(x + 1) for com/lowagie/text/Chunk::getWidthPoint → NO_COVERAGE |
return getImage().getScaledWidth(); |
399 | } | |
400 |
1
1. getWidthPoint : replaced return of float value with -(x + 1) for com/lowagie/text/Chunk::getWidthPoint → NO_COVERAGE |
return font.getCalculatedBaseFont(true).getWidthPoint(getContent(), |
401 | font.getCalculatedSize()) | |
402 |
1
1. getWidthPoint : Replaced float multiplication with division → NO_COVERAGE |
* getHorizontalScaling(); |
403 | } | |
404 | ||
405 | // attributes | |
406 | ||
407 | /** | |
408 | * Checks the attributes of this <CODE>Chunk</CODE>. | |
409 | * | |
410 | * @return false if there aren't any. | |
411 | */ | |
412 | ||
413 | public boolean hasAttributes() { | |
414 |
2
1. hasAttributes : negated conditional → NO_COVERAGE 2. hasAttributes : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return attributes != null; |
415 | } | |
416 | ||
417 | /** | |
418 | * Gets the attributes for this <CODE>Chunk</CODE>. | |
419 | * <P> | |
420 | * It may be null. | |
421 | * | |
422 | * @return the attributes for this <CODE>Chunk</CODE> | |
423 | */ | |
424 | ||
425 | public Map<String, Object> getAttributes() { | |
426 | return attributes; | |
427 | } | |
428 | ||
429 | /** | |
430 | * Sets the attributes all at once. | |
431 | * @param attributes the attributes of a Chunk | |
432 | */ | |
433 | public void setAttributes(Map<String, Object> attributes) { | |
434 | this.attributes = attributes; | |
435 | } | |
436 | ||
437 | /** | |
438 | * Sets an arbitrary attribute. | |
439 | * | |
440 | * @param name | |
441 | * the key for the attribute | |
442 | * @param obj | |
443 | * the value of the attribute | |
444 | * @return this <CODE>Chunk</CODE> | |
445 | */ | |
446 | ||
447 | private Chunk setAttribute(String name, Object obj) { | |
448 |
1
1. setAttribute : negated conditional → SURVIVED |
if (attributes == null) |
449 | attributes = new HashMap<>(); | |
450 | attributes.put(name, obj); | |
451 |
1
1. setAttribute : mutated return of Object value for com/lowagie/text/Chunk::setAttribute to ( if (x != null) null else throw new RuntimeException ) → SURVIVED |
return this; |
452 | } | |
453 | ||
454 | // the attributes are ordered as they appear in the book 'iText in Action' | |
455 | ||
456 | /** Key for text horizontal scaling. */ | |
457 | public static final String HSCALE = "HSCALE"; | |
458 | ||
459 | /** | |
460 | * Sets the text horizontal scaling. A value of 1 is normal and a value of | |
461 | * 0.5f shrinks the text to half it's width. | |
462 | * | |
463 | * @param scale | |
464 | * the horizontal scaling factor | |
465 | * @return this <CODE>Chunk</CODE> | |
466 | */ | |
467 | public Chunk setHorizontalScaling(float scale) { | |
468 |
1
1. setHorizontalScaling : mutated return of Object value for com/lowagie/text/Chunk::setHorizontalScaling to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return setAttribute(HSCALE, scale); |
469 | } | |
470 | ||
471 | /** | |
472 | * Gets the horizontal scaling. | |
473 | * | |
474 | * @return a percentage in float | |
475 | */ | |
476 | public float getHorizontalScaling() { | |
477 |
1
1. getHorizontalScaling : negated conditional → NO_COVERAGE |
if (attributes == null) |
478 |
1
1. getHorizontalScaling : replaced return of float value with -(x + 1) for com/lowagie/text/Chunk::getHorizontalScaling → NO_COVERAGE |
return 1f; |
479 | Float f = (Float) attributes.get(HSCALE); | |
480 |
1
1. getHorizontalScaling : negated conditional → NO_COVERAGE |
if (f == null) |
481 |
1
1. getHorizontalScaling : replaced return of float value with -(x + 1) for com/lowagie/text/Chunk::getHorizontalScaling → NO_COVERAGE |
return 1f; |
482 |
1
1. getHorizontalScaling : replaced return of float value with -(x + 1) for com/lowagie/text/Chunk::getHorizontalScaling → NO_COVERAGE |
return f; |
483 | } | |
484 | ||
485 | /** Key for underline. */ | |
486 | public static final String UNDERLINE = "UNDERLINE"; | |
487 | ||
488 | /** | |
489 | * Sets an horizontal line that can be an underline or a strikethrough. | |
490 | * Actually, the line can be anywhere vertically and has always the <CODE> | |
491 | * Chunk</CODE> width. Multiple call to this method will produce multiple | |
492 | * lines. | |
493 | * | |
494 | * @param thickness | |
495 | * the absolute thickness of the line | |
496 | * @param yPosition | |
497 | * the absolute y position relative to the baseline | |
498 | * @return this <CODE>Chunk</CODE> | |
499 | */ | |
500 | public Chunk setUnderline(float thickness, float yPosition) { | |
501 |
1
1. setUnderline : mutated return of Object value for com/lowagie/text/Chunk::setUnderline to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return setUnderline(null, thickness, 0f, yPosition, 0f, |
502 | PdfContentByte.LINE_CAP_BUTT); | |
503 | } | |
504 | ||
505 | /** | |
506 | * Sets an horizontal line that can be an underline or a strikethrough. | |
507 | * Actually, the line can be anywhere vertically and has always the <CODE> | |
508 | * Chunk</CODE> width. Multiple call to this method will produce multiple | |
509 | * lines. | |
510 | * | |
511 | * @param color | |
512 | * the color of the line or <CODE>null</CODE> to follow the | |
513 | * text color | |
514 | * @param thickness | |
515 | * the absolute thickness of the line | |
516 | * @param thicknessMul | |
517 | * the thickness multiplication factor with the font size | |
518 | * @param yPosition | |
519 | * the absolute y position relative to the baseline | |
520 | * @param yPositionMul | |
521 | * the position multiplication factor with the font size | |
522 | * @param cap | |
523 | * the end line cap. Allowed values are | |
524 | * PdfContentByte.LINE_CAP_BUTT, PdfContentByte.LINE_CAP_ROUND | |
525 | * and PdfContentByte.LINE_CAP_PROJECTING_SQUARE | |
526 | * @return this <CODE>Chunk</CODE> | |
527 | */ | |
528 | public Chunk setUnderline(Color color, float thickness, float thicknessMul, | |
529 | float yPosition, float yPositionMul, int cap) { | |
530 |
1
1. setUnderline : negated conditional → NO_COVERAGE |
if (attributes == null) |
531 | attributes = new HashMap<>(); | |
532 | Object[] obj = { | |
533 | color, | |
534 | new float[]{thickness, thicknessMul, yPosition, yPositionMul, cap}}; | |
535 | Object[][] unders = Utilities.addToArray((Object[][]) attributes.get(UNDERLINE), | |
536 | obj); | |
537 |
1
1. setUnderline : mutated return of Object value for com/lowagie/text/Chunk::setUnderline to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return setAttribute(UNDERLINE, unders); |
538 | } | |
539 | | |
540 | /** Key for sub/superscript. */ | |
541 | public static final String SUBSUPSCRIPT = "SUBSUPSCRIPT"; | |
542 | | |
543 | /** | |
544 | * Sets the text displacement relative to the baseline. Positive values rise | |
545 | * the text, negative values lower the text. | |
546 | * <P> | |
547 | * It can be used to implement sub/superscript. | |
548 | * | |
549 | * @param rise | |
550 | * the displacement in points | |
551 | * @return this <CODE>Chunk</CODE> | |
552 | */ | |
553 | ||
554 | public Chunk setTextRise(float rise) { | |
555 |
1
1. setTextRise : mutated return of Object value for com/lowagie/text/Chunk::setTextRise to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return setAttribute(SUBSUPSCRIPT, rise); |
556 | } | |
557 | ||
558 | /** | |
559 | * Gets the text displacement relative to the baseline. | |
560 | * | |
561 | * @return a displacement in points | |
562 | */ | |
563 | public float getTextRise() { | |
564 |
2
1. getTextRise : negated conditional → NO_COVERAGE 2. getTextRise : negated conditional → NO_COVERAGE |
if (attributes != null && attributes.containsKey(SUBSUPSCRIPT)) { |
565 |
1
1. getTextRise : replaced return of float value with -(x + 1) for com/lowagie/text/Chunk::getTextRise → NO_COVERAGE |
return (Float) attributes.get(SUBSUPSCRIPT); |
566 | } | |
567 |
1
1. getTextRise : replaced return of float value with -(x + 1) for com/lowagie/text/Chunk::getTextRise → NO_COVERAGE |
return 0.0f; |
568 | } | |
569 | ||
570 | /** Key for text skewing. */ | |
571 | public static final String SKEW = "SKEW"; | |
572 | ||
573 | /** | |
574 | * Skews the text to simulate italic and other effects. Try <CODE>alpha=0 | |
575 | * </CODE> and <CODE>beta=12</CODE>. | |
576 | * | |
577 | * @param alpha | |
578 | * the first angle in degrees | |
579 | * @param beta | |
580 | * the second angle in degrees | |
581 | * @return this <CODE>Chunk</CODE> | |
582 | */ | |
583 | public Chunk setSkew(float alpha, float beta) { | |
584 |
2
1. setSkew : Replaced double multiplication with division → NO_COVERAGE 2. setSkew : Replaced double division with multiplication → NO_COVERAGE |
alpha = (float) Math.tan(alpha * Math.PI / 180); |
585 |
2
1. setSkew : Replaced double multiplication with division → NO_COVERAGE 2. setSkew : Replaced double division with multiplication → NO_COVERAGE |
beta = (float) Math.tan(beta * Math.PI / 180); |
586 |
1
1. setSkew : mutated return of Object value for com/lowagie/text/Chunk::setSkew to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return setAttribute(SKEW, new float[] { alpha, beta }); |
587 | } | |
588 | ||
589 | /** Key for background. */ | |
590 | public static final String BACKGROUND = "BACKGROUND"; | |
591 | ||
592 | /** | |
593 | * Sets the color of the background <CODE>Chunk</CODE>. | |
594 | * | |
595 | * @param color | |
596 | * the color of the background | |
597 | * @return this <CODE>Chunk</CODE> | |
598 | */ | |
599 | public Chunk setBackground(Color color) { | |
600 |
1
1. setBackground : mutated return of Object value for com/lowagie/text/Chunk::setBackground to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return setBackground(color, 0, 0, 0, 0); |
601 | } | |
602 | ||
603 | /** | |
604 | * Sets the color and the size of the background <CODE>Chunk</CODE>. | |
605 | * | |
606 | * @param color | |
607 | * the color of the background | |
608 | * @param extraLeft | |
609 | * increase the size of the rectangle in the left | |
610 | * @param extraBottom | |
611 | * increase the size of the rectangle in the bottom | |
612 | * @param extraRight | |
613 | * increase the size of the rectangle in the right | |
614 | * @param extraTop | |
615 | * increase the size of the rectangle in the top | |
616 | * @return this <CODE>Chunk</CODE> | |
617 | */ | |
618 | public Chunk setBackground(Color color, float extraLeft, float extraBottom, | |
619 | float extraRight, float extraTop) { | |
620 |
1
1. setBackground : mutated return of Object value for com/lowagie/text/Chunk::setBackground to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return setAttribute(BACKGROUND, new Object[] { color, |
621 | new float[] { extraLeft, extraBottom, extraRight, extraTop } }); | |
622 | } | |
623 | ||
624 | /** Key for text rendering mode. */ | |
625 | public static final String TEXTRENDERMODE = "TEXTRENDERMODE"; | |
626 | ||
627 | /** | |
628 | * Sets the text rendering mode. It can outline text, simulate bold and make | |
629 | * text invisible. | |
630 | * | |
631 | * @param mode | |
632 | * the text rendering mode. It can be <CODE> | |
633 | * PdfContentByte.TEXT_RENDER_MODE_FILL</CODE>,<CODE> | |
634 | * PdfContentByte.TEXT_RENDER_MODE_STROKE</CODE>,<CODE> | |
635 | * PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE</CODE> and <CODE> | |
636 | * PdfContentByte.TEXT_RENDER_MODE_INVISIBLE</CODE>. | |
637 | * @param strokeWidth | |
638 | * the stroke line width for the modes <CODE> | |
639 | * PdfContentByte.TEXT_RENDER_MODE_STROKE</CODE> and <CODE> | |
640 | * PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE</CODE>. | |
641 | * @param strokeColor | |
642 | * the stroke color or <CODE>null</CODE> to follow the text | |
643 | * color | |
644 | * @return this <CODE>Chunk</CODE> | |
645 | */ | |
646 | public Chunk setTextRenderMode(int mode, float strokeWidth, | |
647 | Color strokeColor) { | |
648 |
1
1. setTextRenderMode : mutated return of Object value for com/lowagie/text/Chunk::setTextRenderMode to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return setAttribute(TEXTRENDERMODE, new Object[] {mode, |
649 | strokeWidth, strokeColor }); | |
650 | } | |
651 | ||
652 | /** Key for split character. */ | |
653 | public static final String SPLITCHARACTER = "SPLITCHARACTER"; | |
654 | ||
655 | /** | |
656 | * Sets the split characters. | |
657 | * | |
658 | * @param splitCharacter | |
659 | * the <CODE>SplitCharacter</CODE> interface | |
660 | * @return this <CODE>Chunk</CODE> | |
661 | */ | |
662 | ||
663 | public Chunk setSplitCharacter(SplitCharacter splitCharacter) { | |
664 |
1
1. setSplitCharacter : mutated return of Object value for com/lowagie/text/Chunk::setSplitCharacter to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return setAttribute(SPLITCHARACTER, splitCharacter); |
665 | } | |
666 | ||
667 | /** Key for hyphenation. */ | |
668 | public static final String HYPHENATION = "HYPHENATION"; | |
669 | | |
670 | /** | |
671 | * sets the hyphenation engine to this <CODE>Chunk</CODE>. | |
672 | * | |
673 | * @param hyphenation | |
674 | * the hyphenation engine | |
675 | * @return this <CODE>Chunk</CODE> | |
676 | */ | |
677 | public Chunk setHyphenation(HyphenationEvent hyphenation) { | |
678 |
1
1. setHyphenation : mutated return of Object value for com/lowagie/text/Chunk::setHyphenation to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return setAttribute(HYPHENATION, hyphenation); |
679 | } | |
680 | ||
681 | /** Key for remote goto. */ | |
682 | public static final String REMOTEGOTO = "REMOTEGOTO"; | |
683 | ||
684 | /** | |
685 | * Sets a goto for a remote destination for this <CODE>Chunk</CODE>. | |
686 | * | |
687 | * @param filename | |
688 | * the file name of the destination document | |
689 | * @param name | |
690 | * the name of the destination to go to | |
691 | * @return this <CODE>Chunk</CODE> | |
692 | */ | |
693 | ||
694 | public Chunk setRemoteGoto(String filename, String name) { | |
695 |
1
1. setRemoteGoto : mutated return of Object value for com/lowagie/text/Chunk::setRemoteGoto to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return setAttribute(REMOTEGOTO, new Object[] { filename, name }); |
696 | } | |
697 | ||
698 | /** | |
699 | * Sets a goto for a remote destination for this <CODE>Chunk</CODE>. | |
700 | * | |
701 | * @param filename | |
702 | * the file name of the destination document | |
703 | * @param page | |
704 | * the page of the destination to go to. First page is 1 | |
705 | * @return this <CODE>Chunk</CODE> | |
706 | */ | |
707 | ||
708 | public Chunk setRemoteGoto(String filename, int page) { | |
709 |
1
1. setRemoteGoto : mutated return of Object value for com/lowagie/text/Chunk::setRemoteGoto to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return setAttribute(REMOTEGOTO, new Object[] { filename, |
710 | page}); | |
711 | } | |
712 | ||
713 | /** Key for local goto. */ | |
714 | public static final String LOCALGOTO = "LOCALGOTO"; | |
715 | | |
716 | /** | |
717 | * Sets a local goto for this <CODE>Chunk</CODE>. | |
718 | * <P> | |
719 | * There must be a local destination matching the name. | |
720 | * | |
721 | * @param name | |
722 | * the name of the destination to go to | |
723 | * @return this <CODE>Chunk</CODE> | |
724 | */ | |
725 | ||
726 | public Chunk setLocalGoto(String name) { | |
727 |
1
1. setLocalGoto : mutated return of Object value for com/lowagie/text/Chunk::setLocalGoto to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return setAttribute(LOCALGOTO, name); |
728 | } | |
729 | ||
730 | /** Key for local destination. */ | |
731 | public static final String LOCALDESTINATION = "LOCALDESTINATION"; | |
732 | ||
733 | /** | |
734 | * Sets a local destination for this <CODE>Chunk</CODE>. | |
735 | * | |
736 | * @param name | |
737 | * the name for this destination | |
738 | * @return this <CODE>Chunk</CODE> | |
739 | */ | |
740 | public Chunk setLocalDestination(String name) { | |
741 |
1
1. setLocalDestination : mutated return of Object value for com/lowagie/text/Chunk::setLocalDestination to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return setAttribute(LOCALDESTINATION, name); |
742 | } | |
743 | ||
744 | /** Key for generic tag. */ | |
745 | public static final String GENERICTAG = "GENERICTAG"; | |
746 | ||
747 | /** | |
748 | * Sets the generic tag <CODE>Chunk</CODE>. | |
749 | * <P> | |
750 | * The text for this tag can be retrieved with <CODE>PdfPageEvent</CODE>. | |
751 | * | |
752 | * @param text | |
753 | * the text for the tag | |
754 | * @return this <CODE>Chunk</CODE> | |
755 | */ | |
756 | ||
757 | public Chunk setGenericTag(String text) { | |
758 |
1
1. setGenericTag : mutated return of Object value for com/lowagie/text/Chunk::setGenericTag to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return setAttribute(GENERICTAG, text); |
759 | } | |
760 | | |
761 | /** Key for image. */ | |
762 | public static final String IMAGE = "IMAGE"; | |
763 | ||
764 | /** | |
765 | * Returns the image. | |
766 | * | |
767 | * @return the image | |
768 | */ | |
769 | ||
770 | public Image getImage() { | |
771 |
1
1. getImage : negated conditional → NO_COVERAGE |
if (attributes == null) |
772 |
1
1. getImage : mutated return of Object value for com/lowagie/text/Chunk::getImage to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return null; |
773 | Object[] obj = (Object[]) attributes.get(Chunk.IMAGE); | |
774 |
1
1. getImage : negated conditional → NO_COVERAGE |
if (obj == null) |
775 |
1
1. getImage : mutated return of Object value for com/lowagie/text/Chunk::getImage to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return null; |
776 | else { | |
777 |
1
1. getImage : mutated return of Object value for com/lowagie/text/Chunk::getImage to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return (Image) obj[0]; |
778 | } | |
779 | } | |
780 | | |
781 | /** Key for Action. */ | |
782 | public static final String ACTION = "ACTION"; | |
783 | ||
784 | /** | |
785 | * Sets an action for this <CODE>Chunk</CODE>. | |
786 | * | |
787 | * @param action | |
788 | * the action | |
789 | * @return this <CODE>Chunk</CODE> | |
790 | */ | |
791 | ||
792 | public Chunk setAction(PdfAction action) { | |
793 |
1
1. setAction : mutated return of Object value for com/lowagie/text/Chunk::setAction to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return setAttribute(ACTION, action); |
794 | } | |
795 | ||
796 | /** | |
797 | * Sets an anchor for this <CODE>Chunk</CODE>. | |
798 | * | |
799 | * @param url | |
800 | * the <CODE>URL</CODE> to link to | |
801 | * @return this <CODE>Chunk</CODE> | |
802 | */ | |
803 | ||
804 | public Chunk setAnchor(URL url) { | |
805 |
1
1. setAnchor : mutated return of Object value for com/lowagie/text/Chunk::setAnchor to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return setAttribute(ACTION, new PdfAction(url.toExternalForm())); |
806 | } | |
807 | ||
808 | /** | |
809 | * Sets an anchor for this <CODE>Chunk</CODE>. | |
810 | * | |
811 | * @param url | |
812 | * the url to link to | |
813 | * @return this <CODE>Chunk</CODE> | |
814 | */ | |
815 | ||
816 | public Chunk setAnchor(String url) { | |
817 |
1
1. setAnchor : mutated return of Object value for com/lowagie/text/Chunk::setAnchor to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return setAttribute(ACTION, new PdfAction(url)); |
818 | } | |
819 | | |
820 | /** Key for newpage. */ | |
821 | public static final String NEWPAGE = "NEWPAGE"; | |
822 | ||
823 | /** | |
824 | * Sets a new page tag.. | |
825 | * | |
826 | * @return this <CODE>Chunk</CODE> | |
827 | */ | |
828 | ||
829 | public Chunk setNewPage() { | |
830 |
1
1. setNewPage : mutated return of Object value for com/lowagie/text/Chunk::setNewPage to ( if (x != null) null else throw new RuntimeException ) → SURVIVED |
return setAttribute(NEWPAGE, null); |
831 | } | |
832 | ||
833 | /** Key for annotation. */ | |
834 | public static final String PDFANNOTATION = "PDFANNOTATION"; | |
835 | ||
836 | /** | |
837 | * Sets a generic annotation to this <CODE>Chunk</CODE>. | |
838 | * | |
839 | * @param annotation | |
840 | * the annotation | |
841 | * @return this <CODE>Chunk</CODE> | |
842 | */ | |
843 | public Chunk setAnnotation(PdfAnnotation annotation) { | |
844 |
1
1. setAnnotation : mutated return of Object value for com/lowagie/text/Chunk::setAnnotation to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return setAttribute(PDFANNOTATION, annotation); |
845 | } | |
846 | | |
847 | /** | |
848 | * @see com.lowagie.text.Element#isContent() | |
849 | * @since iText 2.0.8 | |
850 | */ | |
851 | public boolean isContent() { | |
852 | return true; | |
853 | } | |
854 | ||
855 | /** | |
856 | * @see com.lowagie.text.Element#isNestable() | |
857 | * @since iText 2.0.8 | |
858 | */ | |
859 | public boolean isNestable() { | |
860 | return true; | |
861 | } | |
862 | ||
863 | /** | |
864 | * Returns the hyphenation (if present). | |
865 | * @since 2.1.2 | |
866 | */ | |
867 | public HyphenationEvent getHyphenation() { | |
868 |
2
1. getHyphenation : negated conditional → NO_COVERAGE 2. getHyphenation : mutated return of Object value for com/lowagie/text/Chunk::getHyphenation to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
if (attributes == null) return null; |
869 |
1
1. getHyphenation : mutated return of Object value for com/lowagie/text/Chunk::getHyphenation to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return (HyphenationEvent) attributes.get(Chunk.HYPHENATION); |
870 | } | |
871 | | |
872 | // keys used in PdfChunk | |
873 | | |
874 | /** Key for color. */ | |
875 | public static final String COLOR = "COLOR"; | |
876 | ||
877 | /** Key for encoding. */ | |
878 | public static final String ENCODING = "ENCODING"; | |
879 | ||
880 | /** | |
881 | * Key for character spacing. | |
882 | */ | |
883 | public static final String CHAR_SPACING = "CHAR_SPACING"; | |
884 | ||
885 | /** | |
886 | * Sets the character spacing. | |
887 | * | |
888 | * @param charSpace the character spacing value | |
889 | * @return this <CODE>Chunk</CODE> | |
890 | */ | |
891 | public Chunk setCharacterSpacing(float charSpace) { | |
892 |
1
1. setCharacterSpacing : mutated return of Object value for com/lowagie/text/Chunk::setCharacterSpacing to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return setAttribute(CHAR_SPACING, charSpace); |
893 | } | |
894 | | |
895 | /** | |
896 | * Gets the character spacing. | |
897 | * | |
898 | * @return a value in float | |
899 | */ | |
900 | public float getCharacterSpacing() { | |
901 |
2
1. getCharacterSpacing : negated conditional → NO_COVERAGE 2. getCharacterSpacing : negated conditional → NO_COVERAGE |
if (attributes != null && attributes.containsKey(CHAR_SPACING)) { |
902 |
1
1. getCharacterSpacing : replaced return of float value with -(x + 1) for com/lowagie/text/Chunk::getCharacterSpacing → NO_COVERAGE |
return (Float) attributes.get(CHAR_SPACING); |
903 | } | |
904 |
1
1. getCharacterSpacing : replaced return of float value with -(x + 1) for com/lowagie/text/Chunk::getCharacterSpacing → NO_COVERAGE |
return 0.0f; |
905 | } | |
906 | } | |
Mutations | ||
130 |
1.1 |
|
133 |
1.1 |
|
136 |
1.1 |
|
204 |
1.1 |
|
264 |
1.1 2.2 |
|
301 |
1.1 |
|
303 |
1.1 |
|
324 |
1.1 |
|
386 |
1.1 2.2 |
|
387 |
1.1 2.2 |
|
397 |
1.1 |
|
398 |
1.1 |
|
400 |
1.1 |
|
402 |
1.1 |
|
414 |
1.1 2.2 |
|
448 |
1.1 |
|
451 |
1.1 |
|
468 |
1.1 |
|
477 |
1.1 |
|
478 |
1.1 |
|
480 |
1.1 |
|
481 |
1.1 |
|
482 |
1.1 |
|
501 |
1.1 |
|
530 |
1.1 |
|
537 |
1.1 |
|
555 |
1.1 |
|
564 |
1.1 2.2 |
|
565 |
1.1 |
|
567 |
1.1 |
|
584 |
1.1 2.2 |
|
585 |
1.1 2.2 |
|
586 |
1.1 |
|
600 |
1.1 |
|
620 |
1.1 |
|
648 |
1.1 |
|
664 |
1.1 |
|
678 |
1.1 |
|
695 |
1.1 |
|
709 |
1.1 |
|
727 |
1.1 |
|
741 |
1.1 |
|
758 |
1.1 |
|
771 |
1.1 |
|
772 |
1.1 |
|
774 |
1.1 |
|
775 |
1.1 |
|
777 |
1.1 |
|
793 |
1.1 |
|
805 |
1.1 |
|
817 |
1.1 |
|
830 |
1.1 |
|
844 |
1.1 |
|
868 |
1.1 2.2 |
|
869 |
1.1 |
|
892 |
1.1 |
|
901 |
1.1 2.2 |
|
902 |
1.1 |
|
904 |
1.1 |