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
|
# autometrics.type1 -- Automatic generation of AFM files
#
# Copyright (C) 1998 Federico Di Gregorio.
#
# This program is part of the Definitive Type Manager package.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#### configuration options #####
#
my $verbose = 0;
#
# To configure this file to your needs you can assign to the
# $sys_metrics variable below the full path to the system-wide
# type1 metric directory.
# Another option is to install the Debian distribution and
# forget about that!
#
# The $user_metrics variable should point to the personal metrics
# directory that a user can have in its home directory: make sure
# it contains $HOME or is in a place writable by the user.
#
# the standard metrics path
my $sys_metrics = '/usr/share/fonts/type1/metrics';
#
# this is the standard for the user metrics directory in DTM
my $user_metrics = "$ENV{HOME}/fonts/type1/metrics";
#
#
# The $printafm variable should be set to point to an executable
# with the ability to extract .afm information from a .pfa or
# .pfb font just like the printafm program in ghostscript.
# It should send its output to stdout.
my $printafm = 'printafm';
#
#### end of configuration ####
use strict;
# gets path right and creates if doesn't exists
my $metrics_path = ($> == 0 ? $sys_metrics : $user_metrics);
safe_system("install -d $metrics_path") if !(-d $metrics_path);
# if the font doesn't have metrics generates them
my $autometrics_install_font = sub {
my $catalog = shift;
my $snip = shift;
my $metrics = $snip->get_attr('Metrics');
my $id = $snip->get_attr('ID');
my $alias_id = $snip->get_attr('Alias');
# i need the psname to generate the right metrics name
my $psname = $snip->get_attr('Name', 'psspecific') or do {
dtm_warning("autometrics: font with ID $id misses PostScript " .
"specific information; skipping");
return;
};
if (!$metrics or $metrics eq 'NO') {
my $file;
if ($alias_id) {
my $alias = $catalog->find($alias_id);
$file = $alias->get_attr('FontPath') . '/' .
$alias->get_attr('FontFile');
}
else {
$file = $snip->get_attr('FontPath') . '/' .
$snip->get_attr('FontFile');
}
my $metrics_file = "$metrics_path/$psname.afm";
# prints some info
do {
print "autometrics: generating AFM for font $psname in\n";
print "autometrics: $metrics_file\n";
} if $verbose;
safe_system("$printafm $file >$metrics_file.tmp");
# finds the name and converts it to the *real* psname
open(TMP, "$metrics_file.tmp") or do {
dtm_warning("autometrics: can't open `$metrics_file.tmp' " .
"for reading");
return;
};
open(METR, ">$metrics_file") or do {
dtm_warning("autometrics: can't open `$metrics_file' for writing");
return;
};
while (<TMP>) {
if (/^FontName/) {
print METR "FontName $psname\n";
next;
}
print METR $_;
}
safe_system("rm -f $metrics_file.tmp");
$snip->set_attrs(undef,
Metrics => 'AFM',
MetricsPath => $metrics_path,
MetricsFile => "$psname.afm");
$snip->set_attr('PurgeFiles', "$metrics_file",
'autometrics');
}
};
# removes autometrics files
my $autometrics_remove_font = sub {
my $catalog = shift;
my $snip = shift;
my $purge_files = $snip->get_attr('PurgeFiles', 'autometrics');
# prints some info
print "autometrics: purging file(s): " .
"$purge_files\n"
if $verbose;
safe_system("rm -f $purge_files") if $purge_files;
};
# install the hooks in the DTM system
add_hooks(1,
InstallingFont => $autometrics_install_font,
RemovingFont => $autometrics_remove_font);
1;
|