slloyd has asked for the wisdom of the Perl Monks concerning the following question:

Is there a way to get the list of installed fonts on a win32 system? I cant seem to find a Win32 API for it. Any suggestions?

Replies are listed 'Best First'.
Re: Win32 Font List
by doowah2004 (Monk) on Sep 20, 2004 at 13:18 UTC
    I do not know if this will help, but under Win32::Ole for Microsoft Word there is FontNames. Here is what the Ole-Browser lists:

    FontNames Property Example This example displays the font names in the FontNames collection. For Each aFont In FontNames response = MsgBox(Prompt:=aFont, Buttons:=vbOKCancel) If response = vbCancel Then Exit For Next aFont


    Hope this helps,

    Cameron
Re: Win32 Font List
by muntfish (Chaplain) on Sep 20, 2004 at 12:14 UTC

    I'm surprised there isn't an API call for that. But it looks like (On Windows 2000, anyway) you can check the registry under HKLM\Software\Microsoft\Windows NT\CurrentVersion\Fonts ...


    s^^unp(;75N=&9I<V@`ack(u,^;s|\(.+\`|"$`$'\"$&\"\)"|ee;/m.+h/&&print$&
      I finally found an API call EnumFonts but it looks pretty hairy to set up. Anyone ever used this API that could help me write the perl code to call it?
      #Just a guess... $EnumFonts = new Win32::API("gdi32.lib","EnumFonts", [N,L,L,L],N);
Re: Win32 Font List
by zentara (Cardinal) on Sep 20, 2004 at 14:02 UTC
    Tk has some font modules, which work on Windows. Try running this sample program and see if it works. I don't know if it will list ALL available fonts though. If it works, just diddle it to print a list.
    #!/usr/bin/perl use Tk; use Tk::FontDialog; $top=new MainWindow; my $fd; $b = $top->Button(-text => 'Choose Font', -command => sub { $font = $fd->Show; apply_font($font); })->pack; $f = $top->Frame->pack; $f->Label(-text => 'Test RefontTree 1')->pack; $f2 = $f->Frame->pack; $f2->Label(-text => 'Test RefontTree 2')->pack; $c = $f2->Canvas(-width => 100, -height => 30)->pack; $c->createText(0,0,-anchor => 'nw', -text => 'Canvas Text'); $fd = $top->FontDialog(-nicefont => 0, -title => 'Select Font', -applycmd => \&apply_font, -familylabel => 'Schrift~familie', -fixedfontsbutton => 1, -nicefontsbutton => 1, ); $bf = $top->Frame->pack; $bf->Button(-text => 'OK', -command => sub { print "ok $ok\n"; $top->destroy;})->pack(-side => 'left'); $bf->Button(-text => 'Not OK', -command => sub { print "not ok $ok\n"; $top->destroy;})->pack(-side => 'left'); MainLoop; sub apply_font { my $font = shift; if (defined $font) { $b->configure(-font => $font); $f->RefontTree(-font => $font, -canvas => 1); } }

    I'm not really a human, but I play one on earth. flash japh