home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / share / perl5 / Debian / Defoma / Font.pm < prev    next >
Encoding:
Perl POD Document  |  2006-06-17  |  4.3 KB  |  226 lines

  1. package Debian::Defoma::Font;
  2.  
  3. use strict;
  4. use POSIX;
  5. use Exporter;
  6.  
  7. use vars qw(@EXPORT @ISA %Fobjs $Userspace);
  8.  
  9. use Debian::Defoma::Common;
  10. import Debian::Defoma::Common qw(&arg_check &arg_check_category &get_files);
  11. use Debian::Defoma::FontCache;
  12.  
  13. @ISA = qw(Exporter);
  14. @EXPORT = qw(&defoma_font_init &defoma_font_register &defoma_font_unregister
  15.          &defoma_font_reregister &defoma_font_term
  16.          &defoma_font_if_register &defoma_font_get_fonts
  17.          &defoma_font_get_hints &defoma_font_get_failed
  18.          &defoma_font_get_object);
  19.  
  20. %Fobjs = ();
  21. $Userspace = 1;
  22.  
  23. sub defoma_font_init {
  24.     %Fobjs = ();
  25.     &Debian::Defoma::FontCache::initialize(ROOTDIR);
  26.  
  27.     my @list = get_files("\\.font-cache\$", ROOTDIR);
  28.     my $o;
  29.     my $i;
  30.     
  31.     foreach $i (@list) {
  32.     $i =~ s/\.font-cache$//;
  33.  
  34.     $o = new Debian::Defoma::FontCache($i);
  35.     $o->read();
  36.     $Fobjs{$i} = $o;
  37.     }
  38.  
  39.     return 0;
  40. }
  41.  
  42. sub defoma_font_check_font {
  43.     my $font = shift;
  44.     my @list = values(%Fobjs);
  45.     
  46.     foreach my $fobj (@list) {
  47.     if (exists($fobj->{cache_list}->{$font})) {
  48.         return $fobj->{category};
  49.     }
  50.     }
  51.  
  52.     return '';
  53. }
  54.  
  55. sub defoma_font_get_object {
  56.     my $category = shift;
  57.  
  58.     unless (exists($Fobjs{$category})) {
  59.     my $fo = $Fobjs{$category} = new Debian::Defoma::FontCache($category);
  60.     }
  61.  
  62.     return $Fobjs{$category};
  63. }
  64.  
  65. sub defoma_font_register {
  66.     my $category = shift;
  67.     my $font = shift;
  68.     my @hints = @_;
  69.  
  70.     arg_check($font, $category) || return 1;
  71.     arg_check_category($category) || return 1;
  72.  
  73.     my $fobj;
  74.     if (exists($Fobjs{$category})) {
  75.     $fobj = $Fobjs{$category};
  76.     } else {
  77.     $fobj = $Fobjs{$category} = new Debian::Defoma::FontCache($category);
  78.     }
  79.  
  80.     my $s = defoma_font_check_font($font);
  81.     if ($s ne '') {
  82.     printw("$font: already registered in category $s.");
  83.     return 1;
  84.     }
  85.  
  86.     $fobj->add_font($font, @hints);
  87.     $fobj->add_user($font) if (USERSPACE && $Userspace);
  88.     $Userspace = 1;
  89.  
  90.     printv("Registering $font..");
  91.  
  92.     &Debian::Defoma::Configure::call_m($fobj, 'register', $category, $font,
  93.                        @hints);
  94.  
  95.     return 0;
  96. }
  97.  
  98. sub defoma_font_unregister {
  99.     my $category = shift;
  100.     my $font = shift;
  101.     my $fobj;
  102.     
  103.     unless (exists($Fobjs{$category})) {
  104.     printw("$category: Category not found.");
  105.     return 1;
  106.     }
  107.  
  108.     $fobj = $Fobjs{$category};
  109.  
  110.     unless (exists($fobj->{cache_list}->{$font})) {
  111.     printw("$font: not registered.");
  112.     return 1;
  113.     }
  114.  
  115.     my @hints = split(' ', $fobj->{cache_list}->{$font});
  116.  
  117.     printv("Unregistering $font..");
  118.  
  119.     &Debian::Defoma::Configure::call_m($fobj, 'unregister', $category, $font,
  120.                        @hints);
  121.  
  122.     $fobj->remove_font($font);
  123.     $fobj->remove_user($font) if (USERSPACE);
  124.  
  125.     return 0;
  126. }
  127.  
  128. sub defoma_font_reregister {
  129.     my $category = shift;
  130.     my $font = shift;
  131.     my @hints0;
  132.  
  133.     my $c = defoma_font_check_font($font);
  134.  
  135.     if ($c ne '') {
  136.     if ($c eq $category) {
  137.         @hints0 = defoma_font_get_hints($c, $font);
  138.         
  139.         if (@hints0 == @_) {
  140.         my $i = 0;
  141.         while ($i < @hints0 && $i < @_) {
  142.             last if ($hints0[$i] ne $_[$i]);
  143.             $i++;
  144.         }
  145.  
  146.         return 0 if ($i == @_);
  147.         }
  148.     }
  149.  
  150.     defoma_font_unregister($c, $font);
  151.     }
  152.  
  153.     my $r = defoma_font_register($category, $font, @_);
  154.     
  155.     return $r;
  156. }
  157.  
  158. sub defoma_font_term {
  159.     my $fobj;
  160.     my @list = values(%Fobjs);
  161.  
  162.     foreach $fobj (@list) {
  163.     $fobj->write();
  164.     }
  165.  
  166.     return 0;
  167. }
  168.  
  169. sub defoma_font_if_register {
  170.     my $category = shift;
  171.     my $font = shift;
  172.  
  173.     if (exists($Fobjs{$category})) {
  174.     return 1 if (exists($Fobjs{$category}->{cache_list}->{$font}));
  175.     }
  176.  
  177.     return 0;
  178. }
  179.  
  180. sub defoma_font_get_fonts {
  181.     my $category = shift;
  182.     my @ret = ();
  183.  
  184.     if (exists($Fobjs{$category})) {
  185.     my $fobj = $Fobjs{$category};
  186.     @ret = keys(%{$fobj->{cache_list}});
  187.     }
  188.  
  189.     return @ret;
  190. }
  191.  
  192. sub defoma_font_get_hints {
  193.     my $category = shift;
  194.     my $font = shift;
  195.     my @ret = ();
  196.  
  197.     if (exists($Fobjs{$category})) {
  198.     my $fobj = $Fobjs{$category};
  199.     if (exists($fobj->{cache_list}->{$font})) {
  200.         @ret = split(' ', $fobj->{cache_list}->{$font});
  201.     }
  202.     }
  203.  
  204.     return @ret;
  205. }
  206.  
  207. sub defoma_font_get_failed {
  208.     my $category = shift;
  209.     my $font = shift;
  210.     my %ret = ();
  211.  
  212.     if (exists($Fobjs{$category})) {
  213.     my $fobj = $Fobjs{$category};
  214.     if (exists($fobj->{fcache_list}->{$font})) {
  215.         %ret = %{$fobj->{fcache_list}->{$font}};
  216.     }
  217.     }
  218.  
  219.     return %ret;
  220. }
  221.  
  222. 1;    
  223.     
  224.     
  225.     
  226.