Skip to content

Commit

Permalink
SW-733 SVG - Transformations hide images in the SVG files (#1397)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmed-mrbeam and hungerpirat committed Dec 8, 2021
1 parent 7fdfec7 commit 877819d
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions octoprint_mrbeam/static/js/matrix_oven.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,21 +154,29 @@ Snap.plugin(function (Snap, Element, Paper, global) {
var transformedW = matrix.x(x + w, y + h) - transformedX;
var transformedH = matrix.y(x + w, y + h) - transformedY;

// keep mirroring in the elements matrix if mirrored
const mirroredX = matrix.a < 0;
const mirroredY = matrix.d < 0;
let mat = Snap.matrix();
if (mirroredX) {
// mirrored x-axis
transformedW = Math.abs(transformedW);
mat.a = -1;
transformedX = -transformedX;
}
if (mirroredY) {
// mirrored x-axis
transformedH = Math.abs(transformedH);
mat.d = -1;
transformedY = -transformedY;
}
elem.attr({
x: transformedX,
y: transformedY,
width: transformedW,
height: transformedH,
});
elem.node.removeAttribute("transform"); // prefer less attributes.

if (transformedH < 0) {
elem.attr({
style: "transform: scale(1,-1); transform-origin: top",
height: -transformedH,
y: -transformedY,
});
}
elem.transform(mat);
return ignoredElements;
}

Expand Down

0 comments on commit 877819d

Please sign in to comment.