-
Notifications
You must be signed in to change notification settings - Fork 2
/
figuring-out-fontforge-pythons-representation-of-postscript-curves.html
370 lines (263 loc) · 21.4 KB
/
figuring-out-fontforge-pythons-representation-of-postscript-curves.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=510">
<link rel="stylesheet" href="/and/style/in/reset.css" type="text/css" />
<link rel="stylesheet" href="/and/style/in/grid.css" type="text/css" />
<link rel="stylesheet" type="text/css" href="/and/style/in/tellyou.css" />
<link rel="start" href="/and/" title="Home" />
<link rel="alternate" type="application/atom+xml" title="Recent Entries" href="/and/feed/us/recent_entries.xml" />
<script type="text/javascript" src="/and/scripts/being/jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="/and/scripts/being/scripts.js"></script>
<title>I like tight pants and figuring out fontforge-python’s representation of postscript curves</title>
<meta property="og:title dc:title" content="I like tight pants and figuring out fontforge-python’s representation of postscript curves"/>
<meta property="og:type" content="article"/>
<meta property="og:url" content="http://i.liketightpants.net/and/figuring-out-fontforge-pythons-representation-of-postscript-curves"/>
<meta property="og:image" content="http://i.liketightpants.net/and/assets/scaled/to/830/wide/and/called/i_like_tightpants_and_figuring_out_fontforge_pythons_representation_of_postscript_curves.jpg"/>
<meta property="og:site_name" content="I like tight pants and mathematics"/>
<meta property="og:description dc:description"
content="A young man poses to the right of a whiteboard on which is constructed a path of curves and lines."/>
<meta name="description"
content="A young man poses to the right of a whiteboard on which is constructed a path of curves and lines."/>
<meta property="fb:admins" content="1488294875"/>
<meta property="mt:entry_basename" content="figuring-out-fontforge-pythons-representation-of-postscript-curves" />
<meta property="dc:modified" content="2012-12-25T22:55:28" />
</head>
<body>
<div id="header" class="container_7">
<div class="grid_2">
<h1><a href="/and/">i . like tight pants . net</a></h1>
</div>
<div class="grid_3">
<ul>
<li ><a href="/and/hybrid-publishing-back-to-the-future-publishing-theses-at-the-kabk">latest</a></li>
<li><a href="/and/about">about</a></li>
<li ><a href="/and/archives">index</a></li>
</ul>
</div>
<div class="grid_2">
<p class="byline" id="recent_entries">New entries published Monday and Thursday, 22:00 CET (<a href="/and/feed/us/recent_entries.xml">RSS</a>)</p>
</div>
</div>
<div id="content" class="container_7">
<div class="sidebar grid_1">
<img src="/and/assets/that/are/pictures/of/author/tellyou.png" style="width:100px;height:100px;" alt="" />
<h4 class="author" property="dc:created" content="2012-06-03T15:06:30">June 3, 2012</h4>
<h4 class="author">by <span property="dc:creator">tellyou</span></h4>
<p> </p>
<hr />
<h4>Other articles by tellyou</h4>
<dl>
<dt><a href="/and/hybrid-publishing-back-to-the-future-publishing-theses-at-the-kabk">Hybrid Publishing Back To The Future Publishing Theses at the KABK</a></dt>
<dd>May 10, 2018 10:07 AM</dd>
<dt><a href="/and/the-underwater-screen-or-lessons-from-wordperfect">The Underwater Screen Or Lessons From Wordperfect </a></dt>
<dd>June 10, 2014 6:21 PM</dd>
<dt><a href="/and/graphic-design-is-a-nostalgic-field"> Graphic Design Is A Nostalgic Field </a></dt>
<dd>February 19, 2014 7:02 PM</dd>
<dt><a href="/and/release-early-release-often-version-numbers-for-typefaces">Release Early Release Often Version Numbers For Typefaces</a></dt>
<dd>September 25, 2013 7:53 PM</dd>
<dt><a href="/and/the-story-of-nokia-microsoft-and-a-1000-hearts-breaking">The Story of Nokia, Microsoft and a 1000 Hearts Breaking</a></dt>
<dd>September 4, 2013 8:02 PM</dd>
<dt><a href="/and/etherpad-or-the-textarea-is-a-lonely-place">Etherpad Or The Textarea Is A Lonely Place</a></dt>
<dd>April 22, 2013 7:59 PM</dd>
<dt><a href="/and/how-it-has-come-about-that-code-hosting-site-github-offers-visualisations-of-typeface-development">How it Has Come About That Code Hosting Site Github Offers Visualisations of Typeface Development</a></dt>
<dd>August 4, 2012 7:28 PM</dd>
<dt><a href="/and/my-favourite-wikipedia-user-user-rama">My Favourite Wikipedia User User:Rama</a></dt>
<dd>February 23, 2012 10:43 PM</dd>
<dt><a href="/and/making-unix-programs">Making unix programs</a></dt>
<dd>February 2, 2012 12:33 PM</dd>
<dt><a href="/and/installing-compilers">Installing compilers</a></dt>
<dd>December 1, 2011 2:13 PM</dd>
<dt><a href="/and/we-like-tight-pants-and-mathematics">We like tight pants and mathematics</a></dt>
<dd>November 23, 2011 9:27 AM</dd>
<dt><a href="/and/the-voice-of-the-shell">The voice of the shell</a></dt>
<dd>October 26, 2011 7:20 PM</dd>
<dt><a href="/and/learning-how-to-program">Learning how to program</a></dt>
<dd>August 11, 2011 9:04 AM</dd>
<dt><a href="/and/honest-artist-statements">Honest artist statements</a></dt>
<dd>July 9, 2010 4:15 PM</dd>
<dt><a href="/and/juxtapositions">Juxtapositions</a></dt>
<dd>March 14, 2010 8:32 PM</dd>
<dt><a href="/and/heroes">Heroes</a></dt>
<dd>March 8, 2010 7:06 PM</dd>
</dl>
<h4>tellyou’s comments</h4>
<ul>
<li>Hey Silvio, thanks for your comment. Coincidentally, Ned’s comment higher ... <a href="/and/hackers-culture-and-the-fear-of-wysiwyg#comment-319" title="full comment on: Hacker Culture and the Fear of WYSIWYG">read more</a></li>
<li>There is weird paradox here: When learning programming with Python, ... <a href="/and/48-hours-of-writing-stylesheets-with-etherpad-and-a-gong#comment-265" title="full comment on: 48 Hours of Writing Stylesheets with Etherpad and a Gong">read more</a></li>
<li>There is weird paradox here: When learning programming with Python, ... <a href="/and/48-hours-of-writing-stylesheets-with-etherpad-and-a-gong#comment-264" title="full comment on: 48 Hours of Writing Stylesheets with Etherpad and a Gong">read more</a></li>
<li>What do you do with that script? Where does it ... <a href="/and/48-hours-of-writing-stylesheets-with-etherpad-and-a-gong#comment-262" title="full comment on: 48 Hours of Writing Stylesheets with Etherpad and a Gong">read more</a></li>
<li>For the webfonts, ufo2otf will automatically perform a number of ... <a href="/and/ufo2otf-makes-otfs-webfonts-and-css-from-ufo#comment-260" title="full comment on: ufo2otf Makes OTF’s, Webfonts and CSS From UFO’s">read more</a></li>
<li>Isn’t one of the reasons for the small number of ... <a href="/and/no-one-starts-from-scratch-type-design-and-the-logic-of-the-fork#comment-249" title="full comment on: No-one Starts From Scratch: Type Design and the Logic of the Fork">read more</a></li>
<li>I like how Martin Majoor and Ben Archer use the ... <a href="/and/no-one-starts-from-scratch-type-design-and-the-logic-of-the-fork#comment-246" title="full comment on: No-one Starts From Scratch: Type Design and the Logic of the Fork">read more</a></li>
<li>You are on the trolly side of life today, bnf <a href="/and/i-need-my-generic-font-medicine#comment-244" title="full comment on: I Need My Generic Font Medicine">read more</a></li>
<li>And how did you make the video? <a href="/and/48-hours-of-writing-stylesheets-with-etherpad-and-a-gong#comment-224" title="full comment on: 48 Hours of Writing Stylesheets with Etherpad and a Gong">read more</a></li>
<li>So if you were all writing these styles on an ... <a href="/and/48-hours-of-writing-stylesheets-with-etherpad-and-a-gong#comment-222" title="full comment on: 48 Hours of Writing Stylesheets with Etherpad and a Gong">read more</a></li>
</ul>
<hr />
<h4>Other writers</h4>
<ul>
<li>glit</li>
<li>jenseits</li>
<li>habitus</li>
<li>tellyou</li>
<li>baseline</li>
<li>bnf</li>
</ul>
</div>
<div class="post grid_5">
<p class="byline">
<a href="/and/programmatically-manipulating-typefaces">Previous</a>
/ <a href="/and/hybrid-publishing-back-to-the-future-publishing-theses-at-the-kabk">Next</a>
</p>
<div class="article grid_3 alpha omega suffix_2">
<h4 property="mt:entry_title">Figuring Out Fontforge-Python’s Representation of Postscript Curves</h4>
<article property="mt:entry_id" content="51" class="entry" id="entry-51">
<p><a href="/and/assets/called/i_like_tightpants_and_figuring_out_fontforge_pythons_representation_of_postscript_curves_2.jpg">
<img src="/and/assets/scaled/to/830/wide/and/called/i_like_tightpants_and_figuring_out_fontforge_pythons_representation_of_postscript_curves_2.jpg" style="width:830;height:555;" alt="You see a young man posing to the right of a whiteboard, looking into the camera. He holds a marker in his right hand as if he is writing, his right foot is planted on the whiteboards horizontal support. He wears black leggings and a salmon pink sleeveless t-shirt. On the whiteboard is constructed a path of curves and lines, showing also the bézier control points. All the points are marked either offCurve or onCurve." title="" />
</a></p>
<p class="byline">At the OSP workshop <a href="http://osp.schr.fr/workshop/write-me-a-shadow/raw/latest/specimen/index.html" title="Write me a shadow. OSP @ ESAD Valence">Write me a shadow</a>, ESAD Valence (FR)</p>
<p>When <a href="http://www.ludi.be/" title="ludi">Ludi</a> and me prepare for a workshop on Open Source typography in Valence, we put together a batch of Python scripts for Fontforge. Among which a port of <a href="http://i.liketightpants.net/and/programmatically-manipulating-typefaces#comment-168" title="I like tight pants and programmatically manipulating typefaces">the script</a> that John and me made in Robofab for a previous workshop, that straightens curves by removing the bézier handles.</p>
<p>Internally, many typefaces are constructed with PostScript, which can be seen as a set of drawing instructions to an imaginary pen.</p>
<p>Postscript has three basic drawing instructions:<br /><em>moveto(x, y)</em>: move the pen to this point to start drawing a path<br /><em>lineto(x,y)</em>: draw a line from the previous point to the point x,y<br /><em>curveto(x1,y1,x2,y2,x3,y3)</em>: draw a curve from the previous point to the point x3,y3, using x1,y1 and x2,y2 as bézier handles, off curve points that control the shape of the curve.</p>
<p>It turns out that Fontforge-Python represents PostScript contours as a set of points. Fair enough. The points have a type property, which can be either onCurve or offCurve. So like in the Robofab script, we first try to remove all the offCurve points.</p>
<p>This turns out to be too radical: a lot more points are removed then seems necessary. Prince Charmant <a href="http://www.oep-h.com/" title="OEP-H">Pierre Marchand</a> to the rescue. It turns out that points that are normally created as part of a lineto, are also called offCurve by FontForge, even if they are strictly speaking neither on or off a curve.</p>
<p>So, how to keep the points called offCurve that are actually part of the contours, and throw away the others? We know that if a point is onCurve, it will always be followed y two control points (offCurve). So instead of checking for offCurves, we simply skip the next two points every time we encounter an onCurve.</p>
<p>Like this:</p>
<pre>font = fontforge.activeFont()
for glyph in font.glyphs():
new_contours = []
for contour in glyph.layers[1]:
new_contour = []
i = 0
while i < len(contour):
p = contour[i]
if p.on_curve:
i += 2
new_contour.append((p.x, p.y))
i += 1
new_contours.append(new_contour)
pen = glyph.glyphPen()
for to_draw in new_contours:
pen.moveTo(to_draw[0])
for i in to_draw[1:]:
pen.lineTo(i)
pen.closePath()</pre>
<p>This won’t work, by the way, if you are dealing with TrueType curves. But that’s a different story altogether.</p>
</article>
<h4 class="comments-header">No Comments</h4>
<div id="comments" class="comments">
<div class="comments-content">
<a title="Reply" href="#reply">Reply</a>
</div>
<div class="comments-open" id="comments-open">
<h4 class="comments-open-header">Leave a comment</h4>
<div class="comments-open-content">
<div id="comment-greeting"></div>
<form method="post" action="/comments.cgi">
<input type='hidden' name='csrfmiddlewaretoken' value='1OjGJ903ORE7yiiu7NzgDDkPHt7R1jg4' />
<input id="id_parent" name="parent" type="hidden" />
<input id="id_entry" name="entry" type="hidden" value="51" />
<div id="comments-open-data">
<div id="comment-form-name">
<div class="alpha grid_1"><label for="id_author" class="span-4">Name</label></div>
<div class="omega grid_2"><input id="id_author" maxlength="300" name="author" required="required" size="30" type="text" /></div>
</div>
<div id="comment-form-email">
<div class="alpha grid_1"><label for="id_email" class="span-4">Email address</label></div>
<div class="omega grid_2"><input id="id_email" maxlength="381" name="email" required="required" size="30" type="email" /></div>
</div>
<div id="comment-form-url">
<div class="alpha grid_1"><label for="id_url" class="span-4">URL</label></div>
<div class="omega grid_2"><input id="id_url" maxlength="765" name="url" size="30" type="url" /></div>
</div>
</div>
<div id="comment-form-reply" style="display:none">
<input type="checkbox" id="comment-reply" name="comment_reply" value="" onclick="mtSetCommentParentID()" />
<label for="comment-reply" id="comment-reply-label"></label>
</div>
<div id="comments-open-text">
<label for="id_text">Text:</label><br />
<p class="byline">For formatting your post, you can use html tags like <p> and <br />. Whitespace for now is eaten up, like in HTML. we are sorry—we will have a more friendly commenting option in place shortly!</p>
<textarea cols="40" id="id_text" name="text" required="required" rows="15" style="width:100%">
</textarea>
<!-- <textarea id="comment-text" name="text" rows="15" style="width:100%;" onfocus="mtCommentFormOnFocus()"></textarea> -->
</div>
<p class="byline" id="comments-open-license">By submitting your comment, you agree to license it under the <a href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution Share-Alike license</a>, the same license used for the text of the blog.</p>
<div id="comments-open-captcha">
<div class="alpha grid_1"><label for="id_captcha_code">Anti-spam: What is the last name of David?</label></div>
<div class="omega grid_2"><input id="id_captcha_code" name="captcha_code" required="required" size="30" type="text" /></div>
</div>
<div id="comments-open-footer">
<!-- <input type="submit" accesskey="v" name="preview_button" id="comment-preview" value="Preview" onclick="this.form.preview.value='1';" /> -->
<input type="submit" accesskey="s" name="post" id="comment-submit" value="Submit" />
</div>
</form>
</form>
</div>
</div>
</div><!-- / comments -->
</div> <!-- / article grid_3 -->
<hr />
</div> <!-- / post grid_5-->
<div class="sidebar grid_1">
<h4>Latest articles</h4>
<dl>
<dt><a href="/and/hybrid-publishing-back-to-the-future-publishing-theses-at-the-kabk">Hybrid Publishing Back To The Future Publishing Theses at the KABK</a></dt>
<dd>May 10, 2018 10:07 AM</dd>
<dt><a href="/and/finding-red-letterboxes-in-belgium">Finding Red Letterboxes In Belgium</a></dt>
<dd>May 10, 2018 10:05 AM</dd>
<dt><a href="/and/the-underwater-screen-or-lessons-from-wordperfect">The Underwater Screen Or Lessons From Wordperfect </a></dt>
<dd>June 10, 2014 6:21 PM</dd>
<dt><a href="/and/hackers-culture-and-the-fear-of-wysiwyg">Hacker Culture and the Fear of WYSIWYG</a></dt>
<dd>May 22, 2014 11:40 PM</dd>
<dt><a href="/and/graphic-design-is-a-nostalgic-field"> Graphic Design Is A Nostalgic Field </a></dt>
<dd>February 19, 2014 7:02 PM</dd>
<dt><a href="/and/who-makes-standards">Who gets to write the web: the power struggles around the standards</a></dt>
<dd>November 20, 2013 9:08 PM</dd>
<dt><a href="/and/ufo2otf-makes-otfs-webfonts-and-css-from-ufo">ufo2otf Makes OTF’s, Webfonts and CSS From UFO’s</a></dt>
<dd>November 5, 2013 8:57 PM</dd>
<dt><a href="/and/no-one-starts-from-scratch-type-design-and-the-logic-of-the-fork">No-one Starts From Scratch: Type Design and the Logic of the Fork</a></dt>
<dd>October 9, 2013 8 PM</dd>
<dt><a href="/and/i-need-my-generic-font-medicine">I Need My Generic Font Medicine</a></dt>
<dd>October 9, 2013 7:55 PM</dd>
<dt><a href="/and/48-hours-of-writing-stylesheets-with-etherpad-and-a-gong">48 Hours of Writing Stylesheets with Etherpad and a Gong</a></dt>
<dd>October 8, 2013 8:06 PM</dd>
</dl>
<h4>Latest Comments</h4>
<ul>
<li><strong>Sujon Ahmad:</strong> Keep it up <a href="/and/release-early-release-often-version-numbers-for-typefaces#comment-338" title="full comment on: Release Early Release Often Version Numbers For Typefaces">read more</a></li>
<li><strong>Carly Durocher:</strong> I really like the stylized penrose triangle would you mind ... <a href="/and/illustration#comment-337" title="full comment on: Illustration">read more</a></li>
<li><strong>michaël:</strong> The recent evolution of MediaWiki is worth mentioning. One of ... <a href="/and/hackers-culture-and-the-fear-of-wysiwyg#comment-336" title="full comment on: Hacker Culture and the Fear of WYSIWYG">read more</a></li>
<li><strong>jaromil:</strong> Check the Linux Action Show on Tomb https://www.dyne.org/software/tomb there can ... <a href="/and/hackers-culture-and-the-fear-of-wysiwyg#comment-335" title="full comment on: Hacker Culture and the Fear of WYSIWYG">read more</a></li>
<li><strong>Ian Hickson:</strong> The member list is the one on the charter (it's ... <a href="/and/who-makes-standards#comment-334" title="full comment on: Who gets to write the web: the power struggles around the standards">read more</a></li>
<li><strong>habitus:</strong> Dear Ian, thank you for taking the time to respond. ... <a href="/and/who-makes-standards#comment-333" title="full comment on: Who gets to write the web: the power struggles around the standards">read more</a></li>
<li><strong>Ian Hickson:</strong> The part about the WHATWG membership is wrong. The WHATWG ... <a href="/and/who-makes-standards#comment-332" title="full comment on: Who gets to write the web: the power struggles around the standards">read more</a></li>
<li><strong>Erik:</strong> Good points. Also: writing UI is hard. <a href="/and/the-underwater-screen-or-lessons-from-wordperfect#comment-327" title="full comment on: The Underwater Screen Or Lessons From Wordperfect ">read more</a></li>
<li><strong>nike shox:</strong> do not want to be t basket vans femme pas ... <a href="/and/no-one-starts-from-scratch-type-design-and-the-logic-of-the-fork#comment-324" title="full comment on: No-one Starts From Scratch: Type Design and the Logic of the Fork">read more</a></li>
<li><strong>Tolan Blundell:</strong> As someone who's written a moderately complex CMS from scratch ... <a href="/and/hackers-culture-and-the-fear-of-wysiwyg#comment-323" title="full comment on: Hacker Culture and the Fear of WYSIWYG">read more</a></li>
</ul>
</div>
</div>
<div id="bar"> </div>
<!-- Piwik, Open Source Analytics,
let’s not give Google more data then necessary! Eric -->
<script type="text/javascript">
var pkBaseURL = (("https:" == document.location.protocol) ? "https://var.schr.fr/piwik/" : "http://var.schr.fr/piwik/");
document.write(unescape("%3Cscript src='" + pkBaseURL + "piwik.js' type='text/javascript'%3E%3C/script%3E"));
</script><script type="text/javascript">
try {
var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", 2);
piwikTracker.trackPageView();
piwikTracker.enableLinkTracking();
} catch( err ) {}
</script><noscript><p><img src="http://var.schr.fr/piwik/piwik.php?idsite=2" style="border:0" alt="" /></p></noscript>
<!-- End Piwik Tracking Code -->
<!--[if !(lt IE 8)]><!-->
<script type="text/javascript">
(function(){var e=document.createElement("script");e.type="text/javascript";e.async=true;e.src=document.location.protocol+"//d1agz031tafz8n.cloudfront.net/thedaywefightback.js/widget.min.js";var t=document.getElementsByTagName("script")[0];t.parentNode.insertBefore(e,t)})()
</script>
<!--<![endif]-->
</body>
</html>