1 | /* | |
2 | * | |
3 | * Copyright 2003 Sivan Toledo | |
4 | * | |
5 | * The contents of this file are subject to the Mozilla Public License Version 1.1 | |
6 | * (the "License"); you may not use this file except in compliance with the License. | |
7 | * You may obtain a copy of the License at http://www.mozilla.org/MPL/ | |
8 | * | |
9 | * Software distributed under the License is distributed on an "AS IS" basis, | |
10 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | |
11 | * for the specific language governing rights and limitations under the License. | |
12 | * | |
13 | * Contributor(s): all the names of the contributors are added in the source code | |
14 | * where applicable. | |
15 | * | |
16 | * Alternatively, the contents of this file may be used under the terms of the | |
17 | * LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the | |
18 | * provisions of LGPL are applicable instead of those above. If you wish to | |
19 | * allow use of your version of this file only under the terms of the LGPL | |
20 | * License and not to allow others to use your version of this file under | |
21 | * the MPL, indicate your decision by deleting the provisions above and | |
22 | * replace them with the notice and other provisions required by the LGPL. | |
23 | * If you do not delete the provisions above, a recipient may use your version | |
24 | * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE. | |
25 | * | |
26 | * This library is free software; you can redistribute it and/or modify it | |
27 | * under the terms of the MPL as stated above or under the terms of the GNU | |
28 | * Library General Public License as published by the Free Software Foundation; | |
29 | * either version 2 of the License, or any later version. | |
30 | * | |
31 | * This library is distributed in the hope that it will be useful, but WITHOUT | |
32 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | |
33 | * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more | |
34 | * details. | |
35 | * | |
36 | */ | |
37 | ||
38 | /* | |
39 | * Comments by Sivan Toledo: | |
40 | * I created this class in order to add to iText the ability to utilize | |
41 | * OpenType fonts with CFF glyphs (these usually have an .otf extension). | |
42 | * The CFF font within the CFF table of the OT font might be either a CID | |
43 | * or a Type1 font. (CFF fonts may also contain multiple fonts; I do not | |
44 | * know if this is allowed in an OT table). The PDF spec, however, only | |
45 | * allow a CID font with an Identity-H or Identity-V encoding. Otherwise, | |
46 | * you are limited to an 8-bit encoding. | |
47 | * Adobe fonts come in both flavors. That is, the OTFs sometimes have | |
48 | * a CID CFF inside (for Japanese fonts), and sometimes a Type1 CFF | |
49 | * (virtually all the others, Latin/Greek/Cyrillic). So to easily use | |
50 | * all the glyphs in the latter, without creating multiple 8-bit encoding, | |
51 | * I wrote this class, whose main purpose is to convert a Type1 font inside | |
52 | * a CFF container (which might include other fonts) into a CID CFF font | |
53 | * that can be directly embeded in the PDF. | |
54 | * | |
55 | * Limitations of the current version: | |
56 | * 1. It does not extract a single CID font from a CFF that contains that | |
57 | * particular CID along with other fonts. The Adobe Japanese OTF's that | |
58 | * I have only have one font in the CFF table, so these can be | |
59 | * embeded in the PDF as is. | |
60 | * 2. It does not yet subset fonts. | |
61 | * 3. It may or may not work on CFF fonts that are not within OTF's. | |
62 | * I didn't try that. In any case, that would probably only be | |
63 | * useful for subsetting CID fonts, not for CFF Type1 fonts (I don't | |
64 | * think there are any available. | |
65 | * I plan to extend the class to support these three features at some | |
66 | * future time. | |
67 | */ | |
68 | ||
69 | package com.lowagie.text.pdf; | |
70 | ||
71 | import com.lowagie.text.ExceptionConverter; | |
72 | ||
73 | import java.util.Iterator; | |
74 | import java.util.LinkedList; | |
75 | import java.util.Objects; | |
76 | ||
77 | ||
78 | public class CFFFont { | |
79 | ||
80 | static final String[] operatorNames = { | |
81 | "version", "Notice", "FullName", "FamilyName", | |
82 | "Weight", "FontBBox", "BlueValues", "OtherBlues", | |
83 | "FamilyBlues", "FamilyOtherBlues", "StdHW", "StdVW", | |
84 | "UNKNOWN_12", "UniqueID", "XUID", "charset", | |
85 | "Encoding", "CharStrings", "Private", "Subrs", | |
86 | "defaultWidthX", "nominalWidthX", "UNKNOWN_22", "UNKNOWN_23", | |
87 | "UNKNOWN_24", "UNKNOWN_25", "UNKNOWN_26", "UNKNOWN_27", | |
88 | "UNKNOWN_28", "UNKNOWN_29", "UNKNOWN_30", "UNKNOWN_31", | |
89 | "Copyright", "isFixedPitch", "ItalicAngle", "UnderlinePosition", | |
90 | "UnderlineThickness", "PaintType", "CharstringType", "FontMatrix", | |
91 | "StrokeWidth", "BlueScale", "BlueShift", "BlueFuzz", | |
92 | "StemSnapH", "StemSnapV", "ForceBold", "UNKNOWN_12_15", | |
93 | "UNKNOWN_12_16", "LanguageGroup", "ExpansionFactor", "initialRandomSeed", | |
94 | "SyntheticBase", "PostScript", "BaseFontName", "BaseFontBlend", | |
95 | "UNKNOWN_12_24", "UNKNOWN_12_25", "UNKNOWN_12_26", "UNKNOWN_12_27", | |
96 | "UNKNOWN_12_28", "UNKNOWN_12_29", "ROS", "CIDFontVersion", | |
97 | "CIDFontRevision", "CIDFontType", "CIDCount", "UIDBase", | |
98 | "FDArray", "FDSelect", "FontName" | |
99 | }; | |
100 | ||
101 | static final String[] standardStrings = { | |
102 | // Automatically generated from Appendix A of the CFF specification; do | |
103 | // not edit. Size should be 391. | |
104 | ".notdef", "space", "exclam", "quotedbl", "numbersign", "dollar", | |
105 | "percent", "ampersand", "quoteright", "parenleft", "parenright", | |
106 | "asterisk", "plus", "comma", "hyphen", "period", "slash", "zero", "one", | |
107 | "two", "three", "four", "five", "six", "seven", "eight", "nine", "colon", | |
108 | "semicolon", "less", "equal", "greater", "question", "at", "A", "B", "C", | |
109 | "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", | |
110 | "S", "T", "U", "V", "W", "X", "Y", "Z", "bracketleft", "backslash", | |
111 | "bracketright", "asciicircum", "underscore", "quoteleft", "a", "b", "c", | |
112 | "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", | |
113 | "s", "t", "u", "v", "w", "x", "y", "z", "braceleft", "bar", "braceright", | |
114 | "asciitilde", "exclamdown", "cent", "sterling", "fraction", "yen", | |
115 | "florin", "section", "currency", "quotesingle", "quotedblleft", | |
116 | "guillemotleft", "guilsinglleft", "guilsinglright", "fi", "fl", "endash", | |
117 | "dagger", "daggerdbl", "periodcentered", "paragraph", "bullet", | |
118 | "quotesinglbase", "quotedblbase", "quotedblright", "guillemotright", | |
119 | "ellipsis", "perthousand", "questiondown", "grave", "acute", "circumflex", | |
120 | "tilde", "macron", "breve", "dotaccent", "dieresis", "ring", "cedilla", | |
121 | "hungarumlaut", "ogonek", "caron", "emdash", "AE", "ordfeminine", "Lslash", | |
122 | "Oslash", "OE", "ordmasculine", "ae", "dotlessi", "lslash", "oslash", "oe", | |
123 | "germandbls", "onesuperior", "logicalnot", "mu", "trademark", "Eth", | |
124 | "onehalf", "plusminus", "Thorn", "onequarter", "divide", "brokenbar", | |
125 | "degree", "thorn", "threequarters", "twosuperior", "registered", "minus", | |
126 | "eth", "multiply", "threesuperior", "copyright", "Aacute", "Acircumflex", | |
127 | "Adieresis", "Agrave", "Aring", "Atilde", "Ccedilla", "Eacute", | |
128 | "Ecircumflex", "Edieresis", "Egrave", "Iacute", "Icircumflex", "Idieresis", | |
129 | "Igrave", "Ntilde", "Oacute", "Ocircumflex", "Odieresis", "Ograve", | |
130 | "Otilde", "Scaron", "Uacute", "Ucircumflex", "Udieresis", "Ugrave", | |
131 | "Yacute", "Ydieresis", "Zcaron", "aacute", "acircumflex", "adieresis", | |
132 | "agrave", "aring", "atilde", "ccedilla", "eacute", "ecircumflex", | |
133 | "edieresis", "egrave", "iacute", "icircumflex", "idieresis", "igrave", | |
134 | "ntilde", "oacute", "ocircumflex", "odieresis", "ograve", "otilde", | |
135 | "scaron", "uacute", "ucircumflex", "udieresis", "ugrave", "yacute", | |
136 | "ydieresis", "zcaron", "exclamsmall", "Hungarumlautsmall", | |
137 | "dollaroldstyle", "dollarsuperior", "ampersandsmall", "Acutesmall", | |
138 | "parenleftsuperior", "parenrightsuperior", "twodotenleader", | |
139 | "onedotenleader", "zerooldstyle", "oneoldstyle", "twooldstyle", | |
140 | "threeoldstyle", "fouroldstyle", "fiveoldstyle", "sixoldstyle", | |
141 | "sevenoldstyle", "eightoldstyle", "nineoldstyle", "commasuperior", | |
142 | "threequartersemdash", "periodsuperior", "questionsmall", "asuperior", | |
143 | "bsuperior", "centsuperior", "dsuperior", "esuperior", "isuperior", | |
144 | "lsuperior", "msuperior", "nsuperior", "osuperior", "rsuperior", | |
145 | "ssuperior", "tsuperior", "ff", "ffi", "ffl", "parenleftinferior", | |
146 | "parenrightinferior", "Circumflexsmall", "hyphensuperior", "Gravesmall", | |
147 | "Asmall", "Bsmall", "Csmall", "Dsmall", "Esmall", "Fsmall", "Gsmall", | |
148 | "Hsmall", "Ismall", "Jsmall", "Ksmall", "Lsmall", "Msmall", "Nsmall", | |
149 | "Osmall", "Psmall", "Qsmall", "Rsmall", "Ssmall", "Tsmall", "Usmall", | |
150 | "Vsmall", "Wsmall", "Xsmall", "Ysmall", "Zsmall", "colonmonetary", | |
151 | "onefitted", "rupiah", "Tildesmall", "exclamdownsmall", "centoldstyle", | |
152 | "Lslashsmall", "Scaronsmall", "Zcaronsmall", "Dieresissmall", "Brevesmall", | |
153 | "Caronsmall", "Dotaccentsmall", "Macronsmall", "figuredash", | |
154 | "hypheninferior", "Ogoneksmall", "Ringsmall", "Cedillasmall", | |
155 | "questiondownsmall", "oneeighth", "threeeighths", "fiveeighths", | |
156 | "seveneighths", "onethird", "twothirds", "zerosuperior", "foursuperior", | |
157 | "fivesuperior", "sixsuperior", "sevensuperior", "eightsuperior", | |
158 | "ninesuperior", "zeroinferior", "oneinferior", "twoinferior", | |
159 | "threeinferior", "fourinferior", "fiveinferior", "sixinferior", | |
160 | "seveninferior", "eightinferior", "nineinferior", "centinferior", | |
161 | "dollarinferior", "periodinferior", "commainferior", "Agravesmall", | |
162 | "Aacutesmall", "Acircumflexsmall", "Atildesmall", "Adieresissmall", | |
163 | "Aringsmall", "AEsmall", "Ccedillasmall", "Egravesmall", "Eacutesmall", | |
164 | "Ecircumflexsmall", "Edieresissmall", "Igravesmall", "Iacutesmall", | |
165 | "Icircumflexsmall", "Idieresissmall", "Ethsmall", "Ntildesmall", | |
166 | "Ogravesmall", "Oacutesmall", "Ocircumflexsmall", "Otildesmall", | |
167 | "Odieresissmall", "OEsmall", "Oslashsmall", "Ugravesmall", "Uacutesmall", | |
168 | "Ucircumflexsmall", "Udieresissmall", "Yacutesmall", "Thornsmall", | |
169 | "Ydieresissmall", "001.000", "001.001", "001.002", "001.003", "Black", | |
170 | "Bold", "Book", "Light", "Medium", "Regular", "Roman", "Semibold" | |
171 | }; | |
172 | | |
173 | //private String[] strings; | |
174 | public String getString(char sid) { | |
175 |
3
1. getString : changed conditional boundary → NO_COVERAGE 2. getString : negated conditional → NO_COVERAGE 3. getString : mutated return of Object value for com/lowagie/text/pdf/CFFFont::getString to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
if (sid < standardStrings.length) return standardStrings[sid]; |
176 |
5
1. getString : changed conditional boundary → NO_COVERAGE 2. getString : Replaced integer subtraction with addition → NO_COVERAGE 3. getString : Replaced integer addition with subtraction → NO_COVERAGE 4. getString : negated conditional → NO_COVERAGE 5. getString : mutated return of Object value for com/lowagie/text/pdf/CFFFont::getString to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
if (sid >= standardStrings.length+(stringOffsets.length-1)) return null; |
177 |
1
1. getString : Replaced integer subtraction with addition → NO_COVERAGE |
int j = sid - standardStrings.length; |
178 | //java.lang.System.err.println("going for "+j); | |
179 | int p = getPosition(); | |
180 |
1
1. getString : removed call to com/lowagie/text/pdf/CFFFont::seek → NO_COVERAGE |
seek(stringOffsets[j]); |
181 | StringBuilder s = new StringBuilder(); | |
182 |
4
1. getString : changed conditional boundary → NO_COVERAGE 2. getString : Changed increment from 1 to -1 → NO_COVERAGE 3. getString : Replaced integer addition with subtraction → NO_COVERAGE 4. getString : negated conditional → NO_COVERAGE |
for (int k=stringOffsets[j]; k<stringOffsets[j+1]; k++) { |
183 | s.append(getCard8()); | |
184 | } | |
185 |
1
1. getString : removed call to com/lowagie/text/pdf/CFFFont::seek → NO_COVERAGE |
seek(p); |
186 |
1
1. getString : mutated return of Object value for com/lowagie/text/pdf/CFFFont::getString to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return s.toString(); |
187 | } | |
188 | | |
189 | char getCard8() { | |
190 | try { | |
191 | byte i = buf.readByte(); | |
192 |
2
1. getCard8 : Replaced bitwise AND with OR → NO_COVERAGE 2. getCard8 : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return (char)(i & 0xff); |
193 | } | |
194 | catch (Exception e) { | |
195 | throw new ExceptionConverter(e); | |
196 | } | |
197 | } | |
198 | | |
199 | char getCard16() { | |
200 | try { | |
201 |
1
1. getCard16 : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return buf.readChar(); |
202 | } | |
203 | catch (Exception e) { | |
204 | throw new ExceptionConverter(e); | |
205 | } | |
206 | } | |
207 | | |
208 | int getOffset(int offSize) { | |
209 | int offset = 0; | |
210 |
3
1. getOffset : changed conditional boundary → NO_COVERAGE 2. getOffset : Changed increment from 1 to -1 → NO_COVERAGE 3. getOffset : negated conditional → NO_COVERAGE |
for (int i=0; i<offSize; i++) { |
211 |
1
1. getOffset : Replaced integer multiplication with division → NO_COVERAGE |
offset *= 256; |
212 |
1
1. getOffset : Replaced integer addition with subtraction → NO_COVERAGE |
offset += getCard8(); |
213 | } | |
214 |
1
1. getOffset : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return offset; |
215 | } | |
216 | | |
217 | void seek(int offset) { | |
218 | try { | |
219 |
1
1. seek : removed call to com/lowagie/text/pdf/RandomAccessFileOrArray::seek → NO_COVERAGE |
buf.seek(offset); |
220 | } | |
221 | catch (Exception e) { | |
222 | throw new ExceptionConverter(e); | |
223 | } | |
224 | } | |
225 | | |
226 | short getShort() { | |
227 | try { | |
228 |
1
1. getShort : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return buf.readShort(); |
229 | } | |
230 | catch (Exception e) { | |
231 | throw new ExceptionConverter(e); | |
232 | } | |
233 | } | |
234 | | |
235 | int getInt() { | |
236 | try { | |
237 |
1
1. getInt : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return buf.readInt(); |
238 | } | |
239 | catch (Exception e) { | |
240 | throw new ExceptionConverter(e); | |
241 | } | |
242 | } | |
243 | | |
244 | int getPosition() { | |
245 | try { | |
246 |
1
1. getPosition : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return buf.getFilePointer(); |
247 | } | |
248 | catch (Exception e) { | |
249 | throw new ExceptionConverter(e); | |
250 | } | |
251 | } | |
252 | int nextIndexOffset; | |
253 | // read the offsets in the next index | |
254 | // data structure, convert to global | |
255 | // offsets, and return them. | |
256 | // Sets the nextIndexOffset. | |
257 | int[] getIndex(int nextIndexOffset) { | |
258 | int count, indexOffSize; | |
259 | | |
260 |
1
1. getIndex : removed call to com/lowagie/text/pdf/CFFFont::seek → NO_COVERAGE |
seek(nextIndexOffset); |
261 | count = getCard16(); | |
262 |
1
1. getIndex : Replaced integer addition with subtraction → NO_COVERAGE |
int[] offsets = new int[count+1]; |
263 | | |
264 |
1
1. getIndex : negated conditional → NO_COVERAGE |
if (count==0) { |
265 | offsets[0] = -1; | |
266 |
1
1. getIndex : Changed increment from 2 to -2 → NO_COVERAGE |
nextIndexOffset += 2; |
267 |
1
1. getIndex : mutated return of Object value for com/lowagie/text/pdf/CFFFont::getIndex to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return offsets; |
268 | } | |
269 | | |
270 | indexOffSize = getCard8(); | |
271 | | |
272 |
3
1. getIndex : changed conditional boundary → NO_COVERAGE 2. getIndex : Changed increment from 1 to -1 → NO_COVERAGE 3. getIndex : negated conditional → NO_COVERAGE |
for (int j=0; j<=count; j++) { |
273 | //nextIndexOffset = ofset to relative segment | |
274 |
6
1. getIndex : Replaced integer addition with subtraction → NO_COVERAGE 2. getIndex : Replaced integer addition with subtraction → NO_COVERAGE 3. getIndex : Replaced integer addition with subtraction → NO_COVERAGE 4. getIndex : Replaced integer multiplication with division → NO_COVERAGE 5. getIndex : Replaced integer addition with subtraction → NO_COVERAGE 6. getIndex : Replaced integer subtraction with addition → NO_COVERAGE |
offsets[j] = nextIndexOffset |
275 | //2-> count in the index header. 1->offset size in index header | |
276 | + 2+1 | |
277 | //offset array size * offset size | |
278 | + (count+1)*indexOffSize | |
279 | //???zero <-> one base | |
280 | - 1 | |
281 | // read object offset relative to object array base | |
282 |
1
1. getIndex : Replaced integer addition with subtraction → NO_COVERAGE |
+ getOffset(indexOffSize); |
283 | } | |
284 | //nextIndexOffset = offsets[count]; | |
285 |
1
1. getIndex : mutated return of Object value for com/lowagie/text/pdf/CFFFont::getIndex to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return offsets; |
286 | } | |
287 | | |
288 | protected String key; | |
289 | protected Object[] args = new Object[48]; | |
290 | protected int arg_count = 0; | |
291 | | |
292 | protected void getDictItem() { | |
293 |
3
1. getDictItem : changed conditional boundary → NO_COVERAGE 2. getDictItem : Changed increment from 1 to -1 → NO_COVERAGE 3. getDictItem : negated conditional → NO_COVERAGE |
for (int i=0; i<arg_count; i++) args[i]=null; |
294 | arg_count = 0; | |
295 | key = null; | |
296 | boolean gotKey = false; | |
297 | | |
298 |
1
1. getDictItem : negated conditional → NO_COVERAGE |
while (!gotKey) { |
299 | char b0 = getCard8(); | |
300 |
1
1. getDictItem : negated conditional → NO_COVERAGE |
if (b0 == 29) { |
301 | int item = getInt(); | |
302 | args[arg_count] = item; | |
303 |
1
1. getDictItem : Replaced integer addition with subtraction → NO_COVERAGE |
arg_count++; |
304 | //System.err.println(item+" "); | |
305 | continue; | |
306 | } | |
307 |
1
1. getDictItem : negated conditional → NO_COVERAGE |
if (b0 == 28) { |
308 | short item = getShort(); | |
309 | args[arg_count] = (int) item; | |
310 |
1
1. getDictItem : Replaced integer addition with subtraction → NO_COVERAGE |
arg_count++; |
311 | //System.err.println(item+" "); | |
312 | continue; | |
313 | } | |
314 |
4
1. getDictItem : changed conditional boundary → NO_COVERAGE 2. getDictItem : changed conditional boundary → NO_COVERAGE 3. getDictItem : negated conditional → NO_COVERAGE 4. getDictItem : negated conditional → NO_COVERAGE |
if (b0 >= 32 && b0 <= 246) { |
315 |
1
1. getDictItem : Replaced integer subtraction with addition → NO_COVERAGE |
byte item = (byte) (b0-139); |
316 | args[arg_count] = (int) item; | |
317 |
1
1. getDictItem : Replaced integer addition with subtraction → NO_COVERAGE |
arg_count++; |
318 | //System.err.println(item+" "); | |
319 | continue; | |
320 | } | |
321 |
4
1. getDictItem : changed conditional boundary → NO_COVERAGE 2. getDictItem : changed conditional boundary → NO_COVERAGE 3. getDictItem : negated conditional → NO_COVERAGE 4. getDictItem : negated conditional → NO_COVERAGE |
if (b0 >= 247 && b0 <= 250) { |
322 | char b1 = getCard8(); | |
323 |
4
1. getDictItem : Replaced integer subtraction with addition → NO_COVERAGE 2. getDictItem : Replaced integer multiplication with division → NO_COVERAGE 3. getDictItem : Replaced integer addition with subtraction → NO_COVERAGE 4. getDictItem : Replaced integer addition with subtraction → NO_COVERAGE |
short item = (short) ((b0-247)*256+b1+108); |
324 | args[arg_count] = (int) item; | |
325 |
1
1. getDictItem : Replaced integer addition with subtraction → NO_COVERAGE |
arg_count++; |
326 | //System.err.println(item+" "); | |
327 | continue; | |
328 | } | |
329 |
4
1. getDictItem : changed conditional boundary → NO_COVERAGE 2. getDictItem : changed conditional boundary → NO_COVERAGE 3. getDictItem : negated conditional → NO_COVERAGE 4. getDictItem : negated conditional → NO_COVERAGE |
if (b0 >= 251 && b0 <= 254) { |
330 | char b1 = getCard8(); | |
331 |
5
1. getDictItem : removed negation → NO_COVERAGE 2. getDictItem : Replaced integer subtraction with addition → NO_COVERAGE 3. getDictItem : Replaced integer multiplication with division → NO_COVERAGE 4. getDictItem : Replaced integer subtraction with addition → NO_COVERAGE 5. getDictItem : Replaced integer subtraction with addition → NO_COVERAGE |
short item = (short) (-(b0-251)*256-b1-108); |
332 | args[arg_count] = (int) item; | |
333 |
1
1. getDictItem : Replaced integer addition with subtraction → NO_COVERAGE |
arg_count++; |
334 | //System.err.println(item+" "); | |
335 | continue; | |
336 | } | |
337 |
1
1. getDictItem : negated conditional → NO_COVERAGE |
if (b0 == 30) { |
338 | String item = ""; | |
339 | boolean done = false; | |
340 | char buffer = 0; | |
341 | byte avail = 0; | |
342 | int nibble = 0; | |
343 |
1
1. getDictItem : negated conditional → NO_COVERAGE |
while (!done) { |
344 | // get a nibble | |
345 |
1
1. getDictItem : negated conditional → NO_COVERAGE |
if (avail==0) { buffer = getCard8(); avail=2; } |
346 |
3
1. getDictItem : Replaced integer division with multiplication → NO_COVERAGE 2. getDictItem : Replaced integer subtraction with addition → NO_COVERAGE 3. getDictItem : negated conditional → NO_COVERAGE |
if (avail==1) { nibble = (buffer / 16); avail--; } |
347 |
3
1. getDictItem : Replaced integer modulus with multiplication → NO_COVERAGE 2. getDictItem : Replaced integer subtraction with addition → NO_COVERAGE 3. getDictItem : negated conditional → NO_COVERAGE |
if (avail==2) { nibble = (buffer % 16); avail--; } |
348 | switch (nibble) { | |
349 | case 0xa: item += "." ; break; | |
350 | case 0xb: item += "E" ; break; | |
351 | case 0xc: item += "E-"; break; | |
352 | case 0xe: item += "-" ; break; | |
353 | case 0xf: done=true ; break; | |
354 | default: | |
355 |
4
1. getDictItem : changed conditional boundary → NO_COVERAGE 2. getDictItem : changed conditional boundary → NO_COVERAGE 3. getDictItem : negated conditional → NO_COVERAGE 4. getDictItem : negated conditional → NO_COVERAGE |
if (nibble >= 0 && nibble <= 9) |
356 | item += String.valueOf(nibble); | |
357 | else { | |
358 | item += "<NIBBLE ERROR: " + nibble + '>'; | |
359 | done = true; | |
360 | } | |
361 | break; | |
362 | } | |
363 | } | |
364 | args[arg_count] = item; | |
365 |
1
1. getDictItem : Replaced integer addition with subtraction → NO_COVERAGE |
arg_count++; |
366 | //System.err.println(" real=["+item+"]"); | |
367 | continue; | |
368 | } | |
369 |
2
1. getDictItem : changed conditional boundary → NO_COVERAGE 2. getDictItem : negated conditional → NO_COVERAGE |
if (b0 <= 21) { |
370 | gotKey=true; | |
371 |
1
1. getDictItem : negated conditional → NO_COVERAGE |
if (b0 != 12) key = operatorNames[b0]; |
372 |
1
1. getDictItem : Replaced integer addition with subtraction → NO_COVERAGE |
else key = operatorNames[32 + getCard8()]; |
373 | //for (int i=0; i<arg_count; i++) | |
374 | // System.err.print(args[i].toString()+" "); | |
375 | //System.err.println(key+" ;"); | |
376 | continue; | |
377 | } | |
378 | } | |
379 | } | |
380 | | |
381 | /** List items for the linked list that builds the new CID font. | |
382 | */ | |
383 | | |
384 | protected static abstract class Item { | |
385 | protected int myOffset = -1; | |
386 | /** remember the current offset and increment by item's size in bytes. */ | |
387 | public void increment(int[] currentOffset) { | |
388 | myOffset = currentOffset[0]; | |
389 | } | |
390 | /** Emit the byte stream for this item. */ | |
391 | public void emit(byte[] buffer) {} | |
392 | /** Fix up cross references to this item (applies only to markers). */ | |
393 | public void xref() {} | |
394 | } | |
395 | | |
396 | protected static abstract class OffsetItem extends Item { | |
397 | public int value; | |
398 | /** set the value of an offset item that was initially unknown. | |
399 | * It will be fixed up latex by a call to xref on some marker. | |
400 | */ | |
401 | public void set(int offset) { this.value = offset; } | |
402 | } | |
403 | | |
404 | | |
405 | /** A range item. | |
406 | */ | |
407 | | |
408 | protected static final class RangeItem extends Item { | |
409 | public int offset, length; | |
410 | private RandomAccessFileOrArray buf; | |
411 | public RangeItem(RandomAccessFileOrArray buf, int offset, int length) { | |
412 | this.offset = offset; | |
413 | this.length = length; | |
414 | this.buf = buf; | |
415 | } | |
416 | public void increment(int[] currentOffset) { | |
417 |
1
1. increment : removed call to com/lowagie/text/pdf/CFFFont$Item::increment → NO_COVERAGE |
super.increment(currentOffset); |
418 |
1
1. increment : Replaced integer addition with subtraction → NO_COVERAGE |
currentOffset[0] += length; |
419 | } | |
420 | public void emit(byte[] buffer) { | |
421 | //System.err.println("range emit offset "+offset+" size="+length); | |
422 | try { | |
423 |
1
1. emit : removed call to com/lowagie/text/pdf/RandomAccessFileOrArray::seek → NO_COVERAGE |
buf.seek(offset); |
424 |
4
1. emit : changed conditional boundary → NO_COVERAGE 2. emit : Changed increment from 1 to -1 → NO_COVERAGE 3. emit : Replaced integer addition with subtraction → NO_COVERAGE 4. emit : negated conditional → NO_COVERAGE |
for (int i=myOffset; i<myOffset+length; i++) |
425 | buffer[i] = buf.readByte(); | |
426 | } | |
427 | catch (Exception e) { | |
428 | throw new ExceptionConverter(e); | |
429 | } | |
430 | //System.err.println("finished range emit"); | |
431 | } | |
432 | } | |
433 | | |
434 | /** An index-offset item for the list. | |
435 | * The size denotes the required size in the CFF. A positive | |
436 | * value means that we need a specific size in bytes (for offset arrays) | |
437 | * and a negative value means that this is a dict item that uses a | |
438 | * variable-size representation. | |
439 | */ | |
440 | static protected final class IndexOffsetItem extends OffsetItem { | |
441 | public final int size; | |
442 | public IndexOffsetItem(int size, int value) {this.size=size; this.value=value;} | |
443 | public IndexOffsetItem(int size) {this.size=size; } | |
444 | | |
445 | public void increment(int[] currentOffset) { | |
446 |
1
1. increment : removed call to com/lowagie/text/pdf/CFFFont$OffsetItem::increment → NO_COVERAGE |
super.increment(currentOffset); |
447 |
1
1. increment : Replaced integer addition with subtraction → NO_COVERAGE |
currentOffset[0] += size; |
448 | } | |
449 | public void emit(byte[] buffer) { | |
450 | int i=0; | |
451 | switch (size) { | |
452 | case 4: | |
453 |
3
1. emit : Replaced integer addition with subtraction → NO_COVERAGE 2. emit : Replaced Unsigned Shift Right with Shift Left → NO_COVERAGE 3. emit : Replaced bitwise AND with OR → NO_COVERAGE |
buffer[myOffset+i] = (byte) ((value >>> 24) & 0xff); |
454 |
1
1. emit : Changed increment from 1 to -1 → NO_COVERAGE |
i++; |
455 | case 3: | |
456 |
3
1. emit : Replaced integer addition with subtraction → NO_COVERAGE 2. emit : Replaced Unsigned Shift Right with Shift Left → NO_COVERAGE 3. emit : Replaced bitwise AND with OR → NO_COVERAGE |
buffer[myOffset+i] = (byte) ((value >>> 16) & 0xff); |
457 |
1
1. emit : Changed increment from 1 to -1 → NO_COVERAGE |
i++; |
458 | case 2: | |
459 |
3
1. emit : Replaced integer addition with subtraction → NO_COVERAGE 2. emit : Replaced Unsigned Shift Right with Shift Left → NO_COVERAGE 3. emit : Replaced bitwise AND with OR → NO_COVERAGE |
buffer[myOffset+i] = (byte) ((value >>> 8) & 0xff); |
460 |
1
1. emit : Changed increment from 1 to -1 → NO_COVERAGE |
i++; |
461 | case 1: | |
462 |
3
1. emit : Replaced integer addition with subtraction → NO_COVERAGE 2. emit : Replaced Unsigned Shift Right with Shift Left → NO_COVERAGE 3. emit : Replaced bitwise AND with OR → NO_COVERAGE |
buffer[myOffset+i] = (byte) ((value >>> 0) & 0xff); |
463 |
1
1. emit : Changed increment from 1 to -1 → NO_COVERAGE |
i++; |
464 | } | |
465 | /* | |
466 | int mask = 0xff; | |
467 | for (int i=size-1; i>=0; i--) { | |
468 | buffer[myOffset+i] = (byte) (value & mask); | |
469 | mask <<= 8; | |
470 | } | |
471 | */ | |
472 | } | |
473 | } | |
474 | | |
475 | static protected final class IndexBaseItem extends Item { | |
476 | public IndexBaseItem() {} | |
477 | } | |
478 | | |
479 | static protected final class IndexMarkerItem extends Item { | |
480 | private OffsetItem offItem; | |
481 | private IndexBaseItem indexBase; | |
482 | public IndexMarkerItem(OffsetItem offItem, IndexBaseItem indexBase) { | |
483 | this.offItem = offItem; | |
484 | this.indexBase = indexBase; | |
485 | } | |
486 | public void xref() { | |
487 | //System.err.println("index marker item, base="+indexBase.myOffset+" my="+this.myOffset); | |
488 |
3
1. xref : Replaced integer subtraction with addition → NO_COVERAGE 2. xref : Replaced integer addition with subtraction → NO_COVERAGE 3. xref : removed call to com/lowagie/text/pdf/CFFFont$OffsetItem::set → NO_COVERAGE |
offItem.set(this.myOffset-indexBase.myOffset+1); |
489 | } | |
490 | } | |
491 | /** | |
492 | * TODO To change the template for this generated type comment go to | |
493 | * Window - Preferences - Java - Code Generation - Code and Comments | |
494 | */ | |
495 | static protected final class SubrMarkerItem extends Item { | |
496 | private OffsetItem offItem; | |
497 | private IndexBaseItem indexBase; | |
498 | public SubrMarkerItem(OffsetItem offItem, IndexBaseItem indexBase) { | |
499 | this.offItem = offItem; | |
500 | this.indexBase = indexBase; | |
501 | } | |
502 | public void xref() { | |
503 | //System.err.println("index marker item, base="+indexBase.myOffset+" my="+this.myOffset); | |
504 |
2
1. xref : Replaced integer subtraction with addition → NO_COVERAGE 2. xref : removed call to com/lowagie/text/pdf/CFFFont$OffsetItem::set → NO_COVERAGE |
offItem.set(this.myOffset-indexBase.myOffset); |
505 | } | |
506 | } | |
507 | | |
508 | | |
509 | /** an unknown offset in a dictionary for the list. | |
510 | * We will fix up the offset later; for now, assume it's large. | |
511 | */ | |
512 | static protected final class DictOffsetItem extends OffsetItem { | |
513 | public final int size; | |
514 | public DictOffsetItem() {this.size=5; } | |
515 | | |
516 | public void increment(int[] currentOffset) { | |
517 |
1
1. increment : removed call to com/lowagie/text/pdf/CFFFont$OffsetItem::increment → NO_COVERAGE |
super.increment(currentOffset); |
518 |
1
1. increment : Replaced integer addition with subtraction → NO_COVERAGE |
currentOffset[0] += size; |
519 | } | |
520 | // this is incomplete! | |
521 | public void emit(byte[] buffer) { | |
522 |
1
1. emit : negated conditional → NO_COVERAGE |
if (size==5) { |
523 | buffer[myOffset] = 29; | |
524 |
3
1. emit : Replaced integer addition with subtraction → NO_COVERAGE 2. emit : Replaced Unsigned Shift Right with Shift Left → NO_COVERAGE 3. emit : Replaced bitwise AND with OR → NO_COVERAGE |
buffer[myOffset+1] = (byte) ((value >>> 24) & 0xff); |
525 |
3
1. emit : Replaced integer addition with subtraction → NO_COVERAGE 2. emit : Replaced Unsigned Shift Right with Shift Left → NO_COVERAGE 3. emit : Replaced bitwise AND with OR → NO_COVERAGE |
buffer[myOffset+2] = (byte) ((value >>> 16) & 0xff); |
526 |
3
1. emit : Replaced integer addition with subtraction → NO_COVERAGE 2. emit : Replaced Unsigned Shift Right with Shift Left → NO_COVERAGE 3. emit : Replaced bitwise AND with OR → NO_COVERAGE |
buffer[myOffset+3] = (byte) ((value >>> 8) & 0xff); |
527 |
3
1. emit : Replaced integer addition with subtraction → NO_COVERAGE 2. emit : Replaced Unsigned Shift Right with Shift Left → NO_COVERAGE 3. emit : Replaced bitwise AND with OR → NO_COVERAGE |
buffer[myOffset+4] = (byte) ((value >>> 0) & 0xff); |
528 | } | |
529 | } | |
530 | } | |
531 | | |
532 | /** Card24 item. | |
533 | */ | |
534 | | |
535 | static protected final class UInt24Item extends Item { | |
536 | public int value; | |
537 | public UInt24Item(int value) {this.value=value;} | |
538 | | |
539 | public void increment(int[] currentOffset) { | |
540 |
1
1. increment : removed call to com/lowagie/text/pdf/CFFFont$Item::increment → NO_COVERAGE |
super.increment(currentOffset); |
541 |
1
1. increment : Replaced integer addition with subtraction → NO_COVERAGE |
currentOffset[0] += 3; |
542 | } | |
543 | // this is incomplete! | |
544 | public void emit(byte[] buffer) { | |
545 |
3
1. emit : Replaced integer addition with subtraction → NO_COVERAGE 2. emit : Replaced Unsigned Shift Right with Shift Left → NO_COVERAGE 3. emit : Replaced bitwise AND with OR → NO_COVERAGE |
buffer[myOffset+0] = (byte) ((value >>> 16) & 0xff); |
546 |
3
1. emit : Replaced integer addition with subtraction → NO_COVERAGE 2. emit : Replaced Unsigned Shift Right with Shift Left → NO_COVERAGE 3. emit : Replaced bitwise AND with OR → NO_COVERAGE |
buffer[myOffset+1] = (byte) ((value >>> 8) & 0xff); |
547 |
3
1. emit : Replaced integer addition with subtraction → NO_COVERAGE 2. emit : Replaced Unsigned Shift Right with Shift Left → NO_COVERAGE 3. emit : Replaced bitwise AND with OR → NO_COVERAGE |
buffer[myOffset+2] = (byte) ((value >>> 0) & 0xff); |
548 | } | |
549 | } | |
550 | | |
551 | /** Card32 item. | |
552 | */ | |
553 | | |
554 | static protected final class UInt32Item extends Item { | |
555 | public int value; | |
556 | public UInt32Item(int value) {this.value=value;} | |
557 | | |
558 | public void increment(int[] currentOffset) { | |
559 |
1
1. increment : removed call to com/lowagie/text/pdf/CFFFont$Item::increment → NO_COVERAGE |
super.increment(currentOffset); |
560 |
1
1. increment : Replaced integer addition with subtraction → NO_COVERAGE |
currentOffset[0] += 4; |
561 | } | |
562 | // this is incomplete! | |
563 | public void emit(byte[] buffer) { | |
564 |
3
1. emit : Replaced integer addition with subtraction → NO_COVERAGE 2. emit : Replaced Unsigned Shift Right with Shift Left → NO_COVERAGE 3. emit : Replaced bitwise AND with OR → NO_COVERAGE |
buffer[myOffset+0] = (byte) ((value >>> 24) & 0xff); |
565 |
3
1. emit : Replaced integer addition with subtraction → NO_COVERAGE 2. emit : Replaced Unsigned Shift Right with Shift Left → NO_COVERAGE 3. emit : Replaced bitwise AND with OR → NO_COVERAGE |
buffer[myOffset+1] = (byte) ((value >>> 16) & 0xff); |
566 |
3
1. emit : Replaced integer addition with subtraction → NO_COVERAGE 2. emit : Replaced Unsigned Shift Right with Shift Left → NO_COVERAGE 3. emit : Replaced bitwise AND with OR → NO_COVERAGE |
buffer[myOffset+2] = (byte) ((value >>> 8) & 0xff); |
567 |
3
1. emit : Replaced integer addition with subtraction → NO_COVERAGE 2. emit : Replaced Unsigned Shift Right with Shift Left → NO_COVERAGE 3. emit : Replaced bitwise AND with OR → NO_COVERAGE |
buffer[myOffset+3] = (byte) ((value >>> 0) & 0xff); |
568 | } | |
569 | } | |
570 | ||
571 | /** A SID or Card16 item. | |
572 | */ | |
573 | | |
574 | static protected final class UInt16Item extends Item { | |
575 | public char value; | |
576 | public UInt16Item(char value) {this.value=value;} | |
577 | | |
578 | public void increment(int[] currentOffset) { | |
579 |
1
1. increment : removed call to com/lowagie/text/pdf/CFFFont$Item::increment → NO_COVERAGE |
super.increment(currentOffset); |
580 |
1
1. increment : Replaced integer addition with subtraction → NO_COVERAGE |
currentOffset[0] += 2; |
581 | } | |
582 | // this is incomplete! | |
583 | public void emit(byte[] buffer) { | |
584 |
3
1. emit : Replaced integer addition with subtraction → NO_COVERAGE 2. emit : Replaced Unsigned Shift Right with Shift Left → NO_COVERAGE 3. emit : Replaced bitwise AND with OR → NO_COVERAGE |
buffer[myOffset+0] = (byte) ((value >>> 8) & 0xff); |
585 |
3
1. emit : Replaced integer addition with subtraction → NO_COVERAGE 2. emit : Replaced Unsigned Shift Right with Shift Left → NO_COVERAGE 3. emit : Replaced bitwise AND with OR → NO_COVERAGE |
buffer[myOffset+1] = (byte) ((value >>> 0) & 0xff); |
586 | } | |
587 | } | |
588 | | |
589 | /** A Card8 item. | |
590 | */ | |
591 | | |
592 | static protected final class UInt8Item extends Item { | |
593 | public char value; | |
594 | public UInt8Item(char value) {this.value=value;} | |
595 | | |
596 | public void increment(int[] currentOffset) { | |
597 |
1
1. increment : removed call to com/lowagie/text/pdf/CFFFont$Item::increment → NO_COVERAGE |
super.increment(currentOffset); |
598 |
1
1. increment : Replaced integer addition with subtraction → NO_COVERAGE |
currentOffset[0] += 1; |
599 | } | |
600 | // this is incomplete! | |
601 | public void emit(byte[] buffer) { | |
602 |
3
1. emit : Replaced integer addition with subtraction → NO_COVERAGE 2. emit : Replaced Unsigned Shift Right with Shift Left → NO_COVERAGE 3. emit : Replaced bitwise AND with OR → NO_COVERAGE |
buffer[myOffset+0] = (byte) ((value >>> 0) & 0xff); |
603 | } | |
604 | } | |
605 | | |
606 | static protected final class StringItem extends Item { | |
607 | public String s; | |
608 | public StringItem(String s) {this.s=s;} | |
609 | | |
610 | public void increment(int[] currentOffset) { | |
611 |
1
1. increment : removed call to com/lowagie/text/pdf/CFFFont$Item::increment → NO_COVERAGE |
super.increment(currentOffset); |
612 |
1
1. increment : Replaced integer addition with subtraction → NO_COVERAGE |
currentOffset[0] += s.length(); |
613 | } | |
614 | public void emit(byte[] buffer) { | |
615 |
2
1. emit : changed conditional boundary → NO_COVERAGE 2. emit : negated conditional → NO_COVERAGE |
for (int i=0; i<s.length(); i++) |
616 |
2
1. emit : Replaced integer addition with subtraction → NO_COVERAGE 2. emit : Replaced bitwise AND with OR → NO_COVERAGE |
buffer[myOffset+i] = (byte) (s.charAt(i) & 0xff); |
617 | } | |
618 | } | |
619 | | |
620 | | |
621 | /** A dictionary number on the list. | |
622 | * This implementation is inefficient: it doesn't use the variable-length | |
623 | * representation. | |
624 | */ | |
625 | | |
626 | static protected final class DictNumberItem extends Item { | |
627 | public final int value; | |
628 | public int size = 5; | |
629 | public DictNumberItem(int value) {this.value=value;} | |
630 | public void increment(int[] currentOffset) { | |
631 |
1
1. increment : removed call to com/lowagie/text/pdf/CFFFont$Item::increment → NO_COVERAGE |
super.increment(currentOffset); |
632 |
1
1. increment : Replaced integer addition with subtraction → NO_COVERAGE |
currentOffset[0] += size; |
633 | } | |
634 | // this is incomplete! | |
635 | public void emit(byte[] buffer) { | |
636 |
1
1. emit : negated conditional → NO_COVERAGE |
if (size==5) { |
637 | buffer[myOffset] = 29; | |
638 |
3
1. emit : Replaced integer addition with subtraction → NO_COVERAGE 2. emit : Replaced Unsigned Shift Right with Shift Left → NO_COVERAGE 3. emit : Replaced bitwise AND with OR → NO_COVERAGE |
buffer[myOffset+1] = (byte) ((value >>> 24) & 0xff); |
639 |
3
1. emit : Replaced integer addition with subtraction → NO_COVERAGE 2. emit : Replaced Unsigned Shift Right with Shift Left → NO_COVERAGE 3. emit : Replaced bitwise AND with OR → NO_COVERAGE |
buffer[myOffset+2] = (byte) ((value >>> 16) & 0xff); |
640 |
3
1. emit : Replaced integer addition with subtraction → NO_COVERAGE 2. emit : Replaced Unsigned Shift Right with Shift Left → NO_COVERAGE 3. emit : Replaced bitwise AND with OR → NO_COVERAGE |
buffer[myOffset+3] = (byte) ((value >>> 8) & 0xff); |
641 |
3
1. emit : Replaced integer addition with subtraction → NO_COVERAGE 2. emit : Replaced Unsigned Shift Right with Shift Left → NO_COVERAGE 3. emit : Replaced bitwise AND with OR → NO_COVERAGE |
buffer[myOffset+4] = (byte) ((value >>> 0) & 0xff); |
642 | } | |
643 | } | |
644 | } | |
645 | | |
646 | /** An offset-marker item for the list. | |
647 | * It is used to mark an offset and to set the offset list item. | |
648 | */ | |
649 | | |
650 | static protected final class MarkerItem extends Item { | |
651 | OffsetItem p; | |
652 | public MarkerItem(OffsetItem pointerToMarker) {p=pointerToMarker;} | |
653 | public void xref() { | |
654 |
1
1. xref : removed call to com/lowagie/text/pdf/CFFFont$OffsetItem::set → NO_COVERAGE |
p.set(this.myOffset); |
655 | } | |
656 | } | |
657 | | |
658 | /** a utility that creates a range item for an entire index | |
659 | * | |
660 | * @param indexOffset where the index is | |
661 | * @return a range item representing the entire index | |
662 | */ | |
663 | | |
664 | protected RangeItem getEntireIndexRange(int indexOffset) { | |
665 |
1
1. getEntireIndexRange : removed call to com/lowagie/text/pdf/CFFFont::seek → NO_COVERAGE |
seek(indexOffset); |
666 | int count = getCard16(); | |
667 |
1
1. getEntireIndexRange : negated conditional → NO_COVERAGE |
if (count==0) { |
668 |
1
1. getEntireIndexRange : mutated return of Object value for com/lowagie/text/pdf/CFFFont::getEntireIndexRange to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return new RangeItem(buf,indexOffset,2); |
669 | } else { | |
670 | int indexOffSize = getCard8(); | |
671 |
5
1. getEntireIndexRange : Replaced integer addition with subtraction → NO_COVERAGE 2. getEntireIndexRange : Replaced integer addition with subtraction → NO_COVERAGE 3. getEntireIndexRange : Replaced integer multiplication with division → NO_COVERAGE 4. getEntireIndexRange : Replaced integer addition with subtraction → NO_COVERAGE 5. getEntireIndexRange : removed call to com/lowagie/text/pdf/CFFFont::seek → NO_COVERAGE |
seek(indexOffset+2+1+count*indexOffSize); |
672 |
1
1. getEntireIndexRange : Replaced integer subtraction with addition → NO_COVERAGE |
int size = getOffset(indexOffSize)-1; |
673 |
5
1. getEntireIndexRange : Replaced integer addition with subtraction → NO_COVERAGE 2. getEntireIndexRange : Replaced integer multiplication with division → NO_COVERAGE 3. getEntireIndexRange : Replaced integer addition with subtraction → NO_COVERAGE 4. getEntireIndexRange : Replaced integer addition with subtraction → NO_COVERAGE 5. getEntireIndexRange : mutated return of Object value for com/lowagie/text/pdf/CFFFont::getEntireIndexRange to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return new RangeItem(buf,indexOffset, |
674 | 2+1+(count+1)*indexOffSize+size); | |
675 | } | |
676 | } | |
677 | | |
678 | | |
679 | /** get a single CID font. The PDF architecture (1.4) | |
680 | * supports 16-bit strings only with CID CFF fonts, not | |
681 | * in Type-1 CFF fonts, so we convert the font to CID if | |
682 | * it is in the Type-1 format. | |
683 | * Two other tasks that we need to do are to select | |
684 | * only a single font from the CFF package (this again is | |
685 | * a PDF restriction) and to subset the CharStrings glyph | |
686 | * description. | |
687 | */ | |
688 | | |
689 | | |
690 | public byte[] getCID(String fontName) | |
691 | //throws java.io.FileNotFoundException | |
692 | { | |
693 | int j; | |
694 |
2
1. getCID : changed conditional boundary → NO_COVERAGE 2. getCID : negated conditional → NO_COVERAGE |
for (j=0; j<fonts.length; j++) |
695 |
1
1. getCID : negated conditional → NO_COVERAGE |
if (fontName.equals(fonts[j].name)) break; |
696 |
2
1. getCID : negated conditional → NO_COVERAGE 2. getCID : mutated return of Object value for com/lowagie/text/pdf/CFFFont::getCID to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
if (j==fonts.length) return null; |
697 | | |
698 | LinkedList l = new LinkedList(); | |
699 | | |
700 | // copy the header | |
701 | | |
702 |
1
1. getCID : removed call to com/lowagie/text/pdf/CFFFont::seek → NO_COVERAGE |
seek(0); |
703 | | |
704 | int major = getCard8(); | |
705 | int minor = getCard8(); | |
706 | int hdrSize = getCard8(); | |
707 | int offSize = getCard8(); | |
708 | nextIndexOffset = hdrSize; | |
709 | | |
710 |
1
1. getCID : removed call to java/util/LinkedList::addLast → NO_COVERAGE |
l.addLast(new RangeItem(buf,0,hdrSize)); |
711 | | |
712 | int nglyphs=-1, nstrings=-1; | |
713 |
1
1. getCID : negated conditional → NO_COVERAGE |
if ( ! fonts[j].isCID ) { |
714 | // count the glyphs | |
715 |
1
1. getCID : removed call to com/lowagie/text/pdf/CFFFont::seek → NO_COVERAGE |
seek(fonts[j].charstringsOffset); |
716 | nglyphs = getCard16(); | |
717 |
1
1. getCID : removed call to com/lowagie/text/pdf/CFFFont::seek → NO_COVERAGE |
seek(stringIndexOffset); |
718 |
1
1. getCID : Replaced integer addition with subtraction → NO_COVERAGE |
nstrings = getCard16()+standardStrings.length; |
719 | //System.err.println("number of glyphs = "+nglyphs); | |
720 | } | |
721 | | |
722 | // create a name index | |
723 | | |
724 |
1
1. getCID : removed call to java/util/LinkedList::addLast → NO_COVERAGE |
l.addLast(new UInt16Item((char)1)); // count |
725 |
1
1. getCID : removed call to java/util/LinkedList::addLast → NO_COVERAGE |
l.addLast(new UInt8Item((char)1)); // offSize |
726 |
1
1. getCID : removed call to java/util/LinkedList::addLast → NO_COVERAGE |
l.addLast(new UInt8Item((char)1)); // first offset |
727 |
2
1. getCID : Replaced integer addition with subtraction → NO_COVERAGE 2. getCID : removed call to java/util/LinkedList::addLast → NO_COVERAGE |
l.addLast(new UInt8Item((char)( 1+fonts[j].name.length() ))); |
728 |
1
1. getCID : removed call to java/util/LinkedList::addLast → NO_COVERAGE |
l.addLast(new StringItem(fonts[j].name)); |
729 | | |
730 | // create the topdict Index | |
731 | | |
732 | | |
733 |
1
1. getCID : removed call to java/util/LinkedList::addLast → NO_COVERAGE |
l.addLast(new UInt16Item((char)1)); // count |
734 |
1
1. getCID : removed call to java/util/LinkedList::addLast → NO_COVERAGE |
l.addLast(new UInt8Item((char)2)); // offSize |
735 |
1
1. getCID : removed call to java/util/LinkedList::addLast → NO_COVERAGE |
l.addLast(new UInt16Item((char)1)); // first offset |
736 | OffsetItem topdictIndex1Ref = new IndexOffsetItem(2); | |
737 |
1
1. getCID : removed call to java/util/LinkedList::addLast → NO_COVERAGE |
l.addLast(topdictIndex1Ref); |
738 | IndexBaseItem topdictBase = new IndexBaseItem(); | |
739 |
1
1. getCID : removed call to java/util/LinkedList::addLast → NO_COVERAGE |
l.addLast(topdictBase); |
740 | | |
741 | /* | |
742 | int maxTopdictLen = (topdictOffsets[j+1]-topdictOffsets[j]) | |
743 | + 9*2 // at most 9 new keys | |
744 | + 8*5 // 8 new integer arguments | |
745 | + 3*2;// 3 new SID arguments | |
746 | */ | |
747 | | |
748 | //int topdictNext = 0; | |
749 | //byte[] topdict = new byte[maxTopdictLen]; | |
750 | | |
751 | OffsetItem charsetRef = new DictOffsetItem(); | |
752 | OffsetItem charstringsRef = new DictOffsetItem(); | |
753 | OffsetItem fdarrayRef = new DictOffsetItem(); | |
754 | OffsetItem fdselectRef = new DictOffsetItem(); | |
755 | | |
756 |
1
1. getCID : negated conditional → NO_COVERAGE |
if ( !fonts[j].isCID ) { |
757 | // create a ROS key | |
758 |
1
1. getCID : removed call to java/util/LinkedList::addLast → NO_COVERAGE |
l.addLast(new DictNumberItem(nstrings)); |
759 |
2
1. getCID : Replaced integer addition with subtraction → NO_COVERAGE 2. getCID : removed call to java/util/LinkedList::addLast → NO_COVERAGE |
l.addLast(new DictNumberItem(nstrings+1)); |
760 |
1
1. getCID : removed call to java/util/LinkedList::addLast → NO_COVERAGE |
l.addLast(new DictNumberItem(0)); |
761 |
1
1. getCID : removed call to java/util/LinkedList::addLast → NO_COVERAGE |
l.addLast(new UInt8Item((char)12)); |
762 |
1
1. getCID : removed call to java/util/LinkedList::addLast → NO_COVERAGE |
l.addLast(new UInt8Item((char)30)); |
763 | // create a CIDCount key | |
764 |
1
1. getCID : removed call to java/util/LinkedList::addLast → NO_COVERAGE |
l.addLast(new DictNumberItem(nglyphs)); |
765 |
1
1. getCID : removed call to java/util/LinkedList::addLast → NO_COVERAGE |
l.addLast(new UInt8Item((char)12)); |
766 |
1
1. getCID : removed call to java/util/LinkedList::addLast → NO_COVERAGE |
l.addLast(new UInt8Item((char)34)); |
767 | // What about UIDBase (12,35)? Don't know what is it. | |
768 | // I don't think we need FontName; the font I looked at didn't have it. | |
769 | } | |
770 | | |
771 | // create an FDArray key | |
772 |
1
1. getCID : removed call to java/util/LinkedList::addLast → NO_COVERAGE |
l.addLast(fdarrayRef); |
773 |
1
1. getCID : removed call to java/util/LinkedList::addLast → NO_COVERAGE |
l.addLast(new UInt8Item((char)12)); |
774 |
1
1. getCID : removed call to java/util/LinkedList::addLast → NO_COVERAGE |
l.addLast(new UInt8Item((char)36)); |
775 | // create an FDSelect key | |
776 |
1
1. getCID : removed call to java/util/LinkedList::addLast → NO_COVERAGE |
l.addLast(fdselectRef); |
777 |
1
1. getCID : removed call to java/util/LinkedList::addLast → NO_COVERAGE |
l.addLast(new UInt8Item((char)12)); |
778 |
1
1. getCID : removed call to java/util/LinkedList::addLast → NO_COVERAGE |
l.addLast(new UInt8Item((char)37)); |
779 | // create an charset key | |
780 |
1
1. getCID : removed call to java/util/LinkedList::addLast → NO_COVERAGE |
l.addLast(charsetRef); |
781 |
1
1. getCID : removed call to java/util/LinkedList::addLast → NO_COVERAGE |
l.addLast(new UInt8Item((char)15)); |
782 | // create a CharStrings key | |
783 |
1
1. getCID : removed call to java/util/LinkedList::addLast → NO_COVERAGE |
l.addLast(charstringsRef); |
784 |
1
1. getCID : removed call to java/util/LinkedList::addLast → NO_COVERAGE |
l.addLast(new UInt8Item((char)17)); |
785 | | |
786 |
1
1. getCID : removed call to com/lowagie/text/pdf/CFFFont::seek → NO_COVERAGE |
seek(topdictOffsets[j]); |
787 |
3
1. getCID : changed conditional boundary → NO_COVERAGE 2. getCID : Replaced integer addition with subtraction → NO_COVERAGE 3. getCID : negated conditional → NO_COVERAGE |
while (getPosition() < topdictOffsets[j+1]) { |
788 | int p1 = getPosition(); | |
789 |
1
1. getCID : removed call to com/lowagie/text/pdf/CFFFont::getDictItem → NO_COVERAGE |
getDictItem(); |
790 | int p2 = getPosition(); | |
791 |
1
1. getCID : negated conditional → NO_COVERAGE |
if (Objects.equals(key, "Encoding") |
792 |
1
1. getCID : negated conditional → NO_COVERAGE |
|| Objects.equals(key, "Private") |
793 |
1
1. getCID : negated conditional → NO_COVERAGE |
|| Objects.equals(key, "FDSelect") |
794 |
1
1. getCID : negated conditional → NO_COVERAGE |
|| Objects.equals(key, "FDArray") |
795 |
1
1. getCID : negated conditional → NO_COVERAGE |
|| Objects.equals(key, "charset") |
796 |
1
1. getCID : negated conditional → NO_COVERAGE |
|| Objects.equals(key, "CharStrings") |
797 | ) { | |
798 | // just drop them | |
799 | } else { | |
800 |
1
1. getCID : Replaced integer subtraction with addition → NO_COVERAGE |
l.add(new RangeItem(buf,p1,p2-p1)); |
801 | } | |
802 | } | |
803 | | |
804 |
1
1. getCID : removed call to java/util/LinkedList::addLast → NO_COVERAGE |
l.addLast(new IndexMarkerItem(topdictIndex1Ref,topdictBase)); |
805 | | |
806 | // Copy the string index and append new strings. | |
807 | // We need 3 more strings: Registry, Ordering, and a FontName for one FD. | |
808 | // The total length is at most "Adobe"+"Identity"+63 = 76 | |
809 | | |
810 |
1
1. getCID : negated conditional → NO_COVERAGE |
if (fonts[j].isCID) { |
811 |
1
1. getCID : removed call to java/util/LinkedList::addLast → NO_COVERAGE |
l.addLast(getEntireIndexRange(stringIndexOffset)); |
812 | } else { | |
813 | String fdFontName = fonts[j].name+"-OneRange"; | |
814 |
2
1. getCID : changed conditional boundary → NO_COVERAGE 2. getCID : negated conditional → NO_COVERAGE |
if (fdFontName.length() > 127) |
815 | fdFontName = fdFontName.substring(0,127); | |
816 | String extraStrings = "Adobe"+"Identity"+fdFontName; | |
817 | | |
818 |
2
1. getCID : Replaced integer subtraction with addition → NO_COVERAGE 2. getCID : Replaced integer subtraction with addition → NO_COVERAGE |
int origStringsLen = stringOffsets[stringOffsets.length-1] |
819 | - stringOffsets[0]; | |
820 |
1
1. getCID : Replaced integer subtraction with addition → NO_COVERAGE |
int stringsBaseOffset = stringOffsets[0]-1; |
821 | | |
822 | byte stringsIndexOffSize; | |
823 |
3
1. getCID : changed conditional boundary → NO_COVERAGE 2. getCID : Replaced integer addition with subtraction → NO_COVERAGE 3. getCID : negated conditional → NO_COVERAGE |
if (origStringsLen+extraStrings.length() <= 0xff) stringsIndexOffSize = 1; |
824 |
3
1. getCID : changed conditional boundary → NO_COVERAGE 2. getCID : Replaced integer addition with subtraction → NO_COVERAGE 3. getCID : negated conditional → NO_COVERAGE |
else if (origStringsLen+extraStrings.length() <= 0xffff) stringsIndexOffSize = 2; |
825 |
3
1. getCID : changed conditional boundary → NO_COVERAGE 2. getCID : Replaced integer addition with subtraction → NO_COVERAGE 3. getCID : negated conditional → NO_COVERAGE |
else if (origStringsLen+extraStrings.length() <= 0xffffff) stringsIndexOffSize = 3; |
826 | else stringsIndexOffSize = 4; | |
827 | | |
828 |
3
1. getCID : Replaced integer subtraction with addition → NO_COVERAGE 2. getCID : Replaced integer addition with subtraction → NO_COVERAGE 3. getCID : removed call to java/util/LinkedList::addLast → NO_COVERAGE |
l.addLast(new UInt16Item((char)((stringOffsets.length-1)+3))); // count |
829 |
1
1. getCID : removed call to java/util/LinkedList::addLast → NO_COVERAGE |
l.addLast(new UInt8Item((char)stringsIndexOffSize)); // offSize |
830 | for (int stringOffset : stringOffsets) | |
831 |
2
1. getCID : Replaced integer subtraction with addition → NO_COVERAGE 2. getCID : removed call to java/util/LinkedList::addLast → NO_COVERAGE |
l.addLast(new IndexOffsetItem(stringsIndexOffSize, |
832 | stringOffset - stringsBaseOffset)); | |
833 |
2
1. getCID : Replaced integer subtraction with addition → NO_COVERAGE 2. getCID : Replaced integer subtraction with addition → NO_COVERAGE |
int currentStringsOffset = stringOffsets[stringOffsets.length-1] |
834 | - stringsBaseOffset; | |
835 | //l.addLast(new IndexOffsetItem(stringsIndexOffSize,currentStringsOffset)); | |
836 |
1
1. getCID : Replaced integer addition with subtraction → NO_COVERAGE |
currentStringsOffset += "Adobe".length(); |
837 |
1
1. getCID : removed call to java/util/LinkedList::addLast → NO_COVERAGE |
l.addLast(new IndexOffsetItem(stringsIndexOffSize,currentStringsOffset)); |
838 |
1
1. getCID : Replaced integer addition with subtraction → NO_COVERAGE |
currentStringsOffset += "Identity".length(); |
839 |
1
1. getCID : removed call to java/util/LinkedList::addLast → NO_COVERAGE |
l.addLast(new IndexOffsetItem(stringsIndexOffSize,currentStringsOffset)); |
840 |
1
1. getCID : Replaced integer addition with subtraction → NO_COVERAGE |
currentStringsOffset += fdFontName.length(); |
841 |
1
1. getCID : removed call to java/util/LinkedList::addLast → NO_COVERAGE |
l.addLast(new IndexOffsetItem(stringsIndexOffSize,currentStringsOffset)); |
842 | | |
843 |
1
1. getCID : removed call to java/util/LinkedList::addLast → NO_COVERAGE |
l.addLast(new RangeItem(buf,stringOffsets[0],origStringsLen)); |
844 |
1
1. getCID : removed call to java/util/LinkedList::addLast → NO_COVERAGE |
l.addLast(new StringItem(extraStrings)); |
845 | } | |
846 | | |
847 | // copy the global subroutine index | |
848 | | |
849 |
1
1. getCID : removed call to java/util/LinkedList::addLast → NO_COVERAGE |
l.addLast(getEntireIndexRange(gsubrIndexOffset)); |
850 | | |
851 | // deal with fdarray, fdselect, and the font descriptors | |
852 | | |
853 |
1
1. getCID : negated conditional → NO_COVERAGE |
if (fonts[j].isCID) { |
854 | // copy the FDArray, FDSelect, charset | |
855 | } else { | |
856 | // create FDSelect | |
857 |
1
1. getCID : removed call to java/util/LinkedList::addLast → NO_COVERAGE |
l.addLast(new MarkerItem(fdselectRef)); |
858 |
1
1. getCID : removed call to java/util/LinkedList::addLast → NO_COVERAGE |
l.addLast(new UInt8Item((char)3)); // format identifier |
859 |
1
1. getCID : removed call to java/util/LinkedList::addLast → NO_COVERAGE |
l.addLast(new UInt16Item((char)1)); // nRanges |
860 | | |
861 |
1
1. getCID : removed call to java/util/LinkedList::addLast → NO_COVERAGE |
l.addLast(new UInt16Item((char)0)); // Range[0].firstGlyph |
862 |
1
1. getCID : removed call to java/util/LinkedList::addLast → NO_COVERAGE |
l.addLast(new UInt8Item((char)0)); // Range[0].fd |
863 | | |
864 |
1
1. getCID : removed call to java/util/LinkedList::addLast → NO_COVERAGE |
l.addLast(new UInt16Item((char)nglyphs)); // sentinel |
865 | | |
866 | // recreate a new charset | |
867 | // This format is suitable only for fonts without subsetting | |
868 | | |
869 |
1
1. getCID : removed call to java/util/LinkedList::addLast → NO_COVERAGE |
l.addLast(new MarkerItem(charsetRef)); |
870 |
1
1. getCID : removed call to java/util/LinkedList::addLast → NO_COVERAGE |
l.addLast(new UInt8Item((char)2)); // format identifier |
871 | | |
872 |
1
1. getCID : removed call to java/util/LinkedList::addLast → NO_COVERAGE |
l.addLast(new UInt16Item((char)1)); // first glyph in range (ignore .notdef) |
873 |
2
1. getCID : Replaced integer subtraction with addition → NO_COVERAGE 2. getCID : removed call to java/util/LinkedList::addLast → NO_COVERAGE |
l.addLast(new UInt16Item((char)(nglyphs-1))); // nLeft |
874 | // now all are covered, the data structure is complete. | |
875 | | |
876 | // create a font dict index (fdarray) | |
877 | | |
878 |
1
1. getCID : removed call to java/util/LinkedList::addLast → NO_COVERAGE |
l.addLast(new MarkerItem(fdarrayRef)); |
879 |
1
1. getCID : removed call to java/util/LinkedList::addLast → NO_COVERAGE |
l.addLast(new UInt16Item((char)1)); |
880 |
1
1. getCID : removed call to java/util/LinkedList::addLast → NO_COVERAGE |
l.addLast(new UInt8Item((char)1)); // offSize |
881 |
1
1. getCID : removed call to java/util/LinkedList::addLast → NO_COVERAGE |
l.addLast(new UInt8Item((char)1)); // first offset |
882 | | |
883 | OffsetItem privateIndex1Ref = new IndexOffsetItem(1); | |
884 |
1
1. getCID : removed call to java/util/LinkedList::addLast → NO_COVERAGE |
l.addLast(privateIndex1Ref); |
885 | IndexBaseItem privateBase = new IndexBaseItem(); | |
886 |
1
1. getCID : removed call to java/util/LinkedList::addLast → NO_COVERAGE |
l.addLast(privateBase); |
887 | | |
888 | // looking at the PS that acrobat generates from a PDF with | |
889 | // a CFF opentype font embedded with an identity-H encoding, | |
890 | // it seems that it does not need a FontName. | |
891 | //l.addLast(new DictNumberItem((standardStrings.length+(stringOffsets.length-1)+2))); | |
892 | //l.addLast(new UInt8Item((char)12)); | |
893 | //l.addLast(new UInt8Item((char)38)); // FontName | |
894 | | |
895 |
1
1. getCID : removed call to java/util/LinkedList::addLast → NO_COVERAGE |
l.addLast(new DictNumberItem(fonts[j].privateLength)); |
896 | OffsetItem privateRef = new DictOffsetItem(); | |
897 |
1
1. getCID : removed call to java/util/LinkedList::addLast → NO_COVERAGE |
l.addLast(privateRef); |
898 |
1
1. getCID : removed call to java/util/LinkedList::addLast → NO_COVERAGE |
l.addLast(new UInt8Item((char)18)); // Private |
899 | | |
900 |
1
1. getCID : removed call to java/util/LinkedList::addLast → NO_COVERAGE |
l.addLast(new IndexMarkerItem(privateIndex1Ref,privateBase)); |
901 | | |
902 | // copy the private index & local subroutines | |
903 | | |
904 |
1
1. getCID : removed call to java/util/LinkedList::addLast → NO_COVERAGE |
l.addLast(new MarkerItem(privateRef)); |
905 | // copy the private dict and the local subroutines. | |
906 | // the length of the private dict seems to NOT include | |
907 | // the local subroutines. | |
908 |
1
1. getCID : removed call to java/util/LinkedList::addLast → NO_COVERAGE |
l.addLast(new RangeItem(buf,fonts[j].privateOffset,fonts[j].privateLength)); |
909 |
2
1. getCID : changed conditional boundary → NO_COVERAGE 2. getCID : negated conditional → NO_COVERAGE |
if (fonts[j].privateSubrs >= 0) { |
910 | //System.err.println("has subrs="+fonts[j].privateSubrs+" ,len="+fonts[j].privateLength); | |
911 |
1
1. getCID : removed call to java/util/LinkedList::addLast → NO_COVERAGE |
l.addLast(getEntireIndexRange(fonts[j].privateSubrs)); |
912 | } | |
913 | } | |
914 | | |
915 | // copy the charstring index | |
916 | | |
917 |
1
1. getCID : removed call to java/util/LinkedList::addLast → NO_COVERAGE |
l.addLast(new MarkerItem(charstringsRef)); |
918 |
1
1. getCID : removed call to java/util/LinkedList::addLast → NO_COVERAGE |
l.addLast(getEntireIndexRange(fonts[j].charstringsOffset)); |
919 | | |
920 | // now create the new CFF font | |
921 | | |
922 | int[] currentOffset = new int[1]; | |
923 | currentOffset[0] = 0; | |
924 | | |
925 | Iterator listIter = l.iterator(); | |
926 | while ( listIter.hasNext() ) { | |
927 | Item item = (Item) listIter.next(); | |
928 |
1
1. getCID : removed call to com/lowagie/text/pdf/CFFFont$Item::increment → NO_COVERAGE |
item.increment(currentOffset); |
929 | } | |
930 | | |
931 | listIter = l.iterator(); | |
932 | while ( listIter.hasNext() ) { | |
933 | Item item = (Item) listIter.next(); | |
934 |
1
1. getCID : removed call to com/lowagie/text/pdf/CFFFont$Item::xref → NO_COVERAGE |
item.xref(); |
935 | } | |
936 | | |
937 | int size = currentOffset[0]; | |
938 | byte[] b = new byte[size]; | |
939 | | |
940 | listIter = l.iterator(); | |
941 | while ( listIter.hasNext() ) { | |
942 | Item item = (Item) listIter.next(); | |
943 |
1
1. getCID : removed call to com/lowagie/text/pdf/CFFFont$Item::emit → NO_COVERAGE |
item.emit(b); |
944 | } | |
945 | | |
946 |
1
1. getCID : mutated return of Object value for com/lowagie/text/pdf/CFFFont::getCID to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return b; |
947 | } | |
948 | | |
949 | | |
950 | public boolean isCID(String fontName) { | |
951 | int j; | |
952 |
2
1. isCID : changed conditional boundary → NO_COVERAGE 2. isCID : negated conditional → NO_COVERAGE |
for (j=0; j<fonts.length; j++) |
953 |
2
1. isCID : negated conditional → NO_COVERAGE 2. isCID : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
if (fontName.equals(fonts[j].name)) return fonts[j].isCID; |
954 |
1
1. isCID : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return false; |
955 | } | |
956 | | |
957 | public boolean exists(String fontName) { | |
958 | int j; | |
959 |
2
1. exists : changed conditional boundary → NO_COVERAGE 2. exists : negated conditional → NO_COVERAGE |
for (j=0; j<fonts.length; j++) |
960 |
2
1. exists : negated conditional → NO_COVERAGE 2. exists : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
if (fontName.equals(fonts[j].name)) return true; |
961 |
1
1. exists : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return false; |
962 | } | |
963 | | |
964 | | |
965 | public String[] getNames() { | |
966 | String[] names = new String[ fonts.length ]; | |
967 |
2
1. getNames : changed conditional boundary → NO_COVERAGE 2. getNames : negated conditional → NO_COVERAGE |
for (int i=0; i<fonts.length; i++) |
968 | names[i] = fonts[i].name; | |
969 |
1
1. getNames : mutated return of Object value for com/lowagie/text/pdf/CFFFont::getNames to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return names; |
970 | } | |
971 | /** | |
972 | * A random Access File or an array | |
973 | */ | |
974 | protected RandomAccessFileOrArray buf; | |
975 | private int offSize; | |
976 | | |
977 | protected int nameIndexOffset; | |
978 | protected int topdictIndexOffset; | |
979 | protected int stringIndexOffset; | |
980 | protected int gsubrIndexOffset; | |
981 | protected int[] nameOffsets; | |
982 | protected int[] topdictOffsets; | |
983 | protected int[] stringOffsets; | |
984 | protected int[] gsubrOffsets; | |
985 | | |
986 | /** | |
987 | * TODO Changed from private to protected by Ygal&Oren | |
988 | */ | |
989 | protected final class Font { | |
990 | public String name; | |
991 | public String fullName; | |
992 | public boolean isCID = false; | |
993 | public int privateOffset = -1; // only if not CID | |
994 | public int privateLength = -1; // only if not CID | |
995 | public int privateSubrs = -1; | |
996 | public int charstringsOffset = -1; | |
997 | public int encodingOffset = -1; | |
998 | public int charsetOffset = -1; | |
999 | public int fdarrayOffset = -1; // only if CID | |
1000 | public int fdselectOffset = -1; // only if CID | |
1001 | public int[] fdprivateOffsets; | |
1002 | public int[] fdprivateLengths; | |
1003 | public int[] fdprivateSubrs; | |
1004 | | |
1005 | // Added by Oren & Ygal | |
1006 | public int nglyphs; | |
1007 | public int nstrings; | |
1008 | public int CharsetLength; | |
1009 | public int[] charstringsOffsets; | |
1010 | public int[] charset; | |
1011 | public int[] FDSelect; | |
1012 | public int FDSelectLength; | |
1013 | public int FDSelectFormat; | |
1014 | public int CharstringType = 2; | |
1015 | public int FDArrayCount; | |
1016 | public int FDArrayOffsize; | |
1017 | public int[] FDArrayOffsets; | |
1018 | public int[] PrivateSubrsOffset; | |
1019 | public int[][] PrivateSubrsOffsetsArray; | |
1020 | public int[] SubrsOffsets; | |
1021 | } | |
1022 | // Changed from private to protected by Ygal&Oren | |
1023 | protected Font[] fonts; | |
1024 | | |
1025 | public CFFFont(RandomAccessFileOrArray inputbuffer) { | |
1026 | | |
1027 | //System.err.println("CFF: nStdString = "+standardStrings.length); | |
1028 | buf = inputbuffer; | |
1029 |
1
1. |
seek(0); |
1030 | | |
1031 | int major, minor; | |
1032 | major = getCard8(); | |
1033 | minor = getCard8(); | |
1034 | | |
1035 | //System.err.println("CFF Major-Minor = "+major+"-"+minor); | |
1036 | | |
1037 | int hdrSize = getCard8(); | |
1038 | | |
1039 | offSize = getCard8(); | |
1040 | | |
1041 | //System.err.println("offSize = "+offSize); | |
1042 | | |
1043 | //int count, indexOffSize, indexOffset, nextOffset; | |
1044 | | |
1045 | nameIndexOffset = hdrSize; | |
1046 | nameOffsets = getIndex(nameIndexOffset); | |
1047 |
1
1. |
topdictIndexOffset = nameOffsets[nameOffsets.length-1]; |
1048 | topdictOffsets = getIndex(topdictIndexOffset); | |
1049 |
1
1. |
stringIndexOffset = topdictOffsets[topdictOffsets.length-1]; |
1050 | stringOffsets = getIndex(stringIndexOffset); | |
1051 |
1
1. |
gsubrIndexOffset = stringOffsets[stringOffsets.length-1]; |
1052 | gsubrOffsets = getIndex(gsubrIndexOffset); | |
1053 | | |
1054 |
1
1. |
fonts = new Font[nameOffsets.length-1]; |
1055 | | |
1056 | // now get the name index | |
1057 | | |
1058 | /* | |
1059 | names = new String[nfonts]; | |
1060 | privateOffset = new int[nfonts]; | |
1061 | charsetOffset = new int[nfonts]; | |
1062 | encodingOffset = new int[nfonts]; | |
1063 | charstringsOffset = new int[nfonts]; | |
1064 | fdarrayOffset = new int[nfonts]; | |
1065 | fdselectOffset = new int[nfonts]; | |
1066 | */ | |
1067 | | |
1068 |
4
1. 2. 3. 4. |
for (int j=0; j<nameOffsets.length-1; j++) { |
1069 | fonts[j] = new Font(); | |
1070 |
1
1. |
seek(nameOffsets[j]); |
1071 | fonts[j].name = ""; | |
1072 |
4
1. 2. 3. 4. |
for (int k=nameOffsets[j]; k<nameOffsets[j+1]; k++) { |
1073 | fonts[j].name += getCard8(); | |
1074 | } | |
1075 | //System.err.println("name["+j+"]=<"+fonts[j].name+">"); | |
1076 | } | |
1077 | | |
1078 | // string index | |
1079 | | |
1080 | //strings = new String[stringOffsets.length-1]; | |
1081 | /* | |
1082 | System.err.println("std strings = "+standardStrings.length); | |
1083 | System.err.println("fnt strings = "+(stringOffsets.length-1)); | |
1084 | for (char j=0; j<standardStrings.length+(stringOffsets.length-1); j++) { | |
1085 | //seek(stringOffsets[j]); | |
1086 | //strings[j] = ""; | |
1087 | //for (int k=stringOffsets[j]; k<stringOffsets[j+1]; k++) { | |
1088 | // strings[j] += (char)getCard8(); | |
1089 | //} | |
1090 | System.err.println("j="+(int)j+" <? "+(standardStrings.length+(stringOffsets.length-1))); | |
1091 | System.err.println("strings["+(int)j+"]=<"+getString(j)+">"); | |
1092 | } | |
1093 | */ | |
1094 | | |
1095 | // top dict | |
1096 | | |
1097 |
4
1. 2. 3. 4. |
for (int j=0; j<topdictOffsets.length-1; j++) { |
1098 |
1
1. |
seek(topdictOffsets[j]); |
1099 |
3
1. 2. 3. |
while (getPosition() < topdictOffsets[j+1]) { |
1100 |
1
1. |
getDictItem(); |
1101 |
1
1. |
if (Objects.equals(key, "FullName")) { |
1102 | //System.err.println("getting fullname sid = "+((Integer)args[0]).intValue()); | |
1103 | fonts[j].fullName = getString((char)((Integer)args[0]).intValue()); | |
1104 | //System.err.println("got it"); | |
1105 |
1
1. |
} else if (Objects.equals(key, "ROS")) |
1106 | fonts[j].isCID = true; | |
1107 |
1
1. |
else if (Objects.equals(key, "Private")) { |
1108 | fonts[j].privateLength = (Integer) args[0]; | |
1109 | fonts[j].privateOffset = (Integer) args[1]; | |
1110 | } | |
1111 |
1
1. |
else if (Objects.equals(key, "charset")){ |
1112 | fonts[j].charsetOffset = (Integer) args[0]; | |
1113 | | |
1114 | } | |
1115 |
1
1. |
else if (Objects.equals(key, "Encoding")){ |
1116 | fonts[j].encodingOffset = (Integer) args[0]; | |
1117 |
1
1. |
ReadEncoding(fonts[j].encodingOffset); |
1118 | } | |
1119 |
1
1. |
else if (Objects.equals(key, "CharStrings")) { |
1120 | fonts[j].charstringsOffset = (Integer) args[0]; | |
1121 | //System.err.println("charstrings "+fonts[j].charstringsOffset); | |
1122 | // Added by Oren & Ygal | |
1123 | int p = getPosition(); | |
1124 | fonts[j].charstringsOffsets = getIndex(fonts[j].charstringsOffset); | |
1125 |
1
1. |
seek(p); |
1126 |
1
1. |
} else if (Objects.equals(key, "FDArray")) |
1127 | fonts[j].fdarrayOffset = (Integer) args[0]; | |
1128 |
1
1. |
else if (Objects.equals(key, "FDSelect")) |
1129 | fonts[j].fdselectOffset = (Integer) args[0]; | |
1130 |
1
1. |
else if (Objects.equals(key, "CharstringType")) |
1131 | fonts[j].CharstringType = (Integer) args[0]; | |
1132 | } | |
1133 | | |
1134 | // private dict | |
1135 |
2
1. 2. |
if (fonts[j].privateOffset >= 0) { |
1136 | //System.err.println("PRIVATE::"); | |
1137 |
1
1. |
seek(fonts[j].privateOffset); |
1138 |
3
1. 2. 3. |
while (getPosition() < fonts[j].privateOffset+fonts[j].privateLength) { |
1139 |
1
1. |
getDictItem(); |
1140 |
1
1. |
if (Objects.equals(key, "Subrs")) |
1141 | //Add the private offset to the lsubrs since the offset is | |
1142 | // relative to the beginning of the PrivateDict | |
1143 |
1
1. |
fonts[j].privateSubrs = (Integer) args[0] +fonts[j].privateOffset; |
1144 | } | |
1145 | } | |
1146 | | |
1147 | // fdarray index | |
1148 |
2
1. 2. |
if (fonts[j].fdarrayOffset >= 0) { |
1149 | int[] fdarrayOffsets = getIndex(fonts[j].fdarrayOffset); | |
1150 | | |
1151 |
1
1. |
fonts[j].fdprivateOffsets = new int[fdarrayOffsets.length-1]; |
1152 |
1
1. |
fonts[j].fdprivateLengths = new int[fdarrayOffsets.length-1]; |
1153 | | |
1154 | //System.err.println("FD Font::"); | |
1155 | | |
1156 |
4
1. 2. 3. 4. |
for (int k=0; k<fdarrayOffsets.length-1; k++) { |
1157 |
1
1. |
seek(fdarrayOffsets[k]); |
1158 |
3
1. 2. 3. |
while (getPosition() < fdarrayOffsets[k+1]) |
1159 |
1
1. |
getDictItem(); |
1160 |
1
1. |
if (Objects.equals(key, "Private")) { |
1161 | fonts[j].fdprivateLengths[k] = (Integer) args[0]; | |
1162 | fonts[j].fdprivateOffsets[k] = (Integer) args[1]; | |
1163 | } | |
1164 | | |
1165 | } | |
1166 | } | |
1167 | } | |
1168 | //System.err.println("CFF: done"); | |
1169 | } | |
1170 | | |
1171 | // ADDED BY Oren & Ygal | |
1172 | | |
1173 | void ReadEncoding(int nextIndexOffset){ | |
1174 | int format; | |
1175 |
1
1. ReadEncoding : removed call to com/lowagie/text/pdf/CFFFont::seek → NO_COVERAGE |
seek(nextIndexOffset); |
1176 | format = getCard8(); | |
1177 | } | |
1178 | } | |
Mutations | ||
175 |
1.1 2.2 3.3 |
|
176 |
1.1 2.2 3.3 4.4 5.5 |
|
177 |
1.1 |
|
180 |
1.1 |
|
182 |
1.1 2.2 3.3 4.4 |
|
185 |
1.1 |
|
186 |
1.1 |
|
192 |
1.1 2.2 |
|
201 |
1.1 |
|
210 |
1.1 2.2 3.3 |
|
211 |
1.1 |
|
212 |
1.1 |
|
214 |
1.1 |
|
219 |
1.1 |
|
228 |
1.1 |
|
237 |
1.1 |
|
246 |
1.1 |
|
260 |
1.1 |
|
262 |
1.1 |
|
264 |
1.1 |
|
266 |
1.1 |
|
267 |
1.1 |
|
272 |
1.1 2.2 3.3 |
|
274 |
1.1 2.2 3.3 4.4 5.5 6.6 |
|
282 |
1.1 |
|
285 |
1.1 |
|
293 |
1.1 2.2 3.3 |
|
298 |
1.1 |
|
300 |
1.1 |
|
303 |
1.1 |
|
307 |
1.1 |
|
310 |
1.1 |
|
314 |
1.1 2.2 3.3 4.4 |
|
315 |
1.1 |
|
317 |
1.1 |
|
321 |
1.1 2.2 3.3 4.4 |
|
323 |
1.1 2.2 3.3 4.4 |
|
325 |
1.1 |
|
329 |
1.1 2.2 3.3 4.4 |
|
331 |
1.1 2.2 3.3 4.4 5.5 |
|
333 |
1.1 |
|
337 |
1.1 |
|
343 |
1.1 |
|
345 |
1.1 |
|
346 |
1.1 2.2 3.3 |
|
347 |
1.1 2.2 3.3 |
|
355 |
1.1 2.2 3.3 4.4 |
|
365 |
1.1 |
|
369 |
1.1 2.2 |
|
371 |
1.1 |
|
372 |
1.1 |
|
417 |
1.1 |
|
418 |
1.1 |
|
423 |
1.1 |
|
424 |
1.1 2.2 3.3 4.4 |
|
446 |
1.1 |
|
447 |
1.1 |
|
453 |
1.1 2.2 3.3 |
|
454 |
1.1 |
|
456 |
1.1 2.2 3.3 |
|
457 |
1.1 |
|
459 |
1.1 2.2 3.3 |
|
460 |
1.1 |
|
462 |
1.1 2.2 3.3 |
|
463 |
1.1 |
|
488 |
1.1 2.2 3.3 |
|
504 |
1.1 2.2 |
|
517 |
1.1 |
|
518 |
1.1 |
|
522 |
1.1 |
|
524 |
1.1 2.2 3.3 |
|
525 |
1.1 2.2 3.3 |
|
526 |
1.1 2.2 3.3 |
|
527 |
1.1 2.2 3.3 |
|
540 |
1.1 |
|
541 |
1.1 |
|
545 |
1.1 2.2 3.3 |
|
546 |
1.1 2.2 3.3 |
|
547 |
1.1 2.2 3.3 |
|
559 |
1.1 |
|
560 |
1.1 |
|
564 |
1.1 2.2 3.3 |
|
565 |
1.1 2.2 3.3 |
|
566 |
1.1 2.2 3.3 |
|
567 |
1.1 2.2 3.3 |
|
579 |
1.1 |
|
580 |
1.1 |
|
584 |
1.1 2.2 3.3 |
|
585 |
1.1 2.2 3.3 |
|
597 |
1.1 |
|
598 |
1.1 |
|
602 |
1.1 2.2 3.3 |
|
611 |
1.1 |
|
612 |
1.1 |
|
615 |
1.1 2.2 |
|
616 |
1.1 2.2 |
|
631 |
1.1 |
|
632 |
1.1 |
|
636 |
1.1 |
|
638 |
1.1 2.2 3.3 |
|
639 |
1.1 2.2 3.3 |
|
640 |
1.1 2.2 3.3 |
|
641 |
1.1 2.2 3.3 |
|
654 |
1.1 |
|
665 |
1.1 |
|
667 |
1.1 |
|
668 |
1.1 |
|
671 |
1.1 2.2 3.3 4.4 5.5 |
|
672 |
1.1 |
|
673 |
1.1 2.2 3.3 4.4 5.5 |
|
694 |
1.1 2.2 |
|
695 |
1.1 |
|
696 |
1.1 2.2 |
|
702 |
1.1 |
|
710 |
1.1 |
|
713 |
1.1 |
|
715 |
1.1 |
|
717 |
1.1 |
|
718 |
1.1 |
|
724 |
1.1 |
|
725 |
1.1 |
|
726 |
1.1 |
|
727 |
1.1 2.2 |
|
728 |
1.1 |
|
733 |
1.1 |
|
734 |
1.1 |
|
735 |
1.1 |
|
737 |
1.1 |
|
739 |
1.1 |
|
756 |
1.1 |
|
758 |
1.1 |
|
759 |
1.1 2.2 |
|
760 |
1.1 |
|
761 |
1.1 |
|
762 |
1.1 |
|
764 |
1.1 |
|
765 |
1.1 |
|
766 |
1.1 |
|
772 |
1.1 |
|
773 |
1.1 |
|
774 |
1.1 |
|
776 |
1.1 |
|
777 |
1.1 |
|
778 |
1.1 |
|
780 |
1.1 |
|
781 |
1.1 |
|
783 |
1.1 |
|
784 |
1.1 |
|
786 |
1.1 |
|
787 |
1.1 2.2 3.3 |
|
789 |
1.1 |
|
791 |
1.1 |
|
792 |
1.1 |
|
793 |
1.1 |
|
794 |
1.1 |
|
795 |
1.1 |
|
796 |
1.1 |
|
800 |
1.1 |
|
804 |
1.1 |
|
810 |
1.1 |
|
811 |
1.1 |
|
814 |
1.1 2.2 |
|
818 |
1.1 2.2 |
|
820 |
1.1 |
|
823 |
1.1 2.2 3.3 |
|
824 |
1.1 2.2 3.3 |
|
825 |
1.1 2.2 3.3 |
|
828 |
1.1 2.2 3.3 |
|
829 |
1.1 |
|
831 |
1.1 2.2 |
|
833 |
1.1 2.2 |
|
836 |
1.1 |
|
837 |
1.1 |
|
838 |
1.1 |
|
839 |
1.1 |
|
840 |
1.1 |
|
841 |
1.1 |
|
843 |
1.1 |
|
844 |
1.1 |
|
849 |
1.1 |
|
853 |
1.1 |
|
857 |
1.1 |
|
858 |
1.1 |
|
859 |
1.1 |
|
861 |
1.1 |
|
862 |
1.1 |
|
864 |
1.1 |
|
869 |
1.1 |
|
870 |
1.1 |
|
872 |
1.1 |
|
873 |
1.1 2.2 |
|
878 |
1.1 |
|
879 |
1.1 |
|
880 |
1.1 |
|
881 |
1.1 |
|
884 |
1.1 |
|
886 |
1.1 |
|
895 |
1.1 |
|
897 |
1.1 |
|
898 |
1.1 |
|
900 |
1.1 |
|
904 |
1.1 |
|
908 |
1.1 |
|
909 |
1.1 2.2 |
|
911 |
1.1 |
|
917 |
1.1 |
|
918 |
1.1 |
|
928 |
1.1 |
|
934 |
1.1 |
|
943 |
1.1 |
|
946 |
1.1 |
|
952 |
1.1 2.2 |
|
953 |
1.1 2.2 |
|
954 |
1.1 |
|
959 |
1.1 2.2 |
|
960 |
1.1 2.2 |
|
961 |
1.1 |
|
967 |
1.1 2.2 |
|
969 |
1.1 |
|
1029 |
1.1 |
|
1047 |
1.1 |
|
1049 |
1.1 |
|
1051 |
1.1 |
|
1054 |
1.1 |
|
1068 |
1.1 2.2 3.3 4.4 |
|
1070 |
1.1 |
|
1072 |
1.1 2.2 3.3 4.4 |
|
1097 |
1.1 2.2 3.3 4.4 |
|
1098 |
1.1 |
|
1099 |
1.1 2.2 3.3 |
|
1100 |
1.1 |
|
1101 |
1.1 |
|
1105 |
1.1 |
|
1107 |
1.1 |
|
1111 |
1.1 |
|
1115 |
1.1 |
|
1117 |
1.1 |
|
1119 |
1.1 |
|
1125 |
1.1 |
|
1126 |
1.1 |
|
1128 |
1.1 |
|
1130 |
1.1 |
|
1135 |
1.1 2.2 |
|
1137 |
1.1 |
|
1138 |
1.1 2.2 3.3 |
|
1139 |
1.1 |
|
1140 |
1.1 |
|
1143 |
1.1 |
|
1148 |
1.1 2.2 |
|
1151 |
1.1 |
|
1152 |
1.1 |
|
1156 |
1.1 2.2 3.3 4.4 |
|
1157 |
1.1 |
|
1158 |
1.1 2.2 3.3 |
|
1159 |
1.1 |
|
1160 |
1.1 |
|
1175 |
1.1 |