@qrcommunication/gigapdf-lib 0.57.0 → 0.58.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,55 @@ 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.58.0] - 2026-06-21
8
+
9
+ ### Added
10
+
11
+ - **`setElementOpacity(page, index, fillAlpha)` — constant opacity on *any*
12
+ element.** Sets a single transparency value on a text, image **or** shape
13
+ element in place by registering a page `/ExtGState` (`/ca` = `/CA` =
14
+ `fillAlpha`, clamped to `0..=1`, auto-named `GpGs<n>`) and wrapping the
15
+ element's op range in `q /<gs> gs … Q`, so the alpha applies to that run only
16
+ and following content is unaffected. This is the way to set an **image**'s
17
+ opacity in place; shapes may use either this or `setPathStyle`'s `fillAlpha` /
18
+ `strokeAlpha` (same underlying `/ExtGState` mechanism — the difference is that
19
+ `setElementOpacity` uses one value for both `/ca` and `/CA`, while `setPathStyle`
20
+ can set fill and stroke alpha independently). New ABI
21
+ `gp_set_element_opacity(handle, page, index, fill_alpha)` and core
22
+ `Document::set_element_opacity` / `content::set_element_opacity`. Returns
23
+ `false` for a missing page/index.
24
+ - **`reorderElement(page, index, toFront)` — native PDF stacking order.** Changes
25
+ an element's paint (z) order by splicing its op range to the **end** of the
26
+ content stream (`toFront = true` → painted last, on top) or to the **start**
27
+ (`toFront = false` → painted first, behind everything). The moved range is
28
+ re-wrapped in `q … Q` so it neither inherits nor leaks graphics state; works for
29
+ text, image and shape elements. **The element's unified index changes after the
30
+ splice — re-read `pageElements`.** New ABI `gp_reorder_element(handle, page,
31
+ index, to_front)` and core `Document::reorder_element` /
32
+ `content::reorder_element`. Returns `false` for a missing page/index.
33
+ - **`renderPageExcluding(page, indices, scale?)` — rasterise a page minus given
34
+ elements.** Rasterises a page to PNG while **omitting** the listed top-level
35
+ unified element `indices` (from `pageElements`) — each excluded element paints
36
+ nothing (fills, strokes, shadings, images and text alike) while all
37
+ non-excluded content renders normally. Generalises `renderPageNoText` (which
38
+ suppresses *all* text); an empty `indices` renders the full page and unknown
39
+ indices are ignored. Built for live-overlay editing — paint a background
40
+ without the element currently being edited, then overlay an editable version on
41
+ top. Native rasteriser, no third-party image library. New ABI
42
+ `gp_render_page_excluding(handle, page, indices_ptr, indices_len, scale,
43
+ out_len)` and core `Document::render_page_excluding`, alongside the unchanged
44
+ `renderPage` / `renderPageNoText`.
45
+
46
+ ### Changed
47
+
48
+ - **`setPathStyle` opacity is now real.** `fillAlpha` / `strokeAlpha` (`0..=1`)
49
+ are now **fully applied** (previously accepted for API symmetry but a no-op):
50
+ the engine registers an `/ExtGState` carrying `/ca` / `/CA` on the page and
51
+ injects a `/<gs> gs` into the path's `q … Q` wrap, so the alpha applies to that
52
+ path run only. The earlier "opacity not applied — needs an `/ExtGState`"
53
+ limitation no longer holds. For non-path elements (e.g. images) use
54
+ `setElementOpacity`.
55
+
7
56
  ## [0.57.0] - 2026-06-21
8
57
 
9
58
  ### Added
package/README.md CHANGED
@@ -272,14 +272,18 @@ Or call `GigaPdfEngine.load(bytes)` with bytes you read yourself.
272
272
  - **`GigaPdfDoc`** — text intelligence (`textRuns`, `structuredText`, `search`,
273
273
  `ocr`, `ocrText`, `elements`, `elementAt`), editing (`replaceText`,
274
274
  `removeElement`, `moveElement`, `transformElement` (full affine — move + resize
275
- + rotate in place), `setPathStyle` (in-place vector restyle: fill/stroke/width/dash),
275
+ + rotate in place), `reorderElement` (native z-order — bring to front / send to
276
+ back), `setPathStyle` (in-place vector restyle: fill/stroke/width/dash + **real
277
+ opacity**), `setElementOpacity` (constant opacity on any element — text/image/shape),
276
278
  `duplicateElement`, `redact`), vector drawing
277
279
  (`addRectangle`, `drawLine`, `addEllipse`, `addPolygon`, `addPath` (SVG path),
278
280
  `addImage` (PNG/JPEG, alpha + opacity)), pages (`rotatePage`, `deletePage`,
279
281
  `movePage`, `appendPages`, `extractPages`, `resizePage`, `addPage`, `copyPage`,
280
282
  `pageInfo`),
281
283
  `renderPage` (and `renderPageNoText` — a text-free background for editors that
282
- overlay real editable text; vectors/gradients/images/annotations still rendered),
284
+ overlay real editable text; vectors/gradients/images/annotations still rendered —
285
+ plus `renderPageExcluding` — a background omitting specific elements for
286
+ live-overlay editing),
283
287
  fonts (base-14 `addStandardText`, embed **any** TrueType/OpenType
284
288
  via `embedFont`/`addText`, font-aware editing `replaceText`,
285
289
  the document's own faces `embeddedFonts`/`extractFont`, `neededFonts`),
package/dist/index.cjs CHANGED
@@ -995,10 +995,11 @@ var GigaPdfDoc = class {
995
995
  * in `0..=1`; `dash` is the PDF dash array (`[]` = solid). Returns `false` if
996
996
  * the element is not a path (or the page/index doesn't exist).
997
997
  *
998
- * Opacity note: `fillAlpha`/`strokeAlpha` are accepted for API symmetry but
999
- * are **not** emitted — PDF opacity needs a named `/ExtGState`, which a pure
1000
- * content-stream edit cannot create. Use the resource-level shape APIs when
1001
- * opacity is required.
998
+ * Opacity: `fillAlpha`/`strokeAlpha` (`0..=1`) are fully supported — an
999
+ * `/ExtGState` carrying `/ca`/`/CA` is registered on the page and a `/<gs> gs`
1000
+ * is injected into the path's `q … Q` wrap, so the alpha applies to that path
1001
+ * run only. (For non-path elements such as images, use
1002
+ * {@link setElementOpacity}.)
1002
1003
  */
1003
1004
  setPathStyle(page, index, style) {
1004
1005
  return this.g._withStr(
@@ -1006,6 +1007,30 @@ var GigaPdfDoc = class {
1006
1007
  (p, l) => this.ex().gp_set_path_style_json(this.h, page, index, p, l)
1007
1008
  ) === 0;
1008
1009
  }
1010
+ /**
1011
+ * Set a constant opacity on element `index` on `page` — text, image **or**
1012
+ * shape — by registering an `/ExtGState` (`/ca` = `/CA` = `fillAlpha`, clamped
1013
+ * to `0..=1`) on the page and wrapping the element's op range in
1014
+ * `q /<gs> gs … Q`. This is the way to set an **image**'s alpha in place;
1015
+ * shapes may also use {@link setPathStyle}'s `fillAlpha`/`strokeAlpha` (same
1016
+ * underlying `/ExtGState` mechanism). Returns `false` if the page/index doesn't
1017
+ * exist.
1018
+ */
1019
+ setElementOpacity(page, index, fillAlpha) {
1020
+ return this.ex().gp_set_element_opacity(this.h, page, index, fillAlpha) === 0;
1021
+ }
1022
+ /**
1023
+ * Change the paint order (z-order) of element `index` on `page`. `toFront`
1024
+ * brings it visually on top (its op range is moved to the end of the content
1025
+ * stream, painted last); otherwise it is sent behind everything (moved to the
1026
+ * start, painted first). The moved range is re-wrapped in `q … Q` so it neither
1027
+ * inherits nor leaks graphics state. Works for text, image and shape elements.
1028
+ * The element's index changes after the move — re-read {@link pageElements}.
1029
+ * Returns `false` if the page/index doesn't exist.
1030
+ */
1031
+ reorderElement(page, index, toFront) {
1032
+ return this.ex().gp_reorder_element(this.h, page, index, toFront ? 1 : 0) === 0;
1033
+ }
1009
1034
  duplicateElement(page, index) {
1010
1035
  return this.ex().gp_duplicate_element(this.h, page, index) === 0;
1011
1036
  }
@@ -1289,6 +1314,24 @@ var GigaPdfDoc = class {
1289
1314
  renderPageNoText(page, scale = 1) {
1290
1315
  return this.g._buffer((o) => this.ex().gp_render_page_no_text(this.h, page, scale, o));
1291
1316
  }
1317
+ /**
1318
+ * Rasterize a page to a PNG while **omitting** the given top-level element
1319
+ * `indices` (from {@link pageElements}). Each excluded element paints nothing
1320
+ * — fills, strokes, shadings, images and text alike — while everything else
1321
+ * (including the non-text content of non-excluded elements) renders normally.
1322
+ * Use it to paint a background without specific elements and overlay live,
1323
+ * editable versions on top. Generalises {@link renderPageNoText} (which
1324
+ * suppresses *all* text). An empty `indices` renders the full page; unknown
1325
+ * indices are ignored.
1326
+ */
1327
+ renderPageExcluding(page, indices, scale = 1) {
1328
+ return this.g._buffer(
1329
+ (o) => this.g._withU32(
1330
+ indices,
1331
+ (p, c) => this.ex().gp_render_page_excluding(this.h, page, p, c, scale, o)
1332
+ )
1333
+ );
1334
+ }
1292
1335
  // fonts — embed a downloaded font, then add real selectable text
1293
1336
  /**
1294
1337
  * Embed an outline font program as a Type0 font and return its object number