A Tutorial on Writing Defoma Configuration Script - Using x-postscript Category.
[ previous ]
[ Abstract ]
[ Contents ]
A Tutorial on Writing Defoma Configuration Script
Chapter 7 Using x-postscript Category.
Many X applications that output a PostScript file and substitute X fonts for
PostScript fonts for displaying want a list of PostScript fonts and substitute
X fonts. x-postscript category will satisfy this demand. A font in this
category is a name of PostScript font with `<X>/' prefix added, like
<X>/Times-Roman, and each font has a XLFD as a hint. The
XLFD is considered to have the most similar appearance to the PostScript font.
If the script wants to make use of x-postscript category, its package must
`Depends:' on psfontmgr.
The strategy of the Defoma-configuration script which accepts only x-postscript
category is to ignore all commands except term, and generate a configuration
file in term commands. To obtain available PostScript fonts and their
substitutive XLFDs, the script calls defoma_font_get_fonts()
function, which returns a list of fonts registered in the specified category,
and defoma_font_get_hints() function, which returns hints of the
specified font. All and only available (installed) x-postscript category fonts
are obtained through these functions.
Following is an example of the header of the script. Note that there's
declaration of using Defoma::Font module for
defoma_font_get_fonts() and defoma_font_get_hints()
functions.
@ACCEPT_CATEGORIES = ('x-postscript');
package example;
use Debian::Defoma::Font;
import Debian::Defoma::Font;
The main routine goes like this:
sub x_postscript {
my $com = shift;
return 0 if ($com ne 'term');
open(F, '>/var/lib/defoma/example.d/font.conf');
my @fonts = defoma_font_get_fonts('x-postscript');
foreach my $psfont (@fonts) {
my @hints = defoma_font_get_hints('x-postscript', $psfont);
$psfont =~ s/^\<X\<\///;
my $xfont = $hints[0];
print F "$psfont $xfont\n";
}
close F;
}
This simple codes will generate a list of PostScript fonts and XLFDs like
following.