mirror of
https://github.com/svg/svgo.git
synced 2025-08-09 02:22:08 +03:00
E-notated numbers in paths not recognised (fix #63)
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var regNumericValues = /^([\-+]?\d*\.?\d+)(px|pt|pc|mm|cm|m|in|ft|em|ex|%)?$/,
|
var regNumericValues = /^([\-+]?\d*\.?\d+(\.\d+)?([eE][\-+]?\d+)?)(px|pt|pc|mm|cm|m|in|ft|em|ex|%)?$/,
|
||||||
removeLeadingZero = require('../lib/svgo/tools').removeLeadingZero;
|
removeLeadingZero = require('../lib/svgo/tools').removeLeadingZero;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -26,7 +26,7 @@ exports.cleanupNumericValues = function(item, params) {
|
|||||||
if (match) {
|
if (match) {
|
||||||
// round it to the fixed precision
|
// round it to the fixed precision
|
||||||
var num = +(+match[1]).toFixed(params.floatPrecision),
|
var num = +(+match[1]).toFixed(params.floatPrecision),
|
||||||
units = match[2] || '';
|
units = match[4] || '';
|
||||||
|
|
||||||
// and remove leading zero
|
// and remove leading zero
|
||||||
if (params.leadingZero) {
|
if (params.leadingZero) {
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
var cleanupOutData = require('../lib/svgo/tools').cleanupOutData,
|
var cleanupOutData = require('../lib/svgo/tools').cleanupOutData,
|
||||||
regPathInstructions = /([MmLlHhVvCcSsQqTtAaZz])\s*/,
|
regPathInstructions = /([MmLlHhVvCcSsQqTtAaZz])\s*/,
|
||||||
regPathData = /(?=-)|[\s,]+/,
|
regPathData = /[\-+]?\d*\.?\d+(\.\d+)?([eE][\-+]?\d+)?/g,
|
||||||
pathElems = ['path', 'glyph', 'missing-glyph'],
|
pathElems = ['path', 'glyph', 'missing-glyph'],
|
||||||
hasMarkerMid;
|
hasMarkerMid;
|
||||||
|
|
||||||
@@ -73,17 +73,17 @@ function path2js(pathString) {
|
|||||||
// data item
|
// data item
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// M 35.898 14.374 L 35.898 14.374 → M35.898 14.374L35.898 14.374
|
data = data.trim().match(regPathData);
|
||||||
data = data.trim().split(regPathData).map(function(str) {
|
|
||||||
return +str;
|
|
||||||
});
|
|
||||||
|
|
||||||
// very stupid defense strategy
|
if (data) {
|
||||||
if (typeof data[0] === 'number' && !isNaN(data[0])) {
|
|
||||||
|
|
||||||
var index = 0,
|
var index = 0,
|
||||||
pair = 2;
|
pair = 2;
|
||||||
|
|
||||||
|
data = data.map(function(str) {
|
||||||
|
return +str;
|
||||||
|
});
|
||||||
|
|
||||||
// deal with very first 'Mm' and multiple points data
|
// deal with very first 'Mm' and multiple points data
|
||||||
if ('Mm'.indexOf(instruction) > -1) {
|
if ('Mm'.indexOf(instruction) > -1) {
|
||||||
|
|
||||||
|
@@ -3,6 +3,7 @@
|
|||||||
<path d="M 10 50"/>
|
<path d="M 10 50"/>
|
||||||
<path d="M10 50"/>
|
<path d="M10 50"/>
|
||||||
<path d="M10,50"/>
|
<path d="M10,50"/>
|
||||||
|
<path d="M10-3.05176e-005"/>
|
||||||
<path d="M 10 , 50"/>
|
<path d="M 10 , 50"/>
|
||||||
<path d="M -10,-50"/>
|
<path d="M -10,-50"/>
|
||||||
<path d="M -10 -50"/>
|
<path d="M -10 -50"/>
|
||||||
|
Before Width: | Height: | Size: 342 B After Width: | Height: | Size: 375 B |
@@ -3,6 +3,7 @@
|
|||||||
<path d="M10 50"/>
|
<path d="M10 50"/>
|
||||||
<path d="M10 50"/>
|
<path d="M10 50"/>
|
||||||
<path d="M10 50"/>
|
<path d="M10 50"/>
|
||||||
|
<path d="M10 0"/>
|
||||||
<path d="M10 50"/>
|
<path d="M10 50"/>
|
||||||
<path d="M-10-50"/>
|
<path d="M-10-50"/>
|
||||||
<path d="M-10-50"/>
|
<path d="M-10-50"/>
|
||||||
|
Before Width: | Height: | Size: 327 B After Width: | Height: | Size: 349 B |
Reference in New Issue
Block a user