@syncfusion/ej2-pdf-data-extract 30.1.42 → 30.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/dist/ej2-pdf-data-extract.umd.min.js +1 -2
  2. package/dist/global/ej2-pdf-data-extract.min.js +1 -2
  3. package/dist/global/index.d.ts +1 -2
  4. package/package.json +14 -46
  5. package/dist/ts/index.d.ts +0 -20
  6. package/dist/ts/index.ts +0 -20
  7. package/dist/ts/pdf-data-extract/core/content-parser-helper.d.ts +0 -62
  8. package/dist/ts/pdf-data-extract/core/content-parser-helper.ts +0 -640
  9. package/dist/ts/pdf-data-extract/core/enum.d.ts +0 -6
  10. package/dist/ts/pdf-data-extract/core/enum.ts +0 -6
  11. package/dist/ts/pdf-data-extract/core/graphic-state.d.ts +0 -33
  12. package/dist/ts/pdf-data-extract/core/graphic-state.ts +0 -106
  13. package/dist/ts/pdf-data-extract/core/pdf-data-extractor.d.ts +0 -210
  14. package/dist/ts/pdf-data-extract/core/pdf-data-extractor.ts +0 -977
  15. package/dist/ts/pdf-data-extract/core/pdf-text-parser.d.ts +0 -67
  16. package/dist/ts/pdf-data-extract/core/pdf-text-parser.ts +0 -495
  17. package/dist/ts/pdf-data-extract/core/redaction/index.d.ts +0 -4
  18. package/dist/ts/pdf-data-extract/core/redaction/index.ts +0 -4
  19. package/dist/ts/pdf-data-extract/core/redaction/pdf-redaction-processor.d.ts +0 -55
  20. package/dist/ts/pdf-data-extract/core/redaction/pdf-redaction-processor.ts +0 -592
  21. package/dist/ts/pdf-data-extract/core/redaction/pdf-redaction-region.d.ts +0 -281
  22. package/dist/ts/pdf-data-extract/core/redaction/pdf-redaction-region.ts +0 -342
  23. package/dist/ts/pdf-data-extract/core/redaction/pdf-redactor.d.ts +0 -129
  24. package/dist/ts/pdf-data-extract/core/redaction/pdf-redactor.ts +0 -322
  25. package/dist/ts/pdf-data-extract/core/redaction/text-glyph-mapper.d.ts +0 -12
  26. package/dist/ts/pdf-data-extract/core/redaction/text-glyph-mapper.ts +0 -153
  27. package/dist/ts/pdf-data-extract/core/text-extraction/binary-cmap-reader.d.ts +0 -24
  28. package/dist/ts/pdf-data-extract/core/text-extraction/binary-cmap-reader.ts +0 -281
  29. package/dist/ts/pdf-data-extract/core/text-extraction/cmap.d.ts +0 -50
  30. package/dist/ts/pdf-data-extract/core/text-extraction/cmap.ts +0 -565
  31. package/dist/ts/pdf-data-extract/core/text-extraction/compact-font-parser.d.ts +0 -191
  32. package/dist/ts/pdf-data-extract/core/text-extraction/compact-font-parser.ts +0 -1928
  33. package/dist/ts/pdf-data-extract/core/text-extraction/encoding-utils.d.ts +0 -102
  34. package/dist/ts/pdf-data-extract/core/text-extraction/encoding-utils.ts +0 -5780
  35. package/dist/ts/pdf-data-extract/core/text-extraction/font-structure.d.ts +0 -167
  36. package/dist/ts/pdf-data-extract/core/text-extraction/font-structure.ts +0 -1842
  37. package/dist/ts/pdf-data-extract/core/text-extraction/font-tables.d.ts +0 -5
  38. package/dist/ts/pdf-data-extract/core/text-extraction/font-tables.ts +0 -16
  39. package/dist/ts/pdf-data-extract/core/text-extraction/font-utils.d.ts +0 -18
  40. package/dist/ts/pdf-data-extract/core/text-extraction/font-utils.ts +0 -630
  41. package/dist/ts/pdf-data-extract/core/text-extraction/glyph.d.ts +0 -93
  42. package/dist/ts/pdf-data-extract/core/text-extraction/glyph.ts +0 -622
  43. package/dist/ts/pdf-data-extract/core/text-extraction/index.d.ts +0 -10
  44. package/dist/ts/pdf-data-extract/core/text-extraction/index.ts +0 -10
  45. package/dist/ts/pdf-data-extract/core/text-extraction/matrix-helper.d.ts +0 -38
  46. package/dist/ts/pdf-data-extract/core/text-extraction/matrix-helper.ts +0 -150
  47. package/dist/ts/pdf-data-extract/core/text-extraction/metrics.d.ts +0 -16
  48. package/dist/ts/pdf-data-extract/core/text-extraction/metrics.ts +0 -2938
  49. package/dist/ts/pdf-data-extract/core/text-structure.d.ts +0 -628
  50. package/dist/ts/pdf-data-extract/core/text-structure.ts +0 -668
  51. package/dist/ts/pdf-data-extract/core/utils.d.ts +0 -99
  52. package/dist/ts/pdf-data-extract/core/utils.ts +0 -626
  53. package/dist/ts/pdf-data-extract/index.d.ts +0 -20
  54. package/dist/ts/pdf-data-extract/index.ts +0 -20
@@ -1,1928 +0,0 @@
1
- import { _bytesToString, _defineProperty, _stringToBytes, FormatError } from '@syncfusion/ej2-pdf';
2
- import { _expertEncoding, _standardEncoding, _getEncoding, _getGlyphsUnicode } from './encoding-utils';
3
- import { _FontStructure } from './font-structure';
4
- import { _recoverGlyphName } from './font-utils';
5
- export class _PdfCompactFontParser {
6
- _bytes: Uint8Array;
7
- _properties: any; //eslint-disable-line
8
- _isAnalysisEnabled: boolean;
9
- _compactFontFormat: _PdfCompactFormatFont;
10
- _values: any; //eslint-disable-line
11
- _characterValidationData: any = [ //eslint-disable-line
12
- null,
13
- { id: 'hstem', min: 2, stackClearing: true, stem: true },
14
- null,
15
- { id: 'vstem', min: 2, stackClearing: true, stem: true },
16
- { id: 'vmoveto', min: 1, stackClearing: true },
17
- { id: 'rlineto', min: 2, resetStack: true },
18
- { id: 'hlineto', min: 1, resetStack: true },
19
- { id: 'vlineto', min: 1, resetStack: true },
20
- { id: 'rrcurveto', min: 6, resetStack: true },
21
- null,
22
- { id: 'callsubr', min: 1, undefStack: true },
23
- { id: 'return', min: 0, undefStack: true },
24
- null,
25
- null,
26
- { id: 'endchar', min: 0, stackClearing: true },
27
- null,
28
- null,
29
- null,
30
- { id: 'hstemhm', min: 2, stackClearing: true, stem: true },
31
- { id: 'hintmask', min: 0, stackClearing: true },
32
- { id: 'cntrmask', min: 0, stackClearing: true },
33
- { id: 'rmoveto', min: 2, stackClearing: true },
34
- { id: 'hmoveto', min: 1, stackClearing: true },
35
- { id: 'vstemhm', min: 2, stackClearing: true, stem: true },
36
- { id: 'rcurveline', min: 8, resetStack: true },
37
- { id: 'rlinecurve', min: 8, resetStack: true },
38
- { id: 'vvcurveto', min: 4, resetStack: true },
39
- { id: 'hhcurveto', min: 4, resetStack: true },
40
- null,
41
- { id: 'callgsubr', min: 1, undefStack: true },
42
- { id: 'vhcurveto', min: 4, resetStack: true },
43
- { id: 'hvcurveto', min: 4, resetStack: true }
44
- ];
45
- _characterValidationData12: any = [ //eslint-disable-line
46
- null,
47
- null,
48
- null,
49
- { id: 'and', min: 2, stackDelta: -1 },
50
- { id: 'or', min: 2, stackDelta: -1 },
51
- { id: 'not', min: 1, stackDelta: 0 },
52
- null,
53
- null,
54
- null,
55
- { id: 'abs', min: 1, stackDelta: 0 },
56
- {
57
- id: 'add',
58
- min: 2,
59
- stackDelta: -1,
60
- stackFn(stack: any, index: any) { //eslint-disable-line
61
- stack[index - 2] = stack[index - 2] + stack[index - 1];
62
- }
63
- },
64
- {
65
- id: 'sub',
66
- min: 2,
67
- stackDelta: -1,
68
- stackFn(stack: any, index: any) { //eslint-disable-line
69
- stack[index - 2] = stack[index - 2] - stack[index - 1];
70
- }
71
- },
72
- {
73
- id: 'div',
74
- min: 2,
75
- stackDelta: -1,
76
- stackFn(stack: any, index: any) { //eslint-disable-line
77
- stack[index - 2] = stack[index - 2] / stack[index - 1];
78
- }
79
- },
80
- null,
81
- {
82
- id: 'neg',
83
- min: 1,
84
- stackDelta: 0,
85
- stackFn(stack: any, index: any) { //eslint-disable-line
86
- stack[index - 1] = -stack[index - 1];
87
- }
88
- },
89
- { id: 'eq', min: 2, stackDelta: -1 },
90
- null,
91
- null,
92
- { id: 'drop', min: 1, stackDelta: -1 },
93
- null,
94
- { id: 'put', min: 2, stackDelta: -2 },
95
- { id: 'get', min: 1, stackDelta: 0 },
96
- { id: 'ifelse', min: 4, stackDelta: -3 },
97
- { id: 'random', min: 0, stackDelta: 1 },
98
- {
99
- id: 'mul',
100
- min: 2,
101
- stackDelta: -1,
102
- stackFn(stack: any, index: any) { //eslint-disable-line
103
- stack[index - 2] = stack[index - 2] * stack[index - 1];
104
- }
105
- },
106
- null,
107
- { id: 'sqrt', min: 1, stackDelta: 0 },
108
- { id: 'dup', min: 1, stackDelta: 1 },
109
- { id: 'exch', min: 2, stackDelta: 0 },
110
- { id: 'index', min: 2, stackDelta: 0 },
111
- { id: 'roll', min: 3, stackDelta: -2 },
112
- null,
113
- null,
114
- null,
115
- { id: 'hflex', min: 7, resetStack: true },
116
- { id: 'flex', min: 13, resetStack: true },
117
- { id: 'hflex1', min: 9, resetStack: true },
118
- { id: 'flex1', min: 11, resetStack: true }
119
- ];
120
- _compactCharSetPredefinedTypes: any = { //eslint-disable-line
121
- standard: 0,
122
- expert: 1,
123
- expertSubset: 2
124
- };
125
- _standardCharSet: string[] = [
126
- '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar',
127
- 'percent', 'ampersand', 'quoteright', 'parenleft', 'parenright',
128
- 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash', 'zero',
129
- 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
130
- 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question',
131
- 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
132
- 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
133
- 'bracketleft', 'backslash', 'bracketright', 'asciicircum', 'underscore',
134
- 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
135
- 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
136
- 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
137
- 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
138
- 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
139
- 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
140
- 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase',
141
- 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
142
- 'perthousand', 'questiondown', 'grave', 'acute', 'circumflex', 'tilde',
143
- 'macron', 'breve', 'dotaccent', 'dieresis', 'ring', 'cedilla',
144
- 'hungarumlaut', 'ogonek', 'caron', 'emdash', 'AE', 'ordfeminine',
145
- 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae', 'dotlessi', 'lslash',
146
- 'oslash', 'oe', 'germandbls', 'onesuperior', 'logicalnot', 'mu',
147
- 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn', 'onequarter',
148
- 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters', 'twosuperior',
149
- 'registered', 'minus', 'eth', 'multiply', 'threesuperior', 'copyright',
150
- 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring', 'Atilde',
151
- 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave', 'Iacute',
152
- 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute', 'Ocircumflex',
153
- 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute', 'Ucircumflex',
154
- 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron', 'aacute',
155
- 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde', 'ccedilla',
156
- 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute', 'icircumflex',
157
- 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex', 'odieresis',
158
- 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex', 'udieresis',
159
- 'ugrave', 'yacute', 'ydieresis', 'zcaron'
160
- ];
161
- _expertCharSet: string[] = [
162
- '.notdef', 'space', 'exclamsmall', 'Hungarumlautsmall', 'dollaroldstyle',
163
- 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
164
- 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
165
- 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
166
- 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
167
- 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle',
168
- 'colon', 'semicolon', 'commasuperior', 'threequartersemdash',
169
- 'periodsuperior', 'questionsmall', 'asuperior', 'bsuperior',
170
- 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
171
- 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
172
- 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
173
- 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
174
- 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
175
- 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
176
- 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
177
- 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
178
- 'onefitted', 'rupiah', 'Tildesmall', 'exclamdownsmall', 'centoldstyle',
179
- 'Lslashsmall', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall',
180
- 'Brevesmall', 'Caronsmall', 'Dotaccentsmall', 'Macronsmall',
181
- 'figuredash', 'hypheninferior', 'Ogoneksmall', 'Ringsmall',
182
- 'Cedillasmall', 'onequarter', 'onehalf', 'threequarters',
183
- 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
184
- 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
185
- 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
186
- 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
187
- 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
188
- 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
189
- 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
190
- 'periodinferior', 'commainferior', 'Agravesmall', 'Aacutesmall',
191
- 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall', 'Aringsmall',
192
- 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
193
- 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
194
- 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
195
- 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
196
- 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
197
- 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
198
- 'Ydieresissmall'
199
- ];
200
- _expertSubsetCharSet: string[] = [
201
- '.notdef', 'space', 'dollaroldstyle', 'dollarsuperior',
202
- 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
203
- 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction',
204
- 'zerooldstyle', 'oneoldstyle', 'twooldstyle', 'threeoldstyle',
205
- 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle',
206
- 'eightoldstyle', 'nineoldstyle', 'colon', 'semicolon', 'commasuperior',
207
- 'threequartersemdash', 'periodsuperior', 'asuperior', 'bsuperior',
208
- 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
209
- 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
210
- 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
211
- 'parenrightinferior', 'hyphensuperior', 'colonmonetary', 'onefitted',
212
- 'rupiah', 'centoldstyle', 'figuredash', 'hypheninferior', 'onequarter',
213
- 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
214
- 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
215
- 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
216
- 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
217
- 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
218
- 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
219
- 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
220
- 'periodinferior', 'commainferior'
221
- ];
222
- _standardEncodingChars: any = []; //eslint-disable-line
223
- _widths: any = []; //eslint-disable-line
224
- _pos: number = 0;
225
- constructor(file: any, properties: any, isAnalysisEnabled: boolean) { //eslint-disable-line
226
- this._bytes = file.getBytes();
227
- this._properties = properties;
228
- this._isAnalysisEnabled = isAnalysisEnabled;
229
- }
230
- _parsePrivateDictionary(parentDictionary: any): any { //eslint-disable-line
231
- if (!parentDictionary._hasName('Private')) {
232
- this._emptyPrivateDictionary(parentDictionary);
233
- return;
234
- }
235
- const privateOffset: any = parentDictionary._getByName('Private'); //eslint-disable-line
236
- if (!Array.isArray(privateOffset) || privateOffset.length !== 2) {
237
- parentDictionary._removeByName('Private');
238
- return;
239
- }
240
- const size: number = privateOffset[0];
241
- const offset: number = privateOffset[1];
242
- if (size === 0 || offset >= this._bytes.length) {
243
- this._emptyPrivateDictionary(parentDictionary);
244
- return;
245
- }
246
- const privateDictionary: any = this._createDictionary(_PdfCompactFontPrivateDictionary, this._parseDictionary(this._bytes.subarray(offset, offset + size)), parentDictionary.strings); //eslint-disable-line
247
- parentDictionary.privateDictionary = privateDictionary;
248
- if (privateDictionary._getByName('ExpansionFactor') === 0) {
249
- privateDictionary._setByName('ExpansionFactor', 0.06);
250
- }
251
- if (!privateDictionary._getByName('Subrs')) {
252
- return;
253
- }
254
- const subrsOffset: any = privateDictionary._getByName('Subrs'); //eslint-disable-line
255
- const relativeOffset: any = offset + subrsOffset; //eslint-disable-line
256
- if (subrsOffset === 0 || relativeOffset >= this._bytes.length) {
257
- this._emptyPrivateDictionary(parentDictionary);
258
- return;
259
- }
260
- const subroutineIndex: any = this._parseIndex(relativeOffset); //eslint-disable-line
261
- privateDictionary.subroutineIndex = subroutineIndex.obj;
262
- }
263
- _parse(properties?: any): _PdfCompactFormatFont { //eslint-disable-line
264
- const compactFontFormat: _PdfCompactFormatFont = new _PdfCompactFormatFont();
265
- this._compactFontFormat = compactFontFormat;
266
- const header: any = this._parseHeader(); //eslint-disable-line
267
- const nameIndex: any = this._parseIndex(header.endPos); //eslint-disable-line
268
- const topDictIndex: any = this._parseIndex(nameIndex.endPos); //eslint-disable-line
269
- const stringIndex: any = this._parseIndex(topDictIndex.endPos); //eslint-disable-line
270
- const globalSubroutineIndex: any = this._parseIndex(stringIndex.endPos); //eslint-disable-line
271
- const topDictParsed: any = this._parseDictionary(topDictIndex.obj._get(0)); //eslint-disable-line
272
- const topDict: any = this._createDictionary(_PdfCompactFontTopDictionary, topDictParsed, compactFontFormat.strings); //eslint-disable-line
273
- compactFontFormat.header = header.obj;
274
- compactFontFormat.names = this._parseNameIndex(nameIndex.obj);
275
- compactFontFormat.strings = this._parseStringIndex(stringIndex.obj);
276
- compactFontFormat.topDictionary = topDict;
277
- compactFontFormat.globalSubroutineIndex = globalSubroutineIndex.obj;
278
- this._parsePrivateDictionary(compactFontFormat.topDictionary);
279
- compactFontFormat.isCharacterIdentifierFont = topDict._hasName('ROS');
280
- const charStringOffset: any = topDict._getByName('CharStrings'); //eslint-disable-line
281
- const charStringIndex: any = this._parseIndex(charStringOffset).obj; //eslint-disable-line
282
- const fontMatrix: any = topDict._getByName('FontMatrix'); //eslint-disable-line
283
- if (fontMatrix) {
284
- properties._fontStructure._fontMatrix = fontMatrix;
285
- }
286
- const fontBBox: any = topDict._getByName('FontBBox'); //eslint-disable-line
287
- if (fontBBox) {
288
- properties.ascent = Math.max(fontBBox[3], fontBBox[1]);
289
- properties.descent = Math.min(fontBBox[1], fontBBox[3]);
290
- properties.ascentScaled = true;
291
- }
292
- let charSet: any; //eslint-disable-line
293
- let encoding: any; //eslint-disable-line
294
- if (compactFontFormat.isCharacterIdentifierFont) {
295
- const fontDictionaryArrayIndex: any = this._parseIndex(topDict._getByName('FDArray')).obj; //eslint-disable-line
296
- for (let i: number = 0, ii: number = fontDictionaryArrayIndex.count; i < ii; ++i) {
297
- const dictRaw: any = fontDictionaryArrayIndex._get(i); //eslint-disable-line
298
- const fontDict: any = this._createDictionary( //eslint-disable-line
299
- _PdfCompactFontTopDictionary,
300
- this._parseDictionary(dictRaw),
301
- compactFontFormat.strings
302
- );
303
- this._parsePrivateDictionary(fontDict);
304
- compactFontFormat.fontDictionaryArray.push(fontDict);
305
- }
306
- encoding = null;
307
- charSet = this._parseCharSets(
308
- topDict._getByName('charSet'),
309
- charStringIndex.count,
310
- compactFontFormat.strings,
311
- true
312
- );
313
- compactFontFormat.fontDictionarySelect = this._parseFontDictionarySelect(
314
- topDict._getByName('FDSelect'),
315
- charStringIndex.count
316
- );
317
- } else {
318
- charSet = this._parseCharSets(
319
- topDict._getByName('charSet'),
320
- charStringIndex.count,
321
- compactFontFormat.strings,
322
- false
323
- );
324
- encoding = this._parseEncoding(
325
- topDict._getByName('Encoding'),
326
- this._properties,
327
- compactFontFormat.strings,
328
- charSet.charSet
329
- );
330
- }
331
- compactFontFormat.charSet = charSet;
332
- compactFontFormat.encoding = encoding;
333
- const charStringsAndSeacs: any = this._parseCharStrings( //eslint-disable-line
334
- charStringIndex,
335
- topDict.privateDictionary.subroutineIndex,
336
- globalSubroutineIndex.obj,
337
- compactFontFormat.fontDictionarySelect,
338
- compactFontFormat.fontDictionaryArray,
339
- topDict.privateDictionary
340
- );
341
- compactFontFormat.charStrings = charStringsAndSeacs.charStrings;
342
- compactFontFormat.standardEncodingChars = charStringsAndSeacs.standardEncodingChars;
343
- compactFontFormat.widths = charStringsAndSeacs.widths;
344
- return compactFontFormat;
345
- }
346
- _parseCharStrings(charStrings: any,localSubroutineIndex: any,globalSubroutineIndex: any, fontDictionarySelect: any, fontDictionaryArray: any, //eslint-disable-line
347
- privateDictionary: any): any { //eslint-disable-line
348
- const count: number = charStrings.count;
349
- for (let i: number = 0; i < count; i++) {
350
- const charstring: any = charStrings._get(i); //eslint-disable-line
351
- const state: any = { //eslint-disable-line
352
- callDepth: 0,
353
- stackSize: 0,
354
- stack: [],
355
- undefStack: true,
356
- hints: 0,
357
- firstStackClearing: true,
358
- standardCharacter: null,
359
- width: null,
360
- hasVStems: false
361
- };
362
- let valid: boolean = true;
363
- let localSubrToUse: any = null; //eslint-disable-line
364
- let dictionaryToUse: any = privateDictionary; //eslint-disable-line
365
- if (fontDictionarySelect && fontDictionaryArray.length) {
366
- const fontDictionaryIndex: number = fontDictionarySelect.getFDIndex(i);
367
- if (fontDictionaryIndex === -1) {
368
- //warn('Glyph index is not in font dictionary select.');
369
- valid = false;
370
- }
371
- if (fontDictionaryIndex >= fontDictionaryArray.length) {
372
- //warn('Invalid font dictionary index for glyph index.');
373
- valid = false;
374
- }
375
- if (valid) {
376
- dictionaryToUse = fontDictionaryArray[Number.parseInt(fontDictionaryIndex.toString(), 10)].privateDictionary;
377
- localSubrToUse = dictionaryToUse.subroutineIndex;
378
- }
379
- } else if (localSubroutineIndex) {
380
- localSubrToUse = localSubroutineIndex;
381
- }
382
- if (valid) {
383
- valid = this._parseCharString(
384
- state,
385
- charstring,
386
- localSubrToUse,
387
- globalSubroutineIndex
388
- );
389
- }
390
- if (state.width !== null) {
391
- const nominalWidth: number = dictionaryToUse._getByName('nominalWidthX');
392
- this._widths[Number.parseInt(i.toString(), 10)] = nominalWidth + state.width;
393
- } else {
394
- const defaultWidth: any = dictionaryToUse._getByName('defaultWidthX'); //eslint-disable-line
395
- this._widths[Number.parseInt(i.toString(), 10)] = defaultWidth;
396
- }
397
- if (state.standardCharacter !== null) {
398
- this._standardEncodingChars[Number.parseInt(i.toString(), 10)] = state.standardCharacter;
399
- }
400
- if (!valid) {
401
- // resetting invalid charstring to single 'endchar'
402
- charStrings.set(i, new Uint8Array([14]));
403
- }
404
- }
405
- return { charStrings, this: this._standardEncodingChars, widths: this._widths };
406
- }
407
- _parseFontDictionarySelect(pos: number, length: number): any { //eslint-disable-line
408
- const bytes: any = this._bytes; //eslint-disable-line
409
- const format: any = bytes[pos++]; //eslint-disable-line
410
- const fontDictionarySelect: any = []; //eslint-disable-line
411
- let i: number;
412
- let rangesCount: number;
413
- switch (format) {
414
- case 0:
415
- for (i = 0; i < length; ++i) {
416
- const id: any = bytes[pos++]; //eslint-disable-line
417
- fontDictionarySelect.push(id);
418
- }
419
- break;
420
- case 3:
421
- rangesCount = (bytes[pos++] << 8) | bytes[pos++];
422
- for (i = 0; i < rangesCount; ++i) {
423
- let first: number = (bytes[pos++] << 8) | bytes[pos++];
424
- if (i === 0 && first !== 0) {
425
- first = 0;
426
- }
427
- const fontDictionaryIndex: any = bytes[pos++]; //eslint-disable-line
428
- const next: number = (bytes[Number.parseInt(pos.toString(), 10)] << 8) | bytes[pos + 1];
429
- for (let j: number = first; j < next; ++j) {
430
- fontDictionarySelect.push(fontDictionaryIndex);
431
- }
432
- }
433
- pos += 2;
434
- break;
435
- default:
436
- throw new FormatError(`parseFDSelect: Unknown format '${format}'.`);
437
- }
438
- if (fontDictionarySelect.length !== length) {
439
- throw new FormatError('parseFDSelect: Invalid font data.');
440
- }
441
- return new _PdfCompactFontSelect(format, fontDictionarySelect);
442
- }
443
- _parseCharSets(pos: any, length: any, strings: any, characterIdentifier: any): any { //eslint-disable-line
444
- if (pos === 0) {
445
- return new _PdfCompactFontCharacterSet(
446
- true,
447
- this._compactCharSetPredefinedTypes.standard,
448
- this._standardCharSet
449
- );
450
- } else if (pos === 1) {
451
- return new _PdfCompactFontCharacterSet(
452
- true,
453
- this._compactCharSetPredefinedTypes.expert,
454
- this._expertCharSet
455
- );
456
- } else if (pos === 2) {
457
- return new _PdfCompactFontCharacterSet(
458
- true,
459
- this._compactCharSetPredefinedTypes.expertSubset,
460
- this._expertSubsetCharSet
461
- );
462
- }
463
- const bytes: any = this._bytes; //eslint-disable-line
464
- const start: number = pos;
465
- const format: any = bytes[pos++]; //eslint-disable-line
466
- const charSet: any = [characterIdentifier ? 0 : '.notdef']; //eslint-disable-line
467
- let id: number;
468
- let count: number;
469
- let i: number;
470
- length -= 1;
471
- switch (format) {
472
- case 0:
473
- for (i = 0; i < length; i++) {
474
- id = (bytes[pos++] << 8) | bytes[pos++];
475
- charSet.push(characterIdentifier ? id : strings._get(id));
476
- }
477
- break;
478
- case 1:
479
- while (charSet.length <= length) {
480
- id = (bytes[pos++] << 8) | bytes[pos++];
481
- count = bytes[pos++];
482
- for (i = 0; i <= count; i++) {
483
- charSet.push(characterIdentifier ? id++ : strings._get(id++));
484
- }
485
- }
486
- break;
487
- case 2:
488
- while (charSet.length <= length) {
489
- id = (bytes[pos++] << 8) | bytes[pos++];
490
- count = (bytes[pos++] << 8) | bytes[pos++];
491
- for (i = 0; i <= count; i++) {
492
- charSet.push(characterIdentifier ? id++ : strings._get(id++));
493
- }
494
- }
495
- break;
496
- default:
497
- throw new FormatError('Unknown charSet format');
498
- }
499
- const end: number = pos;
500
- const raw: any = bytes.subarray(start, end); //eslint-disable-line
501
- return new _PdfCompactFontCharacterSet(false, format, charSet, raw);
502
- }
503
- _readSupplement(bytes: any, pos: number, encoding: any, charSet: any, strings: any): any {; //eslint-disable-line
504
- const supplementsCount: number = bytes[pos++];
505
- for (let i: number = 0; i < supplementsCount; i++) {
506
- const code: any = bytes[pos++]; //eslint-disable-line
507
- const sid: any = (bytes[pos++] << 8) + (bytes[pos++] & 0xff); //eslint-disable-line
508
- encoding[Number.parseInt(code.toString(), 10)] = charSet.indexOf(strings._get(sid));
509
- }
510
- return encoding;
511
- }
512
- _parseEncoding(pos: any, properties: any, strings: any, charSet: any): any { //eslint-disable-line
513
- let encoding: any = Object.create(null); //eslint-disable-line
514
- const bytes: any = this._bytes; //eslint-disable-line
515
- let predefined: boolean = false;
516
- let format: number;
517
- let i: number;
518
- let ii: number;
519
- let raw: any = null; //eslint-disable-line
520
- if (pos === 0 || pos === 1) {
521
- predefined = true;
522
- format = pos;
523
- const baseEncoding: string[] = pos ? _expertEncoding : _standardEncoding;
524
- for (i = 0, ii = charSet.length; i < ii; i++) {
525
- const index: number = baseEncoding.indexOf(charSet[Number.parseInt(i.toString(), 10)]);
526
- if (index !== -1) {
527
- encoding[Number.parseInt(index.toString(), 10)] = i;
528
- }
529
- }
530
- } else {
531
- const dataStart: number = pos;
532
- format = bytes[pos++];
533
- let rangesCount: number;
534
- let glyphsCount: number;
535
- let gid: number;
536
- switch (format & 0x7f) {
537
- case 0:
538
- glyphsCount = bytes[pos++];
539
- for (i = 1; i <= glyphsCount; i++) {
540
- encoding[bytes[pos++]] = i;
541
- }
542
- break;
543
- case 1:
544
- rangesCount = bytes[pos++];
545
- gid = 1;
546
- for (i = 0; i < rangesCount; i++) {
547
- const start: number = bytes[pos++];
548
- const left: number = bytes[pos++];
549
- for (let j: number = start; j <= start + left; j++) {
550
- encoding[Number.parseInt(j.toString(), 10)] = gid++;
551
- }
552
- }
553
- break;
554
- default:
555
- throw new FormatError(`Unknown encoding format: ${format} in compactFont`);
556
- }
557
- const dataEnd: number = pos;
558
- if (format & 0x80) {
559
- bytes[Number.parseInt(dataStart.toString(), 10)] &= 0x7f;
560
- encoding = this._readSupplement(bytes, pos, encoding, charSet, strings);
561
- }
562
- raw = bytes.subarray(dataStart, dataEnd);
563
- }
564
- format &= 0x7f;
565
- return new _PdfCompactFontEncoding(predefined, format, encoding, raw);
566
- }
567
- private _parseHeader(): any { //eslint-disable-line
568
- let bytes: any = this._bytes; //eslint-disable-line
569
- const bytesLength: number = bytes.length;
570
- let offset: number = 0;
571
- while (offset < bytesLength && bytes[Number.parseInt(offset.toString(), 10)] !== 1) {
572
- ++offset;
573
- }
574
- if (offset >= bytesLength) {
575
- throw new FormatError('Invalid compactFont header');
576
- }
577
- if (offset !== 0) {
578
- bytes = bytes.subarray(offset);
579
- this._bytes = bytes;
580
- }
581
- const major: any = bytes[0]; //eslint-disable-line
582
- const minor: any = bytes[1]; //eslint-disable-line
583
- const headerSize: any = bytes[2]; //eslint-disable-line
584
- const offSize: any = bytes[3]; //eslint-disable-line
585
- const header: _PdfCompactFontHeader = new _PdfCompactFontHeader(major, minor, headerSize, offSize);
586
- return { obj: header, endPos: headerSize };
587
- }
588
- _parseOperand(dictionary: any): number { //eslint-disable-line
589
- let value: number = dictionary[this._pos++];
590
- if (value === 30) {
591
- return this._parseFloatOperand(dictionary);
592
- } else if (value === 28) {
593
- value = dictionary[this._pos++];
594
- value = ((value << 24) | (dictionary[this._pos++] << 16)) >> 16;
595
- return value;
596
- } else if (value === 29) {
597
- value = dictionary[this._pos++];
598
- value = (value << 8) | dictionary[this._pos++];
599
- value = (value << 8) | dictionary[this._pos++];
600
- value = (value << 8) | dictionary[this._pos++];
601
- return value;
602
- } else if (value >= 32 && value <= 246) {
603
- return value - 139;
604
- } else if (value >= 247 && value <= 250) {
605
- return (value - 247) * 256 + dictionary[this._pos++] + 108;
606
- } else if (value >= 251 && value <= 254) {
607
- return -((value - 251) * 256) - dictionary[this._pos++] - 108;
608
- }
609
- return NaN;
610
- }
611
- _parseFloatOperand(dictionary: any): number { //eslint-disable-line
612
- let str: string = '';
613
- const eof: number = 15;
614
- const lookup: any = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.', 'E', 'E-', null, '-']; //eslint-disable-line
615
- const length: number = dictionary.length;
616
- while (this._pos < length) {
617
- const b: number = dictionary[this._pos++];
618
- const b1: number = b >> 4;
619
- const b2: number = b & 15;
620
- if (b1 === eof) {
621
- break;
622
- }
623
- str += lookup[Number.parseInt(b1.toString(), 10)];
624
- if (b2 === eof) {
625
- break;
626
- }
627
- str += lookup[Number.parseInt(b2.toString(), 10)];
628
- }
629
- return parseFloat(str);
630
- }
631
- _parseDictionary(dictionary: any): [number, number[]][] { //eslint-disable-line
632
- let operands: number[] = [];
633
- const entries: [number, number[]][] = [];
634
- const end: number = dictionary.length;
635
- this._pos = 0;
636
- while (this._pos < end) {
637
- let b: number = dictionary[this._pos];
638
- if (b <= 21) {
639
- if (b === 12) {
640
- b = (b << 8) | dictionary[++this._pos];
641
- }
642
- entries.push([b, operands]);
643
- operands = [];
644
- ++this._pos;
645
- } else {
646
- operands.push(this._parseOperand(dictionary));
647
- }
648
- }
649
- return entries;
650
- }
651
- _parseIndex(pos: number): { obj: _PdfCompactFontIndex; endPos: number } {
652
- const compactFontIndex: _PdfCompactFontIndex = new _PdfCompactFontIndex();
653
- const bytes: any = this._bytes; //eslint-disable-line
654
- const count: number = (bytes[pos++] << 8) | bytes[pos++];
655
- const offsets: number[] = [];
656
- let end: number = pos;
657
- if (count !== 0) {
658
- const offsetSize: number = bytes[pos++];
659
- const startPos: number = pos + (count + 1) * offsetSize - 1;
660
- for (let i: number = 0, ii: number = count + 1; i < ii; ++i) {
661
- let offset: number = 0;
662
- for (let j: number = 0; j < offsetSize; ++j) {
663
- offset <<= 8;
664
- offset += bytes[pos++];
665
- }
666
- offsets.push(startPos + offset);
667
- }
668
- end = offsets[Number.parseInt(count.toString(), 10)];
669
- }
670
- for (let i: number = 0, ii: number = offsets.length - 1; i < ii; ++i) {
671
- const offsetStart: number = offsets[Number.parseInt(i.toString(), 10)];
672
- const offsetEnd: number = offsets[i + 1];
673
- compactFontIndex.add(bytes.subarray(offsetStart, offsetEnd));
674
- }
675
- return { obj: compactFontIndex, endPos: end };
676
- }
677
- _parseNameIndex(index: { count: number; _get: (i: number) => Uint8Array }): string[] {
678
- const names: string[] = [];
679
- for (let i: number = 0, ii: number = index.count; i < ii; ++i) {
680
- const name: any = index._get(i); //eslint-disable-line
681
- names.push(_bytesToString(name));
682
- }
683
- return names;
684
- }
685
- _parseStringIndex(index: { count: number; _get: (i: number) => Uint8Array }): _PdfCompactFontStrings {
686
- const strings: _PdfCompactFontStrings = new _PdfCompactFontStrings();
687
- for (let i: number = 0, ii: number = index.count; i < ii; ++i) {
688
- const data: any = index._get(i); //eslint-disable-line
689
- strings._add(_bytesToString(data));
690
- }
691
- return strings;
692
- }
693
- _createDictionary(type: any, dictionary: [number, number[]][], strings: _PdfCompactFontStrings): any { //eslint-disable-line
694
- const compactFontDict: any = new type(strings); //eslint-disable-line
695
- for (const [key, value] of dictionary) {
696
- compactFontDict._setByKey(key, value);
697
- }
698
- return compactFontDict;
699
- }
700
- _parseCharString(
701
- state: any, //eslint-disable-line
702
- data: number[],
703
- localSubroutineIndex: { count: number; get: (index: number) => number[] },
704
- globalSubroutineIndex: { count: number; get: (index: number) => number[] }
705
- ): any { //eslint-disable-line
706
- if (!data || state.callDepth > 1000) {
707
- return false;
708
- }
709
- let stackSize: number = state.stackSize;
710
- const stack: any = state.stack; //eslint-disable-line
711
- let length: number = data.length;
712
- for (let j: number = 0; j < length;) {
713
- const value: number = data[j++];
714
- let validationCommand: any = null; //eslint-disable-line
715
- if (value === 12) {
716
- const q: number = data[j++];
717
- if (q === 0) {
718
- data[j - 2] = 139;
719
- data[j - 1] = 22;
720
- stackSize = 0;
721
- } else {
722
- validationCommand = this._characterValidationData12[Number.parseInt(q.toString(), 10)];
723
- }
724
- } else if (value === 28) {
725
- stack[Number.parseInt(stackSize.toString(), 10)] = ((data[Number.parseInt(j.toString(), 10)] << 24) |
726
- (data[j + 1] << 16)) >> 16;
727
- j += 2;
728
- stackSize++;
729
- } else if (value === 14) {
730
- if (stackSize >= 4) {
731
- stackSize -= 4;
732
- if (this._isAnalysisEnabled) {
733
- state.standardCharacter = stack.slice(stackSize, stackSize + 4);
734
- return false;
735
- }
736
- }
737
- validationCommand = this._characterValidationData[Number.parseInt(value.toString(), 10)];
738
- } else if (value >= 32 && value <= 246) {
739
- stack[Number.parseInt(stackSize.toString(), 10)] = value - 139;
740
- stackSize++;
741
- } else if (value >= 247 && value <= 254) {
742
- stack[Number.parseInt(stackSize.toString(), 10)] = value < 251
743
- ? ((value - 247) << 8) + data[Number.parseInt(j.toString(), 10)] + 108
744
- : -((value - 251) << 8) - data[Number.parseInt(j.toString(), 10)] - 108;
745
- j++;
746
- stackSize++;
747
- } else if (value === 255) {
748
- stack[Number.parseInt(stackSize.toString(), 10)] = ((data[Number.parseInt(j.toString(), 10)] << 24) |
749
- (data[j + 1] << 16) |
750
- (data[j + 2] << 8) |
751
- data[j + 3]) / 65536;
752
- j += 4;
753
- stackSize++;
754
- } else if (value === 19 || value === 20) {
755
- state.hints += stackSize >> 1;
756
- if (state.hints === 0) {
757
- data.copyWithin(j - 1, j, -1);
758
- j -= 1;
759
- length -= 1;
760
- continue;
761
- }
762
- j += (state.hints + 7) >> 3;
763
- stackSize %= 2;
764
- validationCommand = this._characterValidationData[Number.parseInt(value.toString(), 10)];
765
- } else if (value === 10 || value === 29) {
766
- const subroutineIndex: any = value === 10 ? localSubroutineIndex : globalSubroutineIndex; //eslint-disable-line
767
- if (!subroutineIndex) {
768
- validationCommand = this._characterValidationData[Number.parseInt(value.toString(), 10)];
769
- return false;
770
- }
771
- let bias: number = 32768;
772
- if (subroutineIndex.count < 1240) {
773
- bias = 107;
774
- } else if (subroutineIndex.count < 33900) {
775
- bias = 1131;
776
- }
777
- const subrNumber: number = stack[--stackSize] + bias;
778
- if (subrNumber < 0 || subrNumber >= subroutineIndex.count || isNaN(subrNumber)) {
779
- validationCommand = this._characterValidationData[Number.parseInt(value.toString(), 10)];
780
- return false;
781
- }
782
- state.stackSize = stackSize;
783
- state.callDepth++;
784
- const valid: boolean = this._parseCharString(state, subroutineIndex._get(subrNumber), localSubroutineIndex,
785
- globalSubroutineIndex);
786
- if (!valid) {
787
- return false;
788
- }
789
- state.callDepth--;
790
- stackSize = state.stackSize;
791
- continue;
792
- } else if (value === 11) {
793
- state.stackSize = stackSize;
794
- return true;
795
- } else if (value === 0 && j === data.length) {
796
- data[j - 1] = 14;
797
- validationCommand = this._characterValidationData[14];
798
- } else if (value === 9) {
799
- data.copyWithin(j - 1, j, -1);
800
- j -= 1;
801
- length -= 1;
802
- continue;
803
- } else {
804
- validationCommand = this._characterValidationData[Number.parseInt(value.toString(), 10)];
805
- }
806
- if (validationCommand) {
807
- if (validationCommand.stem) {
808
- state.hints += stackSize >> 1;
809
- if (value === 3 || value === 23) {
810
- state.hasVStems = true;
811
- } else if (state.hasVStems && (value === 1 || value === 18)) {
812
- data[j - 1] = value === 1 ? 3 : 23;
813
- }
814
- }
815
- if ('min' in validationCommand) {
816
- if (!state.undefStack && stackSize < validationCommand.min) {
817
- if (stackSize === 0) {
818
- data[j - 1] = 14;
819
- return true;
820
- }
821
- return false;
822
- }
823
- }
824
- if (state.firstStackClearing && validationCommand.stackClearing) {
825
- state.firstStackClearing = false;
826
- stackSize -= validationCommand.min;
827
- if (stackSize >= 2 && validationCommand.stem) {
828
- stackSize %= 2;
829
- }
830
- if (stackSize > 0) {
831
- state.width = stack[stackSize - 1];
832
- }
833
- }
834
- if ('stackDelta' in validationCommand) {
835
- if ('stackFn' in validationCommand) {
836
- validationCommand.stackFn(stack, stackSize);
837
- }
838
- stackSize += validationCommand.stackDelta;
839
- } else if (validationCommand.stackClearing) {
840
- stackSize = 0;
841
- } else if (validationCommand.resetStack) {
842
- stackSize = 0;
843
- state.undefStack = false;
844
- } else if (validationCommand.undefStack) {
845
- stackSize = 0;
846
- state.undefStack = true;
847
- state.firstStackClearing = false;
848
- }
849
- }
850
- }
851
- if (length < data.length) {
852
- data.fill(/* endchar = */ 14, length);
853
- }
854
- state.stackSize = stackSize;
855
- return true;
856
- }
857
- _emptyPrivateDictionary(parentDictionary: any): void { //eslint-disable-line
858
- const privateDictionary: any = this._createDictionary(_PdfCompactFontPrivateDictionary, [], parentDictionary.strings); //eslint-disable-line
859
- parentDictionary._setByKey(18, [0, 0]);
860
- parentDictionary.privateDictionary = privateDictionary;
861
- }
862
- }
863
- export class _PdfCompactFormatFont {
864
- header: any; //eslint-disable-line
865
- names: any; //eslint-disable-line
866
- topDictionary: any; //eslint-disable-line
867
- strings: _PdfCompactFontStrings;
868
- globalSubroutineIndex: any; //eslint-disable-line
869
- encoding: any; //eslint-disable-line
870
- charSet: any; //eslint-disable-line
871
- charStrings: any; //eslint-disable-line
872
- fontDictionaryArray: any; //eslint-disable-line
873
- fontDictionarySelect: any; //eslint-disable-line
874
- isCharacterIdentifierFont: boolean = false;
875
- standardEncodingChars: any = []; //eslint-disable-line
876
- widths: any = []; //eslint-disable-line
877
- constructor() {
878
- this.header = null;
879
- this.names = [];
880
- this.topDictionary = null;
881
- this.strings = new _PdfCompactFontStrings();
882
- this.globalSubroutineIndex = null;
883
- this.encoding = null;
884
- this.charSet = null;
885
- this.charStrings = null;
886
- this.fontDictionaryArray = [];
887
- this.fontDictionarySelect = null;
888
- this.isCharacterIdentifierFont = false;
889
- }
890
- _duplicateFirstGlyph(): void {
891
- if (this.charStrings.count >= 65535) {
892
- return;
893
- }
894
- const glyphZero: any = this.charStrings._get(0); //eslint-disable-line
895
- this.charStrings.add(glyphZero);
896
- if (this.isCharacterIdentifierFont) {
897
- this.fontDictionarySelect.fontDictionarySelect.push(this.fontDictionarySelect.fontDictionarySelect[0]);
898
- }
899
- }
900
- _hasGlyphId(id: any): boolean { //eslint-disable-line
901
- if (id < 0 || id >= this.charStrings.count) {
902
- return false;
903
- }
904
- const glyph: any = this.charStrings._get(id); //eslint-disable-line
905
- return glyph.length > 0;
906
- }
907
- }
908
- export class _PdfCompactFontHeader {
909
- major: any; //eslint-disable-line
910
- minor: any; //eslint-disable-line
911
- headerSize: any; //eslint-disable-line
912
- offSize: any; //eslint-disable-line
913
- constructor(major: any, minor: any, headerSize: any, offSize: any) { //eslint-disable-line
914
- this.major = major;
915
- this.minor = minor;
916
- this.headerSize = headerSize;
917
- this.offSize = offSize;
918
- }
919
- }
920
- export class _PdfCompactFontStrings {
921
- strings: any; //eslint-disable-line
922
- _numberOfStandardCompactFontStrings: number = 391;
923
- _compactFontStandardStrings: string[] = [
924
- '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
925
- 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
926
- 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
927
- 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
928
- 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
929
- 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
930
- 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright', 'asciicircum',
931
- 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
932
- 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
933
- 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
934
- 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
935
- 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
936
- 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
937
- 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase', 'quotedblbase',
938
- 'quotedblright', 'guillemotright', 'ellipsis', 'perthousand', 'questiondown',
939
- 'grave', 'acute', 'circumflex', 'tilde', 'macron', 'breve', 'dotaccent',
940
- 'dieresis', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron', 'emdash',
941
- 'AE', 'ordfeminine', 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae',
942
- 'dotlessi', 'lslash', 'oslash', 'oe', 'germandbls', 'onesuperior',
943
- 'logicalnot', 'mu', 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn',
944
- 'onequarter', 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters',
945
- 'twosuperior', 'registered', 'minus', 'eth', 'multiply', 'threesuperior',
946
- 'copyright', 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring',
947
- 'Atilde', 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave',
948
- 'Iacute', 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute',
949
- 'Ocircumflex', 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute',
950
- 'Ucircumflex', 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron',
951
- 'aacute', 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde',
952
- 'ccedilla', 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute',
953
- 'icircumflex', 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex',
954
- 'odieresis', 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex',
955
- 'udieresis', 'ugrave', 'yacute', 'ydieresis', 'zcaron', 'exclamsmall',
956
- 'Hungarumlautsmall', 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall',
957
- 'Acutesmall', 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
958
- 'onedotenleader', 'zerooldstyle', 'oneoldstyle', 'twooldstyle',
959
- 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle',
960
- 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'commasuperior',
961
- 'threequartersemdash', 'periodsuperior', 'questionsmall', 'asuperior',
962
- 'bsuperior', 'centsuperior', 'dsuperior', 'esuperior', 'isuperior',
963
- 'lsuperior', 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
964
- 'tsuperior', 'ff', 'ffi', 'ffl', 'parenleftinferior', 'parenrightinferior',
965
- 'Circumflexsmall', 'hyphensuperior', 'Gravesmall', 'Asmall', 'Bsmall',
966
- 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
967
- 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
968
- 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
969
- 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
970
- 'Tildesmall', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
971
- 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall', 'Caronsmall',
972
- 'Dotaccentsmall', 'Macronsmall', 'figuredash', 'hypheninferior',
973
- 'Ogoneksmall', 'Ringsmall', 'Cedillasmall', 'questiondownsmall', 'oneeighth',
974
- 'threeeighths', 'fiveeighths', 'seveneighths', 'onethird', 'twothirds',
975
- 'zerosuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
976
- 'sevensuperior', 'eightsuperior', 'ninesuperior', 'zeroinferior',
977
- 'oneinferior', 'twoinferior', 'threeinferior', 'fourinferior',
978
- 'fiveinferior', 'sixinferior', 'seveninferior', 'eightinferior',
979
- 'nineinferior', 'centinferior', 'dollarinferior', 'periodinferior',
980
- 'commainferior', 'Agravesmall', 'Aacutesmall', 'Acircumflexsmall',
981
- 'Atildesmall', 'Adieresissmall', 'Aringsmall', 'AEsmall', 'Ccedillasmall',
982
- 'Egravesmall', 'Eacutesmall', 'Ecircumflexsmall', 'Edieresissmall',
983
- 'Igravesmall', 'Iacutesmall', 'Icircumflexsmall', 'Idieresissmall',
984
- 'Ethsmall', 'Ntildesmall', 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall',
985
- 'Otildesmall', 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall',
986
- 'Uacutesmall', 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall',
987
- 'Thornsmall', 'Ydieresissmall', '001.000', '001.001', '001.002', '001.003',
988
- 'Black', 'Bold', 'Book', 'Light', 'Medium', 'Regular', 'Roman', 'Semibold'
989
- ];
990
- constructor() {
991
- this.strings = [];
992
- }
993
- _get(index: number): any { //eslint-disable-line
994
- if (index >= 0 && index <= this._numberOfStandardCompactFontStrings - 1) {
995
- return this._compactFontStandardStrings[Number.parseInt(index.toString(), 10)];
996
- }
997
- if (index - this._numberOfStandardCompactFontStrings <= this.strings.length) {
998
- return this.strings[index - this._numberOfStandardCompactFontStrings];
999
- }
1000
- return this._compactFontStandardStrings[0];
1001
- }
1002
- _fetchStringIdentifier(text: any): number { //eslint-disable-line
1003
- let index: number = this._compactFontStandardStrings.indexOf(text);
1004
- if (index !== -1) {
1005
- return index;
1006
- }
1007
- index = this.strings.indexOf(text);
1008
- if (index !== -1) {
1009
- return index + this._numberOfStandardCompactFontStrings;
1010
- }
1011
- return -1;
1012
- }
1013
- _add(value: any): void { //eslint-disable-line
1014
- this.strings.push(value);
1015
- }
1016
- get count(): number {
1017
- return this.strings.length;
1018
- }
1019
- }
1020
- export class _PdfCompactFontIndex {
1021
- objects: any; //eslint-disable-line
1022
- length: number;
1023
- constructor() {
1024
- this.objects = [];
1025
- this.length = 0;
1026
- }
1027
- add(data: any): void { //eslint-disable-line
1028
- this.length += data.length;
1029
- this.objects.push(data);
1030
- }
1031
- set(index: number, data: any): void { //eslint-disable-line
1032
- this.length += data.length - this.objects[Number.parseInt(index.toString(), 10)].length;
1033
- this.objects[Number.parseInt(index.toString(), 10)] = data;
1034
- }
1035
- _get(index: number): any { //eslint-disable-line
1036
- return this.objects[Number.parseInt(index.toString(), 10)];
1037
- }
1038
- get count(): number {
1039
- return this.objects.length;
1040
- }
1041
- }
1042
- export class _PdfCompactFontDictionary {
1043
- keyToNameMap: any; //eslint-disable-line
1044
- nameToKeyMap: any; //eslint-disable-line
1045
- defaults: any; //eslint-disable-line
1046
- types: any; //eslint-disable-line
1047
- opcodes: any; //eslint-disable-line
1048
- order: any; //eslint-disable-line
1049
- strings: any; //eslint-disable-line
1050
- values: any = Object.create(null); //eslint-disable-line
1051
- constructor(tables: any, strings: any) { //eslint-disable-line
1052
- this.keyToNameMap = tables.keyToNameMap;
1053
- this.nameToKeyMap = tables.nameToKeyMap;
1054
- this.defaults = tables.defaults;
1055
- this.types = tables.types;
1056
- this.opcodes = tables.opcodes;
1057
- this.order = tables.order;
1058
- this.strings = strings;
1059
- this.values = Object.create(null);
1060
- }
1061
- _setByKey(key: any, value: any): boolean { //eslint-disable-line
1062
- if (!this.keyToNameMap && (key in this.keyToNameMap)) {
1063
- return false;
1064
- }
1065
- if (value.length === 0) {
1066
- return true;
1067
- }
1068
- for (const val of value) {
1069
- if (isNaN(val)) {
1070
- return true;
1071
- }
1072
- }
1073
- const type: any = this.types[key]; //eslint-disable-line
1074
- if (type === 'num' || type === 'sid' || type === 'offset') {
1075
- value = value[0];
1076
- }
1077
- this.values[Number.parseInt(key.toString(), 10)] = value;
1078
- return true;
1079
- }
1080
- _setByName(name: any, value: any): void { //eslint-disable-line
1081
- if (!(name in this.nameToKeyMap)) {
1082
- throw new FormatError(`Invalid dictionary name '${name}'`);
1083
- }
1084
- this.values[this.nameToKeyMap[Number.parseInt(name.toString(), 10)]] = value;
1085
- }
1086
- _hasName(name: any): any { //eslint-disable-line
1087
- return this.nameToKeyMap[Number.parseInt(name.toString(), 10)] in this.values;
1088
- }
1089
- _getByName(name: string): any { //eslint-disable-line
1090
- if (!(name in this.nameToKeyMap)) {
1091
- throw new FormatError(`Invalid dictionary name ${name}'`);
1092
- }
1093
- const key: any = this.nameToKeyMap[name]; //eslint-disable-line
1094
- if (!(key in this.values)) {
1095
- return this.defaults[key]; // eslint-disable-line
1096
- }
1097
- return this.values[key]; //eslint-disable-line
1098
- }
1099
- _removeByName(name: any): any { //eslint-disable-line
1100
- delete this.values[this.nameToKeyMap[Number.parseInt(name.toString(), 10)]];
1101
- }
1102
- _createTables(layout: any) { //eslint-disable-line
1103
- const tables: any = { //eslint-disable-line
1104
- keyToNameMap: {},
1105
- nameToKeyMap: {},
1106
- defaults: {},
1107
- types: {},
1108
- opcodes: {},
1109
- order: []
1110
- };
1111
- for (const entry of layout) {
1112
- const key: any = Array.isArray(entry[0]) //eslint-disable-line
1113
- ? (entry[0][0] << 8) + entry[0][1]
1114
- : entry[0];
1115
- tables.keyToNameMap[Number.parseInt(key.toString(), 10)] = entry[1];
1116
- tables.nameToKeyMap[entry[1]] = key;
1117
- tables.types[Number.parseInt(key.toString(), 10)] = entry[2];
1118
- tables.defaults[Number.parseInt(key.toString(), 10)] = entry[3];
1119
- tables.opcodes[Number.parseInt(key.toString(), 10)] = Array.isArray(entry[0]) ? entry[0] : [entry[0]];
1120
- tables.order.push(key);
1121
- }
1122
- return tables;
1123
- }
1124
- }
1125
- export class _PdfCompactFontTopDictionary extends _PdfCompactFontDictionary {
1126
- privateDictionary: any; //eslint-disable-line
1127
- static get _tables(): any { //eslint-disable-line
1128
- return _defineProperty(this, 'tables', _PdfCompactFontTopDictionary._createTables());
1129
- }
1130
- constructor(strings?: any) { //eslint-disable-line
1131
- super(_PdfCompactFontTopDictionary._createTables(), strings);
1132
- this.privateDictionary = null;
1133
- }
1134
- static _createTables(): any { //eslint-disable-line
1135
- let layout: any = [ //eslint-disable-line
1136
- [[12, 30], 'ROS', ['sid', 'sid', 'num'], null],
1137
- [[12, 20], 'SyntheticBase', 'num', null],
1138
- [0, 'version', 'sid', null],
1139
- [1, 'Notice', 'sid', null],
1140
- [[12, 0], 'Copyright', 'sid', null],
1141
- [2, 'FullName', 'sid', null],
1142
- [3, 'FamilyName', 'sid', null],
1143
- [4, 'Weight', 'sid', null],
1144
- [[12, 1], 'isFixedPitch', 'num', 0],
1145
- [[12, 2], 'ItalicAngle', 'num', 0],
1146
- [[12, 3], 'UnderlinePosition', 'num', -100],
1147
- [[12, 4], 'UnderlineThickness', 'num', 50],
1148
- [[12, 5], 'PaintType', 'num', 0],
1149
- [[12, 6], 'CharstringType', 'num', 2],
1150
- [[12, 7], 'FontMatrix', ['num', 'num', 'num', 'num', 'num', 'num'],
1151
- [0.001, 0, 0, 0.001, 0, 0]],
1152
- [13, 'UniqueID', 'num', null],
1153
- [5, 'FontBBox', ['num', 'num', 'num', 'num'], [0, 0, 0, 0]],
1154
- [[12, 8], 'StrokeWidth', 'num', 0],
1155
- [14, 'XUID', 'array', null],
1156
- [15, 'charSet', 'offset', 0],
1157
- [16, 'Encoding', 'offset', 0],
1158
- [17, 'CharStrings', 'offset', 0],
1159
- [18, 'Private', ['offset', 'offset'], null],
1160
- [[12, 21], 'PostScript', 'sid', null],
1161
- [[12, 22], 'BaseFontName', 'sid', null],
1162
- [[12, 23], 'BaseFontBlend', 'delta', null],
1163
- [[12, 31], 'CIDFontVersion', 'num', 0],
1164
- [[12, 32], 'CIDFontRevision', 'num', 0],
1165
- [[12, 33], 'CIDFontType', 'num', 0],
1166
- [[12, 34], 'CIDCount', 'num', 8720],
1167
- [[12, 35], 'UIDBase', 'num', null],
1168
- [[12, 37], 'FDSelect', 'offset', null],
1169
- [[12, 36], 'FDArray', 'offset', null],
1170
- [[12, 38], 'FontName', 'sid', null]
1171
- ];
1172
- const tables: any = { //eslint-disable-line
1173
- keyToNameMap: {},
1174
- nameToKeyMap: {},
1175
- defaults: {},
1176
- types: {},
1177
- opcodes: {},
1178
- order: []
1179
- };
1180
- for (const entry of layout) {
1181
- const key: any = Array.isArray(entry[0]) //eslint-disable-line
1182
- ? (entry[0][0] << 8) + entry[0][1]
1183
- : entry[0];
1184
- tables.keyToNameMap[Number.parseInt(key.toString(), 10)] = entry[1];
1185
- tables.nameToKeyMap[entry[1]] = key;
1186
- tables.types[Number.parseInt(key.toString(), 10)] = entry[2];
1187
- tables.defaults[Number.parseInt(key.toString(), 10)] = entry[3];
1188
- tables.opcodes[Number.parseInt(key.toString(), 10)] = Array.isArray(entry[0]) ? entry[0] : [entry[0]];
1189
- tables.order.push(key);
1190
- }
1191
- return tables;
1192
- }
1193
- }
1194
- export class _PdfCompactFontPrivateDictionary extends _PdfCompactFontDictionary {
1195
- strings: any; //eslint-disable-line
1196
- subroutineIndex: any; //eslint-disable-line
1197
- tables: any; //eslint-disable-line
1198
- constructor(strings?: string) {
1199
- const layout: any = [ //eslint-disable-line
1200
- [6, 'BlueValues', 'delta', null],
1201
- [7, 'OtherBlues', 'delta', null],
1202
- [8, 'FamilyBlues', 'delta', null],
1203
- [9, 'FamilyOtherBlues', 'delta', null],
1204
- [[12, 9], 'BlueScale', 'num', 0.039625],
1205
- [[12, 10], 'BlueShift', 'num', 7],
1206
- [[12, 11], 'BlueFuzz', 'num', 1],
1207
- [10, 'StdHW', 'num', null],
1208
- [11, 'StdVW', 'num', null],
1209
- [[12, 12], 'StemSnapH', 'delta', null],
1210
- [[12, 13], 'StemSnapV', 'delta', null],
1211
- [[12, 14], 'ForceBold', 'num', 0],
1212
- [[12, 17], 'LanguageGroup', 'num', 0],
1213
- [[12, 18], 'ExpansionFactor', 'num', 0.06],
1214
- [[12, 19], 'initialRandomSeed', 'num', 0],
1215
- [20, 'defaultWidthX', 'num', 0],
1216
- [21, 'nominalWidthX', 'num', 0],
1217
- [19, 'Subrs', 'offset', null]
1218
- ];
1219
- const tables: any = { //eslint-disable-line
1220
- keyToNameMap: {},
1221
- nameToKeyMap: {},
1222
- defaults: {},
1223
- types: {},
1224
- opcodes: {},
1225
- order: []
1226
- };
1227
- for (const entry of layout) {
1228
- const key: any = Array.isArray(entry[0]) //eslint-disable-line
1229
- ? (entry[0][0] << 8) + entry[0][1]
1230
- : entry[0];
1231
- tables.keyToNameMap[Number.parseInt(key.toString(), 10)] = entry[1];
1232
- tables.nameToKeyMap[entry[1]] = key;
1233
- tables.types[Number.parseInt(key.toString(), 10)] = entry[2];
1234
- tables.defaults[Number.parseInt(key.toString(), 10)] = entry[3];
1235
- tables.opcodes[Number.parseInt(key.toString(), 10)] = Array.isArray(entry[0]) ? entry[0] : [entry[0]];
1236
- tables.order.push(key);
1237
- }
1238
- super(tables, strings);
1239
- this.tables = tables;
1240
- this.subroutineIndex = null;
1241
- }
1242
- }
1243
- export class _PdfCompactFontCharacterSet {
1244
- predefined: any; //eslint-disable-line
1245
- format: any; //eslint-disable-line
1246
- charSet: any; //eslint-disable-line
1247
- raw: any; //eslint-disable-line
1248
- constructor(predefined: any, format: any, charSet: any, raw?: any) { //eslint-disable-line
1249
- this.predefined = predefined;
1250
- this.format = format;
1251
- this.charSet = charSet;
1252
- this.raw = raw;
1253
- }
1254
- }
1255
- export class _PdfCompactFontEncoding {
1256
- predefined: any; //eslint-disable-line
1257
- format: any; //eslint-disable-line
1258
- charSet: any; //eslint-disable-line
1259
- raw: any; //eslint-disable-line
1260
- encoding: any; //eslint-disable-line
1261
- constructor(predefined: any, format: any, encoding: any, raw: any) { //eslint-disable-line
1262
- this.predefined = predefined;
1263
- this.format = format;
1264
- this.encoding = encoding;
1265
- this.raw = raw;
1266
- }
1267
- }
1268
- export class _PdfCompactFontSelect {
1269
- format: any; //eslint-disable-line
1270
- fontDictionarySelect: any; //eslint-disable-line
1271
- constructor(format: any, fontDictionarySelect: any) { //eslint-disable-line
1272
- this.format = format;
1273
- this.fontDictionarySelect = fontDictionarySelect;
1274
- }
1275
- _getFontDictionaryIndex(glyphIndex: number): any { //eslint-disable-line
1276
- if (glyphIndex < 0 || glyphIndex >= this.fontDictionarySelect.length) {
1277
- return -1;
1278
- }
1279
- return this.fontDictionarySelect[Number.parseInt(glyphIndex.toString(), 10)];
1280
- }
1281
- }
1282
- export class _PdfCompactFontOffsetTracker {
1283
- offsets: any; //eslint-disable-line
1284
- constructor() {
1285
- this.offsets = Object.create(null);
1286
- }
1287
- _isTracking(key: any): boolean { //eslint-disable-line
1288
- return key in this.offsets;
1289
- }
1290
- _track(key: any, location: any): void { //eslint-disable-line
1291
- if (key in this.offsets) {
1292
- throw new FormatError(`Already tracking location of ${key}`);
1293
- }
1294
- this.offsets[Number.parseInt(key.toString(), 10)] = location;
1295
- }
1296
- _offset(value: any): void { //eslint-disable-line
1297
- const keys: any = Object.keys(this.offsets); //eslint-disable-line
1298
- for (let i: number = 0; i < keys.length; i++) {
1299
- const key: any = keys[Number.parseInt(i.toString(), 10)]; //eslint-disable-line
1300
- const numericKey: number = Number.parseInt(key, 10);
1301
- this.offsets[Number.parseInt(numericKey.toString(), 10)] += value;
1302
- }
1303
- }
1304
- _setEntryLocation(key: any, values: any, output: any): void { //eslint-disable-line
1305
- if (!(key in this.offsets)) {
1306
- throw new FormatError(`Not tracking location of ${key}`);
1307
- }
1308
- const data: any = output.data; //eslint-disable-line
1309
- const dataOffset: number = this.offsets[Number.parseInt(key.toString(), 10)];
1310
- const size: number = 5;
1311
- for (let i: number = 0, ii: number = values.length; i < ii; ++i) {
1312
- const offset0: number = i * size + dataOffset;
1313
- const offset1: number = offset0 + 1;
1314
- const offset2: number = offset0 + 2;
1315
- const offset3: number = offset0 + 3;
1316
- const offset4: number = offset0 + 4;
1317
- if (data[Number.parseInt(offset0.toString(), 10)] !== 0x1d || data[Number.parseInt(offset1.toString(), 10)] !== 0 ||
1318
- data[Number.parseInt(offset2.toString(), 10)] !== 0 || data[Number.parseInt(offset3.toString(), 10)] !== 0 ||
1319
- data[Number.parseInt(offset4.toString(), 10)] !== 0) {
1320
- throw new FormatError('writing to an offset that is not empty');
1321
- }
1322
- const value: number = values[Number.parseInt(i.toString(), 10)];
1323
- data[Number.parseInt(offset0.toString(), 10)] = 0x1d;
1324
- data[Number.parseInt(offset1.toString(), 10)] = (value >> 24) & 0xff;
1325
- data[Number.parseInt(offset2.toString(), 10)] = (value >> 16) & 0xff;
1326
- data[Number.parseInt(offset3.toString(), 10)] = (value >> 8) & 0xff;
1327
- data[Number.parseInt(offset4.toString(), 10)] = value & 0xff;
1328
- }
1329
- }
1330
- }
1331
- export class _PdfCompactFontCompiler {
1332
- compactFont: any; //eslint-disable-line
1333
- constructor(compactFont: any) { //eslint-disable-line
1334
- this.compactFont = compactFont;
1335
- }
1336
- compile(): any { //eslint-disable-line
1337
- const compactFont: any = this.compactFont; //eslint-disable-line
1338
- const output: any = { //eslint-disable-line
1339
- data: [],
1340
- length: 0,
1341
- add(data: any) { //eslint-disable-line
1342
- try {
1343
- this.data.push(...data);
1344
- } catch {
1345
- this.data = this.data.concat(data);
1346
- }
1347
- this.length = this.data.length;
1348
- }
1349
- };
1350
- const header: any = this._compileHeader(compactFont.header); //eslint-disable-line
1351
- output.add(header);
1352
- const nameIndex: any = this._compileNameIndex(compactFont.names); //eslint-disable-line
1353
- output.add(nameIndex);
1354
- if (compactFont.isCharacterIdentifierFont) {
1355
- if (compactFont.topDict._hasName('FontMatrix')) {
1356
- const base: any = compactFont.topDict._getByName('FontMatrix'); //eslint-disable-line
1357
- compactFont.topDict._removeByName('FontMatrix');
1358
- for (const subDict of compactFont.fontDictionaryArray) {
1359
- let matrix: any = base.slice(0); //eslint-disable-line
1360
- if (subDict._hasName('FontMatrix')) {
1361
- matrix = this._transform(matrix, subDict._getByName('FontMatrix'));
1362
- }
1363
- subDict._setByName('FontMatrix', matrix);
1364
- }
1365
- }
1366
- }
1367
- const xuid: any = compactFont.topDict._getByName('XUID'); //eslint-disable-line
1368
- if (xuid && xuid.length > 16) {
1369
- compactFont.topDict._removeByName('XUID');
1370
- }
1371
- compactFont.topDict._setByName('charSet', 0);
1372
- let compiled: any = this._compileTopDictionary([compactFont.topDict], output.length, compactFont.isCharacterIdentifierFont); //eslint-disable-line
1373
- output.add(compiled.output);
1374
- const topDictTracker: any = compiled.trackers[0]; //eslint-disable-line
1375
- const stringIndex: any = this._compileStringIndex(compactFont.strings.strings); //eslint-disable-line
1376
- output.add(stringIndex);
1377
- const globalSubroutineIndex: any = this._compileIndex(compactFont.globalSubroutineIndex); //eslint-disable-line
1378
- output.add(globalSubroutineIndex);
1379
- if (compactFont.encoding && compactFont.topDict._hasName('Encoding')) {
1380
- if (compactFont.encoding.predefined) {
1381
- topDictTracker._setEntryLocation('Encoding', [compactFont.encoding.format], output);
1382
- } else {
1383
- const encoding: any = this._compileEncoding(compactFont.encoding); //eslint-disable-line
1384
- topDictTracker._setEntryLocation('Encoding', [output.length], output);
1385
- output.add(encoding);
1386
- }
1387
- }
1388
- const charSet: any = this._compileCharSet( //eslint-disable-line
1389
- compactFont.charSet,
1390
- compactFont.charStrings.count,
1391
- compactFont.strings,
1392
- compactFont.isCharacterIdentifierFont
1393
- );
1394
- topDictTracker._setEntryLocation('charSet', [output.length], output);
1395
- output.add(charSet);
1396
- const charStrings: any = this._compileCharStrings(compactFont.charStrings); //eslint-disable-line
1397
- topDictTracker._setEntryLocation('CharStrings', [output.length], output);
1398
- output.add(charStrings);
1399
- if (compactFont.isCharacterIdentifierFont) {
1400
- topDictTracker._setEntryLocation('FDSelect', [output.length], output);
1401
- const fontDictionarySelect: any = this._compileFontDictionarySelect(compactFont.fontDictionarySelect); //eslint-disable-line
1402
- output.add(fontDictionarySelect);
1403
- compiled = this._compileTopDictionary(compactFont.fontDictionaryArray, output.length, true);
1404
- topDictTracker._setEntryLocation('FDArray', [output.length], output);
1405
- output.add(compiled.output);
1406
- const fontDictTrackers: any = compiled.trackers; //eslint-disable-line
1407
- this._compilePrivateDictionary(compactFont.fontDictionaryArray, fontDictTrackers, output);
1408
- }
1409
- this._compilePrivateDictionary([compactFont.topDict], [topDictTracker], output);
1410
- output.add([0]);
1411
- return output.data;
1412
- }
1413
- _transform(m1: any, m2: any): any { //eslint-disable-line
1414
- return [
1415
- m1[0] * m2[0] + m1[2] * m2[1],
1416
- m1[1] * m2[0] + m1[3] * m2[1],
1417
- m1[0] * m2[2] + m1[2] * m2[3],
1418
- m1[1] * m2[2] + m1[3] * m2[3],
1419
- m1[0] * m2[4] + m1[2] * m2[5] + m1[4],
1420
- m1[1] * m2[4] + m1[3] * m2[5] + m1[5]
1421
- ];
1422
- }
1423
- _encodeNumber(value: any): any { //eslint-disable-line
1424
- if (Number.isInteger(value)) {
1425
- return this._encodeInteger(value);
1426
- }
1427
- return this._encodeFloat(value);
1428
- }
1429
- _encodeFloat(count: any): number[] { //eslint-disable-line
1430
- let value: string = count.toString();
1431
- const m: any = _defineProperty(this, 'EncodeFloatRegExp', /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/).exec(value); //eslint-disable-line
1432
- if (m) {
1433
- const epsilon: number = parseFloat('1e' + ((m[2] ? +m[2] : 0) + m[1].length));
1434
- value = (Math.round(count * epsilon) / epsilon).toString();
1435
- }
1436
- let nibbles: string = '';
1437
- for (let i: number = 0; i < value.length; ++i) {
1438
- const a: string = value[Number.parseInt(i.toString(), 10)];
1439
- if (a === 'e') {
1440
- nibbles += value[++i] === '-' ? 'c' : 'b';
1441
- } else if (a === '.') {
1442
- nibbles += 'a';
1443
- } else if (a === '-') {
1444
- nibbles += 'e';
1445
- } else {
1446
- nibbles += a;
1447
- }
1448
- }
1449
- nibbles += nibbles.length & 1 ? 'f' : 'ff';
1450
- const result: number[] = [30];
1451
- for (let i: number = 0; i < nibbles.length; i += 2) {
1452
- result.push(parseInt(nibbles.substring(i, i + 2), 16));
1453
- }
1454
- return result;
1455
- }
1456
- _encodeInteger(value: number): number[] {
1457
- let code: number[];
1458
- if (value >= -107 && value <= 107) {
1459
- code = [value + 139];
1460
- } else if (value >= 108 && value <= 1131) {
1461
- value -= 108;
1462
- code = [(value >> 8) + 247, value & 0xff];
1463
- } else if (value >= -1131 && value <= -108) {
1464
- value = -value - 108;
1465
- code = [(value >> 8) + 251, value & 0xff];
1466
- } else if (value >= -32768 && value <= 32767) {
1467
- code = [0x1c, (value >> 8) & 0xff, value & 0xff];
1468
- } else {
1469
- code = [
1470
- 0x1d,
1471
- (value >> 24) & 0xff,
1472
- (value >> 16) & 0xff,
1473
- (value >> 8) & 0xff,
1474
- value & 0xff
1475
- ];
1476
- }
1477
- return code;
1478
- }
1479
- _compileHeader(header: any): any { //eslint-disable-line
1480
- return [header.major, header.minor, 4, header.offSize];
1481
- }
1482
- _compileNameIndex(names: any): any { //eslint-disable-line
1483
- const nameIndex: _PdfCompactFontIndex = new _PdfCompactFontIndex();
1484
- for (const name of names) {
1485
- const length: number = Math.min(name.length, 127);
1486
- let sanitizedName: any = new Array(length); //eslint-disable-line
1487
- for (let j: number = 0; j < length; j++) {
1488
- let char: string = name[Number.parseInt(j.toString(), 10)];
1489
- if (
1490
- char < '!' ||
1491
- char > '~' ||
1492
- char === '[' ||
1493
- char === ']' ||
1494
- char === '(' ||
1495
- char === ')' ||
1496
- char === '{' ||
1497
- char === '}' ||
1498
- char === '<' ||
1499
- char === '>' ||
1500
- char === '/' ||
1501
- char === '%'
1502
- ) {
1503
- char = '_';
1504
- }
1505
- sanitizedName[Number.parseInt(j.toString(), 10)] = char;
1506
- }
1507
- sanitizedName = sanitizedName.join('');
1508
- if (sanitizedName === '') {
1509
- sanitizedName = 'Bad_Font_Name';
1510
- }
1511
- nameIndex.add(_stringToBytes(sanitizedName));
1512
- }
1513
- return this._compileIndex(nameIndex);
1514
- }
1515
- _compileTopDictionary(dictionary: any, length: any, removeCidKeys: any): any { //eslint-disable-line
1516
- const fontDictTrackers: any = []; //eslint-disable-line
1517
- let fontDictionaryArrayIndex: _PdfCompactFontIndex = new _PdfCompactFontIndex();
1518
- for (const fontDict of dictionary) {
1519
- if (removeCidKeys) {
1520
- fontDict._removeByName('CIDFontVersion');
1521
- fontDict._removeByName('CIDFontRevision');
1522
- fontDict._removeByName('CIDFontType');
1523
- fontDict._removeByName('CIDCount');
1524
- fontDict._removeByName('UIDBase');
1525
- }
1526
- const fontDictTracker: _PdfCompactFontOffsetTracker = new _PdfCompactFontOffsetTracker();
1527
- const fontDictData: any = this._compileDictionary(fontDict, fontDictTracker); //eslint-disable-line
1528
- fontDictTrackers.push(fontDictTracker);
1529
- fontDictionaryArrayIndex.add(fontDictData);
1530
- fontDictTracker._offset(length);
1531
- }
1532
- fontDictionaryArrayIndex = this._compileIndex(fontDictionaryArrayIndex, fontDictTrackers);
1533
- return {
1534
- trackers: fontDictTrackers,
1535
- output: fontDictionaryArrayIndex
1536
- };
1537
- }
1538
- _compilePrivateDictionary(dictionary: any, trackers: any, output: any): void { //eslint-disable-line
1539
- for (let i: number = 0, ii: number = dictionary.length; i < ii; ++i) {
1540
- const fontDict: any = dictionary[Number.parseInt(i.toString(), 10)]; //eslint-disable-line
1541
- const privateDictionary: any = fontDict.privateDictionary; //eslint-disable-line
1542
- if (!privateDictionary || !fontDict._hasName('Private')) {
1543
- throw new FormatError('There must be a private dictionary.');
1544
- }
1545
- const privateDictionaryTracker: _PdfCompactFontOffsetTracker = new _PdfCompactFontOffsetTracker();
1546
- const privateDictionaryData: any = this._compileDictionary(privateDictionary, privateDictionaryTracker); //eslint-disable-line
1547
- let outputLength: number = output.length;
1548
- privateDictionaryTracker._offset(outputLength);
1549
- if (!privateDictionaryData.length) {
1550
- outputLength = 0;
1551
- }
1552
- trackers[Number.parseInt(i.toString(), 10)].setEntryLocation(
1553
- 'Private',
1554
- [privateDictionaryData.length, outputLength],
1555
- output
1556
- );
1557
- output.add(privateDictionaryData);
1558
- if (privateDictionary.subroutineIndex && privateDictionary._hasName('Subrs')) {
1559
- const subrs: any = this._compileIndex(privateDictionary.subroutineIndex); //eslint-disable-line
1560
- privateDictionaryTracker._setEntryLocation(
1561
- 'Subrs',
1562
- [privateDictionaryData.length],
1563
- output
1564
- );
1565
- output.add(subrs);
1566
- }
1567
- }
1568
- }
1569
- _compileDictionary(dictionary: any, offsetTracker: any): any { //eslint-disable-line
1570
- const out = []; //eslint-disable-line
1571
- for (const key of dictionary.order) {
1572
- if (!(key in dictionary.values)) {
1573
- continue;
1574
- }
1575
- let values: any = dictionary.values[key]; //eslint-disable-line
1576
- let types: any = dictionary.types[key]; //eslint-disable-line
1577
- if (!Array.isArray(types)) {
1578
- types = [types];
1579
- }
1580
- if (!Array.isArray(values)) {
1581
- values = [values];
1582
- }
1583
- if (values.length === 0) {
1584
- continue;
1585
- }
1586
- for (let j: number = 0, jj: number = types.length; j < jj; ++j) {
1587
- const type : any= types[Number.parseInt(j.toString(), 10)]; //eslint-disable-line
1588
- const value: number = values[Number.parseInt(jj.toString(), 10)];
1589
- let name: string = '';
1590
- switch (type) {
1591
- case 'num':
1592
- case 'sid':
1593
- try {
1594
- out.push(...this._encodeNumber(value));
1595
- } catch (ex) {
1596
- // Ignoring the error intentionally because...
1597
- }
1598
- break;
1599
- case 'offset':
1600
- name = dictionary.keyToNameMap[Number.parseInt(key.toString(), 10)];
1601
- if (!offsetTracker.isTracking(name)) {
1602
- offsetTracker.track(name, out.length);
1603
- }
1604
- out.push(0x1d, 0, 0, 0, 0);
1605
- break;
1606
- case 'array':
1607
- case 'delta':
1608
- out.push(...this._encodeNumber(value));
1609
- for (let k: number = 1, kk: number = values.length; k < kk; ++k) {
1610
- out.push(...this._encodeNumber(values[Number.parseInt(k.toString(), 10)]));
1611
- }
1612
- break;
1613
- default:
1614
- throw new FormatError(`Unknown data type of ${type}`);
1615
- }
1616
- }
1617
- out.push(...dictionary.opcodes[Number.parseInt(key.toString(), 10)]);
1618
- }
1619
- return out;
1620
- }
1621
- _compileStringIndex(strings: any) { //eslint-disable-line
1622
- const stringIndex: _PdfCompactFontIndex = new _PdfCompactFontIndex();
1623
- for (const string of strings) {
1624
- stringIndex.add(_stringToBytes(string));
1625
- }
1626
- return this._compileIndex(stringIndex);
1627
- }
1628
- _compileCharStrings(charStrings: any): any { //eslint-disable-line
1629
- const charStringsIndex: _PdfCompactFontIndex = new _PdfCompactFontIndex();
1630
- for (let i: number = 0; i < charStrings.count; i++) {
1631
- const glyph: any = charStrings._get(i); //eslint-disable-line
1632
- if (glyph.length === 0) {
1633
- charStringsIndex.add(new Uint8Array([0x8b, 0x0e]));
1634
- continue;
1635
- }
1636
- charStringsIndex.add(glyph);
1637
- }
1638
- return this._compileIndex(charStringsIndex);
1639
- }
1640
- _compileCharSet(charSet: any, glyphCount: any, strings: any, isCharacterIdentifierFont: any): any { //eslint-disable-line
1641
- let out: any; //eslint-disable-line
1642
- const glyphCountLessNotDef: number = glyphCount - 1;
1643
- if (isCharacterIdentifierFont) {
1644
- out = new Uint8Array([2, 0, 0, (glyphCountLessNotDef >> 8) & 0xff, glyphCountLessNotDef & 0xff]);
1645
- } else {
1646
- const length: number = 1 + glyphCountLessNotDef * 2;
1647
- out = new Uint8Array(length);
1648
- out[0] = 0;
1649
- let charSetIndex: number = 0;
1650
- const numcharSets: number = charSet.charSet.length;
1651
- let warned: boolean = false;
1652
- for (let i: number = 1; i < out.length; i += 2) {
1653
- let sid: number = 0;
1654
- if (charSetIndex < numcharSets) {
1655
- const name: any = charSet.charSet[charSetIndex++]; //eslint-disable-line
1656
- sid = strings.getSID(name);
1657
- if (sid === -1) {
1658
- sid = 0;
1659
- if (!warned) {
1660
- warned = true;
1661
- }
1662
- }
1663
- }
1664
- out[Number.parseInt(i.toString(), 10)] = (sid >> 8) & 0xff;
1665
- out[i + 1] = sid & 0xff;
1666
- }
1667
- }
1668
- return this._compileTypedArray(out);
1669
- }
1670
- _compileEncoding(encoding: any) { //eslint-disable-line
1671
- return this._compileTypedArray(encoding.raw);
1672
- }
1673
- _compileFontDictionarySelect(fontDictionarySelect: any) { //eslint-disable-line
1674
- const format: any = fontDictionarySelect.format; //eslint-disable-line
1675
- let out: Uint8Array;
1676
- let i: number;
1677
- let numRanges: number;
1678
- let start: number;
1679
- switch (format) {
1680
- case 0:
1681
- out = new Uint8Array(1 + fontDictionarySelect.fontDictionarySelect.length);
1682
- out[0] = format;
1683
- for (i = 0; i < fontDictionarySelect.fontDictionarySelect.length; i++) {
1684
- out[i + 1] = fontDictionarySelect.fontDictionarySelect[Number.parseInt(i.toString(), 10)];
1685
- }
1686
- break;
1687
- case 3:
1688
- start = 0;
1689
- let lastFD: any = fontDictionarySelect.fontDictionarySelect[0]; //eslint-disable-line
1690
- const ranges: any = [format, 0, 0, (start >> 8) & 0xff, start & 0xff, lastFD]; //eslint-disable-line
1691
- for (i = 1; i < fontDictionarySelect.fontDictionarySelect.length; i++) {
1692
- const currentFD: any = fontDictionarySelect.fontDictionarySelect[Number.parseInt(i.toString(), 10)]; //eslint-disable-line
1693
- if (currentFD !== lastFD) {
1694
- ranges.push((i >> 8) & 0xff, i & 0xff, currentFD);
1695
- lastFD = currentFD;
1696
- }
1697
- }
1698
- numRanges = (ranges.length - 3) / 3;
1699
- ranges[1] = (numRanges >> 8) & 0xff;
1700
- ranges[2] = numRanges & 0xff;
1701
- ranges.push((i >> 8) & 0xff, i & 0xff);
1702
- out = new Uint8Array(ranges);
1703
- break;
1704
- }
1705
- return this._compileTypedArray(out);
1706
- }
1707
- _compileTypedArray(data: any): any { //eslint-disable-line
1708
- return Array.from(data);
1709
- }
1710
- _compileIndex(index: any, trackers: any = []): any { //eslint-disable-line
1711
- const objects: any = index.objects; //eslint-disable-line
1712
- const count: number = objects.length;
1713
- if (count === 0) {
1714
- return [0, 0];
1715
- }
1716
- const data: any = [(count >> 8) & 0xff, count & 0xff]; //eslint-disable-line
1717
- let lastOffset: number = 1;
1718
- let i: number;
1719
- for (i = 0; i < count; ++i) {
1720
- lastOffset += objects[Number.parseInt(i.toString(), 10)].length;
1721
- }
1722
- let offsetSize: number;
1723
- if (lastOffset < 0x100) {
1724
- offsetSize = 1;
1725
- } else if (lastOffset < 0x10000) {
1726
- offsetSize = 2;
1727
- } else if (lastOffset < 0x1000000) {
1728
- offsetSize = 3;
1729
- } else {
1730
- offsetSize = 4;
1731
- }
1732
- data.push(offsetSize);
1733
- let relativeOffset: number = 1;
1734
- for (i = 0; i < count + 1; i++) {
1735
- if (offsetSize === 1) {
1736
- data.push(relativeOffset & 0xff);
1737
- } else if (offsetSize === 2) {
1738
- data.push((relativeOffset >> 8) & 0xff, relativeOffset & 0xff);
1739
- } else if (offsetSize === 3) {
1740
- data.push(
1741
- (relativeOffset >> 16) & 0xff,
1742
- (relativeOffset >> 8) & 0xff,
1743
- relativeOffset & 0xff
1744
- );
1745
- } else {
1746
- data.push(
1747
- (relativeOffset >>> 24) & 0xff,
1748
- (relativeOffset >> 16) & 0xff,
1749
- (relativeOffset >> 8) & 0xff,
1750
- relativeOffset & 0xff
1751
- );
1752
- }
1753
- if (objects[Number.parseInt(i.toString(), 10)]) {
1754
- relativeOffset += objects[Number.parseInt(i.toString(), 10)].length;
1755
- }
1756
- }
1757
- for (i = 0; i < count; i++) {
1758
- if (trackers[Number.parseInt(i.toString(), 10)]) {
1759
- trackers[Number.parseInt(i.toString(), 10)].offset(data.length);
1760
- }
1761
- data.push(...objects[Number.parseInt(i.toString(), 10)]);
1762
- }
1763
- return data;
1764
- }
1765
- }
1766
- export class _PdfCompactFont {
1767
- properties: _FontStructure;
1768
- compactFont: any; //eslint-disable-line
1769
- standardCharacter: any; //eslint-disable-line
1770
- data: any; //eslint-disable-line
1771
- _builtInEncoding: any; //eslint-disable-line
1772
- constructor(file: any, properties: any) { //eslint-disable-line
1773
- this.properties = properties;
1774
- const parser: _PdfCompactFontParser = new _PdfCompactFontParser(file, properties, true);
1775
- this.compactFont = parser._parse(properties);
1776
- this.compactFont._duplicateFirstGlyph();
1777
- const compiler: _PdfCompactFontCompiler = new _PdfCompactFontCompiler(this.compactFont);
1778
- this.standardCharacter = this.compactFont.standardCharacter;
1779
- try {
1780
- this.data = compiler.compile();
1781
- } catch {
1782
- this.data = file;
1783
- }
1784
- this._createBuiltInEncoding();
1785
- }
1786
- get _glyphCount(): number {
1787
- return this.compactFont.charStrings.count;
1788
- }
1789
- _getCharSet(): any { //eslint-disable-line
1790
- return this.compactFont.charSet.charSet;
1791
- }
1792
- _getGlyphMapping(): { [key: number]: number } {
1793
- const compactFont: any = this.compactFont; //eslint-disable-line
1794
- const properties: any = this.properties; //eslint-disable-line
1795
- let cidToGidMap: any; //eslint-disable-line
1796
- const cMap: any = properties._fontStructure._cMap; //eslint-disable-line
1797
- const charSets: any = compactFont.charSet.charSet; //eslint-disable-line
1798
- let charCodeToGlyphId: { [key: number]: number } = {};
1799
- let glyphId: number;
1800
- if (properties._fontStructure._composite) {
1801
- let invCidToGidMap: { [key: number]: number } | undefined;
1802
- if (cidToGidMap && cidToGidMap.length > 0) {
1803
- invCidToGidMap = Object.create(null);
1804
- for (let i: number = 0, ii: number = cidToGidMap.length; i < ii; i++) {
1805
- const gid: any = cidToGidMap[Number.parseInt(i.toString(), 10)]; //eslint-disable-line
1806
- if (typeof(gid) !== 'undefined') {
1807
- invCidToGidMap[Number.parseInt(gid.toString(), 10)] = i;
1808
- }
1809
- }
1810
- }
1811
- let charCode: number;
1812
- if (compactFont.isCharacterIdentifierFont) {
1813
- for (glyphId = 0; glyphId < charSets.length; glyphId++) {
1814
- const cid: any = charSets[glyphId]; //eslint-disable-line
1815
- charCode = cMap._charCodeOf(cid);
1816
- if (invCidToGidMap && typeof(invCidToGidMap[Number.parseInt(charCode.toString(), 10)]) !== 'undefined') {
1817
- charCode = invCidToGidMap[Number.parseInt(charCode.toString(), 10)];
1818
- }
1819
- charCodeToGlyphId[Number.parseInt(charCode.toString(), 10)] = glyphId;
1820
- }
1821
- } else {
1822
- for (glyphId = 0; glyphId < compactFont.charStrings.count; glyphId++) {
1823
- charCode = cMap._charCodeOf(glyphId);
1824
- charCodeToGlyphId[Number.parseInt(charCode.toString(), 10)] = glyphId;
1825
- }
1826
- }
1827
- return charCodeToGlyphId;
1828
- }
1829
- let encoding: any = compactFont.encoding ? compactFont.encoding.encoding : null; //eslint-disable-line
1830
- if (properties._fontStructure._isInternalFont) {
1831
- encoding = properties._fontStructure._defaultEncoding;
1832
- }
1833
- charCodeToGlyphId = this._type1FontGlyphMapping(properties, encoding, charSets);
1834
- return charCodeToGlyphId;
1835
- }
1836
- _hasGlyphId(id: number): boolean {
1837
- return this.compactFont.hasGlyphId(id);
1838
- }
1839
- _type1FontGlyphMapping(properties: any, builtInEncoding: any, glyphNames: any): any { //eslint-disable-line
1840
- const charCodeToGlyphId: any = Object.create(null); //eslint-disable-line
1841
- let glyphId: number;
1842
- let charCode: any; //eslint-disable-line
1843
- let baseEncoding: any; //eslint-disable-line
1844
- const isSymbolicFont: boolean = !!(properties._flags & properties._fontFlags.Symbolic);
1845
- if (properties._fontStructure._isInternalFont) {
1846
- baseEncoding = builtInEncoding;
1847
- for (charCode = 0; charCode < baseEncoding.length; charCode++) {
1848
- glyphId = glyphNames.indexOf(baseEncoding[Number.parseInt(charCode.toString(), 10)]);
1849
- charCodeToGlyphId[Number.parseInt(charCode.toString(), 10)] = glyphId >= 0 ? glyphId : /* notdef = */ 0;
1850
- }
1851
- } else if (properties.baseEncodingName) {
1852
- baseEncoding = _getEncoding(properties.baseEncodingName);
1853
- for (charCode = 0; charCode < baseEncoding.length; charCode++) {
1854
- glyphId = glyphNames.indexOf(baseEncoding[Number.parseInt(charCode.toString(), 10)]);
1855
- charCodeToGlyphId[Number.parseInt(charCode.toString(), 10)] = glyphId >= 0 ? glyphId : /* notdef = */ 0;
1856
- }
1857
- } else if (isSymbolicFont) {
1858
- const builtInEncodingKeys: any = Object.keys(builtInEncoding); //eslint-disable-line
1859
- for (let i: number = 0; i < builtInEncodingKeys.length; i++) {
1860
- const charCode: any = builtInEncodingKeys[Number.parseInt(i.toString(), 10)]; //eslint-disable-line
1861
- const numericCharCode: any = Number.parseInt(charCode, 10); //eslint-disable-line
1862
- charCodeToGlyphId[Number.parseInt(numericCharCode.toString(), 10)] =
1863
- builtInEncoding[Number.parseInt(numericCharCode.toString(), 10)];
1864
- }
1865
- } else {
1866
- baseEncoding = _standardEncoding;
1867
- for (charCode = 0; charCode < baseEncoding.length; charCode++) {
1868
- glyphId = glyphNames.indexOf(baseEncoding[Number.parseInt(charCode.toString(), 10)]);
1869
- charCodeToGlyphId[Number.parseInt(charCode.toString(), 10)] = glyphId >= 0 ? glyphId : /* notdef = */ 0;
1870
- }
1871
- }
1872
- const differences: any = properties._fontStructure._differences; //eslint-disable-line
1873
- let glyphsUnicodeMap: any; //eslint-disable-line
1874
- if (differences) {
1875
- const differencesKeys: any = Object.keys(differences); //eslint-disable-line
1876
- for (let i: number = 0; i < differencesKeys.length; i++) {
1877
- const charCode: any = differencesKeys[Number.parseInt(i.toString(), 10)]; //eslint-disable-line
1878
- const glyphName: any = differences[Number.parseInt(charCode.toString(), 10)]; //eslint-disable-line
1879
- let glyphId: number = -1;
1880
- for (let j: number = 0; j < glyphNames.length; j++) {
1881
- if (glyphNames[Number.parseInt(j.toString(), 10)] === glyphName) {
1882
- glyphId = j;
1883
- break;
1884
- }
1885
- }
1886
- if (glyphId === -1) {
1887
- if (!glyphsUnicodeMap) {
1888
- glyphsUnicodeMap = _getGlyphsUnicode();
1889
- }
1890
- const standardGlyphName: any = _recoverGlyphName(glyphName, glyphsUnicodeMap); //eslint-disable-line
1891
- if (standardGlyphName !== glyphName) {
1892
- for (let k: number = 0; k < glyphNames.length; k++) {
1893
- if (glyphNames[Number.parseInt(k.toString(), 10)] === standardGlyphName) {
1894
- glyphId = k;
1895
- break;
1896
- }
1897
- }
1898
- }
1899
- }
1900
- charCodeToGlyphId[Number.parseInt(charCode, 10)] = glyphId >= 0 ? glyphId : 0;
1901
- }
1902
- }
1903
- return charCodeToGlyphId;
1904
- }
1905
- _createBuiltInEncoding(): void {
1906
- const { charSet, encoding } = this.compactFont;
1907
- if (!charSet || !encoding) {
1908
- return;
1909
- }
1910
- const charSets: any = charSet.charSet; //eslint-disable-line
1911
- const encodings: any = encoding.encoding; //eslint-disable-line
1912
- const map: any[] = []; //eslint-disable-line
1913
- const keys: any = Object.keys(encodings); //eslint-disable-line
1914
- for (let i: number = 0; i < keys.length; i++) {
1915
- const charCode: any = keys[Number.parseInt(i.toString(), 10)]; //eslint-disable-line
1916
- const glyphId: number = encodings[Number.parseInt(charCode, 10)];
1917
- if (glyphId >= 0) {
1918
- const glyphName: any = charSets[glyphId]; //eslint-disable-line
1919
- if (glyphName) {
1920
- map[Number(charCode)] = glyphName;
1921
- }
1922
- }
1923
- }
1924
- if (map.length > 0) {
1925
- this._builtInEncoding = map;
1926
- }
1927
- }
1928
- }