#!/usr/bin/perl -w
#
#  gen_scale_alias.pl v1.0  (Sunday, 1999-12-26)
#
#  A Perl script to generate xfonts-arphic-*.{scale,alias}
#  for the Debian GNU/Linux system
#
#  GNU GPL v2, Copyright (C) 1999, Anthony Fok <foka@debian.org>
#
#  Special thanks to the Chinese GNU/Linux Extension (CLE) Team
#  for the sample *.scale and *.alias files.


# Define meta-information

@fonts = qw/bsmi bkai gbsn gkai/;
@sizes = ( 8..20, 22, 24, 26, 28, 30, 32, 24, 36, 38, 40, 42, 48,
	   54, 60, 72, 80, 96, 108, 144 );

$foundry = 'Arphic';

# Define font-specific information

%bsmi = ( typeface => 'bsmi00lp',
	  familyname => 'AR PL Mingti2L Big5',
	  chinesename => '文鼎PL細上海宋',
	  defaultname => 'ming',
	  charset => 'big5-0' );

%bkai = ( typeface => 'bkai00mp',
	  familyname => 'AR PL KaitiM Big5',
	  chinesename => '文鼎PL中楷',
	  defaultname => 'kai',
	  charset => 'big5-0' );

%gbsn = ( typeface => 'gbsn00lp',
	  familyname => 'AR PL SungtiL GB',
	  chinesename => '恅隋PL潠惆冼',
	  defaultname => 'song',
	  charset => 'gb2312.1980-0' );

%gkai = ( typeface => 'gkai00mp',
	  familyname => 'AR PL KaitiM GB',
	  chinesename => '恅隋PL潠笢翱',
	  defaultname => 'kai',
	  charset => 'gb2312.1980-0' );

# Main program body

for $f (@fonts) {
    $i = 0;
    $bin_package = "xfonts-arphic-" . $$f{typeface};
    open(SCALE, ">$bin_package.scale.in\n");
    open(ALIAS, ">$bin_package.alias\n");

    for $c ($$f{charset}, qw/iso8859-1 iso8859-15 iso10646-1/) {
	for $w (qw/medium bold/) {
	    for $s (qw/r o/) {
		print SCALE $c =~ /^iso8859-/ ? 'bw=0.5:' : '';
		print SCALE $w eq 'bold' ? 'ds=y:' : '';
		print SCALE $s eq 'o' ? 'ai=0.167:' : '';
		print SCALE "vl=y:$$f{typeface}.ttf ";
		print SCALE "-$foundry-$$f{familyname}-$w-$s-normal-";
		print SCALE "-0-0-0-0-c-0-$c\n";
		$i++;
		for $size (@sizes) {
		    print ALIAS "\"-$foundry-$$f{familyname}-$w-$s-normal-";
		    print ALIAS "-$size-${size}0-72-72-c-";
		    print ALIAS $c =~ /^iso8859-/
			? $size % 2 == 0
			    ? $size * 5 : ($size + 1) * 5
			: $size * 10;
		    print ALIAS "-$c\" ";
		    print ALIAS "\"-$foundry-$$f{familyname}-$w-$s-normal-";
		    print ALIAS "-$size-${size}0-0-0-c-0-$c\"\n";
		}
	    }
	}
    }

    # Generate Chinese aliases
    #
    for $w (qw/medium bold/) {
	for $s (qw/r o/) {
	    print ALIAS "\"-$foundry-$$f{chinesename}-$w-$s-normal-";
	    print ALIAS "-0-0-0-0-c-0-$$f{charset}\" ";
	    print ALIAS "\"-$foundry-$$f{familyname}-$w-$s-normal-";
	    print ALIAS "-0-0-0-0-c-0-$$f{charset}\"\n";
	}
    }

    # Generate aliases: -default-ming-*, -default-kai-*, and -default-song-*
    #
    for $w (qw/medium bold/) {
	for $s (qw/r o/) {
	    print ALIAS "-default-$$f{defaultname}-$w-$s-normal-";
	    print ALIAS "-0-0-0-0-c-0-$$f{charset} ";
	    print ALIAS "\"-$foundry-$$f{familyname}-$w-$s-normal-";
	    print ALIAS "-0-0-0-0-c-0-$$f{charset}\"\n";
	    for $size (@sizes) {
		print ALIAS "-default-$$f{defaultname}-$w-$s-normal-";
		print ALIAS "-$size-${size}0-72-72-c-${size}0-$$f{charset} ";
		print ALIAS "\"-$foundry-$$f{familyname}-$w-$s-normal-";
		print ALIAS "-$size-${size}0-0-0-c-0-$$f{charset}\"\n";
	    }
	}
    }

    # Wrapping up...

    close(SCALE);
    close(ALIAS);
    open(SCALEI, ">$bin_package.scale\n");
    print SCALEI "$i\n";
    close(SCALEI);
    system("cat $bin_package.scale.in >> $bin_package.scale");
    unlink("$bin_package.scale.in");
}
