Draw paths in FontLab’s glyph window canvas?

Primary tabs

11 posts / 0 new
Last post
Yanone's picture
Offline
Joined: 11 Dec 2007 - 3:19am
Draw paths in FontLab’s glyph window canvas?
0

Hi everyone,

I’m trying to put FontLab’s super weak implementation of drawing things onto the glyph window canvas to some use. Y’now, the one that disappears once you move a toolbar over it or switch to another window or app.

More specifically, I want to draw a path using a couple of LineTo-commands, but there seems to be no ClosePath implemented, or at least it’s not documented anywhere. So how do I close such a path to get a solid shape?

And once we’re at it: Can one set drawing colors other than using the seven constants? They return integer values between 0 (black) and 16M (white), so could one set anything in between?
Edit: I tried: yes one can.

Thank you,
Yanone


canvas = fl.GetCanvas()
canvas.MoveTo(here)
canvas.LineTo(there)
canvas.LineTo(over there)
# now what??

Andreas Eigendorf's picture
Joined: 2 Sep 2006 - 4:12am
0

Hello Yanone,

You can build a temporary glyph and use this glyph with the canvas.OutlineGlyph() or canvas.FillGlyph() method to draw on the canvas.

Does this help?

Regards

Eigi

Andreas Eigendorf's picture
Joined: 2 Sep 2006 - 4:12am
0

Hello Yanone,

Regarding the colors:

You can use the FontLab build-in function RGB() to calculate the color values.
It is defined in Studio5/Macros/System/init.py and looks like this:


def RGB(r, g, b):
    return long(r) | (long(g) << 8) | (b << 16)

Yanone's picture
Offline
Joined: 11 Dec 2007 - 3:19am
0


def RGB(r, g, b):
return long(r) | (long(g) << 8) | (b << 16)

Nice. I’ve been looking for this for a while on the net, but only found the reverse Integer to RGB conversion. Thank you.
But the b requires another long(), right?

You can build a temporary glyph and use this glyph with the canvas.OutlineGlyph() or canvas.FillGlyph() method to draw on the canvas.

I just tested that successfully with existing glyphs. I guess that constructing a glyph with my wanted path would work. But I couldn’t get to apply a color as opposed to the previously used single lines. Neither pen_color nor brush_color changed the fill color away from black. If it’s not possible to change the color, I might want to stick with the lines.

Anton's picture
Offline
Joined: 14 May 2010 - 2:27pm
0

hi Yanone,
if i would start messing with canvas i would look into these 2 Tool scripts.
Probably you know both.
Erik's "measure glyph" has supernice colors and neat curves.
http://groups.google.com/group/robofab/browse_thread/thread/9f1e292498d5...

Gustavo's Pixelbrush draws filled shapes.
https://github.com/gferreira/PixelBrush

Theres one modification of that one by F.Berlaen, with stiches instead of boxes. Unfortunately on FL canvas it draws still rectangles (once i tried to make triangles, as well didnt work out to change the preview).
Please update us. Post your tipps if you have any success with canvas.

cheers,
Anton

Anton's picture
Offline
Joined: 14 May 2010 - 2:27pm
0

Hi, oh i found it!

I wrote this script to draw simple straight segment on FL canvas. For segments, curves and such... need to add few more lines. Basically FL canvas has no line thickness and no propper fill. So my solution: lets plot the image with geometric shapes that Fontlab supports. Rect and Ellipse. It runs instantly, thus: why not?

http://anton.korkork.com/tech_work/scripts/Draw_Thick_line.py

Hope this helps.

Anton
*Comments to improve are welcome. For example if i click on cavas my image disapears, in some other scripts it doesnt disappear so fast. I think it has to do with the code structure.

Yanone's picture
Offline
Joined: 11 Dec 2007 - 3:19am
0

Hi Anton,

thanks for hinting to the two tools, both of which I didn't know yet, and yours.
But neither helps. Yours and Gustavo's draw rectangles, Erik's draws curves. I need a way to draw an arbitrary path, a polygon (I don't have curves for now).
So the way I see it the only way to draw that is to iterate through the whole canvas using a Point In Polygon function or RoboFab's PointInside and draw one-pixel big Rectangles.
But I tried. It drew one shape in several minutes, so that's kind of beyond reason.
Looks like I might have to stick with the unfilled lines.

Yanone's picture
Offline
Joined: 11 Dec 2007 - 3:19am
0

Come on, guys. I just cannot believe that you implemented moveTo, lineTo and curveTo, but forgot the closePath. I'm not even asking for smooth outlines, just for the closePath. #fail

Yanone's picture
Offline
Joined: 11 Dec 2007 - 3:19am
0

Just in case somebody needs it, I found this on the web:
http://www.ariel.com.au/a/python-point-int-poly.html

I cannot post the code here, the indentation get's screwed.

Yanone's picture
Offline
Joined: 11 Dec 2007 - 3:19am
0

Using a function to calculate the bounding box of a polygon prior to iterting through the canvas, I was able to speed up the process to an extent where I can now sit in front of the screen and watch the pixels draw (e.g. Blinkenlights). It now takes only 427 seconds (more than 7 minutes) to draw my outlines. The result is a piece of computer art that seems to come straight out of a time machine. Almost performance art!

Andreas Eigendorf's picture
Joined: 2 Sep 2006 - 4:12am
0

Hi Yanone,

This is "von hinten durch die Brust ins Auge" but it may work.

You can draw with a 'ReportLabPen' from FontTools (works also with robofab) to create a reportlab.graphics.shapes.Group. Then render this vector graphic with reportlab.graphics.renderPM.drawToPIL() to an image. Finaly paste this image with the FontLab Canvas.PutImage() method into your canvas.

Eigi