This file is indexed.

/usr/share/doc/defoma-doc/defoma-script.html/ch4.html is in defoma-doc 0.11.12ubuntu1.

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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">

<html>

<head>

<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">

<title>A Tutorial on Writing Defoma Configuration Script - Using Defoma::Id module.</title>

<link href="index.html" rel="start">
<link href="ch3.html" rel="prev">
<link href="ch5.html" rel="next">
<link href="index.html#contents" rel="contents">
<link href="index.html#copyright" rel="copyright">
<link href="ch1.html" rel="chapter" title="1 Introduction">
<link href="ch2.html" rel="chapter" title="2 Simple Defoma-configuration script.">
<link href="ch3.html" rel="chapter" title="3 Using hints.">
<link href="ch4.html" rel="chapter" title="4 Using Defoma::Id module.">
<link href="ch5.html" rel="chapter" title="5 Using Defoma::Id (2)">
<link href="ch6.html" rel="chapter" title="6 Using Defoma::Subst module.">
<link href="ch7.html" rel="chapter" title="7 Using x-postscript Category.">

</head>

<body>

<p><a name="ch4"></a></p>
<hr>

<p>
[ <a href="ch3.html">previous</a> ]
[ <a href="index.html#contents">Contents</a> ]
[ <a href="ch1.html">1</a> ]
[ <a href="ch2.html">2</a> ]
[ <a href="ch3.html">3</a> ]
[ 4 ]
[ <a href="ch5.html">5</a> ]
[ <a href="ch6.html">6</a> ]
[ <a href="ch7.html">7</a> ]
[ <a href="ch5.html">next</a> ]
</p>

<hr>

<h1>
A Tutorial on Writing Defoma Configuration Script
<br>Chapter 4 - Using Defoma::Id module.
</h1>

<hr>

<p>
The one major problem of the example of previous chapter is that it doesn't
consider the situation that two different fonts has the same FontName.  It is
so-called name-space conflict, and should be avoided if possible.  Defoma::Id
module can solve this problem.
</p>

<p>
This chapter describes a package named 'example3' which accepts truetype
category fonts.  The application accesses fonts put in a certain directory
(like X), and reads <samp>fonts.dir</samp> file put in the directory which
lists a fontfile and its real name, and <samp>fonts.alias</samp> which lists an
alias and its real name of a font.  The Defoma-configuration script generates
the files and symlinks under <samp>/var/lib/defoma/example3.d/dirs</samp>,
which is supposed to be symlinked from the required directory.
</p>

<p>
In Header of the script, declaration of using Defoma::Id module is needed.
</p>

<pre>
     	  @ACCEPT_CATEGORIES = qw(truetype);
     
     	  package example3;
     	  use Debian::Defoma::Id;
     	  use Debian::Defoma::Common;
     	  import Debian::Defoma::Id;
     	  import Debian::Defoma::Common;
     
     	  my $Id;
     	  my $DIR = '/var/lib/defoma/example3.d/';
     	  my @dir = ();
     	  my @scale = ();
</pre>

<p>
In init command, the script needs to open an id-cache.  In the same way as the
previous examples, the script reads <samp>fonts.dir</samp> and
<samp>fonts.alias</samp> files.
</p>

<pre>
     	  sub init {
     	    unless ($Id) {
     	      $Id = defoma_id_open_cache();
     	      if (open(F, $DIR.'fonts.dir')) {
     	        while (&lt;F&gt;) {
     	          chomp($_);
     	          push(@dir, $_);
     	        }
     	        close F;
     	      }
     	      if (open(F, $DIR.'fonts.alias')) {
     	        while (&lt;F&gt;) {
     	          chomp($_);
     	          push(@alias, $_);
     	        }
     	        close F;
     	      }
     	    }
     	    return 0;
     	  }
</pre>

<p>
In register command, the script parses the hints, and obtain the FontName,
Alias and Location from them.  The script returns error when some required
hints are missing, or the font doesn't contain Korean characters.
</p>

<pre>
     	  
     	  sub register {
     	    my $font = shift;
     	    my $h = parse_hints_start(@_);
     
     	    unless (exists($h-&gt;{FontName}) &amp;&amp; exists($h-&gt;{Location})) {
     	      return 1;
     	    }
     
     	    my $fontname = $h-&gt;{FontName};
     	    $fontname =~ s/ .*//;
     	    my $priority = $h-&gt;{Priority} || 20;
     	    my @locs = split(/ /, $h-&gt;{Location});
     	    my @alias = split(/ /, $h-&gt;{Alias});
     
     	    return 2 unless(grep($_ eq 'Korean', @locs));
</pre>

<p>
Now the script calls defoma_id_register to register the fontname and the
aliases to the id-cache.
</p>

<pre>
     	    defoma_id_register($Id, type =&gt; 'real', font =&gt; $font,
     	                       id =&gt; $fontname, priority =&gt; $priority,
     	                       hints =&gt; join(' ', @_));
     
     	    foreach my $i (@alias) {
     	      defoma_id_register($Id, type =&gt; 'alias', font =&gt; $font,
     	                         id =&gt; $i, priority =&gt; $priority,
     	                         origin =&gt; $fontname);
     	    }
     
     	    return 0;
     	  }
</pre>

<p>
Process in unregister command becomes a bit easier.  The following codes will
do.
</p>

<pre>
     	  sub unregister {
     	    my $font = shift;
     	    defoma_id_unregister($Id, type =&gt; 'alias', font =&gt; $font);
     	    defoma_id_unregister($Id, type =&gt; 'real', font =&gt; $font);
     
     	    return 0;
     	  }
</pre>

<p>
Codes up to this point do nothing about actual configuration.  The script needs
to do two things: create a symlink of a fontfile under
<samp>/var/lib/defoma/example3.d/dirs</samp>, and generate
<samp>fonts.dir</samp> and <samp>fonts.scale</samp> files.  Let's perform these
on do-install-* and do-remove-* commands.
</p>

<p>
Both do-install-* commands and do-remove-* commands are invoked by Defoma::Id
module.  In these commands actual installation and removal are supposed to be
performed in Defoma framework.  Let's create and remove symlinks in these
commands in this example.
</p>

<p>
In this example, a font may have multiple ids, one real name and some aliases.
Creating a symlink of a font is not necessary for each id.  It should be done
when the real name is installed, because aliases never get installed unless the
real name is not installed.  That means creating and removing a symlink should
be done in do-install-real and do-remove-real commands.
</p>

<p>
If creating a symlink fails, the script returns non-zero to tell Defoma::Id
that the font is not installed, which prevents its aliases from getting
installed.
</p>

<pre>
     	  sub do_install_real {
     	    my $font = shift;
     	    my $id = shift;
     	    my $depfont = shift;
     	    my $depid = shift;
     	    my @hints = @_;
     
     	    $font =~ /^(.*)\/(.+)$/;
     	    my $fontfile = $2;
     
     	    symlink($font, $DIR.$fontfile) || return 1;
     
     	    push(@dirs, &quot;/$id ($fontfile) ;&quot;);
     	    return 0;
     	  }
     
     	  sub do_remove_real {
     	    my $font = shift;
     	    my $id = shift;
     	    my $depfont = shift;
     	    my $depid = shift;
     	    my @hints = @_;
     
     	    $font =~ /^(.*)\/(.+)$/;
     	    my $fontfile = $2;
     
     	    unlink($DIR.$fontfile);
     
     	    for (my $i = 0; $i &lt; @dirs; $i++) {
     	      if ($dirs[$i] eq &quot;/$id ($fontfile) ;&quot;) {
     	        $dirs[$i] = '';
     	      }
     	    }
     	    return 0;
     	  }
</pre>

<p>
Installation and removal for aliases are done in do-install-alias and
do-remove-alias commands respectively.  This script modifies @alias in these
commands.  Note that the fourth argument represents the origin of the alias,
which is specified in the arguments of defoma_id_register and is actually the
real name of the font.
</p>

<pre>
     	  sub do_install_alias {
     	    my $font = shift;
     	    my $id = shift;
     	    my $depfont = shift;
     	    my $depid = shift;
     	    my @hints = @_;
     
     	    push(@alias, &quot;/$id /$depid ;&quot;);
     	    return 0;
     	  }
     
     	  sub do_remove_alias {
     	    my $font = shift;
     	    my $id = shift;
     	    my $depfont = shift;
     	    my $depid = shift;
     	    my @hints = @_;
     
     	    for (my $i = 0; $i &lt; @alias; $i++) {
     	      if ($alias[$i] eq &quot;/$id /$depid ;&quot;) {
     	        $alias[$i] = '';
     	      }
     	    }
     	    return 0;
     	  }
</pre>

<p>
term command is almost the same as the previous examples, except closing the
id-cache.
</p>

<pre>
     	  sub term {
     	    my $i;
     	    if ($Id) {
     	      defoma_id_close_cache($Id);
     	      if (open(F, '&gt;'.$DIR.'fonts.dir')) {
     	        foreach $i (@dir) {
     	          print F $i, &quot;\n&quot;; if ($i ne '');
     	        }
     	        close F;
     	      }
     	      if (open(F, '&gt;'.$DIR.'fonts.alias')) {
     	        foreach $i (@alias) {
     	          print F $i, &quot;\n&quot;; if ($i ne '');
     	        }
     	        close F;
     	      }
     	    }
     	    return 0;
     	  }
</pre>

<p>
The <samp>truetype</samp> function goes like this:
</p>

<pre>
     	  sub truetype {
     	    my $com = shift;
     	    if ($com eq 'init') {
     	      return init();
     	    } elsif ($com eq 'term') {
     	      return term();
     	    } elsif ($com eq 'register') {
     	      return register(@_);
     	    } elsif ($com eq 'unregister') {
     	      return unregister(@_);
     	    } elsif ($com eq 'do-install-real') {
     	      return do_install_real(@_);
     	    } elsif ($com eq 'do-install-alias') {
     	      return do_install_alias(@_);
     	    } elsif ($com eq 'do-remove-real') {
     	      return do_remove_real(@_);
     	    } elsif ($com eq 'do-remove-alias') {
     	      return do_remove_alias(@_);
     	    }
     	    return 0;
     	  }
     
     	  1;
</pre>

<p>
The generated files go like:
</p>

<pre>
     	  fonts.dir:
     	  /URWGothicL-Bold (gothicb.ttf) ;
     	  /URWSanL-Obli (sano.ttf) ;
     	  fonts.alias:
     	  /Helvetica-Oblique /URWSanL-Obli ;
     	  /AvantGarde-Bold /URWGothicL-Bold ;
</pre>

<hr>

<p>
[ <a href="ch3.html">previous</a> ]
[ <a href="index.html#contents">Contents</a> ]
[ <a href="ch1.html">1</a> ]
[ <a href="ch2.html">2</a> ]
[ <a href="ch3.html">3</a> ]
[ 4 ]
[ <a href="ch5.html">5</a> ]
[ <a href="ch6.html">6</a> ]
[ <a href="ch7.html">7</a> ]
[ <a href="ch5.html">next</a> ]
</p>

<hr>

<p>
A Tutorial on Writing Defoma Configuration Script
</p>

<address>
Yasuhiro Take<br>
<br>
</address>
<hr>

</body>

</html>