@qrcommunication/gigapdf-lib 0.109.0 → 0.110.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 +66 -0
- package/dist/index.cjs +57 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +37 -2
- package/dist/index.d.ts +37 -2
- package/dist/index.js +57 -2
- package/dist/index.js.map +1 -1
- package/gigapdf.wasm +0 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,72 @@ project adheres to [Semantic Versioning](https://semver.org/).
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [0.110.0] - 2026-06-30
|
|
10
|
+
|
|
11
|
+
### Added — `extractWebFont`: serve a document's own embedded fonts to a browser
|
|
12
|
+
|
|
13
|
+
- New engine method **`extractWebFont(name)`** (FFI `gp_extract_web_font`) returns
|
|
14
|
+
a PDF's **own embedded font** as a **browser-loadable sfnt** for a `@font-face`
|
|
15
|
+
overlay-text layer — keeping the document's **original glyphs**, never a
|
|
16
|
+
substitute. It complements `extractFont` (which returns the raw program for
|
|
17
|
+
re-embedding): where `extractFont` hands back bytes a browser's `FontFace`/OTS
|
|
18
|
+
routinely rejects (a bare CFF, or a `cmap`-less TrueType subset),
|
|
19
|
+
`extractWebFont` repairs them:
|
|
20
|
+
- **CFF (Type1C)** → wrapped to OpenType (`OTTO`) with a `cmap` built from the
|
|
21
|
+
PDF's `code → Unicode` decode mapping (the same one text extraction uses, so
|
|
22
|
+
it resolves subset glyphs whose `/Differences` carries opaque `gNN` names and
|
|
23
|
+
whose `/ToUnicode` is partial — the exact case that otherwise renders the
|
|
24
|
+
wrong letters).
|
|
25
|
+
- **TrueType** → passed through when it already maps Unicode; otherwise a `cmap`
|
|
26
|
+
is synthesised (`code → Unicode` from the decode path, `code → gid` borrowed
|
|
27
|
+
from a sibling's `cmap` for full-glyph-order subsets, else the `code == gid`
|
|
28
|
+
convention) and the OTS-mandatory `OS/2`/`name`/`post` are stubbed in — the
|
|
29
|
+
original `glyf` is kept verbatim.
|
|
30
|
+
- Face selection prefers an **exact raw `/BaseFont`** match (subset prefix
|
|
31
|
+
included), so a host that serves many disjoint subsets of one family gets
|
|
32
|
+
*that* subset's own glyphs per run.
|
|
33
|
+
- New internal helper `cff_to_otf::repair_sfnt_with_cmap` (injects a Unicode
|
|
34
|
+
`cmap` + the OTS-required tables around existing glyph data) and a hardened
|
|
35
|
+
`build_cmap` (now sorts/dedupes segments, so a synthesised format-4 table is
|
|
36
|
+
accepted by strict shapers — FreeType/HarfBuzz).
|
|
37
|
+
- Tests: `repair_injects_cmap_and_required_tables_keeping_originals` (the repair
|
|
38
|
+
keeps the original tables and adds a working `cmap`).
|
|
39
|
+
|
|
40
|
+
### Added — bidirectional conversion symmetry: model importers for RTF, TXT and images
|
|
41
|
+
|
|
42
|
+
- New engine methods `rtfToModel(rtf)`, `txtToModel(text)` and
|
|
43
|
+
`imageToModel(image)` complete the **lower-any-format-into-the-model** matrix.
|
|
44
|
+
The core already exposed `rtf_to_model` / `txt_to_model` / `image_to_model`,
|
|
45
|
+
but they had **no WASM/SDK binding** — so `modelToRtf` could write RTF yet
|
|
46
|
+
nothing could read RTF *into* the model, and likewise for plain text and raster
|
|
47
|
+
images. The three new FFI entry points (`gp_model_from_rtf` /
|
|
48
|
+
`gp_model_from_txt` / `gp_model_from_image`) and their TypeScript wrappers close
|
|
49
|
+
that asymmetry, matching the existing `officeToModel` / `htmlToModel` /
|
|
50
|
+
`mdToModel` / `csvToModel`. `imageToModel` returns `null` on non-image bytes;
|
|
51
|
+
`rtfToModel` routes through the rich RTF parser (run styling, tables, `\pict`
|
|
52
|
+
images, `\field` links).
|
|
53
|
+
- Tests: `test/model_import.test.ts` — 7 round-trip cases through the production
|
|
54
|
+
WASM (`txtToModel`→`modelToPdf`, `rtfToModel`→`modelToRtf`,
|
|
55
|
+
`imageToModel`→`modelToPdf`, plus the non-image `null` guard).
|
|
56
|
+
|
|
57
|
+
## [0.109.1] - 2026-06-30
|
|
58
|
+
|
|
59
|
+
### Fixed — image-format documentation accuracy
|
|
60
|
+
|
|
61
|
+
- `addImage`, `replaceImage` and the image **watermark** path already accept the
|
|
62
|
+
full raster set — **PNG, JPEG, WebP, GIF, TIFF and AVIF** — since 0.109 (every
|
|
63
|
+
one routes through the shared `prepare_image` / `embeddable_image` decoders).
|
|
64
|
+
But the core and WASM docstrings, the SDK `replaceImage` docs, and the
|
|
65
|
+
`unsupported image` error messages still claimed **PNG/JPEG only** (or omitted
|
|
66
|
+
TIFF). Corrected every stale claim so the documented capability matches the
|
|
67
|
+
implementation. **No behaviour change** — purely documentation and error-text.
|
|
68
|
+
|
|
69
|
+
### Added
|
|
70
|
+
|
|
71
|
+
- Regression test `replace_image_accepts_every_raster_format_not_just_png_jpeg`:
|
|
72
|
+
proves `replaceImage` swaps a non-PNG/JPEG raster (WebP) in place while keeping
|
|
73
|
+
the image's object number and every `/Do` reference intact.
|
|
74
|
+
|
|
9
75
|
## [0.109.0] - 2026-06-30
|
|
10
76
|
|
|
11
77
|
### Added — image conversion completeness
|
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
|
|
@@ -1646,7 +1680,8 @@ var GigaPdfDoc = class {
|
|
|
1646
1680
|
* photo while every reference to it stays intact (ISO 32000-1 §8.9). `index` is
|
|
1647
1681
|
* the **unified element index** of an image on `page`, exactly the `index`
|
|
1648
1682
|
* reported by {@link imageElements} (and accepted by {@link removeElement} /
|
|
1649
|
-
* {@link transformElement}); `data` is
|
|
1683
|
+
* {@link transformElement}); `data` is any raster the engine decodes — PNG,
|
|
1684
|
+
* JPEG, WebP, GIF, TIFF or AVIF (the same set {@link addImage} accepts).
|
|
1650
1685
|
*
|
|
1651
1686
|
* Unlike a delete-then-re-add, the image keeps its object number, **every `/Do`
|
|
1652
1687
|
* placement, and its position / scale / rotation / clip matrix** — only the
|
|
@@ -1657,7 +1692,7 @@ var GigaPdfDoc = class {
|
|
|
1657
1692
|
* drawn into the same box (transform the element first to re-fit it).
|
|
1658
1693
|
*
|
|
1659
1694
|
* Returns `false` if `page`/`index` doesn't resolve to a top-level image, or the
|
|
1660
|
-
* bytes aren't a decodable
|
|
1695
|
+
* bytes aren't a decodable raster.
|
|
1661
1696
|
*/
|
|
1662
1697
|
replaceImage(page, index, data) {
|
|
1663
1698
|
return this.g._withBytes(data, (p, l) => this.ex().gp_replace_image(this.h, page, index, p, l)) === 0;
|
|
@@ -2400,6 +2435,26 @@ var GigaPdfDoc = class {
|
|
|
2400
2435
|
const format = buf[0] === 1 ? "truetype" : buf[0] === 2 ? "cff" : "type1";
|
|
2401
2436
|
return { format, bytes: buf.subarray(1) };
|
|
2402
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
|
+
}
|
|
2403
2458
|
/**
|
|
2404
2459
|
* The fonts **embedded** in the document — each `{ baseFont, format }`. Pair
|
|
2405
2460
|
* with {@link extractFont} to pull a font's bytes out and re-embed them via
|