1 | /* | |
2 | * $Id: TrueTypeFontUnicode.java 4065 2009-09-16 23:09:11Z psoares33 $ | |
3 | * | |
4 | * Copyright 2001, 2002 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.IOException; | |
53 | import java.util.ArrayList; | |
54 | import java.util.Arrays; | |
55 | import java.util.Comparator; | |
56 | import java.util.HashMap; | |
57 | import java.util.List; | |
58 | import java.util.Map; | |
59 | ||
60 | import com.lowagie.text.DocumentException; | |
61 | import com.lowagie.text.Utilities; | |
62 | import com.lowagie.text.error_messages.MessageLocalization; | |
63 | ||
64 | /** Represents a True Type font with Unicode encoding. All the character | |
65 | * in the font can be used directly by using the encoding Identity-H or | |
66 | * Identity-V. This is the only way to represent some character sets such | |
67 | * as Thai. | |
68 | * @author Paulo Soares (psoares@consiste.pt) | |
69 | */ | |
70 | class TrueTypeFontUnicode extends TrueTypeFont implements Comparator{ | |
71 | | |
72 | /** | |
73 | * <CODE>true</CODE> if the encoding is vertical. | |
74 | */ | |
75 | boolean vertical = false; | |
76 | | |
77 | Map<Integer, Integer> inverseCmap; | |
78 | | |
79 | /** | |
80 | * Creates a new TrueType font addressed by Unicode characters. The font | |
81 | * will always be embedded. | |
82 | * @param ttFile the location of the font on file. The file must end in '.ttf'. | |
83 | * The modifiers after the name are ignored. | |
84 | * @param enc the encoding to be applied to this font | |
85 | * @param emb true if the font is to be embedded in the PDF | |
86 | * @param ttfAfm the font as a <CODE>byte</CODE> array | |
87 | * @throws DocumentException the font is invalid | |
88 | * @throws IOException the font file could not be read | |
89 | */ | |
90 | TrueTypeFontUnicode(String ttFile, String enc, boolean emb, byte[] ttfAfm, boolean forceRead) throws DocumentException, IOException { | |
91 | String nameBase = getBaseName(ttFile); | |
92 | String ttcName = getTTCName(nameBase); | |
93 |
2
1. 2. |
if (nameBase.length() < ttFile.length()) { |
94 | style = ttFile.substring(nameBase.length()); | |
95 | } | |
96 | encoding = enc; | |
97 | embedded = emb; | |
98 | fileName = ttcName; | |
99 | ttcIndex = ""; | |
100 |
2
1. 2. |
if (ttcName.length() < nameBase.length()) |
101 |
1
1. |
ttcIndex = nameBase.substring(ttcName.length() + 1); |
102 | fontType = FONT_TYPE_TTUNI; | |
103 |
6
1. 2. 3. 4. 5. 6. |
if ((fileName.toLowerCase().endsWith(".ttf") || fileName.toLowerCase().endsWith(".otf") || fileName.toLowerCase().endsWith(".ttc")) && ((enc.equals(IDENTITY_H) || enc.equals(IDENTITY_V)) && emb)) { |
104 |
1
1. |
process(ttfAfm, forceRead); |
105 |
1
1. |
if (os_2.fsType == 2) |
106 | throw new DocumentException(MessageLocalization.getComposedMessage("1.cannot.be.embedded.due.to.licensing.restrictions", fileName + style)); | |
107 | // Sivan | |
108 |
4
1. 2. 3. 4. |
if ((cmap31 == null && !fontSpecific) || (cmap10 == null && fontSpecific)) |
109 | directTextToByte=true; | |
110 | //throw new DocumentException(MessageLocalization.getComposedMessage("1.2.does.not.contain.an.usable.cmap", fileName, style)); | |
111 |
1
1. |
if (fontSpecific) { |
112 | fontSpecific = false; | |
113 | String tempEncoding = encoding; | |
114 | encoding = ""; | |
115 |
1
1. |
createEncoding(); |
116 | encoding = tempEncoding; | |
117 | fontSpecific = true; | |
118 | } | |
119 | } | |
120 | else | |
121 | throw new DocumentException(MessageLocalization.getComposedMessage("1.2.is.not.a.ttf.font.file", fileName, style)); | |
122 | vertical = enc.endsWith("V"); | |
123 | } | |
124 | | |
125 | void readCMaps() throws DocumentException, IOException { | |
126 |
1
1. readCMaps : removed call to com/lowagie/text/pdf/TrueTypeFont::readCMaps → NO_COVERAGE |
super.readCMaps(); |
127 | ||
128 | Map cmap = null; | |
129 |
1
1. readCMaps : negated conditional → NO_COVERAGE |
if (cmapExt != null) { |
130 | cmap = cmapExt; | |
131 |
1
1. readCMaps : negated conditional → NO_COVERAGE |
} else if (cmap31 != null) { |
132 | cmap = cmap31; | |
133 | } | |
134 | ||
135 |
1
1. readCMaps : negated conditional → NO_COVERAGE |
if (cmap != null) { |
136 | inverseCmap = new HashMap<>(); | |
137 | for (Object o : cmap.entrySet()) { | |
138 | Map.Entry entry = (Map.Entry) o; | |
139 | Integer code = (Integer) entry.getKey(); | |
140 | int[] metrics = (int[]) entry.getValue(); | |
141 | inverseCmap.put(metrics[0], code); | |
142 | } | |
143 | } | |
144 | } | |
145 | | |
146 | protected Integer getCharacterCode(int code) { | |
147 |
2
1. getCharacterCode : negated conditional → NO_COVERAGE 2. getCharacterCode : mutated return of Object value for com/lowagie/text/pdf/TrueTypeFontUnicode::getCharacterCode to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return inverseCmap == null ? null : inverseCmap.get(code); |
148 | } | |
149 | | |
150 | | |
151 | /** | |
152 | * Gets the width of a <CODE>char</CODE> in normalized 1000 units. | |
153 | * @param char1 the unicode <CODE>char</CODE> to get the width of | |
154 | * @return the width in normalized 1000 units | |
155 | */ | |
156 | public int getWidth(int char1) { | |
157 |
1
1. getWidth : negated conditional → NO_COVERAGE |
if (vertical) |
158 |
1
1. getWidth : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return 1000; |
159 |
1
1. getWidth : negated conditional → NO_COVERAGE |
if (fontSpecific) { |
160 |
4
1. getWidth : Replaced bitwise AND with OR → NO_COVERAGE 2. getWidth : Replaced bitwise AND with OR → NO_COVERAGE 3. getWidth : negated conditional → NO_COVERAGE 4. getWidth : negated conditional → NO_COVERAGE |
if ((char1 & 0xff00) == 0 || (char1 & 0xff00) == 0xf000) |
161 |
2
1. getWidth : Replaced bitwise AND with OR → NO_COVERAGE 2. getWidth : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return getRawWidth(char1 & 0xff, null); |
162 | else | |
163 |
1
1. getWidth : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return 0; |
164 | } | |
165 | else { | |
166 |
1
1. getWidth : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return getRawWidth(char1, encoding); |
167 | } | |
168 | } | |
169 | | |
170 | /** | |
171 | * Gets the width of a <CODE>String</CODE> in normalized 1000 units. | |
172 | * @param text the <CODE>String</CODE> to get the width of | |
173 | * @return the width in normalized 1000 units | |
174 | */ | |
175 | public int getWidth(String text) { | |
176 |
1
1. getWidth : negated conditional → NO_COVERAGE |
if (vertical) |
177 |
2
1. getWidth : Replaced integer multiplication with division → NO_COVERAGE 2. getWidth : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return text.length() * 1000; |
178 | int total = 0; | |
179 |
1
1. getWidth : negated conditional → NO_COVERAGE |
if (fontSpecific) { |
180 | char[] cc = text.toCharArray(); | |
181 | int len = cc.length; | |
182 | for (char c : cc) { | |
183 |
4
1. getWidth : Replaced bitwise AND with OR → NO_COVERAGE 2. getWidth : Replaced bitwise AND with OR → NO_COVERAGE 3. getWidth : negated conditional → NO_COVERAGE 4. getWidth : negated conditional → NO_COVERAGE |
if ((c & 0xff00) == 0 || (c & 0xff00) == 0xf000) |
184 |
2
1. getWidth : Replaced bitwise AND with OR → NO_COVERAGE 2. getWidth : Replaced integer addition with subtraction → NO_COVERAGE |
total += getRawWidth(c & 0xff, null); |
185 | } | |
186 | } | |
187 | else { | |
188 | int len = text.length(); | |
189 |
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) { |
190 |
1
1. getWidth : negated conditional → NO_COVERAGE |
if (Utilities.isSurrogatePair(text, k)) { |
191 |
1
1. getWidth : Replaced integer addition with subtraction → NO_COVERAGE |
total += getRawWidth(Utilities.convertToUtf32(text, k), encoding); |
192 |
1
1. getWidth : Changed increment from 1 to -1 → NO_COVERAGE |
++k; |
193 | } | |
194 | else | |
195 |
1
1. getWidth : Replaced integer addition with subtraction → NO_COVERAGE |
total += getRawWidth(text.charAt(k), encoding); |
196 | } | |
197 | } | |
198 |
1
1. getWidth : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return total; |
199 | } | |
200 | ||
201 | /** Creates a ToUnicode CMap to allow copy and paste from Acrobat. | |
202 | * @param metrics metrics[0] contains the glyph index and metrics[2] | |
203 | * contains the Unicode code | |
204 | * @return the stream representing this CMap or <CODE>null</CODE> | |
205 | */ | |
206 | private PdfStream getToUnicode(Object[] metrics) { | |
207 | metrics = filterCmapMetrics(metrics); | |
208 |
1
1. getToUnicode : negated conditional → NO_COVERAGE |
if (metrics.length == 0) |
209 |
1
1. getToUnicode : mutated return of Object value for com/lowagie/text/pdf/TrueTypeFontUnicode::getToUnicode to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return null; |
210 | StringBuilder buf = new StringBuilder( | |
211 | "/CIDInit /ProcSet findresource begin\n" + | |
212 | "12 dict begin\n" + | |
213 | "begincmap\n" + | |
214 | "/CIDSystemInfo\n" + | |
215 | "<< /Registry (TTX+0)\n" + | |
216 | "/Ordering (T42UV)\n" + | |
217 | "/Supplement 0\n" + | |
218 | ">> def\n" + | |
219 | "/CMapName /TTX+0 def\n" + | |
220 | "/CMapType 2 def\n" + | |
221 | "1 begincodespacerange\n" + | |
222 | "<0000><FFFF>\n" + | |
223 | "endcodespacerange\n"); | |
224 | int size = 0; | |
225 |
3
1. getToUnicode : changed conditional boundary → NO_COVERAGE 2. getToUnicode : Changed increment from 1 to -1 → NO_COVERAGE 3. getToUnicode : negated conditional → NO_COVERAGE |
for (int k = 0; k < metrics.length; ++k) { |
226 |
1
1. getToUnicode : negated conditional → NO_COVERAGE |
if (size == 0) { |
227 |
1
1. getToUnicode : negated conditional → NO_COVERAGE |
if (k != 0) { |
228 | buf.append("endbfrange\n"); | |
229 | } | |
230 |
1
1. getToUnicode : Replaced integer subtraction with addition → NO_COVERAGE |
size = Math.min(100, metrics.length - k); |
231 | buf.append(size).append(" beginbfrange\n"); | |
232 | } | |
233 |
1
1. getToUnicode : Changed increment from -1 to 1 → NO_COVERAGE |
--size; |
234 | int[] metric = (int[]) metrics[k]; | |
235 | String fromTo = toHex(metric[0]); | |
236 | buf.append(fromTo).append(fromTo).append(toHex(metric[2])).append('\n'); | |
237 | } | |
238 | buf.append( | |
239 | "endbfrange\n" + | |
240 | "endcmap\n" + | |
241 | "CMapName currentdict /CMap defineresource pop\n" + | |
242 | "end end\n"); | |
243 | String s = buf.toString(); | |
244 | PdfStream stream = new PdfStream(PdfEncodings.convertToBytes(s, null)); | |
245 |
1
1. getToUnicode : removed call to com/lowagie/text/pdf/PdfStream::flateCompress → NO_COVERAGE |
stream.flateCompress(compressionLevel); |
246 |
1
1. getToUnicode : mutated return of Object value for com/lowagie/text/pdf/TrueTypeFontUnicode::getToUnicode to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return stream; |
247 | } | |
248 | | |
249 | private Object[] filterCmapMetrics(Object[] metrics) { | |
250 |
1
1. filterCmapMetrics : negated conditional → NO_COVERAGE |
if (metrics.length == 0) { |
251 |
1
1. filterCmapMetrics : mutated return of Object value for com/lowagie/text/pdf/TrueTypeFontUnicode::filterCmapMetrics to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return metrics; |
252 | } | |
253 | ||
254 | List<int[]> cmapMetrics = new ArrayList<>(metrics.length); | |
255 | for (Object metric1 : metrics) { | |
256 | int[] metric = (int[]) metric1; | |
257 | // PdfContentByte.showText(GlyphVector) uses glyphs that might not | |
258 | // map to a character. | |
259 | // the glyphs are included in the metrics array, but we need to | |
260 | // exclude them from the cmap. | |
261 |
2
1. filterCmapMetrics : changed conditional boundary → NO_COVERAGE 2. filterCmapMetrics : negated conditional → NO_COVERAGE |
if (metric.length >= 3) { |
262 | cmapMetrics.add(metric); | |
263 | } | |
264 | } | |
265 | ||
266 |
1
1. filterCmapMetrics : negated conditional → NO_COVERAGE |
if (cmapMetrics.size() == metrics.length) { |
267 |
1
1. filterCmapMetrics : mutated return of Object value for com/lowagie/text/pdf/TrueTypeFontUnicode::filterCmapMetrics to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return metrics; |
268 | } | |
269 | ||
270 |
1
1. filterCmapMetrics : mutated return of Object value for com/lowagie/text/pdf/TrueTypeFontUnicode::filterCmapMetrics to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return cmapMetrics.toArray(); |
271 | } | |
272 | | |
273 | private static String toHex4(int n) { | |
274 | String s = "0000" + Integer.toHexString(n); | |
275 |
2
1. toHex4 : Replaced integer subtraction with addition → NO_COVERAGE 2. toHex4 : mutated return of Object value for com/lowagie/text/pdf/TrueTypeFontUnicode::toHex4 to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return s.substring(s.length() - 4); |
276 | } | |
277 | | |
278 | /** Gets an hex string in the format "<HHHH>". | |
279 | * @param n the number | |
280 | * @return the hex string | |
281 | */ | |
282 | static String toHex(int n) { | |
283 |
2
1. toHex : changed conditional boundary → NO_COVERAGE 2. toHex : negated conditional → NO_COVERAGE |
if (n < 0x10000) |
284 |
1
1. toHex : mutated return of Object value for com/lowagie/text/pdf/TrueTypeFontUnicode::toHex to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return "<" + toHex4(n) + ">"; |
285 |
1
1. toHex : Replaced integer subtraction with addition → NO_COVERAGE |
n -= 0x10000; |
286 |
2
1. toHex : Replaced integer division with multiplication → NO_COVERAGE 2. toHex : Replaced integer addition with subtraction → NO_COVERAGE |
int high = (n / 0x400) + 0xd800; |
287 |
2
1. toHex : Replaced integer modulus with multiplication → NO_COVERAGE 2. toHex : Replaced integer addition with subtraction → NO_COVERAGE |
int low = (n % 0x400) + 0xdc00; |
288 |
1
1. toHex : mutated return of Object value for com/lowagie/text/pdf/TrueTypeFontUnicode::toHex to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return "[<" + toHex4(high) + toHex4(low) + ">]"; |
289 | } | |
290 | | |
291 | /** Generates the CIDFontTyte2 dictionary. | |
292 | * @param fontDescriptor the indirect reference to the font descriptor | |
293 | * @param subsetPrefix the subset prefix | |
294 | * @param metrics the horizontal width metrics | |
295 | * @return a stream | |
296 | */ | |
297 | private PdfDictionary getCIDFontType2(PdfIndirectReference fontDescriptor, String subsetPrefix, Object[] metrics) { | |
298 | PdfDictionary dic = new PdfDictionary(PdfName.FONT); | |
299 | // sivan; cff | |
300 |
1
1. getCIDFontType2 : negated conditional → NO_COVERAGE |
if (cff) { |
301 |
1
1. getCIDFontType2 : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
dic.put(PdfName.SUBTYPE, PdfName.CIDFONTTYPE0); |
302 |
1
1. getCIDFontType2 : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
dic.put(PdfName.BASEFONT, new PdfName(subsetPrefix+fontName+"-"+encoding)); |
303 | } | |
304 | else { | |
305 |
1
1. getCIDFontType2 : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
dic.put(PdfName.SUBTYPE, PdfName.CIDFONTTYPE2); |
306 |
1
1. getCIDFontType2 : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
dic.put(PdfName.BASEFONT, new PdfName(subsetPrefix + fontName)); |
307 | } | |
308 |
1
1. getCIDFontType2 : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
dic.put(PdfName.FONTDESCRIPTOR, fontDescriptor); |
309 |
1
1. getCIDFontType2 : negated conditional → NO_COVERAGE |
if (!cff) |
310 |
1
1. getCIDFontType2 : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
dic.put(PdfName.CIDTOGIDMAP,PdfName.IDENTITY); |
311 | PdfDictionary cdic = new PdfDictionary(); | |
312 |
1
1. getCIDFontType2 : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
cdic.put(PdfName.REGISTRY, new PdfString("Adobe")); |
313 |
1
1. getCIDFontType2 : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
cdic.put(PdfName.ORDERING, new PdfString("Identity")); |
314 |
1
1. getCIDFontType2 : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
cdic.put(PdfName.SUPPLEMENT, new PdfNumber(0)); |
315 |
1
1. getCIDFontType2 : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
dic.put(PdfName.CIDSYSTEMINFO, cdic); |
316 |
1
1. getCIDFontType2 : negated conditional → NO_COVERAGE |
if (!vertical) { |
317 |
1
1. getCIDFontType2 : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
dic.put(PdfName.DW, new PdfNumber(1000)); |
318 | StringBuilder buf = new StringBuilder("["); | |
319 | int lastNumber = -10; | |
320 | boolean firstTime = true; | |
321 | for (Object metric1 : metrics) { | |
322 | int[] metric = (int[]) metric1; | |
323 |
1
1. getCIDFontType2 : negated conditional → NO_COVERAGE |
if (metric[1] == 1000) |
324 | continue; | |
325 | int m = metric[0]; | |
326 |
2
1. getCIDFontType2 : Replaced integer addition with subtraction → NO_COVERAGE 2. getCIDFontType2 : negated conditional → NO_COVERAGE |
if (m == lastNumber + 1) { |
327 | buf.append(' ').append(metric[1]); | |
328 | } else { | |
329 |
1
1. getCIDFontType2 : negated conditional → NO_COVERAGE |
if (!firstTime) { |
330 | buf.append(']'); | |
331 | } | |
332 | firstTime = false; | |
333 | buf.append(m).append('[').append(metric[1]); | |
334 | } | |
335 | lastNumber = m; | |
336 | } | |
337 |
2
1. getCIDFontType2 : changed conditional boundary → NO_COVERAGE 2. getCIDFontType2 : negated conditional → NO_COVERAGE |
if (buf.length() > 1) { |
338 | buf.append("]]"); | |
339 |
1
1. getCIDFontType2 : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
dic.put(PdfName.W, new PdfLiteral(buf.toString())); |
340 | } | |
341 | } | |
342 |
1
1. getCIDFontType2 : mutated return of Object value for com/lowagie/text/pdf/TrueTypeFontUnicode::getCIDFontType2 to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return dic; |
343 | } | |
344 | | |
345 | /** Generates the font dictionary. | |
346 | * @param descendant the descendant dictionary | |
347 | * @param subsetPrefix the subset prefix | |
348 | * @param toUnicode the ToUnicode stream | |
349 | * @return the stream | |
350 | */ | |
351 | private PdfDictionary getFontBaseType(PdfIndirectReference descendant, String subsetPrefix, PdfIndirectReference toUnicode) { | |
352 | PdfDictionary dic = new PdfDictionary(PdfName.FONT); | |
353 | ||
354 |
1
1. getFontBaseType : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
dic.put(PdfName.SUBTYPE, PdfName.TYPE0); |
355 | // The PDF Reference manual advises to add -encoding to CID font names | |
356 |
1
1. getFontBaseType : negated conditional → NO_COVERAGE |
if (cff) |
357 |
1
1. getFontBaseType : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
dic.put(PdfName.BASEFONT, new PdfName(subsetPrefix+fontName+"-"+encoding)); |
358 | //dic.put(PdfName.BASEFONT, new PdfName(subsetPrefix+fontName)); | |
359 | else | |
360 |
1
1. getFontBaseType : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
dic.put(PdfName.BASEFONT, new PdfName(subsetPrefix + fontName)); |
361 | //dic.put(PdfName.BASEFONT, new PdfName(fontName)); | |
362 |
1
1. getFontBaseType : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
dic.put(PdfName.ENCODING, new PdfName(encoding)); |
363 |
1
1. getFontBaseType : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
dic.put(PdfName.DESCENDANTFONTS, new PdfArray(descendant)); |
364 |
1
1. getFontBaseType : negated conditional → NO_COVERAGE |
if (toUnicode != null) |
365 |
1
1. getFontBaseType : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
dic.put(PdfName.TOUNICODE, toUnicode); |
366 |
1
1. getFontBaseType : mutated return of Object value for com/lowagie/text/pdf/TrueTypeFontUnicode::getFontBaseType to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return dic; |
367 | } | |
368 | ||
369 | /** The method used to sort the metrics array. | |
370 | * @param o1 the first element | |
371 | * @param o2 the second element | |
372 | * @return the comparison | |
373 | */ | |
374 | public int compare(Object o1, Object o2) { | |
375 | int m1 = ((int[])o1)[0]; | |
376 | int m2 = ((int[])o2)[0]; | |
377 |
1
1. compare : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return Integer.compare(m1, m2); |
378 | } | |
379 | | |
380 | private static final byte[] rotbits = {(byte)0x80,(byte)0x40,(byte)0x20,(byte)0x10,(byte)0x08,(byte)0x04,(byte)0x02,(byte)0x01}; | |
381 | | |
382 | /** Outputs to the writer the font dictionaries and streams. | |
383 | * @param writer the writer for this document | |
384 | * @param ref the font indirect reference | |
385 | * @param params several parameters that depend on the font type | |
386 | * @throws IOException on error | |
387 | * @throws DocumentException error in generating the object | |
388 | */ | |
389 | void writeFont(PdfWriter writer, PdfIndirectReference ref, Object[] params) throws DocumentException, IOException { | |
390 | HashMap longTag = (HashMap)params[0]; | |
391 |
1
1. writeFont : removed call to com/lowagie/text/pdf/TrueTypeFontUnicode::addRangeUni → NO_COVERAGE |
addRangeUni(longTag, true, subset); |
392 | Object[] metrics = longTag.values().toArray(); | |
393 |
1
1. writeFont : removed call to java/util/Arrays::sort → NO_COVERAGE |
Arrays.sort(metrics, this); |
394 | PdfIndirectReference ind_font = null; | |
395 | PdfObject pobj = null; | |
396 | PdfIndirectObject obj = null; | |
397 | PdfIndirectReference cidset = null; | |
398 |
2
1. writeFont : negated conditional → NO_COVERAGE 2. writeFont : negated conditional → NO_COVERAGE |
if (writer.getPDFXConformance() == PdfWriter.PDFA1A || writer.getPDFXConformance() == PdfWriter.PDFA1B) { |
399 | PdfStream stream; | |
400 |
1
1. writeFont : negated conditional → NO_COVERAGE |
if (metrics.length == 0) { |
401 | stream = new PdfStream(new byte[]{(byte)0x80}); | |
402 | } | |
403 | else { | |
404 |
1
1. writeFont : Replaced integer subtraction with addition → NO_COVERAGE |
int top = ((int[])metrics[metrics.length - 1])[0]; |
405 |
2
1. writeFont : Replaced integer division with multiplication → NO_COVERAGE 2. writeFont : Replaced integer addition with subtraction → NO_COVERAGE |
byte[] bt = new byte[top / 8 + 1]; |
406 | for (Object metric : metrics) { | |
407 | int v = ((int[]) metric)[0]; | |
408 |
3
1. writeFont : Replaced integer division with multiplication → NO_COVERAGE 2. writeFont : Replaced integer modulus with multiplication → NO_COVERAGE 3. writeFont : Replaced bitwise OR with AND → NO_COVERAGE |
bt[v / 8] |= rotbits[v % 8]; |
409 | } | |
410 | stream = new PdfStream(bt); | |
411 |
1
1. writeFont : removed call to com/lowagie/text/pdf/PdfStream::flateCompress → NO_COVERAGE |
stream.flateCompress(compressionLevel); |
412 | } | |
413 | cidset = writer.addToBody(stream).getIndirectReference(); | |
414 | } | |
415 | // sivan: cff | |
416 |
1
1. writeFont : negated conditional → NO_COVERAGE |
if (cff) { |
417 | byte[] b = readCffFont(); | |
418 |
2
1. writeFont : negated conditional → NO_COVERAGE 2. writeFont : negated conditional → NO_COVERAGE |
if (subset || subsetRanges != null) { |
419 | CFFFontSubset cff = new CFFFontSubset(new RandomAccessFileOrArray(b),longTag); | |
420 | b = cff.Process(cff.getNames()[0]); | |
421 | } | |
422 | pobj = new StreamFont(b, "CIDFontType0C", compressionLevel); | |
423 | obj = writer.addToBody(pobj); | |
424 | ind_font = obj.getIndirectReference(); | |
425 | } else { | |
426 | byte[] b; | |
427 |
2
1. writeFont : negated conditional → NO_COVERAGE 2. writeFont : negated conditional → NO_COVERAGE |
if (subset || directoryOffset != 0) { |
428 | TrueTypeFontSubSet sb = new TrueTypeFontSubSet(fileName, new RandomAccessFileOrArray(rf), longTag, directoryOffset, false, false); | |
429 | b = sb.process(); | |
430 | } | |
431 | else { | |
432 | b = getFullFont(); | |
433 | } | |
434 | int[] lengths = new int[]{b.length}; | |
435 | pobj = new StreamFont(b, lengths, compressionLevel); | |
436 | obj = writer.addToBody(pobj); | |
437 | ind_font = obj.getIndirectReference(); | |
438 | } | |
439 | String subsetPrefix = ""; | |
440 |
1
1. writeFont : negated conditional → NO_COVERAGE |
if (subset) |
441 | subsetPrefix = createSubsetPrefix(); | |
442 | PdfDictionary dic = getFontDescriptor(ind_font, subsetPrefix, cidset); | |
443 | obj = writer.addToBody(dic); | |
444 | ind_font = obj.getIndirectReference(); | |
445 | ||
446 | pobj = getCIDFontType2(ind_font, subsetPrefix, metrics); | |
447 | obj = writer.addToBody(pobj); | |
448 | ind_font = obj.getIndirectReference(); | |
449 | ||
450 | pobj = getToUnicode(metrics); | |
451 | PdfIndirectReference toUnicodeRef = null; | |
452 | | |
453 |
1
1. writeFont : negated conditional → NO_COVERAGE |
if (pobj != null) { |
454 | obj = writer.addToBody(pobj); | |
455 | toUnicodeRef = obj.getIndirectReference(); | |
456 | } | |
457 | ||
458 | pobj = getFontBaseType(ind_font, subsetPrefix, toUnicodeRef); | |
459 | writer.addToBody(pobj, ref); | |
460 | } | |
461 | | |
462 | /** | |
463 | * Returns a PdfStream object with the full font program. | |
464 | * @return a PdfStream with the font program | |
465 | * @since 2.1.3 | |
466 | */ | |
467 | public PdfStream getFullFontStream() throws IOException, DocumentException { | |
468 |
1
1. getFullFontStream : negated conditional → NO_COVERAGE |
if (cff) { |
469 |
1
1. getFullFontStream : mutated return of Object value for com/lowagie/text/pdf/TrueTypeFontUnicode::getFullFontStream to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return new StreamFont(readCffFont(), "CIDFontType0C", compressionLevel); |
470 | } | |
471 |
1
1. getFullFontStream : mutated return of Object value for com/lowagie/text/pdf/TrueTypeFontUnicode::getFullFontStream to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return super.getFullFontStream(); |
472 | } | |
473 | | |
474 | /** A forbidden operation. Will throw a null pointer exception. | |
475 | * @param text the text | |
476 | * @return always <CODE>null</CODE> | |
477 | */ | |
478 | byte[] convertToBytes(String text) { | |
479 | return null; | |
480 | } | |
481 | ||
482 | byte[] convertToBytes(int char1) { | |
483 | return null; | |
484 | } | |
485 | ||
486 | /** Gets the glyph index and metrics for a character. | |
487 | * @param c the character | |
488 | * @return an <CODE>int</CODE> array with {glyph index, width} | |
489 | */ | |
490 | public int[] getMetricsTT(int c) { | |
491 |
1
1. getMetricsTT : negated conditional → NO_COVERAGE |
if (cmapExt != null) |
492 |
1
1. getMetricsTT : mutated return of Object value for com/lowagie/text/pdf/TrueTypeFontUnicode::getMetricsTT to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return (int[])cmapExt.get(c); |
493 | HashMap map = null; | |
494 |
1
1. getMetricsTT : negated conditional → NO_COVERAGE |
if (fontSpecific) |
495 | map = cmap10; | |
496 | else | |
497 | map = cmap31; | |
498 |
1
1. getMetricsTT : negated conditional → NO_COVERAGE |
if (map == null) |
499 |
1
1. getMetricsTT : mutated return of Object value for com/lowagie/text/pdf/TrueTypeFontUnicode::getMetricsTT to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return null; |
500 |
1
1. getMetricsTT : negated conditional → NO_COVERAGE |
if (fontSpecific) { |
501 |
4
1. getMetricsTT : Replaced bitwise AND with OR → NO_COVERAGE 2. getMetricsTT : Replaced bitwise AND with OR → NO_COVERAGE 3. getMetricsTT : negated conditional → NO_COVERAGE 4. getMetricsTT : negated conditional → NO_COVERAGE |
if ((c & 0xffffff00) == 0 || (c & 0xffffff00) == 0xf000) |
502 |
2
1. getMetricsTT : Replaced bitwise AND with OR → NO_COVERAGE 2. getMetricsTT : mutated return of Object value for com/lowagie/text/pdf/TrueTypeFontUnicode::getMetricsTT to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return (int[])map.get(c & 0xff); |
503 | else | |
504 |
1
1. getMetricsTT : mutated return of Object value for com/lowagie/text/pdf/TrueTypeFontUnicode::getMetricsTT to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return null; |
505 | } | |
506 | else | |
507 |
1
1. getMetricsTT : mutated return of Object value for com/lowagie/text/pdf/TrueTypeFontUnicode::getMetricsTT to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return (int[])map.get(c); |
508 | } | |
509 | | |
510 | /** | |
511 | * Checks if a character exists in this font. | |
512 | * @param c the character to check | |
513 | * @return <CODE>true</CODE> if the character has a glyph, | |
514 | * <CODE>false</CODE> otherwise | |
515 | */ | |
516 | public boolean charExists(int c) { | |
517 |
2
1. charExists : negated conditional → NO_COVERAGE 2. charExists : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return getMetricsTT(c) != null; |
518 | } | |
519 | | |
520 | /** | |
521 | * Sets the character advance. | |
522 | * @param c the character | |
523 | * @param advance the character advance normalized to 1000 units | |
524 | * @return <CODE>true</CODE> if the advance was set, | |
525 | * <CODE>false</CODE> otherwise | |
526 | */ | |
527 | public boolean setCharAdvance(int c, int advance) { | |
528 | int[] m = getMetricsTT(c); | |
529 |
1
1. setCharAdvance : negated conditional → NO_COVERAGE |
if (m == null) |
530 |
1
1. setCharAdvance : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return false; |
531 | m[1] = advance; | |
532 |
1
1. setCharAdvance : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return true; |
533 | } | |
534 | | |
535 | public int[] getCharBBox(int c) { | |
536 |
1
1. getCharBBox : negated conditional → NO_COVERAGE |
if (bboxes == null) |
537 |
1
1. getCharBBox : mutated return of Object value for com/lowagie/text/pdf/TrueTypeFontUnicode::getCharBBox to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return null; |
538 | int[] m = getMetricsTT(c); | |
539 |
1
1. getCharBBox : negated conditional → NO_COVERAGE |
if (m == null) |
540 |
1
1. getCharBBox : mutated return of Object value for com/lowagie/text/pdf/TrueTypeFontUnicode::getCharBBox to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return null; |
541 |
1
1. getCharBBox : mutated return of Object value for com/lowagie/text/pdf/TrueTypeFontUnicode::getCharBBox to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return bboxes[m[0]]; |
542 | } | |
543 | } | |
Mutations | ||
93 |
1.1 2.2 |
|
100 |
1.1 2.2 |
|
101 |
1.1 |
|
103 |
1.1 2.2 3.3 4.4 5.5 6.6 |
|
104 |
1.1 |
|
105 |
1.1 |
|
108 |
1.1 2.2 3.3 4.4 |
|
111 |
1.1 |
|
115 |
1.1 |
|
126 |
1.1 |
|
129 |
1.1 |
|
131 |
1.1 |
|
135 |
1.1 |
|
147 |
1.1 2.2 |
|
157 |
1.1 |
|
158 |
1.1 |
|
159 |
1.1 |
|
160 |
1.1 2.2 3.3 4.4 |
|
161 |
1.1 2.2 |
|
163 |
1.1 |
|
166 |
1.1 |
|
176 |
1.1 |
|
177 |
1.1 2.2 |
|
179 |
1.1 |
|
183 |
1.1 2.2 3.3 4.4 |
|
184 |
1.1 2.2 |
|
189 |
1.1 2.2 3.3 |
|
190 |
1.1 |
|
191 |
1.1 |
|
192 |
1.1 |
|
195 |
1.1 |
|
198 |
1.1 |
|
208 |
1.1 |
|
209 |
1.1 |
|
225 |
1.1 2.2 3.3 |
|
226 |
1.1 |
|
227 |
1.1 |
|
230 |
1.1 |
|
233 |
1.1 |
|
245 |
1.1 |
|
246 |
1.1 |
|
250 |
1.1 |
|
251 |
1.1 |
|
261 |
1.1 2.2 |
|
266 |
1.1 |
|
267 |
1.1 |
|
270 |
1.1 |
|
275 |
1.1 2.2 |
|
283 |
1.1 2.2 |
|
284 |
1.1 |
|
285 |
1.1 |
|
286 |
1.1 2.2 |
|
287 |
1.1 2.2 |
|
288 |
1.1 |
|
300 |
1.1 |
|
301 |
1.1 |
|
302 |
1.1 |
|
305 |
1.1 |
|
306 |
1.1 |
|
308 |
1.1 |
|
309 |
1.1 |
|
310 |
1.1 |
|
312 |
1.1 |
|
313 |
1.1 |
|
314 |
1.1 |
|
315 |
1.1 |
|
316 |
1.1 |
|
317 |
1.1 |
|
323 |
1.1 |
|
326 |
1.1 2.2 |
|
329 |
1.1 |
|
337 |
1.1 2.2 |
|
339 |
1.1 |
|
342 |
1.1 |
|
354 |
1.1 |
|
356 |
1.1 |
|
357 |
1.1 |
|
360 |
1.1 |
|
362 |
1.1 |
|
363 |
1.1 |
|
364 |
1.1 |
|
365 |
1.1 |
|
366 |
1.1 |
|
377 |
1.1 |
|
391 |
1.1 |
|
393 |
1.1 |
|
398 |
1.1 2.2 |
|
400 |
1.1 |
|
404 |
1.1 |
|
405 |
1.1 2.2 |
|
408 |
1.1 2.2 3.3 |
|
411 |
1.1 |
|
416 |
1.1 |
|
418 |
1.1 2.2 |
|
427 |
1.1 2.2 |
|
440 |
1.1 |
|
453 |
1.1 |
|
468 |
1.1 |
|
469 |
1.1 |
|
471 |
1.1 |
|
491 |
1.1 |
|
492 |
1.1 |
|
494 |
1.1 |
|
498 |
1.1 |
|
499 |
1.1 |
|
500 |
1.1 |
|
501 |
1.1 2.2 3.3 4.4 |
|
502 |
1.1 2.2 |
|
504 |
1.1 |
|
507 |
1.1 |
|
517 |
1.1 2.2 |
|
529 |
1.1 |
|
530 |
1.1 |
|
532 |
1.1 |
|
536 |
1.1 |
|
537 |
1.1 |
|
539 |
1.1 |
|
540 |
1.1 |
|
541 |
1.1 |