From c31e519bd234be1a22d94498234283bee69779bc Mon Sep 17 00:00:00 2001 From: Tim de Koning Date: Fri, 3 Feb 2012 17:47:48 +0100 Subject: [PATCH] Fixed SVG new line issues in IE7 and IE8 --- site | 2 +- src/text.class.js | 76 +++++++++++++++++++++++++++-------------------- 2 files changed, 45 insertions(+), 33 deletions(-) diff --git a/site b/site index e60ffecc..657150ac 160000 --- a/site +++ b/site @@ -1 +1 @@ -Subproject commit e60ffecc183a78f8bd6d043dd45cc920c3497129 +Subproject commit 657150ac35ab5802c49ffa90b4e446b9789ec39f diff --git a/src/text.class.js b/src/text.class.js index f042437a..6364b57e 100644 --- a/src/text.class.js +++ b/src/text.class.js @@ -286,7 +286,7 @@ */ toSVG: function() { - var textLines = this.text.split('\n'), + var textLines = this.text.split(/\r?\n/), lineTopOffset = -this._fontAscent - ((this._fontAscent / 5) * this.lineHeight), textLeftOffset = -(this.width/2), @@ -315,46 +315,58 @@ }, _getSVGShadows: function(lineTopOffset, textLines) { - var shadowSpans = [ ] - for (var j = 0, jlen = this._shadows.length; j < jlen; j++) { - for (var i = 0, ilen = textLines.length; i < ilen; i++) { - var lineLeftOffset = (this._boundaries && this._boundaries[i]) ? this._boundaries[i].left : 0; - shadowSpans.push( - '', - textLines[i], - ''); + var shadowSpans = [], j, i, jlen, ilen, lineTopOffsetMultiplier = 1; + + for (j = 0, jlen = this._shadows.length; j < jlen; j++) { + for (i = 0, ilen = textLines.length; i < ilen; i++) { + if (textLines[i] !== '') { + var lineLeftOffset = (this._boundaries && this._boundaries[i]) ? this._boundaries[i].left : 0; + shadowSpans.push( + '', + textLines[i], + ''); + lineTopOffsetMultiplier = 1; + } else { + // in some environments (e.g. IE 7 & 8) empty tspans are completely ignored, using a lineTopOffsetMultiplier + // prevents empty tspans + lineTopOffsetMultiplier++; + } } } return shadowSpans; }, _getSVGTextAndBg: function(lineTopOffset, textLeftOffset, textLines) { - - var textSpans = [ ], - textBgRects = [ ]; + var textSpans = [ ], textBgRects = [ ], i, lineLeftOffset, len, lineTopOffsetMultiplier = 1; // text and background - for (var i = 0, len = textLines.length; i < len; i++) { - - var lineLeftOffset = (this._boundaries && this._boundaries[i]) ? toFixed(this._boundaries[i].left, 2) : 0; - textSpans.push( - ' elements since setting opacity on containing one doesn't work in Illustrator - this._getFillAttributes(this.fill), '>', - textLines[i], - '' - ); + for (i = 0, len = textLines.length; i < len; i++) { + if (textLines[i] !== '') { + lineLeftOffset = (this._boundaries && this._boundaries[i]) ? toFixed(this._boundaries[i].left, 2) : 0; + textSpans.push( + ' elements since setting opacity on containing one doesn't work in Illustrator + this._getFillAttributes(this.fill), '>', + textLines[i], + '' + ); + lineTopOffsetMultiplier = 1; + } else { + // in some environments (e.g. IE 7 & 8) empty tspans are completely ignored, using a lineTopOffsetMultiplier + // prevents empty tspans + lineTopOffsetMultiplier++; + } if (!this.backgroundColor) continue; - + textBgRects.push( '