/usr/share/doc/xgridfit/html/tutorial3.html is in xgridfit-doc 2.3-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Xgridfit</title>
<link rel="stylesheet" href="oeg.css" media="screen" type="text/css" />
<link rel="stylesheet" href="parchment.css" media="screen"
type="text/css" title="parchment" />
<link rel="alternate stylesheet" href="legible.css" media="screen"
type="text/css" title="legible" />
<style type="text/css" media="print"> @import "oeg.print.css"; </style>
<meta name="AUTHOR" content="Peter S. Baker" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<div id="jumplist">
<a href="http://sourceforge.net"><img src="" width="125" height="37" border="0" alt="SourceForge.net Logo" /></a>
<a href="http://xgridfit.sourceforge.net/">Home Page</a>
<a href="http://sourceforge.net/projects/xgridfit">Project Page</a>
<a href="http://sourceforge.net/project/showfiles.php?group_id=159705">Download</a>
<a href="http://xgridfit.cvs.sourceforge.net/xgridfit/xgridfit/">CVS repository</a>
</div>
<div id="content">
<h1>Tutorial 3: Working with FontForge auto-instructions</h1>
<p>
The easiest way to invoke the FontForge auto-instructor in the
context of an Xgridfit program is
with <a href="merge-mode.html">merge-mode</a>. It is also possible
to copy and revise instructions generated by the auto-instructor.
Here is a practical example drawn
from <a href="http://junicode.sourceforge.net">Junicode
Regular</a>, in which <b>b</b> is instructed "by hand,"
while <b>uni0180</b> (<b>bbar</b>) has been auto-instructed.
</p>
<p>
Although the outlines of <b>b</b> and <b>uni0180</b> are exactly the
same except for the bar, the instructed versions of these glyphs
look rather different at 20 ppem:
</p>
<table>
<tr>
<td>
<img alt="hand-instructed b" src="b-hinted.png"/>
</td>
<td>
<img alt="bbar auto-instructed" src="bbar-hinted.png"/>
</td>
</tr>
</table>
<p>
There are various subtle differences here, but the obvious ones
are that the top of the bowl is thicker and higher in <b>uni0180</b>
than in <b>b</b> and that <b>uni0180</b> is narrower. If we can
change these things, the two glyphs will match reasonably well.
</p>
<p>
The first step is to get a copy of the program for <b>uni0180</b>.
The easiest way to do so is to run a little Xgridfit utility,
<tt>getinstrs</tt>, against a .ttf or .sfd file containing the
glyph with its instructions (the <tt>--xgridfit</tt> option
ensures that we end up with a complete, valid Xgridfit file):
</p>
<pre>
getinstrs --xgridfit Junicode-Regular.ttf uni0180 > uni0180.xgf</pre>
<p>
Now we're ready to edit the instructions. Here is the program, in
which we have identified the problem areas by running the
FontForge TrueType debugger. We've inserted comments to mark the
places:
</p>
<pre>
<?xml version="1.0"?>
<xgridfit xmlns="http://xgridfit.sourceforge.net/Xgridfit2">
<glyph ps-name="uni0180" xml:id="uni0180" init-graphics="no">
<command name="SVTCA" modifier="y-axis"/>
<push>3 1 0</push>
<command name="CALL"/>
<push>9</push>
<command name="SHP" modifier="rp1"/>
<push>60</push>
<command name="MDRP" modifier="min,rnd,black"/>
<push>27 3 0</push>
<command name="CALL"/>
<push>24</push>
<command name="MDRP" modifier="min,rnd,black"/>
<push>27 24 10</push>
<command name="CALL"/>
<push>64 27 31 9</push>
<command name="CALL"/>
<b><!-- top of bowl --></b>
<push>42 52 3 31 13</push>
<command name="CALL"/>
<push>42</push>
<command name="MDRP" modifier="min,rnd,black"/>
<push>42 52 10</push>
<command name="CALL"/>
<push>64 42 46 9</push>
<command name="CALL"/>
<b><!-- end top of bowl --></b>
<push>20 17 3 31 13</push>
<command name="CALL"/>
<push>38</push>
<command name="SHP" modifier="rp1"/>
<push>20</push>
<command name="MDRP" modifier="min,rnd,black"/>
<push>34</push>
<command name="SHP" modifier="rp2"/>
<command name="SVTCA" modifier="x-axis"/>
<push>63</push>
<command name="MDAP" modifier="rnd"/>
<push>15</push>
<command name="MDRP" modifier="rp0,rnd,white"/>
<push>21</push>
<command name="SHP" modifier="rp2"/>
<push>57</push>
<command name="MDRP" modifier="min,rnd,black"/>
<push>32 39</push>
<command name="SHP" modifier="rp2"/>
<command name="SHP" modifier="rp2"/>
<push>57 15 10</push>
<command name="CALL"/>
<push>64 57 37 9</push>
<command name="CALL"/>
<push>15 57 10</push>
<command name="CALL"/>
<push>64 15 26 9</push>
<command name="CALL"/>
<push>64 15 19 9</push>
<command name="CALL"/>
<b><!-- width of character --></b>
<push>57</push>
<command name="SRP0"/>
<push>49 1</push>
<command name="CALL"/>
<push>0</push>
<command name="MDRP" modifier="min,rnd,black"/>
<b><!-- end width of character --></b>
<push>64 1</push>
<command name="CALL"/>
<push>57 15</push>
<command name="SRP1"/>
<command name="SRP2"/>
<push>7 10 30</push>
<command name="IP"/>
<command name="IP"/>
<command name="IP"/>
<push>49</push>
<command name="SRP1"/>
<push>6 3 46</push>
<command name="IP"/>
<command name="IP"/>
<command name="IP"/>
<command name="SVTCA" modifier="y-axis"/>
<push>60 3</push>
<command name="SRP1"/>
<command name="SRP2"/>
<push>6 13</push>
<command name="IP"/>
<command name="IP"/>
<push>52</push>
<command name="SRP1"/>
<push>0</push>
<command name="IP"/>
<command name="IUP" modifier="y"/>
<command name="IUP" modifier="x"/>
</glyph>
</xgridfit></pre>
<p>
The FontForge code looks a little obscure because it does much of
its work by making calls to a library of functions, which the
auto-instructor inserts into every font. (These well-crafted
functions may also be of interest to Xgridfit programmers. You can
get access to them via the macros defined in
<tt>ff-functions.xgf</tt>, found in the <tt>utils</tt>
subdirectory of the Xgridfit directory tree). However, it is not
really necessary to understand the function calls to see in
general terms what the auto-instructor is doing.
</p>
<p>
We'll start by defining some constants for point numbers: first
the two points that define the top and inside top of the bowl, and
next some key points for the straight stem on the left of the
glyph and the round stem on the right:
</p>
<pre>
<constant name="bowl-top" value="46"/>
<constant name="bowl-top-inside" value="52"/>
<constant name="left-left" value="15"/>
<constant name="left-right" value="57"/>
<constant name="right-right" value="0"/>
<constant name="right-left" value="49"/></pre>
<table>
<tr>
<td>
<img alt="bbar auto-instructed" src="bbar-points.png"/>
</td>
</tr>
</table>
<p>
The next step is to notice how the Junicode <b>b</b> is
instructed. There, <tt>bowl-top</tt> is positioned at the x-height
with a control value (<tt>lc-x-height</tt>), and the distance
between <tt>bowl-top</tt> and <tt>bowl-top-inside</tt> is
regulated with another control value
(<tt>lc-horz-thin-curve</tt>). We'll comment out the offending
instructions and replace them with Xgridfit code that employs the
same control values:
</p>
<pre>
<move distance="lc-x-height">
<point num="bowl-top"/>
<move distance="lc-horz-thin-curve">
<point num="bowl-top-inside"/>
</move>
</move>
<!-- top of bowl
<push>42 52 3 31 13</push>
<command name="CALL"/>
<push>42</push>
<command name="MDRP" modifier="min,rnd,black"/>
<push>42 52 10</push>
<command name="CALL"/>
<push>64 42 46 9</push>
<command name="CALL"/>
--></pre>
<p>
Next, the FontForge auto-instructor has instructed along the
x-axis by first positioning <tt>left-left</tt>, then
<tt>left-right</tt> relative to that, then <tt>right-left</tt>,
then <tt>right-right</tt>. In other words, it has gone strictly
left-to-right. The Junicode <b>b</b> is instructed in a different
order: first the left stem is regulated, then the overall width of
the glyph (<tt>left-left</tt> to <tt>right-right</tt>, with a
control value), and finally the right stem. We can approximate
this behavior in revising the FontForge instructions (we'll ignore
the width of the left stem for now):
</p>
<pre>
<move distance="bpq-char-width">
<reference>
<point num="left-left"/>
</reference>
<point num="right-right"/>
<move distance="lc-vert-curve">
<point num="right-left"/>
</move>
</move>
<!-- width of character
<push>57</push>
<command name="SRP0"/>
<push>49 1</push>
<command name="CALL"/>
<push>0</push>
<command name="MDRP" modifier="min,rnd,black"/>
--></pre>
<p>
We'll address two more details before testing the code. First, the
FontForge auto-instructor regulates the left sidebearing with an
MDRP instruction:
</p>
<pre>
<push>63</push>
<command name="MDAP" modifier="rnd"/>
<push>15</push>
<command name="MDRP" modifier="rp0,rnd,white"/></pre>
<p>
This is the equivalent of the following:
</p>
<pre>
<move>
<point num="left-sidebearing"/>
<move>
<point num="left-left"/>
</move>
</move></pre>
<p>
But Junicode uses a control value to regulate this distance. We
can revise the code very simply, by adding the control value and
changing MDRP to MIRP.
</p>
<pre>
<push>63</push>
<command name="MDAP" modifier="rnd"/>
<push>15 b-left-side</push>
<command name="MIRP" modifier="rp0,rnd,white"/></pre>
<p>
Or we could replace the code (omitting to touch the
left-sidebearing point, since this is unnecessary):
</p>
<pre>
<move distance="b-left-side">
<reference>
<point num="left-sidebearing"/>
<reference>
<point num="left-left"/>
</move></pre>
<p>
Junicode also uses a control value to regulate standard vertical
stems, and so we can make a similar change to the way the
auto-instructor regulates the distance between <tt>left-left</tt>
and <tt>left-right</tt>. We'll just change this:
</p>
<pre>
<push>57</push>
<command name="MDRP" modifier="min,rnd,black"/></pre>
<p>
to this:
</p>
<pre>
<push>57 lc-vert-stem</push>
<command name="MIRP" modifier="min,rnd,black"/></pre>
<p>
We'll just use <a href="xinclude.html">XInclude</a> to include the
revised instructions in the font programming and compile (just
<b>b</b> and <b>uni0180</b>, since we haven't got all day). Since
we're feeling confident, we'll use the <tt>-f</tt> option to pipe
Xgridfit's output to FontForge:
</p>
<pre>
$ xgridfit -g b+bbar -f Junicode-Regular.xgf</pre>
<p>
Here is the result from <tt>Junicode-Regular.ttf</tt> as viewed in
FontForge, with <b>b</b> again for comparison:
</p>
<table>
<tr>
<td>
<img alt="hand-instructed b" src="b-hinted.png"/>
</td>
<td>
<img alt="bbar auto-instructed" src="bbar-revised.png"/>
</td>
</tr>
</table>
<p>
It might have been just as easy to copy the program for <b>b</b>
and edit it; but editing an auto-instructed glyph will usually be
quick and very often the easiest thing to do.
</p>
</div>
</body>
</html>
|