Help with quick python script!
Fernando Díaz
Posts: 133
Hi everyone,
I'm in need of help, I'm using Flab 6-7 and need to automatically set the starting point in several glyphs and their masters.
There is an option in "contours"–"set starting point" but if i have to do it one by one I'll take forever.
Does anyone have a script for this?
Do scripts actually work in Flab 6-7? I had several crashes
Thank you!
I'm in need of help, I'm using Flab 6-7 and need to automatically set the starting point in several glyphs and their masters.
There is an option in "contours"–"set starting point" but if i have to do it one by one I'll take forever.
Does anyone have a script for this?
Do scripts actually work in Flab 6-7? I had several crashes
Thank you!
0
Comments
-
Found a way to do it without a script!!!
Either way, if anyone can tell me if there is a python for typography course I would be thankful.0 -
Don't know how to call FL SetStartPoint function from script, but you can try this:
import fontlab as fl import math for glyph in fl.CurrentFont().glyphs: for layer in fl.flGlyph(glyph).layers: for contour in layer.getContours(): bbox = contour.boundingBox() dist = lambda pt: math.sqrt( (bbox.x() - pt.x) ** 2 + (bbox.y() - pt.y) ** 2 ) nodes = [ (index, node) for index, node in enumerate(contour.nodes()) if node.type == "on" ] start_index = sorted( [(index, dist(node)) for index, node in nodes], key=lambda _: _[1], )[0][0] if start_index != 0: contour.setStartPoint(start_index) fl.CurrentFont().update()
1 -
2
-
@Fernando Díaz What you are looking for is among the many functions of TypeRig, the script/add-on that is sufficiently powerful that the FontLab folks made it an optional install in the app, in FontLab 7.
I have become highly dependent on TypeRig for a number of things.
From the FL7 release notes:
“The Scripts menu has a Update / Install Scripts command. Click it to install some useful Python packages as well as TypeRig, a monumental Python extension for FontLab 7 developed independently by Vassil Kateliev. TypeRig brings some example Python scripts as well as TypeRig GUI, a large panel that lets you perform various batch operations. When you run Update / Install Scripts for the first time, you will need to restart FontLab 7 two or three times. Run the command once every few weeks to update TypeRig. Note: This functionality is experimental.”3
Categories
- All Categories
- 43 Introductions
- 3.7K Typeface Design
- 803 Font Technology
- 1K Technique and Theory
- 622 Type Business
- 444 Type Design Critiques
- 542 Type Design Software
- 30 Punchcutting
- 136 Lettering and Calligraphy
- 83 Technique and Theory
- 53 Lettering Critiques
- 485 Typography
- 303 History of Typography
- 114 Education
- 68 Resources
- 499 Announcements
- 80 Events
- 105 Job Postings
- 148 Type Releases
- 165 Miscellaneous News
- 270 About TypeDrawers
- 53 TypeDrawers Announcements
- 116 Suggestions and Bug Reports