/usr/share/doc/defoma-doc/defoma-script.html/ch3.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 | <!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 hints.</title>
<link href="index.html" rel="start">
<link href="ch2.html" rel="prev">
<link href="ch4.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="ch3"></a></p>
<hr>
<p>
[ <a href="ch2.html">previous</a> ]
[ <a href="index.html#contents">Contents</a> ]
[ <a href="ch1.html">1</a> ]
[ <a href="ch2.html">2</a> ]
[ 3 ]
[ <a href="ch4.html">4</a> ]
[ <a href="ch5.html">5</a> ]
[ <a href="ch6.html">6</a> ]
[ <a href="ch7.html">7</a> ]
[ <a href="ch4.html">next</a> ]
</p>
<hr>
<h1>
A Tutorial on Writing Defoma Configuration Script
<br>Chapter 3 - Using hints.
</h1>
<hr>
<p>
register and unregister commands are called with hints of the font. Let's use
hints in font configuration. This chapter describes a package named 'example2'
which accepts truetype category fonts. The Defoma-configuration script
generates <samp>default.conf</samp>, <samp>ja.conf</samp>,
<samp>ko.conf</samp>, <samp>zh_cn.conf</samp> and <samp>zh_tw.conf</samp> under
<samp>/var/lib/defoma/example2.d/dirs</samp> directory, which is supposed to be
symlinked from the required place. These files list the font (path) and its
font name taken from hints. Location hint decides which file to write.
</p>
<p>
Header, init and term goes the same way as the previous chapter's example, so
the detail is not described here. Only one difference is that this script
declares to use <samp>Debian::Defoma::Common</samp> module because this script
calls parse_hints_start() function.
</p>
<pre>
@ACCEPT_CATEGORIES = qw(truetype);
package example2;
use Debian::Defoma::Common;
import Debian::Defoma::Common;
my @default = ();
my @ja = ();
my @ko = ();
my @zh_cn = ();
my @zh_tw = ();
sub init {
if (open(F, '/var/lib/defoma/example2.d/dirs/default.conf')) {
while (<F>) {
chomp($_);
push(@default, $_);
}
close F;
}
if (open(F, '/var/lib/defoma/example2.d/dirs/ja.conf')) {
while (<F>) {
chomp($_);
push(@ja, $_);
}
close F;
}
if (open(F, '/var/lib/defoma/example2.d/dirs/ko.conf')) {
while (<F>) {
chomp($_);
push(@ko, $_);
}
close F;
}
if (open(F, '/var/lib/defoma/example2.d/dirs/zh_cn.conf')) {
while (<F>) {
chomp($_);
push(@zh_cn, $_);
}
close F;
}
if (open(F, '/var/lib/defoma/example2.d/dirs/zh_tw.conf')) {
while (<F>) {
chomp($_);
push(@zh_tw, $_);
}
close F;
}
return 0;
}
sub term {
my $i;
if (open(F, '>/var/lib/defoma/example2.d/dirs/default.conf')) {
foreach $i (@default) {
print F $i, "\n" if ($i ne '');
}
close F;
}
if (open(F, '>/var/lib/defoma/example2.d/dirs/ja.conf')) {
foreach $i (@ja) {
print F $i, "\n" if ($i ne '');
}
close F;
}
if (open(F, '>/var/lib/defoma/example2.d/dirs/ko.conf')) {
foreach $i (@ko) {
print F $i, "\n" if ($i ne '');
}
close F;
}
if (open(F, '>/var/lib/defoma/example2.d/dirs/zh_cn.conf')) {
foreach $i (@zh_cn) {
print F $i, "\n" if ($i ne '');
}
close F;
}
if (open(F, '>/var/lib/defoma/example2.d/dirs/zh_tw.conf')) {
foreach $i (@zh_tw) {
print F $i, "\n" if ($i ne '');
}
close F;
}
return 0;
}
</pre>
<p>
On register command, the hints must be parsed to pick out Location and FontName
hints. parse_hints_start() is used for this purpose. This function converts
hints stored in an array to a hash. For more detail, please refer the manpage
of Defoma::Common.
</p>
<p>
If these necessary HintTypes, Location and FontName are not found, the script
returns non-zero to tell defoma that the script failed to register the font.
Unregister command goes the similar way except that the script does not check
if Location and FontName exist, because defoma does not pass the
registration-failed fonts to the script on unregister command.
</p>
<pre>
sub register {
my $font = shift;
my $h = parse_hints_start(@_);
unless (exists($h->{Location}) || exists($h->{FontName})) {
return 1;
}
my @locs = split(/ /, $h->{Location});
my $fontname = $h->{FontName};
# If there're more than one fontnames, only the first one
# is used and the others are removed.
$fontname=~ s/ .*//;
if (grep($_ eq 'Japanese', @locs)) {
push(@ja, $fontname.' '.$font);
} elsif (grep($_ eq 'Korean', @locs)) {
push(@ko, $fontname.' '.$font);
} elsif (grep($_ eq 'Chinese-China', @locs)) {
push(@zh_cn, $fontname.' '.$font);
} elsif (grep($_ eq 'Chinese-Taiwan', @locs)) {
push(@zh_tw, $fontname.' '.$font);
} else {
push(@default, $fontname.' '.$font);
}
return 0;
}
sub unregister {
my $font = shift;
my $h = parse_hints_start(@_);
my $fontname = $h->{FontName};
$fontname =~ s/ .*//;
my $i;
for ($i = 0; $i < @default; $i++) {
$default[$i] = '' if ($default[$i] eq $fontname.' '.$font);
}
for ($i = 0; $i < @ja; $i++) {
$ja[$i] = '' if ($ja[$i] eq $fontname.' '.$font);
}
for ($i = 0; $i < @ko; $i++) {
$ko[$i] = '' if ($ko[$i] eq $fontname.' '.$font);
}
for ($i = 0; $i < @zh_cn; $i++) {
$zh_cn[$i] = '' if ($zh_cn[$i] eq $fontname.' '.$font);
}
for ($i = 0; $i < @zh_tw; $i++) {
$zh_tw[$i] = '' if ($zh_tw[$i] eq $fontname.' '.$font);
}
return 0;
}
</pre>
<p>
<samp>truetype()</samp> function is the same as the previous chapter's, so
please refer it. The generated file would go like:
</p>
<pre>
Helvetica /usr/share/fonts/truetype/helvetic.ttf
Courier /usr/share/fonts/truetype/courier.ttf
Times-Roman /usr/share/fonts/truetype/times.ttf
</pre>
<hr>
<p>
[ <a href="ch2.html">previous</a> ]
[ <a href="index.html#contents">Contents</a> ]
[ <a href="ch1.html">1</a> ]
[ <a href="ch2.html">2</a> ]
[ 3 ]
[ <a href="ch4.html">4</a> ]
[ <a href="ch5.html">5</a> ]
[ <a href="ch6.html">6</a> ]
[ <a href="ch7.html">7</a> ]
[ <a href="ch4.html">next</a> ]
</p>
<hr>
<p>
A Tutorial on Writing Defoma Configuration Script
</p>
<address>
Yasuhiro Take<br>
<br>
</address>
<hr>
</body>
</html>
|