@qrcommunication/gigapdf-lib 0.43.0 → 0.45.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/CHANGELOG.md CHANGED
@@ -4,6 +4,57 @@ All notable changes to `@qrcommunication/gigapdf-lib` are documented here.
4
4
  The format follows [Keep a Changelog](https://keepachangelog.com/) and the
5
5
  project adheres to [Semantic Versioning](https://semver.org/).
6
6
 
7
+ ## [0.45.0] - 2026-06-18
8
+
9
+ ### Added
10
+
11
+ - **Rich Office → PDF conversion.** `officeToPdf` now maps DOCX/XLSX/PPTX/
12
+ ODT/ODS/ODP (and legacy OLE2 `.doc`/`.xls`/`.ppt`) to styled HTML — headings,
13
+ bold/italic/size/colour runs, tables, lists and embedded images — and renders
14
+ it through the native HTML→PDF engine instead of the old text-only flatten. No
15
+ LibreOffice/soffice dependency.
16
+ - **More OCR languages.** New host-loaded `.gpocr` line models beyond
17
+ Latin/Cyrillic/Greek: Arabic + Hebrew (RTL), Devanagari, Bengali and Tamil,
18
+ plus a larger 24/48/96 backbone retrain (clean-print CER now well past
19
+ Tesseract) and a handwriting-augmented `alpha` variant. Auto-discovered by
20
+ `loadAllBundledOcrModels`; the wasm still ships no weights.
21
+
22
+ ### Fixed
23
+
24
+ - **Text extraction recurses into form XObjects.** Text drawn via reusable form
25
+ XObjects (the `Do` operator — common in invoice/template PDFs) was rasterised
26
+ but never extracted, so it showed in the page image yet could not be selected
27
+ or edited. The extractor now walks `Do` into `/Subtype /Form` XObjects
28
+ (composing the form `/Matrix` with the CTM, with depth and cycle guards), so
29
+ form text is recovered in page space.
30
+ - **Font-less HTML render no longer drops text.** The HTML renderer skipped
31
+ every text run when no embedded font matched, so a render with no
32
+ host-provided fonts produced a blank page; a base-14 standard-font fallback
33
+ now always paints text.
34
+
35
+ ## [0.44.0] - 2026-06-18
36
+
37
+ ### Added
38
+
39
+ - **Raw Type1 (PFB/PFA) font embedding.** Classic encrypted Type1 programs
40
+ (PDF `FontFile`, PFB, PFA) are parsed (eexec + charstring decryption),
41
+ transcoded to Type2 and embedded through the bare-CFF → OpenType path — the
42
+ last font format that required an external converter (FontForge).
43
+ - **Bundled per-script OCR models + multi-language recognition.** The `.gpocr`
44
+ CRNN models ship under `models/`; `GigaPdfEngine.loadAllBundledOcrModels()`
45
+ (plus `loadBundledOcrModel` / `loadBundledOcrModels` and the `OcrScript` type)
46
+ load them so `doc.ocr` recognizes non-Latin scripts — Cyrillic, Greek, Arabic,
47
+ Urdu, Hebrew (the RTL group), Devanagari, Bengali, Tamil — routed per line by
48
+ the engine's script detector. The wasm still ships no weights.
49
+
50
+ ### Fixed
51
+
52
+ - **Glyph counters are now hollow in `renderPage`.** Each glyph contour was
53
+ filled separately, painting counters (the holes in O, e, a, 0, 8, B…) solid.
54
+ Every contour of a glyph is now accumulated and filled once with the non-zero
55
+ winding rule, so inner contours carve out correctly — fixing blobby,
56
+ low-quality text in the rasterized page (editor background, OCR input).
57
+
7
58
  ## [0.43.0] - 2026-06-18
8
59
 
9
60
  ### Added
package/dist/index.cjs CHANGED
@@ -20,6 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
+ ALL_OCR_SCRIPTS: () => ALL_OCR_SCRIPTS,
23
24
  GigaPdfDoc: () => GigaPdfDoc,
24
25
  GigaPdfEngine: () => GigaPdfEngine
25
26
  });
@@ -32,6 +33,20 @@ var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
32
33
  // src/index.ts
33
34
  var enc = new TextEncoder();
34
35
  var dec = new TextDecoder();
36
+ var OCR_MODEL_FILES = {
37
+ alpha: "ocr_alpha.gpocr",
38
+ arabic: "ocr_arabic.gpocr",
39
+ devanagari: "ocr_deva.gpocr",
40
+ bengali: "ocr_beng.gpocr",
41
+ tamil: "ocr_taml.gpocr"
42
+ };
43
+ var ALL_OCR_SCRIPTS = [
44
+ "alpha",
45
+ "arabic",
46
+ "devanagari",
47
+ "bengali",
48
+ "tamil"
49
+ ];
35
50
  var GigaPdfEngine = class _GigaPdfEngine {
36
51
  constructor(ex) {
37
52
  this.ex = ex;
@@ -404,6 +419,70 @@ var GigaPdfEngine = class _GigaPdfEngine {
404
419
  clearOcrModels() {
405
420
  this.ex.gp_ocr_clear_models();
406
421
  }
422
+ /**
423
+ * Resolve a bundled `.gpocr` model (shipped under `models/`) and load it into
424
+ * the engine via {@link loadOcrModel}. **Node hosts only** — it reads the blob
425
+ * from disk the same way {@link loadDefault} resolves the wasm. Returns `true`
426
+ * on success. Use this to recognize non-Latin scripts (Arabic, Devanagari,
427
+ * Bengali, Tamil) or to upgrade Latin/Cyrillic/Greek to the CRNN (`alpha`).
428
+ */
429
+ async loadBundledOcrModel(script) {
430
+ const nodeImport = (m) => import(
431
+ /* webpackIgnore: true */
432
+ /* @vite-ignore */
433
+ m
434
+ );
435
+ const { readFile } = await nodeImport("node:fs/promises");
436
+ const { fileURLToPath } = await nodeImport("node:url");
437
+ const path = fileURLToPath(
438
+ new URL(`../models/${OCR_MODEL_FILES[script]}`, importMetaUrl)
439
+ );
440
+ return this.loadOcrModel(await readFile(path));
441
+ }
442
+ /**
443
+ * Load several bundled OCR models (idempotent per call). Returns the scripts
444
+ * that loaded successfully. Pass {@link ALL_OCR_SCRIPTS} to recognize text in
445
+ * any supported language; the engine's script detector routes each line to the
446
+ * right model.
447
+ */
448
+ async loadBundledOcrModels(scripts) {
449
+ const loaded = [];
450
+ for (const script of scripts) {
451
+ if (await this.loadBundledOcrModel(script)) loaded.push(script);
452
+ }
453
+ return loaded;
454
+ }
455
+ /**
456
+ * Discover and load EVERY bundled `.gpocr` model (Node hosts only). The
457
+ * engine's script detector then routes each recognized line to the matching
458
+ * model, so the OCR recognizes text in any shipped script — Latin, Cyrillic,
459
+ * Greek, Arabic, Urdu, Hebrew (the RTL group), Devanagari, Bengali, Tamil, and
460
+ * any model added later — with no code change. Returns the number loaded.
461
+ */
462
+ async loadAllBundledOcrModels() {
463
+ const nodeImport = (m) => import(
464
+ /* webpackIgnore: true */
465
+ /* @vite-ignore */
466
+ m
467
+ );
468
+ const { readFile, readdir } = await nodeImport("node:fs/promises");
469
+ const { fileURLToPath } = await nodeImport("node:url");
470
+ let entries;
471
+ try {
472
+ entries = await readdir(fileURLToPath(new URL("../models/", importMetaUrl)));
473
+ } catch {
474
+ return 0;
475
+ }
476
+ let count = 0;
477
+ for (const name of entries) {
478
+ if (!name.endsWith(".gpocr")) continue;
479
+ const bytes = await readFile(
480
+ fileURLToPath(new URL(`../models/${name}`, importMetaUrl))
481
+ );
482
+ if (this.loadOcrModel(bytes)) count += 1;
483
+ }
484
+ return count;
485
+ }
407
486
  // ── fonts (catalog / Google Fonts URL — the host performs the fetch) ───────
408
487
  fontCatalog() {
409
488
  return this._json((o) => this.ex.gp_font_catalog_json(o));
@@ -1568,6 +1647,7 @@ var GigaPdfDoc = class {
1568
1647
  };
1569
1648
  // Annotate the CommonJS export names for ESM import in node:
1570
1649
  0 && (module.exports = {
1650
+ ALL_OCR_SCRIPTS,
1571
1651
  GigaPdfDoc,
1572
1652
  GigaPdfEngine
1573
1653
  });