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

I think I have all the pieces, but not how to put them together:

I have a Perl/Tk application that runs on Windows & Linux (Fedora, if it matters). Originally written on Windows.

The Linux default fonts are causing some issues - they make a number of widgets larger, and aren't as readable for some. In any case, the goal is a common look and screen size.

The application users (X display servers) are mostly Windows (VxXsrv), some Linux.

So, I'd like to have the application request (and the clients use) the Windows fonts for the Tk widgets.

What I (think I) know:

That's where I get lost.

I don't want to declare a custom font for every widget - I want the defaults for this application to switch to these as the "system" fonts"

I don't know why I find all this stuff so confusing - OS internals are simple :-)

Thanks in advance

Replies are listed 'Best First'.
Re: Perl/Tk Windows fonts for Linux?
by zentara (Cardinal) on Jul 22, 2018 at 10:56 UTC
    Hi, on modern linux systems, Arial fonts will install fine. Just put your arial.ttf file in your ~/.fonts directory and run fc-cache to make sure it's included in your font list. fc-cache is usually run at boot, but you can run it manually. Afterwards, run fc-list to be sure your new font is listed.

    I think you will run into difficulty trying to declare a default system wide font in .Xdefaults, but you can easily make a default font in a Tk program with a single line. Notice the canvas dosn't pick up on the default font, but other widgets do. I don't run windows, but I would be interested to hear your report on whether the program below looks the same on linux and windows.

    # set a default font for all widgets $mw->optionAdd('*font', 'Arial 24');
    and a full program to demonstrate
    #!/usr/bin/perl use warnings; use strict; use Tk; my $mw = new MainWindow(-bg =>'black'); # set a default font $mw->optionAdd('*font', 'Arial 24'); # a useful way of tagging fonts for special use $mw->fontCreate('big', -family=>'arial', -weight=>'bold', -size=> 38 ); # will use default font my $menubar = $mw->Menu(-type => 'menubar'); $mw->configure(-menu => $menubar); my $menu = $menubar->cascade(-label => '~File'); $menu->command(-label => '~New'); $menu->command(-label => '~Open'); $mw->Button(-text => 'test this font', -bg=>'white')->pack; $mw->Label(-text => 'test this font', -bg=>'lightyellow')->pack; my $text = $mw->Text(-bg=>'white', -height => 4, -width =>20)->pack; $text->insert('0.0','test this font'); my $canvas = $mw->Canvas(-bg=>'lightgreen')->pack; #make a special font my $font = $mw->Font(-family=> 'Arial', -size => 18); # will use default font $canvas->createText( 0, 0, -anchor => 'nw', -text => 'test this font', ); # special font $canvas->createText( 0, 50, -anchor => 'nw', -text => 'test this font', -font => $font, ); # tagged font $canvas->createText( 0, 100, -anchor => 'nw', -text => 'test this font', -font => 'big', ); MainLoop;

    I'm not really a human, but I play one on earth. ..... an animated JAPH