You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
969 B
26 lines
969 B
// v1.0 exported just the parser function. To maintain backwards compatibility,
|
|
// we export additional named features as properties of that function.
|
|
var parserFunction = require('./parser.js').parse;
|
|
parserFunction.parseSVG = parserFunction;
|
|
parserFunction.makeAbsolute = makeSVGPathCommandsAbsolute;
|
|
module.exports = parserFunction;
|
|
|
|
function makeSVGPathCommandsAbsolute(commands) {
|
|
var subpathStart, prevCmd={x:0,y:0};
|
|
var attr = {x:'x0',y:'y0',x1:'x0',y1:'y0',x2:'x0',y2:'y0'};
|
|
commands.forEach(function(cmd) {
|
|
if (cmd.command==='moveto') subpathStart=cmd;
|
|
cmd.x0=prevCmd.x; cmd.y0=prevCmd.y;
|
|
for (var a in attr) if (a in cmd) cmd[a] += cmd.relative ? cmd[attr[a]] : 0;
|
|
if (!('x' in cmd)) cmd.x = prevCmd.x; // V
|
|
if (!('y' in cmd)) cmd.y = prevCmd.y; // X
|
|
cmd.relative = false;
|
|
cmd.code = cmd.code.toUpperCase();
|
|
if (cmd.command=='closepath') {
|
|
cmd.x = subpathStart.x;
|
|
cmd.y = subpathStart.y;
|
|
}
|
|
prevCmd = cmd;
|
|
});
|
|
return commands;
|
|
}
|
|
|