@qrcommunication/gigapdf-lib 0.68.0 → 0.70.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,71 @@ 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.70.0] - 2026-06-23
8
+
9
+ Fidelity + standards release: advanced (PAdES-B-T) timestamped signatures,
10
+ richer shading and JPEG decoding at the rasteriser, complex-script text shaping
11
+ for Indic writing systems, CFF flex curves, and RTF image import. The public API
12
+ is additive — existing behaviour is unchanged.
13
+
14
+ ### Added
15
+
16
+ - **PAdES-B-T trusted timestamps (RFC 3161).** New SDK
17
+ `GigaPdfDoc.signTimestamped()` (async) embeds an RFC 3161 timestamp token in
18
+ the SignerInfo for an *advanced*-level PAdES-B-T signature — `ETSI.CAdES.detached`
19
+ subfilter, `signing-certificate-v2` (ESS) signed attribute, and the
20
+ `id-aa-timeStampToken` unsigned attribute. Uses the engine's pure-data
21
+ two-phase TSA flow (core emits the `TimeStampReq`, host POSTs it, core embeds
22
+ the returned token) since the WASM core has no network stack; `tsaFetch` lets
23
+ the host add auth/proxy/retries **and apply its own SSRF allow-list**, and the
24
+ exported `defaultTsaPost` POSTs `application/timestamp-query` via `fetch`
25
+ (e.g. FreeTSA). Signs with an imported PKCS#12 or a freshly generated
26
+ self-signed identity.
27
+ - **Mesh shadings at the rasteriser.** Free-form (type 4), lattice (type 5),
28
+ Coons (type 6) and tensor (type 7) shadings are now rendered as Gouraud
29
+ triangles (pure, zero-dep decoder; Coons/tensor patches tessellated per
30
+ ISO 32000-1 §8.7.4.5.7), with per-vertex colour resolved through
31
+ `Separation`/`DeviceN`/`ICCBased`/`CMYK`/`Gray`. Axial (2) and radial (3)
32
+ shadings are unchanged.
33
+ - **Arithmetic-coded JPEG decoding.** SOF9 (sequential) and SOF10 (progressive)
34
+ JPEGs now decode via a hand-rolled ISO/IEC 10918-1 Annex MQ arithmetic decoder
35
+ with the F.1.4 DC/AC context models and `DAC` conditioning. Baseline/Huffman
36
+ paths are unchanged; lossless (SOF3/SOF11) and 12-bit Huffman (SOF1) remain
37
+ gracefully unsupported.
38
+ - **Indic complex-script shaping.** A syllabic reordering machine for the
39
+ Brahmi-derived scripts (Devanagari, Bengali, Gurmukhi, Gujarati, Oriya, Tamil,
40
+ Telugu, Kannada, Malayalam) — reph and pre-base matra reordering — plus the
41
+ missing OpenType lookups: GSUB 2 (multiple), GSUB 3 (alternate), GSUB 8
42
+ (reverse chaining single) and GPOS 3 (cursive attachment). Latin and the
43
+ existing contextual paths are unchanged.
44
+ - **CFF/Type2 flex operators.** The Type2 charstring interpreter now implements
45
+ the four flex operators (`flex`, `flex1`, `hflex`, `hflex1`, Adobe TN #5177),
46
+ each emitting two cubic curves — CFF glyphs using flex no longer drop or
47
+ mis-render contour segments.
48
+ - **RTF image import.** RTF import parses the `\pict` group, extracting
49
+ `\pngblip`/`\jpegblip` payloads as `<img src="data:image/…;base64,…">`
50
+ (display size recovered from `\picwgoal`/`\pichgoal`), reusing the HTML
51
+ engine's image-embed pipeline. DIB/BMP, WMF/EMF and binary `\bin` payloads are
52
+ skipped (documented limits), guarded by a PNG/JPEG magic-byte check.
53
+
54
+ ## [0.69.0] - 2026-06-23
55
+
56
+ Image-watermark release: stamp a raster image across any range of pages, with
57
+ the same ergonomics as the existing text watermark. The text watermark is
58
+ unchanged.
59
+
60
+ ### Added
61
+
62
+ - **Image watermark.** Stamp a raster image over pages —
63
+ `addImageWatermark` (SDK) / `add_image_watermark` (core) /
64
+ `gp_add_image_watermark` (FFI). Accepts **PNG / JPEG / WebP / GIF / AVIF**
65
+ source images and supports per-watermark **opacity**, **anchoring**
66
+ (center + four corners) with offsets, **rotation** (about the image center),
67
+ **scaling** to a target size (aspect-follow), and an optional **tiling** grid.
68
+ The image XObject is embedded **once** and referenced on each target page,
69
+ reusing the existing image-embed/raster-transcode pipeline. The text
70
+ watermark and `add_image` behavior are unchanged.
71
+
7
72
  ## [0.68.0] - 2026-06-23
8
73
 
9
74
  Format-reach + import/render fidelity release: the unified model now exports
package/dist/index.cjs CHANGED
@@ -21,7 +21,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
23
  GigaPdfDoc: () => GigaPdfDoc,
24
- GigaPdfEngine: () => GigaPdfEngine
24
+ GigaPdfEngine: () => GigaPdfEngine,
25
+ defaultTsaPost: () => defaultTsaPost
25
26
  });
26
27
  module.exports = __toCommonJS(index_exports);
27
28
  var import_node_fs = require("./node-fs.js");
@@ -853,6 +854,18 @@ var GigaPdfEngine = class _GigaPdfEngine {
853
854
  );
854
855
  }
855
856
  };
857
+ async function defaultTsaPost(url, req) {
858
+ const res = await fetch(url, {
859
+ method: "POST",
860
+ headers: { "Content-Type": "application/timestamp-query" },
861
+ body: req,
862
+ redirect: "error"
863
+ });
864
+ if (!res.ok) {
865
+ throw new Error(`TSA HTTP ${res.status}`);
866
+ }
867
+ return new Uint8Array(await res.arrayBuffer());
868
+ }
856
869
  function packHtmlResources(resources) {
857
870
  let size = 4;
858
871
  for (const r of resources) size += 4 + enc.encode(r.url).length + 4 + r.bytes.length;
@@ -1239,6 +1252,49 @@ var GigaPdfDoc = class {
1239
1252
  (p, l) => this.ex().gp_add_image(this.h, page, p, l, x, y, w, h, opacity)
1240
1253
  ) === 0;
1241
1254
  }
1255
+ /**
1256
+ * Stamp an **image watermark** across pages from raw image bytes. Accepts the
1257
+ * same five formats the engine decodes — **PNG, JPEG, WebP, GIF, AVIF**. The
1258
+ * image is embedded **once** and referenced on every target page.
1259
+ *
1260
+ * `opts.pages` is a list of 1-based page numbers; omit it (or pass `[]`) to
1261
+ * stamp every page. `opts.anchor` positions the image (`'center'` default, or a
1262
+ * corner) and `opts.offsetX`/`offsetY` nudge it (in points; in `tile` mode they
1263
+ * become the gaps between tiles). `opts.width`/`height` set the target size in
1264
+ * points (height keeps the source aspect ratio when omitted). `opts.rotationDeg`
1265
+ * rotates about the image centre and `opts.opacity` (0–1) sets the alpha.
1266
+ * Returns `false` if the image can't be decoded.
1267
+ */
1268
+ addImageWatermark(data, opts = {}) {
1269
+ const anchorTag = {
1270
+ center: 0,
1271
+ "top-left": 1,
1272
+ "top-right": 2,
1273
+ "bottom-left": 3,
1274
+ "bottom-right": 4
1275
+ }[opts.anchor ?? "center"];
1276
+ const pages = opts.pages ?? [];
1277
+ const call = (pp, pc) => this.g._withBytes(
1278
+ data,
1279
+ (p, l) => this.ex().gp_add_image_watermark(
1280
+ this.h,
1281
+ p,
1282
+ l,
1283
+ pp,
1284
+ pc,
1285
+ anchorTag,
1286
+ opts.offsetX ?? 0,
1287
+ opts.offsetY ?? 0,
1288
+ opts.width ?? 0,
1289
+ opts.height ?? 0,
1290
+ opts.rotationDeg ?? 0,
1291
+ opts.opacity ?? 0.25,
1292
+ opts.tile ? 1 : 0
1293
+ )
1294
+ );
1295
+ const rc = pages.length === 0 ? call(0, 0) : this.g._withU32(pages, (pp, pc) => call(pp, pc));
1296
+ return rc === 0;
1297
+ }
1242
1298
  /**
1243
1299
  * Draw SVG markup on a page as **native vector paths** (crisp at any zoom, not
1244
1300
  * rasterized), fitting its `viewBox` into the box `(x, y, w, h)` in PDF points
@@ -1705,6 +1761,95 @@ var GigaPdfDoc = class {
1705
1761
  }
1706
1762
  return out;
1707
1763
  }
1764
+ /**
1765
+ * Sign with an embedded **RFC 3161 trusted timestamp** (PAdES-B-T). Unlike
1766
+ * {@link sign}/{@link signP12} this is `async`: the timestamp requires a
1767
+ * network round trip to a TSA, so the method runs the engine's two-phase flow
1768
+ * — build the signature → POST the `TimeStampReq` to the TSA → embed the
1769
+ * returned token — with the HTTP in between.
1770
+ *
1771
+ * The signing identity is `opts.p12` (+ `opts.password`) when supplied, else a
1772
+ * generated self-signed digital ID from `opts.random` (+ `notBefore`/
1773
+ * `notAfter`). `opts.tsaUrl` is the TSA endpoint (e.g. FreeTSA
1774
+ * `https://freetsa.org/tsr`); pass `opts.tsaFetch` to customise the request
1775
+ * (auth, proxy, SSRF allow-list). Throws a single generic error on any failure
1776
+ * (bad identity, TSA HTTP error, malformed response, or signature too large).
1777
+ */
1778
+ async signTimestamped(opts) {
1779
+ const usingP12 = opts.p12 != null && opts.p12.length > 0;
1780
+ if (!usingP12 && (opts.random == null || opts.random.length < 256)) {
1781
+ throw new Error(
1782
+ "signTimestamped: self-signed path needs `random` \u2265 256 bytes (or pass a `p12`)"
1783
+ );
1784
+ }
1785
+ const fields = [
1786
+ opts.name ?? "",
1787
+ opts.reason ?? "",
1788
+ opts.date ?? "",
1789
+ opts.location ?? "",
1790
+ opts.contactInfo ?? "",
1791
+ opts.notBefore ?? "",
1792
+ opts.notAfter ?? ""
1793
+ ].join(" ");
1794
+ const rand = opts.random ?? new Uint8Array(0);
1795
+ const p12 = opts.p12 ?? new Uint8Array(0);
1796
+ const nonce = opts.nonce ?? new Uint8Array(0);
1797
+ const keyBits = opts.keyBits ?? 2048;
1798
+ const rPtr = this.g._toWasm(rand);
1799
+ const p12Ptr = this.g._toWasm(p12);
1800
+ const noncePtr = this.g._toWasm(nonce);
1801
+ let request;
1802
+ try {
1803
+ request = this.g._withStr(
1804
+ opts.password ?? "",
1805
+ (pwP, pwL) => this.g._withStr(
1806
+ fields,
1807
+ (fP, fL) => this.g._buffer(
1808
+ (o) => this.ex().gp_sign_prepare_tsa(
1809
+ this.h,
1810
+ fP,
1811
+ fL,
1812
+ rPtr,
1813
+ rand.length,
1814
+ keyBits,
1815
+ p12Ptr,
1816
+ p12.length,
1817
+ pwP,
1818
+ pwL,
1819
+ noncePtr,
1820
+ nonce.length,
1821
+ o
1822
+ )
1823
+ )
1824
+ )
1825
+ );
1826
+ } finally {
1827
+ this.g._free(rPtr, rand.length);
1828
+ this.g._free(p12Ptr, p12.length);
1829
+ this.g._free(noncePtr, nonce.length);
1830
+ }
1831
+ if (request.length === 0) {
1832
+ throw new Error(
1833
+ "timestamped signing failed: invalid identity or could not build the timestamp request"
1834
+ );
1835
+ }
1836
+ const response = opts.tsaFetch ? await opts.tsaFetch(request, opts.tsaUrl) : await defaultTsaPost(opts.tsaUrl, request);
1837
+ const tokenPtr = this.g._toWasm(response);
1838
+ let out;
1839
+ try {
1840
+ out = this.g._buffer(
1841
+ (o) => this.ex().gp_sign_finish_tsa(this.h, tokenPtr, response.length, o)
1842
+ );
1843
+ } finally {
1844
+ this.g._free(tokenPtr, response.length);
1845
+ }
1846
+ if (out.length === 0) {
1847
+ throw new Error(
1848
+ "timestamped signing failed: TSA response rejected or signature too large for the reserved space"
1849
+ );
1850
+ }
1851
+ return out;
1852
+ }
1708
1853
  // metadata
1709
1854
  getMetadata(key) {
1710
1855
  return this.g._withStr(
@@ -2104,6 +2249,7 @@ var GigaPdfDoc = class {
2104
2249
  // Annotate the CommonJS export names for ESM import in node:
2105
2250
  0 && (module.exports = {
2106
2251
  GigaPdfDoc,
2107
- GigaPdfEngine
2252
+ GigaPdfEngine,
2253
+ defaultTsaPost
2108
2254
  });
2109
2255
  //# sourceMappingURL=index.cjs.map