1 | /* | |
2 | * $Id: Type1Font.java 4065 2009-09-16 23:09:11Z psoares33 $ | |
3 | * | |
4 | * Copyright 2001-2006 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 java.io.ByteArrayOutputStream; | |
53 | import java.io.IOException; | |
54 | import java.io.InputStream; | |
55 | import java.util.HashMap; | |
56 | import java.util.StringTokenizer; | |
57 | import com.lowagie.text.error_messages.MessageLocalization; | |
58 | ||
59 | import com.lowagie.text.Document; | |
60 | import com.lowagie.text.DocumentException; | |
61 | import com.lowagie.text.pdf.fonts.FontsResourceAnchor; | |
62 | ||
63 | /** Reads a Type1 font | |
64 | * | |
65 | * @author Paulo Soares (psoares@consiste.pt) | |
66 | */ | |
67 | class Type1Font extends BaseFont | |
68 | { | |
69 | private static FontsResourceAnchor resourceAnchor; | |
70 | ||
71 | /** | |
72 | * The PFB file if the input was made with a <CODE>byte</CODE> array. | |
73 | */ | |
74 | protected byte[] pfb; | |
75 | /** The Postscript font name. | |
76 | */ | |
77 | private String FontName; | |
78 | /** The full name of the font. | |
79 | */ | |
80 | private String FullName; | |
81 | /** The family name of the font. | |
82 | */ | |
83 | private String FamilyName; | |
84 | /** The weight of the font: normal, bold, etc. | |
85 | */ | |
86 | private String Weight = ""; | |
87 | /** The italic angle of the font, usually 0.0 or negative. | |
88 | */ | |
89 | private float ItalicAngle = 0.0f; | |
90 | /** <CODE>true</CODE> if all the characters have the same | |
91 | * width. | |
92 | */ | |
93 | private boolean IsFixedPitch = false; | |
94 | /** The character set of the font. | |
95 | */ | |
96 | private String CharacterSet; | |
97 | /** The llx of the FontBox. | |
98 | */ | |
99 | private int llx = -50; | |
100 | /** The lly of the FontBox. | |
101 | */ | |
102 | private int lly = -200; | |
103 | /** The lurx of the FontBox. | |
104 | */ | |
105 | private int urx = 1000; | |
106 | /** The ury of the FontBox. | |
107 | */ | |
108 | private int ury = 900; | |
109 | /** The underline position. | |
110 | */ | |
111 | private int UnderlinePosition = -100; | |
112 | /** The underline thickness. | |
113 | */ | |
114 | private int UnderlineThickness = 50; | |
115 | /** The font's encoding name. This encoding is 'StandardEncoding' or | |
116 | * 'AdobeStandardEncoding' for a font that can be totally encoded | |
117 | * according to the characters names. For all other names the | |
118 | * font is treated as symbolic. | |
119 | */ | |
120 | private String EncodingScheme = "FontSpecific"; | |
121 | /** A variable. | |
122 | */ | |
123 | private int CapHeight = 700; | |
124 | /** A variable. | |
125 | */ | |
126 | private int XHeight = 480; | |
127 | /** A variable. | |
128 | */ | |
129 | private int Ascender = 800; | |
130 | /** A variable. | |
131 | */ | |
132 | private int Descender = -200; | |
133 | /** A variable. | |
134 | */ | |
135 | private int StdHW; | |
136 | /** A variable. | |
137 | */ | |
138 | private int StdVW = 80; | |
139 | | |
140 | /** Represents the section CharMetrics in the AFM file. Each | |
141 | * value of this array contains a <CODE>Object[4]</CODE> with an | |
142 | * Integer, Integer, String and int[]. This is the code, width, name and char bbox. | |
143 | * The key is the name of the char and also an Integer with the char number. | |
144 | */ | |
145 | private HashMap CharMetrics = new HashMap(); | |
146 | /** Represents the section KernPairs in the AFM file. The key is | |
147 | * the name of the first character and the value is a <CODE>Object[]</CODE> | |
148 | * with 2 elements for each kern pair. Position 0 is the name of | |
149 | * the second character and position 1 is the kerning distance. This is | |
150 | * repeated for all the pairs. | |
151 | */ | |
152 | private HashMap KernPairs = new HashMap(); | |
153 | /** The file in use. | |
154 | */ | |
155 | private String fileName; | |
156 | /** <CODE>true</CODE> if this font is one of the 14 built in fonts. | |
157 | */ | |
158 | private boolean builtinFont = false; | |
159 | /** | |
160 | * Types of records in a PFB file. ASCII is 1 and BINARY is 2. | |
161 | * They have to appear in the PFB file in this sequence. | |
162 | */ | |
163 | private static final int[] PFB_TYPES = {1, 2, 1}; | |
164 | | |
165 | /** Creates a new Type1 font. | |
166 | * @param ttfAfm the AFM file if the input is made with a <CODE>byte</CODE> array | |
167 | * @param pfb the PFB file if the input is made with a <CODE>byte</CODE> array | |
168 | * @param afmFile the name of one of the 14 built-in fonts or the location of an AFM file. The file must end in '.afm' | |
169 | * @param enc the encoding to be applied to this font | |
170 | * @param emb true if the font is to be embedded in the PDF | |
171 | * @throws DocumentException the AFM file is invalid | |
172 | * @throws IOException the AFM file could not be read | |
173 | * @since 2.1.5 | |
174 | */ | |
175 | Type1Font(String afmFile, String enc, boolean emb, byte[] ttfAfm, byte[] pfb, boolean forceRead) | |
176 | throws DocumentException, IOException { | |
177 |
3
1. 2. 3. |
if (emb && ttfAfm != null && pfb == null) |
178 | throw new DocumentException(MessageLocalization.getComposedMessage("two.byte.arrays.are.needed.if.the.type1.font.is.embedded")); | |
179 |
2
1. 2. |
if (emb && ttfAfm != null) |
180 | this.pfb = pfb; | |
181 | encoding = enc; | |
182 | embedded = emb; | |
183 | fileName = afmFile; | |
184 | fontType = FONT_TYPE_T1; | |
185 | RandomAccessFileOrArray rf = null; | |
186 | InputStream is = null; | |
187 |
1
1. |
if (BuiltinFonts14.containsKey(afmFile)) { |
188 | embedded = false; | |
189 | builtinFont = true; | |
190 | byte[] buf = new byte[1024]; | |
191 | try { | |
192 |
1
1. |
if (resourceAnchor == null) |
193 | resourceAnchor = new FontsResourceAnchor(); | |
194 | is = getResourceStream(RESOURCE_PATH + afmFile + ".afm", resourceAnchor.getClass().getClassLoader()); | |
195 |
1
1. |
if (is == null) { |
196 | String msg = MessageLocalization.getComposedMessage("1.not.found.as.resource", afmFile); | |
197 |
1
1. |
System.err.println(msg); |
198 | throw new DocumentException(msg); | |
199 | } | |
200 | ByteArrayOutputStream out = new ByteArrayOutputStream(); | |
201 | while (true) { | |
202 | int size = is.read(buf); | |
203 |
2
1. 2. |
if (size < 0) |
204 | break; | |
205 |
1
1. |
out.write(buf, 0, size); |
206 | } | |
207 | buf = out.toByteArray(); | |
208 | } | |
209 | finally { | |
210 |
1
1. |
if (is != null) { |
211 | try { | |
212 |
1
1. |
is.close(); |
213 | } | |
214 | catch (Exception e) { | |
215 | // empty on purpose | |
216 | } | |
217 | } | |
218 | } | |
219 | try { | |
220 | rf = new RandomAccessFileOrArray(buf); | |
221 |
1
1. |
process(rf); |
222 | } | |
223 | finally { | |
224 |
1
1. |
if (rf != null) { |
225 | try { | |
226 |
1
1. |
rf.close(); |
227 | } | |
228 | catch (Exception e) { | |
229 | // empty on purpose | |
230 | } | |
231 | } | |
232 | } | |
233 | } | |
234 |
1
1. |
else if (afmFile.toLowerCase().endsWith(".afm")) { |
235 | try { | |
236 |
1
1. |
if (ttfAfm == null) |
237 | rf = new RandomAccessFileOrArray(afmFile, forceRead, Document.plainRandomAccess); | |
238 | else | |
239 | rf = new RandomAccessFileOrArray(ttfAfm); | |
240 |
1
1. |
process(rf); |
241 | } | |
242 | finally { | |
243 |
1
1. |
if (rf != null) { |
244 | try { | |
245 |
1
1. |
rf.close(); |
246 | } | |
247 | catch (Exception e) { | |
248 | // empty on purpose | |
249 | } | |
250 | } | |
251 | } | |
252 | } | |
253 |
1
1. |
else if (afmFile.toLowerCase().endsWith(".pfm")) { |
254 | try { | |
255 | ByteArrayOutputStream ba = new ByteArrayOutputStream(); | |
256 |
1
1. |
if (ttfAfm == null) |
257 | rf = new RandomAccessFileOrArray(afmFile, forceRead, Document.plainRandomAccess); | |
258 | else | |
259 | rf = new RandomAccessFileOrArray(ttfAfm); | |
260 |
1
1. |
Pfm2afm.convert(rf, ba); |
261 |
1
1. |
rf.close(); |
262 | rf = new RandomAccessFileOrArray(ba.toByteArray()); | |
263 |
1
1. |
process(rf); |
264 | } | |
265 | finally { | |
266 |
1
1. |
if (rf != null) { |
267 | try { | |
268 |
1
1. |
rf.close(); |
269 | } | |
270 | catch (Exception e) { | |
271 | // empty on purpose | |
272 | } | |
273 | } | |
274 | } | |
275 | } | |
276 | else | |
277 | throw new DocumentException(MessageLocalization.getComposedMessage("1.is.not.an.afm.or.pfm.font.file", afmFile)); | |
278 | ||
279 | EncodingScheme = EncodingScheme.trim(); | |
280 |
2
1. 2. |
if (EncodingScheme.equals("AdobeStandardEncoding") || EncodingScheme.equals("StandardEncoding")) { |
281 | fontSpecific = false; | |
282 | } | |
283 |
1
1. |
if (!encoding.startsWith("#")) |
284 | PdfEncodings.convertToBytes(" ", enc); // check if the encoding exists | |
285 |
1
1. |
createEncoding(); |
286 | } | |
287 | | |
288 | /** Gets the width from the font according to the <CODE>name</CODE> or, | |
289 | * if the <CODE>name</CODE> is null, meaning it is a symbolic font, | |
290 | * the char <CODE>c</CODE>. | |
291 | * @param c the char if the font is symbolic | |
292 | * @param name the glyph name | |
293 | * @return the width of the char | |
294 | */ | |
295 | int getRawWidth(int c, String name) { | |
296 | Object[] metrics; | |
297 |
1
1. getRawWidth : negated conditional → NO_COVERAGE |
if (name == null) { // font specific |
298 | metrics = (Object[])CharMetrics.get(c); | |
299 | } | |
300 | else { | |
301 |
1
1. getRawWidth : negated conditional → NO_COVERAGE |
if (name.equals(".notdef")) |
302 |
1
1. getRawWidth : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return 0; |
303 | metrics = (Object[])CharMetrics.get(name); | |
304 | } | |
305 |
1
1. getRawWidth : negated conditional → NO_COVERAGE |
if (metrics != null) |
306 |
1
1. getRawWidth : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return (Integer) (metrics[1]); |
307 |
1
1. getRawWidth : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return 0; |
308 | } | |
309 | | |
310 | /** Gets the kerning between two Unicode characters. The characters | |
311 | * are converted to names and this names are used to find the kerning | |
312 | * pairs in the <CODE>HashMap</CODE> <CODE>KernPairs</CODE>. | |
313 | * @param char1 the first char | |
314 | * @param char2 the second char | |
315 | * @return the kerning to be applied | |
316 | */ | |
317 | public int getKerning(int char1, int char2) | |
318 | { | |
319 | String first = GlyphList.unicodeToName(char1); | |
320 |
1
1. getKerning : negated conditional → NO_COVERAGE |
if (first == null) |
321 |
1
1. getKerning : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return 0; |
322 | String second = GlyphList.unicodeToName(char2); | |
323 |
1
1. getKerning : negated conditional → NO_COVERAGE |
if (second == null) |
324 |
1
1. getKerning : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return 0; |
325 | Object[] obj = (Object[]) KernPairs.get(first); | |
326 |
1
1. getKerning : negated conditional → NO_COVERAGE |
if (obj == null) |
327 |
1
1. getKerning : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return 0; |
328 |
2
1. getKerning : changed conditional boundary → NO_COVERAGE 2. getKerning : negated conditional → NO_COVERAGE |
for (int k = 0; k < obj.length; k += 2) { |
329 |
1
1. getKerning : negated conditional → NO_COVERAGE |
if (second.equals(obj[k])) |
330 |
2
1. getKerning : Replaced integer addition with subtraction → NO_COVERAGE 2. getKerning : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return (Integer) obj[k + 1]; |
331 | } | |
332 |
1
1. getKerning : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return 0; |
333 | } | |
334 | | |
335 | | |
336 | /** Reads the font metrics | |
337 | * @param rf the AFM file | |
338 | * @throws DocumentException the AFM file is invalid | |
339 | * @throws IOException the AFM file could not be read | |
340 | */ | |
341 | public void process(RandomAccessFileOrArray rf) throws DocumentException, IOException | |
342 | { | |
343 | String line; | |
344 | boolean isMetrics = false; | |
345 | label: | |
346 |
1
1. process : negated conditional → NO_COVERAGE |
while ((line = rf.readLine()) != null) { |
347 | StringTokenizer tok = new StringTokenizer(line, " ,\n\r\t\f"); | |
348 |
1
1. process : negated conditional → NO_COVERAGE |
if (!tok.hasMoreTokens()) |
349 | continue; | |
350 | String ident = tok.nextToken(); | |
351 | switch (ident) { | |
352 | case "FontName": | |
353 | FontName = tok.nextToken("\u00ff").substring(1); | |
354 | break; | |
355 | case "FullName": | |
356 | FullName = tok.nextToken("\u00ff").substring(1); | |
357 | break; | |
358 | case "FamilyName": | |
359 | FamilyName = tok.nextToken("\u00ff").substring(1); | |
360 | break; | |
361 | case "Weight": | |
362 | Weight = tok.nextToken("\u00ff").substring(1); | |
363 | break; | |
364 | case "ItalicAngle": | |
365 | ItalicAngle = Float.parseFloat(tok.nextToken()); | |
366 | break; | |
367 | case "IsFixedPitch": | |
368 | IsFixedPitch = tok.nextToken().equals("true"); | |
369 | break; | |
370 | case "CharacterSet": | |
371 | CharacterSet = tok.nextToken("\u00ff").substring(1); | |
372 | break; | |
373 | case "FontBBox": | |
374 | llx = (int) Float.parseFloat(tok.nextToken()); | |
375 | lly = (int) Float.parseFloat(tok.nextToken()); | |
376 | urx = (int) Float.parseFloat(tok.nextToken()); | |
377 | ury = (int) Float.parseFloat(tok.nextToken()); | |
378 | break; | |
379 | case "UnderlinePosition": | |
380 | UnderlinePosition = (int) Float.parseFloat(tok.nextToken()); | |
381 | break; | |
382 | case "UnderlineThickness": | |
383 | UnderlineThickness = (int) Float.parseFloat(tok.nextToken()); | |
384 | break; | |
385 | case "EncodingScheme": | |
386 | EncodingScheme = tok.nextToken("\u00ff").substring(1); | |
387 | break; | |
388 | case "CapHeight": | |
389 | CapHeight = (int) Float.parseFloat(tok.nextToken()); | |
390 | break; | |
391 | case "XHeight": | |
392 | XHeight = (int) Float.parseFloat(tok.nextToken()); | |
393 | break; | |
394 | case "Ascender": | |
395 | Ascender = (int) Float.parseFloat(tok.nextToken()); | |
396 | break; | |
397 | case "Descender": | |
398 | Descender = (int) Float.parseFloat(tok.nextToken()); | |
399 | break; | |
400 | case "StdHW": | |
401 | StdHW = (int) Float.parseFloat(tok.nextToken()); | |
402 | break; | |
403 | case "StdVW": | |
404 | StdVW = (int) Float.parseFloat(tok.nextToken()); | |
405 | break; | |
406 | case "StartCharMetrics": | |
407 | isMetrics = true; | |
408 | break label; | |
409 | } | |
410 | } | |
411 |
1
1. process : negated conditional → NO_COVERAGE |
if (!isMetrics) |
412 | throw new DocumentException(MessageLocalization.getComposedMessage("missing.startcharmetrics.in.1", fileName)); | |
413 |
1
1. process : negated conditional → NO_COVERAGE |
while ((line = rf.readLine()) != null) |
414 | { | |
415 | StringTokenizer tok = new StringTokenizer(line); | |
416 |
1
1. process : negated conditional → NO_COVERAGE |
if (!tok.hasMoreTokens()) |
417 | continue; | |
418 | String ident = tok.nextToken(); | |
419 |
1
1. process : negated conditional → NO_COVERAGE |
if (ident.equals("EndCharMetrics")) |
420 | { | |
421 | isMetrics = false; | |
422 | break; | |
423 | } | |
424 | Integer C = -1; | |
425 | Integer WX = 250; | |
426 | String N = ""; | |
427 | int[] B = null; | |
428 | ||
429 | tok = new StringTokenizer(line, ";"); | |
430 |
1
1. process : negated conditional → NO_COVERAGE |
while (tok.hasMoreTokens()) |
431 | { | |
432 | StringTokenizer tokc = new StringTokenizer(tok.nextToken()); | |
433 |
1
1. process : negated conditional → NO_COVERAGE |
if (!tokc.hasMoreTokens()) |
434 | continue; | |
435 | ident = tokc.nextToken(); | |
436 | switch (ident) { | |
437 | case "C": | |
438 | C = Integer.valueOf(tokc.nextToken()); | |
439 | break; | |
440 | case "WX": | |
441 | WX = (int) Float.parseFloat(tokc.nextToken()); | |
442 | break; | |
443 | case "N": | |
444 | N = tokc.nextToken(); | |
445 | break; | |
446 | case "B": | |
447 | B = new int[]{Integer.parseInt(tokc.nextToken()), | |
448 | Integer.parseInt(tokc.nextToken()), | |
449 | Integer.parseInt(tokc.nextToken()), | |
450 | Integer.parseInt(tokc.nextToken())}; | |
451 | break; | |
452 | } | |
453 | } | |
454 | Object[] metrics = new Object[]{C, WX, N, B}; | |
455 |
2
1. process : changed conditional boundary → NO_COVERAGE 2. process : negated conditional → NO_COVERAGE |
if (C >= 0) |
456 | CharMetrics.put(C, metrics); | |
457 | CharMetrics.put(N, metrics); | |
458 | } | |
459 |
1
1. process : negated conditional → NO_COVERAGE |
if (isMetrics) |
460 | throw new DocumentException(MessageLocalization.getComposedMessage("missing.endcharmetrics.in.1", fileName)); | |
461 |
1
1. process : negated conditional → NO_COVERAGE |
if (!CharMetrics.containsKey("nonbreakingspace")) { |
462 | Object[] space = (Object[])CharMetrics.get("space"); | |
463 |
1
1. process : negated conditional → NO_COVERAGE |
if (space != null) |
464 | CharMetrics.put("nonbreakingspace", space); | |
465 | } | |
466 |
1
1. process : negated conditional → NO_COVERAGE |
while ((line = rf.readLine()) != null) |
467 | { | |
468 | StringTokenizer tok = new StringTokenizer(line); | |
469 |
1
1. process : negated conditional → NO_COVERAGE |
if (!tok.hasMoreTokens()) |
470 | continue; | |
471 | String ident = tok.nextToken(); | |
472 |
1
1. process : negated conditional → NO_COVERAGE |
if (ident.equals("EndFontMetrics")) |
473 | return; | |
474 |
1
1. process : negated conditional → NO_COVERAGE |
if (ident.equals("StartKernPairs")) |
475 | { | |
476 | isMetrics = true; | |
477 | break; | |
478 | } | |
479 | } | |
480 |
1
1. process : negated conditional → NO_COVERAGE |
if (!isMetrics) |
481 | throw new DocumentException(MessageLocalization.getComposedMessage("missing.endfontmetrics.in.1", fileName)); | |
482 |
1
1. process : negated conditional → NO_COVERAGE |
while ((line = rf.readLine()) != null) |
483 | { | |
484 | StringTokenizer tok = new StringTokenizer(line); | |
485 |
1
1. process : negated conditional → NO_COVERAGE |
if (!tok.hasMoreTokens()) |
486 | continue; | |
487 | String ident = tok.nextToken(); | |
488 |
1
1. process : negated conditional → NO_COVERAGE |
if (ident.equals("KPX")) |
489 | { | |
490 | String first = tok.nextToken(); | |
491 | String second = tok.nextToken(); | |
492 | Integer width = (int) Float.parseFloat(tok.nextToken()); | |
493 | Object[] relates = (Object[]) KernPairs.get(first); | |
494 |
1
1. process : negated conditional → NO_COVERAGE |
if (relates == null) |
495 | KernPairs.put(first, new Object[]{second, width}); | |
496 | else | |
497 | { | |
498 | int n = relates.length; | |
499 |
1
1. process : Replaced integer addition with subtraction → NO_COVERAGE |
Object[] relates2 = new Object[n + 2]; |
500 |
1
1. process : removed call to java/lang/System::arraycopy → NO_COVERAGE |
System.arraycopy(relates, 0, relates2, 0, n); |
501 | relates2[n] = second; | |
502 |
1
1. process : Replaced integer addition with subtraction → NO_COVERAGE |
relates2[n + 1] = width; |
503 | KernPairs.put(first, relates2); | |
504 | } | |
505 | } | |
506 |
1
1. process : negated conditional → NO_COVERAGE |
else if (ident.equals("EndKernPairs")) |
507 | { | |
508 | isMetrics = false; | |
509 | break; | |
510 | } | |
511 | } | |
512 |
1
1. process : negated conditional → NO_COVERAGE |
if (isMetrics) |
513 | throw new DocumentException(MessageLocalization.getComposedMessage("missing.endkernpairs.in.1", fileName)); | |
514 |
1
1. process : removed call to com/lowagie/text/pdf/RandomAccessFileOrArray::close → NO_COVERAGE |
rf.close(); |
515 | } | |
516 | | |
517 | /** If the embedded flag is <CODE>false</CODE> or if the font is | |
518 | * one of the 14 built in types, it returns <CODE>null</CODE>, | |
519 | * otherwise the font is read and output in a PdfStream object. | |
520 | * @return the PdfStream containing the font or <CODE>null</CODE> | |
521 | * @throws DocumentException if there is an error reading the font | |
522 | * @since 2.1.3 | |
523 | */ | |
524 | public PdfStream getFullFontStream() throws DocumentException | |
525 | { | |
526 |
2
1. getFullFontStream : negated conditional → NO_COVERAGE 2. getFullFontStream : negated conditional → NO_COVERAGE |
if (builtinFont || !embedded) |
527 |
1
1. getFullFontStream : mutated return of Object value for com/lowagie/text/pdf/Type1Font::getFullFontStream to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return null; |
528 | RandomAccessFileOrArray rf = null; | |
529 | try { | |
530 |
1
1. getFullFontStream : Replaced integer subtraction with addition → NO_COVERAGE |
String filePfb = fileName.substring(0, fileName.length() - 3) + "pfb"; |
531 |
1
1. getFullFontStream : negated conditional → NO_COVERAGE |
if (pfb == null) |
532 | rf = new RandomAccessFileOrArray(filePfb, true, Document.plainRandomAccess); | |
533 | else | |
534 | rf = new RandomAccessFileOrArray(pfb); | |
535 | int fileLength = rf.length(); | |
536 |
1
1. getFullFontStream : Replaced integer subtraction with addition → NO_COVERAGE |
byte[] st = new byte[fileLength - 18]; |
537 | int[] lengths = new int[3]; | |
538 | int bytePtr = 0; | |
539 |
3
1. getFullFontStream : changed conditional boundary → NO_COVERAGE 2. getFullFontStream : Changed increment from 1 to -1 → NO_COVERAGE 3. getFullFontStream : negated conditional → NO_COVERAGE |
for (int k = 0; k < 3; ++k) { |
540 |
1
1. getFullFontStream : negated conditional → NO_COVERAGE |
if (rf.read() != 0x80) |
541 | throw new DocumentException(MessageLocalization.getComposedMessage("start.marker.missing.in.1", filePfb)); | |
542 |
1
1. getFullFontStream : negated conditional → NO_COVERAGE |
if (rf.read() != PFB_TYPES[k]) |
543 | throw new DocumentException(MessageLocalization.getComposedMessage("incorrect.segment.type.in.1", filePfb)); | |
544 | int size = rf.read(); | |
545 |
2
1. getFullFontStream : Replaced Shift Left with Shift Right → NO_COVERAGE 2. getFullFontStream : Replaced integer addition with subtraction → NO_COVERAGE |
size += rf.read() << 8; |
546 |
2
1. getFullFontStream : Replaced Shift Left with Shift Right → NO_COVERAGE 2. getFullFontStream : Replaced integer addition with subtraction → NO_COVERAGE |
size += rf.read() << 16; |
547 |
2
1. getFullFontStream : Replaced Shift Left with Shift Right → NO_COVERAGE 2. getFullFontStream : Replaced integer addition with subtraction → NO_COVERAGE |
size += rf.read() << 24; |
548 | lengths[k] = size; | |
549 |
1
1. getFullFontStream : negated conditional → NO_COVERAGE |
while (size != 0) { |
550 | int got = rf.read(st, bytePtr, size); | |
551 |
2
1. getFullFontStream : changed conditional boundary → NO_COVERAGE 2. getFullFontStream : negated conditional → NO_COVERAGE |
if (got < 0) |
552 | throw new DocumentException(MessageLocalization.getComposedMessage("premature.end.in.1", filePfb)); | |
553 |
1
1. getFullFontStream : Replaced integer addition with subtraction → NO_COVERAGE |
bytePtr += got; |
554 |
1
1. getFullFontStream : Replaced integer subtraction with addition → NO_COVERAGE |
size -= got; |
555 | } | |
556 | } | |
557 |
1
1. getFullFontStream : mutated return of Object value for com/lowagie/text/pdf/Type1Font::getFullFontStream to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return new StreamFont(st, lengths, compressionLevel); |
558 | } | |
559 | catch (Exception e) { | |
560 | throw new DocumentException(e); | |
561 | } | |
562 | finally { | |
563 |
1
1. getFullFontStream : negated conditional → NO_COVERAGE |
if (rf != null) { |
564 | try { | |
565 |
1
1. getFullFontStream : removed call to com/lowagie/text/pdf/RandomAccessFileOrArray::close → NO_COVERAGE |
rf.close(); |
566 | } | |
567 | catch (Exception e) { | |
568 | // empty on purpose | |
569 | } | |
570 | } | |
571 | } | |
572 | } | |
573 | | |
574 | /** Generates the font descriptor for this font or <CODE>null</CODE> if it is | |
575 | * one of the 14 built in fonts. | |
576 | * @param fontStream the indirect reference to a PdfStream containing the font or <CODE>null</CODE> | |
577 | * @return the PdfDictionary containing the font descriptor or <CODE>null</CODE> | |
578 | */ | |
579 | private PdfDictionary getFontDescriptor(PdfIndirectReference fontStream) | |
580 | { | |
581 |
1
1. getFontDescriptor : negated conditional → NO_COVERAGE |
if (builtinFont) |
582 |
1
1. getFontDescriptor : mutated return of Object value for com/lowagie/text/pdf/Type1Font::getFontDescriptor to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return null; |
583 | PdfDictionary dic = new PdfDictionary(PdfName.FONTDESCRIPTOR); | |
584 |
1
1. getFontDescriptor : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
dic.put(PdfName.ASCENT, new PdfNumber(Ascender)); |
585 |
1
1. getFontDescriptor : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
dic.put(PdfName.CAPHEIGHT, new PdfNumber(CapHeight)); |
586 |
1
1. getFontDescriptor : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
dic.put(PdfName.DESCENT, new PdfNumber(Descender)); |
587 |
1
1. getFontDescriptor : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
dic.put(PdfName.FONTBBOX, new PdfRectangle(llx, lly, urx, ury)); |
588 |
1
1. getFontDescriptor : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
dic.put(PdfName.FONTNAME, new PdfName(FontName)); |
589 |
1
1. getFontDescriptor : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
dic.put(PdfName.ITALICANGLE, new PdfNumber(ItalicAngle)); |
590 |
1
1. getFontDescriptor : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
dic.put(PdfName.STEMV, new PdfNumber(StdVW)); |
591 |
1
1. getFontDescriptor : negated conditional → NO_COVERAGE |
if (fontStream != null) |
592 |
1
1. getFontDescriptor : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
dic.put(PdfName.FONTFILE, fontStream); |
593 | int flags = 0; | |
594 |
1
1. getFontDescriptor : negated conditional → NO_COVERAGE |
if (IsFixedPitch) |
595 |
1
1. getFontDescriptor : Replaced bitwise OR with AND → NO_COVERAGE |
flags |= 1; |
596 |
2
1. getFontDescriptor : Replaced bitwise OR with AND → NO_COVERAGE 2. getFontDescriptor : negated conditional → NO_COVERAGE |
flags |= fontSpecific ? 4 : 32; |
597 |
2
1. getFontDescriptor : changed conditional boundary → NO_COVERAGE 2. getFontDescriptor : negated conditional → NO_COVERAGE |
if (ItalicAngle < 0) |
598 |
1
1. getFontDescriptor : Replaced bitwise OR with AND → NO_COVERAGE |
flags |= 64; |
599 |
2
1. getFontDescriptor : negated conditional → NO_COVERAGE 2. getFontDescriptor : negated conditional → NO_COVERAGE |
if (FontName.contains("Caps") || FontName.endsWith("SC")) |
600 |
1
1. getFontDescriptor : Replaced bitwise OR with AND → NO_COVERAGE |
flags |= 131072; |
601 |
1
1. getFontDescriptor : negated conditional → NO_COVERAGE |
if (Weight.equals("Bold")) |
602 |
1
1. getFontDescriptor : Replaced bitwise OR with AND → NO_COVERAGE |
flags |= 262144; |
603 |
1
1. getFontDescriptor : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
dic.put(PdfName.FLAGS, new PdfNumber(flags)); |
604 | | |
605 |
1
1. getFontDescriptor : mutated return of Object value for com/lowagie/text/pdf/Type1Font::getFontDescriptor to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return dic; |
606 | } | |
607 | | |
608 | /** Generates the font dictionary for this font. | |
609 | * @return the PdfDictionary containing the font dictionary | |
610 | * @param firstChar the first valid character | |
611 | * @param lastChar the last valid character | |
612 | * @param shortTag a 256 bytes long <CODE>byte</CODE> array where each unused byte is represented by 0 | |
613 | * @param fontDescriptor the indirect reference to a PdfDictionary containing the font descriptor or <CODE>null</CODE> | |
614 | */ | |
615 | private PdfDictionary getFontBaseType(PdfIndirectReference fontDescriptor, int firstChar, int lastChar, byte[] shortTag) | |
616 | { | |
617 | PdfDictionary dic = new PdfDictionary(PdfName.FONT); | |
618 |
1
1. getFontBaseType : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
dic.put(PdfName.SUBTYPE, PdfName.TYPE1); |
619 |
1
1. getFontBaseType : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
dic.put(PdfName.BASEFONT, new PdfName(FontName)); |
620 |
2
1. getFontBaseType : negated conditional → NO_COVERAGE 2. getFontBaseType : negated conditional → NO_COVERAGE |
boolean stdEncoding = encoding.equals("Cp1252") || encoding.equals("MacRoman"); |
621 |
2
1. getFontBaseType : negated conditional → NO_COVERAGE 2. getFontBaseType : negated conditional → NO_COVERAGE |
if (!fontSpecific || specialMap != null) { |
622 |
3
1. getFontBaseType : changed conditional boundary → NO_COVERAGE 2. getFontBaseType : Changed increment from 1 to -1 → NO_COVERAGE 3. getFontBaseType : negated conditional → NO_COVERAGE |
for (int k = firstChar; k <= lastChar; ++k) { |
623 |
1
1. getFontBaseType : negated conditional → NO_COVERAGE |
if (!differences[k].equals(notdef)) { |
624 | firstChar = k; | |
625 | break; | |
626 | } | |
627 | } | |
628 |
1
1. getFontBaseType : negated conditional → NO_COVERAGE |
if (stdEncoding) |
629 |
2
1. getFontBaseType : negated conditional → NO_COVERAGE 2. getFontBaseType : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
dic.put(PdfName.ENCODING, encoding.equals("Cp1252") ? PdfName.WIN_ANSI_ENCODING : PdfName.MAC_ROMAN_ENCODING); |
630 | else { | |
631 | PdfDictionary enc = new PdfDictionary(PdfName.ENCODING); | |
632 | PdfArray dif = new PdfArray(); | |
633 | boolean gap = true; | |
634 |
3
1. getFontBaseType : changed conditional boundary → NO_COVERAGE 2. getFontBaseType : Changed increment from 1 to -1 → NO_COVERAGE 3. getFontBaseType : negated conditional → NO_COVERAGE |
for (int k = firstChar; k <= lastChar; ++k) { |
635 |
1
1. getFontBaseType : negated conditional → NO_COVERAGE |
if (shortTag[k] != 0) { |
636 |
1
1. getFontBaseType : negated conditional → NO_COVERAGE |
if (gap) { |
637 | dif.add(new PdfNumber(k)); | |
638 | gap = false; | |
639 | } | |
640 | dif.add(new PdfName(differences[k])); | |
641 | } | |
642 | else | |
643 | gap = true; | |
644 | } | |
645 |
1
1. getFontBaseType : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
enc.put(PdfName.DIFFERENCES, dif); |
646 |
1
1. getFontBaseType : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
dic.put(PdfName.ENCODING, enc); |
647 | } | |
648 | } | |
649 |
5
1. getFontBaseType : negated conditional → NO_COVERAGE 2. getFontBaseType : negated conditional → NO_COVERAGE 3. getFontBaseType : negated conditional → NO_COVERAGE 4. getFontBaseType : negated conditional → NO_COVERAGE 5. getFontBaseType : negated conditional → NO_COVERAGE |
if (specialMap != null || forceWidthsOutput || !(builtinFont && (fontSpecific || stdEncoding))) { |
650 |
1
1. getFontBaseType : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
dic.put(PdfName.FIRSTCHAR, new PdfNumber(firstChar)); |
651 |
1
1. getFontBaseType : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
dic.put(PdfName.LASTCHAR, new PdfNumber(lastChar)); |
652 | PdfArray wd = new PdfArray(); | |
653 |
3
1. getFontBaseType : changed conditional boundary → NO_COVERAGE 2. getFontBaseType : Changed increment from 1 to -1 → NO_COVERAGE 3. getFontBaseType : negated conditional → NO_COVERAGE |
for (int k = firstChar; k <= lastChar; ++k) { |
654 |
1
1. getFontBaseType : negated conditional → NO_COVERAGE |
if (shortTag[k] == 0) |
655 | wd.add(new PdfNumber(0)); | |
656 | else | |
657 | wd.add(new PdfNumber(widths[k])); | |
658 | } | |
659 |
1
1. getFontBaseType : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
dic.put(PdfName.WIDTHS, wd); |
660 | } | |
661 |
2
1. getFontBaseType : negated conditional → NO_COVERAGE 2. getFontBaseType : negated conditional → NO_COVERAGE |
if (!builtinFont && fontDescriptor != null) |
662 |
1
1. getFontBaseType : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
dic.put(PdfName.FONTDESCRIPTOR, fontDescriptor); |
663 |
1
1. getFontBaseType : mutated return of Object value for com/lowagie/text/pdf/Type1Font::getFontBaseType to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return dic; |
664 | } | |
665 | | |
666 | /** Outputs to the writer the font dictionaries and streams. | |
667 | * @param writer the writer for this document | |
668 | * @param ref the font indirect reference | |
669 | * @param params several parameters that depend on the font type | |
670 | * @throws IOException on error | |
671 | * @throws DocumentException error in generating the object | |
672 | */ | |
673 | void writeFont(PdfWriter writer, PdfIndirectReference ref, Object[] params) throws DocumentException, IOException { | |
674 | int firstChar = (Integer) params[0]; | |
675 | int lastChar = (Integer) params[1]; | |
676 | byte[] shortTag = (byte[]) params[2]; | |
677 |
2
1. writeFont : negated conditional → NO_COVERAGE 2. writeFont : negated conditional → NO_COVERAGE |
boolean subsetp = (Boolean) params[3] && subset; |
678 |
1
1. writeFont : negated conditional → NO_COVERAGE |
if (!subsetp) { |
679 | firstChar = 0; | |
680 |
1
1. writeFont : Replaced integer subtraction with addition → NO_COVERAGE |
lastChar = shortTag.length - 1; |
681 |
2
1. writeFont : changed conditional boundary → NO_COVERAGE 2. writeFont : negated conditional → NO_COVERAGE |
for (int k = 0; k < shortTag.length; ++k) |
682 | shortTag[k] = 1; | |
683 | } | |
684 | PdfIndirectReference ind_font = null; | |
685 | PdfObject pobj = null; | |
686 | PdfIndirectObject obj = null; | |
687 | pobj = getFullFontStream(); | |
688 |
1
1. writeFont : negated conditional → NO_COVERAGE |
if (pobj != null){ |
689 | obj = writer.addToBody(pobj); | |
690 | ind_font = obj.getIndirectReference(); | |
691 | } | |
692 | pobj = getFontDescriptor(ind_font); | |
693 |
1
1. writeFont : negated conditional → NO_COVERAGE |
if (pobj != null){ |
694 | obj = writer.addToBody(pobj); | |
695 | ind_font = obj.getIndirectReference(); | |
696 | } | |
697 | pobj = getFontBaseType(ind_font, firstChar, lastChar, shortTag); | |
698 | writer.addToBody(pobj, ref); | |
699 | } | |
700 | | |
701 | /** Gets the font parameter identified by <CODE>key</CODE>. Valid values | |
702 | * for <CODE>key</CODE> are <CODE>ASCENT</CODE>, <CODE>CAPHEIGHT</CODE>, <CODE>DESCENT</CODE>, | |
703 | * <CODE>ITALICANGLE</CODE>, <CODE>BBOXLLX</CODE>, <CODE>BBOXLLY</CODE>, <CODE>BBOXURX</CODE> | |
704 | * and <CODE>BBOXURY</CODE>. | |
705 | * @param key the parameter to be extracted | |
706 | * @param fontSize the font size in points | |
707 | * @return the parameter in points | |
708 | */ | |
709 | public float getFontDescriptor(int key, float fontSize) { | |
710 | switch (key) { | |
711 | case AWT_ASCENT: | |
712 | case ASCENT: | |
713 |
3
1. getFontDescriptor : Replaced float multiplication with division → NO_COVERAGE 2. getFontDescriptor : Replaced float division with multiplication → NO_COVERAGE 3. getFontDescriptor : replaced return of float value with -(x + 1) for com/lowagie/text/pdf/Type1Font::getFontDescriptor → NO_COVERAGE |
return Ascender * fontSize / 1000; |
714 | case CAPHEIGHT: | |
715 |
3
1. getFontDescriptor : Replaced float multiplication with division → NO_COVERAGE 2. getFontDescriptor : Replaced float division with multiplication → NO_COVERAGE 3. getFontDescriptor : replaced return of float value with -(x + 1) for com/lowagie/text/pdf/Type1Font::getFontDescriptor → NO_COVERAGE |
return CapHeight * fontSize / 1000; |
716 | case AWT_DESCENT: | |
717 | case DESCENT: | |
718 |
3
1. getFontDescriptor : Replaced float multiplication with division → NO_COVERAGE 2. getFontDescriptor : Replaced float division with multiplication → NO_COVERAGE 3. getFontDescriptor : replaced return of float value with -(x + 1) for com/lowagie/text/pdf/Type1Font::getFontDescriptor → NO_COVERAGE |
return Descender * fontSize / 1000; |
719 | case ITALICANGLE: | |
720 |
1
1. getFontDescriptor : replaced return of float value with -(x + 1) for com/lowagie/text/pdf/Type1Font::getFontDescriptor → NO_COVERAGE |
return ItalicAngle; |
721 | case BBOXLLX: | |
722 |
3
1. getFontDescriptor : Replaced float multiplication with division → NO_COVERAGE 2. getFontDescriptor : Replaced float division with multiplication → NO_COVERAGE 3. getFontDescriptor : replaced return of float value with -(x + 1) for com/lowagie/text/pdf/Type1Font::getFontDescriptor → NO_COVERAGE |
return llx * fontSize / 1000; |
723 | case BBOXLLY: | |
724 |
3
1. getFontDescriptor : Replaced float multiplication with division → NO_COVERAGE 2. getFontDescriptor : Replaced float division with multiplication → NO_COVERAGE 3. getFontDescriptor : replaced return of float value with -(x + 1) for com/lowagie/text/pdf/Type1Font::getFontDescriptor → NO_COVERAGE |
return lly * fontSize / 1000; |
725 | case BBOXURX: | |
726 |
3
1. getFontDescriptor : Replaced float multiplication with division → NO_COVERAGE 2. getFontDescriptor : Replaced float division with multiplication → NO_COVERAGE 3. getFontDescriptor : replaced return of float value with -(x + 1) for com/lowagie/text/pdf/Type1Font::getFontDescriptor → NO_COVERAGE |
return urx * fontSize / 1000; |
727 | case BBOXURY: | |
728 |
3
1. getFontDescriptor : Replaced float multiplication with division → NO_COVERAGE 2. getFontDescriptor : Replaced float division with multiplication → NO_COVERAGE 3. getFontDescriptor : replaced return of float value with -(x + 1) for com/lowagie/text/pdf/Type1Font::getFontDescriptor → NO_COVERAGE |
return ury * fontSize / 1000; |
729 | case AWT_LEADING: | |
730 |
1
1. getFontDescriptor : replaced return of float value with -(x + 1) for com/lowagie/text/pdf/Type1Font::getFontDescriptor → NO_COVERAGE |
return 0; |
731 | case AWT_MAXADVANCE: | |
732 |
4
1. getFontDescriptor : Replaced integer subtraction with addition → NO_COVERAGE 2. getFontDescriptor : Replaced float multiplication with division → NO_COVERAGE 3. getFontDescriptor : Replaced float division with multiplication → NO_COVERAGE 4. getFontDescriptor : replaced return of float value with -(x + 1) for com/lowagie/text/pdf/Type1Font::getFontDescriptor → NO_COVERAGE |
return (urx - llx) * fontSize / 1000; |
733 | case UNDERLINE_POSITION: | |
734 |
3
1. getFontDescriptor : Replaced float multiplication with division → NO_COVERAGE 2. getFontDescriptor : Replaced float division with multiplication → NO_COVERAGE 3. getFontDescriptor : replaced return of float value with -(x + 1) for com/lowagie/text/pdf/Type1Font::getFontDescriptor → NO_COVERAGE |
return UnderlinePosition * fontSize / 1000; |
735 | case UNDERLINE_THICKNESS: | |
736 |
3
1. getFontDescriptor : Replaced float multiplication with division → NO_COVERAGE 2. getFontDescriptor : Replaced float division with multiplication → NO_COVERAGE 3. getFontDescriptor : replaced return of float value with -(x + 1) for com/lowagie/text/pdf/Type1Font::getFontDescriptor → NO_COVERAGE |
return UnderlineThickness * fontSize / 1000; |
737 | } | |
738 |
1
1. getFontDescriptor : replaced return of float value with -(x + 1) for com/lowagie/text/pdf/Type1Font::getFontDescriptor → NO_COVERAGE |
return 0; |
739 | } | |
740 | | |
741 | /** Gets the postscript font name. | |
742 | * @return the postscript font name | |
743 | */ | |
744 | public String getPostscriptFontName() { | |
745 | return FontName; | |
746 | } | |
747 | | |
748 | /** Gets the full name of the font. If it is a True Type font | |
749 | * each array element will have {Platform ID, Platform Encoding ID, | |
750 | * Language ID, font name}. The interpretation of this values can be | |
751 | * found in the Open Type specification, chapter 2, in the 'name' table.<br> | |
752 | * For the other fonts the array has a single element with {"", "", "", | |
753 | * font name}. | |
754 | * @return the full name of the font | |
755 | */ | |
756 | public String[][] getFullFontName() { | |
757 |
1
1. getFullFontName : mutated return of Object value for com/lowagie/text/pdf/Type1Font::getFullFontName to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return new String[][]{{"", "", "", FullName}}; |
758 | } | |
759 | | |
760 | /** Gets all the entries of the names-table. If it is a True Type font | |
761 | * each array element will have {Name ID, Platform ID, Platform Encoding ID, | |
762 | * Language ID, font name}. The interpretation of this values can be | |
763 | * found in the Open Type specification, chapter 2, in the 'name' table.<br> | |
764 | * For the other fonts the array has a single element with {"4", "", "", "", | |
765 | * font name}. | |
766 | * @return the full name of the font | |
767 | */ | |
768 | public String[][] getAllNameEntries() { | |
769 |
1
1. getAllNameEntries : mutated return of Object value for com/lowagie/text/pdf/Type1Font::getAllNameEntries to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return new String[][]{{"4", "", "", "", FullName}}; |
770 | } | |
771 | | |
772 | /** Gets the family name of the font. If it is a True Type font | |
773 | * each array element will have {Platform ID, Platform Encoding ID, | |
774 | * Language ID, font name}. The interpretation of this values can be | |
775 | * found in the Open Type specification, chapter 2, in the 'name' table.<br> | |
776 | * For the other fonts the array has a single element with {"", "", "", | |
777 | * font name}. | |
778 | * @return the family name of the font | |
779 | */ | |
780 | public String[][] getFamilyFontName() { | |
781 |
1
1. getFamilyFontName : mutated return of Object value for com/lowagie/text/pdf/Type1Font::getFamilyFontName to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return new String[][]{{"", "", "", FamilyName}}; |
782 | } | |
783 | | |
784 | /** Checks if the font has any kerning pairs. | |
785 | * @return <CODE>true</CODE> if the font has any kerning pairs | |
786 | */ | |
787 | public boolean hasKernPairs() { | |
788 |
2
1. hasKernPairs : negated conditional → NO_COVERAGE 2. hasKernPairs : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return !KernPairs.isEmpty(); |
789 | } | |
790 | | |
791 | /** | |
792 | * Sets the font name that will appear in the pdf font dictionary. | |
793 | * Use with care as it can easily make a font unreadable if not embedded. | |
794 | * @param name the new font name | |
795 | */ | |
796 | public void setPostscriptFontName(String name) { | |
797 | FontName = name; | |
798 | } | |
799 | | |
800 | /** | |
801 | * Sets the kerning between two Unicode chars. | |
802 | * @param char1 the first char | |
803 | * @param char2 the second char | |
804 | * @param kern the kerning to apply in normalized 1000 units | |
805 | * @return <code>true</code> if the kerning was applied, <code>false</code> otherwise | |
806 | */ | |
807 | public boolean setKerning(int char1, int char2, int kern) { | |
808 | String first = GlyphList.unicodeToName(char1); | |
809 |
1
1. setKerning : negated conditional → NO_COVERAGE |
if (first == null) |
810 |
1
1. setKerning : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return false; |
811 | String second = GlyphList.unicodeToName(char2); | |
812 |
1
1. setKerning : negated conditional → NO_COVERAGE |
if (second == null) |
813 |
1
1. setKerning : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return false; |
814 | Object[] obj = (Object[]) KernPairs.get(first); | |
815 |
1
1. setKerning : negated conditional → NO_COVERAGE |
if (obj == null) { |
816 | obj = new Object[]{second, kern}; | |
817 | KernPairs.put(first, obj); | |
818 |
1
1. setKerning : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return true; |
819 | } | |
820 |
2
1. setKerning : changed conditional boundary → NO_COVERAGE 2. setKerning : negated conditional → NO_COVERAGE |
for (int k = 0; k < obj.length; k += 2) { |
821 |
1
1. setKerning : negated conditional → NO_COVERAGE |
if (second.equals(obj[k])) { |
822 |
1
1. setKerning : Replaced integer addition with subtraction → NO_COVERAGE |
obj[k + 1] = kern; |
823 |
1
1. setKerning : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return true; |
824 | } | |
825 | } | |
826 | int size = obj.length; | |
827 |
1
1. setKerning : Replaced integer addition with subtraction → NO_COVERAGE |
Object[] obj2 = new Object[size + 2]; |
828 |
1
1. setKerning : removed call to java/lang/System::arraycopy → NO_COVERAGE |
System.arraycopy(obj, 0, obj2, 0, size); |
829 | obj2[size] = second; | |
830 |
1
1. setKerning : Replaced integer addition with subtraction → NO_COVERAGE |
obj2[size + 1] = kern; |
831 | KernPairs.put(first, obj2); | |
832 |
1
1. setKerning : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return true; |
833 | } | |
834 | | |
835 | protected int[] getRawCharBBox(int c, String name) { | |
836 | Object[] metrics; | |
837 |
1
1. getRawCharBBox : negated conditional → NO_COVERAGE |
if (name == null) { // font specific |
838 | metrics = (Object[])CharMetrics.get(c); | |
839 | } | |
840 | else { | |
841 |
1
1. getRawCharBBox : negated conditional → NO_COVERAGE |
if (name.equals(".notdef")) |
842 |
1
1. getRawCharBBox : mutated return of Object value for com/lowagie/text/pdf/Type1Font::getRawCharBBox to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return null; |
843 | metrics = (Object[])CharMetrics.get(name); | |
844 | } | |
845 |
1
1. getRawCharBBox : negated conditional → NO_COVERAGE |
if (metrics != null) |
846 |
1
1. getRawCharBBox : mutated return of Object value for com/lowagie/text/pdf/Type1Font::getRawCharBBox to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return ((int[])(metrics[3])); |
847 |
1
1. getRawCharBBox : mutated return of Object value for com/lowagie/text/pdf/Type1Font::getRawCharBBox to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return null; |
848 | } | |
849 | | |
850 | } | |
Mutations | ||
177 |
1.1 2.2 3.3 |
|
179 |
1.1 2.2 |
|
187 |
1.1 |
|
192 |
1.1 |
|
195 |
1.1 |
|
197 |
1.1 |
|
203 |
1.1 2.2 |
|
205 |
1.1 |
|
210 |
1.1 |
|
212 |
1.1 |
|
221 |
1.1 |
|
224 |
1.1 |
|
226 |
1.1 |
|
234 |
1.1 |
|
236 |
1.1 |
|
240 |
1.1 |
|
243 |
1.1 |
|
245 |
1.1 |
|
253 |
1.1 |
|
256 |
1.1 |
|
260 |
1.1 |
|
261 |
1.1 |
|
263 |
1.1 |
|
266 |
1.1 |
|
268 |
1.1 |
|
280 |
1.1 2.2 |
|
283 |
1.1 |
|
285 |
1.1 |
|
297 |
1.1 |
|
301 |
1.1 |
|
302 |
1.1 |
|
305 |
1.1 |
|
306 |
1.1 |
|
307 |
1.1 |
|
320 |
1.1 |
|
321 |
1.1 |
|
323 |
1.1 |
|
324 |
1.1 |
|
326 |
1.1 |
|
327 |
1.1 |
|
328 |
1.1 2.2 |
|
329 |
1.1 |
|
330 |
1.1 2.2 |
|
332 |
1.1 |
|
346 |
1.1 |
|
348 |
1.1 |
|
411 |
1.1 |
|
413 |
1.1 |
|
416 |
1.1 |
|
419 |
1.1 |
|
430 |
1.1 |
|
433 |
1.1 |
|
455 |
1.1 2.2 |
|
459 |
1.1 |
|
461 |
1.1 |
|
463 |
1.1 |
|
466 |
1.1 |
|
469 |
1.1 |
|
472 |
1.1 |
|
474 |
1.1 |
|
480 |
1.1 |
|
482 |
1.1 |
|
485 |
1.1 |
|
488 |
1.1 |
|
494 |
1.1 |
|
499 |
1.1 |
|
500 |
1.1 |
|
502 |
1.1 |
|
506 |
1.1 |
|
512 |
1.1 |
|
514 |
1.1 |
|
526 |
1.1 2.2 |
|
527 |
1.1 |
|
530 |
1.1 |
|
531 |
1.1 |
|
536 |
1.1 |
|
539 |
1.1 2.2 3.3 |
|
540 |
1.1 |
|
542 |
1.1 |
|
545 |
1.1 2.2 |
|
546 |
1.1 2.2 |
|
547 |
1.1 2.2 |
|
549 |
1.1 |
|
551 |
1.1 2.2 |
|
553 |
1.1 |
|
554 |
1.1 |
|
557 |
1.1 |
|
563 |
1.1 |
|
565 |
1.1 |
|
581 |
1.1 |
|
582 |
1.1 |
|
584 |
1.1 |
|
585 |
1.1 |
|
586 |
1.1 |
|
587 |
1.1 |
|
588 |
1.1 |
|
589 |
1.1 |
|
590 |
1.1 |
|
591 |
1.1 |
|
592 |
1.1 |
|
594 |
1.1 |
|
595 |
1.1 |
|
596 |
1.1 2.2 |
|
597 |
1.1 2.2 |
|
598 |
1.1 |
|
599 |
1.1 2.2 |
|
600 |
1.1 |
|
601 |
1.1 |
|
602 |
1.1 |
|
603 |
1.1 |
|
605 |
1.1 |
|
618 |
1.1 |
|
619 |
1.1 |
|
620 |
1.1 2.2 |
|
621 |
1.1 2.2 |
|
622 |
1.1 2.2 3.3 |
|
623 |
1.1 |
|
628 |
1.1 |
|
629 |
1.1 2.2 |
|
634 |
1.1 2.2 3.3 |
|
635 |
1.1 |
|
636 |
1.1 |
|
645 |
1.1 |
|
646 |
1.1 |
|
649 |
1.1 2.2 3.3 4.4 5.5 |
|
650 |
1.1 |
|
651 |
1.1 |
|
653 |
1.1 2.2 3.3 |
|
654 |
1.1 |
|
659 |
1.1 |
|
661 |
1.1 2.2 |
|
662 |
1.1 |
|
663 |
1.1 |
|
677 |
1.1 2.2 |
|
678 |
1.1 |
|
680 |
1.1 |
|
681 |
1.1 2.2 |
|
688 |
1.1 |
|
693 |
1.1 |
|
713 |
1.1 2.2 3.3 |
|
715 |
1.1 2.2 3.3 |
|
718 |
1.1 2.2 3.3 |
|
720 |
1.1 |
|
722 |
1.1 2.2 3.3 |
|
724 |
1.1 2.2 3.3 |
|
726 |
1.1 2.2 3.3 |
|
728 |
1.1 2.2 3.3 |
|
730 |
1.1 |
|
732 |
1.1 2.2 3.3 4.4 |
|
734 |
1.1 2.2 3.3 |
|
736 |
1.1 2.2 3.3 |
|
738 |
1.1 |
|
757 |
1.1 |
|
769 |
1.1 |
|
781 |
1.1 |
|
788 |
1.1 2.2 |
|
809 |
1.1 |
|
810 |
1.1 |
|
812 |
1.1 |
|
813 |
1.1 |
|
815 |
1.1 |
|
818 |
1.1 |
|
820 |
1.1 2.2 |
|
821 |
1.1 |
|
822 |
1.1 |
|
823 |
1.1 |
|
827 |
1.1 |
|
828 |
1.1 |
|
830 |
1.1 |
|
832 |
1.1 |
|
837 |
1.1 |
|
841 |
1.1 |
|
842 |
1.1 |
|
845 |
1.1 |
|
846 |
1.1 |
|
847 |
1.1 |