@qrcommunication/gigapdf-lib 0.109.1 → 0.110.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/CHANGELOG.md CHANGED
@@ -6,6 +6,68 @@ project adheres to [Semantic Versioning](https://semver.org/).
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.110.1] - 2026-06-30
10
+
11
+ ### Fixed — releases now ship the OCR `.gpocr` models again
12
+
13
+ - The 22 per-script line-OCR model weights (`models/ocr_*.gpocr`, 9.6 MB) are
14
+ **git-ignored** (`sdk/.gitignore: models/`), so a clean CI checkout had none —
15
+ every CI-published version since the ignore (e.g. `0.109.1`, `0.110.0`) shipped
16
+ **zero** OCR models, silently degrading runtime OCR to the mono-glyph
17
+ classifier (`0.63.0` still had them because it predates the gap). The release
18
+ workflow now **fetches the models from a durable GitHub Release asset
19
+ (`ocr-models-v1`), verifies their SHA-256, and stages them** before
20
+ `build-wasm.sh`, so every published package carries the full model set again —
21
+ without committing 9.6 MB of weights to the repo. No engine/API change.
22
+
23
+ ## [0.110.0] - 2026-06-30
24
+
25
+ ### Added — `extractWebFont`: serve a document's own embedded fonts to a browser
26
+
27
+ - New engine method **`extractWebFont(name)`** (FFI `gp_extract_web_font`) returns
28
+ a PDF's **own embedded font** as a **browser-loadable sfnt** for a `@font-face`
29
+ overlay-text layer — keeping the document's **original glyphs**, never a
30
+ substitute. It complements `extractFont` (which returns the raw program for
31
+ re-embedding): where `extractFont` hands back bytes a browser's `FontFace`/OTS
32
+ routinely rejects (a bare CFF, or a `cmap`-less TrueType subset),
33
+ `extractWebFont` repairs them:
34
+ - **CFF (Type1C)** → wrapped to OpenType (`OTTO`) with a `cmap` built from the
35
+ PDF's `code → Unicode` decode mapping (the same one text extraction uses, so
36
+ it resolves subset glyphs whose `/Differences` carries opaque `gNN` names and
37
+ whose `/ToUnicode` is partial — the exact case that otherwise renders the
38
+ wrong letters).
39
+ - **TrueType** → passed through when it already maps Unicode; otherwise a `cmap`
40
+ is synthesised (`code → Unicode` from the decode path, `code → gid` borrowed
41
+ from a sibling's `cmap` for full-glyph-order subsets, else the `code == gid`
42
+ convention) and the OTS-mandatory `OS/2`/`name`/`post` are stubbed in — the
43
+ original `glyf` is kept verbatim.
44
+ - Face selection prefers an **exact raw `/BaseFont`** match (subset prefix
45
+ included), so a host that serves many disjoint subsets of one family gets
46
+ *that* subset's own glyphs per run.
47
+ - New internal helper `cff_to_otf::repair_sfnt_with_cmap` (injects a Unicode
48
+ `cmap` + the OTS-required tables around existing glyph data) and a hardened
49
+ `build_cmap` (now sorts/dedupes segments, so a synthesised format-4 table is
50
+ accepted by strict shapers — FreeType/HarfBuzz).
51
+ - Tests: `repair_injects_cmap_and_required_tables_keeping_originals` (the repair
52
+ keeps the original tables and adds a working `cmap`).
53
+
54
+ ### Added — bidirectional conversion symmetry: model importers for RTF, TXT and images
55
+
56
+ - New engine methods `rtfToModel(rtf)`, `txtToModel(text)` and
57
+ `imageToModel(image)` complete the **lower-any-format-into-the-model** matrix.
58
+ The core already exposed `rtf_to_model` / `txt_to_model` / `image_to_model`,
59
+ but they had **no WASM/SDK binding** — so `modelToRtf` could write RTF yet
60
+ nothing could read RTF *into* the model, and likewise for plain text and raster
61
+ images. The three new FFI entry points (`gp_model_from_rtf` /
62
+ `gp_model_from_txt` / `gp_model_from_image`) and their TypeScript wrappers close
63
+ that asymmetry, matching the existing `officeToModel` / `htmlToModel` /
64
+ `mdToModel` / `csvToModel`. `imageToModel` returns `null` on non-image bytes;
65
+ `rtfToModel` routes through the rich RTF parser (run styling, tables, `\pict`
66
+ images, `\field` links).
67
+ - Tests: `test/model_import.test.ts` — 7 round-trip cases through the production
68
+ WASM (`txtToModel`→`modelToPdf`, `rtfToModel`→`modelToRtf`,
69
+ `imageToModel`→`modelToPdf`, plus the non-image `null` guard).
70
+
9
71
  ## [0.109.1] - 2026-06-30
10
72
 
11
73
  ### Fixed — image-format documentation accuracy
package/dist/index.cjs CHANGED
@@ -813,6 +813,40 @@ var GigaPdfEngine = class _GigaPdfEngine {
813
813
  (p, l) => this._modelOrNull((o) => this.ex.gp_model_from_csv(p, l, o))
814
814
  );
815
815
  }
816
+ /**
817
+ * Lower an RTF string into the unified {@link GigaDocument} model. Routed
818
+ * through the rich RTF parser, so run-level styling (bold/italic/underline/
819
+ * strike, colour, size, family), tables, `\pict` images and `\field`
820
+ * hyperlinks are recovered — the inverse of {@link modelToRtf}.
821
+ */
822
+ rtfToModel(rtf) {
823
+ return this._withStr(
824
+ rtf,
825
+ (p, l) => JSON.parse(this._str((o) => this.ex.gp_model_from_rtf(p, l, o)))
826
+ );
827
+ }
828
+ /**
829
+ * Lower a plain-text string into the unified {@link GigaDocument} model: one
830
+ * paragraph per line (blank lines kept as empty paragraphs).
831
+ */
832
+ txtToModel(text) {
833
+ return this._withStr(
834
+ text,
835
+ (p, l) => JSON.parse(this._str((o) => this.ex.gp_model_from_txt(p, l, o)))
836
+ );
837
+ }
838
+ /**
839
+ * Lower a raster image (PNG/JPEG/GIF/WebP, auto-detected) into the unified
840
+ * {@link GigaDocument} model — a single full-page picture block sized to the
841
+ * image's own aspect ratio, with the bytes interned in the model's resource
842
+ * table. Returns `null` if the bytes aren't a recognized image.
843
+ */
844
+ imageToModel(image) {
845
+ return this._withBytes(
846
+ image,
847
+ (p, l) => this._modelOrNull((o) => this.ex.gp_model_from_image(p, l, o))
848
+ );
849
+ }
816
850
  /**
817
851
  * Apply a batch of {@link ModelOp} edits to a model and return the edited
818
852
  * model. Ops run in order; out-of-range addresses (and any op that can't be
@@ -2401,6 +2435,26 @@ var GigaPdfDoc = class {
2401
2435
  const format = buf[0] === 1 ? "truetype" : buf[0] === 2 ? "cff" : "type1";
2402
2436
  return { format, bytes: buf.subarray(1) };
2403
2437
  }
2438
+ /**
2439
+ * Extract an embedded font as a **browser-loadable** sfnt by (fuzzy)
2440
+ * `/BaseFont` name — for a host editor's `@font-face` overlay-text layer.
2441
+ * Unlike {@link extractFont} (raw program, for re-embedding), this always
2442
+ * returns bytes a browser's `FontFace`/OTS will accept, **keeping the
2443
+ * document's own glyphs** (no substitution): a bare CFF (Type1C) is wrapped to
2444
+ * OpenType with a `cmap` from its charset, and a `cmap`-less TrueType subset is
2445
+ * repaired with a `cmap` synthesised from the PDF's `code → Unicode` (original
2446
+ * `glyf` kept). `truetype`/`otf` are directly loadable; `cff`/`type1` are raw
2447
+ * last-resort fallbacks. `null` when nothing embedded matches.
2448
+ */
2449
+ extractWebFont(name) {
2450
+ const buf = this.g._withStr(
2451
+ name,
2452
+ (p, l) => this.g._buffer((o) => this.ex().gp_extract_web_font(this.h, p, l, o))
2453
+ );
2454
+ if (buf.length === 0) return null;
2455
+ const format = buf[0] === 1 ? "truetype" : buf[0] === 2 ? "otf" : buf[0] === 3 ? "cff" : "type1";
2456
+ return { format, bytes: buf.subarray(1) };
2457
+ }
2404
2458
  /**
2405
2459
  * The fonts **embedded** in the document — each `{ baseFont, format }`. Pair
2406
2460
  * with {@link extractFont} to pull a font's bytes out and re-embed them via