#! /usr/bin/perl -w # Defoma - Debian Font Manager # Copyright (C) 2000 Yasuhiro Take # This program is free software. You can freely use, copy, modify, and # redistribute it under the terms of the GNU General Public License, Version 2. use Debian::Defoma::Font; import Debian::Defoma::Font; use Debian::Defoma::Common; import Debian::Defoma::Common qw($DEFOMA_TEST_DIR USERSPACE $ROOTDIR); exit 0 if (USERSPACE); #defoma_common_init(); $LIBDIR= "$DEFOMA_TEST_DIR/usr/share/defoma"; $CONFDIR= "$DEFOMA_TEST_DIR/etc/defoma"; $DATAFILE = "$LIBDIR/psprfonts.data"; $DATAFILE2 = "$LIBDIR/psprfonts.data2"; $CACHEFILE = "$ROOTDIR/psfontmgr.d/psprint.font-cache"; $HINTFILE = "$ROOTDIR/psfontmgr.d/ps-hints.private-cache"; $CEDATAFILE = "$CONFDIR/ps-cset-enc.data"; $PREFIX = 'pspr1'; @EXITREMOVE = (); $SIG{'HUP'} = \&exitfunc; $SIG{'INT'} = \&exitfunc; $SIG{'QUIT'} = \&exitfunc; $SIG{'TERM'} = \&exitfunc; $SIG{'__DIE__'} = \&emes; @CHARSET_LIST = ('Standard', 'Standard Roman charset.', 'Special', 'font-specific charset.', 'Adobe-Japan1', 'Japanese standard charsets.', 'Adobe-Japan2', 'Japanese extended charsets.', 'Adobe-Korea1', 'Korean charsets.', 'Adobe-CNS1', 'Traditional Chinese charsets.', 'Adobe-GB1', 'Simplified Chinese charsets.'); %FAMILY2GFAMILY_LIST = (); $CUT = '/usr/bin/cut'; require("$LIBDIR/libperl-hint.pl"); sub exitfunc { my $e = (@_ > 0) ? shift(@_) : 0; $e = 0 if ($e =~ /[^0-9]/); unlink @EXITREMOVE if (@EXITREMOVE); exit $e; } sub emes { my $msg = shift; print 'defoma-psfont-installer: ', $msg, "\n"; exitfunc 1; } my $RETCHARSET; my $RETENCODING; my @STANDARD_LINES; sub read_standard { my $lcharset; my $lencoding; my $lscharset; my $lsencoding; open(F, $CEDATAFILE) || return 0; while () { chomp($_); next if ($_ eq '' || $_ =~ /^\#/); my @list = split(/[ \t]+/, $_); next if (@list < 3); next if ($list[0] eq ''); push(@STANDARD_LINES, join(' ', @list)); } close F; return 0; } sub get_standard { my $acharset = shift; my $aencoding = shift; $RETCHARSET = $RETENCODING = ''; my $line; foreach (@STANDARD_LINES) { $line = $_; my @list = split(/[ \t]+/, $line); my $lcharset = $list[0]; my $lencoding = $list[1]; my $lscharset = $list[2]; my $lsencoding = (@list > 3) ? $list[3] : ''; $lcharset =~ s/\*/\.\*/g; $lcharset =~ s/\?/\./g; $lencoding =~ s/\*/\.\*/g; $lencoding =~ s/\?/\./g; if ($acharset =~ /^($lcharset)$/ && $aencoding =~ /^($lencoding)$/) { $RETCHARSET = $lscharset; $RETENCODING = $lsencoding; return 1; } } return 0; } sub get_standard_list { my $acharset = shift; my @ret = (); my $line; foreach (@STANDARD_LINES) { $line = $_; my @list = split(/[ \t]+/, $line); next if ($list[2] eq 'ignore'); my $lcharset = $list[0]; my $lscharset = $list[2]; if (@list > 3) { $lscharset .= ' '; $lscharset .= $list[3]; } $lcharset =~ s/\*/\.\*/g; $lcharset =~ s/\?/\./g; if (! $acharset || $acharset =~ /^($lcharset)$/) { push(@ret, $lscharset); } } return @ret; } my @HINTTYPE = qw(Family GeneralFamily Weight Width Shape PSCharset PSEncoding Direction); my @HINTFILE_DATA; my @DATAFILE_DATA; my @DATAFILE2_DATA; sub clear_hints { my $hashptr = shift; foreach my $i (@HINTTYPE) { $$hashptr{$i} = ''; } } sub parse_hints { my $hashptr = shift; my $pattern = join('|', @HINTTYPE); my $i; clear_hints($hashptr); while (@_ > 0) { $i = shift; if ($i =~ /^--($pattern)$/) { $i = $1; while (@_ > 0) { my $j = shift; if ($j =~ /^--/) { unshift(@_, $j); last; } if ($i =~ /^(Shape|Weight)$/) { $$hashptr{$i} .= ' ' if ($$hashptr{$i} ne ''); $$hashptr{$i} .= $j; } else { $$hashptr{$i} = $j; } } } } } sub read_hints { if (open(F, $HINTFILE)) { while () { chomp($_); push(@HINTFILE_DATA, $_); } close F; } if (open(F, $DATAFILE)) { while () { chomp($_); push(@DATAFILE_DATA, $_); } close F; } if (open(F, $DATAFILE2)) { while () { chomp($_); push(@DATAFILE2_DATA, $_); } close F; } for my $i (@HINTFILE_DATA, @DATAFILE_DATA, @DATAFILE2_DATA) { my @list = split(' ', $i); my %hints = (); parse_hints(\%hints, @list); if ($hints{'Family'} ne '' && $hints{'GeneralFamily'} ne '') { $FAMILY2GFAMILY_LIST{$hints{'Family'}} = $hints{'GeneralFamily'}; } } } sub get_not_registered_font { my %list = (); my $psfontname; my @ret = (); foreach (@DATAFILE_DATA) { $psfontname = $_; $psfontname =~ s/^([^ ]+).*/$1/; $list{$psfontname} = 1; } foreach (@HINTFILE_DATA) { $psfontname = $_; $psfontname =~ s/^([^ ]+).*/$1/; $list{$psfontname} = 1; } if (open(F, $CACHEFILE)) { while () { $psfontname = $_; chomp($psfontname); $psfontname =~ s/^([^ ]+).*/$1/; if ($psfontname =~ /^$PREFIX\//) { delete($list{$'}); } } close F; } @ret = sort (keys(%list)); return @ret; } sub get_hints { my $font = shift; my $pscharset = shift; my $psencoding = shift; my $hashptr = shift; my $tmp; my @list; my $line; foreach (@HINTFILE_DATA) { $line = $_; @list = split(' ', $line); if ($list[0] eq $font) { $tmp = shift(@list); parse_hints($hashptr, @list); unless ($$hashptr{'Charset'}) { $$hashptr{'PSCharset'} = $pscharset; $$hashptr{'PSEncoding'} = $psencoding; } return 1; } } foreach (@DATAFILE_DATA) { $line = $_; @list = split(' ', $line); if ($list[0] eq $font) { $tmp = shift(@list); $pscharset = shift(@list); $psencoding = shift(@list); parse_hints($hashptr, @list); $$hashptr{'PSCharset'} = $pscharset; $$hashptr{'PSEncoding'} = $psencoding; return 1; } } foreach (@DATAFILE2_DATA) { $line = $_; @list = split(' ', $line); $list[0] =~ s/\*/\.\*/g; $list[0] =~ s/\?/\./g; if ($font =~ /^($list[0])$/) { $tmp = shift(@list); parse_hints($hashptr, @list); $$hashptr{'PSCharset'} = $pscharset; $$hashptr{'PSEncoding'} = $psencoding; return 1; } } return 0; } my $PSCHARSET; my $PSENCODING; sub input_ps_charset_encoding { my $font = shift; my $defcset = shift; my $defenc = shift; my $text; my $pscharset; my $psencoding = ''; $PSCHARSET = ''; $PSENCODING = ''; $text = <', $text, @CHARSET_LIST, '', ' '); return if ($result != 0); if ($pscharset =~ /^(Standard|Special)$/) { $psencoding = $pscharset; } else { my $cmaplist = ''; my $cmapfile = "$ROOTDIR/psfontmgr.d/$pscharset.cmaps.private-cache"; if (-f $cmapfile) { $cmaplist = `$CUT -d ' ' -f 1 $cmapfile`; } elsif (-f ($cmapfile = "$LIBDIR/$pscharset.default-cmap")) { $cmaplist = `/bin/cat $cmapfile`; } if ($cmaplist ne '') { $text = <', $text, split(/\n/, $cmaplist), ''); } else { $psencoding = input_menu("Input the Encoding of $font.", $defenc, '[^ ]', 0); } return if ($result != 0); } $PSCHARSET = $pscharset; $PSENCODING = $psencoding; return; } my $S_CHARSET; my $S_ENCODING; sub get_charset_encoding { my $font = shift; my $pscharset = shift; my $psencoding = shift; my $text; my $charset = ''; my $encoding = ''; $S_CHARSET = ''; $S_ENCODING = ''; if (get_standard($pscharset, $psencoding) == 0) { $text = <') if (@list > 0); my $ret = input_menu($text2, '', '.', 0, '', $text, @list); return 0 if ($result != 0); @list = split(' ', $ret); $charset = $list[0]; $encoding = $list[1] if (@list > 1); } else { $charset = $RETCHARSET; $encoding = $RETENCODING; } $charset =~ s/,/ /g; $S_CHARSET = $charset; $S_ENCODING = $encoding; return 1; } sub get_generalfamily { my $font = shift; my $family = shift; my %hints; my $ret; if (exists($FAMILY2GFAMILY_LIST{$family})) { $result = 0; return $FAMILY2GFAMILY_LIST{$family}; } $ret = input_generalfamily($font, ''); return if ($result != 0); $FAMILY2GFAMILY_LIST{$family} = $ret; } sub create_hintslines { my $font = shift; my $hintsptr = shift; my $verbose = shift; my $pcset = $$hintsptr{'PSCharset'}; my $penc = $$hintsptr{'PSEncoding'}; my $text = < $tempfile"); if (open(F, $tempfile)) { while () { my $line = $_; chomp($line); if ($line =~ /^\*Font /) { @list = split(' ', $line); $font = $list[1]; $font =~ s/:$//; next if ($font =~ /[^a-zA-Z0-9.-]/); $encoding = $list[2]; $charset = $list[4]; $hints = new_font($verbose, $font, $charset, $encoding); return $result if ($result != 0); if ($hints ne '') { push(@HINTFILE, $hints); } else { push(@SKIPPED, $font); } } } close F; } unlink($tempfile); $tempfile = pop(@EXITREMOVE); return 0; } sub com_register_2b { my $verbose = shift; my $font; my $hints; my @list; my $text; @list = get_not_registered_font(); if (@list > 0) { $text = < 0) { my $file = "$DEFOMA_TEST_DIR/etc/defoma/hints/defoma-ps.hints"; unless (open(F, ">$file")) { $text = < /dev/null 2>&1"); msgbox($text); } else { print "Registering fonts...\n"; system($command); print $text; } } else { if ($NOOUTPUT) { msgbox("No font gets registered. "); } else { print("No font gets registered. "); } } } sub note { my $text = < 0) { my $s = shift(@ARGV); $NOOUTPUT = 1 if ($s eq '--no-output'); $MODE = 'c' if ($s eq '-c'); } defoma_font_init(); hint_beginlib($DIALOGTITLE, $DWIDTH, $MODE); read_hints(); read_standard(); note(); com_register(); exitfunc(0);