reamkit 1.32.1 → 1.33.1
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/LICENSE +1 -1
- package/README.md +16 -11
- package/dist/esm/core/bidi/algorithm.js +2 -2
- package/dist/esm/core/bidi/char-types.js +1 -1
- package/dist/esm/core/bidi/index.js +3 -3
- package/dist/esm/core/bytes.js +1 -1
- package/dist/esm/core/converter/facade.js +10 -5
- package/dist/esm/core/converter/ream.d.ts +9 -0
- package/dist/esm/core/converter/ream.js +40 -10
- package/dist/esm/core/crypto/asn1.js +2 -2
- package/dist/esm/core/crypto/cms.js +5 -3
- package/dist/esm/core/crypto/index.js +2 -1
- package/dist/esm/core/crypto/offcrypto.d.ts +2 -5
- package/dist/esm/core/crypto/offcrypto.js +9 -15
- package/dist/esm/core/crypto/password-error.d.ts +8 -0
- package/dist/esm/core/crypto/password-error.js +14 -0
- package/dist/esm/core/crypto/primitives.js +16 -16
- package/dist/esm/core/document-model/index.d.ts +1 -1
- package/dist/esm/core/document-model/types.d.ts +174 -2
- package/dist/esm/core/drawingml/chart-geometry.d.ts +24 -6
- package/dist/esm/core/drawingml/chart-geometry.js +905 -208
- package/dist/esm/core/drawingml/chart-parser.d.ts +5 -1
- package/dist/esm/core/drawingml/chart-parser.js +275 -19
- package/dist/esm/core/drawingml/chart-text.d.ts +41 -0
- package/dist/esm/core/drawingml/chart-text.js +93 -0
- package/dist/esm/core/drawingml/colors.js +5 -5
- package/dist/esm/core/drawingml/diagram/layout-engine.js +1 -4
- package/dist/esm/core/drawingml/diagram/run.js +2 -1
- package/dist/esm/core/drawingml/preset-geometry.js +4 -6
- package/dist/esm/core/drawingml/shape-render.js +1 -1
- package/dist/esm/core/drawingml/text-warp.js +4 -16
- package/dist/esm/core/drawingml/theme-parser.js +14 -8
- package/dist/esm/core/font/arabic-joining.js +2 -2
- package/dist/esm/core/font/binary-reader.js +2 -0
- package/dist/esm/core/font/font-registry.js +1 -0
- package/dist/esm/core/font/ligatures.js +1 -1
- package/dist/esm/core/font/opentype-layout.js +11 -5
- package/dist/esm/core/font/ttf-build.js +6 -10
- package/dist/esm/core/font/ttf-parser.js +2 -1
- package/dist/esm/core/font/ttf-subset.js +8 -8
- package/dist/esm/core/fonts/families.js +1 -1
- package/dist/esm/core/fonts/remote-fonts.js +4 -4
- package/dist/esm/core/hyphenation/index.js +1 -1
- package/dist/esm/core/images.js +8 -8
- package/dist/esm/core/ir/adapters.d.ts +9 -0
- package/dist/esm/core/ir/loss.js +1 -0
- package/dist/esm/core/line-breaker/cjk.js +1 -1
- package/dist/esm/core/line-breaker/index.js +4 -3
- package/dist/esm/core/links.js +1 -1
- package/dist/esm/core/lzw.js +1 -1
- package/dist/esm/core/metafile/blit.js +1 -1
- package/dist/esm/core/metafile/emf.js +5 -7
- package/dist/esm/core/metafile/picture.js +1 -1
- package/dist/esm/core/metafile/symbol-fonts.js +7 -7
- package/dist/esm/core/metafile/wmf.js +5 -7
- package/dist/esm/core/number-format.js +4 -6
- package/dist/esm/core/numbering/index.js +3 -2
- package/dist/esm/core/ole/cfb.js +4 -4
- package/dist/esm/core/ole/escher-blip.js +1 -1
- package/dist/esm/core/opc/index.js +5 -4
- package/dist/esm/core/opc/package.js +3 -1
- package/dist/esm/core/opc/xml-entities.js +1 -1
- package/dist/esm/core/outline.js +1 -1
- package/dist/esm/core/png-encode.js +3 -3
- package/dist/esm/core/po-helpers.js +1 -1
- package/dist/esm/core/spreadsheet-model/types.d.ts +6 -0
- package/dist/esm/core/style-cascade/index.js +4 -3
- package/dist/esm/core/tiff.js +3 -1
- package/dist/esm/excel/activex-parser.js +1 -1
- package/dist/esm/excel/conditional-format.js +7 -7
- package/dist/esm/excel/formula/functions.js +8 -4
- package/dist/esm/excel/formula/index.js +3 -3
- package/dist/esm/excel/formula/lexer.js +2 -2
- package/dist/esm/excel/formula/parser.js +4 -3
- package/dist/esm/excel/formula/value.js +1 -1
- package/dist/esm/excel/index.js +7 -6
- package/dist/esm/excel/print-model.d.ts +1 -0
- package/dist/esm/excel/print-model.js +7 -32
- package/dist/esm/excel/printer-settings.js +6 -7
- package/dist/esm/excel/rich-value.js +1 -1
- package/dist/esm/excel/sheet-shape-parser.js +4 -2
- package/dist/esm/excel/sheet-to-flow.d.ts +8 -0
- package/dist/esm/excel/sheet-to-flow.js +14 -11
- package/dist/esm/excel/styles-parser.js +5 -3
- package/dist/esm/excel/tint.js +5 -5
- package/dist/esm/excel/vml-drawing.js +2 -2
- package/dist/esm/excel/worksheet-parser.js +5 -5
- package/dist/esm/excel/xls/biff-chart.js +1 -3
- package/dist/esm/excel/xls/biff-reader.js +10 -11
- package/dist/esm/excel/xls/xls-reader.js +1 -1
- package/dist/esm/excel/xlsx-reader.js +17 -4
- package/dist/esm/excel/xlsx-to-pdf.js +1 -1
- package/dist/esm/excel/xlsx-writer.js +2 -2
- package/dist/esm/html/html-writer.js +18 -10
- package/dist/esm/index.js +2 -1
- package/dist/esm/layout/line-paint.js +1 -1
- package/dist/esm/layout/math-layout.js +5 -8
- package/dist/esm/layout/styled-layout.js +133 -75
- package/dist/esm/layout/turned-section.js +2 -2
- package/dist/esm/markdown/markdown-writer.js +50 -9
- package/dist/esm/pdf/encryption.js +9 -9
- package/dist/esm/pdf/icc-profile.js +2 -2
- package/dist/esm/pdf/index.js +3 -2
- package/dist/esm/pdf/objects.js +7 -0
- package/dist/esm/pdf/serialize.js +1 -1
- package/dist/esm/pdf/struct-tree.js +3 -1
- package/dist/esm/pdf/styled-page-emitter.js +23 -15
- package/dist/esm/pdf/styled-page-renderer.js +9 -5
- package/dist/esm/pdf-reader/annot-draw.js +3 -3
- package/dist/esm/pdf-reader/ccitt.js +2 -1
- package/dist/esm/pdf-reader/cff-outline.js +1 -4
- package/dist/esm/pdf-reader/content.js +13 -15
- package/dist/esm/pdf-reader/decrypt.d.ts +18 -6
- package/dist/esm/pdf-reader/decrypt.js +90 -45
- package/dist/esm/pdf-reader/document.d.ts +7 -1
- package/dist/esm/pdf-reader/document.js +18 -4
- package/dist/esm/pdf-reader/encodings.js +1 -1
- package/dist/esm/pdf-reader/flow-build.js +4 -6
- package/dist/esm/pdf-reader/font.js +3 -3
- package/dist/esm/pdf-reader/function.js +8 -7
- package/dist/esm/pdf-reader/icc.js +1 -1
- package/dist/esm/pdf-reader/images.js +1 -1
- package/dist/esm/pdf-reader/jbig2.js +36 -38
- package/dist/esm/pdf-reader/jpeg.js +14 -13
- package/dist/esm/pdf-reader/layout.js +12 -9
- package/dist/esm/pdf-reader/lexer.js +2 -1
- package/dist/esm/pdf-reader/math-rows.js +2 -2
- package/dist/esm/pdf-reader/optional-content.js +1 -1
- package/dist/esm/pdf-reader/page-numbers.js +1 -1
- package/dist/esm/pdf-reader/pattern-tint.js +1 -2
- package/dist/esm/pdf-reader/reader.d.ts +5 -1
- package/dist/esm/pdf-reader/reader.js +83 -16
- package/dist/esm/pdf-reader/struct-tree.js +1 -1
- package/dist/esm/pdf-reader/tagged.js +3 -2
- package/dist/esm/pdf-reader/text.js +2 -2
- package/dist/esm/pdf-reader/type1-outline.js +1 -3
- package/dist/esm/pptx/embedded-fonts.js +3 -5
- package/dist/esm/pptx/placeholder-cascade.js +1 -1
- package/dist/esm/pptx/ppt/ppt-reader.js +5 -4
- package/dist/esm/pptx/ppt/ppt-text.js +9 -10
- package/dist/esm/pptx/pptx-reader.js +6 -5
- package/dist/esm/pptx/preset-table-styles.js +1 -1
- package/dist/esm/pptx/slide-parser.js +6 -4
- package/dist/esm/pptx/sp-helpers.js +1 -1
- package/dist/esm/pptx/table-style.js +2 -1
- package/dist/esm/svg/svg-writer.js +1 -1
- package/dist/esm/word/doc/doc-reader.js +2 -2
- package/dist/esm/word/doc/doc-text.js +20 -22
- package/dist/esm/word/document-parser.js +26 -21
- package/dist/esm/word/docx-reader.js +2 -2
- package/dist/esm/word/docx-to-pdf.js +3 -3
- package/dist/esm/word/docx-writer.js +10 -6
- package/dist/esm/word/drawing-parser.js +18 -18
- package/dist/esm/word/font-table.js +1 -1
- package/dist/esm/word/index.js +6 -5
- package/dist/esm/word/numbering-parser.js +4 -3
- package/dist/esm/word/omml-parser.js +1 -1
- package/dist/esm/word/paragraph-properties.js +11 -10
- package/dist/esm/word/run-properties.js +4 -4
- package/dist/esm/word/settings-parser.js +2 -1
- package/dist/esm/word/shading.js +1 -1
- package/dist/esm/word/styles-parser.js +5 -4
- package/dist/esm/word/table-parser.js +4 -4
- package/dist/esm/word/theme-fonts.js +1 -1
- package/package.json +9 -3
|
@@ -161,12 +161,14 @@ function parseProgram(bytes) {
|
|
|
161
161
|
const tok = lexer.nextToken();
|
|
162
162
|
if (tok.kind === "eof") return depth === 0 ? out : void 0;
|
|
163
163
|
if (tok.kind === "num") out.push(tok.value);
|
|
164
|
-
else if (tok.kind === "keyword")
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
164
|
+
else if (tok.kind === "keyword") {
|
|
165
|
+
if (tok.value === "{") {
|
|
166
|
+
const inner = read(depth + 1);
|
|
167
|
+
if (!inner) return void 0;
|
|
168
|
+
out.push(inner);
|
|
169
|
+
} else if (tok.value === "}") return out;
|
|
170
|
+
else out.push(tok.value);
|
|
171
|
+
}
|
|
170
172
|
}
|
|
171
173
|
};
|
|
172
174
|
const top = read(0);
|
|
@@ -380,7 +382,6 @@ function run(program, stack, depth) {
|
|
|
380
382
|
}
|
|
381
383
|
break;
|
|
382
384
|
}
|
|
383
|
-
default: break;
|
|
384
385
|
}
|
|
385
386
|
}
|
|
386
387
|
}
|
|
@@ -71,7 +71,7 @@ function tagTable(data, view) {
|
|
|
71
71
|
if (count === 0 || count > MAX_TAGS) return void 0;
|
|
72
72
|
const out = /* @__PURE__ */ new Map();
|
|
73
73
|
for (let i = 0; i < count; i++) {
|
|
74
|
-
const at =
|
|
74
|
+
const at = 132 + i * 12;
|
|
75
75
|
if (at + 12 > data.length) break;
|
|
76
76
|
const offset = view.getUint32(at + 4);
|
|
77
77
|
const size = view.getUint32(at + 8);
|
|
@@ -235,7 +235,7 @@ function clippedUnitBox(ctm, clip) {
|
|
|
235
235
|
v1: Math.min(1, Math.max(0, v1))
|
|
236
236
|
};
|
|
237
237
|
if (!(cut.u1 - cut.u0 > CROPS) || !(cut.v1 - cut.v0 > CROPS)) return whole;
|
|
238
|
-
if (cut.u1 - cut.u0 >
|
|
238
|
+
if (cut.u1 - cut.u0 > .99 && cut.v1 - cut.v0 > .99) return whole;
|
|
239
239
|
return cut;
|
|
240
240
|
}
|
|
241
241
|
function matrixOf(file, dict) {
|
|
@@ -333,15 +333,16 @@ var MQDecoder = class {
|
|
|
333
333
|
}
|
|
334
334
|
/** BYTEIN (§E.3.4) — 0xFF is the marker escape, so it feeds a shorter byte. */
|
|
335
335
|
byteIn() {
|
|
336
|
-
if (this.byteAt(this.bp) === 255)
|
|
337
|
-
this.
|
|
338
|
-
|
|
336
|
+
if (this.byteAt(this.bp) === 255) {
|
|
337
|
+
if (this.byteAt(this.bp + 1) > 143) {
|
|
338
|
+
this.c = this.c + 65280 >>> 0;
|
|
339
|
+
this.ct = 8;
|
|
340
|
+
} else {
|
|
341
|
+
this.bp++;
|
|
342
|
+
this.c = this.c + (this.byteAt(this.bp) << 9) >>> 0;
|
|
343
|
+
this.ct = 7;
|
|
344
|
+
}
|
|
339
345
|
} else {
|
|
340
|
-
this.bp++;
|
|
341
|
-
this.c = this.c + (this.byteAt(this.bp) << 9) >>> 0;
|
|
342
|
-
this.ct = 7;
|
|
343
|
-
}
|
|
344
|
-
else {
|
|
345
346
|
this.bp++;
|
|
346
347
|
this.c = this.c + (this.byteAt(this.bp) << 8) >>> 0;
|
|
347
348
|
this.ct = 8;
|
|
@@ -359,17 +360,18 @@ var MQDecoder = class {
|
|
|
359
360
|
const [qe, nmps, nlps, sw] = QE[i] ?? QE[0];
|
|
360
361
|
let d;
|
|
361
362
|
this.a = this.a - qe & 65535;
|
|
362
|
-
if ((this.c >>> 16 & 65535) < qe)
|
|
363
|
-
this.a
|
|
364
|
-
|
|
365
|
-
|
|
363
|
+
if ((this.c >>> 16 & 65535) < qe) {
|
|
364
|
+
if (this.a < qe) {
|
|
365
|
+
this.a = qe;
|
|
366
|
+
d = mps;
|
|
367
|
+
i = nmps;
|
|
368
|
+
} else {
|
|
369
|
+
this.a = qe;
|
|
370
|
+
d = 1 - mps;
|
|
371
|
+
if (sw === 1) mps = 1 - mps;
|
|
372
|
+
i = nlps;
|
|
373
|
+
}
|
|
366
374
|
} else {
|
|
367
|
-
this.a = qe;
|
|
368
|
-
d = 1 - mps;
|
|
369
|
-
if (sw === 1) mps = 1 - mps;
|
|
370
|
-
i = nlps;
|
|
371
|
-
}
|
|
372
|
-
else {
|
|
373
375
|
this.c = this.c - (qe << 16) >>> 0;
|
|
374
376
|
if ((this.a & 32768) !== 0) return mps;
|
|
375
377
|
if (this.a < qe) {
|
|
@@ -474,9 +476,7 @@ function decodeGenericRegion(mq, cx, width, height, template, at, tpgdon, skip)
|
|
|
474
476
|
case 2:
|
|
475
477
|
ctx = px(x - 1, y) << 0 | px(x - 2, y) << 1 | px(x + (a[0]?.x ?? 2), y + (a[0]?.y ?? -1)) << 2 | px(x + 1, y - 1) << 3 | px(x, y - 1) << 4 | px(x - 1, y - 1) << 5 | px(x - 2, y - 1) << 6 | px(x + 1, y - 2) << 7 | px(x, y - 2) << 8 | px(x - 1, y - 2) << 9;
|
|
476
478
|
break;
|
|
477
|
-
default:
|
|
478
|
-
ctx = px(x - 1, y) << 0 | px(x - 2, y) << 1 | px(x - 3, y) << 2 | px(x - 4, y) << 3 | px(x + (a[0]?.x ?? 2), y + (a[0]?.y ?? -1)) << 4 | px(x + 1, y - 1) << 5 | px(x, y - 1) << 6 | px(x - 1, y - 1) << 7 | px(x - 2, y - 1) << 8 | px(x - 3, y - 1) << 9;
|
|
479
|
-
break;
|
|
479
|
+
default: ctx = px(x - 1, y) << 0 | px(x - 2, y) << 1 | px(x - 3, y) << 2 | px(x - 4, y) << 3 | px(x + (a[0]?.x ?? 2), y + (a[0]?.y ?? -1)) << 4 | px(x + 1, y - 1) << 5 | px(x, y - 1) << 6 | px(x - 1, y - 1) << 7 | px(x - 2, y - 1) << 8 | px(x - 3, y - 1) << 9;
|
|
480
480
|
}
|
|
481
481
|
bmp.data[y * width + x] = mq.decode(cx, ctx);
|
|
482
482
|
}
|
|
@@ -669,6 +669,7 @@ function buildHuffTable(lines) {
|
|
|
669
669
|
}
|
|
670
670
|
/** A most-significant-bit-first reader over a segment's data. */
|
|
671
671
|
var BitReader = class {
|
|
672
|
+
d;
|
|
672
673
|
pos = 0;
|
|
673
674
|
bit = 0;
|
|
674
675
|
constructor(d) {
|
|
@@ -1755,6 +1756,7 @@ var OOB = Symbol("OOB");
|
|
|
1755
1756
|
* needs a context set of its own.
|
|
1756
1757
|
*/
|
|
1757
1758
|
var IntDecoder = class {
|
|
1759
|
+
mq;
|
|
1758
1760
|
cx = newContexts(512);
|
|
1759
1761
|
constructor(mq) {
|
|
1760
1762
|
this.mq = mq;
|
|
@@ -1787,6 +1789,8 @@ var IntDecoder = class {
|
|
|
1787
1789
|
};
|
|
1788
1790
|
/** §A.3 — the symbol ID decoder, a fixed-width code down its own context tree. */
|
|
1789
1791
|
var IdDecoder = class {
|
|
1792
|
+
mq;
|
|
1793
|
+
codeLen;
|
|
1790
1794
|
cx;
|
|
1791
1795
|
constructor(mq, codeLen) {
|
|
1792
1796
|
this.mq = mq;
|
|
@@ -1799,14 +1803,6 @@ var IdDecoder = class {
|
|
|
1799
1803
|
return prev - (1 << this.codeLen);
|
|
1800
1804
|
}
|
|
1801
1805
|
};
|
|
1802
|
-
/** How a text region places each instance against the point it names (§6.4.5). */
|
|
1803
|
-
var Corner = /* @__PURE__ */ function(Corner) {
|
|
1804
|
-
Corner[Corner["BottomLeft"] = 0] = "BottomLeft";
|
|
1805
|
-
Corner[Corner["TopLeft"] = 1] = "TopLeft";
|
|
1806
|
-
Corner[Corner["BottomRight"] = 2] = "BottomRight";
|
|
1807
|
-
Corner[Corner["TopRight"] = 3] = "TopRight";
|
|
1808
|
-
return Corner;
|
|
1809
|
-
}(Corner || {});
|
|
1810
1806
|
/**
|
|
1811
1807
|
* §6.4.5 — draw a text region: a run of strips, each holding instances of the
|
|
1812
1808
|
* symbols in `symbols`, placed by running coordinates rather than absolute ones.
|
|
@@ -1875,12 +1871,12 @@ function decodeTextRegion(mq, symbols, p, stripsLog, lent) {
|
|
|
1875
1871
|
if (p.transposed) {
|
|
1876
1872
|
x = tt;
|
|
1877
1873
|
y = curS;
|
|
1878
|
-
if (p.refCorner ===
|
|
1879
|
-
if (p.refCorner ===
|
|
1874
|
+
if (p.refCorner === 0 || p.refCorner === 2) {}
|
|
1875
|
+
if (p.refCorner === 3 || p.refCorner === 2) x = tt - sw + 1;
|
|
1880
1876
|
} else {
|
|
1881
1877
|
x = curS;
|
|
1882
1878
|
y = tt;
|
|
1883
|
-
if (p.refCorner ===
|
|
1879
|
+
if (p.refCorner === 0 || p.refCorner === 2) y = tt - sh + 1;
|
|
1884
1880
|
}
|
|
1885
1881
|
compose(bmp, sym, x, y, p.combOp);
|
|
1886
1882
|
curS += (p.transposed ? sh : sw) - 1;
|
|
@@ -1959,7 +1955,7 @@ function decodeSymbolDictionary(mq, input, newCount, exportCount, template, at,
|
|
|
1959
1955
|
height,
|
|
1960
1956
|
instances,
|
|
1961
1957
|
stripT: 0,
|
|
1962
|
-
refCorner:
|
|
1958
|
+
refCorner: 1,
|
|
1963
1959
|
transposed: false,
|
|
1964
1960
|
combOp: 0,
|
|
1965
1961
|
defPixel: 0,
|
|
@@ -2069,11 +2065,11 @@ function decodeTextRegionHuff(bits, data, symbols, p, stripsLog, t) {
|
|
|
2069
2065
|
if (p.transposed) {
|
|
2070
2066
|
x = tt;
|
|
2071
2067
|
y = curS;
|
|
2072
|
-
if (p.refCorner ===
|
|
2068
|
+
if (p.refCorner === 3 || p.refCorner === 2) x = tt - sw + 1;
|
|
2073
2069
|
} else {
|
|
2074
2070
|
x = curS;
|
|
2075
2071
|
y = tt;
|
|
2076
|
-
if (p.refCorner ===
|
|
2072
|
+
if (p.refCorner === 0 || p.refCorner === 2) y = tt - sh + 1;
|
|
2077
2073
|
}
|
|
2078
2074
|
compose(bmp, sym, x, y, p.combOp);
|
|
2079
2075
|
curS += (p.transposed ? sh : sw) - 1;
|
|
@@ -2114,7 +2110,7 @@ function aggregateSymbolHuff(bits, data, symbols, width, height, codeLen, refine
|
|
|
2114
2110
|
height,
|
|
2115
2111
|
instances: Math.max(1, instances),
|
|
2116
2112
|
stripT: 0,
|
|
2117
|
-
refCorner:
|
|
2113
|
+
refCorner: 1,
|
|
2118
2114
|
transposed: false,
|
|
2119
2115
|
combOp: 0,
|
|
2120
2116
|
defPixel: 0,
|
|
@@ -2307,6 +2303,7 @@ function decodeGrayScale(mq, data, mmr, template, at, width, height, bits, skip)
|
|
|
2307
2303
|
return values;
|
|
2308
2304
|
}
|
|
2309
2305
|
var Reader = class {
|
|
2306
|
+
d;
|
|
2310
2307
|
pos = 0;
|
|
2311
2308
|
constructor(d) {
|
|
2312
2309
|
this.d = d;
|
|
@@ -2462,7 +2459,8 @@ function decodeJbig2(data, globals, width, height) {
|
|
|
2462
2459
|
const flags = r.u8();
|
|
2463
2460
|
page.defPixel = flags >> 2 & 1;
|
|
2464
2461
|
page.defCombOp = flags >> 3 & 3;
|
|
2465
|
-
|
|
2462
|
+
const striping = r.u16();
|
|
2463
|
+
page.striped = (striping & 32768) !== 0;
|
|
2466
2464
|
if (pw > 0 && pw !== 4294967295 && ph > 0 && ph !== 4294967295) {
|
|
2467
2465
|
page.width = Math.min(pw, width);
|
|
2468
2466
|
page.height = Math.min(ph, height);
|
|
@@ -2750,4 +2748,4 @@ function decodeJbig2(data, globals, width, height) {
|
|
|
2750
2748
|
return packed;
|
|
2751
2749
|
}
|
|
2752
2750
|
//#endregion
|
|
2753
|
-
export { decodeJbig2 };
|
|
2751
|
+
export { MQDecoder, decodeGenericRegion, decodeJbig2, decodeRefinement, newContexts, startingContexts, symbolCodeLength };
|
|
@@ -138,7 +138,6 @@ function decode(bytes) {
|
|
|
138
138
|
p = decodeScan(bytes, segEnd, frame, scanComps, dcTables, acTables, quant, restartInterval);
|
|
139
139
|
continue;
|
|
140
140
|
}
|
|
141
|
-
default: break;
|
|
142
141
|
}
|
|
143
142
|
p = segEnd;
|
|
144
143
|
}
|
|
@@ -172,7 +171,7 @@ function readFrame(bytes, p) {
|
|
|
172
171
|
pred: 0,
|
|
173
172
|
blocksPerLine: 0,
|
|
174
173
|
blocksPerCol: 0,
|
|
175
|
-
plane: new Uint8ClampedArray(0),
|
|
174
|
+
plane: /* @__PURE__ */ new Uint8ClampedArray(0),
|
|
176
175
|
stride: 0
|
|
177
176
|
});
|
|
178
177
|
}
|
|
@@ -211,7 +210,7 @@ function readQuantTables(bytes, p, end, into) {
|
|
|
211
210
|
const pq = bytes[p] >> 4;
|
|
212
211
|
const tq = bytes[p] & 15;
|
|
213
212
|
p++;
|
|
214
|
-
const table = new Int32Array(64);
|
|
213
|
+
const table = /* @__PURE__ */ new Int32Array(64);
|
|
215
214
|
for (let i = 0; i < 64; i++) table[ZIGZAG[i]] = pq === 0 ? bytes[p + i] : be16(bytes, p + i * 2);
|
|
216
215
|
p += pq === 0 ? 64 : 128;
|
|
217
216
|
into[tq] = table;
|
|
@@ -235,9 +234,9 @@ function readHuffTables(bytes, p, end, dc, ac) {
|
|
|
235
234
|
}
|
|
236
235
|
/** §F.2.2.3 — the decoding tables, built from BITS and HUFFVAL. */
|
|
237
236
|
function buildHuffTable(counts, values) {
|
|
238
|
-
const maxcode = new Int32Array(18).fill(-1);
|
|
239
|
-
const mincode = new Int32Array(18);
|
|
240
|
-
const valptr = new Int32Array(18);
|
|
237
|
+
const maxcode = (/* @__PURE__ */ new Int32Array(18)).fill(-1);
|
|
238
|
+
const mincode = /* @__PURE__ */ new Int32Array(18);
|
|
239
|
+
const valptr = /* @__PURE__ */ new Int32Array(18);
|
|
241
240
|
let code = 0;
|
|
242
241
|
let k = 0;
|
|
243
242
|
for (let l = 1; l <= 16; l++) {
|
|
@@ -271,10 +270,12 @@ function decodeScan(bytes, start, frame, scan, dcTables, acTables, quant, restar
|
|
|
271
270
|
const nextBit = () => {
|
|
272
271
|
if (bitCount === 0) {
|
|
273
272
|
let b = bytes[at++] ?? 0;
|
|
274
|
-
if (b === 255)
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
273
|
+
if (b === 255) {
|
|
274
|
+
if ((bytes[at] ?? 0) === 0) at++;
|
|
275
|
+
else {
|
|
276
|
+
at--;
|
|
277
|
+
b = 0;
|
|
278
|
+
}
|
|
278
279
|
}
|
|
279
280
|
bitBuf = b;
|
|
280
281
|
bitCount = 8;
|
|
@@ -299,7 +300,7 @@ function decodeScan(bytes, start, frame, scan, dcTables, acTables, quant, restar
|
|
|
299
300
|
for (let i = 0; i < s; i++) v = v << 1 | nextBit();
|
|
300
301
|
return v < 1 << s - 1 ? v - (1 << s) + 1 : v;
|
|
301
302
|
};
|
|
302
|
-
const block = new Int32Array(64);
|
|
303
|
+
const block = /* @__PURE__ */ new Int32Array(64);
|
|
303
304
|
const decodeBlock = (comp, row, col) => {
|
|
304
305
|
block.fill(0);
|
|
305
306
|
const q = quant[comp.tq];
|
|
@@ -352,7 +353,7 @@ function decodeScan(bytes, start, frame, scan, dcTables, acTables, quant, restar
|
|
|
352
353
|
}
|
|
353
354
|
/** §A.3.3 — cos((2x+1)uπ/16) · C(u)/2, precomputed. */
|
|
354
355
|
var COS = (() => {
|
|
355
|
-
const t = new Float32Array(64);
|
|
356
|
+
const t = /* @__PURE__ */ new Float32Array(64);
|
|
356
357
|
for (let u = 0; u < 8; u++) {
|
|
357
358
|
const c = u === 0 ? Math.SQRT1_2 : 1;
|
|
358
359
|
for (let x = 0; x < 8; x++) t[u * 8 + x] = c * Math.cos((2 * x + 1) * u * Math.PI / 16) / 2;
|
|
@@ -361,7 +362,7 @@ var COS = (() => {
|
|
|
361
362
|
})();
|
|
362
363
|
/** The separable 2-D inverse DCT of one block, levelshifted into `out`. */
|
|
363
364
|
function idctBlock(block, out, offset, stride) {
|
|
364
|
-
const rows = new Float32Array(64);
|
|
365
|
+
const rows = /* @__PURE__ */ new Float32Array(64);
|
|
365
366
|
for (let y = 0; y < 8; y++) for (let x = 0; x < 8; x++) {
|
|
366
367
|
let sum = 0;
|
|
367
368
|
for (let u = 0; u < 8; u++) sum += COS[u * 8 + x] * block[y * 8 + u];
|
|
@@ -65,12 +65,13 @@ function reconstructByLayout(file, mode = "flow") {
|
|
|
65
65
|
const art = pages.map((page, i) => {
|
|
66
66
|
const raw = collectPageImages(file, page);
|
|
67
67
|
const images = placeImages(raw.images, shown[i]);
|
|
68
|
-
const
|
|
68
|
+
const covered = images.map((img) => ({
|
|
69
69
|
minX: img.x,
|
|
70
70
|
minY: img.y,
|
|
71
71
|
maxX: img.x + img.widthPt,
|
|
72
72
|
maxY: img.y + img.heightPt
|
|
73
|
-
}))
|
|
73
|
+
}));
|
|
74
|
+
const lifted = collectPageVectors(file, page, covered);
|
|
74
75
|
return {
|
|
75
76
|
images,
|
|
76
77
|
imageLosses: raw.losses,
|
|
@@ -252,7 +253,8 @@ function reconstructByLayout(file, mode = "flow") {
|
|
|
252
253
|
};
|
|
253
254
|
/** A figure's parts in the order the page painted them, its words over its drawing. */
|
|
254
255
|
const figureMembers = (figure) => {
|
|
255
|
-
const
|
|
256
|
+
const painted = [...figure.vectors].sort((a, b) => compareOrder(a.orderKey, b.orderKey));
|
|
257
|
+
const drawn = [...joinLetters(painted).map((v) => ({
|
|
256
258
|
key: v.orderKey,
|
|
257
259
|
member: vectorMember(v)
|
|
258
260
|
})), ...figure.images.map((img) => ({
|
|
@@ -366,7 +368,7 @@ function reconstructByLayout(file, mode = "flow") {
|
|
|
366
368
|
if (cells.some((c) => c.lines.length === 0)) return void 0;
|
|
367
369
|
const top = Math.max(...cells.map((c) => c.lines[0].y));
|
|
368
370
|
const edge = above ?? {
|
|
369
|
-
y: Math.max(...cells.map((c) => c.lines[0].y + .
|
|
371
|
+
y: Math.max(...cells.map((c) => c.lines[0].y + .96 * c.lines[0].fontSize)),
|
|
370
372
|
lineHeight: 0
|
|
371
373
|
};
|
|
372
374
|
const starts = cells.map((c, k) => k === 0 ? left : c.cell.from);
|
|
@@ -1850,7 +1852,7 @@ function continuesLeader(prev, run, fontSize) {
|
|
|
1850
1852
|
const dots = prev.text.endsWith(".") && run.text.startsWith(".");
|
|
1851
1853
|
return (isLeader(prev.text) && prev.text === run.text || dots) && run.x - prev.endX < (run.fontSizePt || fontSize) * CELL_GAP_EM;
|
|
1852
1854
|
}
|
|
1853
|
-
var LEADER_CHARS = new Set([
|
|
1855
|
+
var LEADER_CHARS = /* @__PURE__ */ new Set([
|
|
1854
1856
|
".",
|
|
1855
1857
|
"·",
|
|
1856
1858
|
"_",
|
|
@@ -2332,13 +2334,13 @@ function joinLines(lines) {
|
|
|
2332
2334
|
/** §17.3.3.29 — the hyphen that is a PLACE a word may break, not a hyphen. */
|
|
2333
2335
|
var SOFT_HYPHEN = "";
|
|
2334
2336
|
/** The hyphens that belong to the word they end. */
|
|
2335
|
-
var HYPHENS = new Set([
|
|
2337
|
+
var HYPHENS = /* @__PURE__ */ new Set([
|
|
2336
2338
|
"-",
|
|
2337
2339
|
"‐",
|
|
2338
2340
|
"‑"
|
|
2339
2341
|
]);
|
|
2340
2342
|
/** The dashes, en and em, that belong to the words either side where closed up to them. */
|
|
2341
|
-
var DASHES = new Set(["–", "—"]);
|
|
2343
|
+
var DASHES = /* @__PURE__ */ new Set(["–", "—"]);
|
|
2342
2344
|
/** How many lines' worth of indent still reads as a first line, not a placement. */
|
|
2343
2345
|
var INDENT_LINES = 3;
|
|
2344
2346
|
/** Where in the run of line starts the column's own left edge is looked for. */
|
|
@@ -3917,8 +3919,9 @@ function tableFrom(runs, gutters, edges, stepped) {
|
|
|
3917
3919
|
};
|
|
3918
3920
|
return [...above.map((row) => {
|
|
3919
3921
|
const y = Math.max(...row.map((r) => r.y));
|
|
3922
|
+
const size = Math.max(...row.map((r) => r.fontSizePt || fontSize));
|
|
3920
3923
|
return {
|
|
3921
|
-
el: paragraphFromRuns(lineOf(row, y,
|
|
3924
|
+
el: paragraphFromRuns(lineOf(row, y, size, stepped).spans),
|
|
3922
3925
|
top: y
|
|
3923
3926
|
};
|
|
3924
3927
|
}), {
|
|
@@ -4002,4 +4005,4 @@ var TABLE_ALIGNED_SHARE = .6;
|
|
|
4002
4005
|
*/
|
|
4003
4006
|
var TABLE_CELL_FILL = .65;
|
|
4004
4007
|
//#endregion
|
|
4005
|
-
export { FOOTER_PART, HEADER_PART, endedParagraph, footerBand, numberedFrom, numberingOf, pageTextEdges, reconstructByLayout, runningFoot, stepsBetweenWords };
|
|
4008
|
+
export { EVEN_FOOTER_PART, FOOTER_PART, HEADER_PART, drawnWords, endedParagraph, footerBand, numberedFrom, numberingOf, pageTextEdges, reconstructByLayout, runningFoot, stepsBetweenWords };
|
|
@@ -21,6 +21,7 @@ function hexVal(b) {
|
|
|
21
21
|
* read and assign it directly.
|
|
22
22
|
*/
|
|
23
23
|
var Lexer = class {
|
|
24
|
+
buf;
|
|
24
25
|
pos;
|
|
25
26
|
/**
|
|
26
27
|
* @param buf The PDF byte buffer to tokenize.
|
|
@@ -306,4 +307,4 @@ function latin1(bytes) {
|
|
|
306
307
|
return s;
|
|
307
308
|
}
|
|
308
309
|
//#endregion
|
|
309
|
-
export { Lexer };
|
|
310
|
+
export { Lexer, latin1 };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
//#region src/pdf-reader/math-rows.ts
|
|
2
2
|
/** The brackets a matrix may be written in, opening → closing. */
|
|
3
|
-
var BRACKETS = new Map([
|
|
3
|
+
var BRACKETS = /* @__PURE__ */ new Map([
|
|
4
4
|
["(", ")"],
|
|
5
5
|
["[", "]"],
|
|
6
6
|
["{", "}"],
|
|
@@ -94,7 +94,7 @@ function matrixFrom(cluster) {
|
|
|
94
94
|
endChr: pair.close.text.trim(),
|
|
95
95
|
children: [inside.matrix]
|
|
96
96
|
});
|
|
97
|
-
used = new Set([
|
|
97
|
+
used = /* @__PURE__ */ new Set([
|
|
98
98
|
...used,
|
|
99
99
|
...inside.used,
|
|
100
100
|
pair.open,
|
|
@@ -106,7 +106,7 @@ function sample(marks, cell) {
|
|
|
106
106
|
if (flat.some((m) => covers(m, px, py))) hit++;
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
|
-
return hit /
|
|
109
|
+
return hit / 2304;
|
|
110
110
|
}
|
|
111
111
|
/** Whether one mark paints the point — inside its outline, or under its pen. */
|
|
112
112
|
function covers(mark, px, py) {
|
|
@@ -182,7 +182,6 @@ function flatten(segs) {
|
|
|
182
182
|
]);
|
|
183
183
|
cx = sx;
|
|
184
184
|
cy = sy;
|
|
185
|
-
break;
|
|
186
185
|
}
|
|
187
186
|
return out;
|
|
188
187
|
}
|
|
@@ -14,11 +14,15 @@ import { FlowDoc } from '../core/ir/flow.js';
|
|
|
14
14
|
* @param filters Decoders for `/Filter` names this reader does not implement
|
|
15
15
|
* (§7.4); see {@link StreamFilters}.
|
|
16
16
|
* @returns The reconstructed FlowDoc and its accumulated {@link Loss} report.
|
|
17
|
+
* @throws WrongPasswordError when the file is encrypted and the password opens
|
|
18
|
+
* it neither as its user nor as its owner — none given included.
|
|
17
19
|
*
|
|
18
20
|
* Which of the two readings a file gets is the FILE's to decide and no
|
|
19
21
|
* caller's: a page that is mostly marks is reproduced where it stands, one
|
|
20
22
|
* that is mostly lines is re-set as a document, and the reader records which
|
|
21
|
-
* it chose. There is no override — see the note on {@link readingOf}.
|
|
23
|
+
* it chose. There is no override — see the note on {@link readingOf}. A file
|
|
24
|
+
* kept as a page also carries its `flowing` reading, for the one medium that
|
|
25
|
+
* can keep no page: see {@link ReadResult.flowing}.
|
|
22
26
|
*/
|
|
23
27
|
export declare function readPdf(bytes: Uint8Array, password?: string, filters?: StreamFilters): ReadResult<FlowDoc>;
|
|
24
28
|
/**
|
|
@@ -4,6 +4,7 @@ import { extractPageText } from "./text.js";
|
|
|
4
4
|
import { collectPageVectors } from "./vector.js";
|
|
5
5
|
import { reconstructByLayout } from "./layout.js";
|
|
6
6
|
import { reconstructTaggedPdf } from "./tagged.js";
|
|
7
|
+
import { WrongPasswordError } from "../core/crypto/password-error.js";
|
|
7
8
|
//#region src/pdf-reader/reader.ts
|
|
8
9
|
function sniffPdf(bytes) {
|
|
9
10
|
const limit = Math.min(bytes.length - 5, 1024);
|
|
@@ -41,30 +42,53 @@ function endsLikePdf(bytes) {
|
|
|
41
42
|
* @param filters Decoders for `/Filter` names this reader does not implement
|
|
42
43
|
* (§7.4); see {@link StreamFilters}.
|
|
43
44
|
* @returns The reconstructed FlowDoc and its accumulated {@link Loss} report.
|
|
45
|
+
* @throws WrongPasswordError when the file is encrypted and the password opens
|
|
46
|
+
* it neither as its user nor as its owner — none given included.
|
|
44
47
|
*
|
|
45
48
|
* Which of the two readings a file gets is the FILE's to decide and no
|
|
46
49
|
* caller's: a page that is mostly marks is reproduced where it stands, one
|
|
47
50
|
* that is mostly lines is re-set as a document, and the reader records which
|
|
48
|
-
* it chose. There is no override — see the note on {@link readingOf}.
|
|
51
|
+
* it chose. There is no override — see the note on {@link readingOf}. A file
|
|
52
|
+
* kept as a page also carries its `flowing` reading, for the one medium that
|
|
53
|
+
* can keep no page: see {@link ReadResult.flowing}.
|
|
49
54
|
*/
|
|
50
55
|
function readPdf(bytes, password = "", filters = {}) {
|
|
51
56
|
const file = PdfFile.parse(bytes, password, filters);
|
|
57
|
+
if (file.passwordRefused) throw new WrongPasswordError(password === "" ? "This PDF needs a password to open — pass it as `password`" : "The password opens this PDF neither as its user nor as its owner");
|
|
58
|
+
const { reading, forText } = readingOf(file);
|
|
59
|
+
const read = readAs(file, reading);
|
|
60
|
+
if (!forText) return read;
|
|
61
|
+
return {
|
|
62
|
+
...read,
|
|
63
|
+
flowing: () => readAs(PdfFile.parse(bytes, password, filters), "flow", true)
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* The file read the one way: the losses every reading reports, the reading's
|
|
68
|
+
* own, and its reconstruction.
|
|
69
|
+
*
|
|
70
|
+
* @param file The parsed file.
|
|
71
|
+
* @param reading Whether the words re-set as a document or stand where drawn.
|
|
72
|
+
* @param reflowed Whether this is the flowing reading of a file the reader
|
|
73
|
+
* keeps as a page, for a medium that places nothing.
|
|
74
|
+
* @returns The reconstructed FlowDoc and its losses.
|
|
75
|
+
*/
|
|
76
|
+
function readAs(file, reading, reflowed = false) {
|
|
52
77
|
const losses = [];
|
|
53
78
|
if (file.encryptionUnsupported) losses.push({
|
|
54
79
|
severity: "dropped",
|
|
55
80
|
feature: FEATURES.text,
|
|
56
|
-
detail: "encrypted PDF —
|
|
81
|
+
detail: "encrypted PDF — its security handler is not supported, or its /Encrypt dictionary cannot be read, so its content cannot be decrypted"
|
|
57
82
|
});
|
|
58
83
|
for (const name of file.unknownFilters) losses.push({
|
|
59
84
|
severity: "dropped",
|
|
60
85
|
feature: FEATURES.text,
|
|
61
86
|
detail: `PDF stream filter /${name} is not supported; streams using it are unreadable`
|
|
62
87
|
});
|
|
63
|
-
const reading = readingOf(file);
|
|
64
88
|
losses.push({
|
|
65
89
|
severity: "degraded",
|
|
66
90
|
feature: FEATURES.text,
|
|
67
|
-
detail: reading === "positional" ? "PDF read as a PAGE (placed): its artwork outweighs its prose, so every line stands where its glyphs stand" : "PDF read as a DOCUMENT (flowing): its prose outweighs its artwork, so the words re-set and the artwork takes its turn in reading order"
|
|
91
|
+
detail: reflowed ? "PDF read as a DOCUMENT (flowing) for a medium that keeps only the text: the file is kept as a PAGE elsewhere for its drawn letters or its rules, which only a page can show where they stand" : reading === "positional" ? "PDF read as a PAGE (placed): its artwork outweighs its prose, so every line stands where its glyphs stand" : "PDF read as a DOCUMENT (flowing): its prose outweighs its artwork, so the words re-set and the artwork takes its turn in reading order"
|
|
68
92
|
});
|
|
69
93
|
const tagged = reading === "positional" ? void 0 : reconstructTaggedPdf(file);
|
|
70
94
|
const reconstruction = tagged ?? reconstructByLayout(file, reading);
|
|
@@ -94,7 +118,12 @@ function readPdf(bytes, password = "", filters = {}) {
|
|
|
94
118
|
* folded into a report does not make the report a plan.
|
|
95
119
|
*
|
|
96
120
|
* A threshold is a guess, and this one is stated rather than hidden: the reader
|
|
97
|
-
* records which reading it took and why
|
|
121
|
+
* records which reading it took and why.
|
|
122
|
+
*
|
|
123
|
+
* A glyph the file names no character for is drawn, and counted as a mark like
|
|
124
|
+
* any other path — it IS one, for every medium that has to place it; so is a
|
|
125
|
+
* rule. Whether the page was a page for those alone is said as well: see
|
|
126
|
+
* `forText`.
|
|
98
127
|
*/
|
|
99
128
|
function readingOf(file) {
|
|
100
129
|
/**
|
|
@@ -112,14 +141,28 @@ function readingOf(file) {
|
|
|
112
141
|
const DRAWN = 2;
|
|
113
142
|
/** Below this many runs, an angle is a stamp or a watermark and not the page. */
|
|
114
143
|
const ENOUGH_TURNED = 8;
|
|
144
|
+
/**
|
|
145
|
+
* How many rules a page may have for each mark of other artwork and still be
|
|
146
|
+
* a ruled document: an estimate shades its heading row and its total, and a
|
|
147
|
+
* dozen shaded cells under eighty rules are a table's, not a drawing's.
|
|
148
|
+
*/
|
|
149
|
+
const RULES_PER_MARK = 4;
|
|
115
150
|
const ratios = [];
|
|
151
|
+
/** The same, the drawn letters left out. */
|
|
152
|
+
const artwork = [];
|
|
153
|
+
const ratioOf = (marks, lines) => marks < ENOUGH_MARKS ? 0 : lines > 0 ? marks / lines : DRAWN;
|
|
116
154
|
for (const page of file.pages()) {
|
|
117
155
|
let marks = 0;
|
|
156
|
+
let letters = 0;
|
|
157
|
+
let rules = 0;
|
|
118
158
|
let lines = 0;
|
|
119
159
|
let turned = 0;
|
|
120
160
|
let runs = 0;
|
|
121
161
|
try {
|
|
122
|
-
|
|
162
|
+
const vectors = collectPageVectors(file, page, []).vectors;
|
|
163
|
+
marks = vectors.length;
|
|
164
|
+
letters = vectors.filter((v) => v.glyph === true).length;
|
|
165
|
+
rules = vectors.filter(isRule).length;
|
|
123
166
|
const ys = /* @__PURE__ */ new Set();
|
|
124
167
|
for (const run of extractPageText(file, page)) {
|
|
125
168
|
ys.add(Math.round(run.y));
|
|
@@ -132,17 +175,41 @@ function readingOf(file) {
|
|
|
132
175
|
}
|
|
133
176
|
if (runs >= ENOUGH_TURNED && turned > runs * .5) {
|
|
134
177
|
ratios.push(DRAWN);
|
|
178
|
+
artwork.push(DRAWN);
|
|
135
179
|
continue;
|
|
136
180
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}
|
|
141
|
-
ratios.push(lines > 0 ? marks / lines : DRAWN);
|
|
181
|
+
ratios.push(ratioOf(marks, lines));
|
|
182
|
+
const ruled = lines > 0 && marks - letters - rules < Math.max(ENOUGH_MARKS, rules / RULES_PER_MARK);
|
|
183
|
+
artwork.push(ruled ? 0 : ratioOf(marks - letters, lines));
|
|
142
184
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
185
|
+
const drawn = (rs) => {
|
|
186
|
+
const sorted = [...rs].sort((a, b) => a - b);
|
|
187
|
+
return (sorted[Math.floor(sorted.length / 2)] ?? 0) >= DRAWN;
|
|
188
|
+
};
|
|
189
|
+
if (!drawn(ratios)) return {
|
|
190
|
+
reading: "flow",
|
|
191
|
+
forText: false
|
|
192
|
+
};
|
|
193
|
+
return {
|
|
194
|
+
reading: "positional",
|
|
195
|
+
forText: !drawn(artwork)
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
/** Thinner than this a straight mark is a line, whatever it was drawn as. */
|
|
199
|
+
var RULE_THICKNESS = 2.5;
|
|
200
|
+
/** …and it is a rule rather than a dot or a tick from this long. */
|
|
201
|
+
var RULE_LENGTH = 4;
|
|
202
|
+
/**
|
|
203
|
+
* Whether a painted path is a RULE: straight, along the page, a line thin
|
|
204
|
+
* enough to be one — stroked as a line or filled as a hairline box, which is
|
|
205
|
+
* how many producers draw a table's grid.
|
|
206
|
+
*/
|
|
207
|
+
function isRule(v) {
|
|
208
|
+
if (v.glyph === true || v.gradient !== void 0) return false;
|
|
209
|
+
if (v.segs.some((seg) => seg.op === "cubic")) return false;
|
|
210
|
+
const w = v.maxX - v.minX;
|
|
211
|
+
const h = v.maxY - v.minY;
|
|
212
|
+
return Math.min(w, h) <= RULE_THICKNESS && Math.max(w, h) >= RULE_LENGTH;
|
|
146
213
|
}
|
|
147
214
|
/**
|
|
148
215
|
* The `pdfReader` adapter: a {@link DocumentReader} that sniffs the `%PDF-`
|
|
@@ -151,7 +218,7 @@ function readingOf(file) {
|
|
|
151
218
|
var pdfReader = {
|
|
152
219
|
id: "pdf",
|
|
153
220
|
produces: "flow",
|
|
154
|
-
supports: new Set([
|
|
221
|
+
supports: /* @__PURE__ */ new Set([
|
|
155
222
|
FEATURES.text,
|
|
156
223
|
FEATURES.tables,
|
|
157
224
|
FEATURES.lists,
|
|
@@ -165,4 +232,4 @@ function isFilters(value) {
|
|
|
165
232
|
return typeof value === "object" && value !== null;
|
|
166
233
|
}
|
|
167
234
|
//#endregion
|
|
168
|
-
export { pdfReader };
|
|
235
|
+
export { pdfReader, readPdf };
|
|
@@ -123,7 +123,7 @@ function allMcids(node) {
|
|
|
123
123
|
* `Sub`), a formula (§14.8.4.5.5, which is set in a line as often as out of
|
|
124
124
|
* one), and a list label, which is the start of its item's line.
|
|
125
125
|
*/
|
|
126
|
-
var INLINE = new Set([
|
|
126
|
+
var INLINE = /* @__PURE__ */ new Set([
|
|
127
127
|
"Span",
|
|
128
128
|
"Quote",
|
|
129
129
|
"Reference",
|
|
@@ -43,12 +43,13 @@ function reconstructTaggedPdf(file) {
|
|
|
43
43
|
const placedRuns = turned ? extracted.map((runs, i) => placeRuns(runs, shown[i])) : onSheets;
|
|
44
44
|
const vectorLosses = [];
|
|
45
45
|
const pageVectors = pages.map((page, i) => {
|
|
46
|
-
const
|
|
46
|
+
const covered = collectPageImages(file, page).images.map((img) => ({
|
|
47
47
|
minX: img.x,
|
|
48
48
|
minY: img.y,
|
|
49
49
|
maxX: img.x + img.widthPt,
|
|
50
50
|
maxY: img.y + img.heightPt
|
|
51
|
-
}))
|
|
51
|
+
}));
|
|
52
|
+
const lifted = collectPageVectors(file, page, covered);
|
|
52
53
|
vectorLosses.push(...lifted.losses);
|
|
53
54
|
return placeVectors(lifted.vectors, shown[i]);
|
|
54
55
|
});
|