/usr/share/doc/libfreetype6/design/design-6.html is in libfreetype6-dev 2.8.1-2ubuntu2.
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 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 411 412 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type"
content="text/css">
<meta http-equiv="Content-Script-Type"
content="text/javascript">
<meta name="description"
content="FreeType Documentation">
<meta name="Author"
content="David Turner">
<link rel="icon"
href="../image/favicon_-90.ico">
<link rel="shortcut icon"
href="../image/favicon_-90.ico">
<link rel="stylesheet"
type="text/css"
href="../css/freetype2_-90.css">
<script type="text/javascript"
src="../../../js/jquery-1.11.0.min.js">
</script>
<script type="text/javascript"
src="../../../js/jquery.ba-resize.min.js">
</script>
<script type="text/javascript"
src="../../../js/freetype2.js">
</script>
<title>FreeType Design / V</title>
</head>
<body>
<div id="top"
class="bar">
<h1><a href="http://freetype.org/index.html">FreeType</a>
Design / V</h1>
</div>
<div id="wrapper">
<div class="colmask leftmenu">
<div class="colright">
<div class="col1wrap">
<div class="col1">
<!-- ************************************************** -->
<div id="module-classes">
<h2>V. Interfaces and Services</h2>
<p>We shall now go into detail about interfaces and services
in FreeType.</p>
<p><em>Interfaces</em> in FreeType are analogous to those
found in object-oriented programming. They can be thought
of as internal public APIs, and are essentially tables of
function pointers.</p>
<p>Interfaces only describe the form and functionality, but
the actual function body may be implemented elsewhere.
The module that is implementing the interface will then
pass the required function pointers to the table. This
gives modularity and easy extendability.</p>
<p>There are two main kinds of interfaces: <em>module</em>
interfaces, and <em>services</em>.</p>
<p>Module interfaces are defined for each module. For
example, every font driver provides its own set of
procedures for use in the base layer, which are registered
in an <tt>FT_Driver</tt>. This way, very different font
drivers can be used in the same way in the base layer.</p>
<p>Services are cross-module interfaces. These provide
functionality needed in several font drivers. </p>
<p>Services are created when code from one module needs to
be used in another. Rather than include files from
another module, a service is created instead. Now, the
other module just needs to include the header defining the
interface.</p>
<p>Helper modules are an extreme example of this; all their
public functionality is made for use in other font drivers
and hence are in a single service.</p>
<h3>In-depth guide: Creating a service</h3>
<p>This section will teach you how to write your own
service.</p>
<ol>
<li>
<p>Make the service interface header.</p>
<p>We will be calling our service demo for demonstration
purposes. First, create the header file, which goes
in <tt>include/freetype/internal/services</tt>, and
add the boilerplate.</p>
<pre>
#include FT_INTERNAL_SERVICE_H
FT_BEGIN_HEADER
#define FT_SERVICE_ID_DEMO "demo"
/* ... */
FT_END_HEADER</pre>
<p>This line in particular is required to register the
new service later on.</p>
<pre>
#define <em>service-id service-tag</em></pre>
</li>
<li>
<p>We will have identified some functions that are
needed in another module. Extract the function
signatures of these and place them in the header.</p>
<pre>
[typedef <em>return-type</em>
(*<em>type-name</em>)(<em>function-signature</em>);]+</pre>
<p>Example:</p>
<pre>
typedef FT_Error
(*SampleDoSomethingFunc)( int foo );
typedef void
(*SampleDoAnotherFunc)( int foo,
float bar );</pre>
</li>
<li>
<p>Define the service interface.</p>
<p>Use the <tt>FT_DEFINE_SERVICE</tt> macro to do
this.</p>
<pre>
FT_DEFINE_SERVICE( <em>service-name</em> )
{
[<em>type-name interface-entry</em>;]+
}</pre>
<p>Example:</p>
<pre>
FT_DEFINE_SERVICE( Demo )
{
SampleDoSomethingFunc doSomething;
SampleDoAnotherFunc doAnother;
};</pre>
<p>Here is the definition of the above macro
(in <tt>ftserv.h</tt>).</p>
<pre>
#define FT_DEFINE_SERVICE( name ) \
typedef struct FT_Service_ ## name ## Rec_ \
FT_Service_ ## name ## Rec ; \
typedef struct FT_Service_ ## name ## Rec_ \
const * FT_Service_ ## name ; \
struct FT_Service_ ## name ## Rec_</pre>
<p>This defines a new struct
called <tt>FT_Service_DemoRec</tt>, along with a
handle type for the
struct, <tt>FT_Service_Demo</tt>.</p>
</li>
<li>
<p>Register (and/or implement) the functions for the
newly created interface.</p>
<p>In the module implementing the interface, add a
definition like the following</p>
<pre>
static const <em>service-record table-name</em> =
{
<em>function-name</em>
[,<em>function-name2</em> [,...]]
}</pre>
<p>which corresponds to the interface defined in
step 3. Example:</p>
<pre>
static const FT_Service_DemoRec demo_service_rec =
{
function1,
function2
};</pre>
<p>This initializes the function pointers table. In
this example, <tt>function1</tt> has the function
signature of <tt>SampleDoSomethingFunc</tt> and
implements the <tt>doSomething</tt> functionality, and
so on.</p>
</li>
<li>
<p>Register the new service.</p>
<p>Next, add this code to define the service list in
this module, or append the new service to an existing
list.</p>
<pre>
static const FT_ServiceDescRec <em>service-list-name</em>[] =
{
{ <em>service-id</em>, &<em>table-name</em> },
[{ <em>service-id2</em>, &<em>table-name2</em> }, [...]]
{ NULL, NULL }
}</pre>
<p>Example:</p>
<pre>
static const FT_ServiceDescRec demo_services[] =
{
{ FT_SERVICE_ID_DEMO, &demo_service_rec },
{ NULL, NULL }
};</pre>
<p><em>service-id</em> is what we <tt>#define</tt>'d in
the service header file in step 1. Note that
the <tt>{NULL, NULL}</tt> sentinel value at the
end is required.</p>
<p>Now we need a way for other modules to find this
service. First, we need to implement
the <tt>get_interface</tt> function in
<tt>FT_Module_Class</tt>. Here is a minimal example
that does not do any validation.</p>
<pre>
FT_CALLBACK_DEF( FT_Module_Interface )
<em>get-interface-name</em>( FT_Module module,
const char* module_interface )
{
return ft_service_list_lookup( <em>service-list-name</em>,
module_interface );
}</pre>
<p>Then, pass it into the <tt>FT_DEFINE_MODULE</tt>
macro for this module.</p>
<pre>
(FT_Module_Requester) <em>get-interface-name</em></pre>
<p>The last step is optional but recommended, which is
to register the new service header
in <tt>ftserv.h</tt>.
<pre>
#define FT_SERVICE_DEMO_H <freetype/internal/services/svdemo.h></pre>
</li>
<li>
<p>Use the new service.</p>
<p>Now, in the file that wants to use the service, add
the following code to get the service.</p>
<pre>
<em>service-record-handle</em> service;
FT_FACE_FIND_GLOBAL_SERVICE( face,
service,
<em>service-id-tail</em> );</pre>
<p><tt>face</tt> should be of type <tt>FT_Face</tt>,
which is usually the current face instance being used
in the driver, and FreeType tries to find the service
in the driver of this face first, before searching all
other modules.</p>
<p><em>service-id-tail</em> is the part
of <em>service-id</em>
following <tt>FT_SERVICE_ID_</tt>.
<p>Now to call some function in the service.</p>
<pre>
service-><em>interface-entry</em>( <em>params</em> );</pre>
<p>Example:</p>
<pre>
FT_Service_Demo demo;
FT_Error error;
FT_FACE_FIND_GLOBAL_SERVICE( face, demo, DEMO );
error = demo->doSomething(0);
</pre>
</li>
</ol>
</div>
<!-- ************************************************** -->
<div class="updated">
<p>Last update: 13-Sep-2017</p>
</div>
</div>
</div>
<!-- ************************************************** -->
<div class="col2">
</div>
</div>
</div>
<!-- ************************************************** -->
<div id="TOC">
<ul>
<li class="funding">
<p><a href="https://pledgie.com/campaigns/24434">
<img alt="Click here to lend your support to the FreeType project and make a donation at pledgie.com!"
src="https://pledgie.com/campaigns/24434.png?skin_name=chrome"
border="0"
align="middle">
</a></p>
<p><a href="https://flattr.com/submit/auto?fid=mq2xxp&url=https%3A%2F%2Fwww.freetype.org"
target="_blank">
<img class="with-border"
src="https://button.flattr.com/flattr-badge-large.png"
alt="Flattr this"
title="Flattr this"
border="0"
align="middle">
</a></p>
</li>
<li class="primary">
<a href="http://freetype.org/index.html">Home</a>
</li>
<li class="primary">
<a href="http://freetype.org/index.html#news">News</a>
</li>
<li class="primary">
<a href="../index.html">Overview</a>
</li>
<li class="primary">
<a href="../documentation.html">Documentation</a>
</li>
<li class="primary">
<a href="http://freetype.org/developer.html">Development</a>
</li>
<li class="primary">
<a href="http://freetype.org/contact.html"
class="emphasis">Contact</a>
</li>
<li>
<!-- separate primary from secondary entries -->
</li>
<li class="secondary">
<a href="index.html">FreeType Design</a>
</li>
<li class="tertiary">
<a href="design-1.html">Introduction</a>
</li>
<li class="tertiary">
<a href="design-2.html">Components and APIs</a>
</li>
<li class="tertiary">
<a href="design-3.html">Public Objects and Classes</a>
</li>
<li class="tertiary">
<a href="design-4.html">Internal Objects and Classes</a>
</li>
<li class="tertiary">
<a href="design-5.html">Module Classes</a>
</li>
<li class="tertiary">
<a href="design-6.html" class="current">Interfaces and
Services</a>
</li>
</ul>
</div>
</div> <!-- id="wrapper" -->
<div id="TOC-bottom">
</div>
</body>
</html>
|