pdf-parser.js 5.2.26 → 5.2.28
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/{afm-widths-BYiX2L9D.cjs → afm-widths-BHD2HZIL.cjs} +553 -642
- package/dist/{afm-widths-blUDDjlI.js → afm-widths-B_IGbGky.js} +553 -642
- package/dist/afm-widths.cjs +1 -1
- package/dist/afm-widths.js +1 -1
- package/dist/annotations.cjs +5 -3
- package/dist/annotations.d.cts +2 -2
- package/dist/annotations.d.ts +2 -2
- package/dist/annotations.js +5 -3
- package/dist/attachments.d.cts +2 -2
- package/dist/attachments.d.ts +2 -2
- package/dist/builtin-encoding.cjs +17 -6
- package/dist/builtin-encoding.js +17 -6
- package/dist/bytes/crc32.cjs +5 -3
- package/dist/bytes/crc32.js +5 -3
- package/dist/bytes/flate.cjs +0 -1
- package/dist/bytes/flate.js +0 -1
- package/dist/cff-bounds.cjs +73 -45
- package/dist/cff-bounds.js +73 -45
- package/dist/cff.cjs +13 -6
- package/dist/cff.js +13 -6
- package/dist/cmap-table.cjs +54 -26
- package/dist/cmap-table.js +54 -26
- package/dist/cmap.cjs +5 -3
- package/dist/cmap.js +5 -3
- package/dist/content-read.d.cts +1 -1
- package/dist/content-read.d.ts +1 -1
- package/dist/content-write.cjs +21 -14
- package/dist/content-write.d.cts +2 -2
- package/dist/content-write.d.ts +2 -2
- package/dist/content-write.js +21 -14
- package/dist/crypto/aes.cjs +76 -55
- package/dist/crypto/aes.js +76 -55
- package/dist/crypto/md5.cjs +345 -149
- package/dist/crypto/md5.js +345 -149
- package/dist/crypto/rc4.cjs +5 -4
- package/dist/crypto/rc4.js +5 -4
- package/dist/crypto/sha2.cjs +92 -43
- package/dist/crypto/sha2.js +92 -43
- package/dist/document.cjs +17 -11
- package/dist/document.d.cts +1 -1
- package/dist/document.d.ts +1 -1
- package/dist/document.js +17 -11
- package/dist/{embedded-font-Bnhh4juV.d.ts → embedded-font-ByD7ZiQS.d.ts} +1 -1
- package/dist/{embedded-font-CEf-zBCA.d.cts → embedded-font-DgVBedw6.d.cts} +1 -1
- package/dist/embedded-font-write.d.cts +2 -2
- package/dist/embedded-font-write.d.ts +2 -2
- package/dist/embedded-font.cjs +4 -2
- package/dist/embedded-font.d.cts +1 -1
- package/dist/embedded-font.d.ts +1 -1
- package/dist/embedded-font.js +4 -2
- package/dist/encoding.cjs +1 -1
- package/dist/encoding.js +1 -1
- package/dist/encrypt-write.cjs +25 -21
- package/dist/encrypt-write.d.cts +1 -1
- package/dist/encrypt-write.d.ts +1 -1
- package/dist/encrypt-write.js +25 -21
- package/dist/encrypt.cjs +43 -64
- package/dist/encrypt.d.cts +1 -1
- package/dist/encrypt.d.ts +1 -1
- package/dist/encrypt.js +43 -64
- package/dist/filters.cjs +46 -26
- package/dist/filters.d.cts +1 -1
- package/dist/filters.d.ts +1 -1
- package/dist/filters.js +46 -26
- package/dist/font-face.cjs +2 -1
- package/dist/font-face.js +2 -1
- package/dist/font-read.cjs +12 -6
- package/dist/font-read.d.cts +1 -1
- package/dist/font-read.d.ts +1 -1
- package/dist/font-read.js +12 -6
- package/dist/font-registry.d.cts +3 -3
- package/dist/font-registry.d.ts +3 -3
- package/dist/font-tables.cjs +55 -28
- package/dist/font-tables.js +55 -28
- package/dist/form.cjs +13 -8
- package/dist/form.d.cts +2 -2
- package/dist/form.d.ts +2 -2
- package/dist/form.js +13 -8
- package/dist/gdef-table.cjs +6 -3
- package/dist/gdef-table.js +6 -3
- package/dist/{glyf-contours-C0epBNqP.d.ts → glyf-contours-B1PsI9oA.d.ts} +1 -1
- package/dist/{glyf-contours-BRpvd0rt.d.cts → glyf-contours-NHBpgks-.d.cts} +1 -1
- package/dist/glyf-contours.cjs +3 -1
- package/dist/glyf-contours.d.cts +1 -1
- package/dist/glyf-contours.d.ts +1 -1
- package/dist/glyf-contours.js +3 -1
- package/dist/glyf.cjs +22 -11
- package/dist/glyf.js +22 -11
- package/dist/gpos-table.cjs +37 -19
- package/dist/gpos-table.js +37 -19
- package/dist/gsub-table.cjs +40 -25
- package/dist/gsub-table.js +40 -25
- package/dist/hmtx-table.cjs +5 -3
- package/dist/hmtx-table.js +5 -3
- package/dist/image/ccitt-encode.cjs +8 -5
- package/dist/image/ccitt-encode.js +8 -5
- package/dist/image/ccitt.cjs +801 -209
- package/dist/image/ccitt.js +801 -209
- package/dist/image/jbig2-arith.cjs +340 -306
- package/dist/image/jbig2-arith.js +340 -306
- package/dist/image/jbig2-bitmap.cjs +8 -5
- package/dist/image/jbig2-bitmap.js +8 -5
- package/dist/image/jbig2-generic.cjs +240 -69
- package/dist/image/jbig2-generic.js +240 -69
- package/dist/image/jbig2-text.cjs +4 -2
- package/dist/image/jbig2-text.js +4 -2
- package/dist/image/jbig2.cjs +69 -31
- package/dist/image/jbig2.js +69 -31
- package/dist/image/jp2-boxes.cjs +52 -27
- package/dist/image/jp2-boxes.js +52 -27
- package/dist/image/jpeg-info.cjs +29 -24
- package/dist/image/jpeg-info.js +29 -24
- package/dist/image/jpeg2000-codestream.cjs +61 -32
- package/dist/image/jpeg2000-codestream.js +61 -32
- package/dist/image/jpeg2000-dwt.cjs +2 -1
- package/dist/image/jpeg2000-dwt.js +2 -1
- package/dist/image/jpeg2000-t1.cjs +21 -11
- package/dist/image/jpeg2000-t1.js +21 -11
- package/dist/image/jpeg2000-t2.cjs +12 -5
- package/dist/image/jpeg2000-t2.js +12 -5
- package/dist/image/jpeg2000-tagtree.cjs +8 -4
- package/dist/image/jpeg2000-tagtree.js +8 -4
- package/dist/image/jpeg2000.cjs +11 -6
- package/dist/image/jpeg2000.js +11 -6
- package/dist/image/png-decode.cjs +62 -39
- package/dist/image/png-decode.d.cts +3 -2
- package/dist/image/png-decode.d.ts +3 -2
- package/dist/image/png-decode.js +62 -39
- package/dist/image/png-filter.cjs +23 -15
- package/dist/image/png-filter.js +23 -15
- package/dist/images-read.cjs +41 -36
- package/dist/images-read.d.cts +2 -2
- package/dist/images-read.d.ts +2 -2
- package/dist/images-read.js +41 -36
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/interpret.cjs +68 -40
- package/dist/interpret.d.cts +1 -1
- package/dist/interpret.d.ts +1 -1
- package/dist/interpret.js +68 -40
- package/dist/lexer.cjs +86 -51
- package/dist/lexer.js +86 -51
- package/dist/math-content-write.cjs +9 -5
- package/dist/math-content-write.js +9 -5
- package/dist/math-font-write.cjs +2 -1
- package/dist/math-font-write.d.cts +1 -1
- package/dist/math-font-write.d.ts +1 -1
- package/dist/math-font-write.js +2 -1
- package/dist/math-font.cjs +16 -7
- package/dist/math-font.js +16 -7
- package/dist/math-table.cjs +25 -13
- package/dist/math-table.js +25 -13
- package/dist/matrix.cjs +3 -2
- package/dist/matrix.js +3 -2
- package/dist/measure.cjs +1 -1
- package/dist/measure.js +1 -1
- package/dist/names.cjs +7 -7
- package/dist/names.d.cts +2 -2
- package/dist/names.d.ts +2 -2
- package/dist/names.js +7 -7
- package/dist/navigation.cjs +16 -12
- package/dist/navigation.d.cts +4 -4
- package/dist/navigation.d.ts +4 -4
- package/dist/navigation.js +16 -12
- package/dist/{objects-B7HdMeWS.d.cts → objects-e2RS3-yT.d.cts} +3 -3
- package/dist/{objects-B7HdMeWS.d.ts → objects-e2RS3-yT.d.ts} +3 -3
- package/dist/objects.d.cts +1 -1
- package/dist/objects.d.ts +1 -1
- package/dist/optional-content.d.cts +2 -2
- package/dist/optional-content.d.ts +2 -2
- package/dist/ot-layout-common.cjs +22 -15
- package/dist/ot-layout-common.js +22 -15
- package/dist/parse.cjs +7 -5
- package/dist/parse.d.cts +1 -1
- package/dist/parse.d.ts +1 -1
- package/dist/parse.js +7 -5
- package/dist/pdf-text.cjs +5 -2
- package/dist/pdf-text.js +5 -2
- package/dist/predictors.cjs +14 -9
- package/dist/predictors.d.cts +1 -1
- package/dist/predictors.d.ts +1 -1
- package/dist/predictors.js +14 -9
- package/dist/raster.cjs +30 -19
- package/dist/raster.d.cts +8 -8
- package/dist/raster.d.ts +8 -8
- package/dist/raster.js +30 -19
- package/dist/read.cjs +29 -16
- package/dist/read.js +29 -16
- package/dist/serialize.cjs +6 -2
- package/dist/serialize.d.cts +1 -1
- package/dist/serialize.d.ts +1 -1
- package/dist/serialize.js +6 -2
- package/dist/sfnt-subset.cjs +25 -13
- package/dist/sfnt-subset.d.cts +1 -1
- package/dist/sfnt-subset.d.ts +1 -1
- package/dist/sfnt-subset.js +25 -13
- package/dist/sfnt.cjs +20 -10
- package/dist/sfnt.js +20 -10
- package/dist/structure.d.cts +2 -2
- package/dist/structure.d.ts +2 -2
- package/dist/text-group.cjs +0 -1
- package/dist/text-group.js +0 -1
- package/dist/text-layout.d.cts +1 -1
- package/dist/text-layout.d.ts +1 -1
- package/dist/tounicode.cjs +4 -2
- package/dist/tounicode.d.cts +1 -1
- package/dist/tounicode.d.ts +1 -1
- package/dist/tounicode.js +4 -2
- package/dist/winansi.cjs +1 -1
- package/dist/winansi.js +1 -1
- package/dist/write.cjs +20 -12
- package/dist/write.d.cts +1 -1
- package/dist/write.d.ts +1 -1
- package/dist/write.js +20 -12
- package/dist/xref.cjs +5 -2
- package/dist/xref.d.cts +1 -1
- package/dist/xref.d.ts +1 -1
- package/dist/xref.js +5 -2
- package/package.json +1 -1
package/dist/font-tables.cjs
CHANGED
|
@@ -5,35 +5,53 @@ const HEAD_TABLE_SIZE = 54;
|
|
|
5
5
|
const HEAD_MAGIC_NUMBER = 1594834165;
|
|
6
6
|
const MIN_UNITS_PER_EM = 16;
|
|
7
7
|
const MAX_UNITS_PER_EM = 16384;
|
|
8
|
+
const HEAD_CHECKSUM_ADJUSTMENT_OFFSET = 8;
|
|
9
|
+
const HEAD_MAGIC_NUMBER_OFFSET = 12;
|
|
10
|
+
const HEAD_UNITS_PER_EM_OFFSET = 18;
|
|
11
|
+
const HEAD_X_MIN_OFFSET = 36;
|
|
12
|
+
const HEAD_Y_MIN_OFFSET = 38;
|
|
13
|
+
const HEAD_X_MAX_OFFSET = 40;
|
|
14
|
+
const HEAD_Y_MAX_OFFSET = 42;
|
|
15
|
+
const HEAD_MAC_STYLE_OFFSET = 44;
|
|
16
|
+
const HEAD_INDEX_TO_LOC_FORMAT_OFFSET = 50;
|
|
8
17
|
function parseHead(font) {
|
|
9
18
|
const bytes = require_sfnt.sfntTableBytes(font, "head");
|
|
10
19
|
if (bytes === void 0 || !require_sfnt.hasBytes(bytes, 0, HEAD_TABLE_SIZE)) return;
|
|
11
|
-
if (require_sfnt.u32(bytes,
|
|
12
|
-
const unitsPerEm = require_sfnt.u16(bytes,
|
|
20
|
+
if (require_sfnt.u32(bytes, HEAD_MAGIC_NUMBER_OFFSET) !== HEAD_MAGIC_NUMBER) return;
|
|
21
|
+
const unitsPerEm = require_sfnt.u16(bytes, HEAD_UNITS_PER_EM_OFFSET);
|
|
13
22
|
if (unitsPerEm < MIN_UNITS_PER_EM || unitsPerEm > MAX_UNITS_PER_EM) return;
|
|
14
|
-
const indexToLocFormat = require_sfnt.i16(bytes,
|
|
23
|
+
const indexToLocFormat = require_sfnt.i16(bytes, HEAD_INDEX_TO_LOC_FORMAT_OFFSET);
|
|
15
24
|
if (indexToLocFormat !== 0 && indexToLocFormat !== 1) return;
|
|
16
25
|
return {
|
|
17
26
|
unitsPerEm,
|
|
18
|
-
checkSumAdjustment: require_sfnt.u32(bytes,
|
|
19
|
-
xMin: require_sfnt.i16(bytes,
|
|
20
|
-
yMin: require_sfnt.i16(bytes,
|
|
21
|
-
xMax: require_sfnt.i16(bytes,
|
|
22
|
-
yMax: require_sfnt.i16(bytes,
|
|
27
|
+
checkSumAdjustment: require_sfnt.u32(bytes, HEAD_CHECKSUM_ADJUSTMENT_OFFSET),
|
|
28
|
+
xMin: require_sfnt.i16(bytes, HEAD_X_MIN_OFFSET),
|
|
29
|
+
yMin: require_sfnt.i16(bytes, HEAD_Y_MIN_OFFSET),
|
|
30
|
+
xMax: require_sfnt.i16(bytes, HEAD_X_MAX_OFFSET),
|
|
31
|
+
yMax: require_sfnt.i16(bytes, HEAD_Y_MAX_OFFSET),
|
|
23
32
|
indexToLocFormat,
|
|
24
|
-
macStyle: require_sfnt.u16(bytes,
|
|
33
|
+
macStyle: require_sfnt.u16(bytes, HEAD_MAC_STYLE_OFFSET)
|
|
25
34
|
};
|
|
26
35
|
}
|
|
27
36
|
const MAXP_HEADER_SIZE = 6;
|
|
37
|
+
const MAXP_NUM_GLYPHS_OFFSET = 4;
|
|
28
38
|
function parseMaxp(font) {
|
|
29
39
|
const bytes = require_sfnt.sfntTableBytes(font, "maxp");
|
|
30
40
|
if (bytes === void 0 || !require_sfnt.hasBytes(bytes, 0, MAXP_HEADER_SIZE)) return;
|
|
31
|
-
return { numGlyphs: require_sfnt.u16(bytes,
|
|
41
|
+
return { numGlyphs: require_sfnt.u16(bytes, MAXP_NUM_GLYPHS_OFFSET) };
|
|
32
42
|
}
|
|
33
43
|
const OS2_VERSION_0_SIZE = 78;
|
|
34
44
|
const OS2_VERSION_2_SIZE = 96;
|
|
35
45
|
const OS2_VERSION_WITH_HEIGHTS = 2;
|
|
36
46
|
const OS2_PANOSE_OFFSET = 32;
|
|
47
|
+
const OS2_FS_SELECTION_OFFSET = 62;
|
|
48
|
+
const OS2_S_TYPO_ASCENDER_OFFSET = 68;
|
|
49
|
+
const OS2_S_TYPO_DESCENDER_OFFSET = 70;
|
|
50
|
+
const OS2_S_TYPO_LINE_GAP_OFFSET = 72;
|
|
51
|
+
const OS2_US_WIN_ASCENT_OFFSET = 74;
|
|
52
|
+
const OS2_US_WIN_DESCENT_OFFSET = 76;
|
|
53
|
+
const OS2_SX_HEIGHT_OFFSET = 86;
|
|
54
|
+
const OS2_S_CAP_HEIGHT_OFFSET = 88;
|
|
37
55
|
function parseOs2(font) {
|
|
38
56
|
const bytes = require_sfnt.sfntTableBytes(font, "OS/2");
|
|
39
57
|
if (bytes === void 0 || !require_sfnt.hasBytes(bytes, 0, OS2_VERSION_0_SIZE)) return;
|
|
@@ -41,27 +59,30 @@ function parseOs2(font) {
|
|
|
41
59
|
const hasHeights = version >= OS2_VERSION_WITH_HEIGHTS && require_sfnt.hasBytes(bytes, 0, OS2_VERSION_2_SIZE);
|
|
42
60
|
return {
|
|
43
61
|
version,
|
|
44
|
-
fsSelection: require_sfnt.u16(bytes,
|
|
62
|
+
fsSelection: require_sfnt.u16(bytes, OS2_FS_SELECTION_OFFSET),
|
|
45
63
|
panose: [...bytes.subarray(OS2_PANOSE_OFFSET, 42)],
|
|
46
|
-
sTypoAscender: require_sfnt.i16(bytes,
|
|
47
|
-
sTypoDescender: require_sfnt.i16(bytes,
|
|
48
|
-
sTypoLineGap: require_sfnt.i16(bytes,
|
|
49
|
-
usWinAscent: require_sfnt.u16(bytes,
|
|
50
|
-
usWinDescent: require_sfnt.u16(bytes,
|
|
51
|
-
sxHeight: hasHeights ? require_sfnt.i16(bytes,
|
|
52
|
-
sCapHeight: hasHeights ? require_sfnt.i16(bytes,
|
|
64
|
+
sTypoAscender: require_sfnt.i16(bytes, OS2_S_TYPO_ASCENDER_OFFSET),
|
|
65
|
+
sTypoDescender: require_sfnt.i16(bytes, OS2_S_TYPO_DESCENDER_OFFSET),
|
|
66
|
+
sTypoLineGap: require_sfnt.i16(bytes, OS2_S_TYPO_LINE_GAP_OFFSET),
|
|
67
|
+
usWinAscent: require_sfnt.u16(bytes, OS2_US_WIN_ASCENT_OFFSET),
|
|
68
|
+
usWinDescent: require_sfnt.u16(bytes, OS2_US_WIN_DESCENT_OFFSET),
|
|
69
|
+
sxHeight: hasHeights ? require_sfnt.i16(bytes, OS2_SX_HEIGHT_OFFSET) : void 0,
|
|
70
|
+
sCapHeight: hasHeights ? require_sfnt.i16(bytes, OS2_S_CAP_HEIGHT_OFFSET) : void 0
|
|
53
71
|
};
|
|
54
72
|
}
|
|
55
73
|
const POST_HEADER_SIZE = 32;
|
|
56
74
|
const FIXED_16_16_SCALE = 65536;
|
|
75
|
+
const POST_ITALIC_ANGLE_OFFSET = 4;
|
|
76
|
+
const POST_UNDERLINE_POSITION_OFFSET = 8;
|
|
77
|
+
const POST_UNDERLINE_THICKNESS_OFFSET = 10;
|
|
57
78
|
function parsePost(font) {
|
|
58
79
|
const bytes = require_sfnt.sfntTableBytes(font, "post");
|
|
59
80
|
if (bytes === void 0 || !require_sfnt.hasBytes(bytes, 0, POST_HEADER_SIZE)) return;
|
|
60
81
|
return {
|
|
61
82
|
version: require_sfnt.u32(bytes, 0),
|
|
62
|
-
italicAngle: require_sfnt.i32(bytes,
|
|
63
|
-
underlinePosition: require_sfnt.i16(bytes,
|
|
64
|
-
underlineThickness: require_sfnt.i16(bytes,
|
|
83
|
+
italicAngle: require_sfnt.i32(bytes, POST_ITALIC_ANGLE_OFFSET) / FIXED_16_16_SCALE,
|
|
84
|
+
underlinePosition: require_sfnt.i16(bytes, POST_UNDERLINE_POSITION_OFFSET),
|
|
85
|
+
underlineThickness: require_sfnt.i16(bytes, POST_UNDERLINE_THICKNESS_OFFSET)
|
|
65
86
|
};
|
|
66
87
|
}
|
|
67
88
|
const MAC_STANDARD_GLYPH_ORDER = ".notdef .null nonmarkingreturn space exclam quotedbl numbersign dollar percent ampersand quotesingle parenleft parenright asterisk plus comma hyphen period slash zero one two three four five six seven eight nine colon semicolon less equal greater question at A B C D E F G H I J K L M N O P Q R S T U V W X Y Z bracketleft backslash bracketright asciicircum underscore grave a b c d e f g h i j k l m n o p q r s t u v w x y z braceleft bar braceright asciitilde Adieresis Aring Ccedilla Eacute Ntilde Odieresis Udieresis aacute agrave acircumflex adieresis atilde aring ccedilla eacute egrave ecircumflex edieresis iacute igrave icircumflex idieresis ntilde oacute ograve ocircumflex odieresis otilde uacute ugrave ucircumflex udieresis dagger degree cent sterling section bullet paragraph germandbls registered copyright trademark acute dieresis notequal AE Oslash infinity plusminus lessequal greaterequal yen mu partialdiff summation product pi integral ordfeminine ordmasculine Omega ae oslash questiondown exclamdown logicalnot radical florin approxequal Delta guillemotleft guillemotright ellipsis nonbreakingspace Agrave Atilde Otilde OE oe endash emdash quotedblleft quotedblright quoteleft quoteright divide lozenge ydieresis Ydieresis fraction currency guilsinglleft guilsinglright fi fl daggerdbl periodcentered quotesinglbase quotedblbase perthousand Acircumflex Ecircumflex Aacute Edieresis Egrave Iacute Icircumflex Idieresis Igrave Oacute Ocircumflex apple Ograve Uacute Ucircumflex Ugrave dotlessi circumflex tilde macron breve dotaccent ring cedilla hungarumlaut ogonek caron Lslash lslash Scaron scaron Zcaron zcaron brokenbar Eth eth Yacute yacute Thorn thorn minus multiply onesuperior twosuperior threesuperior onehalf onequarter threequarters franc Gbreve gbreve Idotaccent Scedilla scedilla Cacute cacute Ccaron ccaron dcroat".split(" ");
|
|
@@ -95,6 +116,10 @@ function parsePostGlyphNames(font) {
|
|
|
95
116
|
}
|
|
96
117
|
const NAME_HEADER_SIZE = 6;
|
|
97
118
|
const NAME_RECORD_SIZE = 12;
|
|
119
|
+
const NAME_HEADER_STORAGE_OFFSET_FIELD_OFFSET = 4;
|
|
120
|
+
const NAME_RECORD_NAME_ID_OFFSET = 6;
|
|
121
|
+
const NAME_RECORD_LENGTH_OFFSET = 8;
|
|
122
|
+
const NAME_RECORD_STRING_OFFSET_FIELD_OFFSET = 10;
|
|
98
123
|
const NAME_ID_FAMILY = 1;
|
|
99
124
|
const NAME_ID_POSTSCRIPT = 6;
|
|
100
125
|
const NAME_ID_TYPOGRAPHIC_FAMILY = 16;
|
|
@@ -103,9 +128,10 @@ const PLATFORM_MACINTOSH = 1;
|
|
|
103
128
|
const PLATFORM_WINDOWS = 3;
|
|
104
129
|
const WINDOWS_ENCODING_UNICODE_BMP = 1;
|
|
105
130
|
const MACINTOSH_ENCODING_ROMAN = 0;
|
|
131
|
+
const BITS_PER_BYTE = 8;
|
|
106
132
|
function decodeUtf16Be(bytes, offset, length) {
|
|
107
133
|
let text = "";
|
|
108
|
-
for (let i = 0; i + 1 < length; i += 2) text += String.fromCharCode(bytes[offset + i] <<
|
|
134
|
+
for (let i = 0; i + 1 < length; i += 2) text += String.fromCharCode(bytes[offset + i] << BITS_PER_BYTE | bytes[offset + i + 1]);
|
|
109
135
|
return text;
|
|
110
136
|
}
|
|
111
137
|
function decodeMacRoman(bytes, offset, length) {
|
|
@@ -113,14 +139,15 @@ function decodeMacRoman(bytes, offset, length) {
|
|
|
113
139
|
for (let i = 0; i < length; i++) text += String.fromCharCode(bytes[offset + i]);
|
|
114
140
|
return text;
|
|
115
141
|
}
|
|
142
|
+
const PLATFORM_RANK_UNSUPPORTED = 3;
|
|
116
143
|
function platformRank(record) {
|
|
117
144
|
if (record.platformId === PLATFORM_WINDOWS && record.encodingId === WINDOWS_ENCODING_UNICODE_BMP) return 0;
|
|
118
145
|
if (record.platformId === PLATFORM_UNICODE) return 1;
|
|
119
146
|
if (record.platformId === PLATFORM_MACINTOSH && record.encodingId === MACINTOSH_ENCODING_ROMAN) return 2;
|
|
120
|
-
return
|
|
147
|
+
return PLATFORM_RANK_UNSUPPORTED;
|
|
121
148
|
}
|
|
122
149
|
function readName(bytes, records, nameId) {
|
|
123
|
-
const matches = records.filter((record) => record.nameId === nameId && platformRank(record) <
|
|
150
|
+
const matches = records.filter((record) => record.nameId === nameId && platformRank(record) < PLATFORM_RANK_UNSUPPORTED).sort((a, b) => platformRank(a) - platformRank(b));
|
|
124
151
|
for (const record of matches) {
|
|
125
152
|
if (!require_sfnt.hasBytes(bytes, record.stringOffset, record.length)) continue;
|
|
126
153
|
const text = record.platformId === PLATFORM_MACINTOSH ? decodeMacRoman(bytes, record.stringOffset, record.length) : decodeUtf16Be(bytes, record.stringOffset, record.length);
|
|
@@ -131,7 +158,7 @@ function parseName(font) {
|
|
|
131
158
|
const bytes = require_sfnt.sfntTableBytes(font, "name");
|
|
132
159
|
if (bytes === void 0 || !require_sfnt.hasBytes(bytes, 0, NAME_HEADER_SIZE)) return;
|
|
133
160
|
const count = require_sfnt.u16(bytes, 2);
|
|
134
|
-
const storageOffset = require_sfnt.u16(bytes,
|
|
161
|
+
const storageOffset = require_sfnt.u16(bytes, NAME_HEADER_STORAGE_OFFSET_FIELD_OFFSET);
|
|
135
162
|
if (!require_sfnt.hasBytes(bytes, NAME_HEADER_SIZE, count * NAME_RECORD_SIZE)) return;
|
|
136
163
|
const records = [];
|
|
137
164
|
for (let i = 0; i < count; i++) {
|
|
@@ -139,9 +166,9 @@ function parseName(font) {
|
|
|
139
166
|
records.push({
|
|
140
167
|
platformId: require_sfnt.u16(bytes, recordOffset),
|
|
141
168
|
encodingId: require_sfnt.u16(bytes, recordOffset + 2),
|
|
142
|
-
nameId: require_sfnt.u16(bytes, recordOffset +
|
|
143
|
-
length: require_sfnt.u16(bytes, recordOffset +
|
|
144
|
-
stringOffset: storageOffset + require_sfnt.u16(bytes, recordOffset +
|
|
169
|
+
nameId: require_sfnt.u16(bytes, recordOffset + NAME_RECORD_NAME_ID_OFFSET),
|
|
170
|
+
length: require_sfnt.u16(bytes, recordOffset + NAME_RECORD_LENGTH_OFFSET),
|
|
171
|
+
stringOffset: storageOffset + require_sfnt.u16(bytes, recordOffset + NAME_RECORD_STRING_OFFSET_FIELD_OFFSET)
|
|
145
172
|
});
|
|
146
173
|
}
|
|
147
174
|
return {
|
package/dist/font-tables.js
CHANGED
|
@@ -4,35 +4,53 @@ const HEAD_TABLE_SIZE = 54;
|
|
|
4
4
|
const HEAD_MAGIC_NUMBER = 1594834165;
|
|
5
5
|
const MIN_UNITS_PER_EM = 16;
|
|
6
6
|
const MAX_UNITS_PER_EM = 16384;
|
|
7
|
+
const HEAD_CHECKSUM_ADJUSTMENT_OFFSET = 8;
|
|
8
|
+
const HEAD_MAGIC_NUMBER_OFFSET = 12;
|
|
9
|
+
const HEAD_UNITS_PER_EM_OFFSET = 18;
|
|
10
|
+
const HEAD_X_MIN_OFFSET = 36;
|
|
11
|
+
const HEAD_Y_MIN_OFFSET = 38;
|
|
12
|
+
const HEAD_X_MAX_OFFSET = 40;
|
|
13
|
+
const HEAD_Y_MAX_OFFSET = 42;
|
|
14
|
+
const HEAD_MAC_STYLE_OFFSET = 44;
|
|
15
|
+
const HEAD_INDEX_TO_LOC_FORMAT_OFFSET = 50;
|
|
7
16
|
function parseHead(font) {
|
|
8
17
|
const bytes = sfntTableBytes(font, "head");
|
|
9
18
|
if (bytes === void 0 || !hasBytes(bytes, 0, HEAD_TABLE_SIZE)) return;
|
|
10
|
-
if (u32(bytes,
|
|
11
|
-
const unitsPerEm = u16(bytes,
|
|
19
|
+
if (u32(bytes, HEAD_MAGIC_NUMBER_OFFSET) !== HEAD_MAGIC_NUMBER) return;
|
|
20
|
+
const unitsPerEm = u16(bytes, HEAD_UNITS_PER_EM_OFFSET);
|
|
12
21
|
if (unitsPerEm < MIN_UNITS_PER_EM || unitsPerEm > MAX_UNITS_PER_EM) return;
|
|
13
|
-
const indexToLocFormat = i16(bytes,
|
|
22
|
+
const indexToLocFormat = i16(bytes, HEAD_INDEX_TO_LOC_FORMAT_OFFSET);
|
|
14
23
|
if (indexToLocFormat !== 0 && indexToLocFormat !== 1) return;
|
|
15
24
|
return {
|
|
16
25
|
unitsPerEm,
|
|
17
|
-
checkSumAdjustment: u32(bytes,
|
|
18
|
-
xMin: i16(bytes,
|
|
19
|
-
yMin: i16(bytes,
|
|
20
|
-
xMax: i16(bytes,
|
|
21
|
-
yMax: i16(bytes,
|
|
26
|
+
checkSumAdjustment: u32(bytes, HEAD_CHECKSUM_ADJUSTMENT_OFFSET),
|
|
27
|
+
xMin: i16(bytes, HEAD_X_MIN_OFFSET),
|
|
28
|
+
yMin: i16(bytes, HEAD_Y_MIN_OFFSET),
|
|
29
|
+
xMax: i16(bytes, HEAD_X_MAX_OFFSET),
|
|
30
|
+
yMax: i16(bytes, HEAD_Y_MAX_OFFSET),
|
|
22
31
|
indexToLocFormat,
|
|
23
|
-
macStyle: u16(bytes,
|
|
32
|
+
macStyle: u16(bytes, HEAD_MAC_STYLE_OFFSET)
|
|
24
33
|
};
|
|
25
34
|
}
|
|
26
35
|
const MAXP_HEADER_SIZE = 6;
|
|
36
|
+
const MAXP_NUM_GLYPHS_OFFSET = 4;
|
|
27
37
|
function parseMaxp(font) {
|
|
28
38
|
const bytes = sfntTableBytes(font, "maxp");
|
|
29
39
|
if (bytes === void 0 || !hasBytes(bytes, 0, MAXP_HEADER_SIZE)) return;
|
|
30
|
-
return { numGlyphs: u16(bytes,
|
|
40
|
+
return { numGlyphs: u16(bytes, MAXP_NUM_GLYPHS_OFFSET) };
|
|
31
41
|
}
|
|
32
42
|
const OS2_VERSION_0_SIZE = 78;
|
|
33
43
|
const OS2_VERSION_2_SIZE = 96;
|
|
34
44
|
const OS2_VERSION_WITH_HEIGHTS = 2;
|
|
35
45
|
const OS2_PANOSE_OFFSET = 32;
|
|
46
|
+
const OS2_FS_SELECTION_OFFSET = 62;
|
|
47
|
+
const OS2_S_TYPO_ASCENDER_OFFSET = 68;
|
|
48
|
+
const OS2_S_TYPO_DESCENDER_OFFSET = 70;
|
|
49
|
+
const OS2_S_TYPO_LINE_GAP_OFFSET = 72;
|
|
50
|
+
const OS2_US_WIN_ASCENT_OFFSET = 74;
|
|
51
|
+
const OS2_US_WIN_DESCENT_OFFSET = 76;
|
|
52
|
+
const OS2_SX_HEIGHT_OFFSET = 86;
|
|
53
|
+
const OS2_S_CAP_HEIGHT_OFFSET = 88;
|
|
36
54
|
function parseOs2(font) {
|
|
37
55
|
const bytes = sfntTableBytes(font, "OS/2");
|
|
38
56
|
if (bytes === void 0 || !hasBytes(bytes, 0, OS2_VERSION_0_SIZE)) return;
|
|
@@ -40,27 +58,30 @@ function parseOs2(font) {
|
|
|
40
58
|
const hasHeights = version >= OS2_VERSION_WITH_HEIGHTS && hasBytes(bytes, 0, OS2_VERSION_2_SIZE);
|
|
41
59
|
return {
|
|
42
60
|
version,
|
|
43
|
-
fsSelection: u16(bytes,
|
|
61
|
+
fsSelection: u16(bytes, OS2_FS_SELECTION_OFFSET),
|
|
44
62
|
panose: [...bytes.subarray(OS2_PANOSE_OFFSET, 42)],
|
|
45
|
-
sTypoAscender: i16(bytes,
|
|
46
|
-
sTypoDescender: i16(bytes,
|
|
47
|
-
sTypoLineGap: i16(bytes,
|
|
48
|
-
usWinAscent: u16(bytes,
|
|
49
|
-
usWinDescent: u16(bytes,
|
|
50
|
-
sxHeight: hasHeights ? i16(bytes,
|
|
51
|
-
sCapHeight: hasHeights ? i16(bytes,
|
|
63
|
+
sTypoAscender: i16(bytes, OS2_S_TYPO_ASCENDER_OFFSET),
|
|
64
|
+
sTypoDescender: i16(bytes, OS2_S_TYPO_DESCENDER_OFFSET),
|
|
65
|
+
sTypoLineGap: i16(bytes, OS2_S_TYPO_LINE_GAP_OFFSET),
|
|
66
|
+
usWinAscent: u16(bytes, OS2_US_WIN_ASCENT_OFFSET),
|
|
67
|
+
usWinDescent: u16(bytes, OS2_US_WIN_DESCENT_OFFSET),
|
|
68
|
+
sxHeight: hasHeights ? i16(bytes, OS2_SX_HEIGHT_OFFSET) : void 0,
|
|
69
|
+
sCapHeight: hasHeights ? i16(bytes, OS2_S_CAP_HEIGHT_OFFSET) : void 0
|
|
52
70
|
};
|
|
53
71
|
}
|
|
54
72
|
const POST_HEADER_SIZE = 32;
|
|
55
73
|
const FIXED_16_16_SCALE = 65536;
|
|
74
|
+
const POST_ITALIC_ANGLE_OFFSET = 4;
|
|
75
|
+
const POST_UNDERLINE_POSITION_OFFSET = 8;
|
|
76
|
+
const POST_UNDERLINE_THICKNESS_OFFSET = 10;
|
|
56
77
|
function parsePost(font) {
|
|
57
78
|
const bytes = sfntTableBytes(font, "post");
|
|
58
79
|
if (bytes === void 0 || !hasBytes(bytes, 0, POST_HEADER_SIZE)) return;
|
|
59
80
|
return {
|
|
60
81
|
version: u32(bytes, 0),
|
|
61
|
-
italicAngle: i32(bytes,
|
|
62
|
-
underlinePosition: i16(bytes,
|
|
63
|
-
underlineThickness: i16(bytes,
|
|
82
|
+
italicAngle: i32(bytes, POST_ITALIC_ANGLE_OFFSET) / FIXED_16_16_SCALE,
|
|
83
|
+
underlinePosition: i16(bytes, POST_UNDERLINE_POSITION_OFFSET),
|
|
84
|
+
underlineThickness: i16(bytes, POST_UNDERLINE_THICKNESS_OFFSET)
|
|
64
85
|
};
|
|
65
86
|
}
|
|
66
87
|
const MAC_STANDARD_GLYPH_ORDER = ".notdef .null nonmarkingreturn space exclam quotedbl numbersign dollar percent ampersand quotesingle parenleft parenright asterisk plus comma hyphen period slash zero one two three four five six seven eight nine colon semicolon less equal greater question at A B C D E F G H I J K L M N O P Q R S T U V W X Y Z bracketleft backslash bracketright asciicircum underscore grave a b c d e f g h i j k l m n o p q r s t u v w x y z braceleft bar braceright asciitilde Adieresis Aring Ccedilla Eacute Ntilde Odieresis Udieresis aacute agrave acircumflex adieresis atilde aring ccedilla eacute egrave ecircumflex edieresis iacute igrave icircumflex idieresis ntilde oacute ograve ocircumflex odieresis otilde uacute ugrave ucircumflex udieresis dagger degree cent sterling section bullet paragraph germandbls registered copyright trademark acute dieresis notequal AE Oslash infinity plusminus lessequal greaterequal yen mu partialdiff summation product pi integral ordfeminine ordmasculine Omega ae oslash questiondown exclamdown logicalnot radical florin approxequal Delta guillemotleft guillemotright ellipsis nonbreakingspace Agrave Atilde Otilde OE oe endash emdash quotedblleft quotedblright quoteleft quoteright divide lozenge ydieresis Ydieresis fraction currency guilsinglleft guilsinglright fi fl daggerdbl periodcentered quotesinglbase quotedblbase perthousand Acircumflex Ecircumflex Aacute Edieresis Egrave Iacute Icircumflex Idieresis Igrave Oacute Ocircumflex apple Ograve Uacute Ucircumflex Ugrave dotlessi circumflex tilde macron breve dotaccent ring cedilla hungarumlaut ogonek caron Lslash lslash Scaron scaron Zcaron zcaron brokenbar Eth eth Yacute yacute Thorn thorn minus multiply onesuperior twosuperior threesuperior onehalf onequarter threequarters franc Gbreve gbreve Idotaccent Scedilla scedilla Cacute cacute Ccaron ccaron dcroat".split(" ");
|
|
@@ -94,6 +115,10 @@ function parsePostGlyphNames(font) {
|
|
|
94
115
|
}
|
|
95
116
|
const NAME_HEADER_SIZE = 6;
|
|
96
117
|
const NAME_RECORD_SIZE = 12;
|
|
118
|
+
const NAME_HEADER_STORAGE_OFFSET_FIELD_OFFSET = 4;
|
|
119
|
+
const NAME_RECORD_NAME_ID_OFFSET = 6;
|
|
120
|
+
const NAME_RECORD_LENGTH_OFFSET = 8;
|
|
121
|
+
const NAME_RECORD_STRING_OFFSET_FIELD_OFFSET = 10;
|
|
97
122
|
const NAME_ID_FAMILY = 1;
|
|
98
123
|
const NAME_ID_POSTSCRIPT = 6;
|
|
99
124
|
const NAME_ID_TYPOGRAPHIC_FAMILY = 16;
|
|
@@ -102,9 +127,10 @@ const PLATFORM_MACINTOSH = 1;
|
|
|
102
127
|
const PLATFORM_WINDOWS = 3;
|
|
103
128
|
const WINDOWS_ENCODING_UNICODE_BMP = 1;
|
|
104
129
|
const MACINTOSH_ENCODING_ROMAN = 0;
|
|
130
|
+
const BITS_PER_BYTE = 8;
|
|
105
131
|
function decodeUtf16Be(bytes, offset, length) {
|
|
106
132
|
let text = "";
|
|
107
|
-
for (let i = 0; i + 1 < length; i += 2) text += String.fromCharCode(bytes[offset + i] <<
|
|
133
|
+
for (let i = 0; i + 1 < length; i += 2) text += String.fromCharCode(bytes[offset + i] << BITS_PER_BYTE | bytes[offset + i + 1]);
|
|
108
134
|
return text;
|
|
109
135
|
}
|
|
110
136
|
function decodeMacRoman(bytes, offset, length) {
|
|
@@ -112,14 +138,15 @@ function decodeMacRoman(bytes, offset, length) {
|
|
|
112
138
|
for (let i = 0; i < length; i++) text += String.fromCharCode(bytes[offset + i]);
|
|
113
139
|
return text;
|
|
114
140
|
}
|
|
141
|
+
const PLATFORM_RANK_UNSUPPORTED = 3;
|
|
115
142
|
function platformRank(record) {
|
|
116
143
|
if (record.platformId === PLATFORM_WINDOWS && record.encodingId === WINDOWS_ENCODING_UNICODE_BMP) return 0;
|
|
117
144
|
if (record.platformId === PLATFORM_UNICODE) return 1;
|
|
118
145
|
if (record.platformId === PLATFORM_MACINTOSH && record.encodingId === MACINTOSH_ENCODING_ROMAN) return 2;
|
|
119
|
-
return
|
|
146
|
+
return PLATFORM_RANK_UNSUPPORTED;
|
|
120
147
|
}
|
|
121
148
|
function readName(bytes, records, nameId) {
|
|
122
|
-
const matches = records.filter((record) => record.nameId === nameId && platformRank(record) <
|
|
149
|
+
const matches = records.filter((record) => record.nameId === nameId && platformRank(record) < PLATFORM_RANK_UNSUPPORTED).sort((a, b) => platformRank(a) - platformRank(b));
|
|
123
150
|
for (const record of matches) {
|
|
124
151
|
if (!hasBytes(bytes, record.stringOffset, record.length)) continue;
|
|
125
152
|
const text = record.platformId === PLATFORM_MACINTOSH ? decodeMacRoman(bytes, record.stringOffset, record.length) : decodeUtf16Be(bytes, record.stringOffset, record.length);
|
|
@@ -130,7 +157,7 @@ function parseName(font) {
|
|
|
130
157
|
const bytes = sfntTableBytes(font, "name");
|
|
131
158
|
if (bytes === void 0 || !hasBytes(bytes, 0, NAME_HEADER_SIZE)) return;
|
|
132
159
|
const count = u16(bytes, 2);
|
|
133
|
-
const storageOffset = u16(bytes,
|
|
160
|
+
const storageOffset = u16(bytes, NAME_HEADER_STORAGE_OFFSET_FIELD_OFFSET);
|
|
134
161
|
if (!hasBytes(bytes, NAME_HEADER_SIZE, count * NAME_RECORD_SIZE)) return;
|
|
135
162
|
const records = [];
|
|
136
163
|
for (let i = 0; i < count; i++) {
|
|
@@ -138,9 +165,9 @@ function parseName(font) {
|
|
|
138
165
|
records.push({
|
|
139
166
|
platformId: u16(bytes, recordOffset),
|
|
140
167
|
encodingId: u16(bytes, recordOffset + 2),
|
|
141
|
-
nameId: u16(bytes, recordOffset +
|
|
142
|
-
length: u16(bytes, recordOffset +
|
|
143
|
-
stringOffset: storageOffset + u16(bytes, recordOffset +
|
|
168
|
+
nameId: u16(bytes, recordOffset + NAME_RECORD_NAME_ID_OFFSET),
|
|
169
|
+
length: u16(bytes, recordOffset + NAME_RECORD_LENGTH_OFFSET),
|
|
170
|
+
stringOffset: storageOffset + u16(bytes, recordOffset + NAME_RECORD_STRING_OFFSET_FIELD_OFFSET)
|
|
144
171
|
});
|
|
145
172
|
}
|
|
146
173
|
return {
|
package/dist/form.cjs
CHANGED
|
@@ -13,11 +13,14 @@ function readAcroForm(catalog, resolver, pageIndex, sink) {
|
|
|
13
13
|
const visited = /* @__PURE__ */ new Set();
|
|
14
14
|
for (const fieldRef of require_objects.asArray(resolver.resolve(require_objects.dictGet(acroForm, "Fields"))) ?? []) {
|
|
15
15
|
const fieldDict = resolver.resolveDict(fieldRef);
|
|
16
|
-
if (fieldDict !== void 0)
|
|
16
|
+
if (fieldDict !== void 0) {
|
|
17
|
+
const field = readField(fieldDict, "", resolver, pageIndex, sink, visited);
|
|
18
|
+
if (field !== void 0) fields.push(field);
|
|
19
|
+
}
|
|
17
20
|
}
|
|
18
21
|
return fields;
|
|
19
22
|
}
|
|
20
|
-
function readField(node, parentName, resolver, pageIndex, sink,
|
|
23
|
+
function readField(node, parentName, resolver, pageIndex, sink, visited) {
|
|
21
24
|
if (visited.has(node)) {
|
|
22
25
|
sink({
|
|
23
26
|
code: "pdf/form-field-cycle",
|
|
@@ -35,15 +38,17 @@ function readField(node, parentName, resolver, pageIndex, sink, out, visited) {
|
|
|
35
38
|
const children = [];
|
|
36
39
|
for (const kidRef of require_objects.asArray(resolver.resolve(require_objects.dictGet(node, "Kids"))) ?? []) {
|
|
37
40
|
const kid = resolver.resolveDict(kidRef);
|
|
38
|
-
if (kid !== void 0)
|
|
41
|
+
if (kid !== void 0) {
|
|
42
|
+
const child = readField(kid, name, resolver, pageIndex, sink, visited);
|
|
43
|
+
if (child !== void 0) children.push(child);
|
|
44
|
+
}
|
|
39
45
|
}
|
|
40
|
-
|
|
46
|
+
return {
|
|
41
47
|
name,
|
|
42
48
|
fieldType: "group",
|
|
43
49
|
widgets: [],
|
|
44
50
|
children
|
|
45
|
-
}
|
|
46
|
-
return;
|
|
51
|
+
};
|
|
47
52
|
}
|
|
48
53
|
const flags = require_objects.asNumber(resolver.resolve(require_objects.dictGet(node, "Ff"))) ?? 0;
|
|
49
54
|
const value = fieldValue(node, resolver);
|
|
@@ -60,7 +65,7 @@ function readField(node, parentName, resolver, pageIndex, sink, out, visited) {
|
|
|
60
65
|
const widget = widgetPlacement(node, pageIndex);
|
|
61
66
|
if (widget !== void 0) widgets.push(widget);
|
|
62
67
|
}
|
|
63
|
-
|
|
68
|
+
return {
|
|
64
69
|
name,
|
|
65
70
|
fieldType: mapFieldType(fieldType, flags),
|
|
66
71
|
...valueFields(fieldType, value),
|
|
@@ -69,7 +74,7 @@ function readField(node, parentName, resolver, pageIndex, sink, out, visited) {
|
|
|
69
74
|
...(flags & FLAG_READ_ONLY) !== 0 ? { readOnly: true } : {},
|
|
70
75
|
widgets,
|
|
71
76
|
children: []
|
|
72
|
-
}
|
|
77
|
+
};
|
|
73
78
|
}
|
|
74
79
|
function mapFieldType(fieldType, flags) {
|
|
75
80
|
if (fieldType === "Tx") return "text";
|
package/dist/form.d.cts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { PdfDiagnosticSink } from "./diagnostics.cjs";
|
|
2
|
-
import { n as PdfDict } from "./objects-
|
|
2
|
+
import { n as PdfDict } from "./objects-e2RS3-yT.cjs";
|
|
3
3
|
import { PdfObjectResolver } from "./interpret.cjs";
|
|
4
4
|
import { LayoutFormField } from "./layout.cjs";
|
|
5
5
|
import { PageIndexLookup } from "./navigation.cjs";
|
|
6
6
|
//#region src/form.d.ts
|
|
7
|
-
declare function readAcroForm(catalog: PdfDict, resolver: PdfObjectResolver
|
|
7
|
+
declare function readAcroForm(catalog: PdfDict, resolver: Readonly<PdfObjectResolver>, pageIndex: PageIndexLookup, sink: PdfDiagnosticSink): LayoutFormField[];
|
|
8
8
|
//#endregion
|
|
9
9
|
export { readAcroForm };
|
package/dist/form.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { PdfDiagnosticSink } from "./diagnostics.js";
|
|
2
|
-
import { n as PdfDict } from "./objects-
|
|
2
|
+
import { n as PdfDict } from "./objects-e2RS3-yT.js";
|
|
3
3
|
import { PdfObjectResolver } from "./interpret.js";
|
|
4
4
|
import { LayoutFormField } from "./layout.js";
|
|
5
5
|
import { PageIndexLookup } from "./navigation.js";
|
|
6
6
|
//#region src/form.d.ts
|
|
7
|
-
declare function readAcroForm(catalog: PdfDict, resolver: PdfObjectResolver
|
|
7
|
+
declare function readAcroForm(catalog: PdfDict, resolver: Readonly<PdfObjectResolver>, pageIndex: PageIndexLookup, sink: PdfDiagnosticSink): LayoutFormField[];
|
|
8
8
|
//#endregion
|
|
9
9
|
export { readAcroForm };
|
package/dist/form.js
CHANGED
|
@@ -12,11 +12,14 @@ function readAcroForm(catalog, resolver, pageIndex, sink) {
|
|
|
12
12
|
const visited = /* @__PURE__ */ new Set();
|
|
13
13
|
for (const fieldRef of asArray(resolver.resolve(dictGet(acroForm, "Fields"))) ?? []) {
|
|
14
14
|
const fieldDict = resolver.resolveDict(fieldRef);
|
|
15
|
-
if (fieldDict !== void 0)
|
|
15
|
+
if (fieldDict !== void 0) {
|
|
16
|
+
const field = readField(fieldDict, "", resolver, pageIndex, sink, visited);
|
|
17
|
+
if (field !== void 0) fields.push(field);
|
|
18
|
+
}
|
|
16
19
|
}
|
|
17
20
|
return fields;
|
|
18
21
|
}
|
|
19
|
-
function readField(node, parentName, resolver, pageIndex, sink,
|
|
22
|
+
function readField(node, parentName, resolver, pageIndex, sink, visited) {
|
|
20
23
|
if (visited.has(node)) {
|
|
21
24
|
sink({
|
|
22
25
|
code: "pdf/form-field-cycle",
|
|
@@ -34,15 +37,17 @@ function readField(node, parentName, resolver, pageIndex, sink, out, visited) {
|
|
|
34
37
|
const children = [];
|
|
35
38
|
for (const kidRef of asArray(resolver.resolve(dictGet(node, "Kids"))) ?? []) {
|
|
36
39
|
const kid = resolver.resolveDict(kidRef);
|
|
37
|
-
if (kid !== void 0)
|
|
40
|
+
if (kid !== void 0) {
|
|
41
|
+
const child = readField(kid, name, resolver, pageIndex, sink, visited);
|
|
42
|
+
if (child !== void 0) children.push(child);
|
|
43
|
+
}
|
|
38
44
|
}
|
|
39
|
-
|
|
45
|
+
return {
|
|
40
46
|
name,
|
|
41
47
|
fieldType: "group",
|
|
42
48
|
widgets: [],
|
|
43
49
|
children
|
|
44
|
-
}
|
|
45
|
-
return;
|
|
50
|
+
};
|
|
46
51
|
}
|
|
47
52
|
const flags = asNumber(resolver.resolve(dictGet(node, "Ff"))) ?? 0;
|
|
48
53
|
const value = fieldValue(node, resolver);
|
|
@@ -59,7 +64,7 @@ function readField(node, parentName, resolver, pageIndex, sink, out, visited) {
|
|
|
59
64
|
const widget = widgetPlacement(node, pageIndex);
|
|
60
65
|
if (widget !== void 0) widgets.push(widget);
|
|
61
66
|
}
|
|
62
|
-
|
|
67
|
+
return {
|
|
63
68
|
name,
|
|
64
69
|
fieldType: mapFieldType(fieldType, flags),
|
|
65
70
|
...valueFields(fieldType, value),
|
|
@@ -68,7 +73,7 @@ function readField(node, parentName, resolver, pageIndex, sink, out, visited) {
|
|
|
68
73
|
...(flags & FLAG_READ_ONLY) !== 0 ? { readOnly: true } : {},
|
|
69
74
|
widgets,
|
|
70
75
|
children: []
|
|
71
|
-
}
|
|
76
|
+
};
|
|
72
77
|
}
|
|
73
78
|
function mapFieldType(fieldType, flags) {
|
|
74
79
|
if (fieldType === "Tx") return "text";
|
package/dist/gdef-table.cjs
CHANGED
|
@@ -10,13 +10,16 @@ const GLYPH_CLASS_COMPONENT = 4;
|
|
|
10
10
|
const GDEF_HEADER_SIZE_1_0 = 12;
|
|
11
11
|
const GDEF_HEADER_SIZE_1_2 = 14;
|
|
12
12
|
const MARK_GLYPH_SETS_HEADER_SIZE = 4;
|
|
13
|
+
const GDEF_GLYPH_CLASS_DEF_OFFSET = 4;
|
|
14
|
+
const GDEF_MARK_ATTACH_CLASS_DEF_OFFSET = 10;
|
|
15
|
+
const MARK_GLYPH_SETS_ENTRY_SIZE_BYTES = 4;
|
|
13
16
|
function parseGdefTable(font) {
|
|
14
17
|
const bytes = require_sfnt.sfntTableBytes(font, "GDEF");
|
|
15
18
|
if (bytes === void 0 || !require_sfnt.hasBytes(bytes, 0, GDEF_HEADER_SIZE_1_0) || require_sfnt.u16(bytes, 0) !== 1) return;
|
|
16
19
|
const minorVersion = require_sfnt.u16(bytes, 2);
|
|
17
|
-
const glyphClassDefOffset = require_sfnt.u16(bytes,
|
|
20
|
+
const glyphClassDefOffset = require_sfnt.u16(bytes, GDEF_GLYPH_CLASS_DEF_OFFSET);
|
|
18
21
|
const glyphClassDef = glyphClassDefOffset === 0 ? void 0 : require_ot_layout_common.parseClassDef(bytes, glyphClassDefOffset);
|
|
19
|
-
const markAttachClassDefOffset = require_sfnt.u16(bytes,
|
|
22
|
+
const markAttachClassDefOffset = require_sfnt.u16(bytes, GDEF_MARK_ATTACH_CLASS_DEF_OFFSET);
|
|
20
23
|
const markAttachClassDef = markAttachClassDefOffset === 0 ? void 0 : require_ot_layout_common.parseClassDef(bytes, markAttachClassDefOffset);
|
|
21
24
|
const markGlyphSets = [];
|
|
22
25
|
if (minorVersion >= 2 && require_sfnt.hasBytes(bytes, 0, GDEF_HEADER_SIZE_1_2)) {
|
|
@@ -24,7 +27,7 @@ function parseGdefTable(font) {
|
|
|
24
27
|
if (markGlyphSetsDefOffset !== 0 && require_sfnt.hasBytes(bytes, markGlyphSetsDefOffset, MARK_GLYPH_SETS_HEADER_SIZE) && require_sfnt.u16(bytes, markGlyphSetsDefOffset) === 1) {
|
|
25
28
|
const setCount = require_sfnt.u16(bytes, markGlyphSetsDefOffset + 2);
|
|
26
29
|
const coverageOffsetsOffset = markGlyphSetsDefOffset + MARK_GLYPH_SETS_HEADER_SIZE;
|
|
27
|
-
if (require_sfnt.hasBytes(bytes, coverageOffsetsOffset, setCount *
|
|
30
|
+
if (require_sfnt.hasBytes(bytes, coverageOffsetsOffset, setCount * MARK_GLYPH_SETS_ENTRY_SIZE_BYTES)) for (let i = 0; i < setCount; i++) markGlyphSets.push(require_ot_layout_common.parseCoverage(bytes, markGlyphSetsDefOffset + require_sfnt.u32(bytes, coverageOffsetsOffset + i * MARK_GLYPH_SETS_ENTRY_SIZE_BYTES)));
|
|
28
31
|
}
|
|
29
32
|
}
|
|
30
33
|
return {
|
package/dist/gdef-table.js
CHANGED
|
@@ -9,13 +9,16 @@ const GLYPH_CLASS_COMPONENT = 4;
|
|
|
9
9
|
const GDEF_HEADER_SIZE_1_0 = 12;
|
|
10
10
|
const GDEF_HEADER_SIZE_1_2 = 14;
|
|
11
11
|
const MARK_GLYPH_SETS_HEADER_SIZE = 4;
|
|
12
|
+
const GDEF_GLYPH_CLASS_DEF_OFFSET = 4;
|
|
13
|
+
const GDEF_MARK_ATTACH_CLASS_DEF_OFFSET = 10;
|
|
14
|
+
const MARK_GLYPH_SETS_ENTRY_SIZE_BYTES = 4;
|
|
12
15
|
function parseGdefTable(font) {
|
|
13
16
|
const bytes = sfntTableBytes(font, "GDEF");
|
|
14
17
|
if (bytes === void 0 || !hasBytes(bytes, 0, GDEF_HEADER_SIZE_1_0) || u16(bytes, 0) !== 1) return;
|
|
15
18
|
const minorVersion = u16(bytes, 2);
|
|
16
|
-
const glyphClassDefOffset = u16(bytes,
|
|
19
|
+
const glyphClassDefOffset = u16(bytes, GDEF_GLYPH_CLASS_DEF_OFFSET);
|
|
17
20
|
const glyphClassDef = glyphClassDefOffset === 0 ? void 0 : parseClassDef(bytes, glyphClassDefOffset);
|
|
18
|
-
const markAttachClassDefOffset = u16(bytes,
|
|
21
|
+
const markAttachClassDefOffset = u16(bytes, GDEF_MARK_ATTACH_CLASS_DEF_OFFSET);
|
|
19
22
|
const markAttachClassDef = markAttachClassDefOffset === 0 ? void 0 : parseClassDef(bytes, markAttachClassDefOffset);
|
|
20
23
|
const markGlyphSets = [];
|
|
21
24
|
if (minorVersion >= 2 && hasBytes(bytes, 0, GDEF_HEADER_SIZE_1_2)) {
|
|
@@ -23,7 +26,7 @@ function parseGdefTable(font) {
|
|
|
23
26
|
if (markGlyphSetsDefOffset !== 0 && hasBytes(bytes, markGlyphSetsDefOffset, MARK_GLYPH_SETS_HEADER_SIZE) && u16(bytes, markGlyphSetsDefOffset) === 1) {
|
|
24
27
|
const setCount = u16(bytes, markGlyphSetsDefOffset + 2);
|
|
25
28
|
const coverageOffsetsOffset = markGlyphSetsDefOffset + MARK_GLYPH_SETS_HEADER_SIZE;
|
|
26
|
-
if (hasBytes(bytes, coverageOffsetsOffset, setCount *
|
|
29
|
+
if (hasBytes(bytes, coverageOffsetsOffset, setCount * MARK_GLYPH_SETS_ENTRY_SIZE_BYTES)) for (let i = 0; i < setCount; i++) markGlyphSets.push(parseCoverage(bytes, markGlyphSetsDefOffset + u32(bytes, coverageOffsetsOffset + i * MARK_GLYPH_SETS_ENTRY_SIZE_BYTES)));
|
|
27
30
|
}
|
|
28
31
|
}
|
|
29
32
|
return {
|
|
@@ -8,6 +8,6 @@ interface GlyphContourPoint {
|
|
|
8
8
|
interface GlyphOutline {
|
|
9
9
|
readonly contours: readonly (readonly GlyphContourPoint[])[];
|
|
10
10
|
}
|
|
11
|
-
declare function decodeGlyphOutline(glyf: GlyfTable
|
|
11
|
+
declare function decodeGlyphOutline(glyf: Readonly<GlyfTable>, glyphId: number): GlyphOutline | undefined;
|
|
12
12
|
//#endregion
|
|
13
13
|
export { GlyphOutline as n, decodeGlyphOutline as r, GlyphContourPoint as t };
|
|
@@ -8,6 +8,6 @@ interface GlyphContourPoint {
|
|
|
8
8
|
interface GlyphOutline {
|
|
9
9
|
readonly contours: readonly (readonly GlyphContourPoint[])[];
|
|
10
10
|
}
|
|
11
|
-
declare function decodeGlyphOutline(glyf: GlyfTable
|
|
11
|
+
declare function decodeGlyphOutline(glyf: Readonly<GlyfTable>, glyphId: number): GlyphOutline | undefined;
|
|
12
12
|
//#endregion
|
|
13
13
|
export { GlyphOutline as n, decodeGlyphOutline as r, GlyphContourPoint as t };
|
package/dist/glyf-contours.cjs
CHANGED
|
@@ -8,6 +8,8 @@ const FLAG_REPEAT = 8;
|
|
|
8
8
|
const FLAG_X_SAME_OR_POSITIVE = 16;
|
|
9
9
|
const FLAG_Y_SAME_OR_POSITIVE = 32;
|
|
10
10
|
const MAX_COMPOSITE_DEPTH = 5;
|
|
11
|
+
const SCALED_COMPONENT_OFFSET = 2048;
|
|
12
|
+
const UNSCALED_COMPONENT_OFFSET = 4096;
|
|
11
13
|
function decodeSimpleContours(glyph) {
|
|
12
14
|
const numberOfContours = require_sfnt.i16(glyph, 0);
|
|
13
15
|
const endPtsOffset = 10;
|
|
@@ -87,7 +89,7 @@ function placeComponentContours(contours, component) {
|
|
|
87
89
|
0,
|
|
88
90
|
1
|
|
89
91
|
];
|
|
90
|
-
const scaledOffset = (component.flags &
|
|
92
|
+
const scaledOffset = (component.flags & SCALED_COMPONENT_OFFSET) !== 0 && (component.flags & UNSCALED_COMPONENT_OFFSET) === 0;
|
|
91
93
|
const dx = scaledOffset ? a * component.argument1 + c * component.argument2 : component.argument1;
|
|
92
94
|
const dy = scaledOffset ? b * component.argument1 + d * component.argument2 : component.argument2;
|
|
93
95
|
return contours.map((points) => points.map((point) => ({
|
package/dist/glyf-contours.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as GlyphOutline, r as decodeGlyphOutline, t as GlyphContourPoint } from "./glyf-contours-
|
|
1
|
+
import { n as GlyphOutline, r as decodeGlyphOutline, t as GlyphContourPoint } from "./glyf-contours-NHBpgks-.cjs";
|
|
2
2
|
export { GlyphContourPoint, GlyphOutline, decodeGlyphOutline };
|
package/dist/glyf-contours.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as GlyphOutline, r as decodeGlyphOutline, t as GlyphContourPoint } from "./glyf-contours-
|
|
1
|
+
import { n as GlyphOutline, r as decodeGlyphOutline, t as GlyphContourPoint } from "./glyf-contours-B1PsI9oA.js";
|
|
2
2
|
export { GlyphContourPoint, GlyphOutline, decodeGlyphOutline };
|
package/dist/glyf-contours.js
CHANGED
|
@@ -7,6 +7,8 @@ const FLAG_REPEAT = 8;
|
|
|
7
7
|
const FLAG_X_SAME_OR_POSITIVE = 16;
|
|
8
8
|
const FLAG_Y_SAME_OR_POSITIVE = 32;
|
|
9
9
|
const MAX_COMPOSITE_DEPTH = 5;
|
|
10
|
+
const SCALED_COMPONENT_OFFSET = 2048;
|
|
11
|
+
const UNSCALED_COMPONENT_OFFSET = 4096;
|
|
10
12
|
function decodeSimpleContours(glyph) {
|
|
11
13
|
const numberOfContours = i16(glyph, 0);
|
|
12
14
|
const endPtsOffset = 10;
|
|
@@ -86,7 +88,7 @@ function placeComponentContours(contours, component) {
|
|
|
86
88
|
0,
|
|
87
89
|
1
|
|
88
90
|
];
|
|
89
|
-
const scaledOffset = (component.flags &
|
|
91
|
+
const scaledOffset = (component.flags & SCALED_COMPONENT_OFFSET) !== 0 && (component.flags & UNSCALED_COMPONENT_OFFSET) === 0;
|
|
90
92
|
const dx = scaledOffset ? a * component.argument1 + c * component.argument2 : component.argument1;
|
|
91
93
|
const dy = scaledOffset ? b * component.argument1 + d * component.argument2 : component.argument2;
|
|
92
94
|
return contours.map((points) => points.map((point) => ({
|