Debian Codegraph @

ft2docs/docs/design/design-5.html

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
2 "http://www.w3.org/TR/html4/loose.dtd">
3
4 <html lang="en">
5
6 <head>
7 <meta http-equiv="Content-Type"
8 content="text/html; charset=utf-8">
9 <meta http-equiv="Content-Style-Type"
10 content="text/css">
11 <meta http-equiv="Content-Script-Type"
12 content="text/javascript">
13 <meta name="description"
14 content="FreeType Documentation - Design - Module Classes">
15 <meta name="Author"
16 content="David Turner">
17
18 <link rel="icon"
19 href="../image/favicon_-90.ico">
20 <link rel="shortcut icon"
21 href="../image/favicon_-90.ico">
22 <link rel="stylesheet"
23 type="text/css"
24 href="../css/freetype2_-90.css">
25
26 <script type="text/javascript"
27 src="../../../js/freetype2.js">
28 </script>
29
30 <title>FreeType Design | Module Classes</title>
31 </head>
32
33
34 <body>
35
36 <div id="top"
37 class="bar">
38 <h1><a href="http://freetype.org/index.html">FreeType</a>
39 Design&nbsp;/&nbsp;IV</h1>
40 </div>
41
42
43 <div id="wrapper">
44
45 <div class="colmask leftmenu">
46 <div class="colright">
47 <div class="col1wrap">
48 <div class="col1">
49
50
51 <!-- ************************************************** -->
52
53 <div id="module-classes">
54 <h2>IV. Module Classes</h2>
55
56 <p>We will now try to explain more precisely
57 the <em>types</em> of modules that FreeType&nbsp;2 is
58 capable of managing.</p>
59
60 <ul>
61 <li>
62 <p><em>Renderer</em> modules manage scalable glyph
63 images. This means <em>transforming</em> them,
64 computing their <em>bounding box</em>,
65 and <em>converting</em> them to
66 either <em>monochrome</em> or <em>anti-aliased</em>
67 bitmaps.</p>
68
69 <p>Note that FreeType&nbsp;2 is capable of dealing
70 with <em>any</em> kind of glyph images, as long as a
71 renderer module is provided for it. The library comes
72 by default with four renderers.</p>
73
74 <table>
75 <tr valign=top>
76 <td>
77 <p><tt>raster</tt></p>
78 </td>
79 <td>
80 <p>Convert vectorial outlines
81 to <em>monochrome</em> bitmaps.</p>
82 </td>
83 </tr>
84
85 <tr valign=top>
86 <td>
87 <p><tt>smooth</tt></p>
88 </td>
89 <td>
90 <p>Convert vectorial outlines to
91 <em>anti-aliased</em> pixmaps (using 256 levels of
92 gray). Note that this renderer also supports
93 direct span generation, that is, it provides a
94 hook into the engine so that the application can
95 manipulate the rendering results itself, instead
96 of letting the rasterizer fill a pixmap.
97 See <a href="../tutorial/example4.cpp">this
98 tutorial demo file</a> for an example.</p>
99 </td>
100 </tr>
101
102 <tr valign=top>
103 <td>
104 <p><tt>sdf</tt></p>
105 </td>
106 <td>
107 <p>Convert vectorial outlines to
108 8-bit <em>Signed Distance Field</em> (SDF)
109 bitmaps.</p>
110 </td>
111 </tr>
112
113 <tr valign=top>
114 <td>
115 <p><tt>bsdf</tt></p>
116 </td>
117 <td>
118 <p>Convert bitmap glyphs to 8-bit <em>Signed
119 Distance Field</em> (SDF) bitmaps.</p>
120 </td>
121 </tr>
122 </table>
123
124 <p>The <a href="https://gitlab.freedesktop.org/freetype/freetype-demos/-/blob/master/src/ftsdf.c"><code>ftsdf</code></a>
125 FreeType demo program supports both
126 the <code>sdf</code> and <code>bsdf</code> renderers;
127 all other (graphical) demo
128 programs <code>raster</code>
129 and <code>smooth</code>.</p>
130
131 </li>
132
133 <li>
134 <p><em>Font driver</em> modules support one or more
135 specific font formats. Here is a list with the most
136 important ones.</p>
137
138 <table>
139 <tr valign=top>
140 <td>
141 <p><tt>truetype</tt></p>
142 </td>
143 <td>
144 <p>TrueType fonts.</p>
145 </td>
146 </tr>
147 <tr valign=top>
148 <td>
149 <p><tt>type1</tt></p>
150 </td>
151 <td>
152 <p>Postscript Type&nbsp;1 fonts, both in binary
153 (<tt>.pfb</tt>) or ASCII (<tt>.pfa</tt>)
154 formats, including Multiple Master fonts.</p>
155 </td>
156 </tr>
157 <tr valign=top>
158 <td>
159 <p><tt>cid</tt></p>
160 </td>
161 <td>
162 <p>Postscript CID-keyed fonts.</p>
163 </td>
164 </tr>
165 <tr valign=top>
166 <td>
167 <p><tt>cff</tt></p>
168 </td>
169 <td>
170 <p>OpenType CFF and CFF2, bare CFF, and CEF fonts
171 (CEF is a derivative of CFF used by Adobe in its
172 SVG viewer).</p>
173 </td>
174 </tr>
175 <tr valign=top>
176 <td>
177 <p><tt>winfonts</tt></p>
178 </td>
179 <td>
180 <p>Windows bitmap fonts (i.e., <tt>.fon</tt> and
181 <tt>.fnt</tt>).</p>
182 </td>
183 </tr>
184 </table>
185
186 <p>Note that font drivers can support bitmapped or
187 scalable glyph images. A given font driver that
188 supports B&eacute;zier outlines
189 through <tt>FT_Outline</tt> can also provide its own
190 hinter, or rely on FreeType's <tt>autofit</tt>
191 module for auto-hinting.</p>
192
193 <p>Note further that font drivers need some
194 <em>services</em> to be present: a typical example is
195 <code>FONT_FORMAT</code> to return the name of a font
196 format. This is discussed in
197 the <a href="design-6.html">next section</a>.
198 </li>
199
200 <li>
201 <p><em>Helper</em> modules are used to hold shared code
202 that is often used by several font drivers, or even
203 other modules. The most important are as follows.</p>
204
205 <table>
206 <tr valign=top>
207 <td>
208 <p><tt>sfnt</tt></p>
209 </td>
210 <td>
211 <p>Support for font formats based on
212 the <tt>SFNT</tt> storage scheme: TrueType,
213 OpenType, as well as other variants (like
214 TrueType fonts that only contain embedded
215 bitmaps).</p>
216 </td>
217 </tr>
218 <tr valign=top>
219 <td>
220 <p><tt>psnames</tt></p>
221 </td>
222 <td>
223 <p>Various useful functions related to glyph name
224 ordering and Postscript encodings and charsets.
225 For example, this module is capable of
226 automatically synthetizing a Unicode charmap
227 from a Type&nbsp;1 glyph name dictionary.</p>
228 </td>
229 </tr>
230 <tr valign=top>
231 <td>
232 <p><tt>psaux</tt></p>
233 </td>
234 <td>
235 <p>Auxiliary functions related to Postscript
236 charstring decoding, as needed by
237 the <tt>type1</tt>, <tt>cid</tt>,
238 and <tt>cff</tt> drivers.</p>
239 </td>
240 </tr>
241 </table>
242 </li>
243 <li>
244 <p>Finally, the <em>auto-hinter</em> module
245 (<tt>autofit</tt>) has a specific role in
246 FreeType&nbsp;2, as it can be used automatically
247 during glyph loading to process individual glyph
248 outlines when a font driver doesn't provide its own
249 hinting engine.</p>
250
251 <p>A paper published in the EuroTeX 2003 proceedings,
252 titled <a href="https://tug.org/TUGboat/tb24-3/lemberg.pdf"><em>Real-Time
253 Grid Fitting of Typographic Outlines</em></a>, gives
254 further insight into the auto-hinting system's inner
255 workings.</p>
256 </li>
257 </ul>
258
259 <p>We will now study how modules are described, then managed
260 by the library.</p>
261
262
263 <h3 id="section-1">1. The <tt>FT_Module_Class</tt>
264 Structure</h3>
265
266 <p>Here is the definition of <tt>FT_Module_Class</tt>, with
267 some explanations. The following code is taken from
268 <tt>ftmodapi.h</tt>.</p>
269
270 <pre>
271 typedef struct FT_Module_Class_
272 {
273 FT_ULong module_flags;
274 FT_Int module_size;
275 const FT_String* module_name;
276 FT_Fixed module_version;
277 FT_Fixed module_requires;
278
279 const void* module_interface;
280
281 FT_Module_Constructor module_init;
282 FT_Module_Destructor module_done;
283 FT_Module_Requester get_interface;
284
285 } FT_Module_Class;</pre>
286
287 <p>A description of its fields.</p>
288
289 <table>
290 <tr valign=top>
291 <td>
292 <p><tt>module_flags</tt></p>
293 </td>
294 <td>
295 <p>A set of bit flags to describe the module's
296 category. Valid values are listed below.</p>
297
298 <ul>
299 <li>
300 <tt>FT_MODULE_FONT_DRIVER</tt> if the module is a
301 font driver
302 </li>
303 <li>
304 <tt>FT_MODULE_RENDERER</tt> if the module is a
305 renderer
306 </li>
307 <li>
308 <tt>FT_MODULE_HINTER</tt> if the module is an
309 auto-hinter
310 </li>
311 <li>
312 <tt>FT_MODULE_DRIVER_SCALABLE</tt> if the module
313 is a font driver supporting scalable glyph formats
314 </li>
315 <li>
316 <tt>FT_MODULE_DRIVER_NO_OUTLINES</tt> if the
317 module is a font driver supporting scalable glyph
318 formats that <em>cannot</em> be described by
319 an <tt>FT_Outline</tt> object
320 </li>
321 <li>
322 <tt>FT_MODULE_DRIVER_HAS_HINTER</tt> if the module
323 is a font driver that provides its own hinting
324 scheme/algorithm
325 </li>
326 <li>
327 <tt>FT_MODULE_DRIVER_HINTS_LIGHTLY</tt> if the
328 module is a font driver that generates
329 &lsquo;light&rsquo; hints (this is, only along the
330 vertical axis).
331 </li>
332 </ul>
333 </td>
334 </tr>
335 <tr valign=top>
336 <td>
337 <p><tt>module_size</tt></p>
338 </td>
339 <td>
340 <p>An integer that gives the size in <em>bytes</em> of
341 a given module object. This should <em>never</em>
342 be less than <tt>sizeof(FT_ModuleRec)</tt>, but can
343 be more if the module needs to sub-class the
344 base <tt>FT_ModuleRec</tt> class.</p>
345 </td>
346 </tr>
347 <tr valign=top>
348 <td>
349 <p><tt>module_name</tt></p>
350 </td>
351 <td>
352 <p>The module's internal name, coded as a simple ASCII
353 C&nbsp;string. There can't be two modules with the
354 same name registered in a given <tt>FT_Library</tt>
355 object. However, <tt>FT_Add_Module</tt> uses
356 the <tt>module_version</tt> field to detect module
357 upgrades and perform them cleanly, even at
358 run-time.</p>
359 </td>
360 </tr>
361 <tr valign=top>
362 <td>
363 <p><tt>module_version</tt></p>
364 </td>
365 <td>
366 <p>A 16.16 fixed-point number giving the module's
367 major and minor version numbers. It is used to
368 determine whether a module needs to be upgraded when
369 calling <tt>FT_Add_Module</tt>.</p>
370 </td>
371 </tr>
372 <tr valign=top>
373 <td>
374 <p><tt>module_requires</tt></p>
375 </td>
376 <td>
377 <p>A 16.16 fixed-point number giving the version of
378 FreeType&nbsp;2 that is required to install this
379 module. The default value is 0x20000 for FreeType
380 version&nbsp;2.x</p>
381 </td>
382 </tr>
383 <tr valign=top>
384 <td>
385 <p><tt>module_interface</tt></p>
386 </td>
387 <td>
388 <p>Most modules support one or more
389 &lsquo;interfaces&rsquo;, i.e., tables of function
390 pointers. This field points to the module's main
391 interface, if there is one. It is a short-cut that
392 prevents users of the module to
393 call <tt>get_interface</tt> each time they need to
394 access one of the object's common entry points.</p>
395
396 <p>Note that it is optional, and can be set to NULL.
397 Other interfaces can also be accessed through
398 the <tt>get_interface</tt> field.</p>
399 </td>
400 </tr>
401 <tr valign=top>
402 <td>
403 <p><tt>module_init</tt></p>
404 </td>
405 <td>
406 <p>A pointer to a function to initialize the fields of
407 a fresh new <tt>FT_Module</tt> object. It is
408 called <em>after</em> the module's base fields have
409 been set by the library, and is generally used to
410 initialize the fields of <tt>FT_ModuleRec</tt>
411 subclasses.</p>
412
413 <p>Most module classes set it to NULL to indicate that
414 no extra initialization is necessary.</p>
415 </td>
416 </tr>
417 <tr valign=top>
418 <td>
419 <p><tt>module_done</tt></p>
420 </td>
421 <td>
422 <p>A pointer to a function to finalize the fields of a
423 given <tt>FT_Module</tt> object. Note that it is
424 called <em>before</em> the library unsets the
425 module's base fields, and is generally used to
426 finalize the fields of <tt>FT_ModuleRec</tt>
427 subclasses.</p>
428
429 <p>Most module classes set it to NULL to indicate that
430 no extra finalization is necessary</p>
431 </td>
432 </tr>
433 <tr valign=top>
434 <td>
435 <p><tt>get_interface</tt></p>
436 </td>
437 <td>
438 <p>A pointer to a function to request the address of a
439 given module interface. Set it to NULL if you don't
440 need to support additional interfaces but the main
441 one.</p>
442 </td>
443 </tr>
444 </table>
445
446
447 <h3 id="section-2">2. The <tt>FT_Module</tt> Type</h3>
448
449 <p>The <tt>FT_Module</tt> type is a handle (i.e., a pointer)
450 to a given module object or instance, whose base structure
451 is given by the internal <tt>FT_ModuleRec</tt> type. We
452 will intentionally <em>not</em> describe this structure
453 here, as there is no point to look so far into the
454 library's design.</p>
455
456 <p>When <tt>FT_Add_Module</tt> is called, it first allocates
457 a new module instance, using the <tt>module_size</tt>
458 class field to determine its byte size. The function
459 initializes the root <tt>FT_ModuleRec</tt> field, then
460 calls the class-specific initializer <tt>module_init</tt>
461 when this field is not set to NULL.</p>
462
463 <p>Note that the library defines several sub-classes of
464 <tt>FT_ModuleRec</tt>.</p>
465
466 <ul>
467 <li>
468 <p><tt>FT_Renderer</tt> for renderer modules</p>
469 </li>
470 <li>
471 <p><tt>FT_Driver</tt> for font driver modules</p>
472 </li>
473 <li>
474 <p><tt>FT_AutoHinter</tt> for the auto-hinter</p>
475 </li>
476 </ul>
477
478 <p>Helper modules use the base <tt>FT_ModuleRec</tt>
479 type.</p>
480 </div>
481
482 <!-- ************************************************** -->
483
484 <div class="updated">
485 <p>Last update: 27-Jan-2022</p>
486 </div>
487 </div>
488 </div>
489
490
491 <!-- ************************************************** -->
492
493 <div class="col2">
494 </div>
495 </div>
496 </div>
497
498
499 <!-- ************************************************** -->
500
501 <div id="TOC">
502 <ul>
503 <li class="funding">
504 <form action="https://www.paypal.com/cgi-bin/webscr"
505 method="post"
506 target="_top">
507 <input type="hidden"
508 name="cmd"
509 value="_s-xclick">
510 <input type="hidden"
511 name="hosted_button_id"
512 value="SK827YKEALMT4">
513 <input type="image"
514 src="https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif"
515 name="submit"
516 alt="PayPal - The safer, easier way to pay online!">
517 </form>
518 </li>
519 <li class="primary">
520 <a href="http://freetype.org/index.html">Home</a>
521 </li>
522 <li class="primary">
523 <a href="http://freetype.org/index.html#news">News</a>
524 </li>
525 <li class="primary">
526 <a href="../index.html">Overview</a>
527 </li>
528 <li class="primary">
529 <a href="../documentation.html">Documentation</a>
530 </li>
531 <li class="primary">
532 <a href="http://freetype.org/developer.html">Development</a>
533 </li>
534 <li class="primary">
535 <a href="http://freetype.org/contact.html"
536 class="emphasis">Contact</a>
537 </li>
538
539 <li>
540 &nbsp; <!-- separate primary from secondary entries -->
541 </li>
542
543 <li class="secondary">
544 <a href="index.html">FreeType Design</a>
545 </li>
546 <li class="tertiary">
547 <a href="design-1.html">Introduction</a>
548 </li>
549 <li class="tertiary">
550 <a href="design-2.html">Components and APIs</a>
551 </li>
552 <li class="tertiary">
553 <a href="design-3.html">Public Objects and Classes</a>
554 </li>
555 <li class="tertiary">
556 <a href="design-4.html">Internal Objects and Classes</a>
557 </li>
558 <li class="tertiary">
559 <a href="design-5.html" class="current">Module Classes</a>
560 </li>
561 <li class="tertiary">
562 <a href="design-6.html">Interfaces and Services</a>
563 </li>
564 </ul>
565 </div>
566
567 </div> <!-- id="wrapper" -->
568
569 <div id="TOC-bottom">
570 </div>
571
572 </body>
573 </html>