Whole document tree
    

Whole document tree

A Tutorial on Writing Defoma Configuration Script - Using Defoma::Id (2)
[ previous ] [ Abstract ] [ Contents ] [ next ]

A Tutorial on Writing Defoma Configuration Script
Chapter 5 Using Defoma::Id (2)


This chapter describes another way of creating fonts.dir and fonts.alias files mentioned in the previous example. Only the different point is described, so please also refer the previous chapter.

The general strategy is, get a list of installed fonts and ids from the id-cache in term command and create the files using the list. Reading these files in init command, adding/removing a font and its id to/from @dir in do_install_real/do_remove_real, and codes for do_install_alias/do_remove_alias commands are not necessary now.

     	  sub init {
     	    unless ($Id) {
     	      $Id = defoma_id_open_cache();
     	    }
     	    return 0;
     	  }
     
     	  sub do_install_real {
     	    my $font = shift;
     	    my $id = shift;
     	    my $depfont = shift;
     	    my $depid = shift;
     	    my @hints = @_;
     
     	    $font =~ /^(.*)\/(.+)$/;
     	    my $fontfile = $2;
     
     	    symlink($font, $DIR.$fontfile) || return 1;
     	    return 0;
     	  }
     
     	  sub do_remove_real {
     	    my $font = shift;
     	    my $id = shift;
     	    my $depfont = shift;
     	    my $depid = shift;
     	    my @hints = @_;
     
     	    $font =~ /^(.*)\/(.+)$/;
     	    my $fontfile = $2;
     
     	    unlink($DIR.$fontfile);
     	    return 0;
     	  }
     
     	  sub truetype {
     	    my $com = shift;
     	    if ($com eq 'init') {
     	      return init();
     	    } elsif ($com eq 'term') {
     	      return term();
     	    } elsif ($com eq 'register') {
     	      return register(@_);
     	    } elsif ($com eq 'unregister') {
     	      return unregister(@_);
     	    } elsif ($com eq 'do-install-real') {
     	      return do_install_real(@_);
     	    } elsif ($com eq 'do-remove-real') {
     	      return do_remove_real(@_);
     	    }
     	    return 0;
     	  }

In term command, the script needs to obtain a list of installed fonts and ids. First the script creates fonts.dir file.

     	  my $i;
     	  my $font;
     	  my $fontfile;
     	  my $id;
     	  my $depid;
     
     	  my @list = defoma_id_get_font($Id, 'installed', type => 'SrI');
     
     	  open(F, '>'.$DIR.'fonts.dir');
     	  foreach $i (@list) {
     	    $font = $Id->{e_font}->[$i];
     	    $font =~ /^(.*)\/(.+)$/;
     	    $fontfile = $2;
     	    $id = $Id->{e_id}->[$i];
     
     	    print F "/$id ($fontfile) ;\n";
     	  }
     	  close F;

The defoma_id_get_font function searches ids that match the specified rules from the specified id-cache, and returns the indexes of id-cache which point to the matched fonts. In this example, the function returns the indexes of installed real names. Following is codes to create fonts.alias.

     	  my @list = defoma_id_get_font($Id, 'installed', type => 'SaI');
     
     	  open(F, '>'.$DIR.'fonts.alias');
     	  foreach $i (@list) {
     	    $id = $Id->{e_id}->[$i];
     	    $depid = $Id->{e_depid}->[$i];
     
     	    print F "/$id /$depid ;\n";
     	  }
     	  close F;


[ previous ] [ Abstract ] [ Contents ] [ next ]
A Tutorial on Writing Defoma Configuration Script
Yasuhiro Take