@qrcommunication/gigapdf-lib 0.112.0 → 0.114.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 +95 -0
- package/dist/index.cjs +65 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +116 -1
- package/dist/index.d.ts +116 -1
- package/dist/index.js +65 -0
- package/dist/index.js.map +1 -1
- package/gigapdf.wasm +0 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,101 @@ project adheres to [Semantic Versioning](https://semver.org/).
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [0.114.0] - 2026-07-03
|
|
10
|
+
|
|
11
|
+
### Fixed — embedded web fonts resolved by PHYSICAL identity (accents no longer lost)
|
|
12
|
+
|
|
13
|
+
A PDF often shares ONE embedded font program across MANY `/Font` wrappers
|
|
14
|
+
(69 Type0 wrappers for 20 physical programs on a dense CERFA), each wrapper
|
|
15
|
+
carrying only a PARTIAL `/ToUnicode` for its own codes. The web extraction
|
|
16
|
+
resolved everything **by name**: the Type0 parent of a CIDFont was found by
|
|
17
|
+
scanning for the first wrapper with the same `/BaseFont` — often a sibling
|
|
18
|
+
with a 2-entry `/ToUnicode` — so the served cmap silently dropped accented
|
|
19
|
+
characters (à/â/é/ê/è) whose glyphs DO exist in the subset.
|
|
20
|
+
|
|
21
|
+
- The Type0 parent is now resolved **by reference** (`/DescendantFonts[0]` →
|
|
22
|
+
object id); the name scan survives only as a last-resort fallback.
|
|
23
|
+
- `extractWebFont(name)` no longer dead-ends on a wrapper without a font
|
|
24
|
+
program: the search widens past it, so a non-embedded alias
|
|
25
|
+
(`TimesNewRoman,BoldItalic`) is served by an embedded sibling subset of the
|
|
26
|
+
same face instead of nothing.
|
|
27
|
+
- The served cmap is the **union** of the mappings of EVERY wrapper
|
|
28
|
+
referencing the program (explicit `/ToUnicode` entries first — the
|
|
29
|
+
requesting wrapper wins conflicts — then inferred fills), and gains a
|
|
30
|
+
format 12 (3,10) subtable when a codepoint is beyond the BMP.
|
|
31
|
+
|
|
32
|
+
### Added — physical font identity (`fontId`)
|
|
33
|
+
|
|
34
|
+
- `TextElementInfo.fontId` — 8-hex content hash of the run's embedded font
|
|
35
|
+
program (empty when the wrapper embeds none), resolved in the run's scope
|
|
36
|
+
(form XObjects included): the exact run→program mapping a host needs.
|
|
37
|
+
- `embeddedFontsV2()` — enumeration de-duplicated **by program**:
|
|
38
|
+
`{ fontId, format, numGlyphs, baseFonts[] }` (one fetch per program
|
|
39
|
+
instead of one per wrapper name).
|
|
40
|
+
- `extractWebFontById(fontId, preferWrapper?)` and `webFontCoverage(fontId)`
|
|
41
|
+
(the mapped codepoints of the served cmap, for per-character fallback
|
|
42
|
+
decisions host-side). `extractWebFont(name)` and `embeddedFonts()` are
|
|
43
|
+
unchanged.
|
|
44
|
+
|
|
45
|
+
### Fixed — `pageBlocks` ↔ `textElements` index seam (paragraph editing)
|
|
46
|
+
|
|
47
|
+
`pageBlocks` emitted `source_index` in the unified element index space
|
|
48
|
+
(text + images + shapes) while `textElements()` / `replaceText` count
|
|
49
|
+
**top-level text runs only** — every interposed image or shape shifted the
|
|
50
|
+
seam (measured up to −139 on a dense form), so a host resolving a
|
|
51
|
+
paragraph's runs landed on arbitrary runs anywhere on the page. Both walks
|
|
52
|
+
now share the same text-run ordinal (a cross-check test pins them
|
|
53
|
+
together), and:
|
|
54
|
+
|
|
55
|
+
- coalesced inline runs (paragraphs AND table cells) now carry
|
|
56
|
+
**`source_indices`** — every constituent run index; the scalar
|
|
57
|
+
`source_index` stays the first entry for backward compatibility;
|
|
58
|
+
- `split_paragraphs` is geometrically hardened: a document-level leading
|
|
59
|
+
bound, an absolute 2.5×font-size gap cap and a ≥20 % horizontal-overlap
|
|
60
|
+
requirement stop far-apart lines (a footer and a header) from ever
|
|
61
|
+
fusing into one "paragraph".
|
|
62
|
+
|
|
63
|
+
### Fixed — text form-field appearances match Adobe (`setTextField`)
|
|
64
|
+
|
|
65
|
+
- **Comb fields** (`/MaxLen` + COMB flag): one character per cell, centred.
|
|
66
|
+
- **Auto-size** (`0 Tf`): shrink-to-fit both height AND width (4 pt floor).
|
|
67
|
+
- **Multiline** (`Ff` bit 13): word-wrap at the rect width even without `\n`.
|
|
68
|
+
- **Quadding** (`/Q`): centred/right text measured with the metrics of the
|
|
69
|
+
base-14 face actually named by the `/DA` (was always Helvetica).
|
|
70
|
+
- The appearance stream now clips to the widget rect (long values no
|
|
71
|
+
longer bleed over neighbouring content).
|
|
72
|
+
|
|
73
|
+
### Added — `setCheckboxState(name, state)`
|
|
74
|
+
|
|
75
|
+
Checks a specific named on-state of a checkbox with several widgets (the
|
|
76
|
+
`Oui`/`non` pairs of official forms): sets `/V` and, per widget, `/AS` to
|
|
77
|
+
the widget's own on-state or `/Off`. `setCheckbox(true)` (first on-state)
|
|
78
|
+
is unchanged; `"Off"` unchecks everywhere.
|
|
79
|
+
|
|
80
|
+
### Added — model importers for RTF, TXT and images
|
|
81
|
+
|
|
82
|
+
`rtfToModel` / `txtToModel` / `imageToModel` (WASM: `gp_model_from_rtf`,
|
|
83
|
+
`gp_model_from_txt`, `gp_model_from_image`) — the missing "lower into the
|
|
84
|
+
unified model" bindings; the core importers already existed and are
|
|
85
|
+
unchanged.
|
|
86
|
+
|
|
87
|
+
## [0.113.0] - 2026-07-01
|
|
88
|
+
|
|
89
|
+
### Added — every form-field widget placement (`FieldInfo.widgets`)
|
|
90
|
+
|
|
91
|
+
`fields()` now returns, for each AcroForm field, a **`widgets`** array listing
|
|
92
|
+
EVERY on-page widget of that field — not just the first. A field can have several:
|
|
93
|
+
the same field repeated on a duplicate page (an official form's carbon copy — fill
|
|
94
|
+
it once and it shows on both pages), or one widget per button of a radio group.
|
|
95
|
+
Each `WidgetPlacement` carries its `page`, its top-left `bounds`, and — for a button
|
|
96
|
+
— its on-state `export` (which radio button it is / the value stored when selected).
|
|
97
|
+
The flat `page`/`bounds` stay the first widget for backward compatibility.
|
|
98
|
+
|
|
99
|
+
Redundant or near-coincident widgets (a merged field also listed under `/Kids`, a
|
|
100
|
+
duplicate `/Kids` ref) are de-duplicated by (page, ~2pt bounds). A host renders one
|
|
101
|
+
field overlay per widget, so nothing is missing on page 2 and every radio button is
|
|
102
|
+
placed with the correct checked state.
|
|
103
|
+
|
|
9
104
|
## [0.112.0] - 2026-07-01
|
|
10
105
|
|
|
11
106
|
### Fixed — per-word tiling for space-justified & `Td`-positioned runs (footers now overlay-faithful)
|
package/dist/index.cjs
CHANGED
|
@@ -2455,6 +2455,33 @@ var GigaPdfDoc = class {
|
|
|
2455
2455
|
const format = buf[0] === 1 ? "truetype" : buf[0] === 2 ? "otf" : buf[0] === 3 ? "cff" : "type1";
|
|
2456
2456
|
return { format, bytes: buf.subarray(1) };
|
|
2457
2457
|
}
|
|
2458
|
+
/**
|
|
2459
|
+
* Extract an embedded font as a **browser-loadable** sfnt by its **physical
|
|
2460
|
+
* identity** (`fontId` — the value {@link textElements} and
|
|
2461
|
+
* {@link embeddedFontsV2} report). The name-ambiguity-proof sibling of
|
|
2462
|
+
* {@link extractWebFont}: a form generator routinely embeds dozens of
|
|
2463
|
+
* same-`/BaseFont` wrappers over a handful of physical programs, each with
|
|
2464
|
+
* its own *partial* `/ToUnicode` — a name lookup can land on a homonym whose
|
|
2465
|
+
* 2-entry map drops accents the program actually carries. Resolving by
|
|
2466
|
+
* `fontId` pins the exact program, and the served `cmap` is rebuilt as the
|
|
2467
|
+
* **union of every wrapper** referencing it (explicit `/ToUnicode` entries
|
|
2468
|
+
* first — `preferWrapper`, the run's own {@link TextElementInfo.baseFont},
|
|
2469
|
+
* winning on conflict — then inferred fills). The subset is always served
|
|
2470
|
+
* as-is, never rejected for an incomplete map. `null` only when no embedded
|
|
2471
|
+
* program carries `fontId`.
|
|
2472
|
+
*/
|
|
2473
|
+
extractWebFontById(fontId, preferWrapper) {
|
|
2474
|
+
const buf = this.g._withStr(
|
|
2475
|
+
fontId,
|
|
2476
|
+
(ip, il) => this.g._withOptStr(
|
|
2477
|
+
preferWrapper,
|
|
2478
|
+
(pp, pl) => this.g._buffer((o) => this.ex().gp_extract_web_font_by_id(this.h, ip, il, pp, pl, o))
|
|
2479
|
+
)
|
|
2480
|
+
);
|
|
2481
|
+
if (buf.length === 0) return null;
|
|
2482
|
+
const format = buf[0] === 1 ? "truetype" : buf[0] === 2 ? "otf" : buf[0] === 3 ? "cff" : "type1";
|
|
2483
|
+
return { format, bytes: buf.subarray(1) };
|
|
2484
|
+
}
|
|
2458
2485
|
/**
|
|
2459
2486
|
* The fonts **embedded** in the document — each `{ baseFont, format }`. Pair
|
|
2460
2487
|
* with {@link extractFont} to pull a font's bytes out and re-embed them via
|
|
@@ -2464,6 +2491,30 @@ var GigaPdfDoc = class {
|
|
|
2464
2491
|
embeddedFonts() {
|
|
2465
2492
|
return this.g._json((o) => this.ex().gp_embedded_fonts_json(this.h, o));
|
|
2466
2493
|
}
|
|
2494
|
+
/**
|
|
2495
|
+
* The embedded fonts **deduplicated by physical program** — one
|
|
2496
|
+
* {@link EmbeddedFontV2} per `/FontFile*` stream, carrying its `fontId`,
|
|
2497
|
+
* format, glyph count and every `/BaseFont` wrapped around it. The
|
|
2498
|
+
* per-program sibling of {@link embeddedFonts} (kept intact); its `fontId`s
|
|
2499
|
+
* feed {@link extractWebFontById} / {@link webFontCoverage}. Sorted by
|
|
2500
|
+
* `fontId` for a deterministic output.
|
|
2501
|
+
*/
|
|
2502
|
+
embeddedFontsV2() {
|
|
2503
|
+
return this.g._json((o) => this.ex().gp_embedded_fonts_v2_json(this.h, o));
|
|
2504
|
+
}
|
|
2505
|
+
/**
|
|
2506
|
+
* The Unicode code points mapped by the `cmap` {@link extractWebFontById}
|
|
2507
|
+
* serves for `fontId` — sorted, deduplicated. Lets a host check, before
|
|
2508
|
+
* painting, whether a run's characters are covered by the served face (and
|
|
2509
|
+
* pick a fallback for the gaps). Empty when no embedded program carries
|
|
2510
|
+
* `fontId`.
|
|
2511
|
+
*/
|
|
2512
|
+
webFontCoverage(fontId) {
|
|
2513
|
+
return this.g._withStr(
|
|
2514
|
+
fontId,
|
|
2515
|
+
(p, l) => this.g._json((o) => this.ex().gp_web_font_coverage(this.h, p, l, o))
|
|
2516
|
+
);
|
|
2517
|
+
}
|
|
2467
2518
|
// convert PDF → X
|
|
2468
2519
|
toText() {
|
|
2469
2520
|
return this.g._str((o) => this.ex().gp_to_text(this.h, o));
|
|
@@ -3628,6 +3679,20 @@ var GigaPdfDoc = class {
|
|
|
3628
3679
|
setCheckbox(name, checked) {
|
|
3629
3680
|
return this.g._withStr(name, (p, l) => this.ex().gp_set_checkbox(this.h, p, l, checked ? 1 : 0)) === 0;
|
|
3630
3681
|
}
|
|
3682
|
+
/**
|
|
3683
|
+
* Set a checkbox to a **named** appearance state — the on-state export of
|
|
3684
|
+
* one of its widgets. A multi-widget checkbox names one export per widget
|
|
3685
|
+
* (e.g. `Oui` / `non` on French CERFA forms); {@link setCheckbox} with
|
|
3686
|
+
* `true` only ever reaches the first export, this reaches any of them.
|
|
3687
|
+
* `"Off"` unchecks every widget. Returns `false` when the field or state
|
|
3688
|
+
* doesn't exist.
|
|
3689
|
+
*/
|
|
3690
|
+
setCheckboxState(name, state) {
|
|
3691
|
+
return this.g._withStr(
|
|
3692
|
+
name,
|
|
3693
|
+
(nP, nL) => this.g._withStr(state, (sP, sL) => this.ex().gp_set_checkbox_state(this.h, nP, nL, sP, sL))
|
|
3694
|
+
) === 0;
|
|
3695
|
+
}
|
|
3631
3696
|
setRadio(name, value) {
|
|
3632
3697
|
return this.g._withStr(
|
|
3633
3698
|
name,
|