1 | /* | |
2 | * $Id: BaseFont.java 4065 2009-09-16 23:09:11Z psoares33 $ | |
3 | * | |
4 | * Copyright 2000-2006 by Paulo Soares. | |
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 com.lowagie.text.DocumentException; | |
53 | import com.lowagie.text.error_messages.MessageLocalization; | |
54 | ||
55 | import java.io.IOException; | |
56 | import java.io.InputStream; | |
57 | import java.util.ArrayList; | |
58 | import java.util.HashMap; | |
59 | import java.util.StringTokenizer; | |
60 | import java.util.concurrent.ConcurrentHashMap; | |
61 | ||
62 | /** | |
63 | * Base class for the several font types supported | |
64 | * | |
65 | * @author Paulo Soares (psoares@consiste.pt) | |
66 | */ | |
67 | ||
68 | public abstract class BaseFont { | |
69 | ||
70 | /** This is a possible value of a base 14 type 1 font */ | |
71 | public static final String COURIER = "Courier"; | |
72 | ||
73 | /** This is a possible value of a base 14 type 1 font */ | |
74 | public static final String COURIER_BOLD = "Courier-Bold"; | |
75 | ||
76 | /** This is a possible value of a base 14 type 1 font */ | |
77 | public static final String COURIER_OBLIQUE = "Courier-Oblique"; | |
78 | ||
79 | /** This is a possible value of a base 14 type 1 font */ | |
80 | public static final String COURIER_BOLDOBLIQUE = "Courier-BoldOblique"; | |
81 | ||
82 | /** This is a possible value of a base 14 type 1 font */ | |
83 | public static final String HELVETICA = "Helvetica"; | |
84 | ||
85 | /** This is a possible value of a base 14 type 1 font */ | |
86 | public static final String HELVETICA_BOLD = "Helvetica-Bold"; | |
87 | ||
88 | /** This is a possible value of a base 14 type 1 font */ | |
89 | public static final String HELVETICA_OBLIQUE = "Helvetica-Oblique"; | |
90 | ||
91 | /** This is a possible value of a base 14 type 1 font */ | |
92 | public static final String HELVETICA_BOLDOBLIQUE = "Helvetica-BoldOblique"; | |
93 | ||
94 | /** This is a possible value of a base 14 type 1 font */ | |
95 | public static final String SYMBOL = "Symbol"; | |
96 | ||
97 | /** This is a possible value of a base 14 type 1 font */ | |
98 | public static final String TIMES_ROMAN = "Times-Roman"; | |
99 | ||
100 | /** This is a possible value of a base 14 type 1 font */ | |
101 | public static final String TIMES_BOLD = "Times-Bold"; | |
102 | ||
103 | /** This is a possible value of a base 14 type 1 font */ | |
104 | public static final String TIMES_ITALIC = "Times-Italic"; | |
105 | ||
106 | /** This is a possible value of a base 14 type 1 font */ | |
107 | public static final String TIMES_BOLDITALIC = "Times-BoldItalic"; | |
108 | ||
109 | /** This is a possible value of a base 14 type 1 font */ | |
110 | public static final String ZAPFDINGBATS = "ZapfDingbats"; | |
111 | ||
112 | /** | |
113 | * The maximum height above the baseline reached by glyphs in this font, | |
114 | * excluding the height of glyphs for accented characters. | |
115 | */ | |
116 | public static final int ASCENT = 1; | |
117 | /** | |
118 | * The y coordinate of the top of flat capital letters, measured from the | |
119 | * baseline. | |
120 | */ | |
121 | public static final int CAPHEIGHT = 2; | |
122 | /** | |
123 | * The maximum depth below the baseline reached by glyphs in this font. The | |
124 | * value is a negative number. | |
125 | */ | |
126 | public static final int DESCENT = 3; | |
127 | /** | |
128 | * The angle, expressed in degrees counterclockwise from the vertical, of | |
129 | * the dominant vertical strokes of the font. The value is negative for | |
130 | * fonts that slope to the right, as almost all italic fonts do. | |
131 | */ | |
132 | public static final int ITALICANGLE = 4; | |
133 | /** | |
134 | * The lower left x glyph coordinate. | |
135 | */ | |
136 | public static final int BBOXLLX = 5; | |
137 | /** | |
138 | * The lower left y glyph coordinate. | |
139 | */ | |
140 | public static final int BBOXLLY = 6; | |
141 | /** | |
142 | * The upper right x glyph coordinate. | |
143 | */ | |
144 | public static final int BBOXURX = 7; | |
145 | /** | |
146 | * The upper right y glyph coordinate. | |
147 | */ | |
148 | public static final int BBOXURY = 8; | |
149 | ||
150 | /** java.awt.Font property */ | |
151 | public static final int AWT_ASCENT = 9; | |
152 | /** java.awt.Font property */ | |
153 | public static final int AWT_DESCENT = 10; | |
154 | /** java.awt.Font property */ | |
155 | public static final int AWT_LEADING = 11; | |
156 | /** java.awt.Font property */ | |
157 | public static final int AWT_MAXADVANCE = 12; | |
158 | /** | |
159 | * The underline position. Usually a negative value. | |
160 | */ | |
161 | public static final int UNDERLINE_POSITION = 13; | |
162 | /** | |
163 | * The underline thickness. | |
164 | */ | |
165 | public static final int UNDERLINE_THICKNESS = 14; | |
166 | /** | |
167 | * The strikethrough position. | |
168 | */ | |
169 | public static final int STRIKETHROUGH_POSITION = 15; | |
170 | /** | |
171 | * The strikethrough thickness. | |
172 | */ | |
173 | public static final int STRIKETHROUGH_THICKNESS = 16; | |
174 | /** | |
175 | * The recommended vertical size for subscripts for this font. | |
176 | */ | |
177 | public static final int SUBSCRIPT_SIZE = 17; | |
178 | /** | |
179 | * The recommended vertical offset from the baseline for subscripts for this | |
180 | * font. Usually a negative value. | |
181 | */ | |
182 | public static final int SUBSCRIPT_OFFSET = 18; | |
183 | /** | |
184 | * The recommended vertical size for superscripts for this font. | |
185 | */ | |
186 | public static final int SUPERSCRIPT_SIZE = 19; | |
187 | /** | |
188 | * The recommended vertical offset from the baseline for superscripts for | |
189 | * this font. | |
190 | */ | |
191 | public static final int SUPERSCRIPT_OFFSET = 20; | |
192 | /** | |
193 | * The font is Type 1. | |
194 | */ | |
195 | public static final int FONT_TYPE_T1 = 0; | |
196 | /** | |
197 | * The font is True Type with a standard encoding. | |
198 | */ | |
199 | public static final int FONT_TYPE_TT = 1; | |
200 | /** | |
201 | * The font is CJK. | |
202 | */ | |
203 | public static final int FONT_TYPE_CJK = 2; | |
204 | /** | |
205 | * The font is True Type with a Unicode encoding. | |
206 | */ | |
207 | public static final int FONT_TYPE_TTUNI = 3; | |
208 | /** | |
209 | * A font already inside the document. | |
210 | */ | |
211 | public static final int FONT_TYPE_DOCUMENT = 4; | |
212 | /** | |
213 | * A Type3 font. | |
214 | */ | |
215 | public static final int FONT_TYPE_T3 = 5; | |
216 | /** | |
217 | * The Unicode encoding with horizontal writing. | |
218 | */ | |
219 | public static final String IDENTITY_H = "Identity-H"; | |
220 | /** | |
221 | * The Unicode encoding with vertical writing. | |
222 | */ | |
223 | public static final String IDENTITY_V = "Identity-V"; | |
224 | ||
225 | /** A possible encoding. */ | |
226 | public static final String CP1250 = "Cp1250"; | |
227 | ||
228 | /** A possible encoding. */ | |
229 | public static final String CP1252 = "Cp1252"; | |
230 | ||
231 | /** A possible encoding. */ | |
232 | public static final String CP1257 = "Cp1257"; | |
233 | ||
234 | /** A possible encoding. */ | |
235 | public static final String WINANSI = "Cp1252"; | |
236 | ||
237 | /** A possible encoding. */ | |
238 | public static final String MACROMAN = "MacRoman"; | |
239 | ||
240 | public static final int[] CHAR_RANGE_LATIN = { 0, 0x17f, 0x2000, 0x206f, | |
241 | 0x20a0, 0x20cf, 0xfb00, 0xfb06 }; | |
242 | public static final int[] CHAR_RANGE_ARABIC = { 0, 0x7f, 0x0600, 0x067f, | |
243 | 0x20a0, 0x20cf, 0xfb50, 0xfbff, 0xfe70, 0xfeff }; | |
244 | public static final int[] CHAR_RANGE_HEBREW = { 0, 0x7f, 0x0590, 0x05ff, | |
245 | 0x20a0, 0x20cf, 0xfb1d, 0xfb4f }; | |
246 | public static final int[] CHAR_RANGE_CYRILLIC = { 0, 0x7f, 0x0400, 0x052f, | |
247 | 0x2000, 0x206f, 0x20a0, 0x20cf }; | |
248 | ||
249 | /** if the font has to be embedded */ | |
250 | public static final boolean EMBEDDED = true; | |
251 | ||
252 | /** if the font doesn't have to be embedded */ | |
253 | public static final boolean NOT_EMBEDDED = false; | |
254 | /** if the font has to be cached */ | |
255 | public static final boolean CACHED = true; | |
256 | /** if the font doesn't have to be cached */ | |
257 | public static final boolean NOT_CACHED = false; | |
258 | ||
259 | /** The path to the font resources. */ | |
260 | public static final String RESOURCE_PATH = "com/lowagie/text/pdf/fonts/"; | |
261 | /** The fake CID code that represents a newline. */ | |
262 | public static final char CID_NEWLINE = '\u7fff'; | |
263 | ||
264 | protected ArrayList<int[]> subsetRanges; | |
265 | /** | |
266 | * The font type. | |
267 | */ | |
268 | int fontType; | |
269 | /** a not defined character in a custom PDF encoding */ | |
270 | public static final String notdef = ".notdef"; | |
271 | ||
272 | /** | |
273 | * table of characters widths for this encoding | |
274 | */ | |
275 | protected int[] widths = new int[256]; | |
276 | ||
277 | /** | |
278 | * encoding names | |
279 | */ | |
280 | protected String[] differences = new String[256]; | |
281 | /** | |
282 | * same as differences but with the unicode codes | |
283 | */ | |
284 | protected char[] unicodeDifferences = new char[256]; | |
285 | ||
286 | protected int[][] charBBoxes = new int[256][]; | |
287 | /** encoding used with this font */ | |
288 | protected String encoding; | |
289 | ||
290 | /** true if the font is to be embedded in the PDF */ | |
291 | protected boolean embedded; | |
292 | ||
293 | /** | |
294 | * The compression level for the font stream. | |
295 | * | |
296 | * @since 2.1.3 | |
297 | */ | |
298 | protected int compressionLevel = PdfStream.DEFAULT_COMPRESSION; | |
299 | ||
300 | /** | |
301 | * true if the font must use its built in encoding. In that case the | |
302 | * <CODE>encoding</CODE> is only used to map a char to the position inside | |
303 | * the font, not to the expected char name. | |
304 | */ | |
305 | protected boolean fontSpecific = true; | |
306 | ||
307 | /** cache for the fonts already used. */ | |
308 | protected static ConcurrentHashMap<String, BaseFont> fontCache = new ConcurrentHashMap<>( | |
309 | 500, 0.85f, 64); | |
310 | ||
311 | /** list of the 14 built in fonts. */ | |
312 | protected static final HashMap<String, PdfName> BuiltinFonts14 = new HashMap<>(); | |
313 | ||
314 | /** | |
315 | * Forces the output of the width array. Only matters for the 14 built-in | |
316 | * fonts. | |
317 | */ | |
318 | protected boolean forceWidthsOutput = false; | |
319 | ||
320 | /** | |
321 | * Converts <CODE>char</CODE> directly to <CODE>byte</CODE> by casting. | |
322 | */ | |
323 | protected boolean directTextToByte = false; | |
324 | ||
325 | /** | |
326 | * Indicates if all the glyphs and widths for that particular encoding | |
327 | * should be included in the document. | |
328 | */ | |
329 | protected boolean subset = true; | |
330 | ||
331 | protected boolean fastWinansi = false; | |
332 | ||
333 | /** | |
334 | * Custom encodings use this map to key the Unicode character to the single | |
335 | * byte code. | |
336 | */ | |
337 | protected IntHashtable specialMap; | |
338 | ||
339 | static { | |
340 | BuiltinFonts14.put(COURIER, PdfName.COURIER); | |
341 | BuiltinFonts14.put(COURIER_BOLD, PdfName.COURIER_BOLD); | |
342 | BuiltinFonts14.put(COURIER_BOLDOBLIQUE, PdfName.COURIER_BOLDOBLIQUE); | |
343 | BuiltinFonts14.put(COURIER_OBLIQUE, PdfName.COURIER_OBLIQUE); | |
344 | BuiltinFonts14.put(HELVETICA, PdfName.HELVETICA); | |
345 | BuiltinFonts14.put(HELVETICA_BOLD, PdfName.HELVETICA_BOLD); | |
346 | BuiltinFonts14 | |
347 | .put(HELVETICA_BOLDOBLIQUE, PdfName.HELVETICA_BOLDOBLIQUE); | |
348 | BuiltinFonts14.put(HELVETICA_OBLIQUE, PdfName.HELVETICA_OBLIQUE); | |
349 | BuiltinFonts14.put(SYMBOL, PdfName.SYMBOL); | |
350 | BuiltinFonts14.put(TIMES_ROMAN, PdfName.TIMES_ROMAN); | |
351 | BuiltinFonts14.put(TIMES_BOLD, PdfName.TIMES_BOLD); | |
352 | BuiltinFonts14.put(TIMES_BOLDITALIC, PdfName.TIMES_BOLDITALIC); | |
353 | BuiltinFonts14.put(TIMES_ITALIC, PdfName.TIMES_ITALIC); | |
354 | BuiltinFonts14.put(ZAPFDINGBATS, PdfName.ZAPFDINGBATS); | |
355 | } | |
356 | ||
357 | /** | |
358 | * Generates the PDF stream with the Type1 and Truetype fonts returning a | |
359 | * PdfStream. | |
360 | */ | |
361 | static class StreamFont extends PdfStream { | |
362 | ||
363 | /** | |
364 | * Generates the PDF stream with the Type1 and Truetype fonts returning | |
365 | * a PdfStream. | |
366 | * | |
367 | * @param contents | |
368 | * the content of the stream | |
369 | * @param lengths | |
370 | * an array of int that describes the several lengths of each | |
371 | * part of the font | |
372 | * @param compressionLevel | |
373 | * the compression level of the Stream | |
374 | * @throws DocumentException | |
375 | * error in the stream compression | |
376 | * @since 2.1.3 (replaces the constructor without param | |
377 | * compressionLevel) | |
378 | */ | |
379 | public StreamFont(byte[] contents, int[] lengths, int compressionLevel) | |
380 | throws DocumentException { | |
381 | try { | |
382 | bytes = contents; | |
383 |
1
1. |
put(PdfName.LENGTH, new PdfNumber(bytes.length)); |
384 |
2
1. 2. |
for (int k = 0; k < lengths.length; ++k) { |
385 |
2
1. 2. |
put(new PdfName("Length" + (k + 1)), new PdfNumber( |
386 | lengths[k])); | |
387 | } | |
388 |
1
1. |
flateCompress(compressionLevel); |
389 | } catch (Exception e) { | |
390 | throw new DocumentException(e); | |
391 | } | |
392 | } | |
393 | ||
394 | /** | |
395 | * Generates the PDF stream for a font. | |
396 | * | |
397 | * @param contents | |
398 | * the content of a stream | |
399 | * @param subType | |
400 | * the subtype of the font. | |
401 | * @param compressionLevel | |
402 | * the compression level of the Stream | |
403 | * @throws DocumentException | |
404 | * error in the stream compression | |
405 | * @since 2.1.3 (replaces the constructor without param | |
406 | * compressionLevel) | |
407 | */ | |
408 | public StreamFont(byte[] contents, String subType, int compressionLevel) | |
409 | throws DocumentException { | |
410 | try { | |
411 | bytes = contents; | |
412 |
1
1. |
put(PdfName.LENGTH, new PdfNumber(bytes.length)); |
413 |
1
1. |
if (subType != null) { |
414 |
1
1. |
put(PdfName.SUBTYPE, new PdfName(subType)); |
415 | } | |
416 |
1
1. |
flateCompress(compressionLevel); |
417 | } catch (Exception e) { | |
418 | throw new DocumentException(e); | |
419 | } | |
420 | } | |
421 | } | |
422 | ||
423 | /** | |
424 | * Creates new BaseFont | |
425 | */ | |
426 | protected BaseFont() { | |
427 | } | |
428 | ||
429 | /** | |
430 | * Creates a new font. This will always be the default Helvetica font (not | |
431 | * embedded). This method is introduced because Helvetica is used in many | |
432 | * examples. | |
433 | * | |
434 | * @return a BaseFont object (Helvetica, Winansi, not embedded) | |
435 | * @throws IOException | |
436 | * This shouldn't occur ever | |
437 | * @throws DocumentException | |
438 | * This shouldn't occur ever | |
439 | * @since 2.1.1 | |
440 | */ | |
441 | public static BaseFont createFont() throws DocumentException, IOException { | |
442 |
1
1. createFont : mutated return of Object value for com/lowagie/text/pdf/BaseFont::createFont to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return createFont(BaseFont.HELVETICA, BaseFont.WINANSI, |
443 | BaseFont.NOT_EMBEDDED); | |
444 | } | |
445 | ||
446 | /** | |
447 | * Creates a new font. This font can be one of the 14 built in types, a | |
448 | * Type1 font referred to by an AFM or PFM file, a TrueType font (simple or | |
449 | * collection) or a CJK font from the Adobe Asian Font Pack. TrueType fonts | |
450 | * and CJK fonts can have an optional style modifier appended to the name. | |
451 | * These modifiers are: Bold, Italic and BoldItalic. An example would be | |
452 | * "STSong-Light,Bold". Note that this modifiers do not work if the font is | |
453 | * embedded. Fonts in TrueType collections are addressed by index such as | |
454 | * "msgothic.ttc,1". This would get the second font (indexes start at 0), in | |
455 | * this case "MS PGothic". | |
456 | * <P> | |
457 | * The fonts are cached and if they already exist they are extracted from | |
458 | * the cache, not parsed again. | |
459 | * <P> | |
460 | * Besides the common encodings described by name, custom encodings can also | |
461 | * be made. These encodings will only work for the single byte fonts Type1 | |
462 | * and TrueType. The encoding string starts with a '#' followed by "simple" | |
463 | * or "full". If "simple" there is a decimal for the first character | |
464 | * position and then a list of hex values representing the Unicode codes | |
465 | * that compose that encoding.<br> | |
466 | * The "simple" encoding is recommended for TrueType fonts as the "full" | |
467 | * encoding risks not matching the character with the right glyph if not | |
468 | * done with care.<br> | |
469 | * The "full" encoding is specially aimed at Type1 fonts where the glyphs | |
470 | * have to be described by non standard names like the Tex math fonts. Each | |
471 | * group of three elements compose a code position: the one byte code order | |
472 | * in decimal or as 'x' (x cannot be the space), the name and the Unicode | |
473 | * character used to access the glyph. The space must be assigned to | |
474 | * character position 32 otherwise text justification will not work. | |
475 | * <P> | |
476 | * Example for a "simple" encoding that includes the Unicode character | |
477 | * space, A, B and ecyrillic: | |
478 | * | |
479 | * <PRE> | |
480 | * "# simple 32 0020 0041 0042 0454" | |
481 | * </PRE> | |
482 | * <P> | |
483 | * Example for a "full" encoding for a Type1 Tex font: | |
484 | * | |
485 | * <PRE> | |
486 | * "# full 'A' nottriangeqlleft 0041 'B' dividemultiply 0042 32 space 0020" | |
487 | * </PRE> | |
488 | * <P> | |
489 | * This method calls:<br> | |
490 | * | |
491 | * <PRE> | |
492 | * createFont(name, encoding, embedded, true, null, null); | |
493 | * </PRE> | |
494 | * | |
495 | * @param name | |
496 | * the name of the font or its location on file | |
497 | * @param encoding | |
498 | * the encoding to be applied to this font | |
499 | * @param embedded | |
500 | * true if the font is to be embedded in the PDF | |
501 | * @return returns a new font. This font may come from the cache | |
502 | * @throws DocumentException | |
503 | * the font is invalid | |
504 | * @throws IOException | |
505 | * the font file could not be read | |
506 | */ | |
507 | public static BaseFont createFont(String name, String encoding, | |
508 | boolean embedded) throws DocumentException, IOException { | |
509 |
1
1. createFont : mutated return of Object value for com/lowagie/text/pdf/BaseFont::createFont to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return createFont(name, encoding, embedded, true, null, null, false); |
510 | } | |
511 | ||
512 | /** | |
513 | * Creates a new font. This font can be one of the 14 built in types, a | |
514 | * Type1 font referred to by an AFM or PFM file, a TrueType font (simple or | |
515 | * collection) or a CJK font from the Adobe Asian Font Pack. TrueType fonts | |
516 | * and CJK fonts can have an optional style modifier appended to the name. | |
517 | * These modifiers are: Bold, Italic and BoldItalic. An example would be | |
518 | * "STSong-Light,Bold". Note that this modifiers do not work if the font is | |
519 | * embedded. Fonts in TrueType collections are addressed by index such as | |
520 | * "msgothic.ttc,1". This would get the second font (indexes start at 0), in | |
521 | * this case "MS PGothic". | |
522 | * <P> | |
523 | * The fonts are cached and if they already exist they are extracted from | |
524 | * the cache, not parsed again. | |
525 | * <P> | |
526 | * Besides the common encodings described by name, custom encodings can also | |
527 | * be made. These encodings will only work for the single byte fonts Type1 | |
528 | * and TrueType. The encoding string starts with a '#' followed by "simple" | |
529 | * or "full". If "simple" there is a decimal for the first character | |
530 | * position and then a list of hex values representing the Unicode codes | |
531 | * that compose that encoding.<br> | |
532 | * The "simple" encoding is recommended for TrueType fonts as the "full" | |
533 | * encoding risks not matching the character with the right glyph if not | |
534 | * done with care.<br> | |
535 | * The "full" encoding is specially aimed at Type1 fonts where the glyphs | |
536 | * have to be described by non standard names like the Tex math fonts. Each | |
537 | * group of three elements compose a code position: the one byte code order | |
538 | * in decimal or as 'x' (x cannot be the space), the name and the Unicode | |
539 | * character used to access the glyph. The space must be assigned to | |
540 | * character position 32 otherwise text justification will not work. | |
541 | * <P> | |
542 | * Example for a "simple" encoding that includes the Unicode character | |
543 | * space, A, B and ecyrillic: | |
544 | * | |
545 | * <PRE> | |
546 | * "# simple 32 0020 0041 0042 0454" | |
547 | * </PRE> | |
548 | * <P> | |
549 | * Example for a "full" encoding for a Type1 Tex font: | |
550 | * | |
551 | * <PRE> | |
552 | * "# full 'A' nottriangeqlleft 0041 'B' dividemultiply 0042 32 space 0020" | |
553 | * </PRE> | |
554 | * <P> | |
555 | * This method calls:<br> | |
556 | * | |
557 | * <PRE> | |
558 | * createFont(name, encoding, embedded, true, null, null); | |
559 | * </PRE> | |
560 | * | |
561 | * @param name | |
562 | * the name of the font or its location on file | |
563 | * @param encoding | |
564 | * the encoding to be applied to this font | |
565 | * @param embedded | |
566 | * true if the font is to be embedded in the PDF | |
567 | * @param forceRead | |
568 | * in some cases (TrueTypeFont, Type1Font), the full font file | |
569 | * will be read and kept in memory if forceRead is true | |
570 | * @return returns a new font. This font may come from the cache | |
571 | * @throws DocumentException | |
572 | * the font is invalid | |
573 | * @throws IOException | |
574 | * the font file could not be read | |
575 | * @since 2.1.5 | |
576 | */ | |
577 | public static BaseFont createFont(String name, String encoding, | |
578 | boolean embedded, boolean forceRead) throws DocumentException, | |
579 | IOException { | |
580 |
1
1. createFont : mutated return of Object value for com/lowagie/text/pdf/BaseFont::createFont to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return createFont(name, encoding, embedded, true, null, null, forceRead); |
581 | } | |
582 | ||
583 | /** | |
584 | * Creates a new font. This font can be one of the 14 built in types, a | |
585 | * Type1 font referred to by an AFM or PFM file, a TrueType font (simple or | |
586 | * collection) or a CJK font from the Adobe Asian Font Pack. TrueType fonts | |
587 | * and CJK fonts can have an optional style modifier appended to the name. | |
588 | * These modifiers are: Bold, Italic and BoldItalic. An example would be | |
589 | * "STSong-Light,Bold". Note that this modifiers do not work if the font is | |
590 | * embedded. Fonts in TrueType collections are addressed by index such as | |
591 | * "msgothic.ttc,1". This would get the second font (indexes start at 0), in | |
592 | * this case "MS PGothic". | |
593 | * <P> | |
594 | * The fonts may or may not be cached depending on the flag | |
595 | * <CODE>cached</CODE>. If the <CODE>byte</CODE> arrays are present the font | |
596 | * will be read from them instead of the name. A name is still required to | |
597 | * identify the font type. | |
598 | * <P> | |
599 | * Besides the common encodings described by name, custom encodings can also | |
600 | * be made. These encodings will only work for the single byte fonts Type1 | |
601 | * and TrueType. The encoding string starts with a '#' followed by "simple" | |
602 | * or "full". If "simple" there is a decimal for the first character | |
603 | * position and then a list of hex values representing the Unicode codes | |
604 | * that compose that encoding.<br> | |
605 | * The "simple" encoding is recommended for TrueType fonts as the "full" | |
606 | * encoding risks not matching the character with the right glyph if not | |
607 | * done with care.<br> | |
608 | * The "full" encoding is specially aimed at Type1 fonts where the glyphs | |
609 | * have to be described by non standard names like the Tex math fonts. Each | |
610 | * group of three elements compose a code position: the one byte code order | |
611 | * in decimal or as 'x' (x cannot be the space), the name and the Unicode | |
612 | * character used to access the glyph. The space must be assigned to | |
613 | * character position 32 otherwise text justification will not work. | |
614 | * <P> | |
615 | * Example for a "simple" encoding that includes the Unicode character | |
616 | * space, A, B and ecyrillic: | |
617 | * | |
618 | * <PRE> | |
619 | * "# simple 32 0020 0041 0042 0454" | |
620 | * </PRE> | |
621 | * <P> | |
622 | * Example for a "full" encoding for a Type1 Tex font: | |
623 | * | |
624 | * <PRE> | |
625 | * "# full 'A' nottriangeqlleft 0041 'B' dividemultiply 0042 32 space 0020" | |
626 | * </PRE> | |
627 | * | |
628 | * @param name | |
629 | * the name of the font or its location on file | |
630 | * @param encoding | |
631 | * the encoding to be applied to this font | |
632 | * @param embedded | |
633 | * true if the font is to be embedded in the PDF | |
634 | * @param cached | |
635 | * true if the font comes from the cache or is added to the cache | |
636 | * if new, false if the font is always created new | |
637 | * @param ttfAfm | |
638 | * the true type font or the afm in a byte array | |
639 | * @param pfb | |
640 | * the pfb in a byte array | |
641 | * @return returns a new font. This font may come from the cache but only if | |
642 | * cached is true, otherwise it will always be created new | |
643 | * @throws DocumentException | |
644 | * the font is invalid | |
645 | * @throws IOException | |
646 | * the font file could not be read | |
647 | * @since iText 0.80 | |
648 | */ | |
649 | public static BaseFont createFont(String name, String encoding, | |
650 | boolean embedded, boolean cached, byte[] ttfAfm, byte[] pfb) | |
651 | throws DocumentException, IOException { | |
652 |
1
1. createFont : mutated return of Object value for com/lowagie/text/pdf/BaseFont::createFont to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return createFont(name, encoding, embedded, cached, ttfAfm, pfb, false); |
653 | } | |
654 | ||
655 | /** | |
656 | * Creates a new font. This font can be one of the 14 built in types, a | |
657 | * Type1 font referred to by an AFM or PFM file, a TrueType font (simple or | |
658 | * collection) or a CJK font from the Adobe Asian Font Pack. TrueType fonts | |
659 | * and CJK fonts can have an optional style modifier appended to the name. | |
660 | * These modifiers are: Bold, Italic and BoldItalic. An example would be | |
661 | * "STSong-Light,Bold". Note that this modifiers do not work if the font is | |
662 | * embedded. Fonts in TrueType collections are addressed by index such as | |
663 | * "msgothic.ttc,1". This would get the second font (indexes start at 0), in | |
664 | * this case "MS PGothic". | |
665 | * <P> | |
666 | * The fonts may or may not be cached depending on the flag | |
667 | * <CODE>cached</CODE>. If the <CODE>byte</CODE> arrays are present the font | |
668 | * will be read from them instead of the name. A name is still required to | |
669 | * identify the font type. | |
670 | * <P> | |
671 | * Besides the common encodings described by name, custom encodings can also | |
672 | * be made. These encodings will only work for the single byte fonts Type1 | |
673 | * and TrueType. The encoding string starts with a '#' followed by "simple" | |
674 | * or "full". If "simple" there is a decimal for the first character | |
675 | * position and then a list of hex values representing the Unicode codes | |
676 | * that compose that encoding.<br> | |
677 | * The "simple" encoding is recommended for TrueType fonts as the "full" | |
678 | * encoding risks not matching the character with the right glyph if not | |
679 | * done with care.<br> | |
680 | * The "full" encoding is specially aimed at Type1 fonts where the glyphs | |
681 | * have to be described by non standard names like the Tex math fonts. Each | |
682 | * group of three elements compose a code position: the one byte code order | |
683 | * in decimal or as 'x' (x cannot be the space), the name and the Unicode | |
684 | * character used to access the glyph. The space must be assigned to | |
685 | * character position 32 otherwise text justification will not work. | |
686 | * <P> | |
687 | * Example for a "simple" encoding that includes the Unicode character | |
688 | * space, A, B and ecyrillic: | |
689 | * | |
690 | * <PRE> | |
691 | * "# simple 32 0020 0041 0042 0454" | |
692 | * </PRE> | |
693 | * <P> | |
694 | * Example for a "full" encoding for a Type1 Tex font: | |
695 | * | |
696 | * <PRE> | |
697 | * "# full 'A' nottriangeqlleft 0041 'B' dividemultiply 0042 32 space 0020" | |
698 | * </PRE> | |
699 | * | |
700 | * @param name | |
701 | * the name of the font or its location on file | |
702 | * @param encoding | |
703 | * the encoding to be applied to this font | |
704 | * @param embedded | |
705 | * true if the font is to be embedded in the PDF | |
706 | * @param cached | |
707 | * true if the font comes from the cache or is added to the cache | |
708 | * if new, false if the font is always created new | |
709 | * @param ttfAfm | |
710 | * the true type font or the afm in a byte array | |
711 | * @param pfb | |
712 | * the pfb in a byte array | |
713 | * @param noThrow | |
714 | * if true will not throw an exception if the font is not | |
715 | * recognized and will return null, if false will throw an | |
716 | * exception if the font is not recognized. Note that even if | |
717 | * true an exception may be thrown in some circumstances. This | |
718 | * parameter is useful for FontFactory that may have to check | |
719 | * many invalid font names before finding the right one | |
720 | * @return returns a new font. This font may come from the cache but only if | |
721 | * cached is true, otherwise it will always be created new | |
722 | * @throws DocumentException | |
723 | * the font is invalid | |
724 | * @throws IOException | |
725 | * the font file could not be read | |
726 | * @since 2.0.3 | |
727 | */ | |
728 | public static BaseFont createFont(String name, String encoding, | |
729 | boolean embedded, boolean cached, byte[] ttfAfm, byte[] pfb, | |
730 | boolean noThrow) throws DocumentException, IOException { | |
731 |
1
1. createFont : mutated return of Object value for com/lowagie/text/pdf/BaseFont::createFont to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return createFont(name, encoding, embedded, cached, ttfAfm, pfb, false, |
732 | false); | |
733 | } | |
734 | ||
735 | /** | |
736 | * Creates a new font. This font can be one of the 14 built in types, a | |
737 | * Type1 font referred to by an AFM or PFM file, a TrueType font (simple or | |
738 | * collection) or a CJK font from the Adobe Asian Font Pack. TrueType fonts | |
739 | * and CJK fonts can have an optional style modifier appended to the name. | |
740 | * These modifiers are: Bold, Italic and BoldItalic. An example would be | |
741 | * "STSong-Light,Bold". Note that this modifiers do not work if the font is | |
742 | * embedded. Fonts in TrueType collections are addressed by index such as | |
743 | * "msgothic.ttc,1". This would get the second font (indexes start at 0), in | |
744 | * this case "MS PGothic". | |
745 | * <P> | |
746 | * The fonts may or may not be cached depending on the flag | |
747 | * <CODE>cached</CODE>. If the <CODE>byte</CODE> arrays are present the font | |
748 | * will be read from them instead of the name. A name is still required to | |
749 | * identify the font type. | |
750 | * <P> | |
751 | * Besides the common encodings described by name, custom encodings can also | |
752 | * be made. These encodings will only work for the single byte fonts Type1 | |
753 | * and TrueType. The encoding string starts with a '#' followed by "simple" | |
754 | * or "full". If "simple" there is a decimal for the first character | |
755 | * position and then a list of hex values representing the Unicode codes | |
756 | * that compose that encoding.<br> | |
757 | * The "simple" encoding is recommended for TrueType fonts as the "full" | |
758 | * encoding risks not matching the character with the right glyph if not | |
759 | * done with care.<br> | |
760 | * The "full" encoding is specially aimed at Type1 fonts where the glyphs | |
761 | * have to be described by non standard names like the Tex math fonts. Each | |
762 | * group of three elements compose a code position: the one byte code order | |
763 | * in decimal or as 'x' (x cannot be the space), the name and the Unicode | |
764 | * character used to access the glyph. The space must be assigned to | |
765 | * character position 32 otherwise text justification will not work. | |
766 | * <P> | |
767 | * Example for a "simple" encoding that includes the Unicode character | |
768 | * space, A, B and ecyrillic: | |
769 | * | |
770 | * <PRE> | |
771 | * "# simple 32 0020 0041 0042 0454" | |
772 | * </PRE> | |
773 | * <P> | |
774 | * Example for a "full" encoding for a Type1 Tex font: | |
775 | * | |
776 | * <PRE> | |
777 | * "# full 'A' nottriangeqlleft 0041 'B' dividemultiply 0042 32 space 0020" | |
778 | * </PRE> | |
779 | * | |
780 | * @param name | |
781 | * the name of the font or its location on file | |
782 | * @param encoding | |
783 | * the encoding to be applied to this font | |
784 | * @param embedded | |
785 | * true if the font is to be embedded in the PDF | |
786 | * @param cached | |
787 | * true if the font comes from the cache or is added to the cache | |
788 | * if new, false if the font is always created new | |
789 | * @param ttfAfm | |
790 | * the true type font or the afm in a byte array | |
791 | * @param pfb | |
792 | * the pfb in a byte array | |
793 | * @param noThrow | |
794 | * if true will not throw an exception if the font is not | |
795 | * recognized and will return null, if false will throw an | |
796 | * exception if the font is not recognized. Note that even if | |
797 | * true an exception may be thrown in some circumstances. This | |
798 | * parameter is useful for FontFactory that may have to check | |
799 | * many invalid font names before finding the right one | |
800 | * @param forceRead | |
801 | * in some cases (TrueTypeFont, Type1Font), the full font file | |
802 | * will be read and kept in memory if forceRead is true | |
803 | * @return returns a new font. This font may come from the cache but only if | |
804 | * cached is true, otherwise it will always be created new | |
805 | * @throws DocumentException | |
806 | * the font is invalid | |
807 | * @throws IOException | |
808 | * the font file could not be read | |
809 | * @since 2.1.5 | |
810 | */ | |
811 | public static BaseFont createFont(String name, String encoding, | |
812 | boolean embedded, boolean cached, byte[] ttfAfm, byte[] pfb, | |
813 | boolean noThrow, boolean forceRead) throws DocumentException, | |
814 | IOException { | |
815 | String nameBase = getBaseName(name); | |
816 | encoding = normalizeEncoding(encoding); | |
817 | boolean isBuiltinFonts14 = BuiltinFonts14.containsKey(name); | |
818 |
2
1. createFont : negated conditional → NO_COVERAGE 2. createFont : negated conditional → NO_COVERAGE |
boolean isCJKFont = !isBuiltinFonts14 && CJKFont.isCJKFont( |
819 | nameBase, encoding); | |
820 |
2
1. createFont : negated conditional → NO_COVERAGE 2. createFont : negated conditional → NO_COVERAGE |
if (isBuiltinFonts14 || isCJKFont) { |
821 | embedded = false; | |
822 |
2
1. createFont : negated conditional → NO_COVERAGE 2. createFont : negated conditional → NO_COVERAGE |
} else if (encoding.equals(IDENTITY_H) || encoding.equals(IDENTITY_V)) { |
823 | embedded = true; | |
824 | } | |
825 | BaseFont fontFound = null; | |
826 | BaseFont fontBuilt = null; | |
827 | String key = name + "\n" + encoding + "\n" + embedded; | |
828 |
1
1. createFont : negated conditional → NO_COVERAGE |
if (cached) { |
829 | fontFound = fontCache.get(key); | |
830 |
1
1. createFont : negated conditional → NO_COVERAGE |
if (fontFound != null) { |
831 |
1
1. createFont : mutated return of Object value for com/lowagie/text/pdf/BaseFont::createFont to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return fontFound; |
832 | } | |
833 | } | |
834 |
2
1. createFont : negated conditional → NO_COVERAGE 2. createFont : negated conditional → NO_COVERAGE |
if (isBuiltinFonts14 || name.toLowerCase().endsWith(".afm") |
835 |
1
1. createFont : negated conditional → NO_COVERAGE |
|| name.toLowerCase().endsWith(".pfm")) { |
836 | fontBuilt = new Type1Font(name, encoding, embedded, ttfAfm, pfb, | |
837 | forceRead); | |
838 | fontBuilt.fastWinansi = encoding.equals(CP1252); | |
839 |
1
1. createFont : negated conditional → NO_COVERAGE |
} else if (nameBase.toLowerCase().endsWith(".ttf") |
840 |
1
1. createFont : negated conditional → NO_COVERAGE |
|| nameBase.toLowerCase().endsWith(".otf") |
841 |
2
1. createFont : changed conditional boundary → NO_COVERAGE 2. createFont : negated conditional → NO_COVERAGE |
|| nameBase.toLowerCase().indexOf(".ttc,") > 0) { |
842 |
2
1. createFont : negated conditional → NO_COVERAGE 2. createFont : negated conditional → NO_COVERAGE |
if (encoding.equals(IDENTITY_H) || encoding.equals(IDENTITY_V)) { |
843 | fontBuilt = new TrueTypeFontUnicode(name, encoding, embedded, | |
844 | ttfAfm, forceRead); | |
845 | } else { | |
846 | fontBuilt = new TrueTypeFont(name, encoding, embedded, ttfAfm, | |
847 | false, forceRead); | |
848 | fontBuilt.fastWinansi = encoding.equals(CP1252); | |
849 | } | |
850 |
1
1. createFont : negated conditional → NO_COVERAGE |
} else if (isCJKFont) { |
851 | fontBuilt = new CJKFont(name, encoding, embedded); | |
852 |
1
1. createFont : negated conditional → NO_COVERAGE |
} else if (noThrow) { |
853 |
1
1. createFont : mutated return of Object value for com/lowagie/text/pdf/BaseFont::createFont to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return null; |
854 | } else { | |
855 | throw new DocumentException(MessageLocalization.getComposedMessage( | |
856 | "font.1.with.2.is.not.recognized", name, encoding)); | |
857 | } | |
858 |
1
1. createFont : negated conditional → NO_COVERAGE |
if (cached) { |
859 | fontCache.putIfAbsent(key, fontBuilt); | |
860 |
1
1. createFont : mutated return of Object value for com/lowagie/text/pdf/BaseFont::createFont to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return fontCache.get(key); |
861 | } | |
862 |
1
1. createFont : mutated return of Object value for com/lowagie/text/pdf/BaseFont::createFont to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return fontBuilt; |
863 | } | |
864 | ||
865 | /** | |
866 | * Creates a font based on an existing document font. The created font font | |
867 | * may not behave as expected, depending on the encoding or subset. | |
868 | * | |
869 | * @param fontRef | |
870 | * the reference to the document font | |
871 | * @return the font | |
872 | */ | |
873 | public static BaseFont createFont(PRIndirectReference fontRef) { | |
874 |
1
1. createFont : mutated return of Object value for com/lowagie/text/pdf/BaseFont::createFont to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return new DocumentFont(fontRef); |
875 | } | |
876 | ||
877 | /** | |
878 | * Gets the name without the modifiers Bold, Italic or BoldItalic. | |
879 | * | |
880 | * @param name | |
881 | * the full name of the font | |
882 | * @return the name without the modifiers Bold, Italic or BoldItalic | |
883 | */ | |
884 | protected static String getBaseName(String name) { | |
885 |
1
1. getBaseName : negated conditional → NO_COVERAGE |
if (name.endsWith(",Bold")) { |
886 |
2
1. getBaseName : Replaced integer subtraction with addition → NO_COVERAGE 2. getBaseName : mutated return of Object value for com/lowagie/text/pdf/BaseFont::getBaseName to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return name.substring(0, name.length() - 5); |
887 |
1
1. getBaseName : negated conditional → NO_COVERAGE |
} else if (name.endsWith(",Italic")) { |
888 |
2
1. getBaseName : Replaced integer subtraction with addition → NO_COVERAGE 2. getBaseName : mutated return of Object value for com/lowagie/text/pdf/BaseFont::getBaseName to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return name.substring(0, name.length() - 7); |
889 |
1
1. getBaseName : negated conditional → NO_COVERAGE |
} else if (name.endsWith(",BoldItalic")) { |
890 |
2
1. getBaseName : Replaced integer subtraction with addition → NO_COVERAGE 2. getBaseName : mutated return of Object value for com/lowagie/text/pdf/BaseFont::getBaseName to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return name.substring(0, name.length() - 11); |
891 | } else { | |
892 |
1
1. getBaseName : mutated return of Object value for com/lowagie/text/pdf/BaseFont::getBaseName to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return name; |
893 | } | |
894 | } | |
895 | ||
896 | /** | |
897 | * Normalize the encoding names. "winansi" is changed to "Cp1252" and | |
898 | * "macroman" is changed to "MacRoman". | |
899 | * | |
900 | * @param enc | |
901 | * the encoding to be normalized | |
902 | * @return the normalized encoding | |
903 | */ | |
904 | protected static String normalizeEncoding(String enc) { | |
905 |
2
1. normalizeEncoding : negated conditional → NO_COVERAGE 2. normalizeEncoding : negated conditional → NO_COVERAGE |
if (enc.equals("winansi") || enc.equals("")) { |
906 |
1
1. normalizeEncoding : mutated return of Object value for com/lowagie/text/pdf/BaseFont::normalizeEncoding to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return CP1252; |
907 |
1
1. normalizeEncoding : negated conditional → NO_COVERAGE |
} else if (enc.equals("macroman")) { |
908 |
1
1. normalizeEncoding : mutated return of Object value for com/lowagie/text/pdf/BaseFont::normalizeEncoding to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return MACROMAN; |
909 | } else { | |
910 |
1
1. normalizeEncoding : mutated return of Object value for com/lowagie/text/pdf/BaseFont::normalizeEncoding to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return enc; |
911 | } | |
912 | } | |
913 | ||
914 | /** | |
915 | * Creates the <CODE>widths</CODE> and the <CODE>differences</CODE> arrays | |
916 | */ | |
917 | protected void createEncoding() { | |
918 |
1
1. createEncoding : negated conditional → NO_COVERAGE |
if (encoding.startsWith("#")) { |
919 | specialMap = new IntHashtable(); | |
920 | StringTokenizer tok = new StringTokenizer(encoding.substring(1), | |
921 | " ,\t\n\r\f"); | |
922 |
1
1. createEncoding : negated conditional → NO_COVERAGE |
if (tok.nextToken().equals("full")) { |
923 |
1
1. createEncoding : negated conditional → NO_COVERAGE |
while (tok.hasMoreTokens()) { |
924 | String order = tok.nextToken(); | |
925 | String name = tok.nextToken(); | |
926 | char uni = (char) Integer.parseInt(tok.nextToken(), 16); | |
927 | int orderK; | |
928 |
1
1. createEncoding : negated conditional → NO_COVERAGE |
if (order.startsWith("'")) { |
929 | orderK = order.charAt(1); | |
930 | } else { | |
931 | orderK = Integer.parseInt(order); | |
932 | } | |
933 |
1
1. createEncoding : Replaced integer modulus with multiplication → NO_COVERAGE |
orderK %= 256; |
934 | specialMap.put(uni, orderK); | |
935 | differences[orderK] = name; | |
936 | unicodeDifferences[orderK] = uni; | |
937 | widths[orderK] = getRawWidth(uni, name); | |
938 | charBBoxes[orderK] = getRawCharBBox(uni, name); | |
939 | } | |
940 | } else { | |
941 | int k = 0; | |
942 |
1
1. createEncoding : negated conditional → NO_COVERAGE |
if (tok.hasMoreTokens()) { |
943 | k = Integer.parseInt(tok.nextToken()); | |
944 | } | |
945 |
3
1. createEncoding : changed conditional boundary → NO_COVERAGE 2. createEncoding : negated conditional → NO_COVERAGE 3. createEncoding : negated conditional → NO_COVERAGE |
while (tok.hasMoreTokens() && k < 256) { |
946 | String hex = tok.nextToken(); | |
947 |
1
1. createEncoding : Replaced integer modulus with multiplication → NO_COVERAGE |
int uni = Integer.parseInt(hex, 16) % 0x10000; |
948 | String name = GlyphList.unicodeToName(uni); | |
949 |
1
1. createEncoding : negated conditional → NO_COVERAGE |
if (name != null) { |
950 | specialMap.put(uni, k); | |
951 | differences[k] = name; | |
952 | unicodeDifferences[k] = (char) uni; | |
953 | widths[k] = getRawWidth(uni, name); | |
954 | charBBoxes[k] = getRawCharBBox(uni, name); | |
955 |
1
1. createEncoding : Changed increment from 1 to -1 → NO_COVERAGE |
++k; |
956 | } | |
957 | } | |
958 | } | |
959 |
3
1. createEncoding : changed conditional boundary → NO_COVERAGE 2. createEncoding : Changed increment from 1 to -1 → NO_COVERAGE 3. createEncoding : negated conditional → NO_COVERAGE |
for (int k = 0; k < 256; ++k) { |
960 |
1
1. createEncoding : negated conditional → NO_COVERAGE |
if (differences[k] == null) { |
961 | differences[k] = notdef; | |
962 | } | |
963 | } | |
964 |
1
1. createEncoding : negated conditional → NO_COVERAGE |
} else if (fontSpecific) { |
965 |
3
1. createEncoding : changed conditional boundary → NO_COVERAGE 2. createEncoding : Changed increment from 1 to -1 → NO_COVERAGE 3. createEncoding : negated conditional → NO_COVERAGE |
for (int k = 0; k < 256; ++k) { |
966 | widths[k] = getRawWidth(k, null); | |
967 | charBBoxes[k] = getRawCharBBox(k, null); | |
968 | } | |
969 | } else { | |
970 | String s; | |
971 | String name; | |
972 | char c; | |
973 | byte[] b = new byte[1]; | |
974 |
3
1. createEncoding : changed conditional boundary → NO_COVERAGE 2. createEncoding : Changed increment from 1 to -1 → NO_COVERAGE 3. createEncoding : negated conditional → NO_COVERAGE |
for (int k = 0; k < 256; ++k) { |
975 | b[0] = (byte) k; | |
976 | s = PdfEncodings.convertToString(b, encoding); | |
977 |
2
1. createEncoding : changed conditional boundary → NO_COVERAGE 2. createEncoding : negated conditional → NO_COVERAGE |
if (s.length() > 0) { |
978 | c = s.charAt(0); | |
979 | } else { | |
980 | c = '?'; | |
981 | } | |
982 | name = GlyphList.unicodeToName(c); | |
983 |
1
1. createEncoding : negated conditional → NO_COVERAGE |
if (name == null) { |
984 | name = notdef; | |
985 | } | |
986 | differences[k] = name; | |
987 | unicodeDifferences[k] = c; | |
988 | widths[k] = getRawWidth(c, name); | |
989 | charBBoxes[k] = getRawCharBBox(c, name); | |
990 | } | |
991 | } | |
992 | } | |
993 | ||
994 | /** | |
995 | * Gets the width from the font according to the Unicode char <CODE>c</CODE> | |
996 | * or the <CODE>name</CODE>. If the <CODE>name</CODE> is null it's a | |
997 | * symbolic font. | |
998 | * | |
999 | * @param c | |
1000 | * the unicode char | |
1001 | * @param name | |
1002 | * the glyph name | |
1003 | * @return the width of the char | |
1004 | */ | |
1005 | abstract int getRawWidth(int c, String name); | |
1006 | ||
1007 | /** | |
1008 | * Gets the kerning between two Unicode chars. | |
1009 | * | |
1010 | * @param char1 | |
1011 | * the first char | |
1012 | * @param char2 | |
1013 | * the second char | |
1014 | * @return the kerning to be applied in normalized 1000 units | |
1015 | */ | |
1016 | public abstract int getKerning(int char1, int char2); | |
1017 | ||
1018 | /** | |
1019 | * Sets the kerning between two Unicode chars. | |
1020 | * | |
1021 | * @param char1 | |
1022 | * the first char | |
1023 | * @param char2 | |
1024 | * the second char | |
1025 | * @param kern | |
1026 | * the kerning to apply in normalized 1000 units | |
1027 | * @return <code>true</code> if the kerning was applied, <code>false</code> | |
1028 | * otherwise | |
1029 | */ | |
1030 | public abstract boolean setKerning(int char1, int char2, int kern); | |
1031 | ||
1032 | /** | |
1033 | * Gets the width of a <CODE>char</CODE> in normalized 1000 units. | |
1034 | * | |
1035 | * @param char1 | |
1036 | * the unicode <CODE>char</CODE> to get the width of | |
1037 | * @return the width in normalized 1000 units | |
1038 | */ | |
1039 | public int getWidth(int char1) { | |
1040 |
1
1. getWidth : negated conditional → NO_COVERAGE |
if (fastWinansi) { |
1041 |
6
1. getWidth : changed conditional boundary → NO_COVERAGE 2. getWidth : changed conditional boundary → NO_COVERAGE 3. getWidth : changed conditional boundary → NO_COVERAGE 4. getWidth : negated conditional → NO_COVERAGE 5. getWidth : negated conditional → NO_COVERAGE 6. getWidth : negated conditional → NO_COVERAGE |
if (char1 < 128 || char1 >= 160 && char1 <= 255) { |
1042 |
1
1. getWidth : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return widths[char1]; |
1043 | } else { | |
1044 |
1
1. getWidth : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return widths[PdfEncodings.winansi.get(char1)]; |
1045 | } | |
1046 | } else { | |
1047 | int total = 0; | |
1048 | byte[] mbytes = convertToBytes((char) char1); | |
1049 | for (byte mbyte : mbytes) { | |
1050 |
2
1. getWidth : Replaced bitwise AND with OR → NO_COVERAGE 2. getWidth : Replaced integer addition with subtraction → NO_COVERAGE |
total += widths[0xff & mbyte]; |
1051 | } | |
1052 |
1
1. getWidth : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return total; |
1053 | } | |
1054 | } | |
1055 | ||
1056 | /** | |
1057 | * Gets the width of a <CODE>String</CODE> in normalized 1000 units. | |
1058 | * | |
1059 | * @param text | |
1060 | * the <CODE>String</CODE> to get the width of | |
1061 | * @return the width in normalized 1000 units | |
1062 | */ | |
1063 | public int getWidth(String text) { | |
1064 | int total = 0; | |
1065 |
1
1. getWidth : negated conditional → NO_COVERAGE |
if (fastWinansi) { |
1066 | int len = text.length(); | |
1067 |
3
1. getWidth : changed conditional boundary → NO_COVERAGE 2. getWidth : Changed increment from 1 to -1 → NO_COVERAGE 3. getWidth : negated conditional → NO_COVERAGE |
for (int k = 0; k < len; ++k) { |
1068 | char char1 = text.charAt(k); | |
1069 |
6
1. getWidth : changed conditional boundary → NO_COVERAGE 2. getWidth : changed conditional boundary → NO_COVERAGE 3. getWidth : changed conditional boundary → NO_COVERAGE 4. getWidth : negated conditional → NO_COVERAGE 5. getWidth : negated conditional → NO_COVERAGE 6. getWidth : negated conditional → NO_COVERAGE |
if (char1 < 128 || char1 >= 160 && char1 <= 255) { |
1070 |
1
1. getWidth : Replaced integer addition with subtraction → NO_COVERAGE |
total += widths[char1]; |
1071 | } else { | |
1072 |
1
1. getWidth : Replaced integer addition with subtraction → NO_COVERAGE |
total += widths[PdfEncodings.winansi.get(char1)]; |
1073 | } | |
1074 | } | |
1075 |
1
1. getWidth : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return total; |
1076 | } else { | |
1077 | byte[] mbytes = convertToBytes(text); | |
1078 | for (byte mbyte : mbytes) { | |
1079 |
2
1. getWidth : Replaced bitwise AND with OR → NO_COVERAGE 2. getWidth : Replaced integer addition with subtraction → NO_COVERAGE |
total += widths[0xff & mbyte]; |
1080 | } | |
1081 | } | |
1082 |
1
1. getWidth : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return total; |
1083 | } | |
1084 | ||
1085 | /** | |
1086 | * Gets the descent of a <CODE>String</CODE> in normalized 1000 units. The | |
1087 | * descent will always be less than or equal to zero even if all the | |
1088 | * characters have an higher descent. | |
1089 | * | |
1090 | * @param text | |
1091 | * the <CODE>String</CODE> to get the descent of | |
1092 | * @return the descent in normalized 1000 units | |
1093 | */ | |
1094 | public int getDescent(String text) { | |
1095 | int min = 0; | |
1096 | char[] chars = text.toCharArray(); | |
1097 | for (char c : chars) { | |
1098 | int[] bbox = getCharBBox(c); | |
1099 |
3
1. getDescent : changed conditional boundary → NO_COVERAGE 2. getDescent : negated conditional → NO_COVERAGE 3. getDescent : negated conditional → NO_COVERAGE |
if (bbox != null && bbox[1] < min) { |
1100 | min = bbox[1]; | |
1101 | } | |
1102 | } | |
1103 |
1
1. getDescent : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return min; |
1104 | } | |
1105 | ||
1106 | /** | |
1107 | * Gets the ascent of a <CODE>String</CODE> in normalized 1000 units. The | |
1108 | * ascent will always be greater than or equal to zero even if all the | |
1109 | * characters have a lower ascent. | |
1110 | * | |
1111 | * @param text | |
1112 | * the <CODE>String</CODE> to get the ascent of | |
1113 | * @return the ascent in normalized 1000 units | |
1114 | */ | |
1115 | public int getAscent(String text) { | |
1116 | int max = 0; | |
1117 | char[] chars = text.toCharArray(); | |
1118 | for (char c : chars) { | |
1119 | int[] bbox = getCharBBox(c); | |
1120 |
3
1. getAscent : changed conditional boundary → NO_COVERAGE 2. getAscent : negated conditional → NO_COVERAGE 3. getAscent : negated conditional → NO_COVERAGE |
if (bbox != null && bbox[3] > max) { |
1121 | max = bbox[3]; | |
1122 | } | |
1123 | } | |
1124 |
1
1. getAscent : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return max; |
1125 | } | |
1126 | ||
1127 | /** | |
1128 | * Gets the descent of a <CODE>String</CODE> in points. The descent will | |
1129 | * always be less than or equal to zero even if all the characters have an | |
1130 | * higher descent. | |
1131 | * | |
1132 | * @param text | |
1133 | * the <CODE>String</CODE> to get the descent of | |
1134 | * @param fontSize | |
1135 | * the size of the font | |
1136 | * @return the descent in points | |
1137 | */ | |
1138 | public float getDescentPoint(String text, float fontSize) { | |
1139 |
3
1. getDescentPoint : Replaced float multiplication with division → NO_COVERAGE 2. getDescentPoint : Replaced float multiplication with division → NO_COVERAGE 3. getDescentPoint : replaced return of float value with -(x + 1) for com/lowagie/text/pdf/BaseFont::getDescentPoint → NO_COVERAGE |
return getDescent(text) * 0.001f * fontSize; |
1140 | } | |
1141 | ||
1142 | /** | |
1143 | * Gets the ascent of a <CODE>String</CODE> in points. The ascent will | |
1144 | * always be greater than or equal to zero even if all the characters have a | |
1145 | * lower ascent. | |
1146 | * | |
1147 | * @param text | |
1148 | * the <CODE>String</CODE> to get the ascent of | |
1149 | * @param fontSize | |
1150 | * the size of the font | |
1151 | * @return the ascent in points | |
1152 | */ | |
1153 | public float getAscentPoint(String text, float fontSize) { | |
1154 |
3
1. getAscentPoint : Replaced float multiplication with division → NO_COVERAGE 2. getAscentPoint : Replaced float multiplication with division → NO_COVERAGE 3. getAscentPoint : replaced return of float value with -(x + 1) for com/lowagie/text/pdf/BaseFont::getAscentPoint → NO_COVERAGE |
return getAscent(text) * 0.001f * fontSize; |
1155 | } | |
1156 | ||
1157 | // ia> | |
1158 | ||
1159 | /** | |
1160 | * Gets the width of a <CODE>String</CODE> in points taking kerning into | |
1161 | * account. | |
1162 | * | |
1163 | * @param text | |
1164 | * the <CODE>String</CODE> to get the width of | |
1165 | * @param fontSize | |
1166 | * the font size | |
1167 | * @return the width in points | |
1168 | */ | |
1169 | public float getWidthPointKerned(String text, float fontSize) { | |
1170 |
2
1. getWidthPointKerned : Replaced float multiplication with division → NO_COVERAGE 2. getWidthPointKerned : Replaced float multiplication with division → NO_COVERAGE |
float size = getWidth(text) * 0.001f * fontSize; |
1171 |
1
1. getWidthPointKerned : negated conditional → NO_COVERAGE |
if (!hasKernPairs()) { |
1172 |
1
1. getWidthPointKerned : replaced return of float value with -(x + 1) for com/lowagie/text/pdf/BaseFont::getWidthPointKerned → NO_COVERAGE |
return size; |
1173 | } | |
1174 |
1
1. getWidthPointKerned : Replaced integer subtraction with addition → NO_COVERAGE |
int len = text.length() - 1; |
1175 | int kern = 0; | |
1176 | char[] c = text.toCharArray(); | |
1177 |
3
1. getWidthPointKerned : changed conditional boundary → NO_COVERAGE 2. getWidthPointKerned : Changed increment from 1 to -1 → NO_COVERAGE 3. getWidthPointKerned : negated conditional → NO_COVERAGE |
for (int k = 0; k < len; ++k) { |
1178 |
2
1. getWidthPointKerned : Replaced integer addition with subtraction → NO_COVERAGE 2. getWidthPointKerned : Replaced integer addition with subtraction → NO_COVERAGE |
kern += getKerning(c[k], c[k + 1]); |
1179 | } | |
1180 |
4
1. getWidthPointKerned : Replaced float multiplication with division → NO_COVERAGE 2. getWidthPointKerned : Replaced float multiplication with division → NO_COVERAGE 3. getWidthPointKerned : Replaced float addition with subtraction → NO_COVERAGE 4. getWidthPointKerned : replaced return of float value with -(x + 1) for com/lowagie/text/pdf/BaseFont::getWidthPointKerned → NO_COVERAGE |
return size + kern * 0.001f * fontSize; |
1181 | } | |
1182 | ||
1183 | /** | |
1184 | * Gets the width of a <CODE>String</CODE> in points. | |
1185 | * | |
1186 | * @param text | |
1187 | * the <CODE>String</CODE> to get the width of | |
1188 | * @param fontSize | |
1189 | * the font size | |
1190 | * @return the width in points | |
1191 | */ | |
1192 | public float getWidthPoint(String text, float fontSize) { | |
1193 |
3
1. getWidthPoint : Replaced float multiplication with division → NO_COVERAGE 2. getWidthPoint : Replaced float multiplication with division → NO_COVERAGE 3. getWidthPoint : replaced return of float value with -(x + 1) for com/lowagie/text/pdf/BaseFont::getWidthPoint → NO_COVERAGE |
return getWidth(text) * 0.001f * fontSize; |
1194 | } | |
1195 | ||
1196 | /** | |
1197 | * Gets the width of a <CODE>char</CODE> in points. | |
1198 | * | |
1199 | * @param char1 | |
1200 | * the <CODE>char</CODE> to get the width of | |
1201 | * @param fontSize | |
1202 | * the font size | |
1203 | * @return the width in points | |
1204 | */ | |
1205 | public float getWidthPoint(int char1, float fontSize) { | |
1206 |
3
1. getWidthPoint : Replaced float multiplication with division → NO_COVERAGE 2. getWidthPoint : Replaced float multiplication with division → NO_COVERAGE 3. getWidthPoint : replaced return of float value with -(x + 1) for com/lowagie/text/pdf/BaseFont::getWidthPoint → NO_COVERAGE |
return getWidth(char1) * 0.001f * fontSize; |
1207 | } | |
1208 | ||
1209 | /** | |
1210 | * Converts a <CODE>String</CODE> to a </CODE>byte</CODE> array according to | |
1211 | * the font's encoding. | |
1212 | * | |
1213 | * @param text | |
1214 | * the <CODE>String</CODE> to be converted | |
1215 | * @return an array of <CODE>byte</CODE> representing the conversion | |
1216 | * according to the font's encoding | |
1217 | */ | |
1218 | byte[] convertToBytes(String text) { | |
1219 |
1
1. convertToBytes : negated conditional → NO_COVERAGE |
if (directTextToByte) { |
1220 |
1
1. convertToBytes : mutated return of Object value for com/lowagie/text/pdf/BaseFont::convertToBytes to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return PdfEncodings.convertToBytes(text, null); |
1221 | } | |
1222 |
1
1. convertToBytes : negated conditional → NO_COVERAGE |
if (specialMap != null) { |
1223 | byte[] b = new byte[text.length()]; | |
1224 | int ptr = 0; | |
1225 | int length = text.length(); | |
1226 |
3
1. convertToBytes : changed conditional boundary → NO_COVERAGE 2. convertToBytes : Changed increment from 1 to -1 → NO_COVERAGE 3. convertToBytes : negated conditional → NO_COVERAGE |
for (int k = 0; k < length; ++k) { |
1227 | char c = text.charAt(k); | |
1228 |
1
1. convertToBytes : negated conditional → NO_COVERAGE |
if (specialMap.containsKey(c)) { |
1229 |
1
1. convertToBytes : Changed increment from 1 to -1 → NO_COVERAGE |
b[ptr++] = (byte) specialMap.get(c); |
1230 | } | |
1231 | } | |
1232 |
2
1. convertToBytes : changed conditional boundary → NO_COVERAGE 2. convertToBytes : negated conditional → NO_COVERAGE |
if (ptr < length) { |
1233 | byte[] b2 = new byte[ptr]; | |
1234 |
1
1. convertToBytes : removed call to java/lang/System::arraycopy → NO_COVERAGE |
System.arraycopy(b, 0, b2, 0, ptr); |
1235 |
1
1. convertToBytes : mutated return of Object value for com/lowagie/text/pdf/BaseFont::convertToBytes to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return b2; |
1236 | } else { | |
1237 |
1
1. convertToBytes : mutated return of Object value for com/lowagie/text/pdf/BaseFont::convertToBytes to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return b; |
1238 | } | |
1239 | } | |
1240 |
1
1. convertToBytes : mutated return of Object value for com/lowagie/text/pdf/BaseFont::convertToBytes to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return PdfEncodings.convertToBytes(text, encoding); |
1241 | } | |
1242 | ||
1243 | /** | |
1244 | * Converts a <CODE>char</CODE> to a </CODE>byte</CODE> array according to | |
1245 | * the font's encoding. | |
1246 | * | |
1247 | * @param char1 | |
1248 | * the <CODE>char</CODE> to be converted | |
1249 | * @return an array of <CODE>byte</CODE> representing the conversion | |
1250 | * according to the font's encoding | |
1251 | */ | |
1252 | byte[] convertToBytes(int char1) { | |
1253 |
1
1. convertToBytes : negated conditional → NO_COVERAGE |
if (directTextToByte) { |
1254 |
1
1. convertToBytes : mutated return of Object value for com/lowagie/text/pdf/BaseFont::convertToBytes to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return PdfEncodings.convertToBytes((char) char1, null); |
1255 | } | |
1256 |
1
1. convertToBytes : negated conditional → NO_COVERAGE |
if (specialMap != null) { |
1257 |
1
1. convertToBytes : negated conditional → NO_COVERAGE |
if (specialMap.containsKey(char1)) { |
1258 |
1
1. convertToBytes : mutated return of Object value for com/lowagie/text/pdf/BaseFont::convertToBytes to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return new byte[] { (byte) specialMap.get(char1) }; |
1259 | } else { | |
1260 |
1
1. convertToBytes : mutated return of Object value for com/lowagie/text/pdf/BaseFont::convertToBytes to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return new byte[0]; |
1261 | } | |
1262 | } | |
1263 |
1
1. convertToBytes : mutated return of Object value for com/lowagie/text/pdf/BaseFont::convertToBytes to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return PdfEncodings.convertToBytes((char) char1, encoding); |
1264 | } | |
1265 | ||
1266 | /** | |
1267 | * Outputs to the writer the font dictionaries and streams. | |
1268 | * | |
1269 | * @param writer | |
1270 | * the writer for this document | |
1271 | * @param ref | |
1272 | * the font indirect reference | |
1273 | * @param params | |
1274 | * several parameters that depend on the font type | |
1275 | * @throws IOException | |
1276 | * on error | |
1277 | * @throws DocumentException | |
1278 | * error in generating the object | |
1279 | */ | |
1280 | abstract void writeFont(PdfWriter writer, PdfIndirectReference ref, | |
1281 | Object[] params) throws DocumentException, IOException; | |
1282 | ||
1283 | /** | |
1284 | * Returns a PdfStream object with the full font program (if possible). This | |
1285 | * method will return null for some types of fonts (CJKFont, Type3Font) or | |
1286 | * if there is no font program available (standard Type 1 fonts). | |
1287 | * | |
1288 | * @return a PdfStream with the font program | |
1289 | * @since 2.1.3 | |
1290 | */ | |
1291 | abstract PdfStream getFullFontStream() throws IOException, | |
1292 | DocumentException; | |
1293 | ||
1294 | /** | |
1295 | * Gets the encoding used to convert <CODE>String</CODE> into | |
1296 | * <CODE>byte[]</CODE>. | |
1297 | * | |
1298 | * @return the encoding name | |
1299 | */ | |
1300 | public String getEncoding() { | |
1301 | return encoding; | |
1302 | } | |
1303 | ||
1304 | /** | |
1305 | * Gets the font parameter identified by <CODE>key</CODE>. Valid values for | |
1306 | * <CODE>key</CODE> are <CODE>ASCENT</CODE>, <CODE>AWT_ASCENT</CODE>, | |
1307 | * <CODE>CAPHEIGHT</CODE>, <CODE>DESCENT</CODE>, <CODE>AWT_DESCENT</CODE>, | |
1308 | * <CODE>ITALICANGLE</CODE>, <CODE>BBOXLLX</CODE>, <CODE>BBOXLLY</CODE>, | |
1309 | * <CODE>BBOXURX</CODE> and <CODE>BBOXURY</CODE>. | |
1310 | * | |
1311 | * @param key | |
1312 | * the parameter to be extracted | |
1313 | * @param fontSize | |
1314 | * the font size in points | |
1315 | * @return the parameter in points | |
1316 | */ | |
1317 | public abstract float getFontDescriptor(int key, float fontSize); | |
1318 | ||
1319 | /** | |
1320 | * Gets the font type. The font types can be: FONT_TYPE_T1, FONT_TYPE_TT, | |
1321 | * FONT_TYPE_CJK and FONT_TYPE_TTUNI. | |
1322 | * | |
1323 | * @return the font type | |
1324 | */ | |
1325 | public int getFontType() { | |
1326 | return fontType; | |
1327 | } | |
1328 | ||
1329 | /** | |
1330 | * Gets the embedded flag. | |
1331 | * | |
1332 | * @return <CODE>true</CODE> if the font is embedded. | |
1333 | */ | |
1334 | public boolean isEmbedded() { | |
1335 | return embedded; | |
1336 | } | |
1337 | ||
1338 | /** | |
1339 | * Gets the symbolic flag of the font. | |
1340 | * | |
1341 | * @return <CODE>true</CODE> if the font is symbolic | |
1342 | */ | |
1343 | public boolean isFontSpecific() { | |
1344 | return fontSpecific; | |
1345 | } | |
1346 | ||
1347 | /** | |
1348 | * Creates a unique subset prefix to be added to the font name when the font | |
1349 | * is embedded and subset. | |
1350 | * | |
1351 | * @return the subset prefix | |
1352 | */ | |
1353 | public static String createSubsetPrefix() { | |
1354 | String s = ""; | |
1355 |
2
1. createSubsetPrefix : changed conditional boundary → NO_COVERAGE 2. createSubsetPrefix : negated conditional → NO_COVERAGE |
for (int k = 0; k < 6; ++k) { |
1356 |
2
1. createSubsetPrefix : Replaced double multiplication with division → NO_COVERAGE 2. createSubsetPrefix : Replaced double addition with subtraction → NO_COVERAGE |
s += (char) (Math.random() * 26 + 'A'); |
1357 | } | |
1358 |
1
1. createSubsetPrefix : mutated return of Object value for com/lowagie/text/pdf/BaseFont::createSubsetPrefix to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return s + "+"; |
1359 | } | |
1360 | ||
1361 | /** | |
1362 | * Gets the Unicode character corresponding to the byte output to the pdf | |
1363 | * stream. | |
1364 | * | |
1365 | * @param index | |
1366 | * the byte index | |
1367 | * @return the Unicode character | |
1368 | */ | |
1369 | char getUnicodeDifferences(int index) { | |
1370 |
1
1. getUnicodeDifferences : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return unicodeDifferences[index]; |
1371 | } | |
1372 | ||
1373 | /** | |
1374 | * Gets the postscript font name. | |
1375 | * | |
1376 | * @return the postscript font name | |
1377 | */ | |
1378 | public abstract String getPostscriptFontName(); | |
1379 | ||
1380 | /** | |
1381 | * Sets the font name that will appear in the pdf font dictionary. Use with | |
1382 | * care as it can easily make a font unreadable if not embedded. | |
1383 | * | |
1384 | * @param name | |
1385 | * the new font name | |
1386 | */ | |
1387 | public abstract void setPostscriptFontName(String name); | |
1388 | ||
1389 | /** | |
1390 | * Gets the full name of the font. If it is a True Type font each array | |
1391 | * element will have {Platform ID, Platform Encoding ID, Language ID, font | |
1392 | * name}. The interpretation of this values can be found in the Open Type | |
1393 | * specification, chapter 2, in the 'name' table.<br> | |
1394 | * For the other fonts the array has a single element with {"", "", "", font | |
1395 | * name}. | |
1396 | * | |
1397 | * @return the full name of the font | |
1398 | */ | |
1399 | public abstract String[][] getFullFontName(); | |
1400 | ||
1401 | /** | |
1402 | * Gets all the entries of the names-table. If it is a True Type font each | |
1403 | * array element will have {Name ID, Platform ID, Platform Encoding ID, | |
1404 | * Language ID, font name}. The interpretation of this values can be found | |
1405 | * in the Open Type specification, chapter 2, in the 'name' table.<br> | |
1406 | * For the other fonts the array has a single element with {"4", "", "", "", | |
1407 | * font name}. | |
1408 | * | |
1409 | * @return the full name of the font | |
1410 | * @since 2.0.8 | |
1411 | */ | |
1412 | public abstract String[][] getAllNameEntries(); | |
1413 | ||
1414 | /** | |
1415 | * Gets the full name of the font. If it is a True Type font each array | |
1416 | * element will have {Platform ID, Platform Encoding ID, Language ID, font | |
1417 | * name}. The interpretation of this values can be found in the Open Type | |
1418 | * specification, chapter 2, in the 'name' table.<br> | |
1419 | * For the other fonts the array has a single element with {"", "", "", font | |
1420 | * name}. | |
1421 | * | |
1422 | * @param name | |
1423 | * the name of the font | |
1424 | * @param encoding | |
1425 | * the encoding of the font | |
1426 | * @param ttfAfm | |
1427 | * the true type font or the afm in a byte array | |
1428 | * @throws DocumentException | |
1429 | * on error | |
1430 | * @throws IOException | |
1431 | * on error | |
1432 | * @return the full name of the font | |
1433 | */ | |
1434 | public static String[][] getFullFontName(String name, String encoding, | |
1435 | byte[] ttfAfm) throws DocumentException, IOException { | |
1436 | String nameBase = getBaseName(name); | |
1437 | BaseFont fontBuilt = null; | |
1438 |
1
1. getFullFontName : negated conditional → NO_COVERAGE |
if (nameBase.toLowerCase().endsWith(".ttf") |
1439 |
1
1. getFullFontName : negated conditional → NO_COVERAGE |
|| nameBase.toLowerCase().endsWith(".otf") |
1440 |
2
1. getFullFontName : changed conditional boundary → NO_COVERAGE 2. getFullFontName : negated conditional → NO_COVERAGE |
|| nameBase.toLowerCase().indexOf(".ttc,") > 0) { |
1441 | fontBuilt = new TrueTypeFont(name, CP1252, false, ttfAfm, true, | |
1442 | false); | |
1443 | } else { | |
1444 | fontBuilt = createFont(name, encoding, false, false, ttfAfm, null); | |
1445 | } | |
1446 |
1
1. getFullFontName : mutated return of Object value for com/lowagie/text/pdf/BaseFont::getFullFontName to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return fontBuilt.getFullFontName(); |
1447 | } | |
1448 | ||
1449 | /** | |
1450 | * Gets all the names from the font. Only the required tables are read. | |
1451 | * | |
1452 | * @param name | |
1453 | * the name of the font | |
1454 | * @param encoding | |
1455 | * the encoding of the font | |
1456 | * @param ttfAfm | |
1457 | * the true type font or the afm in a byte array | |
1458 | * @throws DocumentException | |
1459 | * on error | |
1460 | * @throws IOException | |
1461 | * on error | |
1462 | * @return an array of Object[] built with {getPostscriptFontName(), | |
1463 | * getFamilyFontName(), getFullFontName()} | |
1464 | */ | |
1465 | public static Object[] getAllFontNames(String name, String encoding, | |
1466 | byte[] ttfAfm) throws DocumentException, IOException { | |
1467 | String nameBase = getBaseName(name); | |
1468 | BaseFont fontBuilt = null; | |
1469 |
1
1. getAllFontNames : negated conditional → NO_COVERAGE |
if (nameBase.toLowerCase().endsWith(".ttf") |
1470 |
1
1. getAllFontNames : negated conditional → NO_COVERAGE |
|| nameBase.toLowerCase().endsWith(".otf") |
1471 |
2
1. getAllFontNames : changed conditional boundary → NO_COVERAGE 2. getAllFontNames : negated conditional → NO_COVERAGE |
|| nameBase.toLowerCase().indexOf(".ttc,") > 0) { |
1472 | fontBuilt = new TrueTypeFont(name, CP1252, false, ttfAfm, true, | |
1473 | false); | |
1474 | } else { | |
1475 | fontBuilt = createFont(name, encoding, false, false, ttfAfm, null); | |
1476 | } | |
1477 |
1
1. getAllFontNames : mutated return of Object value for com/lowagie/text/pdf/BaseFont::getAllFontNames to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return new Object[] { fontBuilt.getPostscriptFontName(), |
1478 | fontBuilt.getFamilyFontName(), fontBuilt.getFullFontName() }; | |
1479 | } | |
1480 | ||
1481 | /** | |
1482 | * Gets all the entries of the namestable from the font. Only the required | |
1483 | * tables are read. | |
1484 | * | |
1485 | * @param name | |
1486 | * the name of the font | |
1487 | * @param encoding | |
1488 | * the encoding of the font | |
1489 | * @param ttfAfm | |
1490 | * the true type font or the afm in a byte array | |
1491 | * @throws DocumentException | |
1492 | * on error | |
1493 | * @throws IOException | |
1494 | * on error | |
1495 | * @return an array of Object[] built with {getPostscriptFontName(), | |
1496 | * getFamilyFontName(), getFullFontName()} | |
1497 | * @since 2.0.8 | |
1498 | */ | |
1499 | public static String[][] getAllNameEntries(String name, String encoding, | |
1500 | byte[] ttfAfm) throws DocumentException, IOException { | |
1501 | String nameBase = getBaseName(name); | |
1502 | BaseFont fontBuilt = null; | |
1503 |
1
1. getAllNameEntries : negated conditional → NO_COVERAGE |
if (nameBase.toLowerCase().endsWith(".ttf") |
1504 |
1
1. getAllNameEntries : negated conditional → NO_COVERAGE |
|| nameBase.toLowerCase().endsWith(".otf") |
1505 |
2
1. getAllNameEntries : changed conditional boundary → NO_COVERAGE 2. getAllNameEntries : negated conditional → NO_COVERAGE |
|| nameBase.toLowerCase().indexOf(".ttc,") > 0) { |
1506 | fontBuilt = new TrueTypeFont(name, CP1252, false, ttfAfm, true, | |
1507 | false); | |
1508 | } else { | |
1509 | fontBuilt = createFont(name, encoding, false, false, ttfAfm, null); | |
1510 | } | |
1511 |
1
1. getAllNameEntries : mutated return of Object value for com/lowagie/text/pdf/BaseFont::getAllNameEntries to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return fontBuilt.getAllNameEntries(); |
1512 | } | |
1513 | ||
1514 | /** | |
1515 | * Gets the family name of the font. If it is a True Type font each array | |
1516 | * element will have {Platform ID, Platform Encoding ID, Language ID, font | |
1517 | * name}. The interpretation of this values can be found in the Open Type | |
1518 | * specification, chapter 2, in the 'name' table.<br> | |
1519 | * For the other fonts the array has a single element with {"", "", "", font | |
1520 | * name}. | |
1521 | * | |
1522 | * @return the family name of the font | |
1523 | */ | |
1524 | public abstract String[][] getFamilyFontName(); | |
1525 | ||
1526 | /** | |
1527 | * Gets the code pages supported by the font. This has only meaning with | |
1528 | * True Type fonts. | |
1529 | * | |
1530 | * @return the code pages supported by the font | |
1531 | */ | |
1532 | public String[] getCodePagesSupported() { | |
1533 | return new String[0]; | |
1534 | } | |
1535 | ||
1536 | /** | |
1537 | * Enumerates the postscript font names present inside a True Type | |
1538 | * Collection. | |
1539 | * | |
1540 | * @param ttcFile | |
1541 | * the file name of the font | |
1542 | * @throws DocumentException | |
1543 | * on error | |
1544 | * @throws IOException | |
1545 | * on error | |
1546 | * @return the postscript font names | |
1547 | */ | |
1548 | public static String[] enumerateTTCNames(String ttcFile) | |
1549 | throws DocumentException, IOException { | |
1550 |
1
1. enumerateTTCNames : mutated return of Object value for com/lowagie/text/pdf/BaseFont::enumerateTTCNames to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return new EnumerateTTC(ttcFile).getNames(); |
1551 | } | |
1552 | ||
1553 | /** | |
1554 | * Enumerates the postscript font names present inside a True Type | |
1555 | * Collection. | |
1556 | * | |
1557 | * @param ttcArray | |
1558 | * the font as a <CODE>byte</CODE> array | |
1559 | * @throws DocumentException | |
1560 | * on error | |
1561 | * @throws IOException | |
1562 | * on error | |
1563 | * @return the postscript font names | |
1564 | */ | |
1565 | public static String[] enumerateTTCNames(byte[] ttcArray) | |
1566 | throws DocumentException, IOException { | |
1567 |
1
1. enumerateTTCNames : mutated return of Object value for com/lowagie/text/pdf/BaseFont::enumerateTTCNames to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return new EnumerateTTC(ttcArray).getNames(); |
1568 | } | |
1569 | ||
1570 | /** | |
1571 | * Gets the font width array. | |
1572 | * | |
1573 | * @return the font width array | |
1574 | */ | |
1575 | public int[] getWidths() { | |
1576 | return widths; | |
1577 | } | |
1578 | ||
1579 | /** | |
1580 | * Gets the array with the names of the characters. | |
1581 | * | |
1582 | * @return the array with the names of the characters | |
1583 | */ | |
1584 | public String[] getDifferences() { | |
1585 | return differences; | |
1586 | } | |
1587 | ||
1588 | /** | |
1589 | * Gets the array with the unicode characters. | |
1590 | * | |
1591 | * @return the array with the unicode characters | |
1592 | */ | |
1593 | public char[] getUnicodeDifferences() { | |
1594 | return unicodeDifferences; | |
1595 | } | |
1596 | ||
1597 | /** | |
1598 | * Gets the state of the property. | |
1599 | * | |
1600 | * @return value of property forceWidthsOutput | |
1601 | */ | |
1602 | public boolean isForceWidthsOutput() { | |
1603 | return forceWidthsOutput; | |
1604 | } | |
1605 | ||
1606 | /** | |
1607 | * Set to <CODE>true</CODE> to force the generation of the widths array. | |
1608 | * | |
1609 | * @param forceWidthsOutput | |
1610 | * <CODE>true</CODE> to force the generation of the widths array | |
1611 | */ | |
1612 | public void setForceWidthsOutput(boolean forceWidthsOutput) { | |
1613 | this.forceWidthsOutput = forceWidthsOutput; | |
1614 | } | |
1615 | ||
1616 | /** | |
1617 | * Gets the direct conversion of <CODE>char</CODE> to <CODE>byte</CODE>. | |
1618 | * | |
1619 | * @return value of property directTextToByte. | |
1620 | * @see #setDirectTextToByte(boolean directTextToByte) | |
1621 | */ | |
1622 | public boolean isDirectTextToByte() { | |
1623 | return directTextToByte; | |
1624 | } | |
1625 | ||
1626 | /** | |
1627 | * Sets the conversion of <CODE>char</CODE> directly to <CODE>byte</CODE> by | |
1628 | * casting. This is a low level feature to put the bytes directly in the | |
1629 | * content stream without passing through String.getBytes(). | |
1630 | * | |
1631 | * @param directTextToByte | |
1632 | * New value of property directTextToByte. | |
1633 | */ | |
1634 | public void setDirectTextToByte(boolean directTextToByte) { | |
1635 | this.directTextToByte = directTextToByte; | |
1636 | } | |
1637 | ||
1638 | /** | |
1639 | * Indicates if all the glyphs and widths for that particular encoding | |
1640 | * should be included in the document. | |
1641 | * | |
1642 | * @return <CODE>false</CODE> to include all the glyphs and widths. | |
1643 | */ | |
1644 | public boolean isSubset() { | |
1645 | return subset; | |
1646 | } | |
1647 | ||
1648 | /** | |
1649 | * Indicates if all the glyphs and widths for that particular encoding | |
1650 | * should be included in the document. When set to <CODE>true</CODE> only | |
1651 | * the glyphs used will be included in the font. When set to | |
1652 | * <CODE>false</CODE> and {@link #addSubsetRange(int[])} was not called the | |
1653 | * full font will be included otherwise just the characters ranges will be | |
1654 | * included. | |
1655 | * | |
1656 | * @param subset | |
1657 | * new value of property subset | |
1658 | */ | |
1659 | public void setSubset(boolean subset) { | |
1660 | this.subset = subset; | |
1661 | } | |
1662 | ||
1663 | /** | |
1664 | * Gets the font resources. | |
1665 | * | |
1666 | * @param key | |
1667 | * the full name of the resource | |
1668 | * @return the <CODE>InputStream</CODE> to get the resource or | |
1669 | * <CODE>null</CODE> if not found | |
1670 | */ | |
1671 | public static InputStream getResourceStream(String key) { | |
1672 |
1
1. getResourceStream : mutated return of Object value for com/lowagie/text/pdf/BaseFont::getResourceStream to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return getResourceStream(key, null); |
1673 | } | |
1674 | ||
1675 | /** | |
1676 | * Gets the font resources. | |
1677 | * | |
1678 | * @param key | |
1679 | * the full name of the resource | |
1680 | * @param loader | |
1681 | * the ClassLoader to load the resource or null to try the ones | |
1682 | * available | |
1683 | * @return the <CODE>InputStream</CODE> to get the resource or | |
1684 | * <CODE>null</CODE> if not found | |
1685 | */ | |
1686 | public static InputStream getResourceStream(String key, ClassLoader loader) { | |
1687 |
1
1. getResourceStream : negated conditional → NO_COVERAGE |
if (key.startsWith("/")) { |
1688 | key = key.substring(1); | |
1689 | } | |
1690 | InputStream is = null; | |
1691 |
1
1. getResourceStream : negated conditional → NO_COVERAGE |
if (loader != null) { |
1692 | is = loader.getResourceAsStream(key); | |
1693 |
1
1. getResourceStream : negated conditional → NO_COVERAGE |
if (is != null) { |
1694 |
1
1. getResourceStream : mutated return of Object value for com/lowagie/text/pdf/BaseFont::getResourceStream to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return is; |
1695 | } | |
1696 | } | |
1697 | // Try to use Context Class Loader to load the properties file. | |
1698 | try { | |
1699 | ClassLoader contextClassLoader = Thread.currentThread() | |
1700 | .getContextClassLoader(); | |
1701 |
1
1. getResourceStream : negated conditional → NO_COVERAGE |
if (contextClassLoader != null) { |
1702 | is = contextClassLoader.getResourceAsStream(key); | |
1703 | } | |
1704 | } catch (Throwable e) { | |
1705 | } | |
1706 | ||
1707 |
1
1. getResourceStream : negated conditional → NO_COVERAGE |
if (is == null) { |
1708 | is = BaseFont.class.getResourceAsStream("/" + key); | |
1709 | } | |
1710 |
1
1. getResourceStream : negated conditional → NO_COVERAGE |
if (is == null) { |
1711 | is = ClassLoader.getSystemResourceAsStream(key); | |
1712 | } | |
1713 |
1
1. getResourceStream : mutated return of Object value for com/lowagie/text/pdf/BaseFont::getResourceStream to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return is; |
1714 | } | |
1715 | ||
1716 | /** | |
1717 | * Gets the Unicode equivalent to a CID. The (inexistent) CID <FF00> is | |
1718 | * translated as '\n'. It has only meaning with CJK fonts with Identity | |
1719 | * encoding. | |
1720 | * | |
1721 | * @param c | |
1722 | * the CID code | |
1723 | * @return the Unicode equivalent | |
1724 | */ | |
1725 | public int getUnicodeEquivalent(int c) { | |
1726 |
1
1. getUnicodeEquivalent : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return c; |
1727 | } | |
1728 | ||
1729 | /** | |
1730 | * Gets the CID code given an Unicode. It has only meaning with CJK fonts. | |
1731 | * | |
1732 | * @param c | |
1733 | * the Unicode | |
1734 | * @return the CID equivalent | |
1735 | */ | |
1736 | public int getCidCode(int c) { | |
1737 |
1
1. getCidCode : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return c; |
1738 | } | |
1739 | ||
1740 | /** | |
1741 | * Checks if the font has any kerning pairs. | |
1742 | * | |
1743 | * @return <CODE>true</CODE> if the font has any kerning pairs | |
1744 | */ | |
1745 | public abstract boolean hasKernPairs(); | |
1746 | ||
1747 | /** | |
1748 | * Checks if a character exists in this font. | |
1749 | * | |
1750 | * @param c | |
1751 | * the character to check | |
1752 | * @return <CODE>true</CODE> if the character has a glyph, | |
1753 | * <CODE>false</CODE> otherwise | |
1754 | */ | |
1755 | public boolean charExists(int c) { | |
1756 | byte[] b = convertToBytes(c); | |
1757 |
3
1. charExists : changed conditional boundary → NO_COVERAGE 2. charExists : negated conditional → NO_COVERAGE 3. charExists : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return b.length > 0; |
1758 | } | |
1759 | ||
1760 | /** | |
1761 | * Sets the character advance. | |
1762 | * | |
1763 | * @param c | |
1764 | * the character | |
1765 | * @param advance | |
1766 | * the character advance normalized to 1000 units | |
1767 | * @return <CODE>true</CODE> if the advance was set, <CODE>false</CODE> | |
1768 | * otherwise | |
1769 | */ | |
1770 | public boolean setCharAdvance(int c, int advance) { | |
1771 | byte[] b = convertToBytes(c); | |
1772 |
1
1. setCharAdvance : negated conditional → NO_COVERAGE |
if (b.length == 0) { |
1773 |
1
1. setCharAdvance : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return false; |
1774 | } | |
1775 |
1
1. setCharAdvance : Replaced bitwise AND with OR → NO_COVERAGE |
widths[0xff & b[0]] = advance; |
1776 |
1
1. setCharAdvance : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return true; |
1777 | } | |
1778 | ||
1779 | private static void addFont(PRIndirectReference fontRef, IntHashtable hits, | |
1780 | ArrayList<Object[]> fonts) { | |
1781 | PdfObject obj = PdfReader.getPdfObject(fontRef); | |
1782 |
2
1. addFont : negated conditional → NO_COVERAGE 2. addFont : negated conditional → NO_COVERAGE |
if (obj == null || !obj.isDictionary()) { |
1783 | return; | |
1784 | } | |
1785 | PdfDictionary font = (PdfDictionary) obj; | |
1786 | PdfName subtype = font.getAsName(PdfName.SUBTYPE); | |
1787 |
2
1. addFont : negated conditional → NO_COVERAGE 2. addFont : negated conditional → NO_COVERAGE |
if (!PdfName.TYPE1.equals(subtype) && !PdfName.TRUETYPE.equals(subtype)) { |
1788 | return; | |
1789 | } | |
1790 | PdfName name = font.getAsName(PdfName.BASEFONT); | |
1791 | fonts.add(new Object[] { PdfName.decodeName(name.toString()), fontRef }); | |
1792 | hits.put(fontRef.getNumber(), 1); | |
1793 | } | |
1794 | ||
1795 | private static void recourseFonts(PdfDictionary page, IntHashtable hits, | |
1796 | ArrayList<Object[]> fonts, int level) { | |
1797 |
1
1. recourseFonts : Changed increment from 1 to -1 → NO_COVERAGE |
++level; |
1798 |
2
1. recourseFonts : changed conditional boundary → NO_COVERAGE 2. recourseFonts : negated conditional → NO_COVERAGE |
if (level > 50) { |
1799 | return; | |
1800 | } | |
1801 | PdfDictionary resources = page.getAsDict(PdfName.RESOURCES); | |
1802 |
1
1. recourseFonts : negated conditional → NO_COVERAGE |
if (resources == null) { |
1803 | return; | |
1804 | } | |
1805 | PdfDictionary font = resources.getAsDict(PdfName.FONT); | |
1806 |
1
1. recourseFonts : negated conditional → NO_COVERAGE |
if (font != null) { |
1807 | for (PdfName pdfName : font.getKeys()) { | |
1808 | PdfObject ft = font.get(pdfName); | |
1809 |
2
1. recourseFonts : negated conditional → NO_COVERAGE 2. recourseFonts : negated conditional → NO_COVERAGE |
if (ft == null || !ft.isIndirect()) { |
1810 | continue; | |
1811 | } | |
1812 | int hit = ((PRIndirectReference) ft).getNumber(); | |
1813 |
1
1. recourseFonts : negated conditional → NO_COVERAGE |
if (hits.containsKey(hit)) { |
1814 | continue; | |
1815 | } | |
1816 |
1
1. recourseFonts : removed call to com/lowagie/text/pdf/BaseFont::addFont → NO_COVERAGE |
addFont((PRIndirectReference) ft, hits, fonts); |
1817 | } | |
1818 | } | |
1819 | PdfDictionary xobj = resources.getAsDict(PdfName.XOBJECT); | |
1820 |
1
1. recourseFonts : negated conditional → NO_COVERAGE |
if (xobj != null) { |
1821 | for (PdfName pdfName : xobj.getKeys()) { | |
1822 |
1
1. recourseFonts : removed call to com/lowagie/text/pdf/BaseFont::recourseFonts → NO_COVERAGE |
recourseFonts(xobj.getAsDict(pdfName), hits, fonts, |
1823 | level); | |
1824 | } | |
1825 | } | |
1826 | } | |
1827 | ||
1828 | /** | |
1829 | * Gets a list of all document fonts. Each element of the | |
1830 | * <CODE>ArrayList</CODE> contains a | |
1831 | * <CODE>Object[]{String,PRIndirectReference}</CODE> with the font name and | |
1832 | * the indirect reference to it. | |
1833 | * | |
1834 | * @param reader | |
1835 | * the document where the fonts are to be listed from | |
1836 | * @return the list of fonts and references | |
1837 | */ | |
1838 | public static ArrayList<Object[]> getDocumentFonts(PdfReader reader) { | |
1839 | IntHashtable hits = new IntHashtable(); | |
1840 | ArrayList<Object[]> fonts = new ArrayList<>(); | |
1841 | int npages = reader.getNumberOfPages(); | |
1842 |
3
1. getDocumentFonts : changed conditional boundary → NO_COVERAGE 2. getDocumentFonts : Changed increment from 1 to -1 → NO_COVERAGE 3. getDocumentFonts : negated conditional → NO_COVERAGE |
for (int k = 1; k <= npages; ++k) { |
1843 |
1
1. getDocumentFonts : removed call to com/lowagie/text/pdf/BaseFont::recourseFonts → NO_COVERAGE |
recourseFonts(reader.getPageN(k), hits, fonts, 1); |
1844 | } | |
1845 |
1
1. getDocumentFonts : mutated return of Object value for com/lowagie/text/pdf/BaseFont::getDocumentFonts to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return fonts; |
1846 | } | |
1847 | ||
1848 | /** | |
1849 | * Gets a list of the document fonts in a particular page. Each element of | |
1850 | * the <CODE>ArrayList</CODE> contains a | |
1851 | * <CODE>Object[]{String,PRIndirectReference}</CODE> with the font name and | |
1852 | * the indirect reference to it. | |
1853 | * | |
1854 | * @param reader | |
1855 | * the document where the fonts are to be listed from | |
1856 | * @param page | |
1857 | * the page to list the fonts from | |
1858 | * @return the list of fonts and references | |
1859 | */ | |
1860 | public static ArrayList<Object[]> getDocumentFonts(PdfReader reader, | |
1861 | int page) { | |
1862 | IntHashtable hits = new IntHashtable(); | |
1863 | ArrayList<Object[]> fonts = new ArrayList<>(); | |
1864 |
1
1. getDocumentFonts : removed call to com/lowagie/text/pdf/BaseFont::recourseFonts → NO_COVERAGE |
recourseFonts(reader.getPageN(page), hits, fonts, 1); |
1865 |
1
1. getDocumentFonts : mutated return of Object value for com/lowagie/text/pdf/BaseFont::getDocumentFonts to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return fonts; |
1866 | } | |
1867 | ||
1868 | /** | |
1869 | * Gets the smallest box enclosing the character contours. It will return | |
1870 | * <CODE>null</CODE> if the font has not the information or the character | |
1871 | * has no contours, as in the case of the space, for example. Characters | |
1872 | * with no contours may also return [0,0,0,0]. | |
1873 | * | |
1874 | * @param c | |
1875 | * the character to get the contour bounding box from | |
1876 | * @return an array of four floats with the bounding box in the format | |
1877 | * [llx,lly,urx,ury] or <code>null</code> | |
1878 | */ | |
1879 | public int[] getCharBBox(int c) { | |
1880 | byte[] b = convertToBytes(c); | |
1881 |
1
1. getCharBBox : negated conditional → NO_COVERAGE |
if (b.length == 0) { |
1882 |
1
1. getCharBBox : mutated return of Object value for com/lowagie/text/pdf/BaseFont::getCharBBox to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return null; |
1883 | } else { | |
1884 |
2
1. getCharBBox : Replaced bitwise AND with OR → NO_COVERAGE 2. getCharBBox : mutated return of Object value for com/lowagie/text/pdf/BaseFont::getCharBBox to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return charBBoxes[b[0] & 0xff]; |
1885 | } | |
1886 | } | |
1887 | ||
1888 | protected abstract int[] getRawCharBBox(int c, String name); | |
1889 | ||
1890 | /** | |
1891 | * iText expects Arabic Diactrics (tashkeel) to have zero advance but some | |
1892 | * fonts, most notably those that come with Windows, like times.ttf, have | |
1893 | * non-zero advance for those characters. This method makes those character | |
1894 | * to have zero width advance and work correctly in the iText Arabic shaping | |
1895 | * and reordering context. | |
1896 | */ | |
1897 | public void correctArabicAdvance() { | |
1898 |
3
1. correctArabicAdvance : changed conditional boundary → NO_COVERAGE 2. correctArabicAdvance : Replaced integer addition with subtraction → NO_COVERAGE 3. correctArabicAdvance : negated conditional → NO_COVERAGE |
for (char c = '\u064b'; c <= '\u0658'; ++c) { |
1899 | setCharAdvance(c, 0); | |
1900 | } | |
1901 | setCharAdvance('\u0670', 0); | |
1902 |
3
1. correctArabicAdvance : changed conditional boundary → NO_COVERAGE 2. correctArabicAdvance : Replaced integer addition with subtraction → NO_COVERAGE 3. correctArabicAdvance : negated conditional → NO_COVERAGE |
for (char c = '\u06d6'; c <= '\u06dc'; ++c) { |
1903 | setCharAdvance(c, 0); | |
1904 | } | |
1905 |
3
1. correctArabicAdvance : changed conditional boundary → NO_COVERAGE 2. correctArabicAdvance : Replaced integer addition with subtraction → NO_COVERAGE 3. correctArabicAdvance : negated conditional → NO_COVERAGE |
for (char c = '\u06df'; c <= '\u06e4'; ++c) { |
1906 | setCharAdvance(c, 0); | |
1907 | } | |
1908 |
3
1. correctArabicAdvance : changed conditional boundary → NO_COVERAGE 2. correctArabicAdvance : Replaced integer addition with subtraction → NO_COVERAGE 3. correctArabicAdvance : negated conditional → NO_COVERAGE |
for (char c = '\u06e7'; c <= '\u06e8'; ++c) { |
1909 | setCharAdvance(c, 0); | |
1910 | } | |
1911 |
3
1. correctArabicAdvance : changed conditional boundary → NO_COVERAGE 2. correctArabicAdvance : Replaced integer addition with subtraction → NO_COVERAGE 3. correctArabicAdvance : negated conditional → NO_COVERAGE |
for (char c = '\u06ea'; c <= '\u06ed'; ++c) { |
1912 | setCharAdvance(c, 0); | |
1913 | } | |
1914 | } | |
1915 | ||
1916 | /** | |
1917 | * Adds a character range when subsetting. The range is an <CODE>int</CODE> | |
1918 | * array where the first element is the start range inclusive and the second | |
1919 | * element is the end range inclusive. Several ranges are allowed in the | |
1920 | * same array. | |
1921 | * | |
1922 | * @param range | |
1923 | * the character range | |
1924 | */ | |
1925 | public void addSubsetRange(int[] range) { | |
1926 |
1
1. addSubsetRange : negated conditional → NO_COVERAGE |
if (subsetRanges == null) { |
1927 | subsetRanges = new ArrayList<>(); | |
1928 | } | |
1929 | subsetRanges.add(range); | |
1930 | } | |
1931 | ||
1932 | /** | |
1933 | * Returns the compression level used for the font streams. | |
1934 | * | |
1935 | * @return the compression level (0 = best speed, 9 = best compression, -1 | |
1936 | * is default) | |
1937 | * @since 2.1.3 | |
1938 | */ | |
1939 | public int getCompressionLevel() { | |
1940 | return compressionLevel; | |
1941 | } | |
1942 | ||
1943 | /** | |
1944 | * Sets the compression level to be used for the font streams. | |
1945 | * | |
1946 | * @param compressionLevel | |
1947 | * a value between 0 (best speed) and 9 (best compression) | |
1948 | * @since 2.1.3 | |
1949 | */ | |
1950 | public void setCompressionLevel(int compressionLevel) { | |
1951 |
4
1. setCompressionLevel : changed conditional boundary → NO_COVERAGE 2. setCompressionLevel : changed conditional boundary → NO_COVERAGE 3. setCompressionLevel : negated conditional → NO_COVERAGE 4. setCompressionLevel : negated conditional → NO_COVERAGE |
if (compressionLevel < PdfStream.NO_COMPRESSION |
1952 | || compressionLevel > PdfStream.BEST_COMPRESSION) { | |
1953 | this.compressionLevel = PdfStream.DEFAULT_COMPRESSION; | |
1954 | } else { | |
1955 | this.compressionLevel = compressionLevel; | |
1956 | } | |
1957 | } | |
1958 | } | |
Mutations | ||
383 |
1.1 |
|
384 |
1.1 2.2 |
|
385 |
1.1 2.2 |
|
388 |
1.1 |
|
412 |
1.1 |
|
413 |
1.1 |
|
414 |
1.1 |
|
416 |
1.1 |
|
442 |
1.1 |
|
509 |
1.1 |
|
580 |
1.1 |
|
652 |
1.1 |
|
731 |
1.1 |
|
818 |
1.1 2.2 |
|
820 |
1.1 2.2 |
|
822 |
1.1 2.2 |
|
828 |
1.1 |
|
830 |
1.1 |
|
831 |
1.1 |
|
834 |
1.1 2.2 |
|
835 |
1.1 |
|
839 |
1.1 |
|
840 |
1.1 |
|
841 |
1.1 2.2 |
|
842 |
1.1 2.2 |
|
850 |
1.1 |
|
852 |
1.1 |
|
853 |
1.1 |
|
858 |
1.1 |
|
860 |
1.1 |
|
862 |
1.1 |
|
874 |
1.1 |
|
885 |
1.1 |
|
886 |
1.1 2.2 |
|
887 |
1.1 |
|
888 |
1.1 2.2 |
|
889 |
1.1 |
|
890 |
1.1 2.2 |
|
892 |
1.1 |
|
905 |
1.1 2.2 |
|
906 |
1.1 |
|
907 |
1.1 |
|
908 |
1.1 |
|
910 |
1.1 |
|
918 |
1.1 |
|
922 |
1.1 |
|
923 |
1.1 |
|
928 |
1.1 |
|
933 |
1.1 |
|
942 |
1.1 |
|
945 |
1.1 2.2 3.3 |
|
947 |
1.1 |
|
949 |
1.1 |
|
955 |
1.1 |
|
959 |
1.1 2.2 3.3 |
|
960 |
1.1 |
|
964 |
1.1 |
|
965 |
1.1 2.2 3.3 |
|
974 |
1.1 2.2 3.3 |
|
977 |
1.1 2.2 |
|
983 |
1.1 |
|
1040 |
1.1 |
|
1041 |
1.1 2.2 3.3 4.4 5.5 6.6 |
|
1042 |
1.1 |
|
1044 |
1.1 |
|
1050 |
1.1 2.2 |
|
1052 |
1.1 |
|
1065 |
1.1 |
|
1067 |
1.1 2.2 3.3 |
|
1069 |
1.1 2.2 3.3 4.4 5.5 6.6 |
|
1070 |
1.1 |
|
1072 |
1.1 |
|
1075 |
1.1 |
|
1079 |
1.1 2.2 |
|
1082 |
1.1 |
|
1099 |
1.1 2.2 3.3 |
|
1103 |
1.1 |
|
1120 |
1.1 2.2 3.3 |
|
1124 |
1.1 |
|
1139 |
1.1 2.2 3.3 |
|
1154 |
1.1 2.2 3.3 |
|
1170 |
1.1 2.2 |
|
1171 |
1.1 |
|
1172 |
1.1 |
|
1174 |
1.1 |
|
1177 |
1.1 2.2 3.3 |
|
1178 |
1.1 2.2 |
|
1180 |
1.1 2.2 3.3 4.4 |
|
1193 |
1.1 2.2 3.3 |
|
1206 |
1.1 2.2 3.3 |
|
1219 |
1.1 |
|
1220 |
1.1 |
|
1222 |
1.1 |
|
1226 |
1.1 2.2 3.3 |
|
1228 |
1.1 |
|
1229 |
1.1 |
|
1232 |
1.1 2.2 |
|
1234 |
1.1 |
|
1235 |
1.1 |
|
1237 |
1.1 |
|
1240 |
1.1 |
|
1253 |
1.1 |
|
1254 |
1.1 |
|
1256 |
1.1 |
|
1257 |
1.1 |
|
1258 |
1.1 |
|
1260 |
1.1 |
|
1263 |
1.1 |
|
1355 |
1.1 2.2 |
|
1356 |
1.1 2.2 |
|
1358 |
1.1 |
|
1370 |
1.1 |
|
1438 |
1.1 |
|
1439 |
1.1 |
|
1440 |
1.1 2.2 |
|
1446 |
1.1 |
|
1469 |
1.1 |
|
1470 |
1.1 |
|
1471 |
1.1 2.2 |
|
1477 |
1.1 |
|
1503 |
1.1 |
|
1504 |
1.1 |
|
1505 |
1.1 2.2 |
|
1511 |
1.1 |
|
1550 |
1.1 |
|
1567 |
1.1 |
|
1672 |
1.1 |
|
1687 |
1.1 |
|
1691 |
1.1 |
|
1693 |
1.1 |
|
1694 |
1.1 |
|
1701 |
1.1 |
|
1707 |
1.1 |
|
1710 |
1.1 |
|
1713 |
1.1 |
|
1726 |
1.1 |
|
1737 |
1.1 |
|
1757 |
1.1 2.2 3.3 |
|
1772 |
1.1 |
|
1773 |
1.1 |
|
1775 |
1.1 |
|
1776 |
1.1 |
|
1782 |
1.1 2.2 |
|
1787 |
1.1 2.2 |
|
1797 |
1.1 |
|
1798 |
1.1 2.2 |
|
1802 |
1.1 |
|
1806 |
1.1 |
|
1809 |
1.1 2.2 |
|
1813 |
1.1 |
|
1816 |
1.1 |
|
1820 |
1.1 |
|
1822 |
1.1 |
|
1842 |
1.1 2.2 3.3 |
|
1843 |
1.1 |
|
1845 |
1.1 |
|
1864 |
1.1 |
|
1865 |
1.1 |
|
1881 |
1.1 |
|
1882 |
1.1 |
|
1884 |
1.1 2.2 |
|
1898 |
1.1 2.2 3.3 |
|
1902 |
1.1 2.2 3.3 |
|
1905 |
1.1 2.2 3.3 |
|
1908 |
1.1 2.2 3.3 |
|
1911 |
1.1 2.2 3.3 |
|
1926 |
1.1 |
|
1951 |
1.1 2.2 3.3 4.4 |