mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-19 22:58:07 +02:00
Merge pull request #18417 from Snuffleupagus/DOMFilterFactory-baseUrl
Create absolute filter-URLs when needed in `DOMFilterFactory` (issue 18406)
This commit is contained in:
commit
8082c2daf1
4 changed files with 35 additions and 5 deletions
|
@ -49,6 +49,8 @@ class PixelsPerInch {
|
|||
* does the magic for us.
|
||||
*/
|
||||
class DOMFilterFactory extends BaseFilterFactory {
|
||||
#baseUrl;
|
||||
|
||||
#_cache;
|
||||
|
||||
#_defs;
|
||||
|
@ -121,6 +123,25 @@ class DOMFilterFactory extends BaseFilterFactory {
|
|||
return [bufferR.join(","), bufferG.join(","), bufferB.join(",")];
|
||||
}
|
||||
|
||||
#createUrl(id) {
|
||||
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
|
||||
if (this.#baseUrl === undefined) {
|
||||
const url = this.#document.URL;
|
||||
if (url === this.#document.baseURI) {
|
||||
// No `<base>`-element present, hence a relative URL should work.
|
||||
this.#baseUrl = "";
|
||||
} else if (isDataScheme(url)) {
|
||||
warn('#createUrl: ignore "data:"-URL for performance reasons.');
|
||||
this.#baseUrl = "";
|
||||
} else {
|
||||
this.#baseUrl = url.split("#", 1)[0];
|
||||
}
|
||||
}
|
||||
return `url(${this.#baseUrl}#${id})`;
|
||||
}
|
||||
return `url(${id})`;
|
||||
}
|
||||
|
||||
addFilter(maps) {
|
||||
if (!maps) {
|
||||
return "none";
|
||||
|
@ -146,7 +167,7 @@ class DOMFilterFactory extends BaseFilterFactory {
|
|||
// https://www.w3.org/TR/SVG11/filters.html#feComponentTransferElement
|
||||
|
||||
const id = `g_${this.#docId}_transfer_map_${this.#id++}`;
|
||||
const url = `url(#${id})`;
|
||||
const url = this.#createUrl(id);
|
||||
this.#cache.set(maps, url);
|
||||
this.#cache.set(key, url);
|
||||
|
||||
|
@ -232,7 +253,7 @@ class DOMFilterFactory extends BaseFilterFactory {
|
|||
filter
|
||||
);
|
||||
|
||||
info.url = `url(#${id})`;
|
||||
info.url = this.#createUrl(id);
|
||||
return info.url;
|
||||
}
|
||||
|
||||
|
@ -254,7 +275,7 @@ class DOMFilterFactory extends BaseFilterFactory {
|
|||
}
|
||||
|
||||
const id = `g_${this.#docId}_alpha_map_${this.#id++}`;
|
||||
const url = `url(#${id})`;
|
||||
const url = this.#createUrl(id);
|
||||
this.#cache.set(map, url);
|
||||
this.#cache.set(key, url);
|
||||
|
||||
|
@ -287,7 +308,7 @@ class DOMFilterFactory extends BaseFilterFactory {
|
|||
}
|
||||
|
||||
const id = `g_${this.#docId}_luminosity_map_${this.#id++}`;
|
||||
const url = `url(#${id})`;
|
||||
const url = this.#createUrl(id);
|
||||
this.#cache.set(map, url);
|
||||
this.#cache.set(key, url);
|
||||
|
||||
|
@ -389,7 +410,7 @@ class DOMFilterFactory extends BaseFilterFactory {
|
|||
filter
|
||||
);
|
||||
|
||||
info.url = `url(#${id})`;
|
||||
info.url = this.#createUrl(id);
|
||||
return info.url;
|
||||
}
|
||||
|
||||
|
|
1
test/pdfs/.gitignore
vendored
1
test/pdfs/.gitignore
vendored
|
@ -127,6 +127,7 @@
|
|||
!issue7891_bc0.pdf
|
||||
!issue11242_reduced.pdf
|
||||
!issue16176.pdf
|
||||
!issue16287.pdf
|
||||
!issue17064_readonly.pdf
|
||||
!issue11279.pdf
|
||||
!issue11362.pdf
|
||||
|
|
BIN
test/pdfs/issue16287.pdf
Normal file
BIN
test/pdfs/issue16287.pdf
Normal file
Binary file not shown.
|
@ -5646,6 +5646,14 @@
|
|||
"rounds": 1,
|
||||
"type": "eq"
|
||||
},
|
||||
{
|
||||
"id": "issue16287",
|
||||
"file": "pdfs/issue16287.pdf",
|
||||
"md5": "cd3e0859140465ae8b8bde0c95cb4929",
|
||||
"rounds": 1,
|
||||
"type": "eq",
|
||||
"about": "Please note that this file currently renders incorrectly."
|
||||
},
|
||||
{
|
||||
"id": "issue2006",
|
||||
"file": "pdfs/issue2006.pdf",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue