1 | /* | |
2 | * $Id: PdfLine.java 3994 2009-06-24 13:08:04Z blowagie $ | |
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.util.ArrayList; | |
53 | import java.util.Iterator; | |
54 | ||
55 | import com.lowagie.text.Chunk; | |
56 | import com.lowagie.text.Element; | |
57 | import com.lowagie.text.ListItem; | |
58 | ||
59 | /** | |
60 | * <CODE>PdfLine</CODE> defines an array with <CODE>PdfChunk</CODE>-objects | |
61 | * that fit into 1 line. | |
62 | */ | |
63 | ||
64 | public class PdfLine { | |
65 | | |
66 | // membervariables | |
67 | | |
68 | /** The arraylist containing the chunks. */ | |
69 | protected ArrayList line; | |
70 | | |
71 | /** The left indentation of the line. */ | |
72 | protected float left; | |
73 | | |
74 | /** The width of the line. */ | |
75 | protected float width; | |
76 | | |
77 | /** The alignment of the line. */ | |
78 | protected int alignment; | |
79 | | |
80 | /** The height of the line. */ | |
81 | protected float height; | |
82 | | |
83 | /** The listsymbol (if necessary). */ | |
84 | protected Chunk listSymbol = null; | |
85 | | |
86 | /** The listsymbol (if necessary). */ | |
87 | protected float symbolIndent; | |
88 | | |
89 | /** <CODE>true</CODE> if the chunk splitting was caused by a newline. */ | |
90 | protected boolean newlineSplit = false; | |
91 | | |
92 | /** The original width. */ | |
93 | protected float originalWidth; | |
94 | | |
95 | protected boolean isRTL = false; | |
96 | | |
97 | // constructors | |
98 | | |
99 | /** | |
100 | * Constructs a new <CODE>PdfLine</CODE>-object. | |
101 | * | |
102 | * @param left the limit of the line at the left | |
103 | * @param right the limit of the line at the right | |
104 | * @param alignment the alignment of the line | |
105 | * @param height the height of the line | |
106 | */ | |
107 | | |
108 | PdfLine(float left, float right, int alignment, float height) { | |
109 | this.left = left; | |
110 |
1
1. |
this.width = right - left; |
111 | this.originalWidth = this.width; | |
112 | this.alignment = alignment; | |
113 | this.height = height; | |
114 | this.line = new ArrayList(); | |
115 | } | |
116 | | |
117 | /** | |
118 | * Creates a PdfLine object. | |
119 | * @param left the left offset | |
120 | * @param originalWidth the original width of the line | |
121 | * @param remainingWidth bigger than 0 if the line isn't completely filled | |
122 | * @param alignment the alignment of the line | |
123 | * @param newlineSplit was the line splitted (or does the paragraph end with this line) | |
124 | * @param line an array of PdfChunk objects | |
125 | * @param isRTL do you have to read the line from Right to Left? | |
126 | */ | |
127 | PdfLine(float left, float originalWidth, float remainingWidth, int alignment, boolean newlineSplit, ArrayList line, boolean isRTL) { | |
128 | this.left = left; | |
129 | this.originalWidth = originalWidth; | |
130 | this.width = remainingWidth; | |
131 | this.alignment = alignment; | |
132 | this.line = line; | |
133 | this.newlineSplit = newlineSplit; | |
134 | this.isRTL = isRTL; | |
135 | } | |
136 | | |
137 | // methods | |
138 | | |
139 | /** | |
140 | * Adds a <CODE>PdfChunk</CODE> to the <CODE>PdfLine</CODE>. | |
141 | * | |
142 | * @param chunk the <CODE>PdfChunk</CODE> to add | |
143 | * @return <CODE>null</CODE> if the chunk could be added completely; if not | |
144 | * a <CODE>PdfChunk</CODE> containing the part of the chunk that could | |
145 | * not be added is returned | |
146 | */ | |
147 | | |
148 | PdfChunk add(PdfChunk chunk) { | |
149 | // nothing happens if the chunk is null. | |
150 |
2
1. add : negated conditional → NO_COVERAGE 2. add : negated conditional → NO_COVERAGE |
if (chunk == null || chunk.toString().equals("")) { |
151 |
1
1. add : mutated return of Object value for com/lowagie/text/pdf/PdfLine::add to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return null; |
152 | } | |
153 | | |
154 | // we split the chunk to be added | |
155 | PdfChunk overflow = chunk.split(width); | |
156 |
2
1. add : negated conditional → NO_COVERAGE 2. add : negated conditional → NO_COVERAGE |
newlineSplit = (chunk.isNewlineSplit() || overflow == null); |
157 | // if (chunk.isNewlineSplit() && alignment == Element.ALIGN_JUSTIFIED) | |
158 | // alignment = Element.ALIGN_LEFT; | |
159 |
1
1. add : negated conditional → NO_COVERAGE |
if (chunk.isTab()) { |
160 | Object[] tab = (Object[])chunk.getAttribute(Chunk.TAB); | |
161 | float tabPosition = (Float) tab[1]; | |
162 | boolean newline = (Boolean) tab[2]; | |
163 |
4
1. add : changed conditional boundary → NO_COVERAGE 2. add : Replaced float subtraction with addition → NO_COVERAGE 3. add : negated conditional → NO_COVERAGE 4. add : negated conditional → NO_COVERAGE |
if (newline && tabPosition < originalWidth - width) { |
164 |
1
1. add : mutated return of Object value for com/lowagie/text/pdf/PdfLine::add to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return chunk; |
165 | } | |
166 |
1
1. add : Replaced float subtraction with addition → NO_COVERAGE |
width = originalWidth - tabPosition; |
167 |
1
1. add : removed call to com/lowagie/text/pdf/PdfChunk::adjustLeft → NO_COVERAGE |
chunk.adjustLeft(left); |
168 |
1
1. add : removed call to com/lowagie/text/pdf/PdfLine::addToLine → NO_COVERAGE |
addToLine(chunk); |
169 | } | |
170 | // if the length of the chunk > 0 we add it to the line | |
171 |
3
1. add : changed conditional boundary → NO_COVERAGE 2. add : negated conditional → NO_COVERAGE 3. add : negated conditional → NO_COVERAGE |
else if (chunk.length() > 0 || chunk.isImage()) { |
172 |
1
1. add : negated conditional → NO_COVERAGE |
if (overflow != null) |
173 | chunk.trimLastSpace(); | |
174 |
1
1. add : Replaced float subtraction with addition → NO_COVERAGE |
width -= chunk.width(); |
175 |
1
1. add : removed call to com/lowagie/text/pdf/PdfLine::addToLine → NO_COVERAGE |
addToLine(chunk); |
176 | } | |
177 | // if the length == 0 and there were no other chunks added to the line yet, | |
178 | // we risk to end up in an endless loop trying endlessly to add the same chunk | |
179 |
2
1. add : changed conditional boundary → NO_COVERAGE 2. add : negated conditional → NO_COVERAGE |
else if (line.size() < 1) { |
180 | chunk = overflow; | |
181 | overflow = chunk.truncate(width); | |
182 |
1
1. add : Replaced float subtraction with addition → NO_COVERAGE |
width -= chunk.width(); |
183 |
2
1. add : changed conditional boundary → NO_COVERAGE 2. add : negated conditional → NO_COVERAGE |
if (chunk.length() > 0) { |
184 |
1
1. add : removed call to com/lowagie/text/pdf/PdfLine::addToLine → NO_COVERAGE |
addToLine(chunk); |
185 |
1
1. add : mutated return of Object value for com/lowagie/text/pdf/PdfLine::add to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return overflow; |
186 | } | |
187 | // if the chunk couldn't even be truncated, we add everything, so be it | |
188 | else { | |
189 |
1
1. add : negated conditional → NO_COVERAGE |
if (overflow != null) |
190 |
1
1. add : removed call to com/lowagie/text/pdf/PdfLine::addToLine → NO_COVERAGE |
addToLine(overflow); |
191 |
1
1. add : mutated return of Object value for com/lowagie/text/pdf/PdfLine::add to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return null; |
192 | } | |
193 | } | |
194 | else { | |
195 |
2
1. add : Replaced integer subtraction with addition → NO_COVERAGE 2. add : Replaced float addition with subtraction → NO_COVERAGE |
width += ((PdfChunk)(line.get(line.size() - 1))).trimLastSpace(); |
196 | } | |
197 |
1
1. add : mutated return of Object value for com/lowagie/text/pdf/PdfLine::add to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return overflow; |
198 | } | |
199 | | |
200 | private void addToLine(PdfChunk chunk) { | |
201 |
2
1. addToLine : negated conditional → NO_COVERAGE 2. addToLine : negated conditional → NO_COVERAGE |
if (chunk.changeLeading && chunk.isImage()) { |
202 |
2
1. addToLine : Replaced float addition with subtraction → NO_COVERAGE 2. addToLine : Replaced float addition with subtraction → NO_COVERAGE |
float f = chunk.getImage().getScaledHeight() + chunk.getImageOffsetY() + chunk.getImage().getBorderWidthTop(); |
203 |
2
1. addToLine : changed conditional boundary → NO_COVERAGE 2. addToLine : negated conditional → NO_COVERAGE |
if (f > height) height = f; |
204 | } | |
205 | line.add(chunk); | |
206 | } | |
207 | | |
208 | // methods to retrieve information | |
209 | | |
210 | /** | |
211 | * Returns the number of chunks in the line. | |
212 | * | |
213 | * @return a value | |
214 | */ | |
215 | | |
216 | public int size() { | |
217 | return line.size(); | |
218 | } | |
219 | | |
220 | /** | |
221 | * Returns an iterator of <CODE>PdfChunk</CODE>s. | |
222 | * | |
223 | * @return an <CODE>Iterator</CODE> | |
224 | */ | |
225 | | |
226 | public Iterator iterator() { | |
227 | return line.iterator(); | |
228 | } | |
229 | | |
230 | /** | |
231 | * Returns the height of the line. | |
232 | * | |
233 | * @return a value | |
234 | */ | |
235 | | |
236 | float height() { | |
237 | return height; | |
238 | } | |
239 | | |
240 | /** | |
241 | * Returns the left indentation of the line taking the alignment of the line into account. | |
242 | * | |
243 | * @return a value | |
244 | */ | |
245 | | |
246 | float indentLeft() { | |
247 |
1
1. indentLeft : negated conditional → NO_COVERAGE |
if (isRTL) { |
248 | switch (alignment) { | |
249 | case Element.ALIGN_LEFT: | |
250 |
2
1. indentLeft : Replaced float addition with subtraction → NO_COVERAGE 2. indentLeft : replaced return of float value with -(x + 1) for com/lowagie/text/pdf/PdfLine::indentLeft → NO_COVERAGE |
return left + width; |
251 | case Element.ALIGN_CENTER: | |
252 |
3
1. indentLeft : Replaced float division with multiplication → NO_COVERAGE 2. indentLeft : Replaced float addition with subtraction → NO_COVERAGE 3. indentLeft : replaced return of float value with -(x + 1) for com/lowagie/text/pdf/PdfLine::indentLeft → NO_COVERAGE |
return left + (width / 2f); |
253 | default: | |
254 |
1
1. indentLeft : replaced return of float value with -(x + 1) for com/lowagie/text/pdf/PdfLine::indentLeft → NO_COVERAGE |
return left; |
255 | } | |
256 | } | |
257 |
1
1. indentLeft : negated conditional → NO_COVERAGE |
else if (this.getSeparatorCount() == 0) { |
258 | switch (alignment) { | |
259 | case Element.ALIGN_RIGHT: | |
260 |
2
1. indentLeft : Replaced float addition with subtraction → NO_COVERAGE 2. indentLeft : replaced return of float value with -(x + 1) for com/lowagie/text/pdf/PdfLine::indentLeft → NO_COVERAGE |
return left + width; |
261 | case Element.ALIGN_CENTER: | |
262 |
3
1. indentLeft : Replaced float division with multiplication → NO_COVERAGE 2. indentLeft : Replaced float addition with subtraction → NO_COVERAGE 3. indentLeft : replaced return of float value with -(x + 1) for com/lowagie/text/pdf/PdfLine::indentLeft → NO_COVERAGE |
return left + (width / 2f); |
263 | } | |
264 | } | |
265 |
1
1. indentLeft : replaced return of float value with -(x + 1) for com/lowagie/text/pdf/PdfLine::indentLeft → NO_COVERAGE |
return left; |
266 | } | |
267 | | |
268 | /** | |
269 | * Checks if this line has to be justified. | |
270 | * | |
271 | * @return <CODE>true</CODE> if the alignment equals <VAR>ALIGN_JUSTIFIED</VAR> and there is some width left. | |
272 | */ | |
273 | | |
274 | public boolean hasToBeJustified() { | |
275 |
4
1. hasToBeJustified : negated conditional → NO_COVERAGE 2. hasToBeJustified : negated conditional → NO_COVERAGE 3. hasToBeJustified : negated conditional → NO_COVERAGE 4. hasToBeJustified : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return ((alignment == Element.ALIGN_JUSTIFIED || alignment == Element.ALIGN_JUSTIFIED_ALL) && width != 0); |
276 | } | |
277 | | |
278 | /** | |
279 | * Resets the alignment of this line. | |
280 | * <P> | |
281 | * The alignment of the last line of for instance a <CODE>Paragraph</CODE> | |
282 | * that has to be justified, has to be reset to <VAR>ALIGN_LEFT</VAR>. | |
283 | */ | |
284 | | |
285 | public void resetAlignment() { | |
286 |
1
1. resetAlignment : negated conditional → NO_COVERAGE |
if (alignment == Element.ALIGN_JUSTIFIED) { |
287 | alignment = Element.ALIGN_LEFT; | |
288 | } | |
289 | } | |
290 | | |
291 | /** Adds extra indentation to the left (for Paragraph.setFirstLineIndent). */ | |
292 | void setExtraIndent(float extra) { | |
293 |
1
1. setExtraIndent : Replaced float addition with subtraction → NO_COVERAGE |
left += extra; |
294 |
1
1. setExtraIndent : Replaced float subtraction with addition → NO_COVERAGE |
width -= extra; |
295 | } | |
296 | | |
297 | /** | |
298 | * Returns the width that is left, after a maximum of characters is added to the line. | |
299 | * | |
300 | * @return a value | |
301 | */ | |
302 | | |
303 | float widthLeft() { | |
304 | return width; | |
305 | } | |
306 | | |
307 | /** | |
308 | * Returns the number of space-characters in this line. | |
309 | * | |
310 | * @return a value | |
311 | */ | |
312 | | |
313 | int numberOfSpaces() { | |
314 | String string = toString(); | |
315 | int length = string.length(); | |
316 | int numberOfSpaces = 0; | |
317 |
3
1. numberOfSpaces : changed conditional boundary → NO_COVERAGE 2. numberOfSpaces : Changed increment from 1 to -1 → NO_COVERAGE 3. numberOfSpaces : negated conditional → NO_COVERAGE |
for (int i = 0; i < length; i++) { |
318 |
1
1. numberOfSpaces : negated conditional → NO_COVERAGE |
if (string.charAt(i) == ' ') { |
319 |
1
1. numberOfSpaces : Changed increment from 1 to -1 → NO_COVERAGE |
numberOfSpaces++; |
320 | } | |
321 | } | |
322 |
1
1. numberOfSpaces : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return numberOfSpaces; |
323 | } | |
324 | | |
325 | /** | |
326 | * Sets the listsymbol of this line. | |
327 | * <P> | |
328 | * This is only necessary for the first line of a <CODE>ListItem</CODE>. | |
329 | * | |
330 | * @param listItem the list symbol | |
331 | */ | |
332 | | |
333 | public void setListItem(ListItem listItem) { | |
334 | this.listSymbol = listItem.getListSymbol(); | |
335 | this.symbolIndent = listItem.getIndentationLeft(); | |
336 | } | |
337 | | |
338 | /** | |
339 | * Returns the listsymbol of this line. | |
340 | * | |
341 | * @return a <CODE>PdfChunk</CODE> if the line has a listsymbol; <CODE>null</CODE> otherwise | |
342 | */ | |
343 | | |
344 | public Chunk listSymbol() { | |
345 | return listSymbol; | |
346 | } | |
347 | | |
348 | /** | |
349 | * Return the indentation needed to show the listsymbol. | |
350 | * | |
351 | * @return a value | |
352 | */ | |
353 | | |
354 | public float listIndent() { | |
355 | return symbolIndent; | |
356 | } | |
357 | | |
358 | /** | |
359 | * Get the string representation of what is in this line. | |
360 | * | |
361 | * @return a <CODE>String</CODE> | |
362 | */ | |
363 | | |
364 | public String toString() { | |
365 | StringBuilder tmp = new StringBuilder(); | |
366 | for (Object o : line) { | |
367 | tmp.append(o.toString()); | |
368 | } | |
369 | return tmp.toString(); | |
370 | } | |
371 | | |
372 | /** | |
373 | * Returns the length of a line in UTF32 characters | |
374 | * @return the length in UTF32 characters | |
375 | * @since 2.1.2 | |
376 | */ | |
377 | public int GetLineLengthUtf32() { | |
378 | int total = 0; | |
379 | for (Object o : line) { | |
380 |
1
1. GetLineLengthUtf32 : Replaced integer addition with subtraction → NO_COVERAGE |
total += ((PdfChunk) o).lengthUtf32(); |
381 | } | |
382 |
1
1. GetLineLengthUtf32 : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return total; |
383 | } | |
384 | | |
385 | /** | |
386 | * Checks if a newline caused the line split. | |
387 | * @return <CODE>true</CODE> if a newline caused the line split | |
388 | */ | |
389 | public boolean isNewlineSplit() { | |
390 |
3
1. isNewlineSplit : negated conditional → NO_COVERAGE 2. isNewlineSplit : negated conditional → NO_COVERAGE 3. isNewlineSplit : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return newlineSplit && (alignment != Element.ALIGN_JUSTIFIED_ALL); |
391 | } | |
392 | | |
393 | /** | |
394 | * Gets the index of the last <CODE>PdfChunk</CODE> with metric attributes | |
395 | * @return the last <CODE>PdfChunk</CODE> with metric attributes | |
396 | */ | |
397 | public int getLastStrokeChunk() { | |
398 |
1
1. getLastStrokeChunk : Replaced integer subtraction with addition → NO_COVERAGE |
int lastIdx = line.size() - 1; |
399 |
3
1. getLastStrokeChunk : changed conditional boundary → NO_COVERAGE 2. getLastStrokeChunk : Changed increment from -1 to 1 → NO_COVERAGE 3. getLastStrokeChunk : negated conditional → NO_COVERAGE |
for (; lastIdx >= 0; --lastIdx) { |
400 | PdfChunk chunk = (PdfChunk)line.get(lastIdx); | |
401 |
1
1. getLastStrokeChunk : negated conditional → NO_COVERAGE |
if (chunk.isStroked()) |
402 | break; | |
403 | } | |
404 |
1
1. getLastStrokeChunk : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return lastIdx; |
405 | } | |
406 | | |
407 | /** | |
408 | * Gets a <CODE>PdfChunk</CODE> by index. | |
409 | * @param idx the index | |
410 | * @return the <CODE>PdfChunk</CODE> or null if beyond the array | |
411 | */ | |
412 | public PdfChunk getChunk(int idx) { | |
413 |
4
1. getChunk : changed conditional boundary → NO_COVERAGE 2. getChunk : changed conditional boundary → NO_COVERAGE 3. getChunk : negated conditional → NO_COVERAGE 4. getChunk : negated conditional → NO_COVERAGE |
if (idx < 0 || idx >= line.size()) |
414 |
1
1. getChunk : mutated return of Object value for com/lowagie/text/pdf/PdfLine::getChunk to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return null; |
415 |
1
1. getChunk : mutated return of Object value for com/lowagie/text/pdf/PdfLine::getChunk to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return (PdfChunk)line.get(idx); |
416 | } | |
417 | | |
418 | /** | |
419 | * Gets the original width of the line. | |
420 | * @return the original width of the line | |
421 | */ | |
422 | public float getOriginalWidth() { | |
423 | return originalWidth; | |
424 | } | |
425 | | |
426 | /* | |
427 | * Gets the maximum size of all the fonts used in this line | |
428 | * including images. | |
429 | * @return maximum size of all the fonts used in this line | |
430 | float getMaxSizeSimple() { | |
431 | float maxSize = 0; | |
432 | PdfChunk chunk; | |
433 | for (int k = 0; k < line.size(); ++k) { | |
434 | chunk = (PdfChunk)line.get(k); | |
435 | if (!chunk.isImage()) { | |
436 | maxSize = Math.max(chunk.font().size(), maxSize); | |
437 | } | |
438 | else { | |
439 | maxSize = Math.max(chunk.getImage().getScaledHeight() + chunk.getImageOffsetY() , maxSize); | |
440 | } | |
441 | } | |
442 | return maxSize; | |
443 | }*/ | |
444 | | |
445 | /** | |
446 | * Gets the difference between the "normal" leading and the maximum | |
447 | * size (for instance when there are images in the chunk). | |
448 | * @return an extra leading for images | |
449 | * @since 2.1.5 | |
450 | */ | |
451 | float[] getMaxSize() { | |
452 | float normal_leading = 0; | |
453 | float image_leading = -10000; | |
454 | PdfChunk chunk; | |
455 | for (Object o : line) { | |
456 | chunk = (PdfChunk) o; | |
457 |
1
1. getMaxSize : negated conditional → NO_COVERAGE |
if (!chunk.isImage()) { |
458 | normal_leading = Math.max(chunk.font().size(), normal_leading); | |
459 | } else { | |
460 |
1
1. getMaxSize : Replaced float addition with subtraction → NO_COVERAGE |
image_leading = Math.max(chunk.getImage().getScaledHeight() + chunk.getImageOffsetY(), image_leading); |
461 | } | |
462 | } | |
463 |
1
1. getMaxSize : mutated return of Object value for com/lowagie/text/pdf/PdfLine::getMaxSize to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return new float[]{normal_leading, image_leading}; |
464 | } | |
465 | | |
466 | boolean isRTL() { | |
467 | return isRTL; | |
468 | } | |
469 | | |
470 | /** | |
471 | * Gets the number of separators in the line. | |
472 | * @return the number of separators in the line | |
473 | * @since 2.1.2 | |
474 | */ | |
475 | int getSeparatorCount() { | |
476 | int s = 0; | |
477 | PdfChunk ck; | |
478 | for (Object o : line) { | |
479 | ck = (PdfChunk) o; | |
480 |
1
1. getSeparatorCount : negated conditional → NO_COVERAGE |
if (ck.isTab()) { |
481 |
1
1. getSeparatorCount : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return 0; |
482 | } | |
483 |
1
1. getSeparatorCount : negated conditional → NO_COVERAGE |
if (ck.isHorizontalSeparator()) { |
484 |
1
1. getSeparatorCount : Changed increment from 1 to -1 → NO_COVERAGE |
s++; |
485 | } | |
486 | } | |
487 |
1
1. getSeparatorCount : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return s; |
488 | } | |
489 | | |
490 | /** | |
491 | * Gets a width corrected with a charSpacing and wordSpacing. | |
492 | * @param charSpacing | |
493 | * @param wordSpacing | |
494 | * @return a corrected width | |
495 | */ | |
496 | public float getWidthCorrected(float charSpacing, float wordSpacing) { | |
497 | float total = 0; | |
498 | for (Object o : line) { | |
499 | PdfChunk ck = (PdfChunk) o; | |
500 |
1
1. getWidthCorrected : Replaced float addition with subtraction → NO_COVERAGE |
total += ck.getWidthCorrected(charSpacing, wordSpacing); |
501 | } | |
502 |
1
1. getWidthCorrected : replaced return of float value with -(x + 1) for com/lowagie/text/pdf/PdfLine::getWidthCorrected → NO_COVERAGE |
return total; |
503 | } | |
504 | | |
505 | /** | |
506 | * Gets the maximum size of the ascender for all the fonts used | |
507 | * in this line. | |
508 | * @return maximum size of all the ascenders used in this line | |
509 | */ | |
510 | public float getAscender() { | |
511 | float ascender = 0; | |
512 | for (Object o : line) { | |
513 | PdfChunk ck = (PdfChunk) o; | |
514 |
1
1. getAscender : negated conditional → NO_COVERAGE |
if (ck.isImage()) |
515 |
1
1. getAscender : Replaced float addition with subtraction → NO_COVERAGE |
ascender = Math.max(ascender, ck.getImage().getScaledHeight() + ck.getImageOffsetY()); |
516 | else { | |
517 | PdfFont font = ck.font(); | |
518 | ascender = Math.max(ascender, font.getFont().getFontDescriptor(BaseFont.ASCENT, font.size())); | |
519 | } | |
520 | } | |
521 |
1
1. getAscender : replaced return of float value with -(x + 1) for com/lowagie/text/pdf/PdfLine::getAscender → NO_COVERAGE |
return ascender; |
522 | } | |
523 | ||
524 | /** | |
525 | * Gets the biggest descender for all the fonts used | |
526 | * in this line. Note that this is a negative number. | |
527 | * @return maximum size of all the ascenders used in this line | |
528 | */ | |
529 | public float getDescender() { | |
530 | float descender = 0; | |
531 | for (Object o : line) { | |
532 | PdfChunk ck = (PdfChunk) o; | |
533 |
1
1. getDescender : negated conditional → NO_COVERAGE |
if (ck.isImage()) |
534 | descender = Math.min(descender, ck.getImageOffsetY()); | |
535 | else { | |
536 | PdfFont font = ck.font(); | |
537 | descender = Math.min(descender, font.getFont().getFontDescriptor(BaseFont.DESCENT, font.size())); | |
538 | } | |
539 | } | |
540 |
1
1. getDescender : replaced return of float value with -(x + 1) for com/lowagie/text/pdf/PdfLine::getDescender → NO_COVERAGE |
return descender; |
541 | } | |
542 | } | |
Mutations | ||
110 |
1.1 |
|
150 |
1.1 2.2 |
|
151 |
1.1 |
|
156 |
1.1 2.2 |
|
159 |
1.1 |
|
163 |
1.1 2.2 3.3 4.4 |
|
164 |
1.1 |
|
166 |
1.1 |
|
167 |
1.1 |
|
168 |
1.1 |
|
171 |
1.1 2.2 3.3 |
|
172 |
1.1 |
|
174 |
1.1 |
|
175 |
1.1 |
|
179 |
1.1 2.2 |
|
182 |
1.1 |
|
183 |
1.1 2.2 |
|
184 |
1.1 |
|
185 |
1.1 |
|
189 |
1.1 |
|
190 |
1.1 |
|
191 |
1.1 |
|
195 |
1.1 2.2 |
|
197 |
1.1 |
|
201 |
1.1 2.2 |
|
202 |
1.1 2.2 |
|
203 |
1.1 2.2 |
|
247 |
1.1 |
|
250 |
1.1 2.2 |
|
252 |
1.1 2.2 3.3 |
|
254 |
1.1 |
|
257 |
1.1 |
|
260 |
1.1 2.2 |
|
262 |
1.1 2.2 3.3 |
|
265 |
1.1 |
|
275 |
1.1 2.2 3.3 4.4 |
|
286 |
1.1 |
|
293 |
1.1 |
|
294 |
1.1 |
|
317 |
1.1 2.2 3.3 |
|
318 |
1.1 |
|
319 |
1.1 |
|
322 |
1.1 |
|
380 |
1.1 |
|
382 |
1.1 |
|
390 |
1.1 2.2 3.3 |
|
398 |
1.1 |
|
399 |
1.1 2.2 3.3 |
|
401 |
1.1 |
|
404 |
1.1 |
|
413 |
1.1 2.2 3.3 4.4 |
|
414 |
1.1 |
|
415 |
1.1 |
|
457 |
1.1 |
|
460 |
1.1 |
|
463 |
1.1 |
|
480 |
1.1 |
|
481 |
1.1 |
|
483 |
1.1 |
|
484 |
1.1 |
|
487 |
1.1 |
|
500 |
1.1 |
|
502 |
1.1 |
|
514 |
1.1 |
|
515 |
1.1 |
|
521 |
1.1 |
|
533 |
1.1 |
|
540 |
1.1 |