postext-pdf 1.27.1 → 1.28.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 +1 -1
- package/dist/__tests__/arabicShaping.test.js +2 -0
- package/dist/__tests__/arabicShaping.test.js.map +1 -1
- package/dist/__tests__/crossRefLinks.test.js +49 -0
- package/dist/__tests__/crossRefLinks.test.js.map +1 -1
- package/dist/__tests__/inlineCaptionSide.test.d.ts +2 -0
- package/dist/__tests__/inlineCaptionSide.test.d.ts.map +1 -0
- package/dist/__tests__/inlineCaptionSide.test.js +151 -0
- package/dist/__tests__/inlineCaptionSide.test.js.map +1 -0
- package/dist/__tests__/lineTracking.test.js +31 -0
- package/dist/__tests__/lineTracking.test.js.map +1 -1
- package/dist/__tests__/metadata.test.js +40 -0
- package/dist/__tests__/metadata.test.js.map +1 -1
- package/dist/__tests__/printOutput.test.js +34 -0
- package/dist/__tests__/printOutput.test.js.map +1 -1
- package/dist/__tests__/scriptContext.test.d.ts +2 -0
- package/dist/__tests__/scriptContext.test.d.ts.map +1 -0
- package/dist/__tests__/scriptContext.test.js +266 -0
- package/dist/__tests__/scriptContext.test.js.map +1 -0
- package/dist/__tests__/scriptContextHan.test.d.ts +2 -0
- package/dist/__tests__/scriptContextHan.test.d.ts.map +1 -0
- package/dist/__tests__/scriptContextHan.test.js +164 -0
- package/dist/__tests__/scriptContextHan.test.js.map +1 -0
- package/dist/faceFiles.d.ts +9 -0
- package/dist/faceFiles.d.ts.map +1 -1
- package/dist/faceFiles.js +22 -0
- package/dist/faceFiles.js.map +1 -1
- package/dist/pdf-backend/blockRender.d.ts.map +1 -1
- package/dist/pdf-backend/blockRender.js +11 -5
- package/dist/pdf-backend/blockRender.js.map +1 -1
- package/dist/pdf-backend/index.d.ts +8 -0
- package/dist/pdf-backend/index.d.ts.map +1 -1
- package/dist/pdf-backend/index.js +15 -0
- package/dist/pdf-backend/index.js.map +1 -1
- package/dist/pdf-backend/links.d.ts +14 -5
- package/dist/pdf-backend/links.d.ts.map +1 -1
- package/dist/pdf-backend/links.js +20 -6
- package/dist/pdf-backend/links.js.map +1 -1
- package/dist/pdf-backend/primitives.d.ts +10 -1
- package/dist/pdf-backend/primitives.d.ts.map +1 -1
- package/dist/pdf-backend/primitives.js +25 -2
- package/dist/pdf-backend/primitives.js.map +1 -1
- package/dist/pdf-backend/renderResourceBlock.d.ts.map +1 -1
- package/dist/pdf-backend/renderResourceBlock.js +8 -6
- package/dist/pdf-backend/renderResourceBlock.js.map +1 -1
- package/dist/pdf-backend/rtlRun.d.ts +5 -1
- package/dist/pdf-backend/rtlRun.d.ts.map +1 -1
- package/dist/pdf-backend/rtlRun.js +7 -3
- package/dist/pdf-backend/rtlRun.js.map +1 -1
- package/dist/pdf-backend/shapedText.d.ts.map +1 -1
- package/dist/pdf-backend/shapedText.js +13 -3
- package/dist/pdf-backend/shapedText.js.map +1 -1
- package/dist/print/pdfx.d.ts +8 -1
- package/dist/print/pdfx.d.ts.map +1 -1
- package/dist/print/pdfx.js +25 -1
- package/dist/print/pdfx.js.map +1 -1
- package/dist/shapingLanguage.d.ts +15 -3
- package/dist/shapingLanguage.d.ts.map +1 -1
- package/dist/shapingLanguage.js +50 -3
- package/dist/shapingLanguage.js.map +1 -1
- package/package.json +3 -3
|
@@ -10,9 +10,18 @@ export declare function shapingLanguage(): string | undefined;
|
|
|
10
10
|
* openTypeLanguageOf}), then put back the language in force before, also
|
|
11
11
|
* when `fn` throws. */
|
|
12
12
|
export declare function withShapingLanguage<T>(language: string | undefined, fn: () => T): T;
|
|
13
|
+
/** The script (ISO 15924) text is shaped in now; undefined: the one each
|
|
14
|
+
* shaper reads from the text. */
|
|
15
|
+
export declare function shapingScript(): string | undefined;
|
|
16
|
+
/** A letter of the script in force (a code point), undefined with none. */
|
|
17
|
+
export declare function shapingScriptLetter(): number | undefined;
|
|
18
|
+
/** Run `fn` with text shaped in `script` (an ISO 15924 code the engine
|
|
19
|
+
* acts on, else ignored), then put back the script in force before, also
|
|
20
|
+
* when `fn` throws. */
|
|
21
|
+
export declare function withShapingScript<T>(script: string | undefined, fn: () => T): T;
|
|
13
22
|
/** The key a cache of shaped `text` holds it under: the text itself in
|
|
14
|
-
* the default language (as every cache did), else tagged with
|
|
15
|
-
* language it was shaped in. */
|
|
23
|
+
* the default language and script (as every cache did), else tagged with
|
|
24
|
+
* the language and the script it was shaped in. */
|
|
16
25
|
export declare function shapingKey(text: string): string;
|
|
17
26
|
/**
|
|
18
27
|
* Make the fontkit face of `font` shape in the language in force when a
|
|
@@ -21,7 +30,10 @@ export declare function shapingKey(text: string): string;
|
|
|
21
30
|
* Text of punctuation alone is shaped as Han under a language (fontkit
|
|
22
31
|
* would read no script from it, and take the default script, which has no
|
|
23
32
|
* language systems), as a browser shapes it with the Japanese text around
|
|
24
|
-
* it. With
|
|
33
|
+
* it. With a script in force the text is shaped in it, left to right
|
|
34
|
+
* (fontkit would take the direction from the script and set `1367` in an
|
|
35
|
+
* Arabic sentence backwards; a right-to-left word is HarfBuzz's). With
|
|
36
|
+
* neither in force the call is the one it always was.
|
|
25
37
|
*/
|
|
26
38
|
export declare function shapeInCurrentLanguage(font: PDFFont): void;
|
|
27
39
|
//# sourceMappingURL=shapingLanguage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shapingLanguage.d.ts","sourceRoot":"","sources":["../src/shapingLanguage.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"shapingLanguage.d.ts","sourceRoot":"","sources":["../src/shapingLanguage.ts"],"names":[],"mappings":"AA+BA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAIvC;;yCAEyC;AACzC,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAE9E;AAED;gBACgB;AAChB,wBAAgB,eAAe,IAAI,MAAM,GAAG,SAAS,CAEpD;AAED;;wBAEwB;AACxB,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,GAAG,SAAS,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CASnF;AAWD;kCACkC;AAClC,wBAAgB,aAAa,IAAI,MAAM,GAAG,SAAS,CAElD;AAED,2EAA2E;AAC3E,wBAAgB,mBAAmB,IAAI,MAAM,GAAG,SAAS,CAExD;AAED;;wBAEwB;AACxB,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,GAAG,SAAS,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAU/E;AAED;;oDAEoD;AACpD,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAG/C;AAWD;;;;;;;;;;;GAWG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,CAY1D"}
|
package/dist/shapingLanguage.js
CHANGED
|
@@ -19,6 +19,14 @@
|
|
|
19
19
|
* ({@link openTypeLanguageOf}), none for any other language, so Chinese,
|
|
20
20
|
* Korean, Latin and Arabic text is shaped exactly as before. Pages are
|
|
21
21
|
* painted synchronously, so the language in force is the page's.
|
|
22
|
+
*
|
|
23
|
+
* The script in force (#725) works the same way, for one word at a time:
|
|
24
|
+
* a word with no letter (`46.`, `1367)`) that the layout measured in the
|
|
25
|
+
* script of the text around it (`VDTLineSegment.scriptContext`) is shaped
|
|
26
|
+
* in that script ({@link withShapingScript}), where fontkit would read no
|
|
27
|
+
* script from its characters and take the font's default. Amiri sets the
|
|
28
|
+
* Latin full stop and brackets under `latn` only: without it the PDF
|
|
29
|
+
* printed Arabic ones in a Latin note, wider than the places measured.
|
|
22
30
|
*/
|
|
23
31
|
import { isJapaneseLanguage } from 'postext';
|
|
24
32
|
let current;
|
|
@@ -48,10 +56,44 @@ export function withShapingLanguage(language, fn) {
|
|
|
48
56
|
current = previous;
|
|
49
57
|
}
|
|
50
58
|
}
|
|
59
|
+
/** The scripts a word with no letter may be shaped in (ISO 15924, as
|
|
60
|
+
* `VDTLineSegment.scriptContext` names them) and their OpenType tags. */
|
|
61
|
+
const OPENTYPE_SCRIPT = { Latn: 'latn', Grek: 'grek', Cyrl: 'cyrl', Arab: 'arab', Hebr: 'hebr', Hani: 'hani' };
|
|
62
|
+
/** A letter of each script: the file of a face cut into several that
|
|
63
|
+
* holds it is the one the script's text is set in (`fileRuns`). */
|
|
64
|
+
const SCRIPT_LETTER = { Latn: 0x6E, Grek: 0x3BD, Cyrl: 0x43D, Arab: 0x628, Hebr: 0x5D0, Hani: 0x4E00 };
|
|
65
|
+
let currentScript;
|
|
66
|
+
/** The script (ISO 15924) text is shaped in now; undefined: the one each
|
|
67
|
+
* shaper reads from the text. */
|
|
68
|
+
export function shapingScript() {
|
|
69
|
+
return currentScript;
|
|
70
|
+
}
|
|
71
|
+
/** A letter of the script in force (a code point), undefined with none. */
|
|
72
|
+
export function shapingScriptLetter() {
|
|
73
|
+
return currentScript === undefined ? undefined : SCRIPT_LETTER[currentScript];
|
|
74
|
+
}
|
|
75
|
+
/** Run `fn` with text shaped in `script` (an ISO 15924 code the engine
|
|
76
|
+
* acts on, else ignored), then put back the script in force before, also
|
|
77
|
+
* when `fn` throws. */
|
|
78
|
+
export function withShapingScript(script, fn) {
|
|
79
|
+
const next = script !== undefined && OPENTYPE_SCRIPT[script] !== undefined ? script : undefined;
|
|
80
|
+
if (next === currentScript)
|
|
81
|
+
return fn();
|
|
82
|
+
const previous = currentScript;
|
|
83
|
+
currentScript = next;
|
|
84
|
+
try {
|
|
85
|
+
return fn();
|
|
86
|
+
}
|
|
87
|
+
finally {
|
|
88
|
+
currentScript = previous;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
51
91
|
/** The key a cache of shaped `text` holds it under: the text itself in
|
|
52
|
-
* the default language (as every cache did), else tagged with
|
|
53
|
-
* language it was shaped in. */
|
|
92
|
+
* the default language and script (as every cache did), else tagged with
|
|
93
|
+
* the language and the script it was shaped in. */
|
|
54
94
|
export function shapingKey(text) {
|
|
95
|
+
if (currentScript !== undefined)
|
|
96
|
+
return `${currentScript}\u0001${current ?? ''}\u0000${text}`;
|
|
55
97
|
return current === undefined ? text : `${current}\u0000${text}`;
|
|
56
98
|
}
|
|
57
99
|
/** Text with a character of a script of its own (Han, kana, Latin…), from
|
|
@@ -66,7 +108,10 @@ const shaped = new WeakSet();
|
|
|
66
108
|
* Text of punctuation alone is shaped as Han under a language (fontkit
|
|
67
109
|
* would read no script from it, and take the default script, which has no
|
|
68
110
|
* language systems), as a browser shapes it with the Japanese text around
|
|
69
|
-
* it. With
|
|
111
|
+
* it. With a script in force the text is shaped in it, left to right
|
|
112
|
+
* (fontkit would take the direction from the script and set `1367` in an
|
|
113
|
+
* Arabic sentence backwards; a right-to-left word is HarfBuzz's). With
|
|
114
|
+
* neither in force the call is the one it always was.
|
|
70
115
|
*/
|
|
71
116
|
export function shapeInCurrentLanguage(font) {
|
|
72
117
|
const face = font.embedder?.font;
|
|
@@ -75,6 +120,8 @@ export function shapeInCurrentLanguage(font) {
|
|
|
75
120
|
const layout = face.layout.bind(face);
|
|
76
121
|
face.layout = (text, features, script, language, direction) => {
|
|
77
122
|
const lang = language ?? current;
|
|
123
|
+
if (script === undefined && currentScript !== undefined)
|
|
124
|
+
return layout(text, features, OPENTYPE_SCRIPT[currentScript], lang, direction ?? 'ltr');
|
|
78
125
|
if (lang === undefined)
|
|
79
126
|
return layout(text, features, script, language, direction);
|
|
80
127
|
const scriptTag = script ?? (typeof text === 'string' && !STRONG_SCRIPT_RE.test(text) ? 'hani' : undefined);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shapingLanguage.js","sourceRoot":"","sources":["../src/shapingLanguage.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"shapingLanguage.js","sourceRoot":"","sources":["../src/shapingLanguage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,OAAO,EAAE,kBA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EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE;QAC5D,MAAM,IAAI,GAAG,QAAQ,IAAI,OAAO,CAAC;QACjC,IAAI,MAAM,KAAK,SAAS,IAAI,aAAa,KAAK,SAAS;YAAE,OAAO,MAAM,CAAC,IAAI,EAAE,QAAQ,EAAE,eAAe,CAAC,aAAa,CAAC,EAAE,IAAI,EAAE,SAAS,IAAI,KAAK,CAAC,CAAC;QACjJ,IAAI,IAAI,KAAK,SAAS;YAAE,OAAO,MAAM,CAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;QACnF,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;QAC5G,OAAO,MAAM,CAAC,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,CAAC,CAAC;IAC5D,CAAC,CAAC;IACF,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AACnB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "postext-pdf",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.28.0",
|
|
4
4
|
"description": "Browser-native PDF renderer for Postext documents. Consumes the same VDT as the canvas/HTML backends and produces a physical PDF with faithful glyph positioning, justification, crop marks, and baseline grid.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"./package.json": "./package.json"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
|
-
"postext": "^1.
|
|
43
|
+
"postext": "^1.28.0"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"@pdf-lib/fontkit": "^1.1.1",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"@types/node": "^26.5.0",
|
|
55
55
|
"eslint": "^9.39.4",
|
|
56
56
|
"harfbuzzjs": "1.6.2",
|
|
57
|
-
"postext": "1.
|
|
57
|
+
"postext": "1.28.0",
|
|
58
58
|
"typescript": "^6.0.3",
|
|
59
59
|
"typescript-eslint": "^8.70.0",
|
|
60
60
|
"vitest": "^5.0.0"
|