Include the document-id in the SVG-filter names (PR 16062 follow-up)

In the general PDF.js library multiple PDF documents may be opened on the same web-page, which is why we many years ago started using document-specific identifiers to prevent issues with global data such e.g. with fonts.
Hence we need to treat the identifiers generated by the `FilterFactory` in the same way, since the SVG-filters for two separate PDF documents may otherwise get identical ids.
This commit is contained in:
Jonas Jenwald 2023-03-09 15:27:57 +01:00
parent a0ef5a4ae1
commit 92296fa6a1
2 changed files with 7 additions and 4 deletions

View file

@ -53,11 +53,14 @@ class FilterFactory {
#_defs;
#docId;
#document;
#id = 0;
constructor({ ownerDocument = globalThis.document } = {}) {
constructor({ docId, ownerDocument = globalThis.document } = {}) {
this.#docId = docId;
this.#document = ownerDocument;
}
@ -124,7 +127,7 @@ class FilterFactory {
// We create a SVG filter: feComponentTransferElement
// https://www.w3.org/TR/SVG11/filters.html#feComponentTransferElement
const id = `transfer_map_${this.#id++}`;
const id = `g_${this.#docId}_transfer_map_${this.#id++}`;
const url = `url(#${id})`;
this.#cache.set(maps, url);
this.#cache.set(key, url);