diff --git a/editor/recalculate.js b/editor/recalculate.js index a2e3d702..0065bdb7 100644 --- a/editor/recalculate.js +++ b/editor/recalculate.js @@ -76,6 +76,7 @@ svgedit.recalculate.recalculateDimensions = function (selected) { // remove any unnecessary transforms if (tlist && tlist.numberOfItems > 0) { k = tlist.numberOfItems; + var noi = k; while (k--) { var xform = tlist.getItem(k); if (xform.type === 0) { @@ -83,6 +84,14 @@ svgedit.recalculate.recalculateDimensions = function (selected) { // remove identity matrices } else if (xform.type === 1) { if (svgedit.math.isIdentity(xform.matrix)) { + if (noi === 1) { + // Overcome Chrome bug (though only when noi is 1) with + // `removeItem` preventing `removeAttribute` from + // subsequently working + // See https://bugs.chromium.org/p/chromium/issues/detail?id=843901 + selected.removeAttribute('transform'); + return null; + } tlist.removeItem(k); } // remove zero-degree rotations @@ -99,9 +108,11 @@ svgedit.recalculate.recalculateDimensions = function (selected) { // if this element had no transforms, we are done if (!tlist || tlist.numberOfItems === 0) { - // Chrome has a bug that requires clearing the attribute first. + // Chrome apparently had a bug that requires clearing the attribute first. selected.setAttribute('transform', ''); + // However, this still next line currently doesn't work at all in Chrome selected.removeAttribute('transform'); + // selected.transform.baseVal.clear(); // Didn't help for Chrome bug return null; } diff --git a/editor/svgutils.js b/editor/svgutils.js index b5001e55..878317aa 100644 --- a/editor/svgutils.js +++ b/editor/svgutils.js @@ -548,7 +548,20 @@ svgedit.utilities.getBBox = function (elem) { } } else if (~visElemsArr.indexOf(elname)) { if (selected) { - ret = selected.getBBox(); + try { + ret = selected.getBBox(); + } catch (err) { + // tspan (and textPath apparently) have no `getBBox` in Firefox: https://bugzilla.mozilla.org/show_bug.cgi?id=937268 + // Re: Chrome returning bbox for containing text element, see: https://bugs.chromium.org/p/chromium/issues/detail?id=349835 + var extent = selected.getExtentOfChar(0); // pos+dimensions of the first glyph + var width = selected.getComputedTextLength(); // width of the tspan + ret = { + x: extent.x, + y: extent.y, + width: width, + height: extent.height + }; + } } else { // Check if element is child of a foreignObject var fo = $(selected).closest('foreignObject');