Method-Draw icon indicating copy to clipboard operation
Method-Draw copied to clipboard

Many transforms: recalculateDimensions() calculates wrong

Open d9k opened this issue 4 years ago • 0 comments

For example, I import image with <g> element which have

transform attribute with value.

matrix(1,0,0,1,16.98053,22.125)
translate(1106.75,1180.008)
rotate(270)
scale(0.8,0.8)
matrix(1,0,0,1,-16.98053,-22.125)

after I click on this <g> element recalculateDimensions() runs and transform attribute becomes

rotate(270 1121.6668701171873,1202.1330566406248)
matrix(0.800000011920929,0,0,0.800000011920929,1110.1461057975764,1184.4330563768744)

visually element translates off the canvas.

I fixed this issue by adding these lines to the top of recalculateDimensions() :

  if (tlist.numberOfItems >= 4) {
    // TODO refactor to tlist.simplifyToOneMatrix()
    let resultMatrix = svgroot.createSVGMatrix();
    for (var i=0; i< tlist.numberOfItems; i++) {
      let tlistItem = tlist.getItem(i);
      let matrix = tlistItem.matrix;
      resultMatrix = matrixMultiply(resultMatrix, matrix);
    }

    var resultMatrixTransform = svgroot.createSVGTransform();
    resultMatrixTransform.setMatrix(resultMatrix);

    tlist.clear();

    tlist.appendItem(resultMatrixTransform);
  }

(after the lines

  if (selected == null) return null;

  var tlist = getTransformList(selected);

)

d9k avatar Feb 19 '21 13:02 d9k