Skip to content

Commit

Permalink
Merge pull request #18972 from calixteman/refactor_highlight
Browse files Browse the repository at this point in the history
[Editor] Refactor the free highlight stuff in order to be able to use the code for more general drawing
  • Loading branch information
calixteman authored Oct 29, 2024
2 parents 9870099 + 5a9607b commit f142fb8
Show file tree
Hide file tree
Showing 7 changed files with 630 additions and 473 deletions.
22 changes: 8 additions & 14 deletions src/display/draw_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,11 @@ class DrawLayer {
return clipPathId;
}

highlight(outlines, color, opacity, isPathUpdatable = false) {
draw(outlines, color, opacity, isPathUpdatable = false) {
const id = this.#id++;
const root = this.#createSVG(outlines.box);
root.classList.add("highlight");
if (outlines.free) {
root.classList.add("free");
}
root.classList.add(...outlines.classNamesForDrawing);

const defs = DrawLayer._svgFactory.createElement("defs");
root.append(defs);
const path = DrawLayer._svgFactory.createElement("path");
Expand All @@ -119,14 +117,14 @@ class DrawLayer {
return { id, clipPathId: `url(#${clipPathId})` };
}

highlightOutline(outlines) {
drawOutline(outlines) {
// We cannot draw the outline directly in the SVG for highlights because
// it composes with its parent with mix-blend-mode: multiply.
// But the outline has a different mix-blend-mode, so we need to draw it in
// its own SVG.
const id = this.#id++;
const root = this.#createSVG(outlines.box);
root.classList.add("highlightOutline");
root.classList.add(...outlines.classNamesForOutlining);
const defs = DrawLayer._svgFactory.createElement("defs");
root.append(defs);
const path = DrawLayer._svgFactory.createElement("path");
Expand All @@ -137,8 +135,7 @@ class DrawLayer {
path.setAttribute("vector-effect", "non-scaling-stroke");

let maskId;
if (outlines.free) {
root.classList.add("free");
if (outlines.mustRemoveSelfIntersections) {
const mask = DrawLayer._svgFactory.createElement("mask");
defs.append(mask);
maskId = `mask_p${this.pageIndex}_${id}`;
Expand Down Expand Up @@ -188,11 +185,6 @@ class DrawLayer {
path.setAttribute("d", line.toSVGPath());
}

removeFreeHighlight(id) {
this.remove(id);
this.#toUpdate.delete(id);
}

updatePath(id, line) {
this.#toUpdate.get(id).setAttribute("d", line.toSVGPath());
}
Expand Down Expand Up @@ -230,6 +222,7 @@ class DrawLayer {
}

remove(id) {
this.#toUpdate.delete(id);
if (this.#parent === null) {
return;
}
Expand All @@ -243,6 +236,7 @@ class DrawLayer {
root.remove();
}
this.#mapping.clear();
this.#toUpdate.clear();
}
}

Expand Down
Loading

0 comments on commit f142fb8

Please sign in to comment.