pdf-codec.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/cmap-table.js
CHANGED
|
@@ -3,17 +3,28 @@ import { hasBytes, sfntTableBytes, u16, u32, u8 } from "./sfnt.js";
|
|
|
3
3
|
const CMAP_HEADER_SIZE = 4;
|
|
4
4
|
const SUBTABLE_RECORD_SIZE = 8;
|
|
5
5
|
const MAX_UNICODE_CODE_POINT = 1114111;
|
|
6
|
+
const SUBTABLE_RECORD_OFFSET_FIELD = 4;
|
|
7
|
+
const CMAP_FORMAT_4 = 4;
|
|
8
|
+
const CMAP_FORMAT_6 = 6;
|
|
9
|
+
const CMAP_FORMAT_12 = 12;
|
|
10
|
+
const INT16_SIGN_BIT = 32768;
|
|
11
|
+
const UINT16_MODULUS = 65536;
|
|
12
|
+
const UINT16_MASK = 65535;
|
|
6
13
|
const FORMAT_4_HEADER_SIZE = 14;
|
|
14
|
+
const FORMAT_4_SEG_COUNT_X2_FIELD = 6;
|
|
15
|
+
const FORMAT_4_PARALLEL_ARRAY_COUNT = 4;
|
|
16
|
+
const MAX_BMP_CODE_POINT = 65535;
|
|
17
|
+
const LAST_MAPPABLE_BMP_CODE = 65534;
|
|
7
18
|
function parseFormat4(bytes, subtableOffset) {
|
|
8
19
|
if (!hasBytes(bytes, subtableOffset, FORMAT_4_HEADER_SIZE)) return;
|
|
9
|
-
const segCountX2 = u16(bytes, subtableOffset +
|
|
20
|
+
const segCountX2 = u16(bytes, subtableOffset + FORMAT_4_SEG_COUNT_X2_FIELD);
|
|
10
21
|
if (segCountX2 === 0 || segCountX2 % 2 !== 0) return;
|
|
11
22
|
const segCount = segCountX2 / 2;
|
|
12
23
|
const endCodesOffset = subtableOffset + FORMAT_4_HEADER_SIZE;
|
|
13
24
|
const startCodesOffset = endCodesOffset + segCountX2 + 2;
|
|
14
25
|
const idDeltasOffset = startCodesOffset + segCountX2;
|
|
15
26
|
const idRangeOffsetsOffset = idDeltasOffset + segCountX2;
|
|
16
|
-
if (!hasBytes(bytes, endCodesOffset, segCountX2 *
|
|
27
|
+
if (!hasBytes(bytes, endCodesOffset, segCountX2 * FORMAT_4_PARALLEL_ARRAY_COUNT + 2)) return;
|
|
17
28
|
const segments = [];
|
|
18
29
|
for (let i = 0; i < segCount; i++) {
|
|
19
30
|
const idRangeOffsetPos = idRangeOffsetsOffset + i * 2;
|
|
@@ -21,27 +32,27 @@ function parseFormat4(bytes, subtableOffset) {
|
|
|
21
32
|
segments.push({
|
|
22
33
|
endCode: u16(bytes, endCodesOffset + i * 2),
|
|
23
34
|
startCode: u16(bytes, startCodesOffset + i * 2),
|
|
24
|
-
idDelta: rawDelta >=
|
|
35
|
+
idDelta: rawDelta >= INT16_SIGN_BIT ? rawDelta - UINT16_MODULUS : rawDelta,
|
|
25
36
|
idRangeOffsetPos,
|
|
26
37
|
idRangeOffset: u16(bytes, idRangeOffsetPos)
|
|
27
38
|
});
|
|
28
39
|
}
|
|
29
40
|
const lookup = (codePoint) => {
|
|
30
|
-
if (codePoint >
|
|
41
|
+
if (codePoint > MAX_BMP_CODE_POINT) return;
|
|
31
42
|
for (const segment of segments) {
|
|
32
43
|
if (codePoint < segment.startCode || codePoint > segment.endCode) continue;
|
|
33
|
-
if (segment.idRangeOffset === 0) return codePoint + segment.idDelta &
|
|
44
|
+
if (segment.idRangeOffset === 0) return codePoint + segment.idDelta & UINT16_MASK;
|
|
34
45
|
const glyphIndexAddress = segment.idRangeOffsetPos + segment.idRangeOffset + (codePoint - segment.startCode) * 2;
|
|
35
46
|
if (!hasBytes(bytes, glyphIndexAddress, 2)) return;
|
|
36
47
|
const glyphId = u16(bytes, glyphIndexAddress);
|
|
37
|
-
return glyphId === 0 ? void 0 : glyphId + segment.idDelta &
|
|
48
|
+
return glyphId === 0 ? void 0 : glyphId + segment.idDelta & UINT16_MASK;
|
|
38
49
|
}
|
|
39
50
|
};
|
|
40
51
|
return {
|
|
41
52
|
lookup,
|
|
42
53
|
forEachMapping(visit) {
|
|
43
54
|
for (const segment of segments) {
|
|
44
|
-
const end = Math.min(segment.endCode,
|
|
55
|
+
const end = Math.min(segment.endCode, LAST_MAPPABLE_BMP_CODE);
|
|
45
56
|
for (let code = segment.startCode; code <= end; code++) {
|
|
46
57
|
const glyphId = lookup(code);
|
|
47
58
|
if (glyphId !== void 0 && glyphId !== 0) visit(code, glyphId);
|
|
@@ -51,10 +62,13 @@ function parseFormat4(bytes, subtableOffset) {
|
|
|
51
62
|
};
|
|
52
63
|
}
|
|
53
64
|
const FORMAT_12_HEADER_SIZE = 16;
|
|
65
|
+
const FORMAT_12_NUM_GROUPS_FIELD = 12;
|
|
54
66
|
const FORMAT_12_GROUP_SIZE = 12;
|
|
67
|
+
const FORMAT_12_GROUP_END_CHAR_CODE_FIELD = 4;
|
|
68
|
+
const FORMAT_12_GROUP_START_GLYPH_ID_FIELD = 8;
|
|
55
69
|
function parseFormat12(bytes, subtableOffset) {
|
|
56
70
|
if (!hasBytes(bytes, subtableOffset, FORMAT_12_HEADER_SIZE)) return;
|
|
57
|
-
const numGroups = u32(bytes, subtableOffset +
|
|
71
|
+
const numGroups = u32(bytes, subtableOffset + FORMAT_12_NUM_GROUPS_FIELD);
|
|
58
72
|
const groupsOffset = subtableOffset + FORMAT_12_HEADER_SIZE;
|
|
59
73
|
if (!hasBytes(bytes, groupsOffset, numGroups * FORMAT_12_GROUP_SIZE)) return;
|
|
60
74
|
const groups = [];
|
|
@@ -62,8 +76,8 @@ function parseFormat12(bytes, subtableOffset) {
|
|
|
62
76
|
const recordOffset = groupsOffset + i * FORMAT_12_GROUP_SIZE;
|
|
63
77
|
groups.push({
|
|
64
78
|
startCharCode: u32(bytes, recordOffset),
|
|
65
|
-
endCharCode: u32(bytes, recordOffset +
|
|
66
|
-
startGlyphId: u32(bytes, recordOffset +
|
|
79
|
+
endCharCode: u32(bytes, recordOffset + FORMAT_12_GROUP_END_CHAR_CODE_FIELD),
|
|
80
|
+
startGlyphId: u32(bytes, recordOffset + FORMAT_12_GROUP_START_GLYPH_ID_FIELD)
|
|
67
81
|
});
|
|
68
82
|
}
|
|
69
83
|
return {
|
|
@@ -79,18 +93,20 @@ function parseFormat12(bytes, subtableOffset) {
|
|
|
79
93
|
};
|
|
80
94
|
}
|
|
81
95
|
const FORMAT_0_SIZE = 262;
|
|
96
|
+
const FORMAT_0_GLYPH_ID_ARRAY_OFFSET = 6;
|
|
97
|
+
const MAX_FORMAT_0_CODE = 255;
|
|
82
98
|
function parseFormat0(bytes, subtableOffset) {
|
|
83
99
|
if (!hasBytes(bytes, subtableOffset, FORMAT_0_SIZE)) return;
|
|
84
|
-
const glyphIdArrayOffset = subtableOffset +
|
|
100
|
+
const glyphIdArrayOffset = subtableOffset + FORMAT_0_GLYPH_ID_ARRAY_OFFSET;
|
|
85
101
|
const lookup = (codePoint) => {
|
|
86
|
-
if (codePoint < 0 || codePoint >
|
|
102
|
+
if (codePoint < 0 || codePoint > MAX_FORMAT_0_CODE) return;
|
|
87
103
|
const glyphId = u8(bytes, glyphIdArrayOffset + codePoint);
|
|
88
104
|
return glyphId === 0 ? void 0 : glyphId;
|
|
89
105
|
};
|
|
90
106
|
return {
|
|
91
107
|
lookup,
|
|
92
108
|
forEachMapping(visit) {
|
|
93
|
-
for (let code = 0; code <=
|
|
109
|
+
for (let code = 0; code <= MAX_FORMAT_0_CODE; code++) {
|
|
94
110
|
const glyphId = lookup(code);
|
|
95
111
|
if (glyphId !== void 0) visit(code, glyphId);
|
|
96
112
|
}
|
|
@@ -98,10 +114,12 @@ function parseFormat0(bytes, subtableOffset) {
|
|
|
98
114
|
};
|
|
99
115
|
}
|
|
100
116
|
const FORMAT_6_HEADER_SIZE = 10;
|
|
117
|
+
const FORMAT_6_FIRST_CODE_FIELD = 6;
|
|
118
|
+
const FORMAT_6_ENTRY_COUNT_FIELD = 8;
|
|
101
119
|
function parseFormat6(bytes, subtableOffset) {
|
|
102
120
|
if (!hasBytes(bytes, subtableOffset, FORMAT_6_HEADER_SIZE)) return;
|
|
103
|
-
const firstCode = u16(bytes, subtableOffset +
|
|
104
|
-
const entryCount = u16(bytes, subtableOffset +
|
|
121
|
+
const firstCode = u16(bytes, subtableOffset + FORMAT_6_FIRST_CODE_FIELD);
|
|
122
|
+
const entryCount = u16(bytes, subtableOffset + FORMAT_6_ENTRY_COUNT_FIELD);
|
|
105
123
|
const glyphIdArrayOffset = subtableOffset + FORMAT_6_HEADER_SIZE;
|
|
106
124
|
if (!hasBytes(bytes, glyphIdArrayOffset, entryCount * 2)) return;
|
|
107
125
|
const lookup = (codePoint) => {
|
|
@@ -121,19 +139,29 @@ function parseFormat6(bytes, subtableOffset) {
|
|
|
121
139
|
}
|
|
122
140
|
};
|
|
123
141
|
}
|
|
142
|
+
const PLATFORM_WINDOWS = 3;
|
|
143
|
+
const PLATFORM_UNICODE = 0;
|
|
144
|
+
const ENCODING_WINDOWS_UCS4 = 10;
|
|
145
|
+
const ENCODING_WINDOWS_UNICODE_BMP = 1;
|
|
146
|
+
const RANK_WINDOWS_UCS4_FORMAT_12 = 0;
|
|
147
|
+
const RANK_UNICODE_FORMAT_12 = 1;
|
|
148
|
+
const RANK_OTHER_FORMAT_12 = 2;
|
|
149
|
+
const RANK_WINDOWS_BMP_FORMAT_4 = 3;
|
|
150
|
+
const RANK_OTHER_FORMAT_4 = 4;
|
|
151
|
+
const RANK_FORMAT_6 = 5;
|
|
124
152
|
function preferenceRank(subtable) {
|
|
125
|
-
if (subtable.format ===
|
|
126
|
-
if (subtable.platformId ===
|
|
127
|
-
if (subtable.platformId ===
|
|
128
|
-
return
|
|
153
|
+
if (subtable.format === CMAP_FORMAT_12) {
|
|
154
|
+
if (subtable.platformId === PLATFORM_WINDOWS && subtable.encodingId === ENCODING_WINDOWS_UCS4) return RANK_WINDOWS_UCS4_FORMAT_12;
|
|
155
|
+
if (subtable.platformId === PLATFORM_UNICODE) return RANK_UNICODE_FORMAT_12;
|
|
156
|
+
return RANK_OTHER_FORMAT_12;
|
|
129
157
|
}
|
|
130
|
-
if (subtable.format ===
|
|
131
|
-
return
|
|
158
|
+
if (subtable.format === CMAP_FORMAT_4) return subtable.platformId === PLATFORM_WINDOWS && subtable.encodingId === ENCODING_WINDOWS_UNICODE_BMP ? RANK_WINDOWS_BMP_FORMAT_4 : RANK_OTHER_FORMAT_4;
|
|
159
|
+
return RANK_FORMAT_6;
|
|
132
160
|
}
|
|
133
161
|
function parseSubtable(bytes, record) {
|
|
134
|
-
if (record.format ===
|
|
135
|
-
if (record.format ===
|
|
136
|
-
if (record.format ===
|
|
162
|
+
if (record.format === CMAP_FORMAT_12) return parseFormat12(bytes, record.offset);
|
|
163
|
+
if (record.format === CMAP_FORMAT_4) return parseFormat4(bytes, record.offset);
|
|
164
|
+
if (record.format === CMAP_FORMAT_6) return parseFormat6(bytes, record.offset);
|
|
137
165
|
return record.format === 0 ? parseFormat0(bytes, record.offset) : void 0;
|
|
138
166
|
}
|
|
139
167
|
function readCmapSubtables(font) {
|
|
@@ -144,7 +172,7 @@ function readCmapSubtables(font) {
|
|
|
144
172
|
const subtables = [];
|
|
145
173
|
for (let i = 0; i < numTables; i++) {
|
|
146
174
|
const recordOffset = CMAP_HEADER_SIZE + i * SUBTABLE_RECORD_SIZE;
|
|
147
|
-
const offset = u32(cmapBytes, recordOffset +
|
|
175
|
+
const offset = u32(cmapBytes, recordOffset + SUBTABLE_RECORD_OFFSET_FIELD);
|
|
148
176
|
if (!hasBytes(cmapBytes, offset, 2)) continue;
|
|
149
177
|
const record = {
|
|
150
178
|
platformId: u16(cmapBytes, recordOffset),
|
|
@@ -163,7 +191,7 @@ function readCmapSubtables(font) {
|
|
|
163
191
|
return subtables;
|
|
164
192
|
}
|
|
165
193
|
function buildCmapLookup(font) {
|
|
166
|
-
return readCmapSubtables(font).filter((s) => s.format ===
|
|
194
|
+
return readCmapSubtables(font).filter((s) => s.format === CMAP_FORMAT_4 || s.format === CMAP_FORMAT_6 || s.format === CMAP_FORMAT_12).sort((a, b) => preferenceRank(a) - preferenceRank(b))[0]?.lookup;
|
|
167
195
|
}
|
|
168
196
|
//#endregion
|
|
169
197
|
export { buildCmapLookup, readCmapSubtables };
|
package/dist/cmap.cjs
CHANGED
|
@@ -2,14 +2,16 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
const require_bytes_reader = require("./bytes/reader.cjs");
|
|
3
3
|
const require_lexer = require("./lexer.cjs");
|
|
4
4
|
//#region src/cmap.ts
|
|
5
|
+
const BYTE_RADIX = 256;
|
|
6
|
+
const BITS_PER_BYTE = 8;
|
|
5
7
|
function hexBytesToNumber(bytes) {
|
|
6
8
|
let value = 0;
|
|
7
|
-
for (const byte of bytes) value = value *
|
|
9
|
+
for (const byte of bytes) value = value * BYTE_RADIX + byte;
|
|
8
10
|
return value;
|
|
9
11
|
}
|
|
10
12
|
function decodeUtf16BEString(bytes) {
|
|
11
13
|
const units = [];
|
|
12
|
-
for (let i = 0; i + 1 < bytes.length; i += 2) units.push((bytes[i] ?? 0) <<
|
|
14
|
+
for (let i = 0; i + 1 < bytes.length; i += 2) units.push((bytes[i] ?? 0) << BITS_PER_BYTE | (bytes[i + 1] ?? 0));
|
|
13
15
|
return String.fromCharCode(...units);
|
|
14
16
|
}
|
|
15
17
|
function parseToUnicodeCMap(bytes, sink) {
|
|
@@ -85,7 +87,7 @@ function readBfRange(reader, map, sink) {
|
|
|
85
87
|
function registerBfRangeSingle(map, lo, hi, dstBytes) {
|
|
86
88
|
if (dstBytes.length < 2) return;
|
|
87
89
|
const prefix = decodeUtf16BEString(dstBytes.subarray(0, dstBytes.length - 2));
|
|
88
|
-
const baseUnit = (dstBytes[dstBytes.length - 2] ?? 0) <<
|
|
90
|
+
const baseUnit = (dstBytes[dstBytes.length - 2] ?? 0) << BITS_PER_BYTE | (dstBytes[dstBytes.length - 1] ?? 0);
|
|
89
91
|
for (let code = lo; code <= hi; code++) map.set(code, prefix + String.fromCharCode(baseUnit + (code - lo)));
|
|
90
92
|
}
|
|
91
93
|
function readBfRangeArray(reader, map, lo, sink) {
|
package/dist/cmap.js
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { ByteReader } from "./bytes/reader.js";
|
|
2
2
|
import { nextToken } from "./lexer.js";
|
|
3
3
|
//#region src/cmap.ts
|
|
4
|
+
const BYTE_RADIX = 256;
|
|
5
|
+
const BITS_PER_BYTE = 8;
|
|
4
6
|
function hexBytesToNumber(bytes) {
|
|
5
7
|
let value = 0;
|
|
6
|
-
for (const byte of bytes) value = value *
|
|
8
|
+
for (const byte of bytes) value = value * BYTE_RADIX + byte;
|
|
7
9
|
return value;
|
|
8
10
|
}
|
|
9
11
|
function decodeUtf16BEString(bytes) {
|
|
10
12
|
const units = [];
|
|
11
|
-
for (let i = 0; i + 1 < bytes.length; i += 2) units.push((bytes[i] ?? 0) <<
|
|
13
|
+
for (let i = 0; i + 1 < bytes.length; i += 2) units.push((bytes[i] ?? 0) << BITS_PER_BYTE | (bytes[i + 1] ?? 0));
|
|
12
14
|
return String.fromCharCode(...units);
|
|
13
15
|
}
|
|
14
16
|
function parseToUnicodeCMap(bytes, sink) {
|
|
@@ -84,7 +86,7 @@ function readBfRange(reader, map, sink) {
|
|
|
84
86
|
function registerBfRangeSingle(map, lo, hi, dstBytes) {
|
|
85
87
|
if (dstBytes.length < 2) return;
|
|
86
88
|
const prefix = decodeUtf16BEString(dstBytes.subarray(0, dstBytes.length - 2));
|
|
87
|
-
const baseUnit = (dstBytes[dstBytes.length - 2] ?? 0) <<
|
|
89
|
+
const baseUnit = (dstBytes[dstBytes.length - 2] ?? 0) << BITS_PER_BYTE | (dstBytes[dstBytes.length - 1] ?? 0);
|
|
88
90
|
for (let code = lo; code <= hi; code++) map.set(code, prefix + String.fromCharCode(baseUnit + (code - lo)));
|
|
89
91
|
}
|
|
90
92
|
function readBfRangeArray(reader, map, lo, sink) {
|
package/dist/content-read.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PdfDiagnosticSink } from "./diagnostics.cjs";
|
|
2
|
-
import { n as PdfDict, r as PdfObject } from "./objects-
|
|
2
|
+
import { n as PdfDict, r as PdfObject } from "./objects-e2RS3-yT.cjs";
|
|
3
3
|
//#region src/content-read.d.ts
|
|
4
4
|
interface ContentOperation {
|
|
5
5
|
readonly operands: readonly PdfObject[];
|
package/dist/content-read.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PdfDiagnosticSink } from "./diagnostics.js";
|
|
2
|
-
import { n as PdfDict, r as PdfObject } from "./objects-
|
|
2
|
+
import { n as PdfDict, r as PdfObject } from "./objects-e2RS3-yT.js";
|
|
3
3
|
//#region src/content-read.d.ts
|
|
4
4
|
interface ContentOperation {
|
|
5
5
|
readonly operands: readonly PdfObject[];
|
package/dist/content-write.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_afm_widths = require("./afm-widths-
|
|
2
|
+
const require_afm_widths = require("./afm-widths-BHD2HZIL.cjs");
|
|
3
3
|
const require_objects = require("./objects.cjs");
|
|
4
4
|
const require_bytes_writer = require("./bytes/writer.cjs");
|
|
5
5
|
const require_serialize = require("./serialize.cjs");
|
|
@@ -8,6 +8,7 @@ const require_embedded_font = require("./embedded-font.cjs");
|
|
|
8
8
|
//#region src/content-write.ts
|
|
9
9
|
const GLYPH_SPACE_UNITS_PER_EM = 1e3;
|
|
10
10
|
const EMBEDDED_HORIZONTAL_SCALE_PERCENT = 100;
|
|
11
|
+
const PERCENT_SCALE_FACTOR = 100;
|
|
11
12
|
function writeRgbOperator(writer, color, operator) {
|
|
12
13
|
writer.writeAscii(`${require_serialize.formatNumber(color.r)} ${require_serialize.formatNumber(color.g)} ${require_serialize.formatNumber(color.b)} ${operator}\n`);
|
|
13
14
|
}
|
|
@@ -43,15 +44,15 @@ function writeShowTextBlock(writer, item, resourceName, scalePercent, show) {
|
|
|
43
44
|
writer.writeAscii(` ${show.operator}\n`);
|
|
44
45
|
writer.writeAscii("ET\n");
|
|
45
46
|
}
|
|
46
|
-
function writeStandardText(writer, item, standardName, resourceName, measurer
|
|
47
|
+
function writeStandardText(writer, item, standardName, resourceName, measurer) {
|
|
47
48
|
const encoded = require_afm_widths.encodeForShow(item.text, standardName);
|
|
48
|
-
substitutions.push(...encoded.substitutions);
|
|
49
49
|
const scale = measurer.horizontalScaleFor(item.font);
|
|
50
|
-
writeShowTextBlock(writer, item, resourceName, scale *
|
|
50
|
+
writeShowTextBlock(writer, item, resourceName, scale * PERCENT_SCALE_FACTOR, {
|
|
51
51
|
operand: require_objects.pdfHexString(encoded.codes),
|
|
52
52
|
operator: "Tj"
|
|
53
53
|
});
|
|
54
54
|
if (item.underline === true) writeUnderline(writer, item, item.widthPt ?? encoded.width1000 / GLYPH_SPACE_UNITS_PER_EM * item.sizePt * scale, measurer.underlineAtSize(item.font, item.sizePt));
|
|
55
|
+
return encoded.substitutions;
|
|
55
56
|
}
|
|
56
57
|
function embeddedShowOperand(encoded) {
|
|
57
58
|
if (encoded.kerns.length === 0) return {
|
|
@@ -71,22 +72,25 @@ function embeddedShowOperand(encoded) {
|
|
|
71
72
|
operator: "TJ"
|
|
72
73
|
};
|
|
73
74
|
}
|
|
74
|
-
function writeEmbeddedText(writer, item, face, resourceName
|
|
75
|
+
function writeEmbeddedText(writer, item, face, resourceName) {
|
|
75
76
|
const encoded = require_embedded_font.encodeForShowEmbedded(item.text, face);
|
|
76
|
-
missingGlyphs.push(...encoded.substitutions);
|
|
77
77
|
writeShowTextBlock(writer, item, resourceName, EMBEDDED_HORIZONTAL_SCALE_PERCENT, embeddedShowOperand(encoded));
|
|
78
78
|
if (item.underline === true) writeUnderline(writer, item, item.widthPt ?? encoded.width1000 / GLYPH_SPACE_UNITS_PER_EM * item.sizePt, {
|
|
79
79
|
offsetPt: face.metrics.underlinePositionGlyphSpace / GLYPH_SPACE_UNITS_PER_EM * item.sizePt,
|
|
80
80
|
thicknessPt: face.metrics.underlineThicknessGlyphSpace / GLYPH_SPACE_UNITS_PER_EM * item.sizePt
|
|
81
81
|
});
|
|
82
|
+
return encoded.substitutions;
|
|
82
83
|
}
|
|
83
|
-
function writeText(writer, item, context
|
|
84
|
+
function writeText(writer, item, context) {
|
|
84
85
|
const font = context.resolveFont(item.font);
|
|
85
|
-
if (font.kind === "embedded") {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
|
|
86
|
+
if (font.kind === "embedded") return {
|
|
87
|
+
substitutions: [],
|
|
88
|
+
missingGlyphs: writeEmbeddedText(writer, item, font.face, font.resourceName)
|
|
89
|
+
};
|
|
90
|
+
return {
|
|
91
|
+
substitutions: writeStandardText(writer, item, font.standardName, font.resourceName, context.measurer),
|
|
92
|
+
missingGlyphs: []
|
|
93
|
+
};
|
|
90
94
|
}
|
|
91
95
|
function paintOperatorFor(fill, stroke, fillRule) {
|
|
92
96
|
const evenOdd = fillRule === "evenodd";
|
|
@@ -332,8 +336,11 @@ function writeContentStream(items, context) {
|
|
|
332
336
|
if (layerObjectNum !== void 0) writer.writeAscii(` /OC ${layerObjectNum} 0 R`);
|
|
333
337
|
writer.writeAscii(" >> BDC\n");
|
|
334
338
|
}
|
|
335
|
-
if (item.kind === "text")
|
|
336
|
-
|
|
339
|
+
if (item.kind === "text") {
|
|
340
|
+
const written = writeText(writer, item, context);
|
|
341
|
+
substitutions.push(...written.substitutions);
|
|
342
|
+
missingGlyphs.push(...written.missingGlyphs);
|
|
343
|
+
} else if (item.kind === "image") writeImage(writer, item, context);
|
|
337
344
|
else if (item.kind === "rect") writeRect(writer, item);
|
|
338
345
|
else if (item.kind === "line") writeLine(writer, item);
|
|
339
346
|
else if (item.kind === "ellipse") writeEllipse(writer, item);
|
package/dist/content-write.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { r as StandardFontName } from "./afm-widths-CneRyu5l.cjs";
|
|
2
2
|
import { LayoutItem } from "./layout.cjs";
|
|
3
|
-
import { r as EmbeddedFaceSubstitution, t as EmbeddedFace } from "./embedded-font-
|
|
3
|
+
import { r as EmbeddedFaceSubstitution, t as EmbeddedFace } from "./embedded-font-DgVBedw6.cjs";
|
|
4
4
|
import { WinAnsiSubstitution } from "./winansi.cjs";
|
|
5
5
|
import { LayoutFont, TextMeasurer } from "document-schema.js";
|
|
6
6
|
//#region src/content-write.d.ts
|
|
@@ -18,7 +18,7 @@ interface ResolvedImageResource {
|
|
|
18
18
|
}
|
|
19
19
|
interface ContentWriteContext {
|
|
20
20
|
readonly measurer: TextMeasurer;
|
|
21
|
-
resolveFont: (font: LayoutFont) => ResolvedFontResource;
|
|
21
|
+
resolveFont: (font: Readonly<LayoutFont>) => ResolvedFontResource;
|
|
22
22
|
resolveImage: (imageId: string) => ResolvedImageResource;
|
|
23
23
|
readonly layerObjectNumberOf?: (name: string) => number | undefined;
|
|
24
24
|
readonly nextMcid?: () => number;
|
package/dist/content-write.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { r as StandardFontName } from "./afm-widths-CneRyu5l.js";
|
|
2
2
|
import { LayoutItem } from "./layout.js";
|
|
3
|
-
import { r as EmbeddedFaceSubstitution, t as EmbeddedFace } from "./embedded-font-
|
|
3
|
+
import { r as EmbeddedFaceSubstitution, t as EmbeddedFace } from "./embedded-font-ByD7ZiQS.js";
|
|
4
4
|
import { WinAnsiSubstitution } from "./winansi.js";
|
|
5
5
|
import { LayoutFont, TextMeasurer } from "document-schema.js";
|
|
6
6
|
//#region src/content-write.d.ts
|
|
@@ -18,7 +18,7 @@ interface ResolvedImageResource {
|
|
|
18
18
|
}
|
|
19
19
|
interface ContentWriteContext {
|
|
20
20
|
readonly measurer: TextMeasurer;
|
|
21
|
-
resolveFont: (font: LayoutFont) => ResolvedFontResource;
|
|
21
|
+
resolveFont: (font: Readonly<LayoutFont>) => ResolvedFontResource;
|
|
22
22
|
resolveImage: (imageId: string) => ResolvedImageResource;
|
|
23
23
|
readonly layerObjectNumberOf?: (name: string) => number | undefined;
|
|
24
24
|
readonly nextMcid?: () => number;
|
package/dist/content-write.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { h as encodeForShow } from "./afm-widths-
|
|
1
|
+
import { h as encodeForShow } from "./afm-widths-B_IGbGky.js";
|
|
2
2
|
import { pdfArray, pdfHexString, pdfNum } from "./objects.js";
|
|
3
3
|
import { ByteWriter } from "./bytes/writer.js";
|
|
4
4
|
import { formatNumber, writeObject } from "./serialize.js";
|
|
@@ -7,6 +7,7 @@ import { encodeForShowEmbedded } from "./embedded-font.js";
|
|
|
7
7
|
//#region src/content-write.ts
|
|
8
8
|
const GLYPH_SPACE_UNITS_PER_EM = 1e3;
|
|
9
9
|
const EMBEDDED_HORIZONTAL_SCALE_PERCENT = 100;
|
|
10
|
+
const PERCENT_SCALE_FACTOR = 100;
|
|
10
11
|
function writeRgbOperator(writer, color, operator) {
|
|
11
12
|
writer.writeAscii(`${formatNumber(color.r)} ${formatNumber(color.g)} ${formatNumber(color.b)} ${operator}\n`);
|
|
12
13
|
}
|
|
@@ -42,15 +43,15 @@ function writeShowTextBlock(writer, item, resourceName, scalePercent, show) {
|
|
|
42
43
|
writer.writeAscii(` ${show.operator}\n`);
|
|
43
44
|
writer.writeAscii("ET\n");
|
|
44
45
|
}
|
|
45
|
-
function writeStandardText(writer, item, standardName, resourceName, measurer
|
|
46
|
+
function writeStandardText(writer, item, standardName, resourceName, measurer) {
|
|
46
47
|
const encoded = encodeForShow(item.text, standardName);
|
|
47
|
-
substitutions.push(...encoded.substitutions);
|
|
48
48
|
const scale = measurer.horizontalScaleFor(item.font);
|
|
49
|
-
writeShowTextBlock(writer, item, resourceName, scale *
|
|
49
|
+
writeShowTextBlock(writer, item, resourceName, scale * PERCENT_SCALE_FACTOR, {
|
|
50
50
|
operand: pdfHexString(encoded.codes),
|
|
51
51
|
operator: "Tj"
|
|
52
52
|
});
|
|
53
53
|
if (item.underline === true) writeUnderline(writer, item, item.widthPt ?? encoded.width1000 / GLYPH_SPACE_UNITS_PER_EM * item.sizePt * scale, measurer.underlineAtSize(item.font, item.sizePt));
|
|
54
|
+
return encoded.substitutions;
|
|
54
55
|
}
|
|
55
56
|
function embeddedShowOperand(encoded) {
|
|
56
57
|
if (encoded.kerns.length === 0) return {
|
|
@@ -70,22 +71,25 @@ function embeddedShowOperand(encoded) {
|
|
|
70
71
|
operator: "TJ"
|
|
71
72
|
};
|
|
72
73
|
}
|
|
73
|
-
function writeEmbeddedText(writer, item, face, resourceName
|
|
74
|
+
function writeEmbeddedText(writer, item, face, resourceName) {
|
|
74
75
|
const encoded = encodeForShowEmbedded(item.text, face);
|
|
75
|
-
missingGlyphs.push(...encoded.substitutions);
|
|
76
76
|
writeShowTextBlock(writer, item, resourceName, EMBEDDED_HORIZONTAL_SCALE_PERCENT, embeddedShowOperand(encoded));
|
|
77
77
|
if (item.underline === true) writeUnderline(writer, item, item.widthPt ?? encoded.width1000 / GLYPH_SPACE_UNITS_PER_EM * item.sizePt, {
|
|
78
78
|
offsetPt: face.metrics.underlinePositionGlyphSpace / GLYPH_SPACE_UNITS_PER_EM * item.sizePt,
|
|
79
79
|
thicknessPt: face.metrics.underlineThicknessGlyphSpace / GLYPH_SPACE_UNITS_PER_EM * item.sizePt
|
|
80
80
|
});
|
|
81
|
+
return encoded.substitutions;
|
|
81
82
|
}
|
|
82
|
-
function writeText(writer, item, context
|
|
83
|
+
function writeText(writer, item, context) {
|
|
83
84
|
const font = context.resolveFont(item.font);
|
|
84
|
-
if (font.kind === "embedded") {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
|
|
85
|
+
if (font.kind === "embedded") return {
|
|
86
|
+
substitutions: [],
|
|
87
|
+
missingGlyphs: writeEmbeddedText(writer, item, font.face, font.resourceName)
|
|
88
|
+
};
|
|
89
|
+
return {
|
|
90
|
+
substitutions: writeStandardText(writer, item, font.standardName, font.resourceName, context.measurer),
|
|
91
|
+
missingGlyphs: []
|
|
92
|
+
};
|
|
89
93
|
}
|
|
90
94
|
function paintOperatorFor(fill, stroke, fillRule) {
|
|
91
95
|
const evenOdd = fillRule === "evenodd";
|
|
@@ -331,8 +335,11 @@ function writeContentStream(items, context) {
|
|
|
331
335
|
if (layerObjectNum !== void 0) writer.writeAscii(` /OC ${layerObjectNum} 0 R`);
|
|
332
336
|
writer.writeAscii(" >> BDC\n");
|
|
333
337
|
}
|
|
334
|
-
if (item.kind === "text")
|
|
335
|
-
|
|
338
|
+
if (item.kind === "text") {
|
|
339
|
+
const written = writeText(writer, item, context);
|
|
340
|
+
substitutions.push(...written.substitutions);
|
|
341
|
+
missingGlyphs.push(...written.missingGlyphs);
|
|
342
|
+
} else if (item.kind === "image") writeImage(writer, item, context);
|
|
336
343
|
else if (item.kind === "rect") writeRect(writer, item);
|
|
337
344
|
else if (item.kind === "line") writeLine(writer, item);
|
|
338
345
|
else if (item.kind === "ellipse") writeEllipse(writer, item);
|