diff --git a/src/basic/Matrix.js b/src/basic/Matrix.js index edf0287f..50c0930a 100644 --- a/src/basic/Matrix.js +++ b/src/basic/Matrix.js @@ -238,7 +238,7 @@ var Matrix = this.Matrix = Base.extend(/** @lends Matrix# */{ * @return {String} A string representation of this transform. */ toString: function() { - var format = Base.formatNumber; + var format = Base.formatFloat; return '[[' + [format(this._a), format(this._b), format(this._tx)].join(', ') + '], [' + [format(this._c), format(this._d), diff --git a/src/basic/Point.js b/src/basic/Point.js index b1ce2b4b..02e6203c 100644 --- a/src/basic/Point.js +++ b/src/basic/Point.js @@ -209,7 +209,7 @@ var Point = this.Point = Base.extend(/** @lends Point# */{ * @return {String} A string representation of the point. */ toString: function() { - var format = Base.formatNumber; + var format = Base.formatFloat; return '{ x: ' + format(this.x) + ', y: ' + format(this.y) + ' }'; }, diff --git a/src/basic/Rectangle.js b/src/basic/Rectangle.js index 9b8882f9..183a1df8 100644 --- a/src/basic/Rectangle.js +++ b/src/basic/Rectangle.js @@ -398,7 +398,7 @@ var Rectangle = this.Rectangle = Base.extend(/** @lends Rectangle# */{ * @return {String} A string representation of this rectangle. */ toString: function() { - var format = Base.formatNumber; + var format = Base.formatFloat; return '{ x: ' + format(this.x) + ', y: ' + format(this.y) + ', width: ' + format(this.width) diff --git a/src/basic/Size.js b/src/basic/Size.js index 2f603e75..dd3a3c7a 100644 --- a/src/basic/Size.js +++ b/src/basic/Size.js @@ -129,7 +129,7 @@ var Size = this.Size = Base.extend(/** @lends Size# */{ * @return {String} A string representation of the size. */ toString: function() { - var format = Base.formatNumber; + var format = Base.formatFloat; return '{ width: ' + format(this.width) + ', height: ' + format(this.height) + ' }'; }, diff --git a/src/color/Color.js b/src/color/Color.js index b9676314..89632a22 100644 --- a/src/color/Color.js +++ b/src/color/Color.js @@ -459,7 +459,7 @@ var Color = this.Color = Base.extend(new function() { */ toString: function() { var parts = [], - format = Base.formatNumber; + format = Base.formatFloat; for (var i = 0, l = this._components.length; i < l; i++) { var component = this._components[i], value = this['_' + component]; diff --git a/src/core/Base.js b/src/core/Base.js index 8c6a6230..b0be0aa7 100644 --- a/src/core/Base.js +++ b/src/core/Base.js @@ -44,7 +44,7 @@ this.Base = Base.inject(/** @lends Base# */{ if (key.charAt(0) != '_') { var type = typeof value; this.push(key + ': ' + (type === 'number' - ? Base.formatNumber(value) + ? Base.formatFloat(value) : type === 'string' ? "'" + value + "'" : value)); } }, []).join(', ') + ' }'; @@ -239,8 +239,12 @@ this.Base = Base.inject(/** @lends Base# */{ * * @param {Number} num the number to be converted to a string */ - formatNumber: function(num) { + formatFloat: function(num) { return (Math.round(num * 100000) / 100000).toString(); + }, + + toFloat: function(str) { + return parseFloat(str, 10); } } }); diff --git a/src/core/PaperScript.js b/src/core/PaperScript.js index 3f1b512f..194a96a2 100644 --- a/src/core/PaperScript.js +++ b/src/core/PaperScript.js @@ -204,9 +204,8 @@ var PaperScript = this.PaperScript = new function() { var xhr = new (window.ActiveXObject || XMLHttpRequest)( 'Microsoft.XMLHTTP'); xhr.open('GET', url, true); - if (xhr.overrideMimeType) { + if (xhr.overrideMimeType) xhr.overrideMimeType('text/plain'); - } xhr.onreadystatechange = function() { if (xhr.readyState === 4) { return evaluate(xhr.responseText, scope); diff --git a/src/path/CurveLocation.js b/src/path/CurveLocation.js index fa949a75..a2d174d0 100644 --- a/src/path/CurveLocation.js +++ b/src/path/CurveLocation.js @@ -201,9 +201,9 @@ CurveLocation = Base.extend(/** @lends CurveLocation# */{ parts.push('index: ' + index); var parameter = this.getParameter(); if (parameter != null) - parts.push('parameter: ' + Base.formatNumber(parameter)); + parts.push('parameter: ' + Base.formatFloat(parameter)); if (this._distance != null) - parts.push('distance: ' + Base.formatNumber(this._distance)); + parts.push('distance: ' + Base.formatFloat(this._distance)); return '{ ' + parts.join(', ') + ' }'; } }); diff --git a/src/svg/SvgExport.js b/src/svg/SvgExport.js index 56d38f97..5acadab8 100644 --- a/src/svg/SvgExport.js +++ b/src/svg/SvgExport.js @@ -22,18 +22,18 @@ */ new function() { - // Shortcut to Base.formatNumber - var formatNumber = Base.formatNumber; + // Shortcut to Base.formatFloat + var formatFloat = Base.formatFloat; function formatPoint(point) { - return formatNumber(point.x) + ',' + formatNumber(point.y); + return formatFloat(point.x) + ',' + formatFloat(point.y); } function setAttributes(svg, attrs) { for (var key in attrs) { var val = attrs[key]; if (typeof val === 'number') - val = formatNumber(val); + val = formatFloat(val); svg.setAttribute(key, val); } return svg; @@ -70,7 +70,7 @@ new function() { scale = matrix.getScaling(); if (angle != null) { transform.push(angle - ? 'rotate(' + formatNumber(angle) + ')' + ? 'rotate(' + formatFloat(angle) + ')' : 'scale(' + formatPoint(scale) +')'); } else { transform.push('matrix(' + matrix.getValues().join(',') + ')'); @@ -309,7 +309,7 @@ new function() { break; } if (angle) { - attrs.transform = 'rotate(' + formatNumber(angle) + ',' + attrs.transform = 'rotate(' + formatFloat(angle) + ',' + formatPoint(center) + ')'; } var svg = createElement(type, attrs); @@ -348,7 +348,7 @@ new function() { : entry.type === 'array' ? value.join(',') : entry.type === 'number' - ? formatNumber(value) + ? formatFloat(value) : value; } }); diff --git a/src/svg/SvgImport.js b/src/svg/SvgImport.js index 9aa5b748..ddff6c0b 100644 --- a/src/svg/SvgImport.js +++ b/src/svg/SvgImport.js @@ -62,7 +62,7 @@ new function() { return value === 'none' ? null : type === 'number' - ? parseFloat(value, 10) + ? Base.toFloat(value) : type === 'array' ? value.split(/[\s,]+/g).map(parseFloat) : type === 'color' && getDefinition(value) @@ -394,7 +394,7 @@ new function() { case 'stop-opacity': // http://www.w3.org/TR/SVG/masking.html#OpacityProperty case 'opacity': - var opacity = parseFloat(value, 10); + var opacity = Base.toFloat(value); if (name === 'stop-opacity') { item.color.setAlpha(opacity); } else { @@ -459,7 +459,7 @@ new function() { item.setFont(value.split(',')[0].replace(/^\s+|\s+$/g, '')); break; case 'font-size': - item.setFontSize(parseFloat(value, 10)); + item.setFontSize(Base.toFloat(value)); break; case 'text-anchor': item.setJustification({