pdf-codec 3.5.3 → 3.6.0
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/README.md +12 -2
- package/dist/{afm-widths-W02fJh-k.cjs → afm-widths-BTu0IDp2.cjs} +570 -1
- package/dist/{afm-widths-B6KdmpRF.js → afm-widths-De_QMWgC.js} +541 -2
- package/dist/afm-widths.cjs +1 -1
- package/dist/afm-widths.js +1 -1
- package/dist/builtin-encoding.cjs +221 -0
- package/dist/builtin-encoding.d.cts +8 -0
- package/dist/builtin-encoding.d.ts +8 -0
- package/dist/builtin-encoding.js +220 -0
- package/dist/cff.cjs +14 -0
- package/dist/cff.d.cts +4 -1
- package/dist/cff.d.ts +4 -1
- package/dist/cff.js +12 -1
- package/dist/cmap-table.cjs +76 -13
- package/dist/cmap-table.d.cts +9 -1
- package/dist/cmap-table.d.ts +9 -1
- package/dist/cmap-table.js +77 -15
- package/dist/codec.d.cts +2 -0
- package/dist/codec.d.ts +2 -0
- package/dist/content-write.cjs +1 -1
- package/dist/content-write.js +1 -1
- package/dist/encoding.cjs +6 -1
- package/dist/encoding.d.cts +6 -1
- package/dist/encoding.d.ts +6 -1
- package/dist/encoding.js +2 -2
- package/dist/font-read.cjs +56 -11
- package/dist/font-read.js +57 -12
- package/dist/font-tables.cjs +31 -0
- package/dist/font-tables.d.cts +3 -1
- package/dist/font-tables.d.ts +3 -1
- package/dist/font-tables.js +31 -2
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/interpret.cjs +72 -41
- package/dist/interpret.js +72 -41
- package/dist/layout.d.cts +4 -0
- package/dist/layout.d.ts +4 -0
- package/dist/math-font.cjs +1 -1
- package/dist/math-font.js +1 -1
- package/dist/measure.cjs +1 -1
- package/dist/measure.js +1 -1
- package/dist/winansi.cjs +1 -1
- package/dist/winansi.js +1 -1
- package/dist/write.cjs +1 -1
- package/dist/write.js +1 -1
- package/package.json +2 -2
package/dist/font-tables.cjs
CHANGED
|
@@ -64,6 +64,35 @@ function parsePost(font) {
|
|
|
64
64
|
underlineThickness: require_sfnt.i16(bytes, 10)
|
|
65
65
|
};
|
|
66
66
|
}
|
|
67
|
+
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(" ");
|
|
68
|
+
const POST_VERSION_MAC_STANDARD_ORDER = 65536;
|
|
69
|
+
const POST_VERSION_CUSTOM_NAMES = 131072;
|
|
70
|
+
function parsePostGlyphNames(font) {
|
|
71
|
+
const bytes = require_sfnt.sfntTableBytes(font, "post");
|
|
72
|
+
if (bytes === void 0 || !require_sfnt.hasBytes(bytes, 0, POST_HEADER_SIZE)) return;
|
|
73
|
+
const version = require_sfnt.u32(bytes, 0);
|
|
74
|
+
if (version === POST_VERSION_MAC_STANDARD_ORDER) return (glyphId) => MAC_STANDARD_GLYPH_ORDER[glyphId];
|
|
75
|
+
if (version !== POST_VERSION_CUSTOM_NAMES) return;
|
|
76
|
+
if (!require_sfnt.hasBytes(bytes, POST_HEADER_SIZE, 2)) return;
|
|
77
|
+
const numGlyphs = require_sfnt.u16(bytes, POST_HEADER_SIZE);
|
|
78
|
+
const indicesOffset = 34;
|
|
79
|
+
if (!require_sfnt.hasBytes(bytes, indicesOffset, numGlyphs * 2)) return;
|
|
80
|
+
const names = [];
|
|
81
|
+
let cursor = indicesOffset + numGlyphs * 2;
|
|
82
|
+
while (require_sfnt.hasBytes(bytes, cursor, 1)) {
|
|
83
|
+
const length = require_sfnt.u8(bytes, cursor);
|
|
84
|
+
if (!require_sfnt.hasBytes(bytes, cursor + 1, length)) break;
|
|
85
|
+
let name = "";
|
|
86
|
+
for (let i = 0; i < length; i++) name += String.fromCharCode(require_sfnt.u8(bytes, cursor + 1 + i));
|
|
87
|
+
names.push(name);
|
|
88
|
+
cursor += 1 + length;
|
|
89
|
+
}
|
|
90
|
+
return (glyphId) => {
|
|
91
|
+
if (glyphId < 0 || glyphId >= numGlyphs) return;
|
|
92
|
+
const index = require_sfnt.u16(bytes, indicesOffset + glyphId * 2);
|
|
93
|
+
return index < MAC_STANDARD_GLYPH_ORDER.length ? MAC_STANDARD_GLYPH_ORDER[index] : names[index - MAC_STANDARD_GLYPH_ORDER.length];
|
|
94
|
+
};
|
|
95
|
+
}
|
|
67
96
|
const NAME_HEADER_SIZE = 6;
|
|
68
97
|
const NAME_RECORD_SIZE = 12;
|
|
69
98
|
const NAME_ID_FAMILY = 1;
|
|
@@ -121,8 +150,10 @@ function parseName(font) {
|
|
|
121
150
|
};
|
|
122
151
|
}
|
|
123
152
|
//#endregion
|
|
153
|
+
exports.MAC_STANDARD_GLYPH_ORDER = MAC_STANDARD_GLYPH_ORDER;
|
|
124
154
|
exports.parseHead = parseHead;
|
|
125
155
|
exports.parseMaxp = parseMaxp;
|
|
126
156
|
exports.parseName = parseName;
|
|
127
157
|
exports.parseOs2 = parseOs2;
|
|
128
158
|
exports.parsePost = parsePost;
|
|
159
|
+
exports.parsePostGlyphNames = parsePostGlyphNames;
|
package/dist/font-tables.d.cts
CHANGED
|
@@ -35,10 +35,12 @@ interface PostTable {
|
|
|
35
35
|
readonly underlineThickness: number;
|
|
36
36
|
}
|
|
37
37
|
declare function parsePost(font: SfntFont): PostTable | undefined;
|
|
38
|
+
declare const MAC_STANDARD_GLYPH_ORDER: readonly string[];
|
|
39
|
+
declare function parsePostGlyphNames(font: SfntFont): ((glyphId: number) => string | undefined) | undefined;
|
|
38
40
|
interface NameTable {
|
|
39
41
|
readonly postScriptName: string | undefined;
|
|
40
42
|
readonly familyName: string | undefined;
|
|
41
43
|
}
|
|
42
44
|
declare function parseName(font: SfntFont): NameTable | undefined;
|
|
43
45
|
//#endregion
|
|
44
|
-
export { HeadTable, MaxpTable, NameTable, Os2Table, PostTable, parseHead, parseMaxp, parseName, parseOs2, parsePost };
|
|
46
|
+
export { HeadTable, MAC_STANDARD_GLYPH_ORDER, MaxpTable, NameTable, Os2Table, PostTable, parseHead, parseMaxp, parseName, parseOs2, parsePost, parsePostGlyphNames };
|
package/dist/font-tables.d.ts
CHANGED
|
@@ -35,10 +35,12 @@ interface PostTable {
|
|
|
35
35
|
readonly underlineThickness: number;
|
|
36
36
|
}
|
|
37
37
|
declare function parsePost(font: SfntFont): PostTable | undefined;
|
|
38
|
+
declare const MAC_STANDARD_GLYPH_ORDER: readonly string[];
|
|
39
|
+
declare function parsePostGlyphNames(font: SfntFont): ((glyphId: number) => string | undefined) | undefined;
|
|
38
40
|
interface NameTable {
|
|
39
41
|
readonly postScriptName: string | undefined;
|
|
40
42
|
readonly familyName: string | undefined;
|
|
41
43
|
}
|
|
42
44
|
declare function parseName(font: SfntFont): NameTable | undefined;
|
|
43
45
|
//#endregion
|
|
44
|
-
export { HeadTable, MaxpTable, NameTable, Os2Table, PostTable, parseHead, parseMaxp, parseName, parseOs2, parsePost };
|
|
46
|
+
export { HeadTable, MAC_STANDARD_GLYPH_ORDER, MaxpTable, NameTable, Os2Table, PostTable, parseHead, parseMaxp, parseName, parseOs2, parsePost, parsePostGlyphNames };
|
package/dist/font-tables.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { hasBytes, i16, i32, sfntTableBytes, u16, u32 } from "./sfnt.js";
|
|
1
|
+
import { hasBytes, i16, i32, sfntTableBytes, u16, u32, u8 } from "./sfnt.js";
|
|
2
2
|
//#region src/font-tables.ts
|
|
3
3
|
const HEAD_TABLE_SIZE = 54;
|
|
4
4
|
const HEAD_MAGIC_NUMBER = 1594834165;
|
|
@@ -63,6 +63,35 @@ function parsePost(font) {
|
|
|
63
63
|
underlineThickness: i16(bytes, 10)
|
|
64
64
|
};
|
|
65
65
|
}
|
|
66
|
+
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(" ");
|
|
67
|
+
const POST_VERSION_MAC_STANDARD_ORDER = 65536;
|
|
68
|
+
const POST_VERSION_CUSTOM_NAMES = 131072;
|
|
69
|
+
function parsePostGlyphNames(font) {
|
|
70
|
+
const bytes = sfntTableBytes(font, "post");
|
|
71
|
+
if (bytes === void 0 || !hasBytes(bytes, 0, POST_HEADER_SIZE)) return;
|
|
72
|
+
const version = u32(bytes, 0);
|
|
73
|
+
if (version === POST_VERSION_MAC_STANDARD_ORDER) return (glyphId) => MAC_STANDARD_GLYPH_ORDER[glyphId];
|
|
74
|
+
if (version !== POST_VERSION_CUSTOM_NAMES) return;
|
|
75
|
+
if (!hasBytes(bytes, POST_HEADER_SIZE, 2)) return;
|
|
76
|
+
const numGlyphs = u16(bytes, POST_HEADER_SIZE);
|
|
77
|
+
const indicesOffset = 34;
|
|
78
|
+
if (!hasBytes(bytes, indicesOffset, numGlyphs * 2)) return;
|
|
79
|
+
const names = [];
|
|
80
|
+
let cursor = indicesOffset + numGlyphs * 2;
|
|
81
|
+
while (hasBytes(bytes, cursor, 1)) {
|
|
82
|
+
const length = u8(bytes, cursor);
|
|
83
|
+
if (!hasBytes(bytes, cursor + 1, length)) break;
|
|
84
|
+
let name = "";
|
|
85
|
+
for (let i = 0; i < length; i++) name += String.fromCharCode(u8(bytes, cursor + 1 + i));
|
|
86
|
+
names.push(name);
|
|
87
|
+
cursor += 1 + length;
|
|
88
|
+
}
|
|
89
|
+
return (glyphId) => {
|
|
90
|
+
if (glyphId < 0 || glyphId >= numGlyphs) return;
|
|
91
|
+
const index = u16(bytes, indicesOffset + glyphId * 2);
|
|
92
|
+
return index < MAC_STANDARD_GLYPH_ORDER.length ? MAC_STANDARD_GLYPH_ORDER[index] : names[index - MAC_STANDARD_GLYPH_ORDER.length];
|
|
93
|
+
};
|
|
94
|
+
}
|
|
66
95
|
const NAME_HEADER_SIZE = 6;
|
|
67
96
|
const NAME_RECORD_SIZE = 12;
|
|
68
97
|
const NAME_ID_FAMILY = 1;
|
|
@@ -120,4 +149,4 @@ function parseName(font) {
|
|
|
120
149
|
};
|
|
121
150
|
}
|
|
122
151
|
//#endregion
|
|
123
|
-
export { parseHead, parseMaxp, parseName, parseOs2, parsePost };
|
|
152
|
+
export { MAC_STANDARD_GLYPH_ORDER, parseHead, parseMaxp, parseName, parseOs2, parsePost, parsePostGlyphNames };
|
package/dist/index.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-BTu0IDp2.cjs");
|
|
3
3
|
const require_image_ccitt = require("./image/ccitt.cjs");
|
|
4
4
|
const require_image_jbig2_errors = require("./image/jbig2-errors.cjs");
|
|
5
5
|
const require_image_jbig2 = require("./image/jbig2.cjs");
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as STANDARD_METRICS } from "./afm-widths-
|
|
1
|
+
import { t as STANDARD_METRICS } from "./afm-widths-De_QMWgC.js";
|
|
2
2
|
import { decodeCcittFax } from "./image/ccitt.js";
|
|
3
3
|
import { Jbig2ParseError, Jbig2UnsupportedError } from "./image/jbig2-errors.js";
|
|
4
4
|
import { decodeJbig2Embedded } from "./image/jbig2.js";
|
package/dist/interpret.cjs
CHANGED
|
@@ -9,10 +9,8 @@ let document_schema_js = require("document-schema.js");
|
|
|
9
9
|
const MAX_FORM_XOBJECT_DEPTH = 12;
|
|
10
10
|
const FALLBACK_GLYPH_WIDTH_PER_1000 = 500;
|
|
11
11
|
const DEFAULT_LINE_WIDTH_PT = 1;
|
|
12
|
-
function
|
|
12
|
+
function initialTextParameters() {
|
|
13
13
|
return {
|
|
14
|
-
tm: require_matrix.IDENTITY_MATRIX,
|
|
15
|
-
tlm: require_matrix.IDENTITY_MATRIX,
|
|
16
14
|
fontResourceName: void 0,
|
|
17
15
|
fontSizePt: 0,
|
|
18
16
|
charSpace: 0,
|
|
@@ -22,16 +20,22 @@ function defaultTextState() {
|
|
|
22
20
|
rise: 0
|
|
23
21
|
};
|
|
24
22
|
}
|
|
25
|
-
function
|
|
23
|
+
function defaultTextObjectState() {
|
|
24
|
+
return {
|
|
25
|
+
tm: require_matrix.IDENTITY_MATRIX,
|
|
26
|
+
tlm: require_matrix.IDENTITY_MATRIX
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function computeTrm(gs, text) {
|
|
26
30
|
const fontMatrix = [
|
|
27
|
-
|
|
31
|
+
gs.fontSizePt * gs.horizScale,
|
|
28
32
|
0,
|
|
29
33
|
0,
|
|
30
|
-
|
|
34
|
+
gs.fontSizePt,
|
|
31
35
|
0,
|
|
32
|
-
|
|
36
|
+
gs.rise
|
|
33
37
|
];
|
|
34
|
-
return require_matrix.multiplyMatrices(require_matrix.multiplyMatrices(fontMatrix,
|
|
38
|
+
return require_matrix.multiplyMatrices(require_matrix.multiplyMatrices(fontMatrix, text.tm), gs.ctm);
|
|
35
39
|
}
|
|
36
40
|
function numAt(operands, index) {
|
|
37
41
|
return require_objects.asNumber(operands[index]) ?? 0;
|
|
@@ -271,7 +275,8 @@ function interpretContentStream(bytes, resources, context) {
|
|
|
271
275
|
ctm: require_matrix.IDENTITY_MATRIX,
|
|
272
276
|
fillColor: document_schema_js.COLOR_BLACK,
|
|
273
277
|
strokeColor: document_schema_js.COLOR_BLACK,
|
|
274
|
-
lineWidth: DEFAULT_LINE_WIDTH_PT
|
|
278
|
+
lineWidth: DEFAULT_LINE_WIDTH_PT,
|
|
279
|
+
...initialTextParameters()
|
|
275
280
|
}, context, items, 0, []);
|
|
276
281
|
return items;
|
|
277
282
|
}
|
|
@@ -289,7 +294,7 @@ function runContentStream(bytes, resources, initialState, context, items, depth,
|
|
|
289
294
|
const operations = require_content_read.readContentStream(bytes, context.sink);
|
|
290
295
|
const gsStack = [];
|
|
291
296
|
let gs = initialState;
|
|
292
|
-
let
|
|
297
|
+
let text = defaultTextObjectState();
|
|
293
298
|
let pathSubpaths = [];
|
|
294
299
|
let currentSubpath;
|
|
295
300
|
const inScope = (key) => {
|
|
@@ -407,26 +412,28 @@ function runContentStream(bytes, resources, initialState, context, items, depth,
|
|
|
407
412
|
resetPath();
|
|
408
413
|
};
|
|
409
414
|
const advanceThroughString = (codes) => {
|
|
410
|
-
|
|
415
|
+
const fontResourceName = gs.fontResourceName;
|
|
416
|
+
if (fontResourceName === void 0) return;
|
|
411
417
|
let offset = 0;
|
|
412
418
|
while (offset < codes.length) {
|
|
413
|
-
const glyph = context.fontMetrics.glyphAdvance(
|
|
419
|
+
const glyph = context.fontMetrics.glyphAdvance(fontResourceName, resources, codes, offset);
|
|
414
420
|
if (glyph === void 0) context.sink({
|
|
415
421
|
code: "pdf/font-not-resolved",
|
|
416
422
|
severity: "warning",
|
|
417
|
-
message: `could not resolve font resource /${
|
|
423
|
+
message: `could not resolve font resource /${fontResourceName} to compute a glyph advance; assuming a fallback width`
|
|
418
424
|
});
|
|
419
425
|
const widthPer1000 = glyph?.widthPer1000 ?? FALLBACK_GLYPH_WIDTH_PER_1000;
|
|
420
426
|
const byteLength = glyph?.byteLengthConsumed ?? 1;
|
|
421
427
|
const isSingleByteSpace = byteLength === 1 && codes[offset] === 32;
|
|
422
|
-
const tx = (widthPer1000 / 1e3 *
|
|
423
|
-
|
|
428
|
+
const tx = (widthPer1000 / 1e3 * gs.fontSizePt + gs.charSpace + (isSingleByteSpace ? gs.wordSpace : 0)) * gs.horizScale;
|
|
429
|
+
text.tm = require_matrix.multiplyMatrices(require_matrix.translationMatrix(tx, 0), text.tm);
|
|
424
430
|
offset += byteLength;
|
|
425
431
|
}
|
|
426
432
|
};
|
|
427
433
|
const showTextArray = (elements) => {
|
|
428
|
-
|
|
429
|
-
|
|
434
|
+
const fontResourceName = gs.fontResourceName;
|
|
435
|
+
if (fontResourceName === void 0) return;
|
|
436
|
+
const startMatrix = computeTrm(gs, text);
|
|
430
437
|
const chunks = [];
|
|
431
438
|
let totalLength = 0;
|
|
432
439
|
for (const el of elements) if (el.kind === "string") {
|
|
@@ -434,8 +441,8 @@ function runContentStream(bytes, resources, initialState, context, items, depth,
|
|
|
434
441
|
totalLength += el.bytes.length;
|
|
435
442
|
advanceThroughString(el.bytes);
|
|
436
443
|
} else if (el.kind === "number") {
|
|
437
|
-
const adjustment = -(el.value / 1e3) *
|
|
438
|
-
|
|
444
|
+
const adjustment = -(el.value / 1e3) * gs.fontSizePt * gs.horizScale;
|
|
445
|
+
text.tm = require_matrix.multiplyMatrices(require_matrix.translationMatrix(adjustment, 0), text.tm);
|
|
439
446
|
}
|
|
440
447
|
if (totalLength === 0) return;
|
|
441
448
|
const combined = new Uint8Array(totalLength);
|
|
@@ -444,15 +451,15 @@ function runContentStream(bytes, resources, initialState, context, items, depth,
|
|
|
444
451
|
combined.set(chunk, at);
|
|
445
452
|
at += chunk.length;
|
|
446
453
|
}
|
|
447
|
-
const endMatrix = computeTrm(gs
|
|
454
|
+
const endMatrix = computeTrm(gs, text);
|
|
448
455
|
pushItem({
|
|
449
456
|
kind: "text",
|
|
450
457
|
codes: combined,
|
|
451
|
-
fontResourceName
|
|
458
|
+
fontResourceName,
|
|
452
459
|
resources,
|
|
453
460
|
startMatrix,
|
|
454
461
|
endMatrix,
|
|
455
|
-
sizePt:
|
|
462
|
+
sizePt: gs.fontSizePt,
|
|
456
463
|
color: gs.fillColor
|
|
457
464
|
});
|
|
458
465
|
};
|
|
@@ -464,8 +471,8 @@ function runContentStream(bytes, resources, initialState, context, items, depth,
|
|
|
464
471
|
}]);
|
|
465
472
|
};
|
|
466
473
|
const nextLine = () => {
|
|
467
|
-
|
|
468
|
-
|
|
474
|
+
text.tlm = require_matrix.multiplyMatrices(require_matrix.translationMatrix(0, -gs.leading), text.tlm);
|
|
475
|
+
text.tm = text.tlm;
|
|
469
476
|
};
|
|
470
477
|
const handleDo = (name) => {
|
|
471
478
|
if (name === void 0) return;
|
|
@@ -711,39 +718,60 @@ function runContentStream(bytes, resources, initialState, context, items, depth,
|
|
|
711
718
|
emitPaint(operator);
|
|
712
719
|
break;
|
|
713
720
|
case "BT":
|
|
714
|
-
|
|
721
|
+
text = defaultTextObjectState();
|
|
715
722
|
break;
|
|
716
723
|
case "Tf":
|
|
717
|
-
|
|
718
|
-
|
|
724
|
+
gs = {
|
|
725
|
+
...gs,
|
|
726
|
+
fontResourceName: require_objects.asName(operands[0]),
|
|
727
|
+
fontSizePt: numAt(operands, 1)
|
|
728
|
+
};
|
|
719
729
|
break;
|
|
720
730
|
case "Tc":
|
|
721
|
-
|
|
731
|
+
gs = {
|
|
732
|
+
...gs,
|
|
733
|
+
charSpace: numAt(operands, 0)
|
|
734
|
+
};
|
|
722
735
|
break;
|
|
723
736
|
case "Tw":
|
|
724
|
-
|
|
737
|
+
gs = {
|
|
738
|
+
...gs,
|
|
739
|
+
wordSpace: numAt(operands, 0)
|
|
740
|
+
};
|
|
725
741
|
break;
|
|
726
742
|
case "Tz":
|
|
727
|
-
|
|
743
|
+
gs = {
|
|
744
|
+
...gs,
|
|
745
|
+
horizScale: numAt(operands, 0) / 100
|
|
746
|
+
};
|
|
728
747
|
break;
|
|
729
748
|
case "TL":
|
|
730
|
-
|
|
749
|
+
gs = {
|
|
750
|
+
...gs,
|
|
751
|
+
leading: numAt(operands, 0)
|
|
752
|
+
};
|
|
731
753
|
break;
|
|
732
754
|
case "Ts":
|
|
733
|
-
|
|
755
|
+
gs = {
|
|
756
|
+
...gs,
|
|
757
|
+
rise: numAt(operands, 0)
|
|
758
|
+
};
|
|
734
759
|
break;
|
|
735
760
|
case "Td":
|
|
736
|
-
|
|
737
|
-
|
|
761
|
+
text.tlm = require_matrix.multiplyMatrices(require_matrix.translationMatrix(numAt(operands, 0), numAt(operands, 1)), text.tlm);
|
|
762
|
+
text.tm = text.tlm;
|
|
738
763
|
break;
|
|
739
764
|
case "TD":
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
765
|
+
gs = {
|
|
766
|
+
...gs,
|
|
767
|
+
leading: -numAt(operands, 1)
|
|
768
|
+
};
|
|
769
|
+
text.tlm = require_matrix.multiplyMatrices(require_matrix.translationMatrix(numAt(operands, 0), numAt(operands, 1)), text.tlm);
|
|
770
|
+
text.tm = text.tlm;
|
|
743
771
|
break;
|
|
744
772
|
case "Tm":
|
|
745
|
-
|
|
746
|
-
|
|
773
|
+
text.tlm = matrixFromOperands(operands);
|
|
774
|
+
text.tm = text.tlm;
|
|
747
775
|
break;
|
|
748
776
|
case "T*":
|
|
749
777
|
nextLine();
|
|
@@ -760,8 +788,11 @@ function runContentStream(bytes, resources, initialState, context, items, depth,
|
|
|
760
788
|
break;
|
|
761
789
|
}
|
|
762
790
|
case "\"": {
|
|
763
|
-
|
|
764
|
-
|
|
791
|
+
gs = {
|
|
792
|
+
...gs,
|
|
793
|
+
wordSpace: numAt(operands, 0),
|
|
794
|
+
charSpace: numAt(operands, 1)
|
|
795
|
+
};
|
|
765
796
|
nextLine();
|
|
766
797
|
const str = operands[2];
|
|
767
798
|
if (str?.kind === "string") showText(str.bytes);
|
package/dist/interpret.js
CHANGED
|
@@ -8,10 +8,8 @@ import { COLOR_BLACK } from "document-schema.js";
|
|
|
8
8
|
const MAX_FORM_XOBJECT_DEPTH = 12;
|
|
9
9
|
const FALLBACK_GLYPH_WIDTH_PER_1000 = 500;
|
|
10
10
|
const DEFAULT_LINE_WIDTH_PT = 1;
|
|
11
|
-
function
|
|
11
|
+
function initialTextParameters() {
|
|
12
12
|
return {
|
|
13
|
-
tm: IDENTITY_MATRIX,
|
|
14
|
-
tlm: IDENTITY_MATRIX,
|
|
15
13
|
fontResourceName: void 0,
|
|
16
14
|
fontSizePt: 0,
|
|
17
15
|
charSpace: 0,
|
|
@@ -21,16 +19,22 @@ function defaultTextState() {
|
|
|
21
19
|
rise: 0
|
|
22
20
|
};
|
|
23
21
|
}
|
|
24
|
-
function
|
|
22
|
+
function defaultTextObjectState() {
|
|
23
|
+
return {
|
|
24
|
+
tm: IDENTITY_MATRIX,
|
|
25
|
+
tlm: IDENTITY_MATRIX
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function computeTrm(gs, text) {
|
|
25
29
|
const fontMatrix = [
|
|
26
|
-
|
|
30
|
+
gs.fontSizePt * gs.horizScale,
|
|
27
31
|
0,
|
|
28
32
|
0,
|
|
29
|
-
|
|
33
|
+
gs.fontSizePt,
|
|
30
34
|
0,
|
|
31
|
-
|
|
35
|
+
gs.rise
|
|
32
36
|
];
|
|
33
|
-
return multiplyMatrices(multiplyMatrices(fontMatrix,
|
|
37
|
+
return multiplyMatrices(multiplyMatrices(fontMatrix, text.tm), gs.ctm);
|
|
34
38
|
}
|
|
35
39
|
function numAt(operands, index) {
|
|
36
40
|
return asNumber(operands[index]) ?? 0;
|
|
@@ -270,7 +274,8 @@ function interpretContentStream(bytes, resources, context) {
|
|
|
270
274
|
ctm: IDENTITY_MATRIX,
|
|
271
275
|
fillColor: COLOR_BLACK,
|
|
272
276
|
strokeColor: COLOR_BLACK,
|
|
273
|
-
lineWidth: DEFAULT_LINE_WIDTH_PT
|
|
277
|
+
lineWidth: DEFAULT_LINE_WIDTH_PT,
|
|
278
|
+
...initialTextParameters()
|
|
274
279
|
}, context, items, 0, []);
|
|
275
280
|
return items;
|
|
276
281
|
}
|
|
@@ -288,7 +293,7 @@ function runContentStream(bytes, resources, initialState, context, items, depth,
|
|
|
288
293
|
const operations = readContentStream(bytes, context.sink);
|
|
289
294
|
const gsStack = [];
|
|
290
295
|
let gs = initialState;
|
|
291
|
-
let
|
|
296
|
+
let text = defaultTextObjectState();
|
|
292
297
|
let pathSubpaths = [];
|
|
293
298
|
let currentSubpath;
|
|
294
299
|
const inScope = (key) => {
|
|
@@ -406,26 +411,28 @@ function runContentStream(bytes, resources, initialState, context, items, depth,
|
|
|
406
411
|
resetPath();
|
|
407
412
|
};
|
|
408
413
|
const advanceThroughString = (codes) => {
|
|
409
|
-
|
|
414
|
+
const fontResourceName = gs.fontResourceName;
|
|
415
|
+
if (fontResourceName === void 0) return;
|
|
410
416
|
let offset = 0;
|
|
411
417
|
while (offset < codes.length) {
|
|
412
|
-
const glyph = context.fontMetrics.glyphAdvance(
|
|
418
|
+
const glyph = context.fontMetrics.glyphAdvance(fontResourceName, resources, codes, offset);
|
|
413
419
|
if (glyph === void 0) context.sink({
|
|
414
420
|
code: "pdf/font-not-resolved",
|
|
415
421
|
severity: "warning",
|
|
416
|
-
message: `could not resolve font resource /${
|
|
422
|
+
message: `could not resolve font resource /${fontResourceName} to compute a glyph advance; assuming a fallback width`
|
|
417
423
|
});
|
|
418
424
|
const widthPer1000 = glyph?.widthPer1000 ?? FALLBACK_GLYPH_WIDTH_PER_1000;
|
|
419
425
|
const byteLength = glyph?.byteLengthConsumed ?? 1;
|
|
420
426
|
const isSingleByteSpace = byteLength === 1 && codes[offset] === 32;
|
|
421
|
-
const tx = (widthPer1000 / 1e3 *
|
|
422
|
-
|
|
427
|
+
const tx = (widthPer1000 / 1e3 * gs.fontSizePt + gs.charSpace + (isSingleByteSpace ? gs.wordSpace : 0)) * gs.horizScale;
|
|
428
|
+
text.tm = multiplyMatrices(translationMatrix(tx, 0), text.tm);
|
|
423
429
|
offset += byteLength;
|
|
424
430
|
}
|
|
425
431
|
};
|
|
426
432
|
const showTextArray = (elements) => {
|
|
427
|
-
|
|
428
|
-
|
|
433
|
+
const fontResourceName = gs.fontResourceName;
|
|
434
|
+
if (fontResourceName === void 0) return;
|
|
435
|
+
const startMatrix = computeTrm(gs, text);
|
|
429
436
|
const chunks = [];
|
|
430
437
|
let totalLength = 0;
|
|
431
438
|
for (const el of elements) if (el.kind === "string") {
|
|
@@ -433,8 +440,8 @@ function runContentStream(bytes, resources, initialState, context, items, depth,
|
|
|
433
440
|
totalLength += el.bytes.length;
|
|
434
441
|
advanceThroughString(el.bytes);
|
|
435
442
|
} else if (el.kind === "number") {
|
|
436
|
-
const adjustment = -(el.value / 1e3) *
|
|
437
|
-
|
|
443
|
+
const adjustment = -(el.value / 1e3) * gs.fontSizePt * gs.horizScale;
|
|
444
|
+
text.tm = multiplyMatrices(translationMatrix(adjustment, 0), text.tm);
|
|
438
445
|
}
|
|
439
446
|
if (totalLength === 0) return;
|
|
440
447
|
const combined = new Uint8Array(totalLength);
|
|
@@ -443,15 +450,15 @@ function runContentStream(bytes, resources, initialState, context, items, depth,
|
|
|
443
450
|
combined.set(chunk, at);
|
|
444
451
|
at += chunk.length;
|
|
445
452
|
}
|
|
446
|
-
const endMatrix = computeTrm(gs
|
|
453
|
+
const endMatrix = computeTrm(gs, text);
|
|
447
454
|
pushItem({
|
|
448
455
|
kind: "text",
|
|
449
456
|
codes: combined,
|
|
450
|
-
fontResourceName
|
|
457
|
+
fontResourceName,
|
|
451
458
|
resources,
|
|
452
459
|
startMatrix,
|
|
453
460
|
endMatrix,
|
|
454
|
-
sizePt:
|
|
461
|
+
sizePt: gs.fontSizePt,
|
|
455
462
|
color: gs.fillColor
|
|
456
463
|
});
|
|
457
464
|
};
|
|
@@ -463,8 +470,8 @@ function runContentStream(bytes, resources, initialState, context, items, depth,
|
|
|
463
470
|
}]);
|
|
464
471
|
};
|
|
465
472
|
const nextLine = () => {
|
|
466
|
-
|
|
467
|
-
|
|
473
|
+
text.tlm = multiplyMatrices(translationMatrix(0, -gs.leading), text.tlm);
|
|
474
|
+
text.tm = text.tlm;
|
|
468
475
|
};
|
|
469
476
|
const handleDo = (name) => {
|
|
470
477
|
if (name === void 0) return;
|
|
@@ -710,39 +717,60 @@ function runContentStream(bytes, resources, initialState, context, items, depth,
|
|
|
710
717
|
emitPaint(operator);
|
|
711
718
|
break;
|
|
712
719
|
case "BT":
|
|
713
|
-
|
|
720
|
+
text = defaultTextObjectState();
|
|
714
721
|
break;
|
|
715
722
|
case "Tf":
|
|
716
|
-
|
|
717
|
-
|
|
723
|
+
gs = {
|
|
724
|
+
...gs,
|
|
725
|
+
fontResourceName: asName(operands[0]),
|
|
726
|
+
fontSizePt: numAt(operands, 1)
|
|
727
|
+
};
|
|
718
728
|
break;
|
|
719
729
|
case "Tc":
|
|
720
|
-
|
|
730
|
+
gs = {
|
|
731
|
+
...gs,
|
|
732
|
+
charSpace: numAt(operands, 0)
|
|
733
|
+
};
|
|
721
734
|
break;
|
|
722
735
|
case "Tw":
|
|
723
|
-
|
|
736
|
+
gs = {
|
|
737
|
+
...gs,
|
|
738
|
+
wordSpace: numAt(operands, 0)
|
|
739
|
+
};
|
|
724
740
|
break;
|
|
725
741
|
case "Tz":
|
|
726
|
-
|
|
742
|
+
gs = {
|
|
743
|
+
...gs,
|
|
744
|
+
horizScale: numAt(operands, 0) / 100
|
|
745
|
+
};
|
|
727
746
|
break;
|
|
728
747
|
case "TL":
|
|
729
|
-
|
|
748
|
+
gs = {
|
|
749
|
+
...gs,
|
|
750
|
+
leading: numAt(operands, 0)
|
|
751
|
+
};
|
|
730
752
|
break;
|
|
731
753
|
case "Ts":
|
|
732
|
-
|
|
754
|
+
gs = {
|
|
755
|
+
...gs,
|
|
756
|
+
rise: numAt(operands, 0)
|
|
757
|
+
};
|
|
733
758
|
break;
|
|
734
759
|
case "Td":
|
|
735
|
-
|
|
736
|
-
|
|
760
|
+
text.tlm = multiplyMatrices(translationMatrix(numAt(operands, 0), numAt(operands, 1)), text.tlm);
|
|
761
|
+
text.tm = text.tlm;
|
|
737
762
|
break;
|
|
738
763
|
case "TD":
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
764
|
+
gs = {
|
|
765
|
+
...gs,
|
|
766
|
+
leading: -numAt(operands, 1)
|
|
767
|
+
};
|
|
768
|
+
text.tlm = multiplyMatrices(translationMatrix(numAt(operands, 0), numAt(operands, 1)), text.tlm);
|
|
769
|
+
text.tm = text.tlm;
|
|
742
770
|
break;
|
|
743
771
|
case "Tm":
|
|
744
|
-
|
|
745
|
-
|
|
772
|
+
text.tlm = matrixFromOperands(operands);
|
|
773
|
+
text.tm = text.tlm;
|
|
746
774
|
break;
|
|
747
775
|
case "T*":
|
|
748
776
|
nextLine();
|
|
@@ -759,8 +787,11 @@ function runContentStream(bytes, resources, initialState, context, items, depth,
|
|
|
759
787
|
break;
|
|
760
788
|
}
|
|
761
789
|
case "\"": {
|
|
762
|
-
|
|
763
|
-
|
|
790
|
+
gs = {
|
|
791
|
+
...gs,
|
|
792
|
+
wordSpace: numAt(operands, 0),
|
|
793
|
+
charSpace: numAt(operands, 1)
|
|
794
|
+
};
|
|
764
795
|
nextLine();
|
|
765
796
|
const str = operands[2];
|
|
766
797
|
if (str?.kind === "string") showText(str.bytes);
|
package/dist/layout.d.cts
CHANGED
|
@@ -440,6 +440,7 @@ declare const LayoutAnnotationSchema: z.ZodObject<{
|
|
|
440
440
|
odf: "odf";
|
|
441
441
|
markdown: "markdown";
|
|
442
442
|
pdf: "pdf";
|
|
443
|
+
epub: "epub";
|
|
443
444
|
}>;
|
|
444
445
|
xml: z.ZodString;
|
|
445
446
|
}, z.core.$strict>>;
|
|
@@ -654,6 +655,7 @@ declare const LayoutPageSchema: z.ZodObject<{
|
|
|
654
655
|
odf: "odf";
|
|
655
656
|
markdown: "markdown";
|
|
656
657
|
pdf: "pdf";
|
|
658
|
+
epub: "epub";
|
|
657
659
|
}>;
|
|
658
660
|
xml: z.ZodString;
|
|
659
661
|
}, z.core.$strict>>;
|
|
@@ -981,6 +983,7 @@ declare const LayoutDocumentSchema: z.ZodObject<{
|
|
|
981
983
|
odf: "odf";
|
|
982
984
|
markdown: "markdown";
|
|
983
985
|
pdf: "pdf";
|
|
986
|
+
epub: "epub";
|
|
984
987
|
}>;
|
|
985
988
|
xml: z.ZodString;
|
|
986
989
|
}, z.core.$strict>>;
|
|
@@ -1044,6 +1047,7 @@ declare const LayoutDocumentSchema: z.ZodObject<{
|
|
|
1044
1047
|
odf: "odf";
|
|
1045
1048
|
markdown: "markdown";
|
|
1046
1049
|
pdf: "pdf";
|
|
1050
|
+
epub: "epub";
|
|
1047
1051
|
}>;
|
|
1048
1052
|
xml: z.ZodString;
|
|
1049
1053
|
}, z.core.$strict>>>;
|
package/dist/layout.d.ts
CHANGED
|
@@ -440,6 +440,7 @@ declare const LayoutAnnotationSchema: z.ZodObject<{
|
|
|
440
440
|
odf: "odf";
|
|
441
441
|
markdown: "markdown";
|
|
442
442
|
pdf: "pdf";
|
|
443
|
+
epub: "epub";
|
|
443
444
|
}>;
|
|
444
445
|
xml: z.ZodString;
|
|
445
446
|
}, z.core.$strict>>;
|
|
@@ -654,6 +655,7 @@ declare const LayoutPageSchema: z.ZodObject<{
|
|
|
654
655
|
odf: "odf";
|
|
655
656
|
markdown: "markdown";
|
|
656
657
|
pdf: "pdf";
|
|
658
|
+
epub: "epub";
|
|
657
659
|
}>;
|
|
658
660
|
xml: z.ZodString;
|
|
659
661
|
}, z.core.$strict>>;
|
|
@@ -981,6 +983,7 @@ declare const LayoutDocumentSchema: z.ZodObject<{
|
|
|
981
983
|
odf: "odf";
|
|
982
984
|
markdown: "markdown";
|
|
983
985
|
pdf: "pdf";
|
|
986
|
+
epub: "epub";
|
|
984
987
|
}>;
|
|
985
988
|
xml: z.ZodString;
|
|
986
989
|
}, z.core.$strict>>;
|
|
@@ -1044,6 +1047,7 @@ declare const LayoutDocumentSchema: z.ZodObject<{
|
|
|
1044
1047
|
odf: "odf";
|
|
1045
1048
|
markdown: "markdown";
|
|
1046
1049
|
pdf: "pdf";
|
|
1050
|
+
epub: "epub";
|
|
1047
1051
|
}>;
|
|
1048
1052
|
xml: z.ZodString;
|
|
1049
1053
|
}, z.core.$strict>>>;
|
package/dist/math-font.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_util_base64 = require("./util/base64.cjs");
|
|
3
3
|
const require_sfnt = require("./sfnt.cjs");
|
|
4
|
-
const require_cff_bounds = require("./cff-bounds.cjs");
|
|
5
4
|
const require_cmap_table = require("./cmap-table.cjs");
|
|
5
|
+
const require_cff_bounds = require("./cff-bounds.cjs");
|
|
6
6
|
const require_hmtx_table = require("./hmtx-table.cjs");
|
|
7
7
|
const require_assets_stix_two_math_font = require("./assets/stix-two-math-font.cjs");
|
|
8
8
|
const require_math_stretch = require("./math-stretch.cjs");
|