reamkit 1.6.0 → 1.9.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 +13 -1
- package/dist/esm/core/converter/ream.d.ts +1 -0
- package/dist/esm/core/converter/ream.js +1 -1
- package/dist/esm/core/document-model/types.d.ts +3 -1
- package/dist/esm/core/drawingml/chart-serializer.d.ts +2 -0
- package/dist/esm/core/drawingml/chart-serializer.js +53 -0
- package/dist/esm/core/drawingml/shape-render.d.ts +3 -1
- package/dist/esm/core/drawingml/shape-render.js +27 -1
- package/dist/esm/core/vector.d.ts +10 -0
- package/dist/esm/excel/print-model.js +6 -3
- package/dist/esm/excel/xlsx-writer.js +81 -17
- package/dist/esm/html/html-writer.js +4 -2
- package/dist/esm/layout/styled-layout.js +5 -2
- package/dist/esm/pdf/shading.d.ts +12 -0
- package/dist/esm/pdf/shading.js +152 -0
- package/dist/esm/pdf/styled-page-emitter.js +29 -4
- package/dist/esm/pdf/vector-graphics.d.ts +1 -1
- package/dist/esm/pdf/vector-graphics.js +5 -3
- package/dist/esm/pdf-reader/ccitt.d.ts +15 -0
- package/dist/esm/pdf-reader/ccitt.js +394 -0
- package/dist/esm/pdf-reader/content.d.ts +43 -1
- package/dist/esm/pdf-reader/content.js +173 -4
- package/dist/esm/pdf-reader/crypto.d.ts +7 -0
- package/dist/esm/pdf-reader/crypto.js +609 -0
- package/dist/esm/pdf-reader/decrypt.d.ts +5 -0
- package/dist/esm/pdf-reader/decrypt.js +211 -0
- package/dist/esm/pdf-reader/document.d.ts +8 -1
- package/dist/esm/pdf-reader/document.js +210 -27
- package/dist/esm/pdf-reader/flow-build.d.ts +16 -1
- package/dist/esm/pdf-reader/flow-build.js +113 -3
- package/dist/esm/pdf-reader/image-decode.d.ts +15 -0
- package/dist/esm/pdf-reader/image-decode.js +550 -0
- package/dist/esm/pdf-reader/images.d.ts +16 -0
- package/dist/esm/pdf-reader/images.js +90 -0
- package/dist/esm/pdf-reader/layout.d.ts +2 -2
- package/dist/esm/pdf-reader/layout.js +86 -14
- package/dist/esm/pdf-reader/png-encode.d.ts +2 -0
- package/dist/esm/pdf-reader/png-encode.js +98 -0
- package/dist/esm/pdf-reader/predictor.d.ts +7 -0
- package/dist/esm/pdf-reader/predictor.js +61 -0
- package/dist/esm/pdf-reader/reader.d.ts +1 -1
- package/dist/esm/pdf-reader/reader.js +14 -7
- package/dist/esm/pdf-reader/shading.d.ts +3 -0
- package/dist/esm/pdf-reader/shading.js +147 -0
- package/dist/esm/pdf-reader/tagged.d.ts +2 -2
- package/dist/esm/pdf-reader/tagged.js +60 -7
- package/dist/esm/pdf-reader/text.js +91 -10
- package/dist/esm/pdf-reader/vector.d.ts +16 -0
- package/dist/esm/pdf-reader/vector.js +63 -0
- package/dist/esm/svg/svg-writer.js +12 -5
- package/dist/esm/word/docx-writer.js +104 -8
- package/dist/esm/word/drawing-parser.js +28 -17
- package/dist/esm/word/omml-serializer.d.ts +2 -0
- package/dist/esm/word/omml-serializer.js +48 -0
- package/package.json +1 -1
|
@@ -6,6 +6,7 @@ import { reverseByCodePoint } from "../core/bidi/index.js";
|
|
|
6
6
|
import "../layout/styled-layout.js";
|
|
7
7
|
import { paintPlan } from "../layout/page-doc.js";
|
|
8
8
|
import { emitVectorShape } from "./vector-graphics.js";
|
|
9
|
+
import { buildGradientPattern, shapeBbox } from "./shading.js";
|
|
9
10
|
import { sanitizeHref } from "../core/links.js";
|
|
10
11
|
import { embedAssociatedFile } from "./embedded-file.js";
|
|
11
12
|
import { buildSrgbIccProfile } from "./icc-profile.js";
|
|
@@ -49,9 +50,33 @@ function assembleStyledPdf(laid, options, doc) {
|
|
|
49
50
|
let annotParentCount = 0;
|
|
50
51
|
const fontResourceDict = buildFontResourceDict(laid.fontResources, embeddedFonts);
|
|
51
52
|
const xobjectResourceDict = buildXObjectResourceDict(laid.imageResources, embeddedImages);
|
|
53
|
+
const gradientNames = /* @__PURE__ */ new Map();
|
|
54
|
+
const patternEntries = {};
|
|
55
|
+
if (!pdfaProfile) for (const page of renderedPages) {
|
|
56
|
+
const ph = page.height;
|
|
57
|
+
for (const item of paintPlan(page.commands).shapes) {
|
|
58
|
+
const gradient = item.shape.fillGradient;
|
|
59
|
+
if (!gradient) continue;
|
|
60
|
+
const bbox = shapeBbox(item.shape);
|
|
61
|
+
if (!bbox) continue;
|
|
62
|
+
const t = item.shape.transform;
|
|
63
|
+
const ctm = [
|
|
64
|
+
t[0],
|
|
65
|
+
-t[1],
|
|
66
|
+
t[2],
|
|
67
|
+
-t[3],
|
|
68
|
+
t[4],
|
|
69
|
+
ph - t[5]
|
|
70
|
+
];
|
|
71
|
+
const nm = `Sh${gradientNames.size}`;
|
|
72
|
+
patternEntries[nm] = ref(buildGradientPattern(doc, gradient, bbox, ctm).id);
|
|
73
|
+
gradientNames.set(item.shape, nm);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
52
76
|
const resourcesDict = dict({
|
|
53
77
|
Font: fontResourceDict,
|
|
54
|
-
...xobjectResourceDict ? { XObject: xobjectResourceDict } : {}
|
|
78
|
+
...xobjectResourceDict ? { XObject: xobjectResourceDict } : {},
|
|
79
|
+
...Object.keys(patternEntries).length > 0 ? { Pattern: dict(patternEntries) } : {}
|
|
55
80
|
});
|
|
56
81
|
let pdfaIccRef;
|
|
57
82
|
let transparencyGroup;
|
|
@@ -78,7 +103,7 @@ function assembleStyledPdf(laid, options, doc) {
|
|
|
78
103
|
tagFor: (structId) => builder.node(structId).type
|
|
79
104
|
};
|
|
80
105
|
}
|
|
81
|
-
const { content: contentBytes, links } = emitPageContent(page, pageTagging);
|
|
106
|
+
const { content: contentBytes, links } = emitPageContent(page, pageTagging, gradientNames);
|
|
82
107
|
const contentsRef = doc.add(stream({}, contentBytes));
|
|
83
108
|
const pageEntries = {
|
|
84
109
|
Type: name("Page"),
|
|
@@ -361,7 +386,7 @@ function emitTaggedRuns(out, cmds, tagging, body) {
|
|
|
361
386
|
}
|
|
362
387
|
close();
|
|
363
388
|
}
|
|
364
|
-
function emitPageContent(page, tagging) {
|
|
389
|
+
function emitPageContent(page, tagging, gradientNames) {
|
|
365
390
|
const commands = page.commands;
|
|
366
391
|
const links = [];
|
|
367
392
|
if (commands.length === 0) return {
|
|
@@ -454,7 +479,7 @@ function emitPageContent(page, tagging) {
|
|
|
454
479
|
H - t[5]
|
|
455
480
|
]
|
|
456
481
|
};
|
|
457
|
-
for (const op of emitVectorShape(shape)) out.push(op);
|
|
482
|
+
for (const op of emitVectorShape(shape, gradientNames?.get(sh.shape))) out.push(op);
|
|
458
483
|
});
|
|
459
484
|
const lines = plan.lines;
|
|
460
485
|
if (lines.length > 0) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { VectorShape } from '../core/vector.js';
|
|
2
2
|
export type { PathSegment, StrokeStyle, VectorPath, VectorShape } from '../core/vector.js';
|
|
3
3
|
export { PathBuilder } from '../core/vector.js';
|
|
4
|
-
export declare function emitVectorShape(shape: VectorShape): Array<string>;
|
|
4
|
+
export declare function emitVectorShape(shape: VectorShape, patternName?: string): Array<string>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "../core/vector.js";
|
|
2
2
|
//#region src/pdf/vector-graphics.ts
|
|
3
|
-
function emitVectorShape(shape) {
|
|
3
|
+
function emitVectorShape(shape, patternName) {
|
|
4
4
|
const out = [];
|
|
5
5
|
out.push("q");
|
|
6
6
|
const [a, b, c, d, e, f] = shape.transform;
|
|
@@ -14,7 +14,9 @@ function emitVectorShape(shape) {
|
|
|
14
14
|
const [r, g, bl] = hexToRgb01(stroke.colorHex);
|
|
15
15
|
out.push(`${num(r)} ${num(g)} ${num(bl)} RG`);
|
|
16
16
|
}
|
|
17
|
-
|
|
17
|
+
const usePattern = patternName !== void 0 && shape.fillGradient !== void 0;
|
|
18
|
+
if (usePattern) out.push(`/Pattern cs /${patternName} scn`);
|
|
19
|
+
else if (shape.fillColorHex) {
|
|
18
20
|
const [r, g, bl] = hexToRgb01(shape.fillColorHex);
|
|
19
21
|
out.push(`${num(r)} ${num(g)} ${num(bl)} rg`);
|
|
20
22
|
}
|
|
@@ -23,7 +25,7 @@ function emitVectorShape(shape) {
|
|
|
23
25
|
if (path.fillRule === "evenodd") evenodd = true;
|
|
24
26
|
for (const seg of path.segments) out.push(emitSegment(seg));
|
|
25
27
|
}
|
|
26
|
-
out.push(paintOp(shape.fillColorHex !== void 0, stroke !== void 0, evenodd));
|
|
28
|
+
out.push(paintOp(usePattern || shape.fillColorHex !== void 0, stroke !== void 0, evenodd));
|
|
27
29
|
out.push("Q");
|
|
28
30
|
return out;
|
|
29
31
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface CcittParams {
|
|
2
|
+
readonly k: number;
|
|
3
|
+
readonly columns: number;
|
|
4
|
+
readonly rows: number;
|
|
5
|
+
readonly byteAlign: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare function decodeCcitt(data: Uint8Array, params: CcittParams): Uint8Array | undefined;
|
|
8
|
+
export interface Mode {
|
|
9
|
+
readonly kind: 'pass' | 'horizontal' | 'vertical';
|
|
10
|
+
readonly d: number;
|
|
11
|
+
}
|
|
12
|
+
export declare const WHITE_CODES: ReadonlyArray<readonly [number, string]>;
|
|
13
|
+
export declare const BLACK_CODES: ReadonlyArray<readonly [number, string]>;
|
|
14
|
+
export declare const SHARED_MAKEUP: ReadonlyArray<readonly [number, string]>;
|
|
15
|
+
export declare const MODE_CODES: ReadonlyArray<readonly [string, Mode]>;
|
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
//#region src/pdf-reader/ccitt.ts
|
|
2
|
+
function decodeCcitt(data, params) {
|
|
3
|
+
const { k, columns, rows, byteAlign } = params;
|
|
4
|
+
if (k > 0) return void 0;
|
|
5
|
+
if (columns <= 0 || rows <= 0 || columns > 1 << 20) return void 0;
|
|
6
|
+
const reader = new BitReader(data);
|
|
7
|
+
const rowBytes = columns + 7 >> 3;
|
|
8
|
+
const out = new Uint8Array(rowBytes * rows);
|
|
9
|
+
let ref = [columns, columns];
|
|
10
|
+
for (let y = 0; y < rows; y++) {
|
|
11
|
+
if (byteAlign && y > 0) reader.align();
|
|
12
|
+
const cur = k < 0 ? decode2D(reader, ref, columns) : decode1D(reader, columns);
|
|
13
|
+
if (!cur) {
|
|
14
|
+
if (y === 0) return void 0;
|
|
15
|
+
break;
|
|
16
|
+
}
|
|
17
|
+
expandRow(cur, columns, out, y * rowBytes);
|
|
18
|
+
cur.push(columns, columns);
|
|
19
|
+
ref = cur;
|
|
20
|
+
}
|
|
21
|
+
return out;
|
|
22
|
+
}
|
|
23
|
+
function decode1D(reader, columns) {
|
|
24
|
+
const cur = [];
|
|
25
|
+
let pos = 0;
|
|
26
|
+
let color = 0;
|
|
27
|
+
while (pos < columns) {
|
|
28
|
+
const run = readRun(reader, color);
|
|
29
|
+
if (run < 0) return cur.length > 0 ? cur : null;
|
|
30
|
+
pos = Math.min(pos + run, columns);
|
|
31
|
+
cur.push(pos);
|
|
32
|
+
color ^= 1;
|
|
33
|
+
}
|
|
34
|
+
return cur;
|
|
35
|
+
}
|
|
36
|
+
function decode2D(reader, ref, columns) {
|
|
37
|
+
const cur = [];
|
|
38
|
+
let a0 = -1;
|
|
39
|
+
let color = 0;
|
|
40
|
+
while (a0 < columns) {
|
|
41
|
+
const [b1, b2] = findB(ref, a0, color, columns);
|
|
42
|
+
const mode = readMode(reader);
|
|
43
|
+
if (!mode) return cur.length > 0 || a0 >= 0 ? cur : null;
|
|
44
|
+
if (mode.kind === "pass") a0 = b2;
|
|
45
|
+
else if (mode.kind === "horizontal") {
|
|
46
|
+
const start = a0 < 0 ? 0 : a0;
|
|
47
|
+
const r1 = readRun(reader, color);
|
|
48
|
+
const r2 = readRun(reader, color ^ 1);
|
|
49
|
+
if (r1 < 0 || r2 < 0) return cur.length > 0 ? cur : null;
|
|
50
|
+
const a1 = Math.min(start + r1, columns);
|
|
51
|
+
const a2 = Math.min(a1 + r2, columns);
|
|
52
|
+
cur.push(a1, a2);
|
|
53
|
+
a0 = a2;
|
|
54
|
+
} else {
|
|
55
|
+
const a1 = Math.min(Math.max(b1 + mode.d, 0), columns);
|
|
56
|
+
cur.push(a1);
|
|
57
|
+
a0 = a1;
|
|
58
|
+
color ^= 1;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return cur;
|
|
62
|
+
}
|
|
63
|
+
function findB(ref, a0, color, columns) {
|
|
64
|
+
let i = 0;
|
|
65
|
+
while (i < ref.length && ref[i] <= a0) i++;
|
|
66
|
+
const wantEven = color === 0;
|
|
67
|
+
if (i < ref.length && i % 2 === 0 !== wantEven) i++;
|
|
68
|
+
return [i < ref.length ? ref[i] : columns, i + 1 < ref.length ? ref[i + 1] : columns];
|
|
69
|
+
}
|
|
70
|
+
function expandRow(cur, columns, out, rowOff) {
|
|
71
|
+
let prev = 0;
|
|
72
|
+
let color = 0;
|
|
73
|
+
for (const cRaw of cur) {
|
|
74
|
+
const c = Math.min(cRaw, columns);
|
|
75
|
+
if (color === 1) setBlack(out, rowOff, prev, c);
|
|
76
|
+
prev = c;
|
|
77
|
+
color ^= 1;
|
|
78
|
+
if (prev >= columns) return;
|
|
79
|
+
}
|
|
80
|
+
if (color === 1 && prev < columns) setBlack(out, rowOff, prev, columns);
|
|
81
|
+
}
|
|
82
|
+
function setBlack(out, rowOff, from, to) {
|
|
83
|
+
for (let x = from; x < to; x++) out[rowOff + (x >> 3)] |= 128 >> (x & 7);
|
|
84
|
+
}
|
|
85
|
+
function readRun(reader, color) {
|
|
86
|
+
const table = color === 1 ? BLACK : WHITE;
|
|
87
|
+
let total = 0;
|
|
88
|
+
for (let guard = 0; guard < 64; guard++) {
|
|
89
|
+
const run = readCode(reader, table);
|
|
90
|
+
if (run < 0) return -1;
|
|
91
|
+
total += run;
|
|
92
|
+
if (run < 64) return total;
|
|
93
|
+
}
|
|
94
|
+
return -1;
|
|
95
|
+
}
|
|
96
|
+
function readMode(reader) {
|
|
97
|
+
let code = 0;
|
|
98
|
+
for (let len = 1; len <= 7; len++) {
|
|
99
|
+
const b = reader.readBit();
|
|
100
|
+
if (b < 0) return void 0;
|
|
101
|
+
code = code << 1 | b;
|
|
102
|
+
const m = MODES.get(len << 8 | code);
|
|
103
|
+
if (m) return m;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
function readCode(reader, table) {
|
|
107
|
+
let code = 0;
|
|
108
|
+
for (let len = 1; len <= table.maxLen; len++) {
|
|
109
|
+
const b = reader.readBit();
|
|
110
|
+
if (b < 0) return -1;
|
|
111
|
+
code = code << 1 | b;
|
|
112
|
+
const run = table.map.get(len << 16 | code);
|
|
113
|
+
if (run !== void 0) return run;
|
|
114
|
+
}
|
|
115
|
+
return -1;
|
|
116
|
+
}
|
|
117
|
+
var BitReader = class {
|
|
118
|
+
bytePos = 0;
|
|
119
|
+
bitPos = 0;
|
|
120
|
+
constructor(data) {
|
|
121
|
+
this.data = data;
|
|
122
|
+
}
|
|
123
|
+
readBit() {
|
|
124
|
+
if (this.bytePos >= this.data.length) return -1;
|
|
125
|
+
const bit = this.data[this.bytePos] >> 7 - this.bitPos & 1;
|
|
126
|
+
if (++this.bitPos === 8) {
|
|
127
|
+
this.bitPos = 0;
|
|
128
|
+
this.bytePos++;
|
|
129
|
+
}
|
|
130
|
+
return bit;
|
|
131
|
+
}
|
|
132
|
+
align() {
|
|
133
|
+
if (this.bitPos !== 0) {
|
|
134
|
+
this.bitPos = 0;
|
|
135
|
+
this.bytePos++;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
var WHITE_CODES = [
|
|
140
|
+
[0, "00110101"],
|
|
141
|
+
[1, "000111"],
|
|
142
|
+
[2, "0111"],
|
|
143
|
+
[3, "1000"],
|
|
144
|
+
[4, "1011"],
|
|
145
|
+
[5, "1100"],
|
|
146
|
+
[6, "1110"],
|
|
147
|
+
[7, "1111"],
|
|
148
|
+
[8, "10011"],
|
|
149
|
+
[9, "10100"],
|
|
150
|
+
[10, "00111"],
|
|
151
|
+
[11, "01000"],
|
|
152
|
+
[12, "001000"],
|
|
153
|
+
[13, "000011"],
|
|
154
|
+
[14, "110100"],
|
|
155
|
+
[15, "110101"],
|
|
156
|
+
[16, "101010"],
|
|
157
|
+
[17, "101011"],
|
|
158
|
+
[18, "0100111"],
|
|
159
|
+
[19, "0001100"],
|
|
160
|
+
[20, "0001000"],
|
|
161
|
+
[21, "0010111"],
|
|
162
|
+
[22, "0000011"],
|
|
163
|
+
[23, "0000100"],
|
|
164
|
+
[24, "0101000"],
|
|
165
|
+
[25, "0101011"],
|
|
166
|
+
[26, "0010011"],
|
|
167
|
+
[27, "0100100"],
|
|
168
|
+
[28, "0011000"],
|
|
169
|
+
[29, "00000010"],
|
|
170
|
+
[30, "00000011"],
|
|
171
|
+
[31, "00011010"],
|
|
172
|
+
[32, "00011011"],
|
|
173
|
+
[33, "00010010"],
|
|
174
|
+
[34, "00010011"],
|
|
175
|
+
[35, "00010100"],
|
|
176
|
+
[36, "00010101"],
|
|
177
|
+
[37, "00010110"],
|
|
178
|
+
[38, "00010111"],
|
|
179
|
+
[39, "00101000"],
|
|
180
|
+
[40, "00101001"],
|
|
181
|
+
[41, "00101010"],
|
|
182
|
+
[42, "00101011"],
|
|
183
|
+
[43, "00101100"],
|
|
184
|
+
[44, "00101101"],
|
|
185
|
+
[45, "00000100"],
|
|
186
|
+
[46, "00000101"],
|
|
187
|
+
[47, "00001010"],
|
|
188
|
+
[48, "00001011"],
|
|
189
|
+
[49, "01010010"],
|
|
190
|
+
[50, "01010011"],
|
|
191
|
+
[51, "01010100"],
|
|
192
|
+
[52, "01010101"],
|
|
193
|
+
[53, "00100100"],
|
|
194
|
+
[54, "00100101"],
|
|
195
|
+
[55, "01011000"],
|
|
196
|
+
[56, "01011001"],
|
|
197
|
+
[57, "01011010"],
|
|
198
|
+
[58, "01011011"],
|
|
199
|
+
[59, "01001010"],
|
|
200
|
+
[60, "01001011"],
|
|
201
|
+
[61, "00110010"],
|
|
202
|
+
[62, "00110011"],
|
|
203
|
+
[63, "00110100"],
|
|
204
|
+
[64, "11011"],
|
|
205
|
+
[128, "10010"],
|
|
206
|
+
[192, "010111"],
|
|
207
|
+
[256, "0110111"],
|
|
208
|
+
[320, "00110110"],
|
|
209
|
+
[384, "00110111"],
|
|
210
|
+
[448, "01100100"],
|
|
211
|
+
[512, "01100101"],
|
|
212
|
+
[576, "01101000"],
|
|
213
|
+
[640, "01100111"],
|
|
214
|
+
[704, "011001100"],
|
|
215
|
+
[768, "011001101"],
|
|
216
|
+
[832, "011010010"],
|
|
217
|
+
[896, "011010011"],
|
|
218
|
+
[960, "011010100"],
|
|
219
|
+
[1024, "011010101"],
|
|
220
|
+
[1088, "011010110"],
|
|
221
|
+
[1152, "011010111"],
|
|
222
|
+
[1216, "011011000"],
|
|
223
|
+
[1280, "011011001"],
|
|
224
|
+
[1344, "011011010"],
|
|
225
|
+
[1408, "011011011"],
|
|
226
|
+
[1472, "010011000"],
|
|
227
|
+
[1536, "010011001"],
|
|
228
|
+
[1600, "010011010"],
|
|
229
|
+
[1664, "011000"],
|
|
230
|
+
[1728, "010011011"]
|
|
231
|
+
];
|
|
232
|
+
var BLACK_CODES = [
|
|
233
|
+
[0, "0000110111"],
|
|
234
|
+
[1, "010"],
|
|
235
|
+
[2, "11"],
|
|
236
|
+
[3, "10"],
|
|
237
|
+
[4, "011"],
|
|
238
|
+
[5, "0011"],
|
|
239
|
+
[6, "0010"],
|
|
240
|
+
[7, "00011"],
|
|
241
|
+
[8, "000101"],
|
|
242
|
+
[9, "000100"],
|
|
243
|
+
[10, "0000100"],
|
|
244
|
+
[11, "0000101"],
|
|
245
|
+
[12, "0000111"],
|
|
246
|
+
[13, "00000100"],
|
|
247
|
+
[14, "00000111"],
|
|
248
|
+
[15, "000011000"],
|
|
249
|
+
[16, "0000010111"],
|
|
250
|
+
[17, "0000011000"],
|
|
251
|
+
[18, "0000001000"],
|
|
252
|
+
[19, "00001100111"],
|
|
253
|
+
[20, "00001101000"],
|
|
254
|
+
[21, "00001101100"],
|
|
255
|
+
[22, "00000110111"],
|
|
256
|
+
[23, "00000101000"],
|
|
257
|
+
[24, "00000010111"],
|
|
258
|
+
[25, "00000011000"],
|
|
259
|
+
[26, "000011001010"],
|
|
260
|
+
[27, "000011001011"],
|
|
261
|
+
[28, "000011001100"],
|
|
262
|
+
[29, "000011001101"],
|
|
263
|
+
[30, "000001101000"],
|
|
264
|
+
[31, "000001101001"],
|
|
265
|
+
[32, "000001101010"],
|
|
266
|
+
[33, "000001101011"],
|
|
267
|
+
[34, "000011010010"],
|
|
268
|
+
[35, "000011010011"],
|
|
269
|
+
[36, "000011010100"],
|
|
270
|
+
[37, "000011010101"],
|
|
271
|
+
[38, "000011010110"],
|
|
272
|
+
[39, "000011010111"],
|
|
273
|
+
[40, "000001101100"],
|
|
274
|
+
[41, "000001101101"],
|
|
275
|
+
[42, "000011011010"],
|
|
276
|
+
[43, "000011011011"],
|
|
277
|
+
[44, "000001010100"],
|
|
278
|
+
[45, "000001010101"],
|
|
279
|
+
[46, "000001010110"],
|
|
280
|
+
[47, "000001010111"],
|
|
281
|
+
[48, "000001100100"],
|
|
282
|
+
[49, "000001100101"],
|
|
283
|
+
[50, "000001010010"],
|
|
284
|
+
[51, "000001010011"],
|
|
285
|
+
[52, "000000100100"],
|
|
286
|
+
[53, "000000110111"],
|
|
287
|
+
[54, "000000111000"],
|
|
288
|
+
[55, "000000100111"],
|
|
289
|
+
[56, "000000101000"],
|
|
290
|
+
[57, "000001011000"],
|
|
291
|
+
[58, "000001011001"],
|
|
292
|
+
[59, "000000101011"],
|
|
293
|
+
[60, "000000101100"],
|
|
294
|
+
[61, "000001011010"],
|
|
295
|
+
[62, "000001100110"],
|
|
296
|
+
[63, "000001100111"],
|
|
297
|
+
[64, "0000001111"],
|
|
298
|
+
[128, "000011001000"],
|
|
299
|
+
[192, "000011001001"],
|
|
300
|
+
[256, "000001011011"],
|
|
301
|
+
[320, "000000110011"],
|
|
302
|
+
[384, "000000110100"],
|
|
303
|
+
[448, "000000110101"],
|
|
304
|
+
[512, "0000001101100"],
|
|
305
|
+
[576, "0000001101101"],
|
|
306
|
+
[640, "0000001001010"],
|
|
307
|
+
[704, "0000001001011"],
|
|
308
|
+
[768, "0000001001100"],
|
|
309
|
+
[832, "0000001001101"],
|
|
310
|
+
[896, "0000001110010"],
|
|
311
|
+
[960, "0000001110011"],
|
|
312
|
+
[1024, "0000001110100"],
|
|
313
|
+
[1088, "0000001110101"],
|
|
314
|
+
[1152, "0000001110110"],
|
|
315
|
+
[1216, "0000001110111"],
|
|
316
|
+
[1280, "0000001010010"],
|
|
317
|
+
[1344, "0000001010011"],
|
|
318
|
+
[1408, "0000001010100"],
|
|
319
|
+
[1472, "0000001010101"],
|
|
320
|
+
[1536, "0000001011010"],
|
|
321
|
+
[1600, "0000001011011"],
|
|
322
|
+
[1664, "0000001100100"],
|
|
323
|
+
[1728, "0000001100101"]
|
|
324
|
+
];
|
|
325
|
+
var SHARED_MAKEUP = [
|
|
326
|
+
[1792, "00000001000"],
|
|
327
|
+
[1856, "00000001100"],
|
|
328
|
+
[1920, "00000001101"],
|
|
329
|
+
[1984, "000000010010"],
|
|
330
|
+
[2048, "000000010011"],
|
|
331
|
+
[2112, "000000010100"],
|
|
332
|
+
[2176, "000000010101"],
|
|
333
|
+
[2240, "000000010110"],
|
|
334
|
+
[2304, "000000010111"],
|
|
335
|
+
[2368, "000000011100"],
|
|
336
|
+
[2432, "000000011101"],
|
|
337
|
+
[2496, "000000011110"],
|
|
338
|
+
[2560, "000000011111"]
|
|
339
|
+
];
|
|
340
|
+
var MODE_CODES = [
|
|
341
|
+
["0001", {
|
|
342
|
+
kind: "pass",
|
|
343
|
+
d: 0
|
|
344
|
+
}],
|
|
345
|
+
["001", {
|
|
346
|
+
kind: "horizontal",
|
|
347
|
+
d: 0
|
|
348
|
+
}],
|
|
349
|
+
["1", {
|
|
350
|
+
kind: "vertical",
|
|
351
|
+
d: 0
|
|
352
|
+
}],
|
|
353
|
+
["011", {
|
|
354
|
+
kind: "vertical",
|
|
355
|
+
d: 1
|
|
356
|
+
}],
|
|
357
|
+
["000011", {
|
|
358
|
+
kind: "vertical",
|
|
359
|
+
d: 2
|
|
360
|
+
}],
|
|
361
|
+
["0000011", {
|
|
362
|
+
kind: "vertical",
|
|
363
|
+
d: 3
|
|
364
|
+
}],
|
|
365
|
+
["010", {
|
|
366
|
+
kind: "vertical",
|
|
367
|
+
d: -1
|
|
368
|
+
}],
|
|
369
|
+
["000010", {
|
|
370
|
+
kind: "vertical",
|
|
371
|
+
d: -2
|
|
372
|
+
}],
|
|
373
|
+
["0000010", {
|
|
374
|
+
kind: "vertical",
|
|
375
|
+
d: -3
|
|
376
|
+
}]
|
|
377
|
+
];
|
|
378
|
+
function buildRunTable(...groups) {
|
|
379
|
+
const map = /* @__PURE__ */ new Map();
|
|
380
|
+
let maxLen = 0;
|
|
381
|
+
for (const group of groups) for (const [run, bits] of group) {
|
|
382
|
+
map.set(bits.length << 16 | parseInt(bits, 2), run);
|
|
383
|
+
maxLen = Math.max(maxLen, bits.length);
|
|
384
|
+
}
|
|
385
|
+
return {
|
|
386
|
+
map,
|
|
387
|
+
maxLen
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
var WHITE = buildRunTable(WHITE_CODES, SHARED_MAKEUP);
|
|
391
|
+
var BLACK = buildRunTable(BLACK_CODES, SHARED_MAKEUP);
|
|
392
|
+
var MODES = new Map(MODE_CODES.map(([bits, m]) => [bits.length << 8 | parseInt(bits, 2), m]));
|
|
393
|
+
//#endregion
|
|
394
|
+
export { decodeCcitt };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ShapeGradient } from '../core/vector.js';
|
|
1
2
|
export interface ContentFont {
|
|
2
3
|
readonly bytesPerCode: 1 | 2;
|
|
3
4
|
decode: (codes: ReadonlyArray<number>) => string;
|
|
@@ -10,5 +11,46 @@ export interface TextRun {
|
|
|
10
11
|
readonly fontSizePt: number;
|
|
11
12
|
readonly fontKey: string;
|
|
12
13
|
readonly mcid?: number;
|
|
14
|
+
readonly href?: string;
|
|
13
15
|
}
|
|
14
|
-
export
|
|
16
|
+
export interface ImagePlacement {
|
|
17
|
+
readonly name: string;
|
|
18
|
+
readonly ctm: Matrix;
|
|
19
|
+
readonly mcid?: number;
|
|
20
|
+
}
|
|
21
|
+
export type PathSeg = {
|
|
22
|
+
readonly op: 'move';
|
|
23
|
+
readonly x: number;
|
|
24
|
+
readonly y: number;
|
|
25
|
+
} | {
|
|
26
|
+
readonly op: 'line';
|
|
27
|
+
readonly x: number;
|
|
28
|
+
readonly y: number;
|
|
29
|
+
} | {
|
|
30
|
+
readonly op: 'cubic';
|
|
31
|
+
readonly x1: number;
|
|
32
|
+
readonly y1: number;
|
|
33
|
+
readonly x2: number;
|
|
34
|
+
readonly y2: number;
|
|
35
|
+
readonly x: number;
|
|
36
|
+
readonly y: number;
|
|
37
|
+
} | {
|
|
38
|
+
readonly op: 'close';
|
|
39
|
+
};
|
|
40
|
+
export interface VectorPlacement {
|
|
41
|
+
readonly segs: ReadonlyArray<PathSeg>;
|
|
42
|
+
readonly fillHex?: string;
|
|
43
|
+
readonly gradient?: ShapeGradient;
|
|
44
|
+
readonly strokeHex?: string;
|
|
45
|
+
readonly lineWidth?: number;
|
|
46
|
+
readonly mcid?: number;
|
|
47
|
+
}
|
|
48
|
+
export interface InterpretResult {
|
|
49
|
+
readonly texts: Array<TextRun>;
|
|
50
|
+
readonly images: Array<ImagePlacement>;
|
|
51
|
+
readonly vectors: Array<VectorPlacement>;
|
|
52
|
+
}
|
|
53
|
+
export type Matrix = readonly [number, number, number, number, number, number];
|
|
54
|
+
export declare const IDENTITY: Matrix;
|
|
55
|
+
export declare function multiply(a: Matrix, b: Matrix): Matrix;
|
|
56
|
+
export declare function interpretContent(bytes: Uint8Array, fonts: ReadonlyMap<string, ContentFont>, initialCtm?: Matrix, shadings?: ReadonlyMap<string, ShapeGradient>): InterpretResult;
|