Whole document tree
    

Whole document tree

A Tutorial on Writing Defoma Configuration Script - Using Defoma::Subst module.
[ previous ] [ Abstract ] [ Contents ] [ next ]

A Tutorial on Writing Defoma Configuration Script
Chapter 6 Using Defoma::Subst module.


This document describes How to write Defoma-configuration script using font substitution mechanism. Font substitution mechanism makes fonts substitute for a certain id described in a subst-rule. The subst-rule file describes required ids and their appearance information as hints, called rules, so that more similar fonts substitute for the described required id. Substitutive fonts are registered in a subst-cache. When a new id is added to a subst-rule, fonts registered in the subst-cache similar to the id will substitute for the id.

Usually a subst-rule may be edited by users, but there is one that cannot be edited. It is called private subst-rule. Private subst-rule is supposed to add/remove rules from a Defoma-configuration script. This chapter describes a modifiable subst-rule.

The script needs to call defoma_subst_open() in init command. This function opens the subst-rule and subst-cache specified by the rulename argument. You need to specify the id-cache to which the substituted ids are registered.

     	  ...
     	  $Id = defoma_id_open_cache();
     	  $Sb = defoma_subst_open(rulename => 'gsfonts',
     	                          idobject => $Id);
     	  ...

The script needs to call defoma_subst_register() and defoma_subst_unregister() functions in register and unregister commands respectively. You need to pass the substitutive font and its realname to the arguments. It is required to pass the hints of the font to the arguments of defoma_id_register() on registering the real name.

     	  sub register {
     	    ...
     	    defoma_id_register($Id, type => 'real', font => $font,
     	                       id => $realname, priority => $priority,
     	                       hints => join(' ', @hints));
     	    defoma_subst_register($Sb, $font, $realname);
     	    ...
     	  }
     
     	  sub unregister {
     	    ...
     	    defoma_subst_unregister($Sb, $font);
     	    defoma_id_unregister($Id, type => 'real', font => $font);
     	    ...
     	  }

The script needs to call defoma_subst_close() in term command.

     	  ...
     	  defoma_subst_close($Sb);
     	  defoma_id_close_cache($Id);
     	  ...

The substituted ids are directly registered to the id-cache. Then Defoma::Id module calls back the script with do-install-subst and do-remove-subst commands, so the script must handle these commands.

     	  type1 {
     	    my $com = shift;
     	    if (
     	    ...
     	    } elsif ($com =~ /^do-install-(alias|subst)$/) {
     	      return do_install_alias(@_);
     	    } elsif ($com =~ /^do-remove-(alias|subst)$/) {
     	      return do_remove_alias(@_);
     	    }
     	    ...
     	  }

This example unite the operation for -subst into -alias. It it appropriate because substituted ids are considered as alias.


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