You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Paths like m 0 0 h 5 v 5 h -5 v -5 should be converted to m 0 0 h 5 v 5 h -5 z for better minification. That is, convert the line home to z.
(To follow up on that, you could also convert m 0 0 a 2.5 2.5 0 0 0 0 5 a 2.5 2.5 0 0 0 0 -5 z to m 0 0 a 2.5 2.5 0 0 0 0 5 a 2.5 2.5 0 0 0 0 -5. That is, remove a redundant z.)
I already made a plugin that does the first one, but it should probably be rewritten to fit in to the existing path transformer better. And the second one requires disabling on stroke. Anyway, code of the plugin, in case it helps:
constprocessPath: Visitor={element: {enter(element){constpath='pathJS'inelement&&(element.pathJSasPathDataItem[]);if(!path)return;conststart=[0,0];constcursor=[0,0];for(leti=0;i<path.length;i+=1){constpathItem=path[i];const{ command, args }=pathItem;// moveto (x y)if(command==='m'){cursor[0]+=args[0];cursor[1]+=args[1];start[0]=cursor[0];start[1]=cursor[1];}if(command==='M'){cursor[0]=args[0];cursor[1]=args[1];start[0]=cursor[0];start[1]=cursor[1];}// lineto (x y)if(command==='l'){cursor[0]+=args[0];cursor[1]+=args[1];}if(command==='L'){cursor[0]=args[0];cursor[1]=args[1];}// horizontal lineto (x)if(command==='h'){cursor[0]+=args[0];}if(command==='H'){cursor[0]=args[0];}// vertical lineto (y)if(command==='v'){cursor[1]+=args[0];}if(command==='V'){cursor[1]=args[0];}if(['l','L','h','H','v','V'].includes(command)){// !! the part that does stuffif(start[0]==cursor[0]&&start[1]==cursor[1])path[i]={command: 'z',args: []};}// curveto (x1 y1 x2 y2 x y)if(command==='c'){cursor[0]+=args[4];cursor[1]+=args[5];}if(command==='C'){cursor[0]=args[4];cursor[1]=args[5];}// smooth curveto (x2 y2 x y)if(command==='s'){cursor[0]+=args[2];cursor[1]+=args[3];}if(command==='S'){cursor[0]=args[2];cursor[1]=args[3];}// quadratic Bézier curveto (x1 y1 x y)if(command==='q'){cursor[0]+=args[2];cursor[1]+=args[3];}if(command==='Q'){cursor[0]=args[2];cursor[1]=args[3];}// smooth quadratic Bézier curveto (x y)if(command==='t'){cursor[0]+=args[0];cursor[1]+=args[1];}if(command==='T'){cursor[0]=args[0];cursor[1]=args[1];}// elliptical arc (rx ry x-axis-rotation large-arc-flag sweep-flag x y)if(command==='a'){cursor[0]+=args[5];cursor[1]+=args[6];}if(command==='A'){cursor[0]=args[5];cursor[1]=args[6];}// closepathif(command==='Z'||command==='z'){// reset cursorcursor[0]=start[0];cursor[1]=start[1];}}element.attributes.d=stringifyPathData({pathData: path,});},},};
The text was updated successfully, but these errors were encountered:
Paths like
m 0 0 h 5 v 5 h -5 v -5
should be converted tom 0 0 h 5 v 5 h -5 z
for better minification. That is, convert the line home toz
.(To follow up on that, you could also convert
m 0 0 a 2.5 2.5 0 0 0 0 5 a 2.5 2.5 0 0 0 0 -5 z
tom 0 0 a 2.5 2.5 0 0 0 0 5 a 2.5 2.5 0 0 0 0 -5
. That is, remove a redundantz
.)I already made a plugin that does the first one, but it should probably be rewritten to fit in to the existing path transformer better. And the second one requires disabling on stroke. Anyway, code of the plugin, in case it helps:
The text was updated successfully, but these errors were encountered: