@syncfusion/ej2-pdf-data-extract 30.1.42 → 30.2.4
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.
- package/dist/ej2-pdf-data-extract.umd.min.js +1 -2
- package/dist/global/ej2-pdf-data-extract.min.js +1 -2
- package/dist/global/index.d.ts +1 -2
- package/package.json +14 -46
- package/dist/ts/index.d.ts +0 -20
- package/dist/ts/index.ts +0 -20
- package/dist/ts/pdf-data-extract/core/content-parser-helper.d.ts +0 -62
- package/dist/ts/pdf-data-extract/core/content-parser-helper.ts +0 -640
- package/dist/ts/pdf-data-extract/core/enum.d.ts +0 -6
- package/dist/ts/pdf-data-extract/core/enum.ts +0 -6
- package/dist/ts/pdf-data-extract/core/graphic-state.d.ts +0 -33
- package/dist/ts/pdf-data-extract/core/graphic-state.ts +0 -106
- package/dist/ts/pdf-data-extract/core/pdf-data-extractor.d.ts +0 -210
- package/dist/ts/pdf-data-extract/core/pdf-data-extractor.ts +0 -977
- package/dist/ts/pdf-data-extract/core/pdf-text-parser.d.ts +0 -67
- package/dist/ts/pdf-data-extract/core/pdf-text-parser.ts +0 -495
- package/dist/ts/pdf-data-extract/core/redaction/index.d.ts +0 -4
- package/dist/ts/pdf-data-extract/core/redaction/index.ts +0 -4
- package/dist/ts/pdf-data-extract/core/redaction/pdf-redaction-processor.d.ts +0 -55
- package/dist/ts/pdf-data-extract/core/redaction/pdf-redaction-processor.ts +0 -592
- package/dist/ts/pdf-data-extract/core/redaction/pdf-redaction-region.d.ts +0 -281
- package/dist/ts/pdf-data-extract/core/redaction/pdf-redaction-region.ts +0 -342
- package/dist/ts/pdf-data-extract/core/redaction/pdf-redactor.d.ts +0 -129
- package/dist/ts/pdf-data-extract/core/redaction/pdf-redactor.ts +0 -322
- package/dist/ts/pdf-data-extract/core/redaction/text-glyph-mapper.d.ts +0 -12
- package/dist/ts/pdf-data-extract/core/redaction/text-glyph-mapper.ts +0 -153
- package/dist/ts/pdf-data-extract/core/text-extraction/binary-cmap-reader.d.ts +0 -24
- package/dist/ts/pdf-data-extract/core/text-extraction/binary-cmap-reader.ts +0 -281
- package/dist/ts/pdf-data-extract/core/text-extraction/cmap.d.ts +0 -50
- package/dist/ts/pdf-data-extract/core/text-extraction/cmap.ts +0 -565
- package/dist/ts/pdf-data-extract/core/text-extraction/compact-font-parser.d.ts +0 -191
- package/dist/ts/pdf-data-extract/core/text-extraction/compact-font-parser.ts +0 -1928
- package/dist/ts/pdf-data-extract/core/text-extraction/encoding-utils.d.ts +0 -102
- package/dist/ts/pdf-data-extract/core/text-extraction/encoding-utils.ts +0 -5780
- package/dist/ts/pdf-data-extract/core/text-extraction/font-structure.d.ts +0 -167
- package/dist/ts/pdf-data-extract/core/text-extraction/font-structure.ts +0 -1842
- package/dist/ts/pdf-data-extract/core/text-extraction/font-tables.d.ts +0 -5
- package/dist/ts/pdf-data-extract/core/text-extraction/font-tables.ts +0 -16
- package/dist/ts/pdf-data-extract/core/text-extraction/font-utils.d.ts +0 -18
- package/dist/ts/pdf-data-extract/core/text-extraction/font-utils.ts +0 -630
- package/dist/ts/pdf-data-extract/core/text-extraction/glyph.d.ts +0 -93
- package/dist/ts/pdf-data-extract/core/text-extraction/glyph.ts +0 -622
- package/dist/ts/pdf-data-extract/core/text-extraction/index.d.ts +0 -10
- package/dist/ts/pdf-data-extract/core/text-extraction/index.ts +0 -10
- package/dist/ts/pdf-data-extract/core/text-extraction/matrix-helper.d.ts +0 -38
- package/dist/ts/pdf-data-extract/core/text-extraction/matrix-helper.ts +0 -150
- package/dist/ts/pdf-data-extract/core/text-extraction/metrics.d.ts +0 -16
- package/dist/ts/pdf-data-extract/core/text-extraction/metrics.ts +0 -2938
- package/dist/ts/pdf-data-extract/core/text-structure.d.ts +0 -628
- package/dist/ts/pdf-data-extract/core/text-structure.ts +0 -668
- package/dist/ts/pdf-data-extract/core/utils.d.ts +0 -99
- package/dist/ts/pdf-data-extract/core/utils.ts +0 -626
- package/dist/ts/pdf-data-extract/index.d.ts +0 -20
- package/dist/ts/pdf-data-extract/index.ts +0 -20
|
@@ -1,1842 +0,0 @@
|
|
|
1
|
-
import { _fontTables } from './font-tables';
|
|
2
|
-
import { _getFontEncodedString, _fontFlags, _getUnicodeForGlyph } from './font-utils';
|
|
3
|
-
import { _PdfMetrics } from './metrics';
|
|
4
|
-
import { _getDingbatsGlyphsUnicode, _getEncoding, _getFontBasicMetrics, _getFontNameToFileMap, _getGlyphMapForStandardFonts, _getGlyphsUnicode, _getNonStdFontMap, _getSerifFonts, _getStdFontMap, _getSupplementalGlyphMapForArialBlack, _getFontGlyphMap, _getSymbolsFonts, _macRomanEncoding, _standardEncoding, _symbolSetEncoding, _winAnsiEncoding, _zapfDingbatsEncoding } from './encoding-utils';
|
|
5
|
-
import { _PdfCharacterMapFactory, _PdfIdentityCharacterMap } from './cmap';
|
|
6
|
-
import { _PdfGlyphTable } from './glyph';
|
|
7
|
-
import { _PdfCompactFont } from './compact-font-parser';
|
|
8
|
-
import { _bytesToString, _PdfBaseStream, _PdfCrossReference, _PdfDictionary, _PdfName, _PdfNullStream, _PdfReference, _PdfStream, FormatError, PdfFontStyle } from '@syncfusion/ej2-pdf';
|
|
9
|
-
export class _FontStructure {
|
|
10
|
-
_ascent: number;
|
|
11
|
-
_boundingBox: number[];
|
|
12
|
-
_characterMap: any; //eslint-disable-line
|
|
13
|
-
_fontStyle: PdfFontStyle;
|
|
14
|
-
_builtInEncoding: any; //eslint-disable-line
|
|
15
|
-
_fallBackToUnicodeMap: any; //eslint-disable-line
|
|
16
|
-
_capHeight: number;
|
|
17
|
-
_encoding: string = '';
|
|
18
|
-
_composite: boolean = false;
|
|
19
|
-
_cssFontInfo: any = null; //eslint-disable-line
|
|
20
|
-
_data: Uint8Array[];
|
|
21
|
-
_defaultEncoding: any[]; //eslint-disable-line
|
|
22
|
-
_defaultWidth: number;
|
|
23
|
-
_descent: number;
|
|
24
|
-
_differences: any[]; //eslint-disable-line
|
|
25
|
-
_disableFontFace: boolean;
|
|
26
|
-
_characterSystemInfo: any; //eslint-disable-line
|
|
27
|
-
_fontMatrix: number[];
|
|
28
|
-
_charsCache: any = Object.create(null); //eslint-disable-line
|
|
29
|
-
_glyphCache: any = Object.create(null); //eslint-disable-line
|
|
30
|
-
_widths: number[];
|
|
31
|
-
_vertical: boolean;
|
|
32
|
-
_type: string;
|
|
33
|
-
_toUnicode: any; //eslint-disable-line
|
|
34
|
-
_toFontChar: any; //eslint-disable-line
|
|
35
|
-
_isSerifFont: boolean = false;
|
|
36
|
-
_isSymbolicFont: boolean = false;
|
|
37
|
-
_isType3Font: boolean = false;
|
|
38
|
-
_isInternalFont: boolean = false;
|
|
39
|
-
_lineHeight: number;
|
|
40
|
-
_mimeType: any; //eslint-disable-line
|
|
41
|
-
_missingFile: boolean;
|
|
42
|
-
_name: string;
|
|
43
|
-
_flags: number;
|
|
44
|
-
_psName: string;
|
|
45
|
-
_subtype: string;
|
|
46
|
-
_systemFontInfo: any; //eslint-disable-line
|
|
47
|
-
_dictionary: _PdfDictionary;
|
|
48
|
-
_crossReference: _PdfCrossReference;
|
|
49
|
-
_isOpenType: boolean;
|
|
50
|
-
_lineGap: any; //eslint-disable-line
|
|
51
|
-
_bold: any; //eslint-disable-line
|
|
52
|
-
_italic: any; //eslint-disable-line
|
|
53
|
-
_black: any; //eslint-disable-line
|
|
54
|
-
_length1: number;
|
|
55
|
-
_length2: number;
|
|
56
|
-
_length3: number;
|
|
57
|
-
constructor();
|
|
58
|
-
constructor(dictionary: _PdfDictionary, crossReference: _PdfCrossReference);
|
|
59
|
-
constructor(dictionary?: _PdfDictionary, crossReference?: _PdfCrossReference) {
|
|
60
|
-
if (dictionary) {
|
|
61
|
-
this._dictionary = dictionary;
|
|
62
|
-
this._crossReference = crossReference;
|
|
63
|
-
this._initialize();
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
_initialize(): void {
|
|
67
|
-
const font: _FontHelper = new _FontHelper(this, this._crossReference);
|
|
68
|
-
font._preEvaluateFont(this._dictionary);
|
|
69
|
-
}
|
|
70
|
-
_charsToGlyphs(chars: string): _Glyph[] {
|
|
71
|
-
let glyphs: any; //eslint-disable-line
|
|
72
|
-
const font: _FontHelper = new _FontHelper(this, this._crossReference);
|
|
73
|
-
if (this._charsCache) {
|
|
74
|
-
glyphs = this._charsCache[chars]; //eslint-disable-line
|
|
75
|
-
}
|
|
76
|
-
if (glyphs) {
|
|
77
|
-
return glyphs;
|
|
78
|
-
}
|
|
79
|
-
glyphs = [];
|
|
80
|
-
if (this._characterMap) {
|
|
81
|
-
const c: any = Object.create(null); //eslint-disable-line
|
|
82
|
-
const ii: number = chars.length;
|
|
83
|
-
let i: number = 0;
|
|
84
|
-
while (i < ii) {
|
|
85
|
-
this._characterMap._readCharacterCodeFromString(chars, i, c);
|
|
86
|
-
const { charcode, length } = c;
|
|
87
|
-
const char: string = chars.substring(i, i + length);
|
|
88
|
-
i += length;
|
|
89
|
-
const glyph: _Glyph = font._charToGlyph(charcode, length === 1 && chars.charCodeAt(i - 1) === 0x20);
|
|
90
|
-
glyph._fontCharacter = char;
|
|
91
|
-
glyphs.push(glyph);
|
|
92
|
-
}
|
|
93
|
-
} else {
|
|
94
|
-
for (let i: number = 0, ii: number = chars.length; i < ii; ++i) {
|
|
95
|
-
const charcode: any = chars.charCodeAt(i); //eslint-disable-line
|
|
96
|
-
const glyph: _Glyph = font._charToGlyph(charcode, charcode === 0x20);
|
|
97
|
-
glyph._fontCharacter = chars[Number.parseInt(i.toString(), 10)];
|
|
98
|
-
glyphs.push(glyph);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
return (this._charsCache[chars] = glyphs); //eslint-disable-line
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
export class _FontHelper {
|
|
105
|
-
_fontStructure: _FontStructure;
|
|
106
|
-
_scaleFactors: any; //eslint-disable-line
|
|
107
|
-
_hasIncludedToUnicodeMap: boolean = false;
|
|
108
|
-
_crossReference: _PdfCrossReference;
|
|
109
|
-
_firstChar: number;
|
|
110
|
-
_lastChar: number;
|
|
111
|
-
_table: _fontTables = new _fontTables(); //option
|
|
112
|
-
_remeasure: any; //eslint-disable-line
|
|
113
|
-
_standardCharacter: any; //eslint-disable-line
|
|
114
|
-
_data: any; //eslint-disable-line
|
|
115
|
-
_flags: number;
|
|
116
|
-
_vertical: boolean;
|
|
117
|
-
_file: any; //eslint-disable-line
|
|
118
|
-
_fileType: string;
|
|
119
|
-
_fileSubtype: string;
|
|
120
|
-
_italicAngle: number;
|
|
121
|
-
_xHeight: number;
|
|
122
|
-
_baseEncodingName: any; //eslint-disable-line
|
|
123
|
-
_fontIdentityMatrix: number[] = [0.001, 0, 0, 0.001, 0, 0];
|
|
124
|
-
_fallBackToUnicodeMap: any; //eslint-disable-line
|
|
125
|
-
_characterIdToGlyphMap: any; //eslint-disable-line
|
|
126
|
-
_hasEncoding: any; //eslint-disable-line
|
|
127
|
-
_isOpenType: boolean = false;
|
|
128
|
-
_standardFontDataCache: Map<any, any> = new Map<any, any>(); //eslint-disable-line
|
|
129
|
-
_fontFlags: any = { FixedPitch: 1, Serif: 2, Symbolic: 4, Script: 8, NonSymbolic: 32, Italic: 64, AllCap: 65536, SmallCap: 131072, ForceBold: 262144}; //eslint-disable-line
|
|
130
|
-
_validTables: any = ['OS/2', 'cmap', 'head', 'hhea', 'hmtx', 'maxp', 'name', 'post', 'loca', 'glyf', 'fpgm', 'prep', 'cvt', 'compactFont']; //eslint-disable-line
|
|
131
|
-
_ttOpsStackDeltas: number[] = [
|
|
132
|
-
0, 0, 0, 0, 0, 0, 0, 0, -2, -2, -2, -2, 0, 0, -2, -5,
|
|
133
|
-
-1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, -1, -1,
|
|
134
|
-
1, -1, -999, 0, 1, 0, -1, -2, 0, -1, -2, -1, -1, 0, -1, -1,
|
|
135
|
-
0, 0, -999, -999, -1, -1, -1, -1, -2, -999, -2, -2, -999, 0, -2, -2,
|
|
136
|
-
0, 0, -2, 0, -2, 0, 0, 0, -2, -1, -1, 1, 1, 0, 0, -1,
|
|
137
|
-
-1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, 0, -999, -1, -1,
|
|
138
|
-
-1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
139
|
-
-2, -999, -999, -999, -999, -999, -1, -1, -2, -2, 0, 0, 0, 0, -1, -1,
|
|
140
|
-
-999, -2, -2, 0, 0, -1, -2, -2, 0, 0, 0, -1, -1, -1, -2];
|
|
141
|
-
constructor(fontStructure: _FontStructure, crossReference: _PdfCrossReference) {
|
|
142
|
-
this._fontStructure = fontStructure;
|
|
143
|
-
this._crossReference = crossReference;
|
|
144
|
-
}
|
|
145
|
-
_preEvaluateFont(dictionary: _PdfDictionary): any { //eslint-disable-line
|
|
146
|
-
const baseDictionary: _PdfDictionary = dictionary;
|
|
147
|
-
let type: any = dictionary.get('Subtype'); //eslint-disable-line
|
|
148
|
-
this._fontStructure._composite = false;
|
|
149
|
-
let firstChar: number;
|
|
150
|
-
let lastChar: number;
|
|
151
|
-
let descendantFonts: any; //eslint-disable-line
|
|
152
|
-
const fontStyle: PdfFontStyle = this._getFontStyle(dictionary);
|
|
153
|
-
this._fontStructure._fontStyle = fontStyle;
|
|
154
|
-
if (type.name === 'Type0') {
|
|
155
|
-
descendantFonts = dictionary.get('DescendantFonts');
|
|
156
|
-
dictionary = Array.isArray(descendantFonts) ? (descendantFonts[0] instanceof _PdfReference ?
|
|
157
|
-
this._crossReference._fetch(descendantFonts[0]) : descendantFonts[0]) : descendantFonts;
|
|
158
|
-
type = dictionary.get('Subtype');
|
|
159
|
-
this._fontStructure._composite = true;
|
|
160
|
-
}
|
|
161
|
-
if (dictionary.has('FirstChar')) {
|
|
162
|
-
firstChar = dictionary.get('FirstChar');
|
|
163
|
-
} else {
|
|
164
|
-
firstChar = 0;
|
|
165
|
-
}
|
|
166
|
-
if (dictionary.has('LastChar')) {
|
|
167
|
-
lastChar = dictionary.get('LastChar');
|
|
168
|
-
} else {
|
|
169
|
-
lastChar = this._fontStructure._composite ? 0xffff : 0xff;
|
|
170
|
-
}
|
|
171
|
-
this._fontStructure._type = type.name;
|
|
172
|
-
let descriptor: any; //eslint-disable-line
|
|
173
|
-
let toUnicode: any; //eslint-disable-line
|
|
174
|
-
if (dictionary.has('FontDescriptor')) {
|
|
175
|
-
descriptor = dictionary.get('FontDescriptor');
|
|
176
|
-
}
|
|
177
|
-
if (dictionary.has('ToUnicode')) {
|
|
178
|
-
toUnicode = dictionary.get('ToUnicode');
|
|
179
|
-
}
|
|
180
|
-
if (baseDictionary.has('ToUnicode')) {
|
|
181
|
-
toUnicode = baseDictionary.get('ToUnicode');
|
|
182
|
-
}
|
|
183
|
-
this._translateFont(descriptor, dictionary, baseDictionary, firstChar, lastChar, toUnicode);
|
|
184
|
-
}
|
|
185
|
-
_getFontStyle(dictionary: _PdfDictionary): PdfFontStyle {
|
|
186
|
-
let fontStyle: PdfFontStyle = PdfFontStyle.regular;
|
|
187
|
-
if (typeof (dictionary) !== 'undefined' && dictionary.has('BaseFont')) {
|
|
188
|
-
const baseFont: string = dictionary.get('BaseFont').name;
|
|
189
|
-
if (baseFont.indexOf('-') !== -1 || baseFont.indexOf(',') !== -1) {
|
|
190
|
-
let style: string = '';
|
|
191
|
-
if (baseFont.indexOf('-') !== -1) {
|
|
192
|
-
style = baseFont.split('-')[1];
|
|
193
|
-
} else if (baseFont.indexOf(',') !== -1) {
|
|
194
|
-
style = baseFont.split(',')[1];
|
|
195
|
-
}
|
|
196
|
-
style = style.replace('MT', '');
|
|
197
|
-
switch (style) {
|
|
198
|
-
case 'Italic':
|
|
199
|
-
case 'Oblique':
|
|
200
|
-
fontStyle = PdfFontStyle.italic;
|
|
201
|
-
break;
|
|
202
|
-
case 'Bold':
|
|
203
|
-
case 'BoldMT':
|
|
204
|
-
fontStyle = PdfFontStyle.bold;
|
|
205
|
-
break;
|
|
206
|
-
case 'BoldItalic':
|
|
207
|
-
case 'BoldOblique':
|
|
208
|
-
fontStyle = PdfFontStyle.italic | PdfFontStyle.bold;
|
|
209
|
-
break;
|
|
210
|
-
}
|
|
211
|
-
} else {
|
|
212
|
-
if (baseFont.indexOf('Bold') !== -1) {
|
|
213
|
-
fontStyle = PdfFontStyle.bold;
|
|
214
|
-
}
|
|
215
|
-
if (baseFont.indexOf('BoldItalic') !== -1 || baseFont.indexOf('BoldOblique') !== -1) {
|
|
216
|
-
fontStyle = PdfFontStyle.italic | PdfFontStyle.bold;
|
|
217
|
-
}
|
|
218
|
-
if (baseFont.indexOf('Italic') !== -1 || baseFont.indexOf('Oblique') !== -1) {
|
|
219
|
-
fontStyle = PdfFontStyle.italic;
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
return fontStyle;
|
|
224
|
-
}
|
|
225
|
-
_translateFont(descriptor: any, dictionary: any, baseDictionary: any, firstChar: number, lastChar: number, unicode: any): any { //eslint-disable-line
|
|
226
|
-
const isType3Font: boolean = this._fontStructure._type === 'Type3';
|
|
227
|
-
this._fontStructure._isType3Font = isType3Font;
|
|
228
|
-
if (!descriptor) {
|
|
229
|
-
if (isType3Font) {
|
|
230
|
-
const bbox: number[] = this._lookupNormalRect(dictionary.getArray('FontBBox'), [0, 0, 0, 0]);
|
|
231
|
-
descriptor = new _PdfDictionary();
|
|
232
|
-
descriptor.set('FontName', _PdfName.get(this._fontStructure._type));
|
|
233
|
-
descriptor.set('FontBBox', bbox);
|
|
234
|
-
} else {
|
|
235
|
-
let baseFontName: any = dictionary.get('BaseFont'); //eslint-disable-line
|
|
236
|
-
if (!(baseFontName instanceof _PdfName)) {
|
|
237
|
-
throw new FormatError('Base font is not specified');
|
|
238
|
-
}
|
|
239
|
-
baseFontName = baseFontName.name.replace(/[,_]/g, '-');
|
|
240
|
-
const metrics: any = this._getBaseFontMetrics(baseFontName); //eslint-disable-line
|
|
241
|
-
const fontNameWoStyle: any = baseFontName.split('-', 1)[0]; //eslint-disable-line
|
|
242
|
-
const flags: number = (this._isSerifFont(fontNameWoStyle) ? _fontFlags.Serif : 0) | (metrics.monospace ?
|
|
243
|
-
_fontFlags.FixedPitch : 0) |
|
|
244
|
-
(_getSymbolsFonts()[fontNameWoStyle] ? _fontFlags.Symbolic //eslint-disable-line
|
|
245
|
-
: _fontFlags.NonSymbolic);
|
|
246
|
-
this._fontStructure._name = baseFontName;
|
|
247
|
-
this._fontStructure._widths = metrics.widths;
|
|
248
|
-
this._fontStructure._defaultWidth = metrics.defaultWidth;
|
|
249
|
-
this._fontStructure._isType3Font = isType3Font;
|
|
250
|
-
this._fontStructure._flags = flags;
|
|
251
|
-
const widths: any = dictionary.get('Widths'); //eslint-disable-line
|
|
252
|
-
const standardFontName: any = this._getStandardFontName(baseFontName); //eslint-disable-line
|
|
253
|
-
let file: any = null; //eslint-disable-line
|
|
254
|
-
if (standardFontName) {
|
|
255
|
-
file = this._fetchStandardFontData(standardFontName);
|
|
256
|
-
this._fontStructure._isInternalFont = !!file;
|
|
257
|
-
}
|
|
258
|
-
this._extractDataStructures(dictionary, unicode);
|
|
259
|
-
if (Array.isArray(widths)) {
|
|
260
|
-
const glyphWidths: any = []; //eslint-disable-line
|
|
261
|
-
let j: number = firstChar;
|
|
262
|
-
for (const w of widths) {
|
|
263
|
-
if (w instanceof _PdfReference) {
|
|
264
|
-
const width: any = this._crossReference._fetch(w); //eslint-disable-line
|
|
265
|
-
if (typeof width === 'number') {
|
|
266
|
-
glyphWidths[Number.parseInt(j.toString(), 10)] = width;
|
|
267
|
-
}
|
|
268
|
-
} else if (typeof(w) === 'number') {
|
|
269
|
-
glyphWidths[Number.parseInt(j.toString(), 10)] = w;
|
|
270
|
-
}
|
|
271
|
-
j++;
|
|
272
|
-
}
|
|
273
|
-
this._fontStructure._widths = glyphWidths;
|
|
274
|
-
} else {
|
|
275
|
-
this._fontStructure._widths = this._buildCharCodeToWidth(metrics.widths);
|
|
276
|
-
}
|
|
277
|
-
this._setFontData();
|
|
278
|
-
return;
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
let fontName: any; //eslint-disable-line
|
|
282
|
-
if (descriptor.has('FontName')) {
|
|
283
|
-
fontName = descriptor.get('FontName');
|
|
284
|
-
this._fontStructure._name = fontName.name;
|
|
285
|
-
}
|
|
286
|
-
let baseFont: any = dictionary.get('BaseFont'); //eslint-disable-line
|
|
287
|
-
if (typeof fontName === 'string') {
|
|
288
|
-
fontName = _PdfName.get(fontName);
|
|
289
|
-
}
|
|
290
|
-
if (typeof baseFont === 'string') {
|
|
291
|
-
baseFont = _PdfName.get(baseFont);
|
|
292
|
-
}
|
|
293
|
-
if (!fontName) {
|
|
294
|
-
fontName = baseFont;
|
|
295
|
-
}
|
|
296
|
-
if (!(fontName instanceof _PdfName)) {
|
|
297
|
-
throw new FormatError('invalid font name');
|
|
298
|
-
}
|
|
299
|
-
let fontFile: any; //eslint-disable-line
|
|
300
|
-
let length1: number;
|
|
301
|
-
let length2: number;
|
|
302
|
-
let length3: number;
|
|
303
|
-
try {
|
|
304
|
-
if (descriptor.has('FontFile')) {
|
|
305
|
-
fontFile = descriptor.get('FontFile');
|
|
306
|
-
} else if (descriptor.has('FontFile2')) {
|
|
307
|
-
fontFile = descriptor.get('FontFile2');
|
|
308
|
-
} else if (descriptor.has('FontFile3')) {
|
|
309
|
-
fontFile = descriptor.get('FontFile3');
|
|
310
|
-
}
|
|
311
|
-
} catch (ex) {
|
|
312
|
-
fontFile = new _PdfNullStream();
|
|
313
|
-
}
|
|
314
|
-
if (fontFile) {
|
|
315
|
-
if (fontFile.dictionary) {
|
|
316
|
-
const subtypeEntry: any = fontFile.dictionary.get('Subtype'); //eslint-disable-line
|
|
317
|
-
if (subtypeEntry instanceof _PdfName) {
|
|
318
|
-
this._fontStructure._subtype = subtypeEntry.name;
|
|
319
|
-
}
|
|
320
|
-
length1 = fontFile.dictionary.get('Length1');
|
|
321
|
-
length2 = fontFile.dictionary.get('Length2');
|
|
322
|
-
length3 = fontFile.dictionary.get('Length3');
|
|
323
|
-
this._fontStructure._length1 = length1;
|
|
324
|
-
this._fontStructure._length2 = length2;
|
|
325
|
-
this._fontStructure._length3 = length3;
|
|
326
|
-
this._file = fontFile;
|
|
327
|
-
}
|
|
328
|
-
} else if (!isType3Font) {
|
|
329
|
-
const standardFontName: any = this._getStandardFontName(fontName.name); //eslint-disable-line
|
|
330
|
-
if (standardFontName) {
|
|
331
|
-
fontFile = this._fetchStandardFontData(standardFontName);
|
|
332
|
-
this._fontStructure._isInternalFont = !!fontFile;
|
|
333
|
-
this._file = fontFile;
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
const fontMatrix: number[] = this._lookupMatrix(dictionary.getArray('FontMatrix'), this._fontIdentityMatrix);
|
|
337
|
-
const bbox: number[] = this._lookupNormalRect(descriptor.getArray('FontBBox') || dictionary.getArray('FontBBox'), undefined);
|
|
338
|
-
let ascent: number;
|
|
339
|
-
let descent: number;
|
|
340
|
-
let capHeight: number;
|
|
341
|
-
let flags: number;
|
|
342
|
-
if (descriptor.has('Ascent')) {
|
|
343
|
-
ascent = descriptor.get('Ascent');
|
|
344
|
-
}
|
|
345
|
-
if (descriptor.has('Descent')) {
|
|
346
|
-
descent = descriptor.get('Descent');
|
|
347
|
-
}
|
|
348
|
-
if (descriptor.has('CapHeight')) {
|
|
349
|
-
capHeight = descriptor.get('CapHeight');
|
|
350
|
-
}
|
|
351
|
-
if (descriptor.has('FontName')) {
|
|
352
|
-
this._fontStructure._name = descriptor.get('FontName').name;
|
|
353
|
-
}
|
|
354
|
-
if (descriptor.has('Flags')) {
|
|
355
|
-
flags = descriptor.get('Flags');
|
|
356
|
-
}
|
|
357
|
-
const glyphSpaceUnits: number = 1000;
|
|
358
|
-
this._fontStructure._fontMatrix = fontMatrix;
|
|
359
|
-
this._fontStructure._boundingBox = bbox;
|
|
360
|
-
this._firstChar = firstChar;
|
|
361
|
-
this._lastChar = lastChar;
|
|
362
|
-
this._fontStructure._ascent = ascent / glyphSpaceUnits;
|
|
363
|
-
this._fontStructure._descent = descent / glyphSpaceUnits;
|
|
364
|
-
this._fontStructure._lineHeight = this._fontStructure._ascent - this._fontStructure._descent;
|
|
365
|
-
this._fontStructure._flags = flags;
|
|
366
|
-
let encoding: _PdfName;
|
|
367
|
-
if (baseDictionary.has('Encoding')) {
|
|
368
|
-
const cidEncoding: any = baseDictionary.get('Encoding'); //eslint-disable-line
|
|
369
|
-
if (cidEncoding instanceof _PdfName) {
|
|
370
|
-
encoding = cidEncoding;
|
|
371
|
-
this._fontStructure._encoding = encoding.name;
|
|
372
|
-
} else if (cidEncoding instanceof _PdfDictionary && cidEncoding.has('Type')) {
|
|
373
|
-
this._fontStructure._encoding = cidEncoding.get('Type').name;
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
if (this._fontStructure._composite) {
|
|
377
|
-
const map: _PdfCharacterMapFactory = new _PdfCharacterMapFactory();
|
|
378
|
-
const cMap: any = map._create(encoding, null, null); //eslint-disable-line
|
|
379
|
-
this._fontStructure._characterMap = cMap;
|
|
380
|
-
this._fontStructure._vertical = this._fontStructure._characterMap._vertical;
|
|
381
|
-
}
|
|
382
|
-
this._extractDataStructures(dictionary, unicode);
|
|
383
|
-
this._extractWidths(dictionary, flags, firstChar, descriptor);
|
|
384
|
-
this._setFontData();
|
|
385
|
-
this._fontStructure._capHeight = capHeight / glyphSpaceUnits;
|
|
386
|
-
}
|
|
387
|
-
_buildCharCodeToWidth(widthsByGlyphName: any): any { //eslint-disable-line
|
|
388
|
-
const widths: any = Object.create(null); //eslint-disable-line
|
|
389
|
-
const differences: any = this._fontStructure._differences; //eslint-disable-line
|
|
390
|
-
const encoding: any = this._fontStructure._defaultEncoding; //eslint-disable-line
|
|
391
|
-
for (let charCode = 0; charCode < 256; charCode++) { //eslint-disable-line
|
|
392
|
-
if (charCode in differences && widthsByGlyphName[differences[charCode]]) { //eslint-disable-line
|
|
393
|
-
widths[charCode] = widthsByGlyphName[differences[charCode]]; //eslint-disable-line
|
|
394
|
-
continue;
|
|
395
|
-
}
|
|
396
|
-
if (charCode in encoding && widthsByGlyphName[encoding[charCode]]) { //eslint-disable-line
|
|
397
|
-
widths[charCode] = widthsByGlyphName[encoding[charCode]]; //eslint-disable-line
|
|
398
|
-
continue;
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
return widths;
|
|
402
|
-
}
|
|
403
|
-
_fetchStandardFontData(name: string): any { //eslint-disable-line
|
|
404
|
-
const cachedData: any = this._standardFontDataCache.get(name); //eslint-disable-line
|
|
405
|
-
if (cachedData) {
|
|
406
|
-
return new _PdfStream(cachedData);
|
|
407
|
-
}
|
|
408
|
-
if (name !== 'Symbol' && name !== 'ZapfDingbats') {
|
|
409
|
-
return null;
|
|
410
|
-
}
|
|
411
|
-
const standardFontNameToFileName: any = _getFontNameToFileMap; //eslint-disable-line
|
|
412
|
-
const filename: string = standardFontNameToFileName[name]; //eslint-disable-line
|
|
413
|
-
const cleanBase64: string = _getFontEncodedString(filename).replace(/^data:.+;base64,/, '');
|
|
414
|
-
const binaryString: string = atob(cleanBase64);
|
|
415
|
-
const len: number = binaryString.length;
|
|
416
|
-
const bytes: Uint8Array = new Uint8Array(len);
|
|
417
|
-
for (let i: number = 0; i < len; i++) {
|
|
418
|
-
bytes[Number.parseInt(i.toString(), 10)] = binaryString.charCodeAt(i);
|
|
419
|
-
}
|
|
420
|
-
this._file = new _PdfStream(bytes);
|
|
421
|
-
return this._file;
|
|
422
|
-
}
|
|
423
|
-
_setFontData(): any { //eslint-disable-line
|
|
424
|
-
if (this._fontStructure._type === 'Type3') {
|
|
425
|
-
this._fontStructure._toFontChar = [];
|
|
426
|
-
for (let charCode: number = 0; charCode < 256; charCode++) {
|
|
427
|
-
this._fontStructure._toFontChar[Number.parseInt(charCode.toString(), 10)] =
|
|
428
|
-
this._fontStructure._differences[Number.parseInt(charCode.toString(), 10)] ||
|
|
429
|
-
this._fontStructure._defaultEncoding[Number.parseInt(charCode.toString(), 10)];
|
|
430
|
-
}
|
|
431
|
-
return;
|
|
432
|
-
}
|
|
433
|
-
if (!this._file) {
|
|
434
|
-
this._setFallBackSystemFont(this);
|
|
435
|
-
return;
|
|
436
|
-
}
|
|
437
|
-
this._getFontFileType();
|
|
438
|
-
let compactFont: any; //eslint-disable-line
|
|
439
|
-
try {
|
|
440
|
-
switch (this._fileType) {
|
|
441
|
-
case 'MMType1':
|
|
442
|
-
case 'Type1':
|
|
443
|
-
case 'CIDFontType0':
|
|
444
|
-
this._fontStructure._mimeType = 'font/opentype';
|
|
445
|
-
if (this._fileSubtype === 'Type1C' || this._fileSubtype === 'CIDFontType0C') {
|
|
446
|
-
compactFont = new _PdfCompactFont(this._file, this);
|
|
447
|
-
if (compactFont._builtInEncoding) {
|
|
448
|
-
this._fontStructure._builtInEncoding = compactFont._builtInEncoding;
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
this._adjustWidths();
|
|
452
|
-
if (this._fontStructure._builtInEncoding) {
|
|
453
|
-
this._adjustType1ToUnicode();
|
|
454
|
-
}
|
|
455
|
-
break;
|
|
456
|
-
case 'OpenType':
|
|
457
|
-
case 'TrueType':
|
|
458
|
-
case 'CIDFontType2':
|
|
459
|
-
this._fontStructure._mimeType = 'font/opentype';
|
|
460
|
-
this._checkAndRepair(this._file);
|
|
461
|
-
if (this._isOpenType) {
|
|
462
|
-
this._adjustWidths();
|
|
463
|
-
this._fontStructure._type = 'OpenType';
|
|
464
|
-
}
|
|
465
|
-
break;
|
|
466
|
-
default:
|
|
467
|
-
throw new FormatError('Font is not supported');
|
|
468
|
-
}
|
|
469
|
-
} catch (e) {
|
|
470
|
-
this._setFallBackSystemFont(this);
|
|
471
|
-
return;
|
|
472
|
-
}
|
|
473
|
-
this._amendFallBackToUnicodeMap(this);
|
|
474
|
-
this._fontStructure._subtype = this._fileSubtype;
|
|
475
|
-
}
|
|
476
|
-
_isTrueTypeFile(file: any): boolean { //eslint-disable-line
|
|
477
|
-
const header: any = file.peekBytes(4); //eslint-disable-line
|
|
478
|
-
return (
|
|
479
|
-
this._readUnsignedInt32(header, 0) === 0x00010000 || _bytesToString(header) === 'true'
|
|
480
|
-
);
|
|
481
|
-
}
|
|
482
|
-
_readUnsignedInt32(data: any, offset: any): any { //eslint-disable-line
|
|
483
|
-
return (((data[Number.parseInt(offset.toString(), 10)] << 24) | (data[offset + 1] << 16) | (data[offset + 2] << 8)
|
|
484
|
-
| data[offset + 3]) >>> 0);
|
|
485
|
-
}
|
|
486
|
-
_isOpenTypeFile(file: any): boolean { //eslint-disable-line
|
|
487
|
-
const header: any = file.peekBytes(4); //eslint-disable-line
|
|
488
|
-
return _bytesToString(header) === 'OTTO';
|
|
489
|
-
}
|
|
490
|
-
_isType1File(file: any): boolean { //eslint-disable-line
|
|
491
|
-
const header : any= file.peekBytes(2); //eslint-disable-line
|
|
492
|
-
if (header[0] === 0x25 && header[1] === 0x21) {
|
|
493
|
-
return true;
|
|
494
|
-
}
|
|
495
|
-
if (header[0] === 0x80 && header[1] === 0x01) {
|
|
496
|
-
return true;
|
|
497
|
-
}
|
|
498
|
-
return false;
|
|
499
|
-
}
|
|
500
|
-
_isCompactFontFile(file: any): boolean { //eslint-disable-line
|
|
501
|
-
const header: any = file.peekBytes(4); //eslint-disable-line
|
|
502
|
-
if (header[0] >= 1 && header[3] >= 1 && header[3] <= 4) {
|
|
503
|
-
return true;
|
|
504
|
-
}
|
|
505
|
-
return false;
|
|
506
|
-
}
|
|
507
|
-
_getFontFileType(): void {
|
|
508
|
-
const composite: boolean = this._fontStructure._composite;
|
|
509
|
-
const type: string = this._fontStructure._type;
|
|
510
|
-
const subtype: string = this._fontStructure._subtype;
|
|
511
|
-
if (this._isTrueTypeFile(this._file) || this._isTrueTypeCollectionFile(this._file)) {
|
|
512
|
-
this._fileType = composite ? 'CIDFontType2' : 'TrueType';
|
|
513
|
-
} else if (this._isOpenTypeFile(this._file)) {
|
|
514
|
-
this._fileType = composite ? 'CIDFontType2' : 'OpenType';
|
|
515
|
-
} else if (this._isType1File(this._file)) {
|
|
516
|
-
if (composite) {
|
|
517
|
-
this._fileType = 'CIDFontType0';
|
|
518
|
-
} else {
|
|
519
|
-
this._fileType = type === 'MMType1' ? 'MMType1' : 'Type1';
|
|
520
|
-
}
|
|
521
|
-
} else if (this._isCompactFontFile(this._file)) {
|
|
522
|
-
if (composite) {
|
|
523
|
-
this._fileType = 'CIDFontType0';
|
|
524
|
-
this._fileSubtype = 'CIDFontType0C';
|
|
525
|
-
} else {
|
|
526
|
-
this._fileType = type === 'MMType1' ? 'MMType1' : 'Type1';
|
|
527
|
-
this._fileSubtype = 'Type1C';
|
|
528
|
-
}
|
|
529
|
-
} else {
|
|
530
|
-
this._fileType = type;
|
|
531
|
-
this._fileSubtype = subtype;
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
_extractWidths(descriptor: _PdfDictionary, flags: number, firstChar: number, dictionary: _PdfDictionary): void {
|
|
535
|
-
let glyphsWidths: any = []; //eslint-disable-line
|
|
536
|
-
let defaultWidth: number = 0;
|
|
537
|
-
const glyphsVMetrics: any = []; //eslint-disable-line
|
|
538
|
-
let defaultVMetrics: any; //eslint-disable-line
|
|
539
|
-
if (this._fontStructure._composite) {
|
|
540
|
-
const dw: any = descriptor.get('DW'); //eslint-disable-line
|
|
541
|
-
defaultWidth = typeof dw === 'number' ? Math.ceil(dw) : 1000;
|
|
542
|
-
const widths: any = descriptor.get('W'); //eslint-disable-line
|
|
543
|
-
if (Array.isArray(widths)) {
|
|
544
|
-
for (let i: number = 0, ii: number = widths.length; i < ii; i++) {
|
|
545
|
-
let start: any; //eslint-disable-line
|
|
546
|
-
if (widths[Number.parseInt(i.toString(), 10)] instanceof _PdfReference) {
|
|
547
|
-
start = this._crossReference._fetch(widths[i++]);
|
|
548
|
-
} else {
|
|
549
|
-
start = widths[i++];
|
|
550
|
-
}
|
|
551
|
-
if (!Number.isInteger(start)) {
|
|
552
|
-
break;
|
|
553
|
-
}
|
|
554
|
-
let code: any = widths[Number.parseInt(i.toString(), 10)]; //eslint-disable-line
|
|
555
|
-
if (code instanceof _PdfReference) {
|
|
556
|
-
code = this._crossReference._fetch(widths[Number.parseInt(i.toString(), 10)]);
|
|
557
|
-
}
|
|
558
|
-
if (Array.isArray(code)) {
|
|
559
|
-
for (const c of code) {
|
|
560
|
-
let width: any; //eslint-disable-line
|
|
561
|
-
if (c instanceof _PdfReference) {
|
|
562
|
-
width = this._crossReference._fetch(c);
|
|
563
|
-
} else {
|
|
564
|
-
width = c;
|
|
565
|
-
}
|
|
566
|
-
if (typeof width === 'number') {
|
|
567
|
-
glyphsWidths[Number.parseInt(start.toString(), 10)] = width;
|
|
568
|
-
}
|
|
569
|
-
start++;
|
|
570
|
-
}
|
|
571
|
-
} else if (Number.isInteger(code)) {
|
|
572
|
-
let width: any; //eslint-disable-line
|
|
573
|
-
const widthValue: any = widths[++i]; //eslint-disable-line
|
|
574
|
-
if (widthValue instanceof _PdfReference) {
|
|
575
|
-
width = this._crossReference._fetch(widthValue);
|
|
576
|
-
} else {
|
|
577
|
-
width = widthValue;
|
|
578
|
-
}
|
|
579
|
-
if (typeof width !== 'number') {
|
|
580
|
-
continue;
|
|
581
|
-
}
|
|
582
|
-
for (let j: number = start; j <= code; j++) {
|
|
583
|
-
glyphsWidths[Number.parseInt(j.toString(), 10)] = width;
|
|
584
|
-
}
|
|
585
|
-
} else {
|
|
586
|
-
break;
|
|
587
|
-
}
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
|
-
if (this._vertical) {
|
|
591
|
-
const dw2: any = descriptor.getArray('DW2'); //eslint-disable-line
|
|
592
|
-
let vmetrics: any = this._isNumberArray(dw2, 2) ? dw2 : [880, -1000]; //eslint-disable-line
|
|
593
|
-
vmetrics = descriptor.get('W2');
|
|
594
|
-
if (Array.isArray(vmetrics)) {
|
|
595
|
-
for (let i: number = 0, ii: number = vmetrics.length; i < ii; i++) {
|
|
596
|
-
let start: any = this._crossReference._fetch(vmetrics[i++]); //eslint-disable-line
|
|
597
|
-
if (!Number.isInteger(start)) {
|
|
598
|
-
break;
|
|
599
|
-
}
|
|
600
|
-
const code: number = this._crossReference._fetch(vmetrics[Number.parseInt(i.toString(), 10)]);
|
|
601
|
-
if (Array.isArray(code)) {
|
|
602
|
-
for (let j: number = 0, jj: number = code.length; j < jj; j++) {
|
|
603
|
-
const vmetric: any = [this._crossReference._fetch(code[j++]), this._crossReference._fetch(code[j++]), //eslint-disable-line
|
|
604
|
-
this._crossReference._fetch(code[Number.parseInt(j.toString(), 10)])];
|
|
605
|
-
if (this._isNumberArray(vmetric, null)) {
|
|
606
|
-
glyphsVMetrics[Number.parseInt(start.toString(), 10)] = vmetric;
|
|
607
|
-
}
|
|
608
|
-
start++;
|
|
609
|
-
}
|
|
610
|
-
} else if (Number.isInteger(code)) {
|
|
611
|
-
const vmetric: any = [this._crossReference._fetch(vmetrics[++i]),this._crossReference._fetch(vmetrics[++i]), //eslint-disable-line
|
|
612
|
-
this._crossReference._fetch(vmetrics[++i])];
|
|
613
|
-
if (!this._isNumberArray(vmetric, null)) {
|
|
614
|
-
continue;
|
|
615
|
-
}
|
|
616
|
-
for (let j: number = start; j <= code; j++) {
|
|
617
|
-
glyphsVMetrics[Number.parseInt(j.toString(), 10)] = vmetric;
|
|
618
|
-
}
|
|
619
|
-
} else {
|
|
620
|
-
break;
|
|
621
|
-
}
|
|
622
|
-
}
|
|
623
|
-
}
|
|
624
|
-
}
|
|
625
|
-
} else {
|
|
626
|
-
const widths: any = descriptor.get('Widths'); //eslint-disable-line
|
|
627
|
-
if (Array.isArray(widths)) {
|
|
628
|
-
let j: number = firstChar;
|
|
629
|
-
for (const w of widths) {
|
|
630
|
-
let width: any; //eslint-disable-line
|
|
631
|
-
if (w instanceof _PdfReference) {
|
|
632
|
-
width = this._crossReference._fetch(w);
|
|
633
|
-
} else {
|
|
634
|
-
width = w;
|
|
635
|
-
}
|
|
636
|
-
if (typeof width === 'number') {
|
|
637
|
-
glyphsWidths[Number.parseInt(j.toString(), 10)] = width;
|
|
638
|
-
}
|
|
639
|
-
j++;
|
|
640
|
-
}
|
|
641
|
-
const missingWidth: any = dictionary.get('MissingWidth'); //eslint-disable-line
|
|
642
|
-
defaultWidth = typeof missingWidth === 'number' ? missingWidth : 0;
|
|
643
|
-
}
|
|
644
|
-
}
|
|
645
|
-
let isMonospace: boolean = true;
|
|
646
|
-
let firstWidth: any = defaultWidth; //eslint-disable-line
|
|
647
|
-
const keys: any = Object.keys(glyphsWidths); //eslint-disable-line
|
|
648
|
-
for (let i: number = 0; i < keys.length; i++) {
|
|
649
|
-
const glyph: any = keys[i]; //eslint-disable-line
|
|
650
|
-
const glyphWidth: any = glyphsWidths[glyph]; //eslint-disable-line
|
|
651
|
-
if (!glyphWidth) {
|
|
652
|
-
continue;
|
|
653
|
-
}
|
|
654
|
-
if (!firstWidth) {
|
|
655
|
-
firstWidth = glyphWidth;
|
|
656
|
-
continue;
|
|
657
|
-
}
|
|
658
|
-
if (firstWidth !== glyphWidth) {
|
|
659
|
-
isMonospace = false;
|
|
660
|
-
break;
|
|
661
|
-
}
|
|
662
|
-
}
|
|
663
|
-
if (isMonospace) {
|
|
664
|
-
flags |= this._fontFlags.FixedPitch;
|
|
665
|
-
} else {
|
|
666
|
-
flags &= ~this._fontFlags.FixedPitch;
|
|
667
|
-
}
|
|
668
|
-
this._fontStructure._defaultWidth = defaultWidth;
|
|
669
|
-
this._fontStructure._widths = glyphsWidths;
|
|
670
|
-
this._flags = flags;
|
|
671
|
-
}
|
|
672
|
-
_normalizeRect(rect: number[]): number[] {
|
|
673
|
-
const r: number[] = rect.slice(0); // clone rect
|
|
674
|
-
if (rect[0] > rect[2]) {
|
|
675
|
-
r[0] = rect[2];
|
|
676
|
-
r[2] = rect[0];
|
|
677
|
-
}
|
|
678
|
-
if (rect[1] > rect[3]) {
|
|
679
|
-
r[1] = rect[3];
|
|
680
|
-
r[3] = rect[1];
|
|
681
|
-
}
|
|
682
|
-
return r;
|
|
683
|
-
}
|
|
684
|
-
private _isNumberArray(arr: any, len: number): boolean { //eslint-disable-line
|
|
685
|
-
if (!Array.isArray(arr)) {
|
|
686
|
-
return false;
|
|
687
|
-
}
|
|
688
|
-
if (len !== null && arr.length !== len) {
|
|
689
|
-
return false;
|
|
690
|
-
}
|
|
691
|
-
for (let i: number = 0; i < arr.length; i++) {
|
|
692
|
-
if (typeof arr[Number.parseInt(i.toString(), 10)] !== 'number') {
|
|
693
|
-
return false;
|
|
694
|
-
}
|
|
695
|
-
}
|
|
696
|
-
return true;
|
|
697
|
-
}
|
|
698
|
-
_lookupMatrix(arr: any, fallBack: number[]): any { //eslint-disable-line
|
|
699
|
-
return this._isNumberArray(arr, 6) ? arr : fallBack;
|
|
700
|
-
}
|
|
701
|
-
_lookupRect(arr: any, fallBack: number[]): any { //eslint-disable-line
|
|
702
|
-
return this._isNumberArray(arr, 4) ? arr : fallBack;
|
|
703
|
-
}
|
|
704
|
-
_lookupNormalRect(arr: any, fallBack: number[]): any { //eslint-disable-line
|
|
705
|
-
return this._isNumberArray(arr, 4) ? this._normalizeRect(arr) : fallBack;
|
|
706
|
-
}
|
|
707
|
-
_extractDataStructures(dictionary: _PdfDictionary, unicode?: any): void { //eslint-disable-line
|
|
708
|
-
const differences: any = []; //eslint-disable-line
|
|
709
|
-
let baseEncodingName: any = null; //eslint-disable-line
|
|
710
|
-
let encoding: any; //eslint-disable-line
|
|
711
|
-
if (this._fontStructure._composite) {
|
|
712
|
-
const cidSystemInfo: any = dictionary.get('CIDSystemInfo'); //eslint-disable-line
|
|
713
|
-
if (cidSystemInfo instanceof _PdfDictionary) {
|
|
714
|
-
this._fontStructure._characterSystemInfo = {
|
|
715
|
-
registry: this._stringToPdfString(cidSystemInfo.get('Registry')),
|
|
716
|
-
ordering: this._stringToPdfString(cidSystemInfo.get('Ordering')),
|
|
717
|
-
supplement: cidSystemInfo.get('Supplement')
|
|
718
|
-
};
|
|
719
|
-
}
|
|
720
|
-
}
|
|
721
|
-
if (dictionary.has('Encoding')) {
|
|
722
|
-
encoding = dictionary.get('Encoding');
|
|
723
|
-
if (encoding instanceof _PdfDictionary) {
|
|
724
|
-
baseEncodingName = encoding.get('BaseEncoding');
|
|
725
|
-
baseEncodingName = baseEncodingName instanceof _PdfName ? baseEncodingName.name : null;
|
|
726
|
-
if (encoding.has('Differences')) {
|
|
727
|
-
const diffEncoding: any = encoding.get('Differences'); //eslint-disable-line
|
|
728
|
-
let index: number = 0;
|
|
729
|
-
for (const entry of diffEncoding) {
|
|
730
|
-
let data: any; //eslint-disable-line
|
|
731
|
-
if (entry instanceof _PdfReference) {
|
|
732
|
-
data = this._crossReference._fetch(entry);
|
|
733
|
-
} else {
|
|
734
|
-
data = entry;
|
|
735
|
-
}
|
|
736
|
-
if (typeof data === 'number') {
|
|
737
|
-
index = data;
|
|
738
|
-
} else if (data instanceof _PdfName) {
|
|
739
|
-
differences[index++] = data.name;
|
|
740
|
-
} else {
|
|
741
|
-
throw new FormatError(`Invalid entry in 'Differences' array: ${data}`);
|
|
742
|
-
}
|
|
743
|
-
}
|
|
744
|
-
}
|
|
745
|
-
} else if (encoding instanceof _PdfName) {
|
|
746
|
-
baseEncodingName = encoding.name;
|
|
747
|
-
}
|
|
748
|
-
if (baseEncodingName !== 'MacRomanEncoding' && baseEncodingName !== 'MacExpertEncoding' && baseEncodingName !== 'WinAnsiEncoding') {
|
|
749
|
-
baseEncodingName = null;
|
|
750
|
-
}
|
|
751
|
-
}
|
|
752
|
-
const nonEmbeddedFont: any = !this._file || this._fontStructure._isInternalFont; //eslint-disable-line
|
|
753
|
-
let isSymbolsFontName: any = _getSymbolsFonts()[this._fontStructure._name]; //eslint-disable-line
|
|
754
|
-
if (baseEncodingName && nonEmbeddedFont && isSymbolsFontName) {
|
|
755
|
-
baseEncodingName = null;
|
|
756
|
-
}
|
|
757
|
-
if (baseEncodingName) {
|
|
758
|
-
this._fontStructure._defaultEncoding = _getEncoding(baseEncodingName);
|
|
759
|
-
} else {
|
|
760
|
-
const isSymbolicFont: boolean = !!(this._fontStructure._flags & this._fontFlags.Symbolic);
|
|
761
|
-
const isNonSymbolicFont: boolean = !!(this._fontStructure._flags & this._fontFlags.NonSymbolic);
|
|
762
|
-
encoding = _standardEncoding;
|
|
763
|
-
if (this._fontStructure._type === 'TrueType' && !isNonSymbolicFont) {
|
|
764
|
-
encoding = _winAnsiEncoding;
|
|
765
|
-
}
|
|
766
|
-
if (isSymbolicFont) {
|
|
767
|
-
encoding = _macRomanEncoding;
|
|
768
|
-
if (nonEmbeddedFont) {
|
|
769
|
-
if (/Symbol/i.test(this._fontStructure._name)) {
|
|
770
|
-
encoding = _symbolSetEncoding;
|
|
771
|
-
} else if (/Dingbats/i.test(this._fontStructure._name)) {
|
|
772
|
-
encoding = _zapfDingbatsEncoding;
|
|
773
|
-
} else if (/Wingdings/i.test(this._fontStructure._name)) {
|
|
774
|
-
encoding = _winAnsiEncoding;
|
|
775
|
-
}
|
|
776
|
-
}
|
|
777
|
-
}
|
|
778
|
-
this._fontStructure._defaultEncoding = encoding;
|
|
779
|
-
}
|
|
780
|
-
this._fontStructure._differences = differences;
|
|
781
|
-
this._baseEncodingName = baseEncodingName;
|
|
782
|
-
this._fontStructure._toUnicode = this._readToUnicode(unicode);
|
|
783
|
-
this._hasEncoding = !!baseEncodingName || differences.length > 0;
|
|
784
|
-
this._fontStructure._toUnicode = this._buildToUnicode(baseEncodingName, this._hasEncoding, this._fontStructure._toUnicode);
|
|
785
|
-
}
|
|
786
|
-
_stringToPdfString(text: any): any { //eslint-disable-line
|
|
787
|
-
if (text[0] >= '\xEF') {
|
|
788
|
-
let encoding: any; //eslint-disable-line
|
|
789
|
-
if (text[0] === '\xFE' && text[1] === '\xFF') {
|
|
790
|
-
encoding = 'utf-16be';
|
|
791
|
-
if (text.length % 2 === 1) {
|
|
792
|
-
text = text.slice(0, -1);
|
|
793
|
-
}
|
|
794
|
-
} else if (text[0] === '\xFF' && text[1] === '\xFE') {
|
|
795
|
-
encoding = 'utf-16le';
|
|
796
|
-
if (text.length % 2 === 1) {
|
|
797
|
-
text = text.slice(0, -1);
|
|
798
|
-
}
|
|
799
|
-
} else if (text[0] === '\xEF' && text[1] === '\xBB' && text[2] === '\xBF') {
|
|
800
|
-
encoding = 'utf-8';
|
|
801
|
-
}
|
|
802
|
-
if (encoding) {
|
|
803
|
-
try {
|
|
804
|
-
const decoder: TextDecoder = new TextDecoder(encoding, { fatal: true });
|
|
805
|
-
const buffer : Uint8Array = this._stringToBytes(text);
|
|
806
|
-
const decoded: string = decoder.decode(buffer);
|
|
807
|
-
if (!decoded.includes('\x1b')) {
|
|
808
|
-
return decoded;
|
|
809
|
-
}
|
|
810
|
-
return decoded.replace(/[\x1b][^\x1b]*(?:[\x1b]|$)/g, ''); //eslint-disable-line
|
|
811
|
-
} catch (ex) {
|
|
812
|
-
throw new FormatError(ex.toString());
|
|
813
|
-
}
|
|
814
|
-
}
|
|
815
|
-
}
|
|
816
|
-
const strBuf: any = []; //eslint-disable-line
|
|
817
|
-
const stringTranslateTable: any = [ //eslint-disable-line
|
|
818
|
-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2d8,
|
|
819
|
-
0x2c7, 0x2c6, 0x2d9, 0x2dd, 0x2db, 0x2da, 0x2dc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
820
|
-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
821
|
-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
822
|
-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
823
|
-
0, 0, 0, 0, 0, 0, 0, 0, 0x2022, 0x2020, 0x2021, 0x2026, 0x2014, 0x2013, 0x192,
|
|
824
|
-
0x2044, 0x2039, 0x203a, 0x2212, 0x2030, 0x201e, 0x201c, 0x201d, 0x2018,
|
|
825
|
-
0x2019, 0x201a, 0x2122, 0xfb01, 0xfb02, 0x141, 0x152, 0x160, 0x178, 0x17d,
|
|
826
|
-
0x131, 0x142, 0x153, 0x161, 0x17e, 0, 0x20ac
|
|
827
|
-
];
|
|
828
|
-
for (let i: number = 0, ii: number = text.length; i < ii; i++) {
|
|
829
|
-
const charCode: any = text.charCodeAt(i); //eslint-disable-line
|
|
830
|
-
const code: any = stringTranslateTable[charCode]; //eslint-disable-line
|
|
831
|
-
strBuf.push(code ? String.fromCharCode(code) : text.charAt(i));
|
|
832
|
-
}
|
|
833
|
-
return strBuf.join('');
|
|
834
|
-
}
|
|
835
|
-
_readToUnicode(cmapObj: any): any { //eslint-disable-line
|
|
836
|
-
const cMap: _PdfCharacterMapFactory = new _PdfCharacterMapFactory();
|
|
837
|
-
if (!cmapObj) {
|
|
838
|
-
return null;
|
|
839
|
-
}
|
|
840
|
-
if (cmapObj instanceof _PdfName) {
|
|
841
|
-
const cmap : any = cMap._create(cmapObj, null, null); //eslint-disable-line
|
|
842
|
-
if (cmap instanceof _PdfIdentityCharacterMap) {
|
|
843
|
-
return new _PdfIdentityToUnicodeMap(0, 0xffff);
|
|
844
|
-
}
|
|
845
|
-
return new _ToUnicodeMap(cmap.getMap());
|
|
846
|
-
}
|
|
847
|
-
if (cmapObj instanceof _PdfBaseStream) {
|
|
848
|
-
try {
|
|
849
|
-
const cmap : any = cMap._create(cmapObj, null, null); //eslint-disable-line
|
|
850
|
-
if (cmap instanceof _PdfIdentityCharacterMap) {
|
|
851
|
-
return new _PdfIdentityToUnicodeMap(0, 0xffff);
|
|
852
|
-
}
|
|
853
|
-
const map: any = new Array(cmap._map.length); //eslint-disable-line
|
|
854
|
-
cmap._forEach((charCode: any, token: any) => { //eslint-disable-line
|
|
855
|
-
if (typeof token === 'number') {
|
|
856
|
-
map[Number.parseInt(charCode.toString(), 10)] = String.fromCodePoint(token);
|
|
857
|
-
return;
|
|
858
|
-
}
|
|
859
|
-
if (token.length % 2 !== 0) {
|
|
860
|
-
token = '\u0000' + token;
|
|
861
|
-
}
|
|
862
|
-
const str: any = []; //eslint-disable-line
|
|
863
|
-
for (let k: number = 0; k < token.length; k += 2) {
|
|
864
|
-
const w1: any = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1); //eslint-disable-line
|
|
865
|
-
if ((w1 & 0xf800) !== 0xd800) {
|
|
866
|
-
str.push(w1);
|
|
867
|
-
continue;
|
|
868
|
-
}
|
|
869
|
-
k += 2;
|
|
870
|
-
const w2: any = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1); //eslint-disable-line
|
|
871
|
-
str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
|
|
872
|
-
}
|
|
873
|
-
map[charCode] = String.fromCodePoint(...str); //eslint-disable-line
|
|
874
|
-
});
|
|
875
|
-
return new _ToUnicodeMap(map);
|
|
876
|
-
} catch (reason) {
|
|
877
|
-
throw new FormatError(reason.toString());
|
|
878
|
-
}
|
|
879
|
-
}
|
|
880
|
-
return null;
|
|
881
|
-
}
|
|
882
|
-
_buildToUnicode(baseEncodingName: any, isEncoding: boolean, toUnicode: any): any { //eslint-disable-line
|
|
883
|
-
this._hasIncludedToUnicodeMap = toUnicode && toUnicode._length > 0;
|
|
884
|
-
if (this._hasIncludedToUnicodeMap) {
|
|
885
|
-
if (!this._fontStructure._composite && isEncoding) {
|
|
886
|
-
this._fallBackToUnicodeMap = this._simpleFontToUnicode(baseEncodingName);
|
|
887
|
-
}
|
|
888
|
-
return toUnicode;
|
|
889
|
-
}
|
|
890
|
-
if (!this._fontStructure._composite) {
|
|
891
|
-
return new _ToUnicodeMap(this._simpleFontToUnicode(this._baseEncodingName));
|
|
892
|
-
}
|
|
893
|
-
if (this._fontStructure._composite && ((this._fontStructure._characterMap.builtInCMap &&
|
|
894
|
-
!(this._fontStructure._characterMap instanceof _PdfIdentityCharacterMap)) ||
|
|
895
|
-
(this._fontStructure._characterSystemInfo && this._fontStructure._characterSystemInfo.registry === 'Adobe' &&
|
|
896
|
-
(this._fontStructure._characterSystemInfo.ordering === 'GB1' || this._fontStructure._characterSystemInfo.ordering === 'CNS1' ||
|
|
897
|
-
this._fontStructure._characterSystemInfo.ordering === 'Japan1' || this._fontStructure._characterSystemInfo.ordering === 'Korea1')))) {
|
|
898
|
-
const { registry, ordering } = this._fontStructure._characterSystemInfo;
|
|
899
|
-
const ucs2CMapName: any = _PdfName.get(`${registry}-${ordering}-UCS2`); //eslint-disable-line
|
|
900
|
-
const map: _PdfCharacterMapFactory = new _PdfCharacterMapFactory();
|
|
901
|
-
const ucs2CMap: any = map._create(ucs2CMapName, null, null); //eslint-disable-line
|
|
902
|
-
const toUnicode: any = []; //eslint-disable-line
|
|
903
|
-
let buf: any = []; //eslint-disable-line
|
|
904
|
-
this._fontStructure._characterMap._forEach((charcode: any, cid: any) => { //eslint-disable-line
|
|
905
|
-
if (cid > 0xffff) {
|
|
906
|
-
throw new FormatError('Max size of Character identifier is 65,535');
|
|
907
|
-
}
|
|
908
|
-
const ucs2: any = ucs2CMap._lookup(cid); //eslint-disable-line
|
|
909
|
-
if (ucs2) {
|
|
910
|
-
buf.length = 0;
|
|
911
|
-
for (let i: number = 0, ii: number = ucs2.length; i < ii; i += 2) {
|
|
912
|
-
buf.push((ucs2.charCodeAt(i) << 8) + ucs2.charCodeAt(i + 1));
|
|
913
|
-
}
|
|
914
|
-
toUnicode[charcode] = String.fromCharCode(...buf); //eslint-disable-line
|
|
915
|
-
}
|
|
916
|
-
});
|
|
917
|
-
return new _ToUnicodeMap(toUnicode);
|
|
918
|
-
}
|
|
919
|
-
return new _PdfIdentityToUnicodeMap(this._firstChar, this._lastChar);
|
|
920
|
-
}
|
|
921
|
-
_simpleFontToUnicode(baseEncodingName: any, forceGlyphs: boolean = false): void { //eslint-disable-line
|
|
922
|
-
const toUnicode: any = []; //eslint-disable-line
|
|
923
|
-
const encoding: any = this._fontStructure._defaultEncoding.slice(); //eslint-disable-line
|
|
924
|
-
const differences: any = this._fontStructure._differences; //eslint-disable-line
|
|
925
|
-
let keys: any = Object.keys(differences); //eslint-disable-line
|
|
926
|
-
for (let i: number = 0; i < keys.length; i++) {
|
|
927
|
-
const charCode: any = keys[i]; //eslint-disable-line
|
|
928
|
-
const glyphName: string = differences[Number.parseInt(charCode.toString(), 10)];
|
|
929
|
-
if (glyphName === '.notdef') {
|
|
930
|
-
continue;
|
|
931
|
-
}
|
|
932
|
-
encoding[Number.parseInt(charCode.toString(), 10)] = glyphName;
|
|
933
|
-
}
|
|
934
|
-
const glyphsUnicodeMap: any = _getGlyphsUnicode(); //eslint-disable-line
|
|
935
|
-
keys = Object.keys(encoding);
|
|
936
|
-
for (let i: number = 0; i < keys.length; i++) {
|
|
937
|
-
const charcode: any = keys[i]; //eslint-disable-line
|
|
938
|
-
let glyphName: any = encoding[Number.parseInt(charcode.toString(), 10)]; //eslint-disable-line
|
|
939
|
-
if (glyphName === '') {
|
|
940
|
-
continue;
|
|
941
|
-
}
|
|
942
|
-
let unicode: any = glyphsUnicodeMap[glyphName]; //eslint-disable-line
|
|
943
|
-
if (unicode !== undefined) {
|
|
944
|
-
toUnicode[Number.parseInt(charcode.toString(), 10)] = String.fromCharCode(unicode);
|
|
945
|
-
continue;
|
|
946
|
-
}
|
|
947
|
-
let code: number = 0;
|
|
948
|
-
switch (glyphName[0]) {
|
|
949
|
-
case 'G':
|
|
950
|
-
if (glyphName.length === 3) {
|
|
951
|
-
code = parseInt(glyphName.substring(1), 16);
|
|
952
|
-
}
|
|
953
|
-
break;
|
|
954
|
-
case 'g':
|
|
955
|
-
if (glyphName.length === 5) {
|
|
956
|
-
code = parseInt(glyphName.substring(1), 16);
|
|
957
|
-
}
|
|
958
|
-
break;
|
|
959
|
-
case 'C':
|
|
960
|
-
case 'c':
|
|
961
|
-
if (glyphName.length >= 3 && glyphName.length <= 4) {
|
|
962
|
-
const codeStr: any = glyphName.substring(1); //eslint-disable-line
|
|
963
|
-
if (forceGlyphs) {
|
|
964
|
-
code = parseInt(codeStr, 16);
|
|
965
|
-
break;
|
|
966
|
-
}
|
|
967
|
-
code = +codeStr;
|
|
968
|
-
if (Number.isNaN(code) && Number.isInteger(parseInt(codeStr, 16))) {
|
|
969
|
-
return this._simpleFontToUnicode(true);
|
|
970
|
-
}
|
|
971
|
-
}
|
|
972
|
-
break;
|
|
973
|
-
case 'u':
|
|
974
|
-
unicode = _getUnicodeForGlyph(glyphName, glyphsUnicodeMap);
|
|
975
|
-
if (unicode !== -1) {
|
|
976
|
-
code = unicode;
|
|
977
|
-
}
|
|
978
|
-
break;
|
|
979
|
-
default:
|
|
980
|
-
switch (glyphName) {
|
|
981
|
-
case 'f_h':
|
|
982
|
-
case 'f_t':
|
|
983
|
-
case 'T_h':
|
|
984
|
-
toUnicode[Number.parseInt(charcode.toString(), 10)] = glyphName.replace('_', '');
|
|
985
|
-
continue;
|
|
986
|
-
}
|
|
987
|
-
break;
|
|
988
|
-
}
|
|
989
|
-
if (code > 0 && code <= 0x10ffff && Number.isInteger(code)) {
|
|
990
|
-
if (baseEncodingName && code === +charcode) {
|
|
991
|
-
const baseEncoding: any = _getEncoding(baseEncodingName); //eslint-disable-line
|
|
992
|
-
glyphName = baseEncoding[Number.parseInt(charcode.toString(), 10)];
|
|
993
|
-
if (baseEncoding && glyphName) {
|
|
994
|
-
toUnicode[Number.parseInt(charcode.toString(), 10)] =
|
|
995
|
-
String.fromCharCode(glyphsUnicodeMap[Number.parseInt(glyphName.toString(), 10)]);
|
|
996
|
-
continue;
|
|
997
|
-
}
|
|
998
|
-
}
|
|
999
|
-
toUnicode[Number.parseInt(charcode.toString(), 10)] = String.fromCodePoint(code);
|
|
1000
|
-
}
|
|
1001
|
-
}
|
|
1002
|
-
return toUnicode;
|
|
1003
|
-
}
|
|
1004
|
-
_string32(value: any) { //eslint-disable-line
|
|
1005
|
-
return String.fromCharCode((value >> 24) & 0xff, (value >> 16) & 0xff, (value >> 8) & 0xff, value & 0xff);
|
|
1006
|
-
}
|
|
1007
|
-
_buildToFontChar(encoding: any, glyphsUnicodeMap: any, differences: any): any { //eslint-disable-line
|
|
1008
|
-
const toFontChar: any = []; //eslint-disable-line
|
|
1009
|
-
let unicode: any; //eslint-disable-line
|
|
1010
|
-
for (let i: number = 0, ii: number = encoding.length; i < ii; i++) {
|
|
1011
|
-
unicode = this._getUnicodeForGlyph(encoding[Number.parseInt(i.toString(), 10)], glyphsUnicodeMap);
|
|
1012
|
-
if (unicode !== -1) {
|
|
1013
|
-
toFontChar[Number.parseInt(i.toString(), 10)] = unicode;
|
|
1014
|
-
}
|
|
1015
|
-
}
|
|
1016
|
-
const keys: any = Object.keys(differences); //eslint-disable-line
|
|
1017
|
-
for (let i: number = 0; i < keys.length; i++) {
|
|
1018
|
-
const charCode = keys[i]; //eslint-disable-line
|
|
1019
|
-
unicode = this._getUnicodeForGlyph(differences[Number.parseInt(charCode.toString(), 10)], glyphsUnicodeMap);
|
|
1020
|
-
if (unicode !== -1) {
|
|
1021
|
-
toFontChar[+charCode] = unicode;
|
|
1022
|
-
}
|
|
1023
|
-
}
|
|
1024
|
-
return toFontChar;
|
|
1025
|
-
}
|
|
1026
|
-
_getUnicodeForGlyph(name: any, glyphsUnicodeMap: any): any { //eslint-disable-line
|
|
1027
|
-
let unicode: any = glyphsUnicodeMap[Number.parseInt(name.toString(), 10)]; //eslint-disable-line
|
|
1028
|
-
if (unicode !== undefined) {
|
|
1029
|
-
return unicode;
|
|
1030
|
-
}
|
|
1031
|
-
if (!name) {
|
|
1032
|
-
return -1;
|
|
1033
|
-
}
|
|
1034
|
-
if (name[0] === 'u') {
|
|
1035
|
-
const nameLen: number = name.length;
|
|
1036
|
-
let hexStr: string;
|
|
1037
|
-
if (nameLen === 7 && name[1] === 'n' && name[2] === 'i') {
|
|
1038
|
-
hexStr = name.substring(3);
|
|
1039
|
-
} else if (nameLen >= 5 && nameLen <= 7) {
|
|
1040
|
-
hexStr = name.substring(1);
|
|
1041
|
-
} else {
|
|
1042
|
-
return -1;
|
|
1043
|
-
}
|
|
1044
|
-
if (hexStr === hexStr.toUpperCase()) {
|
|
1045
|
-
unicode = parseInt(hexStr, 16);
|
|
1046
|
-
if (unicode >= 0) {
|
|
1047
|
-
return unicode;
|
|
1048
|
-
}
|
|
1049
|
-
}
|
|
1050
|
-
}
|
|
1051
|
-
return -1;
|
|
1052
|
-
}
|
|
1053
|
-
_writeUnSignedInt32(bytes: number[], index: number, value: number): void {
|
|
1054
|
-
bytes[index + 3] = value & 0xff;
|
|
1055
|
-
bytes[index + 2] = value >>> 8;
|
|
1056
|
-
bytes[index + 1] = value >>> 16;
|
|
1057
|
-
bytes[Number.parseInt(index.toString(), 10)] = value >>> 24;
|
|
1058
|
-
}
|
|
1059
|
-
_stringToBytes(value: any): Uint8Array { //eslint-disable-line
|
|
1060
|
-
if (typeof value !== 'string') {
|
|
1061
|
-
//unreachable('Invalid argument for stringToBytes');
|
|
1062
|
-
}
|
|
1063
|
-
const length: number = value.length;
|
|
1064
|
-
const bytes: Uint8Array = new Uint8Array(length);
|
|
1065
|
-
for (let i: number = 0; i < length; ++i) {
|
|
1066
|
-
bytes[Number.parseInt(i.toString(), 10)] = value.charCodeAt(i) & 0xff;
|
|
1067
|
-
}
|
|
1068
|
-
return bytes;
|
|
1069
|
-
}
|
|
1070
|
-
_writeSignedInt16(bytes: number[], index: number, value: number): void {
|
|
1071
|
-
bytes[index + 1] = value;
|
|
1072
|
-
bytes[Number.parseInt(index.toString(), 10)] = value >>> 8;
|
|
1073
|
-
}
|
|
1074
|
-
_signedInt16(b0: number, b1: number): number {
|
|
1075
|
-
const value: number = (b0 << 8) + b1;
|
|
1076
|
-
return value & (1 << 15) ? value - 0x10000 : value;
|
|
1077
|
-
}
|
|
1078
|
-
_isSerifFont(baseFontName: string): boolean {
|
|
1079
|
-
const fontNameWoStyle: any = baseFontName.split('-', 1)[0]; //eslint-disable-line
|
|
1080
|
-
return (fontNameWoStyle in _getSerifFonts() || /serif/gi.test(fontNameWoStyle));
|
|
1081
|
-
}
|
|
1082
|
-
_adjustWidths(): any { //eslint-disable-line
|
|
1083
|
-
if (!this._fontStructure._fontMatrix[0]) {
|
|
1084
|
-
return;
|
|
1085
|
-
}
|
|
1086
|
-
if (this._fontStructure._fontMatrix[0] === this._fontIdentityMatrix[0]) {
|
|
1087
|
-
return;
|
|
1088
|
-
}
|
|
1089
|
-
const scale: number = 0.001 / this._fontStructure._fontMatrix[0];
|
|
1090
|
-
const glyphsWidths: any = this._fontStructure._widths; //eslint-disable-line
|
|
1091
|
-
const keys: any = Object.keys(glyphsWidths); //eslint-disable-line
|
|
1092
|
-
for (let i: number = 0; i < keys.length; i++) {
|
|
1093
|
-
const glyph = keys[i]; //eslint-disable-line
|
|
1094
|
-
glyphsWidths[Number.parseInt(glyph.toString(), 10)] *= scale;
|
|
1095
|
-
}
|
|
1096
|
-
this._fontStructure._defaultWidth *= scale;
|
|
1097
|
-
}
|
|
1098
|
-
_getBaseFontMetrics(name: string): any { //eslint-disable-line
|
|
1099
|
-
let defaultWidth: number = 0;
|
|
1100
|
-
let widths: any = Object.create(null); //eslint-disable-line
|
|
1101
|
-
let monospace: boolean = false;
|
|
1102
|
-
const stdFontMap: any = _getStdFontMap(); //eslint-disable-line
|
|
1103
|
-
let lookupName: string = stdFontMap[Number.parseInt(name.toString(), 10)] || name;
|
|
1104
|
-
const metrices: any = this._getMetrics(); //eslint-disable-line
|
|
1105
|
-
if (metrices.indexOf(lookupName) === -1) {
|
|
1106
|
-
lookupName = this._isSerifFont(name) ? 'Times-Roman' : 'Helvetica';
|
|
1107
|
-
}
|
|
1108
|
-
const metrics: _PdfMetrics = new _PdfMetrics();
|
|
1109
|
-
let glyphWidths: any; //eslint-disable-line
|
|
1110
|
-
switch (lookupName) {
|
|
1111
|
-
case 'Courier':
|
|
1112
|
-
glyphWidths = metrics._courier;
|
|
1113
|
-
break;
|
|
1114
|
-
case 'Courier-Bold':
|
|
1115
|
-
glyphWidths = metrics._courierBold;
|
|
1116
|
-
break;
|
|
1117
|
-
case 'Courier-BoldOblique':
|
|
1118
|
-
glyphWidths = metrics._courierBoldOblique;
|
|
1119
|
-
break;
|
|
1120
|
-
case 'Courier-Oblique':
|
|
1121
|
-
glyphWidths = metrics._courierOblique;
|
|
1122
|
-
break;
|
|
1123
|
-
case 'Helvetica':
|
|
1124
|
-
glyphWidths = metrics._helveticaWidths;
|
|
1125
|
-
break;
|
|
1126
|
-
case 'Helvetica-Bold':
|
|
1127
|
-
glyphWidths = metrics._helveticaBold;
|
|
1128
|
-
break;
|
|
1129
|
-
case 'Helvetica-BoldOblique':
|
|
1130
|
-
glyphWidths = metrics._helveticaBoldOblique;
|
|
1131
|
-
break;
|
|
1132
|
-
case 'Helvetica-Oblique':
|
|
1133
|
-
glyphWidths = metrics._helveticaOblique;
|
|
1134
|
-
break;
|
|
1135
|
-
case 'Symbol':
|
|
1136
|
-
glyphWidths = metrics._symbol;
|
|
1137
|
-
break;
|
|
1138
|
-
case 'Times-Roman':
|
|
1139
|
-
glyphWidths = metrics._timesRoman;
|
|
1140
|
-
break;
|
|
1141
|
-
case 'Times-Bold':
|
|
1142
|
-
glyphWidths = metrics._timesBold;
|
|
1143
|
-
break;
|
|
1144
|
-
case 'Times-BoldItalic':
|
|
1145
|
-
glyphWidths = metrics._timesBoldItalic;
|
|
1146
|
-
break;
|
|
1147
|
-
case 'Times-Italic':
|
|
1148
|
-
glyphWidths = metrics._timesItalic;
|
|
1149
|
-
break;
|
|
1150
|
-
case 'ZapfDingbats':
|
|
1151
|
-
glyphWidths = metrics._zapfDingbats;
|
|
1152
|
-
break;
|
|
1153
|
-
}
|
|
1154
|
-
if (typeof glyphWidths === 'number') {
|
|
1155
|
-
defaultWidth = glyphWidths;
|
|
1156
|
-
monospace = true;
|
|
1157
|
-
} else {
|
|
1158
|
-
widths = glyphWidths;
|
|
1159
|
-
}
|
|
1160
|
-
return {defaultWidth, monospace, widths};
|
|
1161
|
-
}
|
|
1162
|
-
_getMetrics(): any { //eslint-disable-line
|
|
1163
|
-
const fontNames: any = ['Courier', 'Courier-Bold', 'Courier-BoldOblique', 'Courier-Oblique', 'Helvetica', 'Helvetica-Bold', 'Helvetica-BoldOblique', 'Helvetica-Oblique', 'Symbol', 'Times-Bold', 'Times-Roman', 'Times-BoldItalic', 'Times-Italic', 'ZapfDingbats']; //eslint-disable-line
|
|
1164
|
-
return fontNames;
|
|
1165
|
-
}
|
|
1166
|
-
_getStandardFontName(name: string): any { //eslint-disable-line
|
|
1167
|
-
const fontName: string = this._normalizeFontName(name);
|
|
1168
|
-
const stdFontMap: any = _getStdFontMap(); //eslint-disable-line
|
|
1169
|
-
return stdFontMap[fontName]; //eslint-disable-line
|
|
1170
|
-
}
|
|
1171
|
-
_normalizeFontName(name: string): string {
|
|
1172
|
-
return name.replace(/[,_]/g, '-').replace(/\s/g, '');
|
|
1173
|
-
}
|
|
1174
|
-
_amendFallBackToUnicodeMap(properties: any): void { //eslint-disable-line
|
|
1175
|
-
if (!properties._fallBackToUnicodeMap) {
|
|
1176
|
-
return;
|
|
1177
|
-
}
|
|
1178
|
-
if (properties._fontStructure._toUnicode instanceof _PdfIdentityToUnicodeMap) {
|
|
1179
|
-
return;
|
|
1180
|
-
}
|
|
1181
|
-
const toUnicode: any = []; //eslint-disable-line
|
|
1182
|
-
for (const charCode in properties._fallBackToUnicodeMap) {
|
|
1183
|
-
if (properties._fontStructure._toUnicode._has(charCode)) {
|
|
1184
|
-
continue;
|
|
1185
|
-
}
|
|
1186
|
-
toUnicode[Number.parseInt(charCode.toString(), 10)] = properties._fallBackToUnicodeMap[
|
|
1187
|
-
Number.parseInt(charCode.toString(), 10)];
|
|
1188
|
-
}
|
|
1189
|
-
if (toUnicode.length > 0) {
|
|
1190
|
-
properties._fontStructure._toUnicode._amend(toUnicode);
|
|
1191
|
-
}
|
|
1192
|
-
}
|
|
1193
|
-
_applyStandardFontGlyphMap(map: any, glyphMap: any): any { //eslint-disable-line
|
|
1194
|
-
const keys: any = Object.keys(glyphMap); //eslint-disable-line
|
|
1195
|
-
for (let i: number = 0; i < keys.length; i++) {
|
|
1196
|
-
const charCode: any = keys[Number.parseInt(i.toString(), 10)]; //eslint-disable-line
|
|
1197
|
-
map[+charCode] = glyphMap[Number.parseInt(charCode.toString(), 10)];
|
|
1198
|
-
}
|
|
1199
|
-
}
|
|
1200
|
-
_setFallBackSystemFont(properties: any): any { //eslint-disable-line
|
|
1201
|
-
this._fontStructure._missingFile = true;
|
|
1202
|
-
const name: string = this._fontStructure._name;
|
|
1203
|
-
const type: string = this._fontStructure._type;
|
|
1204
|
-
let fontName: string = this._normalizeFontName(name);
|
|
1205
|
-
const stdFontMap: any = _getStdFontMap(); //eslint-disable-line
|
|
1206
|
-
const nonStdFontMap: any = _getNonStdFontMap(); //eslint-disable-line
|
|
1207
|
-
const isStandardFont: boolean = !!stdFontMap[fontName]; //eslint-disable-line
|
|
1208
|
-
const isMappedToStandardFont: any = !!(nonStdFontMap[fontName] && stdFontMap //eslint-disable-line
|
|
1209
|
-
[nonStdFontMap[fontName]]); //eslint-disable-line
|
|
1210
|
-
fontName = stdFontMap[fontName] || nonStdFontMap[fontName] //eslint-disable-line
|
|
1211
|
-
|| fontName;
|
|
1212
|
-
const fontBasicMetricsMap: any = _getFontBasicMetrics(); //eslint-disable-line
|
|
1213
|
-
const metrics: any = fontBasicMetricsMap[fontName]; //eslint-disable-line
|
|
1214
|
-
if (metrics) {
|
|
1215
|
-
if (isNaN(this._fontStructure._ascent)) {
|
|
1216
|
-
this._fontStructure._ascent = metrics.ascent / 1000;
|
|
1217
|
-
}
|
|
1218
|
-
if (isNaN(this._fontStructure._descent)) {
|
|
1219
|
-
this._fontStructure._descent = metrics.descent / 1000;
|
|
1220
|
-
}
|
|
1221
|
-
if (isNaN(this._fontStructure._capHeight)) {
|
|
1222
|
-
this._fontStructure._capHeight = metrics.capHeight / 1000;
|
|
1223
|
-
}
|
|
1224
|
-
}
|
|
1225
|
-
this._fontStructure._bold = /bold/gi.test(fontName);
|
|
1226
|
-
this._fontStructure._italic = /oblique|italic/gi.test(fontName);
|
|
1227
|
-
this._fontStructure._black = /Black/g.test(name);
|
|
1228
|
-
const isNarrow: boolean = /Narrow/g.test(name);
|
|
1229
|
-
this._remeasure = (!isStandardFont || isNarrow) && Object.keys(this._fontStructure._widths).length > 0;
|
|
1230
|
-
if ((isStandardFont || isMappedToStandardFont) && type === 'CIDFontType2' && this._fontStructure._encoding.startsWith('Identity-')) {
|
|
1231
|
-
const cidToGidMap: any = properties.cidToGidMap; //eslint-disable-line
|
|
1232
|
-
const map: any= []; //eslint-disable-line
|
|
1233
|
-
this._applyStandardFontGlyphMap(map, _getGlyphMapForStandardFonts());
|
|
1234
|
-
if (/Arial-?Black/i.test(name)) {
|
|
1235
|
-
this._applyStandardFontGlyphMap(map, _getSupplementalGlyphMapForArialBlack());
|
|
1236
|
-
} else if (/Calibri/i.test(name)) {
|
|
1237
|
-
this._applyStandardFontGlyphMap(map, _getFontGlyphMap());
|
|
1238
|
-
}
|
|
1239
|
-
if (cidToGidMap) {
|
|
1240
|
-
const keys: any = Object.keys(map); //eslint-disable-line
|
|
1241
|
-
for (let i: number = 0; i < keys.length; i++) {
|
|
1242
|
-
const charCode: any = keys[Number.parseInt(i.toString(), 10)]; //eslint-disable-line
|
|
1243
|
-
const cid: any = map[Number.parseInt(charCode.toString(), 10)]; //eslint-disable-line
|
|
1244
|
-
if (cidToGidMap[Number.parseInt(cid.toString(), 10)] !== undefined) {
|
|
1245
|
-
map[+charCode] = cidToGidMap[Number.parseInt(cid.toString(), 10)];
|
|
1246
|
-
}
|
|
1247
|
-
}
|
|
1248
|
-
if (cidToGidMap.length !== this._fontStructure._toUnicode.length && properties.hasIncludedToUnicodeMap &&
|
|
1249
|
-
this._fontStructure._toUnicode instanceof _PdfIdentityToUnicodeMap) {
|
|
1250
|
-
this._fontStructure._toUnicode._forEach((charCode: any, unicodeCharCode: any) => { //eslint-disable-line
|
|
1251
|
-
const cid: any = map[Number.parseInt(charCode.toString(), 10)]; //eslint-disable-line
|
|
1252
|
-
if (cidToGidMap[Number.parseInt(cid.toString(), 10)] === undefined) {
|
|
1253
|
-
map[+charCode] = unicodeCharCode;
|
|
1254
|
-
}
|
|
1255
|
-
});
|
|
1256
|
-
}
|
|
1257
|
-
}
|
|
1258
|
-
if (!(this._fontStructure._toUnicode instanceof _PdfIdentityToUnicodeMap)) {
|
|
1259
|
-
this._fontStructure._toUnicode._forEach((charCode: any, unicodeCharCode: any) => { //eslint-disable-line
|
|
1260
|
-
map[+charCode] = unicodeCharCode;
|
|
1261
|
-
});
|
|
1262
|
-
}
|
|
1263
|
-
this._fontStructure._toFontChar = map;
|
|
1264
|
-
this._fontStructure._toUnicode = new _ToUnicodeMap(map);
|
|
1265
|
-
} else if (/Symbol/i.test(fontName)) {
|
|
1266
|
-
this._fontStructure._toFontChar = this._buildToFontChar(_symbolSetEncoding, _getGlyphsUnicode(),
|
|
1267
|
-
this._fontStructure._differences);
|
|
1268
|
-
} else if (/Dingbats/i.test(fontName)) {
|
|
1269
|
-
this._fontStructure._toFontChar = this._buildToFontChar(_zapfDingbatsEncoding, _getDingbatsGlyphsUnicode(),
|
|
1270
|
-
this._fontStructure._differences);
|
|
1271
|
-
} else if (isStandardFont) {
|
|
1272
|
-
const map: any = this._buildToFontChar(this._fontStructure._defaultEncoding, _getGlyphsUnicode(), this._fontStructure._differences); //eslint-disable-line
|
|
1273
|
-
if (type === 'CIDFontType2' && !this._fontStructure._encoding.startsWith('Identity-') && !(this._fontStructure._toUnicode instanceof _PdfIdentityToUnicodeMap)) {
|
|
1274
|
-
this._fontStructure._toUnicode._forEach((charCode: any, unicodeCharCode:any) => { //eslint-disable-line
|
|
1275
|
-
map[+charCode] = unicodeCharCode;
|
|
1276
|
-
});
|
|
1277
|
-
}
|
|
1278
|
-
this._fontStructure._toFontChar = map;
|
|
1279
|
-
} else {
|
|
1280
|
-
const glyphsUnicodeMap: any = _getGlyphsUnicode(); //eslint-disable-line
|
|
1281
|
-
const map: any = []; //eslint-disable-line
|
|
1282
|
-
this._fontStructure._toUnicode._forEach((charCode: any, unicodeCharCode: any) => { //eslint-disable-line
|
|
1283
|
-
if (!this._fontStructure._composite) {
|
|
1284
|
-
const glyphName: any = this._fontStructure._differences[charCode] || this._fontStructure._defaultEncoding[charCode]; //eslint-disable-line
|
|
1285
|
-
const unicode: any = _getUnicodeForGlyph(glyphName, glyphsUnicodeMap); //eslint-disable-line
|
|
1286
|
-
if (unicode !== -1) {
|
|
1287
|
-
unicodeCharCode = unicode;
|
|
1288
|
-
}
|
|
1289
|
-
}
|
|
1290
|
-
map[+charCode] = unicodeCharCode;
|
|
1291
|
-
});
|
|
1292
|
-
if (this._fontStructure._composite && this._fontStructure._toUnicode instanceof _PdfIdentityToUnicodeMap) {
|
|
1293
|
-
if (/Tahoma|Verdana/i.test(name)) {
|
|
1294
|
-
this._applyStandardFontGlyphMap(map, _getGlyphMapForStandardFonts());
|
|
1295
|
-
}
|
|
1296
|
-
}
|
|
1297
|
-
this._fontStructure._toFontChar = map;
|
|
1298
|
-
}
|
|
1299
|
-
this._amendFallBackToUnicodeMap(properties);
|
|
1300
|
-
}
|
|
1301
|
-
get _spaceWidth(): number{
|
|
1302
|
-
const possibleSpaceReplacements: string[] = ['space', 'minus', 'one', 'i', 'I'];
|
|
1303
|
-
let width: number;
|
|
1304
|
-
for (let i: number = 0; i < possibleSpaceReplacements.length ; i++) {
|
|
1305
|
-
const glyphName: any = possibleSpaceReplacements[i]; //eslint-disable-line
|
|
1306
|
-
if (glyphName in this._fontStructure._widths) {
|
|
1307
|
-
width = this._fontStructure._widths[glyphName]; //eslint-disable-line
|
|
1308
|
-
break;
|
|
1309
|
-
}
|
|
1310
|
-
const glyphsUnicodeMap: any = _getGlyphsUnicode(); //eslint-disable-line
|
|
1311
|
-
const glyphUnicode = glyphsUnicodeMap[glyphName]; //eslint-disable-line
|
|
1312
|
-
let charcode: number = 0;
|
|
1313
|
-
if (this._fontStructure._composite && this._fontStructure._characterMap._contains(glyphUnicode)) {
|
|
1314
|
-
charcode = this._fontStructure._characterMap._lookup(glyphUnicode);
|
|
1315
|
-
if (typeof charcode === 'string') {
|
|
1316
|
-
charcode = this._convertCidString(glyphUnicode, charcode);
|
|
1317
|
-
}
|
|
1318
|
-
}
|
|
1319
|
-
if (!charcode && this._fontStructure._toUnicode) {
|
|
1320
|
-
charcode = this._fontStructure._toUnicode._charCodeOf(glyphUnicode);
|
|
1321
|
-
}
|
|
1322
|
-
if (charcode <= 0) {
|
|
1323
|
-
charcode = glyphUnicode;
|
|
1324
|
-
}
|
|
1325
|
-
width = this._fontStructure._widths[charcode]; //eslint-disable-line
|
|
1326
|
-
if (width) {
|
|
1327
|
-
break;
|
|
1328
|
-
}
|
|
1329
|
-
}
|
|
1330
|
-
return width;
|
|
1331
|
-
}
|
|
1332
|
-
_charToGlyph(charCode: any, isSpace: boolean = false): _Glyph { //eslint-disable-line
|
|
1333
|
-
let vmetrics: any; //eslint-disable-line
|
|
1334
|
-
let glyph; //eslint-disable-line
|
|
1335
|
-
if (this._fontStructure._glyphCache) {
|
|
1336
|
-
glyph = this._fontStructure._glyphCache[Number.parseInt(charCode.toString(), 10)
|
|
1337
|
-
];
|
|
1338
|
-
}
|
|
1339
|
-
if (typeof(glyph) !== 'undefined' && glyph !== null && glyph.isSpace === isSpace) {
|
|
1340
|
-
return glyph;
|
|
1341
|
-
}
|
|
1342
|
-
let fontCharCode: any; //eslint-disable-line
|
|
1343
|
-
let width: number;
|
|
1344
|
-
let widthCode: any = charCode; //eslint-disable-line
|
|
1345
|
-
const cMap: any = this._fontStructure._characterMap; //eslint-disable-line
|
|
1346
|
-
if (cMap && cMap._contains(charCode)) {
|
|
1347
|
-
widthCode = this._fontStructure._characterMap._lookup(charCode);
|
|
1348
|
-
if (typeof widthCode === 'string') {
|
|
1349
|
-
widthCode = this._convertCidString(charCode, widthCode);
|
|
1350
|
-
}
|
|
1351
|
-
}
|
|
1352
|
-
width = this._fontStructure._widths[Number.parseInt(widthCode.toString(), 10)];
|
|
1353
|
-
if (typeof width !== 'number') {
|
|
1354
|
-
width = this._fontStructure._defaultWidth;
|
|
1355
|
-
}
|
|
1356
|
-
let vmetric: any; //eslint-disable-line
|
|
1357
|
-
if (vmetrics) {
|
|
1358
|
-
vmetric = vmetrics[Number.parseInt(widthCode.toString(), 10)];
|
|
1359
|
-
}
|
|
1360
|
-
let unicode: any = this._fontStructure._toUnicode._get(charCode) || charCode; //eslint-disable-line
|
|
1361
|
-
if (typeof unicode === 'number') {
|
|
1362
|
-
unicode = String.fromCharCode(unicode);
|
|
1363
|
-
}
|
|
1364
|
-
let isInFont: boolean = false;
|
|
1365
|
-
if (this._fontStructure._missingFile) {
|
|
1366
|
-
const glyphName: any = this._fontStructure._differences[Number.parseInt(charCode.toString(), 10)] || this._fontStructure._defaultEncoding[Number.parseInt(charCode.toString(), 10)]; //eslint-disable-line
|
|
1367
|
-
if ((glyphName === '.notdef' || glyphName === '') && this._fontStructure._type === 'Type1') {
|
|
1368
|
-
fontCharCode = 0x20;
|
|
1369
|
-
if (glyphName === '') {
|
|
1370
|
-
if (!width) {
|
|
1371
|
-
width = this._spaceWidth;
|
|
1372
|
-
}
|
|
1373
|
-
unicode = String.fromCharCode(fontCharCode);
|
|
1374
|
-
}
|
|
1375
|
-
}
|
|
1376
|
-
}
|
|
1377
|
-
let accent: any; //eslint-disable-line
|
|
1378
|
-
if (this._standardCharacter && this._standardCharacter[Number.parseInt(charCode.toString(), 10)]) {
|
|
1379
|
-
isInFont = true;
|
|
1380
|
-
const accentedCharcter: any = this._standardCharacter[Number.parseInt(charCode.toString(), 10)]; //eslint-disable-line
|
|
1381
|
-
accent = {fontChar: String.fromCodePoint(accentedCharcter.accentFontCharCode), offset: accentedCharcter.accentOffset};
|
|
1382
|
-
}
|
|
1383
|
-
glyph = new _Glyph(unicode, accent, width, vmetric, isSpace, isInFont);
|
|
1384
|
-
return (this._fontStructure._glyphCache[Number.parseInt(charCode.toString(), 10)] = glyph);
|
|
1385
|
-
}
|
|
1386
|
-
_convertCidString(characterCode: any, characterIdentifier: any, shouldThrow: boolean = false): any { //eslint-disable-line
|
|
1387
|
-
switch (characterIdentifier.length) {
|
|
1388
|
-
case 1:
|
|
1389
|
-
return characterIdentifier.charCodeAt(0);
|
|
1390
|
-
case 2:
|
|
1391
|
-
return (characterIdentifier.charCodeAt(0) << 8) | characterIdentifier.charCodeAt(1);
|
|
1392
|
-
}
|
|
1393
|
-
const msg: string = `Unsupported CID string (charCode ${characterCode}): '${characterIdentifier}'.`;
|
|
1394
|
-
if (shouldThrow) {
|
|
1395
|
-
throw new FormatError(msg);
|
|
1396
|
-
}
|
|
1397
|
-
return characterIdentifier;
|
|
1398
|
-
}
|
|
1399
|
-
_isTrueTypeCollectionFile(file: any) { //eslint-disable-line
|
|
1400
|
-
const header: any = file.peekBytes(4); //eslint-disable-line
|
|
1401
|
-
return _bytesToString(header) === 'ttcf';
|
|
1402
|
-
}
|
|
1403
|
-
_readTrueTypeCollectionHeader(data: any) { //eslint-disable-line
|
|
1404
|
-
const ttcTag: any = data.getString(4); //eslint-disable-line
|
|
1405
|
-
const majorVersion: number = data.getUnsignedInteger16();
|
|
1406
|
-
const minorVersion: number = data.getUnsignedInteger16();
|
|
1407
|
-
const numFonts: number = data.getInt32() >>> 0;
|
|
1408
|
-
const offsetTable: any = []; //eslint-disable-line
|
|
1409
|
-
for (let i: number = 0; i < numFonts; i++) {
|
|
1410
|
-
offsetTable.push(data.getInt32() >>> 0);
|
|
1411
|
-
}
|
|
1412
|
-
const header: any = {ttcTag, majorVersion, minorVersion, numFonts, offsetTable}; //eslint-disable-line
|
|
1413
|
-
switch (majorVersion) {
|
|
1414
|
-
case 1:
|
|
1415
|
-
return header;
|
|
1416
|
-
case 2:
|
|
1417
|
-
// header.dsigTag = ttc.getInt32() >>> 0;
|
|
1418
|
-
// header.dsigLength = ttc.getInt32() >>> 0;
|
|
1419
|
-
// header.dsigOffset = ttc.getInt32() >>> 0;
|
|
1420
|
-
return header;
|
|
1421
|
-
}
|
|
1422
|
-
throw new FormatError(`Invalid TrueType Collection majorVersion: ${majorVersion}.`);
|
|
1423
|
-
}
|
|
1424
|
-
_getString(length: number, file: any) { //eslint-disable-line
|
|
1425
|
-
return _bytesToString(file.getBytes(length));
|
|
1426
|
-
}
|
|
1427
|
-
_readOpenTypeHeader(ttf: any) { //eslint-disable-line
|
|
1428
|
-
return {version: this._getString(4, ttf), numTables: ttf.getUnsignedInteger16(), searchRange: ttf.getUnsignedInteger16(),
|
|
1429
|
-
entrySelector: ttf.getUnsignedInteger16(), rangeShift: ttf.getUnsignedInteger16()};
|
|
1430
|
-
}
|
|
1431
|
-
_readTables(file: any, numberOfTables: any) { //eslint-disable-line
|
|
1432
|
-
const tables: any = Object.create(null); //eslint-disable-line
|
|
1433
|
-
tables['OS/2'] = null;
|
|
1434
|
-
tables.cmap = null;
|
|
1435
|
-
tables.head = null;
|
|
1436
|
-
tables.hhea = null;
|
|
1437
|
-
tables.hmtx = null;
|
|
1438
|
-
tables.maxp = null;
|
|
1439
|
-
tables.name = null;
|
|
1440
|
-
tables.post = null;
|
|
1441
|
-
for (let i: number = 0; i < numberOfTables; i++) {
|
|
1442
|
-
const table: any = this._readTableEntry(file); //eslint-disable-line
|
|
1443
|
-
if (!this._validTables.includes(table.tag)) {
|
|
1444
|
-
continue;
|
|
1445
|
-
}
|
|
1446
|
-
if (table.length === 0) {
|
|
1447
|
-
continue;
|
|
1448
|
-
}
|
|
1449
|
-
tables[table.tag] = table;
|
|
1450
|
-
}
|
|
1451
|
-
return tables;
|
|
1452
|
-
}
|
|
1453
|
-
_readTableEntry(file: any) { //eslint-disable-line
|
|
1454
|
-
const tag: string = this._getString(4, file);
|
|
1455
|
-
const checksum: number = file.getInt32() >>> 0;
|
|
1456
|
-
const offset: number = file.getInt32() >>> 0;
|
|
1457
|
-
const length: number = file.getInt32() >>> 0;
|
|
1458
|
-
const previousPosition: number = file.position;
|
|
1459
|
-
file.pos = file.start || 0;
|
|
1460
|
-
file.position = file.pos;
|
|
1461
|
-
file.skip(offset);
|
|
1462
|
-
const data: any = file.getBytes(length); //eslint-disable-line
|
|
1463
|
-
file.pos = previousPosition;
|
|
1464
|
-
file.position = file.pos;
|
|
1465
|
-
if (tag === 'head') {
|
|
1466
|
-
data[8] = data[9] = data[10] = data[11] = 0;
|
|
1467
|
-
data[17] |= 0x20;
|
|
1468
|
-
}
|
|
1469
|
-
return {tag, checksum, length, offset, data};
|
|
1470
|
-
}
|
|
1471
|
-
_isMacNameRecord(r: any) { //eslint-disable-line
|
|
1472
|
-
return r.platform === 1 && r.encoding === 0 && r.language === 0;
|
|
1473
|
-
}
|
|
1474
|
-
_isWinNameRecord(r: any) { //eslint-disable-line
|
|
1475
|
-
return r.platform === 3 && r.encoding === 1 && r.language === 0x409;
|
|
1476
|
-
}
|
|
1477
|
-
_readNameTable(nameTable: any, font: any) { //eslint-disable-line
|
|
1478
|
-
const start: number = (font.start || 0) + nameTable.offset;
|
|
1479
|
-
font.pos = start;
|
|
1480
|
-
const names: any = [[], []], records: any = []; //eslint-disable-line
|
|
1481
|
-
const length: number = nameTable.length;
|
|
1482
|
-
const end: number = start + length;
|
|
1483
|
-
const format: number = font.getUnsignedInteger16();
|
|
1484
|
-
const FORMAT_0_HEADER_LENGTH: number = 6;
|
|
1485
|
-
if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) {
|
|
1486
|
-
return [names, records];
|
|
1487
|
-
}
|
|
1488
|
-
const numRecords: number = font.getUnsignedInteger16();
|
|
1489
|
-
const stringsStart: number = font.getUnsignedInteger16();
|
|
1490
|
-
const NAME_RECORD_LENGTH: number = 12;
|
|
1491
|
-
let i: number;
|
|
1492
|
-
let ii: number;
|
|
1493
|
-
for (i = 0; i < numRecords && font.pos + NAME_RECORD_LENGTH <= end; i++) {
|
|
1494
|
-
const r: any = {platform: font.getUnsignedInteger16(), encoding : font.getUnsignedInteger16(), language: font.getUnsignedInteger16(), name: font.getUnsignedInteger16(), //eslint-disable-line
|
|
1495
|
-
length: font.getUnsignedInteger16(), offset: font.getUnsignedInteger16()};
|
|
1496
|
-
if (this._isMacNameRecord(r) || this._isWinNameRecord(r)) {
|
|
1497
|
-
records.push(r);
|
|
1498
|
-
}
|
|
1499
|
-
}
|
|
1500
|
-
for (i = 0, ii = records.length; i < ii; i++) {
|
|
1501
|
-
const record: any = records[Number.parseInt(i.toString(), 10)]; //eslint-disable-line
|
|
1502
|
-
if (record.length <= 0) {
|
|
1503
|
-
continue;
|
|
1504
|
-
}
|
|
1505
|
-
const pos: number = start + stringsStart + record.offset;
|
|
1506
|
-
if (pos + record.length > end) {
|
|
1507
|
-
continue;
|
|
1508
|
-
}
|
|
1509
|
-
font.pos = pos;
|
|
1510
|
-
const nameIndex: any = record.name; //eslint-disable-line
|
|
1511
|
-
if (record.encoding) {
|
|
1512
|
-
let str: string = '';
|
|
1513
|
-
for (let j: number = 0, jj: number = record.length; j < jj; j += 2) {
|
|
1514
|
-
str += String.fromCharCode(font.getUnsignedInteger16());
|
|
1515
|
-
}
|
|
1516
|
-
names[1][Number.parseInt(nameIndex.toString(), 10)] = str;
|
|
1517
|
-
} else {
|
|
1518
|
-
names[0][Number.parseInt(nameIndex.toString(), 10)] = font.getString(record.length);
|
|
1519
|
-
}
|
|
1520
|
-
}
|
|
1521
|
-
return [names, records];
|
|
1522
|
-
}
|
|
1523
|
-
_readTrueTypeCollectionData(data: any, fontName: any, font: any) { //eslint-disable-line
|
|
1524
|
-
const { numFonts, offsetTable }: any = this._readTrueTypeCollectionHeader(data); //eslint-disable-line
|
|
1525
|
-
const fontNameParts: any = fontName.split('+'); //eslint-disable-line
|
|
1526
|
-
let fallbackData: any; //eslint-disable-line
|
|
1527
|
-
for (let i: number = 0; i < numFonts; i++) {
|
|
1528
|
-
data.pos = (data.start || 0) + offsetTable[Number.parseInt(i.toString(), 10)];
|
|
1529
|
-
const potentialHeader: any = this._readOpenTypeHeader(data); //eslint-disable-line
|
|
1530
|
-
const potentialTables: any = this._readTables(data, potentialHeader.numTables); //eslint-disable-line
|
|
1531
|
-
if (!potentialTables.name) {
|
|
1532
|
-
throw new FormatError('TrueType Collection font must contain a name table.');
|
|
1533
|
-
}
|
|
1534
|
-
const [nameTable] = this._readNameTable(potentialTables.name, font);
|
|
1535
|
-
for (let j: number = 0, jj: number = nameTable.length; j < jj; j++) {
|
|
1536
|
-
for (let k: number = 0, kk: number = nameTable[Number.parseInt(j.toString(), 10)].length; k < kk; k++) {
|
|
1537
|
-
const nameEntry: any = nameTable[Number.parseInt(j.toString(), 10)][Number.parseInt(k.toString(), 10)] && nameTable[Number.parseInt(j.toString(), 10)][Number.parseInt(k.toString(), 10)].replaceAll(/\s/g, ''); //eslint-disable-line
|
|
1538
|
-
if (!nameEntry) {
|
|
1539
|
-
continue;
|
|
1540
|
-
}
|
|
1541
|
-
if (nameEntry === fontName) {
|
|
1542
|
-
return {header: potentialHeader, tables: potentialTables};
|
|
1543
|
-
}
|
|
1544
|
-
if (fontNameParts.length < 2) {
|
|
1545
|
-
continue;
|
|
1546
|
-
}
|
|
1547
|
-
for (const part of fontNameParts) {
|
|
1548
|
-
if (nameEntry === part) {
|
|
1549
|
-
fallbackData = {name: part, header: potentialHeader, tables: potentialTables};
|
|
1550
|
-
}
|
|
1551
|
-
}
|
|
1552
|
-
}
|
|
1553
|
-
}
|
|
1554
|
-
}
|
|
1555
|
-
if (fallbackData) {
|
|
1556
|
-
return {header: fallbackData.header, tables: fallbackData.tables};
|
|
1557
|
-
}
|
|
1558
|
-
throw new FormatError(`TrueType Collection does not contain '${fontName}' font.`);
|
|
1559
|
-
}
|
|
1560
|
-
_int16(b0: any, b1: any) { //eslint-disable-line
|
|
1561
|
-
return (b0 << 8) + b1;
|
|
1562
|
-
}
|
|
1563
|
-
_checkAndRepair(font: any) : void { //eslint-disable-line
|
|
1564
|
-
font = new _PdfStream(new Uint8Array(font.getBytes()));
|
|
1565
|
-
let header: any; //eslint-disable-line
|
|
1566
|
-
let tables: any; //eslint-disable-line
|
|
1567
|
-
if (this._isTrueTypeCollectionFile(font)) {
|
|
1568
|
-
const ttcData: any = this._readTrueTypeCollectionData(font, this._fontStructure._name, font); //eslint-disable-line
|
|
1569
|
-
header = ttcData.header;
|
|
1570
|
-
tables = ttcData.tables;
|
|
1571
|
-
} else {
|
|
1572
|
-
header = this._readOpenTypeHeader(font);
|
|
1573
|
-
tables = this._readTables(font, header.numTables);
|
|
1574
|
-
}
|
|
1575
|
-
const isTrueType: boolean = !tables['compactFont '];
|
|
1576
|
-
if (!isTrueType) {
|
|
1577
|
-
const isComposite: boolean = this._fontStructure._composite && (this._characterIdToGlyphMap &&
|
|
1578
|
-
this._characterIdToGlyphMap.length > 0 || !(
|
|
1579
|
-
this._fontStructure._characterMap instanceof _PdfIdentityCharacterMap));
|
|
1580
|
-
if ((header.version === 'OTTO' && !isComposite) || !tables.head || !tables.hhea || !tables.maxp || !tables.post) {
|
|
1581
|
-
this._adjustWidths();
|
|
1582
|
-
}
|
|
1583
|
-
delete tables.glyf;
|
|
1584
|
-
delete tables.loca;
|
|
1585
|
-
delete tables.fpgm;
|
|
1586
|
-
delete tables.prep;
|
|
1587
|
-
delete tables['cvt '];
|
|
1588
|
-
this._isOpenType = true;
|
|
1589
|
-
} else {
|
|
1590
|
-
if (!tables.loca) {
|
|
1591
|
-
throw new FormatError('Required loca table is not found');
|
|
1592
|
-
}
|
|
1593
|
-
if (!tables.glyf) {
|
|
1594
|
-
tables.glyf = {tag: 'glyf', data: new Uint8Array(0)};
|
|
1595
|
-
}
|
|
1596
|
-
this._isOpenType = false;
|
|
1597
|
-
}
|
|
1598
|
-
if (!tables.maxp) {
|
|
1599
|
-
throw new FormatError('Required maxp table is not found');
|
|
1600
|
-
}
|
|
1601
|
-
font.pos = (font.start || 0) + tables.maxp.offset;
|
|
1602
|
-
font.position = font.pos;
|
|
1603
|
-
let version: number = font.getInt32();
|
|
1604
|
-
font.pos = font.position;
|
|
1605
|
-
const numGlyphs: number = font.getUnsignedInteger16();
|
|
1606
|
-
font.pos = font.position;
|
|
1607
|
-
if (version !== 0x00010000 && version !== 0x00005000) {
|
|
1608
|
-
if (tables.maxp.length === 6) {
|
|
1609
|
-
version = 0x0005000;
|
|
1610
|
-
} else if (tables.maxp.length >= 32) {
|
|
1611
|
-
version = 0x00010000;
|
|
1612
|
-
} else {
|
|
1613
|
-
throw new FormatError('maxp table has a wrong version number');
|
|
1614
|
-
}
|
|
1615
|
-
this._writeUnSignedInt32(tables.maxp.data, 0, version);
|
|
1616
|
-
}
|
|
1617
|
-
if (this._scaleFactors && this._scaleFactors.length === numGlyphs && isTrueType) {
|
|
1618
|
-
const { _scaleFactors } = this;
|
|
1619
|
-
const isGlyphLocationsLong: boolean = this._int16(tables.head.data[50], tables.head.data[51]);
|
|
1620
|
-
const glyphs: _PdfGlyphTable = new _PdfGlyphTable({glyfTable: tables.glyf.data, isGlyphLocationsLong, locaTable:
|
|
1621
|
-
tables.loca.data, numGlyphs});
|
|
1622
|
-
glyphs.scale(_scaleFactors);
|
|
1623
|
-
const { data, loca, isLocationLong } = glyphs._write();
|
|
1624
|
-
tables.glyf.data = data;
|
|
1625
|
-
tables.loca.data = loca;
|
|
1626
|
-
if (isLocationLong !== !!isGlyphLocationsLong) {
|
|
1627
|
-
tables.head.data[50] = 0;
|
|
1628
|
-
tables.head.data[51] = isLocationLong ? 1 : 0;
|
|
1629
|
-
}
|
|
1630
|
-
}
|
|
1631
|
-
if (!tables.hhea) {
|
|
1632
|
-
throw new FormatError('Required hhea table is not found');
|
|
1633
|
-
}
|
|
1634
|
-
if (tables.hhea.data[10] === 0 && tables.hhea.data[11] === 0) {
|
|
1635
|
-
tables.hhea.data[10] = 0xff;
|
|
1636
|
-
tables.hhea.data[11] = 0xff;
|
|
1637
|
-
}
|
|
1638
|
-
const metricsOverride: any = {unitsPerEm: this._int16(tables.head.data[18], tables.head.data[19]), //eslint-disable-line
|
|
1639
|
-
yMax: this._signedInt16(tables.head.data[42], tables.head.data[43]),
|
|
1640
|
-
yMin: this._signedInt16(tables.head.data[38], tables.head.data[39]),
|
|
1641
|
-
ascent: this._signedInt16(tables.hhea.data[4], tables.hhea.data[5]),
|
|
1642
|
-
descent: this._signedInt16(tables.hhea.data[6], tables.hhea.data[7]),
|
|
1643
|
-
lineGap: this._signedInt16(tables.hhea.data[8], tables.hhea.data[9])
|
|
1644
|
-
};
|
|
1645
|
-
this._fontStructure._ascent = metricsOverride.ascent / metricsOverride.unitsPerEm;
|
|
1646
|
-
this._fontStructure._descent = metricsOverride.descent / metricsOverride.unitsPerEm;
|
|
1647
|
-
this._fontStructure._lineGap = metricsOverride.lineGap / metricsOverride.unitsPerEm;
|
|
1648
|
-
if (this._fontStructure._cssFontInfo && this._fontStructure._cssFontInfo.lineHeight) {
|
|
1649
|
-
this._fontStructure._lineHeight = this._fontStructure._cssFontInfo.metrics.lineHeight;
|
|
1650
|
-
this._fontStructure._lineGap = this._fontStructure._cssFontInfo.metrics.lineGap;
|
|
1651
|
-
} else {
|
|
1652
|
-
this._fontStructure._lineHeight = this._fontStructure._ascent - this._fontStructure._descent + this._fontStructure._lineGap;
|
|
1653
|
-
}
|
|
1654
|
-
if (tables.name) {
|
|
1655
|
-
const [namePrototype, nameRecords] = this._readNameTable(tables.name, font);
|
|
1656
|
-
this._fontStructure._psName = namePrototype[0][6] || null;
|
|
1657
|
-
if (!this._fontStructure._composite) {
|
|
1658
|
-
this._adjustTrueTypeToUnicode(this._fontStructure, this._fontStructure._isSymbolicFont, nameRecords);
|
|
1659
|
-
}
|
|
1660
|
-
}
|
|
1661
|
-
}
|
|
1662
|
-
_adjustType1ToUnicode() { //eslint-disable-line
|
|
1663
|
-
if (this._fontStructure._isInternalFont) {
|
|
1664
|
-
return;
|
|
1665
|
-
}
|
|
1666
|
-
if (this._hasIncludedToUnicodeMap) {
|
|
1667
|
-
return;
|
|
1668
|
-
}
|
|
1669
|
-
if (this._fontStructure._builtInEncoding === this._fontStructure._defaultEncoding) {
|
|
1670
|
-
return;
|
|
1671
|
-
}
|
|
1672
|
-
if (this._fontStructure._toUnicode instanceof _PdfIdentityToUnicodeMap) {
|
|
1673
|
-
return;
|
|
1674
|
-
}
|
|
1675
|
-
const toUnicode: any = []; //eslint-disable-line
|
|
1676
|
-
const glyphsUnicodeMap: any = _getGlyphsUnicode(); //eslint-disable-line
|
|
1677
|
-
const keys: any = Object.keys(this._fontStructure._builtInEncoding); //eslint-disable-line
|
|
1678
|
-
for (let i: number = 0; i < keys.length; i++) {
|
|
1679
|
-
const charCode: any = keys[Number.parseInt(i.toString(), 10)]; //eslint-disable-line
|
|
1680
|
-
if (this._hasEncoding) {
|
|
1681
|
-
if (this._baseEncodingName || this._fontStructure._differences[Number.parseInt(charCode.toString(), 10)] !== undefined) {
|
|
1682
|
-
continue;
|
|
1683
|
-
}
|
|
1684
|
-
}
|
|
1685
|
-
const glyphName: any = this._fontStructure._builtInEncoding[Number.parseInt(charCode.toString(), 10)]; //eslint-disable-line
|
|
1686
|
-
const unicode: any = _getUnicodeForGlyph(glyphName, glyphsUnicodeMap); //eslint-disable-line
|
|
1687
|
-
if (unicode !== -1) {
|
|
1688
|
-
toUnicode[Number.parseInt(charCode.toString(), 10)] = String.fromCharCode(unicode);
|
|
1689
|
-
}
|
|
1690
|
-
}
|
|
1691
|
-
if (toUnicode.length > 0) {
|
|
1692
|
-
this._fontStructure._toUnicode._amend(toUnicode);
|
|
1693
|
-
}
|
|
1694
|
-
}
|
|
1695
|
-
_adjustTrueTypeToUnicode(properties: any, isSymbolicFont: any, nameRecords: any) { //eslint-disable-line
|
|
1696
|
-
if (properties._isInternalFont) {
|
|
1697
|
-
return;
|
|
1698
|
-
}
|
|
1699
|
-
if (this._hasIncludedToUnicodeMap) {
|
|
1700
|
-
return;
|
|
1701
|
-
}
|
|
1702
|
-
if (this._hasEncoding) {
|
|
1703
|
-
return;
|
|
1704
|
-
}
|
|
1705
|
-
if (properties._toUnicode instanceof _PdfIdentityToUnicodeMap) {
|
|
1706
|
-
return;
|
|
1707
|
-
}
|
|
1708
|
-
if (!isSymbolicFont) {
|
|
1709
|
-
return;
|
|
1710
|
-
}
|
|
1711
|
-
if (nameRecords.length === 0) {
|
|
1712
|
-
return;
|
|
1713
|
-
}
|
|
1714
|
-
if (properties._defaultEncoding === _winAnsiEncoding) {
|
|
1715
|
-
return;
|
|
1716
|
-
}
|
|
1717
|
-
for (const r of nameRecords) {
|
|
1718
|
-
if (!this._isWinNameRecord(r)) {
|
|
1719
|
-
return;
|
|
1720
|
-
}
|
|
1721
|
-
}
|
|
1722
|
-
const encoding: string[] = _winAnsiEncoding;
|
|
1723
|
-
const toUnicode: any= []; //eslint-disable-line
|
|
1724
|
-
const glyphsUnicodeMap: any = _getGlyphsUnicode(); //eslint-disable-line
|
|
1725
|
-
const keys: any = Object.keys(encoding); //eslint-disable-line
|
|
1726
|
-
for (let i: number = 0; i < keys.length; i++) {
|
|
1727
|
-
const charCode: any = keys[Number.parseInt(i.toString(), 10)]; //eslint-disable-line
|
|
1728
|
-
const glyphName: any = encoding[Number.parseInt(charCode.toString(), 10)]; //eslint-disable-line
|
|
1729
|
-
if (glyphName === '') {
|
|
1730
|
-
continue;
|
|
1731
|
-
}
|
|
1732
|
-
const unicode: any = glyphsUnicodeMap[Number.parseInt(glyphName.toString(), 10)]; //eslint-disable-line
|
|
1733
|
-
if (unicode === undefined) {
|
|
1734
|
-
continue;
|
|
1735
|
-
}
|
|
1736
|
-
toUnicode[Number.parseInt(charCode.toString(), 10)] = String.fromCharCode(unicode);
|
|
1737
|
-
}
|
|
1738
|
-
if (toUnicode.length > 0) {
|
|
1739
|
-
properties._toUnicode._amend(toUnicode);
|
|
1740
|
-
}
|
|
1741
|
-
}
|
|
1742
|
-
}
|
|
1743
|
-
export class _Glyph {
|
|
1744
|
-
_unicode: string;
|
|
1745
|
-
_accent: number;
|
|
1746
|
-
_width: number;
|
|
1747
|
-
_fontCharacter: string;
|
|
1748
|
-
_verticalMetrics: any; //eslint-disable-line
|
|
1749
|
-
_isSpace: boolean;
|
|
1750
|
-
_isInFont: boolean;
|
|
1751
|
-
constructor(unicode: string, accent: any, width: number, _verticalMetrics: any, //eslint-disable-line
|
|
1752
|
-
isSpace: boolean, isInFont: boolean) {
|
|
1753
|
-
this._unicode = unicode;
|
|
1754
|
-
this._accent = accent;
|
|
1755
|
-
this._width = width;
|
|
1756
|
-
this._verticalMetrics = _verticalMetrics;
|
|
1757
|
-
this._isSpace = isSpace;
|
|
1758
|
-
this._isInFont = isInFont;
|
|
1759
|
-
}
|
|
1760
|
-
}
|
|
1761
|
-
class _ToUnicodeMap {
|
|
1762
|
-
_map: (number | string)[];
|
|
1763
|
-
constructor(cmap: any) { //eslint-disable-line
|
|
1764
|
-
this._map = cmap;
|
|
1765
|
-
}
|
|
1766
|
-
get _length(): number {
|
|
1767
|
-
return this._map.length;
|
|
1768
|
-
}
|
|
1769
|
-
_forEach(): { characterCode: number; unicode: number }[] {
|
|
1770
|
-
const results: { characterCode: number; unicode: number }[] = [];
|
|
1771
|
-
const keys: any = Object.keys(this._map); //eslint-disable-line
|
|
1772
|
-
for (let i: number = 0; i < keys.length; i++) {
|
|
1773
|
-
const charCode: any = keys[Number.parseInt(i.toString(), 10)]; //eslint-disable-line
|
|
1774
|
-
const unicodeValue: any = this._map[Number.parseInt(charCode, 10)]; //eslint-disable-line
|
|
1775
|
-
if (unicodeValue) {
|
|
1776
|
-
results.push({
|
|
1777
|
-
characterCode: Number.parseInt(charCode, 10),
|
|
1778
|
-
unicode: (unicodeValue as string).charCodeAt(0)
|
|
1779
|
-
});
|
|
1780
|
-
}
|
|
1781
|
-
}
|
|
1782
|
-
return results;
|
|
1783
|
-
}
|
|
1784
|
-
_has(i: number): boolean {
|
|
1785
|
-
return typeof(this._map[Number.parseInt(i.toString(), 10)]) !== 'undefined';
|
|
1786
|
-
}
|
|
1787
|
-
_get(i: number): any { //eslint-disable-line
|
|
1788
|
-
return this._map[Number.parseInt(i.toString(), 10)];
|
|
1789
|
-
}
|
|
1790
|
-
_charCodeOf(value: string | number): number {
|
|
1791
|
-
const map: any = this._map; //eslint-disable-line
|
|
1792
|
-
if (map.length <= 0x10000) {
|
|
1793
|
-
return map.indexOf(value);
|
|
1794
|
-
}
|
|
1795
|
-
const keys: any = Object.keys(map); //eslint-disable-line
|
|
1796
|
-
for (let i: number = 0; i < keys.length; i++) {
|
|
1797
|
-
const charCode: any = keys[Number.parseInt(i.toString(), 10)]; //eslint-disable-line
|
|
1798
|
-
if (map[Number.parseInt(charCode.toString(), 10)] === value) {
|
|
1799
|
-
return Number.parseInt(charCode.toString(), 10);
|
|
1800
|
-
}
|
|
1801
|
-
}
|
|
1802
|
-
return -1;
|
|
1803
|
-
}
|
|
1804
|
-
_amend(map: { [key: number]: string | number }): void {
|
|
1805
|
-
const keys: any = Object.keys(map); //eslint-disable-line
|
|
1806
|
-
for (let i: number = 0; i < keys.length; i++) {
|
|
1807
|
-
const charCode: any = keys[Number.parseInt(i.toString(), 10)]; //eslint-disable-line
|
|
1808
|
-
this._map[Number.parseInt(charCode.toString(), 10)] = map[Number.parseInt(charCode.toString(), 10)];
|
|
1809
|
-
}
|
|
1810
|
-
}
|
|
1811
|
-
}
|
|
1812
|
-
class _PdfIdentityToUnicodeMap {
|
|
1813
|
-
_firstChar: number;
|
|
1814
|
-
_lastChar: number;
|
|
1815
|
-
constructor(firstChar: number, lastChar: number) {
|
|
1816
|
-
this._firstChar = firstChar;
|
|
1817
|
-
this._lastChar = lastChar;
|
|
1818
|
-
}
|
|
1819
|
-
get _length(): number {
|
|
1820
|
-
return this._lastChar + 1 - this._firstChar;
|
|
1821
|
-
}
|
|
1822
|
-
_forEach(callback: (charCode: number, unicode: number) => void): void {
|
|
1823
|
-
for (let i: number = this._firstChar, ii: number = this._lastChar; i <= ii; i++) {
|
|
1824
|
-
callback(i, i);
|
|
1825
|
-
}
|
|
1826
|
-
}
|
|
1827
|
-
_has(index: number): boolean {
|
|
1828
|
-
return this._firstChar <= index && index <= this._lastChar;
|
|
1829
|
-
}
|
|
1830
|
-
_get(index: number): string | undefined {
|
|
1831
|
-
if (this._firstChar <= index && index <= this._lastChar) {
|
|
1832
|
-
return String.fromCharCode(index);
|
|
1833
|
-
}
|
|
1834
|
-
return undefined;
|
|
1835
|
-
}
|
|
1836
|
-
_charCodeOf(v: number): number {
|
|
1837
|
-
return Number.isInteger(v) && v >= this._firstChar && v <= this._lastChar ? v : -1;
|
|
1838
|
-
}
|
|
1839
|
-
_amend(): void {
|
|
1840
|
-
throw new Error('Should not call amend()');
|
|
1841
|
-
}
|
|
1842
|
-
}
|