A FontForge plug-in to harmonize or tunnify (balance) or add inflection points to the selected part
Linus Romer
Posts: 187
While working on my type family Elemaints, I have written several scripts that enhance the capabilities of FontForge. On https://github.com/linusromer/harmonize-tunnify-inflection I have published some of these tools, as you might find them useful too, if you are using FontForge.
4
Comments
-
@Linus Romer WOW ! That's very good news. I have spent so much time to add inflection points to my FF drawings. Thanks you so much !
0 -
@Linus Romer very useful tool, first of all inflection points!btw. if I can suggest a little trick in Fontforge-Python that I discovered too late, because it is useful. You can avoid the definitions of
harmonize_contours, harmonize_handles_contours, tunnify_contours, inflection_contours, harmonize_glyphs, harmonize_handles_glyphs, tunnify_glyphs, inflection_glyphs
and use "junk" variable. Instead of:
You can directly<code>
fontforge.registerMenuItem(harmonize_glyphs,are_glyphs_selected,None,"Font",None,"Harmonize");
...
...<br>def modify_glyphs(junk,font,action):<br>...<br>def harmonize_glyphs(junk,font):<br> modify_glyphs(junk,font,"harmonize")<br>...<br>if fontforge.hasUserInterface():<br><div>...<br></div>def modify_glyphs(action,font):<br>...<br>if fontforge.hasUserInterface():<br> fontforge.registerMenuItem(modify_glyphs,are_glyphs_selected,"harmonize","Font",None,"Harmonize");<br>...
1 -
The user and all related content has been deleted.2
-
@Linus Romer I installed it as explained and it appears in the Tools Menu. My FF version is the last PPA for Ubuntu 18.04 . I get this error :0
-
it’s exciting to see another person coding plugins for FontForge! Honestly, I thought I was the only one for a while. None of mine are publicly available yet, though, so you’ve 1-upped me there ;-)0
-
I have updated the plugin on https://github.com/linusromer/harmonize-tunnify-inflection. The plugin no longer relies on fontforge.point() and therefore should work now with older versions of FontForge (e.g. from 2017) too.@Grzegorz Luk (gluk) Indeed, this is a cool trick, it makes the code much more compact. I have implemented the trick in the new version. Thank you for the hint!If needed I could have placed those additional points of inflection without the need of this script.
In automated processes one will still need a script in order to add points of inflection.
That point on the right side of the shape really should be at the extreme and not where it is at the moment of being "tunnified". Use your eyes!I have never claimed any of these contours to be perfect. The non-horizontal-or-vertical node on the dot contour should demonstrate that the tools will work for such nodes, too.
@ivan louette I think I have figured out what probably happend: You inserted an inflection point at the end of a contour. This led to a problem because the end node is identical with the start node. I have fixed this bug now. I hope it will work now for you.
@AbrahamLee Unfortunately, there are hardly any plugins of FontForge available. I have only found the plugin in the FontForge documentation and those of David Crossland (which were worth a lot for me because the documentation is so sparse). I am looking forward to the publication of your scripts.
0 -
@Linus Romer Thanks for the update. However now Tool menu remain greyed and I get this message :0
-
@ivan louette According to the error message I assume you have downloaded the html-file instead of the raw file. The direct link to the file (without html view) is:https://raw.githubusercontent.com/linusromer/harmonize-tunnify-inflection/master/harmonize_tunnify_inflection.py
0 -
@Linus Romer OOOOPS ! I was so silly ! Now it works like a charm on my current 2017 FF ! Thanks for your patience
0 -
@Linus Romer I downloaded the file from the link above, but...
I use Windows 8.1 and the latest an official version of FontForge.0 -
@AbrahamLee Unfortunately, there are hardly any plugins of FontForge available. I have only found the plugin in the FontForge documentation and those of David Crossland (which were worth a lot for me because the documentation is so sparse).I am looking forward to the publication of your scripts.0
-
@Stefan Peev Thanks for the note. This bug was due to the windows path "C:\Users..." in the docstring. Under Linux there were no complaints but under Windows "\U" obviously must not be contained in the docstring. I have fixed the bug and tested the new version with Windows (and it worked):0
-
@Linus Romer Thank you. Now it works for me too.0
-
I was asked if my plugin could be part of the (future) contrib scripts of FontForge. Therefore, I had to change a few things and I will release the updated plugin under a new name (because the compatibility to FontForge2017 will be broken). However, I am not sure what name will fit the plugin. At the moment, I have chosen "Curvatura" because my tools are related to curvature and "Curvatura" is understandable in many languages and "Curvatura.py" is not as overused as "Curvature.py":If you have a better name for the plugin, I would be glad to read it here.2
-
This is really interesting and useful. Any interest in doing the same for FL5?0
-
@Jeremy Dooley Unfortunately, I do not own a copy of Fontlab 5, which is a bad precondition for testing and supporting. However, if someone wants to adapt the script: Feel free to use my script (under the conditions of the GPL). For all the actions in my plugin there are low level methods that can be used 1:1 for FontLab.0
-
Thanks for the info, Linus and for your contribution to the community.1
-
Anyone want to make a quick $200 on my dime and contribute to the community?
https://www.upwork.com/ab/applicants/1219390351307173888/job-details
0 -
@Jeremy Dooley, sorry I don’t have an account at UpWork, but I’m curious to know what this is about. What’s the task?0
-
Hi @AbrahamLee, the task is to adapt the "tunnify" fontforge plugin to FL5.
0 -
Gotcha. Thanks for explaining.0
-
Looks like I posted a private URL. Here's the public listing: https://www.upwork.com/jobs/~012c24b2d860806f010
-
The first and original tunnify script was written for FontLab 5, by Andres Torresi. I wrote about this more here:
https://typedrawers.com/discussion/comment/15766/#Comment_15766
4 -
@Andres Torresi
Is this script still around? I've found your github repository, but I can't identify it. Much appreciated.0 -
Curvatura is the successor of harmonize-tunnify-inflection . Curvatura now also supports G3-continuity (see this thread).1
-
Linus,that's fantastic0
-
I created both balance and harmonize macros for Windows FontLab 5.2 a few months ago and just now published them to github. The functions for the macros are contained in an extension module which I wrote in Cython C++, which makes the macros perform much faster than if they were run as plain Python.They were created out of the need to harmonize individual curve segments without changing anything not selected, something RMX has difficulties with.The balance macro works the same way as the harmonize macro. This is a feature sadly missing from RMX.So far this particular project is still unfinished, but outside of a some edge cases, it mostly works as expected.
0 -
@Jameson R Spires Laudable that you share your macros! I hope you do not mind, if I give you a hint: The harmonize algorithm of Simon Cozens works in most of the cases but depends on finding an intersection point, which may not exist. Therefore, I use a different algorithm (with the same results in generic cases) in the latest version of curvatura: (the code environment does not work on typedrawers.com, sorry)# Returns the signed distance of the point p from the line
# starting in q and going to r. The value is positive, iff
# p is right from the line.
def side(px,py,qx,qy,rx,ry):
a, b = rx-qx, ry-qy
return ((py-qy)*a-(px-qx)*b)/(a**2+b**2)**.5
# Given two adjacent cubic bezier curves (a,b), (c,d), (e,f), (g,h)
# and (g,h), (i,j), (k,l), (m,n) that are smooth at (g,h)
# this method calculates a new point (g,h) such that
# the curves are G2-continuous in (g,h).
def harmonize_cubic(a,b,c,d,e,f,g,h,i,j,k,l,m,n):
if e==i and f==j:
return g, h # no changes
d2 = abs(side(c,d,e,f,i,j))
l2 = abs(side(k,l,e,f,i,j))
if d2 == l2: # then (g,h) is in mid between handles
return .5*(e+i), .5*(f+j)
t = (d2-(d2*l2)**.5)/(d2-l2)
return (1-t)*e+t*i, (1-t)*f+t*j<br>
T
his algorithm may be faster as well (but please check yourself). The mathematics behind are explained in https://github.com/linusromer/curvatura/blob/master/curvatura-doc.pdf. The idea behind the function `side()` is: length of the crossproduct over the length of the one vector equals the height of the spanned parallelogram.
0 -
I adapted your method above to the harmonize_curves() function in the extension module. It should be quicker due to considerably fewer calculations, but I did not measure it. Thanks for your help.
cdef double harmonize_distance(cPoint &p0, cPoint &p1, cPoint &p2) nogil:
cdef:
double i = p2.x - p1.x
double j = p2.y - p1.y
return fabs((((p0.y - p1.y) * i) - ((p0.x - p1.x) * j)) / sqrt(pow(i, 2) + pow(j, 2)))
cdef cPoint harmonize_cubic(cCurve &curve, cCurve &next_curve) nogil:
if curve.p2.x == next_curve.p1.x and curve.p2.y == next_curve.p1.y:
return curve.p3
cdef:
double d0 = harmonize_distance(curve.p1, curve.p2, next_curve.p1)
double d1 = harmonize_distance(next_curve.p2, curve.p2, next_curve.p1)
if d0 == d1:
return Point(.5 * (curve.p2.x + next_curve.p1.x), .5 * (curve.p2.y + next_curve.p1.y), 0)
cdef:
double t = (d0 - sqrt(d0 * d1)) / (d0 - d1)
double t_1 = 1 - t
return Point(t_1 * curve.p2.x + t * next_curve.p1.x, t_1 * curve.p2.y + t * next_curve.p1.y, 0)0 -
My pleasure! I see, that you have optimized abs(), which is absolutely correct in this case. I use side() for other functions as well and therefore side() does not include abs(). But after looking at your code, I think I should split side() in two functions harmonize_distance() and sideness() just as you.
0
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