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 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410
|
<!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="http://sflogo.sourceforge.net/sflogo.php?group_id=159705&type=4" 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 1: Gentium's period</h1>
<p>
To introduce the basics of Xgridfit, let's instruct one of the
simplest possible glyphs: the period. Here's what it looks like in
Gentium Italic when opened in FontForge:
</p>
<table>
<tr>
<td>
<img src="Gentium_period.png" alt="Gentium period"/>
</td>
</tr>
</table>
<p>
Our aim in instructing this glyph is to move key points onto the
gridlines (which run between pixels) so that the TrueType
rasterizer always renders the glyph cleanly, without relying too
much on anti-aliasing and other tricks. Here's how the
uninstructed period sits on the raster grid at twenty pixels per
em; notice that none of the points falls on a gridline. The
darkened squares show that the anti-aliased glyph will be a
shapeless blob.
</p>
<table>
<tr>
<td>
<img src="Gentium_period_num.png" alt="Gentium period"/>
</td>
</tr>
</table>
<p>
We need to fit only the four points at the extrema to the grid:
these are numbered 0, 5, 8, and 13: a sensible start on our
project would be to name these points. At the same time we will
erect the elements that every Xgridfit program and every glyph
program must have: <xgridfit>, <pre-program> (needed
even when empty), and <glyph>:
</p>
<pre>
<?xml version="1.0"?>
<xgridfit xmlns="http://xgridfit.sourceforge.net/Xgridfit2">
<constant name="left-sidebearing" value="last + 1"/>
<pre-program>
</pre-program>
<glyph ps-name="period">
<constant name="last" value="15"/>
<constant name="left" value="8"/>
<constant name="right" value="0"/>
<constant name="bottom" value="5"/>
<constant name="top" value="13"/>
</glyph>
</xgridfit>
</pre>
<p>
We have also included a global constant <tt>left-sidebearing</tt>,
which gives us access to the left sidebearing point for any glyph
for which we have defined the constant <tt>last</tt> (which points
to the number of the last point in the glyph outline).
</p>
<p>
Let us deal first with the horizontal movements of points
<tt>left</tt> and <tt>right</tt>. We'll put all the programming
for horizontal movement in a with-block:
</p>
<pre>
<with-vectors axis="x">
</with-vectors>
</pre>
<p>
Our strategy will be to position point <tt>left</tt>, and then
position point <tt>right</tt> relative to it. In deciding how to
position <tt>left</tt>, it would help to know whether its distance
from the <tt>left-sidebearing</tt> point is a standard distance in
this font--that is, whether other glyphs have the same left
sidebearing. In fact, the colon and the exclamation mark have the
same left sidebearing of 51 font units; a control value will help
us control those glyphs in a consistent way. We'll put it right
after the global constant:
</p>
<pre>
<control-value name="period-left-sidebearing" value="51"/>
</pre>
<p>
Now we can add our first instruction to the glyph program We will
position point <tt>left</tt> distance
<tt>period-left-sidebearing</tt> from point
<tt>left-sidebearing</tt>:
</p>
<pre>
<move distance="period-left-sidebearing">
<reference>
<point num="left-sidebearing"/>
</reference>
<point num="left"/>
</move>
</pre>
<p>
Since we have not said otherwise, it is implicit that we want the
distance to be rounded so that <tt>left</tt> is positioned on a
gridline.
</p>
<p>
The width of the period is also standard in this font, shared by
various dots in (for example) the colon, semicolon and exclamation
mark. So we need to add another control value:
</p>
<pre>
<control-value name="period-width" value="232"/>
</pre>
<p>
To control the width of the period we position point
<tt>right</tt> relative to point <tt>left</tt>. We
<em>could</em> do this by adding a <move> element
right after the one we just wrote, like this:
</p>
<pre>
<move distance="period-width">
<reference>
<point num="left"/>
</reference>
<point num="right"/>
</move>
</pre>
<p>
But it is better to nest the new <move> element inside the
other. The point in a nested <move> is always positioned
relative to the point moved by the parent <move>, so we can
omit the <reference> element:
</p>
<pre>
<move distance="period-left-sidebearing">
<reference>
<point num="left-sidebearing"/>
</reference>
<point num="left"/>
<move distance="period-width">
<point num="right"/>
</move>
</move>
</pre>
<p>
That finishes our work on the x axis. Let's look at the
result. The program so far looks like this:
</p>
<pre>
<?xml version="1.0"?>
<xgridfit xmlns="http://xgridfit.sourceforge.net/Xgridfit2">
<constant name="left-sidebearing" value="last + 1"/>
<control-value name="period-left-sidebearing" value="51"/>
<control-value name="period-width" value="232"/>
<pre-program>
</pre-program>
<glyph ps-name="period">
<constant name="last" value="15"/>
<constant name="left" value="8"/>
<constant name="right" value="0"/>
<constant name="bottom" value="5"/>
<constant name="top" value="13"/>
<with-vectors axis="x">
<move distance="period-left-sidebearing">
<reference>
<point num="left-sidebearing"/>
</reference>
<point num="left"/>
<move distance="period-width">
<point num="right"/>
</move>
</move>
</with-vectors>
</glyph>
</xgridfit>
</pre>
<p>
And when we run it from inside FontForge, the glyph looks like
this:
</p>
<table>
<tr>
<td>
<img src="Gentium_period_horz.png" alt="Gentium period"/>
</td>
</tr>
</table>
<p>
It doesn't look like much yet, but you can see that points
<tt>left</tt> and <tt>right</tt> are positioned on gridlines.
</p>
<p>
We'll start work on vertical moves by adding a with-block for the
y axis:
</p>
<pre>
<with-vectors axis="y">
</with-vectors>
</pre>
<p>
The distances we have to work with here are that of point
<tt>bottom</tt> from the baseline (-31) and that of point
<tt>top</tt> from <tt>bottom</tt> (277). These are also standard
in the font, found in the colon, exclamation mark and
elsewhere. So we add control values:
</p>
<pre>
<control-value name="period-bottom" value="-31"/>
<control-value name="period-height" value="277"/>
</pre>
<p>
We'll start by positioning point <tt>bottom</tt> at position
<tt>period-bottom</tt>. Since we are positioning the point on the
grid rather than relative to another point, we don't need a
<reference> element; and the distance will be rounded since
we haven't said otherwise:
</p>
<pre>
<move distance="period-bottom">
<point num="bottom"/>
</move>
</pre>
<p>
Then we'll position point <tt>top</tt> relative to point
<tt>bottom</tt>. Once again, the preferred method is to nest a
<move> element in the one we've just written:
</p>
<pre>
<move distance="period-bottom">
<point num="bottom"/>
<move distance="period-height">
<point num="top"/>
</move>
</move>
</pre>
<p>
Here's the result:
</p>
<table>
<tr>
<td>
<img src="Gentium_period_hv.png" alt="Gentium period"/>
</td>
</tr>
</table>
<p>
It looks really bad because we have moved only four points of the
fifteen that make up the glyph. We can position the rest
automatically by adding this instruction at the end of the
program:
</p>
<pre>
<interpolate-untouched-points/>
</pre>
<p>
And the result looks like this:
</p>
<table>
<tr>
<td>
<img src="Gentium_period_int.png" alt="Gentium period"/>
</td>
</tr>
</table>
<p>
The glyph is rather narrow and tall at the resolution we have been
using for illustration (20 pixels per em). If we want it to
be rounder, we should adjust the control value
<tt>period-height</tt>: that way, all of the various dots
controlled by that control value will be adjusted at the same
time. We add these elements to the <pre-program>:
</p>
<pre>
<round value="period-height"/>
<control-value-delta>
<delta-set size="11" distance="-8" cv="period-height"/>
</control-value-delta>
</pre>
<p>
The <round> element rounds the control value
<tt>period-height</tt> at all resolutions. The
<control-value-delta> element shrinks the distance by one
pixel at 20 pixels per em (for details about the operation of
delta instructions, see <a href="deltas.html">here</a>). Since the
distance <tt>period-height</tt> is already rounded, we can add an
attribute <tt>round="no"</tt> to the element that moves
<tt>top</tt>. Now when the program is run, the result looks like
this:
</p>
<table>
<tr>
<td>
<img src="Gentium_period_final.png" alt="Gentium period"/>
</td>
</tr>
</table>
<p>
You can check the appearance of the period at various resolutions
in FontForge or using ftview (a utility that accompanies
FreeType), and add <delta-set> elements to the
<control-value-delta> element as needed. Now the complete
Xgridfit file is as follows:
</p>
<pre>
<?xml version="1.0"?>
<xgridfit xmlns="http://xgridfit.sourceforge.net/Xgridfit2">
<constant name="left-sidebearing" value="last + 1"/>
<control-value name="period-left-sidebearing" value="51"/>
<control-value name="period-width" value="232"/>
<control-value name="period-bottom" value="-31"/>
<control-value name="period-height" value="277"/>
<pre-program>
<round value="period-height"/>
<control-value-delta>
<delta-set size="11" distance="-8" cv="period-height"/>
</control-value-delta>
</pre-program>
<glyph ps-name="period">
<constant name="last" value="15"/>
<constant name="left" value="8"/>
<constant name="right" value="0"/>
<constant name="bottom" value="5"/>
<constant name="top" value="13"/>
<with-vectors axis="x">
<move distance="period-left-sidebearing">
<reference>
<point num="left-sidebearing"/>
</reference>
<point num="left"/>
<move distance="period-width">
<point num="right"/>
</move>
</move>
</with-vectors>
<with-vectors axis="y">
<move distance="period-bottom">
<point num="bottom"/>
<move distance="period-height" round="no">
<point num="top"/>
</move>
</move>
</with-vectors>
<interpolate-untouched-points/>
</glyph>
</xgridfit>
</pre>
<p>
The illustrations above were generated by running the Xgridfit
program from the FontForge GUI (File--Execute Script). If we want
to run it from the command line, we must add <infile> and
<outfile> elements somewhere near the top of the file:
</p>
<pre>
<infile>Gentium-Italic.sfd</infile>
<outfile>Gentium-Italic.ttf</outfile>
</pre>
<p>
And now, supposing we have named the file
<tt>Gentium-Italic.xgf</tt>, we can run the program with this
command:
</p>
<pre>
xgridfit -f Gentium-Italic.xgf
</pre>
</div>
</body>
</html>
|