basiljs / basil.js

An attempt to port the spirit of the Processing visualization language to Adobe Indesign.
http://basiljs.ch/
Other
246 stars 30 forks source link

createOutlines + points() #265

Open ffd8 opened 6 years ago

ffd8 commented 6 years ago

Working on a function similar to P5's Geomerative, for returning a 2D array of the points within their paths (similar to getPointsInPath example) from a textFrame. This function wouldn't actually touch the type, it would work with a duplicate to just return this array/object of the coordinates for doing other fancy things to. Thought of using getOutlines(obj) or getPointPaths(obj) (paying homage to Geomerative) or __. But we don't have functions that involve get...

Hmm actually it should probably be points(obj) and also accept any form, not just textframes (which it would createOutlines() of if necessary)...

Semantics semantics.. any suggestions?

There's already obj.createOutlines() in the API, but should we have a simple wrapper in basiljs style, createOutlines(obj, false) (optional 2nd param if it should trash the original text or not (default is true by API).

trych commented 6 years ago

Hey @ffd8, I sure like the idea, just a quick heads up, we already had collected some thoughts about this back here: #100.

For me this sounds a bit like to different functions, one which returns the outlines for you and another one which returns the points only. Right?

ffd8 commented 6 years ago

Riight, so yeah, that solves the proposed wrapper.. although I'd suggest we call it createOutlines() to be consistent with the naming in InDesign. Also as @fabianmoronzirfas pointed out, the default behavior for deleting the original text is true. I'd now vote for it just being an optional second param, where one can write 'false' if they don't want their text deleted. But whenever one does it via the GUI, it deletes the text, so I'm sure it will rarely be used and therefore only need the single param of what object.

And yeah, two different functions. One just converts to outlines, the other will deal with giving an array of points for a given item. Working on the points() function now to detect type vs not type items being passed.

trych commented 6 years ago

Why does there need to be a difference between type and none-type objects? Should it not work the same, no matter if I pass a textframe or an ellipse?

ffd8 commented 6 years ago

I wanted to be able to send live type (still editable), but get the points, so weird things could be done without losing that active type layer. It will create a duplicate that gets trashed, so that it just gives back the coordinates and doesn't generate any new shapes.

trych commented 6 years ago

Yes, but should the same not also work for ellipses and such? So it would create a duplicate of the ellipse that gets trashed, gives back the coordinates but keeps the original ellipse to be able to live edit that later. So I think the behavior should be the same, no matter if you feed the function an ellipse or a text frame. Or am I misunderstanding something?

ffd8 commented 6 years ago

Sorry.. I'm probably not making much sense.. function started off by just being meant for type - which meant that it needed to duplicate the textframe, createOutlines(), grab all coords, then trash the outline, so you just got the array of coordinates. But realized it would also be useful to use the same function to pass odd vertex shapes and get all the points for connecting dots/etc. If sending any item into such a function, it needs to tell if it's type and if so, createOutlines – otherwise, just spit back the array of pathPoints.

Unfortunately it's not going to be so fancy for anything curved.. ellipses included.. since an ellipse returns just 4 points due to beziers.. gotta research if there's something like 'addpoints' that illustrator has to make it more complex and more fun to play with. Any ideas?

trych commented 6 years ago

I seem to remember you can retrieve something like the left anchor and right anchor of each path point for outlines, so you should be able to recreate bezier curves as well. I remember it was really fiddly to get it right as you have nested objects and then an array in an array in an array, but I think it should work.