Merge pull request #16180 from Snuffleupagus/appendFeFunc

Add a helper, in `DOMFilterFactory`, to reduce duplication when creating `<feFuncX>`s
This commit is contained in:
Jonas Jenwald 2023-03-20 12:41:03 +01:00 committed by GitHub
commit fb2367d14f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 48 deletions

View File

@ -3320,8 +3320,7 @@ class InternalRenderTask {
this.canvasFactory,
this.filterFactory,
{ optionalContentConfig },
this.annotationCanvasMap,
this.pageColors
this.annotationCanvasMap
);
this.gfx.beginDrawing({
transform,

View File

@ -98,6 +98,13 @@ class DOMFilterFactory extends BaseFilterFactory {
return this.#_defs;
}
#appendFeFunc(feComponentTransfer, func, table) {
const feFunc = this.#document.createElementNS(SVG_NS, func);
feFunc.setAttribute("type", "discrete");
feFunc.setAttribute("tableValues", table);
feComponentTransfer.append(feFunc);
}
addFilter(maps) {
if (!maps) {
return "none";
@ -157,21 +164,9 @@ class DOMFilterFactory extends BaseFilterFactory {
);
filter.append(feComponentTransfer);
const type = "discrete";
const feFuncR = this.#document.createElementNS(SVG_NS, "feFuncR");
feFuncR.setAttribute("type", type);
feFuncR.setAttribute("tableValues", tableR);
feComponentTransfer.append(feFuncR);
const feFuncG = this.#document.createElementNS(SVG_NS, "feFuncG");
feFuncG.setAttribute("type", type);
feFuncG.setAttribute("tableValues", tableG);
feComponentTransfer.append(feFuncG);
const feFuncB = this.#document.createElementNS(SVG_NS, "feFuncB");
feFuncB.setAttribute("type", type);
feFuncB.setAttribute("tableValues", tableB);
feComponentTransfer.append(feFuncB);
this.#appendFeFunc(feComponentTransfer, "feFuncR", tableR);
this.#appendFeFunc(feComponentTransfer, "feFuncG", tableG);
this.#appendFeFunc(feComponentTransfer, "feFuncB", tableB);
this.#defs.append(filter);
@ -239,21 +234,9 @@ class DOMFilterFactory extends BaseFilterFactory {
);
filter.append(feComponentTransfer);
let type = "discrete";
let feFuncR = this.#document.createElementNS(SVG_NS, "feFuncR");
feFuncR.setAttribute("type", type);
feFuncR.setAttribute("tableValues", table);
feComponentTransfer.append(feFuncR);
let feFuncG = this.#document.createElementNS(SVG_NS, "feFuncG");
feFuncG.setAttribute("type", type);
feFuncG.setAttribute("tableValues", table);
feComponentTransfer.append(feFuncG);
let feFuncB = this.#document.createElementNS(SVG_NS, "feFuncB");
feFuncB.setAttribute("type", type);
feFuncB.setAttribute("tableValues", table);
feComponentTransfer.append(feFuncB);
this.#appendFeFunc(feComponentTransfer, "feFuncR", table);
this.#appendFeFunc(feComponentTransfer, "feFuncG", table);
this.#appendFeFunc(feComponentTransfer, "feFuncB", table);
const feColorMatrix = this.#document.createElementNS(
SVG_NS,
@ -281,22 +264,9 @@ class DOMFilterFactory extends BaseFilterFactory {
}
return arr.join(",");
};
type = "discrete";
feFuncR = this.#document.createElementNS(SVG_NS, "feFuncR");
feFuncR.setAttribute("type", type);
feFuncR.setAttribute("tableValues", `${getSteps(0, 5)}`);
feComponentTransfer.append(feFuncR);
feFuncG = this.#document.createElementNS(SVG_NS, "feFuncG");
feFuncG.setAttribute("type", type);
feFuncG.setAttribute("tableValues", `${getSteps(1, 5)}`);
feComponentTransfer.append(feFuncG);
feFuncB = this.#document.createElementNS(SVG_NS, "feFuncB");
feFuncB.setAttribute("type", type);
feFuncB.setAttribute("tableValues", `${getSteps(2, 5)}`);
feComponentTransfer.append(feFuncB);
this.#appendFeFunc(feComponentTransfer, "feFuncR", getSteps(0, 5));
this.#appendFeFunc(feComponentTransfer, "feFuncG", getSteps(1, 5));
this.#appendFeFunc(feComponentTransfer, "feFuncB", getSteps(2, 5));
this.#defs.append(filter);