mirror of
https://github.com/svg/svgo.git
synced 2025-07-29 20:21:14 +03:00
Corrected path merging
This commit is contained in:
@ -17,13 +17,7 @@ exports.fn = function(item) {
|
|||||||
if (item.isElem() && !item.isEmpty()) {
|
if (item.isElem() && !item.isEmpty()) {
|
||||||
|
|
||||||
var prevContentItem,
|
var prevContentItem,
|
||||||
delim = '',
|
prevContentItemKeys = null;
|
||||||
prevContentItemKeys = null,
|
|
||||||
prevItemPathClosed = false,
|
|
||||||
contentItemKeys = null,
|
|
||||||
contentItemPathClosed = false,
|
|
||||||
equalData,
|
|
||||||
attrName;
|
|
||||||
|
|
||||||
item.content = item.content.filter(function(contentItem) {
|
item.content = item.content.filter(function(contentItem) {
|
||||||
|
|
||||||
@ -35,56 +29,36 @@ exports.fn = function(item) {
|
|||||||
contentItem.hasAttr('d')
|
contentItem.hasAttr('d')
|
||||||
) {
|
) {
|
||||||
|
|
||||||
prevItemPathClosed = prevContentItem.attr('d').value.charAt(prevContentItem.attr('d').value.length-1) === 'z';
|
if (prevContentItemKeys == null) {
|
||||||
contentItemPathClosed = contentItem.attr('d').value.charAt(contentItem.attr('d').value.length-1) === 'z';
|
prevContentItemKeys = Object.keys(prevContentItem.attrs);
|
||||||
|
|
||||||
if (!prevItemPathClosed && contentItemPathClosed){
|
|
||||||
//console.log('Previous path not closed, current plath closed', prevContentItem.attr('d').value, contentItem.attr('d').value);
|
|
||||||
prevContentItem = contentItem;
|
|
||||||
prevContentItemKeys = null;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (prevContentItemKeys === null){
|
var contentItemKeys = Object.keys(contentItem.attrs);
|
||||||
prevContentItemKeys = Object.keys(prevContentItem.attrs);
|
if (contentItemKeys.length > 1 || prevContentItemKeys.length > 1) {
|
||||||
}
|
if (contentItemKeys.length != prevContentItemKeys.length) {
|
||||||
|
prevContentItem = contentItem;
|
||||||
contentItemKeys = Object.keys(contentItem.attrs);
|
prevContentItemKeys = null;
|
||||||
if (contentItemKeys.length !== 1 || prevContentItemKeys.length !== 1){
|
return true;
|
||||||
if (contentItemKeys.length !== prevContentItemKeys.length){
|
|
||||||
prevContentItem = contentItem;
|
|
||||||
prevContentItemKeys = null;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
equalData = true;
|
var equalData = contentItemKeys.every(function(key) {
|
||||||
for(var i = 0, I = contentItemKeys.length; i < I; i++){
|
return key == 'd' ||
|
||||||
attrName = contentItemKeys[i];
|
prevContentItem.hasAttr(key) &&
|
||||||
if (attrName != 'd'){
|
prevContentItem.attr(key).value == contentItem.attr(key).value;
|
||||||
if(typeof prevContentItem.attrs[attrName] === 'undefined'){
|
});
|
||||||
equalData = false;
|
if (!equalData) {
|
||||||
break;
|
prevContentItem = contentItem;
|
||||||
} else if (prevContentItem.attrs[attrName].value !== contentItem.attrs[attrName].value){
|
prevContentItemKeys = null;
|
||||||
equalData = false;
|
return true;
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (!equalData){
|
|
||||||
prevContentItem = contentItem;
|
|
||||||
prevContentItemKeys = null;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// "zM", but "z m"
|
|
||||||
// looks like a FontForge parsing bug
|
|
||||||
if (contentItem.attr('d').value.charAt(0) === 'm') {
|
|
||||||
delim = ' ';
|
|
||||||
} else {
|
|
||||||
delim = ''; // reset delim from looping
|
|
||||||
}
|
}
|
||||||
|
|
||||||
prevContentItem.attr('d').value += delim + contentItem.attr('d').value;
|
prevContentItem.attr('d').value += contentItem.attr('d').value.replace(/m/i, 'M');
|
||||||
|
|
||||||
|
var pathJS = prevContentItem.pathJS;
|
||||||
|
if (pathJS) {
|
||||||
|
pathJS.push.apply(pathJS, contentItem.pathJS);
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,8 +11,7 @@
|
|||||||
@@@
|
@@@
|
||||||
|
|
||||||
<svg xmlns="http://www.w3.org/2000/svg">
|
<svg xmlns="http://www.w3.org/2000/svg">
|
||||||
<path d="M 0,0 zM 10,10 zM 20,20"/>
|
<path d="M 0,0 zM 10,10 zM 20,20M 30,30 z"/>
|
||||||
<path d="M 30,30 z"/>
|
|
||||||
<path d="M 30,30 z" fill="#f00"/>
|
<path d="M 30,30 z" fill="#f00"/>
|
||||||
<path d="M 40,40 z m 50,50 z"/>
|
<path d="M 40,40 zM 50,50 z"/>
|
||||||
</svg>
|
</svg>
|
||||||
|
Before Width: | Height: | Size: 432 B After Width: | Height: | Size: 414 B |
@ -18,10 +18,8 @@
|
|||||||
@@@
|
@@@
|
||||||
|
|
||||||
<svg xmlns="http://www.w3.org/2000/svg">
|
<svg xmlns="http://www.w3.org/2000/svg">
|
||||||
<path d="M 0,0 zM 10,10 zM 20,20" fill="#fff" stroke="#333"/>
|
<path d="M 0,0 zM 10,10 zM 20,20M 30,30 z" fill="#fff" stroke="#333"/>
|
||||||
<path d="M 30,30 z" fill="#fff" stroke="#333"/>
|
|
||||||
<path d="M 30,30 z" fill="#f00"/>
|
<path d="M 30,30 z" fill="#f00"/>
|
||||||
<path d="M 40,40 z m 50,50 zM 40,40 m 50,50"/>
|
<path d="M 40,40 zM 50,50 zM 40,40M 50,50"/>
|
||||||
<path d="M 40,40 z m 50,50 zM 40,40 m 50,50" fill="#fff" stroke="#333"/>
|
<path d="M 40,40 zM 50,50 zM 40,40M 50,50M 50,50 z" fill="#fff" stroke="#333"/>
|
||||||
<path d="m 50,50 z" fill="#fff" stroke="#333"/>
|
|
||||||
</svg>
|
</svg>
|
||||||
|
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 946 B |
Reference in New Issue
Block a user