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
|
# gs.type1 -- Ghostscript type1 hooks for the DTM system
#
# Copyright (C) 1997-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_fontmap variable below the full path to the system-wide
# Fontmap file. (Or you can install Debian and forget about that.)
# The $user_fontmap variable should point to the personal Fontmap
# every user can have in its home directory: make sure it contains
# $HOME or is in a place writable by the user.
#
# the standard Fontmap in /usr/local/lib/ghostscripts/fonts
# my $sys_fontmap = '/usr/local/lib/ghostscript/fonts/Fontmap'
#
# the same but for distributions that install gs in /usr
# my $sys_fontmap = '/usr/lib/ghostscript/fonts/Fontmap'
#
# the Debian distribution keeps all the configuration files in
# /etc: the Fontmap in /usr is a link to /etc/gs.Fontmap
my $sys_fontmap = '/etc/gs.Fontmap';
#
# this is the standard for the user Fontmap in DTM
my $user_fontmap = "$ENV{HOME}/fonts/type1/outlines/Fontmap";
#
#### end of configuration ####
use strict;
# gets fontmap right
my $fontmap = ($> == 0 ? $sys_fontmap : $user_fontmap);
# install a new font by creating the right Fontmap entry
my $gs_install_font = sub {
my $catalog = shift;
my $snip = shift;
my $id = $snip->get_attr('ID');
my $psname = $snip->get_attr('Name', 'psspecific') or do {
dtm_warning("font with ID $id misses PostScript " .
"specific information; skipping");
return;
};
safe_system("cp $fontmap $fontmap.old")
if -r "$fontmap";
open(FONTMAP, ">>$fontmap") or do {
dtm_warning("can't open `$fontmap' for writing");
return;
};
# check if this font is an alias: if yes gets the Postscript
# name of the aliased font and uses it to build the Fontmap
# entryy
my $alias = $snip->get_attr('Alias');
if ($alias) {
my $aliasedfont = $catalog->find($alias);
my $aliasedid = $aliasedfont->get_attr('ID');
my $aliasedpsname = $aliasedfont->get_attr('Name', 'psspecific')
or do {
dtm_warning("font with ID $aliasedid is missing " .
"PostScript specific information; skipping");
return;
};
print "gs: creating alias: `$psname' -> `$aliasedpsname'\n"
if $verbose;
print FONTMAP "/$psname /$aliasedpsname ;\n";
}
else
{
my $file = $snip->get_attr('FontPath') . "/" .
$snip->get_attr('FontFile');
print "gs: installing `$file' as `$psname'\n"
if $verbose;
print FONTMAP "/$psname ($file) ;\n";
}
close(FONTMAP);
};
# removes a font from the fontmap: simply copies every line
# from the .old file to the new one skipping the right entry
my $gs_remove_font = sub {
my $catalog = shift;
my $snip = shift;
my $id = $snip->get_attr('ID');
my $psname = $snip->get_attr('Name', 'psspecific') or do {
dtm_warning("font with ID $id misses PostScript " .
"specific information; skipping");
return;
};
if (-r $fontmap) {
safe_system("cp $fontmap $fontmap.old");
}
else {
dtm_warning("the `Fontmap' file doesn't exist; " .
"can't remove font with ID $id");
return;
}
open(FONTMAP, ">$fontmap") or do {
dtm_warning("can't open `$fontmap' for writing");
return;
};
open(OLD, "$fontmap.old") or do {
dtm_warning("can't open `$fontmap.old' for writing");
return;
};
print "gs: purging entry `$psname'\n"
if $verbose;
while (<OLD>) {
next if /^\/$psname\s.+\s;/; # skips removed one
print FONTMAP $_;
}
close(FONTMAP);
close(OLD);
};
# these two hooks are not really required, but we use them to
# write a nice header for the Fontmap and to remove old files
# when the last font is deleted from the user home directory
my $nice_header = "
% Fontmap - standard font catalog for Ghostscript
%
% This file was automatically generated by the DTM system.
% Editing it by hand can cause the loss of font information.
% Please use the dtm program or the fountain interface.
\n";
# this one just writes the header to the user Fontmap
# I don't touch the system one because other fonts can
# be there (type1inst, old .gsf fonts, etc...)
my $gs_add_path = sub {
my $catalog = shift;
my $snip = shift;
my $path = shift;
if ($> != 0) { # not root!
open(FONTMAP, ">$fontmap") or do {
dtm_warning("can't open `$fontmap' for writing");
return;
};
print "gs: installing empty Fontmap in `$fontmap'\n"
if $verbose;
print FONTMAP $nice_header;
close(FONTMAP);
}
};
# as above, I remove the files only if they are owned by the
# user; I don't touch the system wide one.
my $gs_delete_path = sub {
my $catalog = shift;
my $snip = shift;
my $path = shift;
if ($> != 0) { # not root!
print "gs: removing `$fontmap'\n"
if $verbose;
safe_system("rm -f $fontmap $fontmap.old");
}
};
# install the hooks in the DTM system
add_hooks(0,
InstallingFont => $gs_install_font,
RemovingFont => $gs_remove_font,
AddingPath => $gs_add_path,
DeletingPath => $gs_delete_path);
1;
|