Created
August 5, 2016 02:29
-
-
Save ten-A/c80a36ad9f62f3b5b949e0a607e73191 to your computer and use it in GitHub Desktop.
Illustrator's path -> Type2Charstring array.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function pathExamine(tg) { | |
var baseline = 120; //global preset | |
var stck = []; | |
var crnt = [] | |
stck.push(Math.round(tg.pathPoints[0].anchor[0])); | |
stck.push(Math.round(tg.pathPoints[0].anchor[1]+1000 -baseline)); | |
var prv = stck; | |
stck.push("rmoveto"); | |
for (var i=0;i<tg.pathPoints.length;i++){ | |
crnt = [Math.round(tg.pathPoints[i].rightDirection[0]), | |
Math.round(tg.pathPoints[i].rightDirection[1]+1000 -baseline)]; | |
stck.push(crnt[0] - prv[0]); | |
stck.push(crnt[1] - prv[1]); | |
prv = crnt; | |
if (i==tg.pathPoints.length-1){ | |
crnt = [Math.round(tg.pathPoints[0].leftDirection[0]), | |
Math.round(tg.pathPoints[0].leftDirection[1]+1000 -baseline)]; | |
stck.push(crnt[0] - prv[0]); | |
stck.push(crnt[1] - prv[1]); | |
prv = crnt; | |
crnt = [Math.round(tg.pathPoints[0].anchor[0]), | |
Math.round(tg.pathPoints[0].anchor[1]+1000 -baseline)]; | |
stck.push(crnt[0] - prv[0]); | |
stck.push(crnt[1] - prv[1]); | |
stck.push("rrcurveto"); | |
stck.push("endchar"); | |
} | |
else { | |
crnt = [Math.round(tg.pathPoints[i+1].leftDirection[0]), | |
Math.round(tg.pathPoints[i+1].leftDirection[1]+1000 -baseline)]; | |
stck.push(crnt[0] - prv[0]); | |
stck.push(crnt[1] - prv[1]); | |
prv = crnt; | |
crnt = [Math.round(tg.pathPoints[i+1].anchor[0]), | |
Math.round(tg.pathPoints[i+1].anchor[1]+1000 -baseline)]; | |
stck.push(crnt[0] - prv[0]); | |
stck.push(crnt[1] - prv[1]); | |
stck.push("rrcurveto"); | |
prv = crnt; | |
} | |
} | |
return stck; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Give a target PathItem and call it. You can get Type2Charstring array.