summaryrefslogtreecommitdiffstats
path: root/perl-install/standalone/drakfont
blob: 00fb2723d8ae01939c585cc3e6a2b2308ab9eac4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
#!/usr/bin/perl -w
# drakfont Future Overview
#         - Fonts import :
#                 pfb ( Adobe Type 1 binary )
#                 pfa ( Adobe Type 1 ASCII )
#                 ttf ( True-Type  )
#                 pcf.gz
#                 Speedo
#                 and Bitmap (PCF, BDF, and SNF)
#         - Features
#                 - Install fonts from any directory
#                 - Get windows fonts on any vfat partitions
#                 - Get fonts on any partitions.
#                 - UN-installation of any fonts (even if not installed through drakfont)
#         - Support
#               - Xfs
#               - ghostscript & printer
#               - Staroffice & printer
#               - abiword
#               - Koffice, Gnumeric, ... studying
#               - all fonts supported by printer
#               - anti-aliases by RENDER in Xfree86 .... 
# 				supported by KDE.
# 				will be supported by gnome 1.2.
# Visual Interface:
#         Window interface:
#           - Fontselectiondialog widget
#           - Command buttons under Fontselectiondialog (like the actual frontend).
#         Commands buttons:
#           - import from windows partition.
#                 import from all fat32 partitions and look for winnt/windows/font
#                 and import all (delete doublon) but don't import if already exist.
#           - import from directory
#                 look for if it exist before for each font and not delete the original.
#                 (replace all, no, none)
#                 expert options:
#                         ask the directory, and look for if it exist before
#                         if it exist ask: (replace all, no, none)
#           - uninstall with list per font type
#         Expert additional switch
#           - option support:   ghostscript, Staroffice, etc...
#                 check-button. (by default all check)
#           - Printer Application Fonts Support...
#                 check-button. (by default all check)
#
# TODO:
#     - abiword, Koffice, Gnumeric, ...  
#     - Speedo  and Bitmap (PCF, BDF, and SNF)
#                
# REQUIRE:
#     - font-tools.*.mdk.i586.rpm
#
# USING:
#    -  pfm2afm:   by Ken Borgendale: Convert a Windows .pfm  file to a .afm (Adobe Font Metrics)
#    -  type1inst: by James Macnicol: type1inst generates files fonts.dir fonts.scale & Fontmap.
#    -  ttf2pt1:   by Andrew Weeks, Frank Siegert, Thomas Henlich, Sergey Babkin  convert ttf font files to afm and pfb fonts
#
#
# directory to install fonts /usr/X11R6/lib/X11/fonts/
# -->> /usr/X11R6/lib/X11/fonts/drakfont


use Gtk;
use lib qw(/usr/lib/libDrakX);
use interactive;
use standalone;
use my_gtk qw(:helpers :wrappers);
use common;
use strict;
use MDK::Common::Globals "network", qw($in $prefix $connect_file $disconnect_file $connect_prog);


if ("@ARGV" =~ /--help|-h/) {
    print q(Font Importation and monitoring appli    $check11->signal_connect( 'toggled',  sub { $gs == 0 and $gs = 1 or $gs = 0; print "gs =  $gs\n" });
cation
--windows_import : import from all available windows partitions.
--xls_fonts      : show all fonts that already exist from xls
--strong         : strong verification of font.
--install        : accept any font file and any directry.
--uninstall      : uninstall any font or any directory of font.
--replace        : replace all font if already exist
--application    : 0 none application.
                 : 1 all application available supported.
                 : name_of_application like  so for staroffice 
                 : and gs for ghostscript for only this one.
);
    exit(0);
}

#   global variables needed by each functions
my $xlsfonts = 0;
my $windows = 0;
my $strong;
my $replace;
my $application;
my $install;
my $uninstall;
my $so = 1;
my $gs = 1;
my $abi = 1;
my $printer = 1;
my $mode = -1;
my @application;
my @install;
my @uninstall;
my $interactive;
my $text;
my $vscrollbar;
my $check4;
my $check1;
my $check2;
my $check3;
my $pbar;
my $pbar1;
my $pbar2;
my $pbar3;
my $font_box;
my $central_widget;
my $label1;
my $label2;
my $label3;
my $label4;

foreach (@ARGV) {
    /--xls_fonts/ and $xlsfonts = 1, $mode=-1;
    /--windows_import|-wi/ and $windows = 1, $mode=-1;
    /--strong|-s/ and $strong = 1, $mode=-1;
    /--replace|-r/ and $replace = 1, $mode=-1;
    /--application/ and $mode = 0, next;
    $mode == 0 and push @application, $_;
    /--install/ and $mode = 1, next;
    $mode == 1 and push @install, $_;
    /--uninstall/ and $mode = 2, next;
    $mode == 2 and push @uninstall, $_;
}



foreach my $i (@application) {
    if ( $i =~ /so/i) {
	if ( $gs != 2 ) { $gs = 0;}
	$so = 2;
    }
    if ($i  =~ /gs/i){ 
	if ( $so != 2 ) { $so = 0; }
	$gs = 2;
    }
}

# only debug
# print "app : @application\n";
# print "install : @install\n";
# print "uninstall : @uninstall\n";
# print "applications supproted: so: $so  gs: $gs \n";


# PATH and binary full path
my $xfs_conffile = '/etc/X11/fs/config';
my $drakfont_dir = '/home/damien/new2_drakfont'; # '/usr/X11R6/lib/X11/fonts/drakfont';
my $ttf2pt1 = '/usr/sbin/ttf2pt1';
my $pfm2afm = '/usr/sbin/pfm2afm';
my $type1inst = '/usr/sbin/type1inst';
my $chkfontpath = '/usr/sbin/chkfontpath';
my $ttmkfdir = '/usr/sbin/ttmkfdir';
my $ghostscript;

# Global lists, just to manipulate it easily.
# my @font_list                    => list of fonts to install.
# my @installed_fonts;             => list of installed fonts.
# my @installed_fonts_path;        => list of path included in xfs.
# my @fontsdir_to_install;         => list of fonts to uninstall.
# my @fontsdir_to_uninstall;       => path to remove in xfs font file.
# my @installed_fonts_full_path;   => full path list of fonts to uninstall.

my @font_list;
my @installed_fonts;
my @installed_fonts_path;
my @fontsdir_to_install;
my @fontsdir_to_uninstall;
my @installed_fonts_full_path;


sub list_fontpath {
    foreach (grep { /\d+:\s/ } `$chkfontpath -l`) {
	chomp;
	s/\d+:\s//gi;
	s/:\w*$//gi;
	push @installed_fonts_path, $_;
    }
}

sub search_installed_fonts {
    list_fontpath();
    $interactive and progress($pbar, 0, _("search installed fonts"));
    push @installed_fonts, all($_) foreach @installed_fonts_path;
    $interactive and progress($pbar, 100/3, _("Search fonts in install list"));
}

sub search_installed_fonts_full_path {
    list_fontpath();
    foreach my $i (@installed_fonts_path) {
	foreach my $j (all($i)) {
	    push @installed_fonts_full_path, "$i/$j";
	}
    }
}

sub search_windows_font {
    foreach my $fstab_line (grep { /ext2/ } cat_('/etc/mtab') ) {
	my $win_dir = (split('\s', $fstab_line))[1];
	my @list_fonts_win = all("$win_dir/windows/fonts");
	my @list_fonts_winnt = all("$win_dir/winnt/fonts");
	my $nb_dir = @list_fonts_win + @list_fonts_winnt;
	if(!@list_fonts_win && !@list_fonts_winnt) {
	    print "drakfont:: could not find any font in $win_dir/win*/fonts \n";
	    $interactive and display_error(_("could not find any font in %s/win*/fonts", $win_dir));
	    return 0;
	}
	foreach $_ ([\@list_fonts_win, "windows"], [\@list_fonts_winnt, "winnt"]) {
	    foreach my $i (@{$_->[0]}) {
		if($interactive) {
		    if($nb_dir) { progress($pbar, 34/$nb_dir, "toto") } else {
			display_error(_("no fonts found"));
			return 0;
		    }
		}
		!$replace && grep(/$i/, @installed_fonts) and next;
		grep ( /$i$/, @font_list) or push @font_list, "$win_dir/$_->[1]/fonts/$i";
	    }
	}
	$interactive && $nb_dir and  progress($pbar, 100/3, "toto");
    }
    1;
}

sub is_a_font {
    local $_ = $_[0];
    /.ttf$/i || /.pfa$/i || /.pfb$/i || /.pcf$/i || /.pcf.gz$/i || /.pfm$/i || /.gsf$/;
}

sub search_dir_font {
    my ($fn) = @_;
    my @font_list_tmp = ();
    my @font_list_tmpp = ();
    my $dir ;
    if (!(-e $fn )) { print "$_ :: no such file or directory \n" } else {
	if ( -d $fn ) {
	    $dir = $fn;
# fixme : faire test avant sur les repertoiers ne pas avoir plusieurs fosi le meme rep!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 
	    foreach my $i (all($fn)) {
		if (is_a_font($i)) {
		    push @font_list_tmp, "$i";
		    foreach my $i (@font_list_tmp) {
			!$replace && grep(/$i/, @installed_fonts) and next;
			grep /$i/, @font_list or push @font_list, "$fn/$i";
		    }
		}
	    }
	} else {
	    if (is_a_font($fn)) {
		!$replace && grep(/$fn/, @installed_fonts) and next;
		!grep /$fn/, (@installed_fonts) and push @font_list, "$fn";
	    }
	}
    }
    $interactive and progress($pbar, 2*100/3, _("Search fonts in install list"));
}

sub search_dir_font_uninstall {
    my @font_list_tmp = ();
    my $fn = $_;
    if ( -d $fn ) { 
	foreach my $i (all($fn)) {
	    if (is_a_font($i)) { push @font_list_tmp, "$i"; }
	}
    }
    else { if (is_a_font($fn)) { push @font_list_tmp, "$fn"; }
       }
    foreach my $i (@installed_fonts_full_path) {
	foreach my $j (@font_list_tmp) {
	    if ( $i =~ /$j/) { push @font_list, "$i" ;}
	}
    }
    print "Fonts to uninstal : " . $_ . "\n" foreach (@font_list);
}

sub print_list { print "Font(s) to Install :\n\n"; print "$_\n" foreach (@font_list) }

sub dir_created {
    -e $drakfont_dir		    || mkdir_p($drakfont_dir);
    -e $drakfont_dir . "/Type1"	    || mkdir_p($drakfont_dir."/Type1"); 
    -e $drakfont_dir . "/ttf"	    || mkdir_p($drakfont_dir."/ttf");
    -e $drakfont_dir . "/tmp"	    || mkdir_p($drakfont_dir."/tmp");
    -e $drakfont_dir . "/tmp/ttf"   || mkdir_p($drakfont_dir."/tmp/ttf");
    -e $drakfont_dir . "/tmp/Type1" || mkdir_p($drakfont_dir."/tmp/Type1");
    -e $drakfont_dir . "/tmp/tmp"   || mkdir_p($drakfont_dir."/tmp/tmp");
}

sub put_font_dir {
  -e "/usr/share/ghostscript" or $gs = 0 && print "ghostscript is not installed on your system...\n"  ;
  if (@font_list) {
    dir_created();
    foreach my $i (@font_list) {
	cp_af($i, $drakfont_dir . "/tmp/tmp");
	$interactive and progress($pbar1, 100/@font_list, _("Fonts copy"));
    }
    system ("cd $drakfont_dir/tmp/tmp   && cp *.ttf ../../ttf");
    system ("cd $drakfont_dir/ttf && $ttmkfdir > fonts.dir" );
    my $restart_xfs = "$chkfontpath -a $drakfont_dir/ttf";
    $interactive and progress($pbar2, 50, _("True Type fonts installation"));

#    my nb += $_ ?1 : 0 foreach ($so, $gs); #add abiword when implemented
    if ($so && $gs)  {
      foreach my $fontname ( glob ("$drakfont_dir/tmp/tmp/*.ttf") ) { 
	system ("cd $drakfont_dir/tmp/tmp && $ttf2pt1 -b $fontname");
      }
      system ("cd $drakfont_dir/tmp/tmp && mv *.gsf *.pfb *.pfm *.afm ../Type1");
      system ("cd $drakfont_dir/tmp/Type1 && $type1inst" );
      system ("cd $drakfont_dir/tmp/Type1 && cat Fontmap >> `rpm -ql ghostscript | grep Fontmap.GS` " );
      system ("cd $drakfont_dir/tmp/Type1 && mv *.pfm *.gsf *.afm *.pfb ../../Type1 ");
      system ("cd $drakfont_dir/Type1 && $type1inst");
      $restart_xfs .= "; $chkfontpath -a $drakfont_dir/Type1";
    }
    if (!$so && $gs)  {
      foreach my $fontname ( glob ("$/drakfont_dir/tmp/tmp/*.ttf") ) { 
	system ("cd $/drakfont_dir/tmp/tmp && $ttf2pt1 -b $fontname");
      }
      system ("cd $drakfont_dir/tmp/tmp && mv *.gsf *.pfb *.pfm ../Type1");
      system ("cd $drakfont_dir/tmp/Type1 && $type1inst" );
      system ("cd $drakfont_dir/tmp/Type1 && cat Fontmap >> `rpm -ql ghostscript | grep Fontmap.GS` " );
      system ("cd $drakfont_dir/tmp/Type1 && mv *.pfm *.afm *.gsf *.pfb ../../Type1 ");
      system ("cd $drakfont_dir/Type1 && $type1inst");
      $restart_xfs .= "; $chkfontpath -a $drakfont_dir/Type1";
    }
    if ($so && !$gs)  {
      foreach my $fontname ( glob ("$drakfont_dir/tmp/tmp/*.ttf") ) { 
	system ("cd $drakfont_dir/tmp/tmp && $ttf2pt1 $fontname");
      }
      foreach my $fontname ( glob ("$drakfont_dir/tmp/tmp/*.pfm") ) { 
	system ("cd $drakfont_dir/tmp/tmp && $pfm2afm $fontname");
      }
      system ("cd $drakfont_dir/tmp/tmp && mv  *.afm ../Type1");
      system ("cd $drakfont_dir/tmp/Type1 && mv *.afm ../../Type1 ");
      system ("cd $drakfont_dir/Type1 && $type1inst");
      $restart_xfs .= "; $chkfontpath -a $drakfont_dir/Type1";
    }
    $interactive and  progress($pbar2, 50, _("Fonts conversion for applications"));
    rm_rf("$drakfont_dir/tmp/");
    $interactive and  progress($pbar3, 50, _("Suppress temporary Files"));
    print "\n\nretarting xfs......\n";
    system ($restart_xfs);
    $interactive and  progress($pbar3, 50, _("Restart XFS"));
  }
}

sub remove_gs_fonts {
    my @Fontmap_new;

    if (all("$drakfont_dir/remove"))  {
	system (" cd $drakfont_dir/remove && $type1inst");
	my @Fontmap_out = cat_("$drakfont_dir/remove/Fontmap");
	my $FontmapGS = `rpm -ql ghostscript | grep Fontmap.GS`;
	chomp ($FontmapGS);
	my @FontmapGS_list = cat_($FontmapGS);
	foreach my $font_gs (@FontmapGS_list) {
	    my @tmp_list = split (' ',$font_gs);
	    grep ( $_ =~ /$tmp_list[0]/ , @Fontmap_out) or  push @Fontmap_new, $font_gs;
	}
	print $_ foreach @Fontmap_new;
	output($FontmapGS, @Fontmap_new );
    }
}

sub remove_fonts {
    my @list_dir;
    my @toto;
    -e $drakfont_dir . "/remove"  || mkdir_p($drakfont_dir . "/remove");
    foreach my $i (@font_list) {
	$_ = $i;
	if ( /.pfb$/ || /.gsf$/ || /.pfm$/ || /.pfa$/ ) {
	    system ("cp $_ $drakfont_dir/remove ");
	} else {
	    rm_rf($i);
	}
	$i =~ s/\/\w*\.\w*//gi;
	grep ( $i, (@list_dir)) or push @list_dir, $i;
    }
    -e "/usr/share/ghostscript" and  remove_gs_fonts();
    foreach my $i (@list_dir) {
	if (listlength all("$i") < 3)  {
	    # remove this directory of the de fontpath
	    system("chkfontpath -r $i") or print "PERL::system command failed during chkfontpath\n";
	} else {
	    #	    # do type1inst in this path
	    system("cd $i && type1inst") or print "PERL::system command failed during cd or type1inst\n";
	}
    }
    system ("/etc/rc.d/init.d/xfs restart");
    -e "/usr/share/ghostscript" and  rm_rf("$drakfont_dir/remove");
}

sub license_msg {
    print _("Before installing any fonts, be sure that you have the right to use and install them on your system.\n\n-You can install the fonts using the normal way. In rare cases, bogus fonts may hang up your X Server.")."\n";
}

$xlsfonts || $windows || @install || @uninstall ? backend_mod() : interactive_mode();

sub backend_mod {
    if ($xlsfonts) {
	system ("xlsfonts");
    }
    if ($windows) {
	license_msg();
	print "........Windows fonts Installation........\n\n";
	search_installed_fonts();
	if(search_windows_font()) {
	    print_list();
	    put_font_dir();
	}
	print "\n...............The End...................\n";
    }

    if (@install) {
	license_msg();
	print ".......Install Specifics Fonts...........\n\n";
	search_installed_fonts();
	search_dir_font $_ foreach (@install);
	print "Font to install : " . $_ . "\n" foreach (@font_list);
	put_font_dir();
	print "\n...............The End...................\n";
    }

    if (@uninstall) {
	license_msg();
	print "........Uninstall Specifics Fonts........\n\n";
	search_installed_fonts_full_path();
	search_dir_font_uninstall $_ foreach (@uninstall);
	remove_fonts();
	print "\n...............The End...................\n";
    }
}



sub create_fontsel {
    my $font_sel;
    gtkpack($font_box,
	    $font_sel = new Gtk::FontSelection,
	   );
    $central_widget = \$font_sel;
}

sub display_error {
    my ($message) = @_;
    my $label;
    my $error_box;
    ${$central_widget}->destroy();
    gtkpack($font_box,
	    $error_box = gtkpack_(new Gtk::VBox(0,0),
		  1, new Gtk::Label($message),
		  0, gtkadd(gtkset_layout(new Gtk::HButtonBox, -spread),
			    gtksignal_connect(new Gtk::Button(_("OK")), clicked => sub { ${$central_widget}->destroy(); create_fontsel() }),
			   ),
				 )
	   );
    $central_widget = \$error_box;
}

sub interactive_mode {
    my $font_sel;
    $interactive = 1;

    init Gtk;

    my $window1 = $::isEmbedded ? new Gtk::Plug ($::XID) : new Gtk::Window -toplevel;
    $window1->signal_connect (delete_event => sub { Gtk->exit(0) });
    $window1->set_position(1);
    $window1->set_title(_("Fonts Importation"));
    $window1->set_border_width(5);

    gtkadd($window1,
	   gtkpack_(new Gtk::HBox(0,2),
		    1, gtkpack_(new Gtk::VBox(0,0),
				1, new Gtk::VBox(0,0),
				1, gtkpack($font_box = new Gtk::VBox(0,5),
					   $font_sel = new Gtk::FontSelection,
					   ),
				1, new Gtk::VBox(0,0)
				),
		    0, gtkpack_(new Gtk::VBox(0,5),
				0, _("DrakFont"),
				0, gtkadd(gtkset_layout(new Gtk::VButtonBox, -end),
					  gtksignal_connect(new Gtk::Button(_("Windows Importation")), clicked 	=>
							    sub { ${$central_widget}->destroy(); $windows = 1; license(\&appli_choice)}),
					  gtksignal_connect(new Gtk::Button(_("Advanced Importation")), clicked =>
							    sub {  ${$central_widget}->destroy(); $windows = 0; license(\&advanced_install)}),
					  gtksignal_connect(new Gtk::Button(_("Uninstall Fonts")), clicked => sub { Gtk->main_quit() }),
					 ),
				1, new Gtk::VBox(0,0),
				1, gtkadd(gtkset_layout(new Gtk::VButtonBox, -end),
					  gtksignal_connect(new Gtk::Button(_("             Help           ")), clicked => sub { 
					       ${$central_widget}->destroy(); help(); print _("Help\n") }),
					  gtksignal_connect(new Gtk::Button(_("Close")), clicked => sub { Gtk->main_quit() }),
					 ),
				)
		    ),
	   );
    $central_widget = \$font_sel;
    $window1->show_all;
    $window1->realize;
    $window1->show_all();

    Gtk->main;
    Gtk->exit(0);
}


sub license {
    my ($function) = @_,
    my $text = new Gtk::Text(undef, undef);
    my $license_box;
    gtkpack($font_box,
	    $license_box = gtkpack_(new Gtk::VBox(0,10),
				    1, gtkpack_(new Gtk::HBox(0,0),
						1, gtktext_insert(gtkset_editable($text, 1), "Before installing any fonts, be sure that you have the right to use and install them on your system.\n\n-You can install the fonts using the normal way. In rare cases, bogus fonts may hang up your X Server."),
						0, new Gtk::VScrollbar($text->vadj),
					       ),
				    0, gtkadd(gtkset_layout(new Gtk::HButtonBox, -spread),
					      gtksignal_connect(new Gtk::Button(_("OK")), clicked => sub { 
								    ${$central_widget}->destroy(); $function->(); }),
					      gtksignal_connect(new Gtk::Button(_("Cancel")), clicked => sub {
								    ${$central_widget}->destroy(); create_fontsel() }),
					     ),
				   )
	   );
    $central_widget = \$license_box;
    $font_box->show_all();
}

sub help {
    my $text = new Gtk::Text(undef, undef);
    my $help_box;
    gtkpack($font_box,
	    $help_box = gtkpack_(new Gtk::VBox(0,10),
	       1, gtkpack_(new Gtk::HBox(0,0),
			   1, gtktext_insert(gtkset_editable($text, 1), "drakfont Future Overview
        - Fonts import :
                pfb ( Adobe Type 1 binary )
                pfa ( Adobe Type 1 ASCII )
                ttf ( True-Type  )
                pcf.gz
                Speedo
                and Bitmap (PCF, BDF, and SNF)
        - Features
                - Install fonts from any directory
                - Get windows fonts on any vfat partitions
                - Get fonts on any partitions.
                - UN-installation of any fonts (even if not installed through drakfont)
        - Support
              - Xfs
              - ghostscript & printer
              - Staroffice & printer
              - abiword
              - Koffice, Gnumeric, ... studying
              - all fonts supported by printer
              - anti-aliases by RENDER in Xfree86 .... 
				supported by KDE.
				will be supported by gnome 1.2.
Visual Interface:
        Window interface:
          - Fontselectiondialog widget
          - Command buttons under Fontselectiondialog (like the actual frontend).
        Commands buttons:
          - import from windows partition.
                import from all fat32 partitions and look for winnt/windows/font
                and import all (delete doublon) but don't import if already exist.
          - import from directory
                look for if it exist before for each font and not delete the original.
                (replace all, no, none)
                expert options:
                        ask the directory, and look for if it exist before
                        if it exist ask: (replace all, no, none)
          - uninstall with list per font type
        Expert additional switch
          - option support:   ghostscript, Staroffice, etc...
                check-button. (by default all check)
          - Printer Application Fonts Support...

________________________ ABOUT ____________________________ 


 USING:
    -  pfm2afm:   
	 by Ken Borgendale:
	    Convert a Windows .pfm  file to a .afm (Adobe Font Metrics)
    -  type1inst:
	 by James Macnicol: 
	    type1inst generates files fonts.dir fonts.scale & Fontmap.
    -  ttf2pt1:   
	  by Andrew Weeks, Frank Siegert, Thomas Henlich, Sergey Babkin  
             Convert ttf font files to afm and pfb fonts


"),
			   0, new Gtk::VScrollbar($text->vadj),
			   ),
			     0, gtkadd(gtkset_layout(new Gtk::HButtonBox, -spread),
				gtksignal_connect(new Gtk::Button(_("OK")), clicked => sub { ${$central_widget}->destroy(); create_fontsel() }),
				       ),
				 )
	    );
    $central_widget = \$help_box;
    $font_box->show_all();
}


sub appli_choice {
    my $choice_box;
    gtkpack($font_box,
	    $choice_box = gtkpack_(new Gtk::VBox(0,10),
				   1, my $table2 = create_packtable({ col_spacings => 2, row_spacings => 15},
	    [_("Choose the applications that will support the fonts :"), ],
	    [ "" , "" ],		    
	    [_("Ghostscript"), gtksignal_connect(my $check11 = new Gtk::CheckButton(), clicked =>  sub { print "appli = " ; })],
	    [_("StarOffice"),  my $check22 = new Gtk::CheckButton()],
	    [_("Abiword"),  my $check33 = new Gtk::CheckButton()],
	    [_("Generic Printers"), my $check44 = new Gtk::CheckButton()],
								   ),
				   0, gtkadd(gtkset_layout(new Gtk::HButtonBox, -spread),
					     gtksignal_connect(new Gtk::Button(_("OK")), clicked => sub { 
								   ${$central_widget}->destroy(); import_status() }),
					     gtksignal_connect(new Gtk::Button(_("Cancel")), clicked => sub { 
								   ${$central_widget}->destroy(); create_fontsel() }),
					    ),
				  )
	   );
    foreach ([$check11, \$gs], [$check22, \$so], [$check33, \$abi], [$check44, \$printer]) {
	my $ref = $_->[1];
	gtksignal_connect(gtkset_active($_->[0], ${$ref}), toggled => sub { ${$ref} = ${$ref} ? 0 : 1; })
    }
    $central_widget = \$choice_box;
    $font_box->show_all();
}

my $list;
# = new Gtk::List();

sub font_choice {
    my $file_dialog;
    $file_dialog = gtksignal_connect(new Gtk::FileSelection(_("File Selection")), destroy => sub { $file_dialog->destroy(); } );
    $file_dialog->ok_button->signal_connect(clicked => \&file_ok_sel, $file_dialog);
    $file_dialog->ok_button->child->set(_("Add"));
    $file_dialog->cancel_button->signal_connect(clicked => sub { $file_dialog->destroy() });
    $file_dialog->cancel_button->child->set(_("Close"));
#    gtkpack__($file_dialog->fileop_dialog, _("Select the font file or directory and click on 'Add'"));
    $file_dialog->set_filename(_("Select the font file or directory and click on 'Add'"));
    $file_dialog->show();
}

sub file_ok_sel { 
    my ( $widget, $file_selection ) = @_;     
    my $file_name = $file_selection->get_filename();
    print "-- @install\n";
    if(!member($file_name, @install)) {
	push(@install, $file_name);
	$list->add(gtkshow(new Gtk::ListItem($file_name)));
    }
}

sub list_remove {
	my($widget, $list) = @_;
	my @to_remove;
	push @to_remove, $list->child_position($_) foreach($list->selection);
	splice @install, $_, 1 foreach(reverse sort @to_remove);
	$list->remove_items($list->selection);
}

sub advanced_install {
    my $gtklist = new Gtk::List();
    my $scrolled_window;
    my $adv_box;
    $list = new Gtk::List();
    $list->set_selection_mode(-extended);

    gtkpack($font_box,
	    $adv_box = gtkpack_(new Gtk::VBox(0,10),
				1, gtkpack_(new Gtk::HBox(0,4),
					    1, $scrolled_window =new Gtk::ScrolledWindow( undef, undef ),
					    $scrolled_window->set_usize( 440, 200 ),
					    $scrolled_window->add_with_viewport( $list ),
					    ),
				0, gtkadd(gtkset_layout(new Gtk::HButtonBox, -spread),
					  gtksignal_connect(new Gtk::Button(_("Add")), clicked => sub { font_choice() }),
					  gtksignal_connect(new Gtk::Button(_("Remove Selected")), clicked => \&list_remove, $list),
					  gtksignal_connect(new Gtk::Button(_("Install List")), clicked => sub { 
					      ${$central_widget}->destroy(); import_status() }),
					  ),
				)
	    );
    $central_widget = \$adv_box;
    $adv_box->show_all();
}

sub import_status {
    my $adj = new Gtk::Adjustment( 0, 1, 100, 0, 0, 0 );
    my $adj1 = new Gtk::Adjustment( 0, 1, 100, 0, 0, 0 );
    my $adj2 = new Gtk::Adjustment( 0, 1, 100, 0, 0, 0 );
    my $adj3 = new Gtk::Adjustment( 0, 1, 100, 0, 0, 0 );
    my $table;
    $pbar = new_with_adjustment Gtk::ProgressBar($adj);
    $pbar1 = new_with_adjustment Gtk::ProgressBar($adj1);
    $pbar2 = new_with_adjustment Gtk::ProgressBar($adj2);
    $pbar3 = new_with_adjustment Gtk::ProgressBar($adj3);
    gtkpack($font_box,
	    $table = create_packtable({ col_spacings => 10, row_spacings => 2},
   [ " ", $pbar->{label} = new Gtk::Label(' ' ), ' '],				 
   [_("Initial tests"), $pbar, ' '],
   [ " ", $pbar1->{label} = new Gtk::Label(' ' ), ' '],				 
   [_("Copy all fonts on your system"), $pbar1, ' '],
   [ " ", $pbar2->{label} = new Gtk::Label(' ' ), ' '],				 
   [_("Install & convert Fonts"), $pbar2, ' '],
   [ " ", $pbar3->{label} = new Gtk::Label(' ' ), ' '],				 
   [_("Post Install"), $pbar3, ' '],
			    ),
# 	    $table = create_packtable({ col_spacings => 10, row_spacings => 2},
#    [ " ", $label1 = new Gtk::Label(' ' )],				 
#    [_("Initial tests"), $pbar = new_with_adjustment Gtk::ProgressBar($adj), gtkset_sensitive($check1 = new Gtk::CheckButton(), 0)],
#    [ " ", $label2 = new Gtk::Label(' ' )],				 
#    [_("Copy all fonts on your system"), $pbar1 = new_with_adjustment Gtk::ProgressBar($adj1), gtkset_sensitive($check2 = new Gtk::CheckButton(), 0)],
#    [ " ", $label3 = new Gtk::Label(' ' )],				 
#    [_("Install & convert Fonts"), $pbar2 = new_with_adjustment Gtk::ProgressBar($adj2), gtkset_sensitive($check3 = new Gtk::CheckButton(), 0)],
#    [ " ", $label4 = new Gtk::Label(' ' )],				 
#    [_("Post Install"), $pbar3 = new_with_adjustment Gtk::ProgressBar($adj3), gtkset_sensitive($check4 = new Gtk::CheckButton(), 0)],
# 			    ),
	   );
    $central_widget = \$table;
    $font_box->show_all();
    progress($pbar, 0.1, "toto");
#    my $timer  = Gtk->timeout_add(  5, \&progress_timeout );
#    my $timer1 = Gtk->timeout_add( 10, \&progress_timeout1 );
#    my $timer2 = Gtk->timeout_add( 15, \&progress_timeout2 );
#    my $timer3 = Gtk->timeout_add( 20, \&progress_timeout3 );
    Gtk->main_iteration while Gtk->events_pending;
    backend_mod();
}

sub progress {
    my ($bar, $incr, $label_text) = @_;
    my $new_val;
    my $adjt;
    $new_val = $pbar->get_value() + $incr;
    $adjt = $bar->adjustment;
    $bar->set_value($new_val);
    $bar->{label}->set($label_text);
#    $new_val < 100 || gtkset_active($check1 , 1);
    Gtk->main_iteration while Gtk->events_pending;
    $new_val < 100 ;
}


#1, gtksignal_connect(my $button_connect = gtkset_sensitive(new Gtk::Button(), 0), clicked => \&connection),



# interface graphique a faire
# option strong: verifier strong  ttmkfdir -c ???
# gestion abiword, netscape, gimp....
# xlsfonts | less pour verifier l'installation des polices.