Current test status: All tests passing (in at least Chrome and Firefox beta)

- Fix (Firefox): tspan (and textPath apparently) have no `getBBox` in Firefox, so recover (fixes FF issue with recalculate test 3: "recalculateDimensions() on text w/tspan with simple translate")
- Fix (Chrome): Chrome has a bug in not performing `removeAttribute` after `removeItem`; deal with it (though only if there is a single identity matrix) (fixes Chrome issue with recalculate test 1: " recalculateDimensions() on rect with identity matrix")
master
Brett Zamir 2018-05-17 15:27:38 +08:00
parent 6f791b12dd
commit 69f3a42aa8
2 changed files with 26 additions and 2 deletions

View File

@ -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;
}

View File

@ -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');