For Programmers: Free Programming Magazines  


Home > Archive > PerlTk > May 2005 > PerlTk Fonts Issue - Linux









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author PerlTk Fonts Issue - Linux
lobita

2005-05-10, 3:57 pm

Hello,

I am currently using PerlTk 5.8.0 on the Linux Platform, but I am
having trouble displaying a different font than the default one.

I have tried the following:
1. Specify the font on the comand line:
myProgram.pl -font "Monaco 12"
2. Specify the fonts in the program with the -font option

I have used the xfontsel and xlsfonts commands to verify that the
fonts are installed on the system. I tested the same program on UNIX
and I do NOT have any fonts issue.

It seems that it is a configuration issue or a Linux bug.
Does any body knows how/where PerlTk defines the fonts? How can I check
PerlTk fonts configuration?

Any hints will be hightly appreciated.

Thanks,
FEL

thundergnat

2005-05-10, 3:57 pm

lobita wrote:
> Hello,
>
> I am currently using PerlTk 5.8.0 on the Linux Platform, but I am
> having trouble displaying a different font than the default one.
>
> I have tried the following:
> 1. Specify the font on the comand line:
> myProgram.pl -font "Monaco 12"
> 2. Specify the fonts in the program with the -font option
>
> I have used the xfontsel and xlsfonts commands to verify that the
> fonts are installed on the system. I tested the same program on UNIX
> and I do NOT have any fonts issue.
>
> It seems that it is a configuration issue or a Linux bug.
> Does any body knows how/where PerlTk defines the fonts? How can I check
> PerlTk fonts configuration?
>
> Any hints will be hightly appreciated.
>
> Thanks,
> FEL
>


You need to modify the option database. Check the docs for Tk::option for
rather vague instructions. Take a look at this post for more hints.

http://groups-beta.google.com/group...6078a5c15f82cfa


The following defaults to Arial 8 pt text. Invoke the script with a
font name and size to override the defaults.


perl script.pl Monico 12


#!/usr/local/bin/perl
use warnings;
use strict;
use Tk;

my $fontname = shift || 'Arial';

my $fontsize = shift || '8';

my $font = "$fontname $fontsize";

print $font;

my $mw = MainWindow->new;

$mw->optionAdd("*font", $font, "userDefault");

for my $col (1 .. 5){
for my $row (1 .. 10){
$mw->Label(
-text => " < Label $row : $col > ",
)->grid(-row => $row, -column => $col);
}
}

MainLoop;
thundergnat

2005-05-10, 8:57 pm

thundergnat wrote:
> lobita wrote:
>
>
> You need to modify the option database. Check the docs for Tk::option for
> rather vague instructions. Take a look at this post for more hints.
>
> http://groups-beta.google.com/group...6078a5c15f82cfa
>
>
> The following defaults to Arial 8 pt text. Invoke the script with a
> font name and size to override the defaults.
>
>


In my previous post, I left out the curly brackets around $fontname
they are only necessary for multi-word font names though.

Here is a modification of the previously posted script that lets you
interactively play around with fonts and sizes.



#!/usr/local/bin/perl
use warnings;
use strict;
use Tk;
use Tk::BrowseEntry;

my $fontname = shift || 'Arial';

my $fontsize = shift || '8';

my $font = "{$fontname} $fontsize";

my $mw = MainWindow->new;

$mw->optionAdd("*font", $font, "userDefault");

my $tframe = $mw->Frame->pack;
my $fontlist = $tframe->BrowseEntry(
-label => 'Font',
-variable=> \$fontname
)->grid(-row=>1, -column=>1, -pady => 5);

$fontlist->insert ('end', sort($mw->fontFamilies));

$tframe->Label(
-text => 'Point Size',
)->grid(-row=>1, -column=>2, -pady => 5);

$tframe->Entry(
-width => 4,
-textvariable=> \$fontsize,
-validate => 'key',
-vcmd => sub{ return 0 if $_[0] =~ /\D/; return 1},
)->grid(-row=>1, -column=>3, -pady => 5);

$tframe->Button(
-text => 'Ok',
-command => sub{$font = "{$fontname} $fontsize"; conf($mw)},
)->grid(-row=>1, -column=>4, -padx => 15);

my @labels;

my $bframe = $mw->Frame->pack;

for my $col (1 .. 5){
for my $row (1 .. 5){
push @labels, $bframe->Label(
-text => " < Label $row : $col > ",
)->grid(-row => $row, -column => $col);
}
}

MainLoop;

sub conf{
my $container = shift;
for my $widget($container->children){
if ($widget->isa('Tk::Frame') or $widget->isa('Tk::Pane')){
conf($widget);
next;
}
my %confighash = $widget->ConfigSpecs;
$widget->configure(-font => $font) if (exists $confighash{'-font'});
}
}
lobita

2005-05-11, 3:59 pm

Thanks for your response.

I setup the fonts on the .Xdefaults and I also tried the
optionAdd("*font", $font, "userDefault") with and without the curly
brackets. But, I still cannot get the fonts that I want.

Is that any way to check if the Fonts for Perl/Tk got installed
correctly? How do I check the perlTk fonts configuration?

Thanks,
FEL

thundergnat wrote:
> thundergnat wrote:
check[color=darkred]
Tk::option for[color=darkred]
http://groups-beta.google.com/group...6078a5c15f82cfa
[color=darkred]
>
> In my previous post, I left out the curly brackets around $fontname
> they are only necessary for multi-word font names though.
>
> Here is a modification of the previously posted script that lets you
> interactively play around with fonts and sizes.
>
>
>
> #!/usr/local/bin/perl
> use warnings;
> use strict;
> use Tk;
> use Tk::BrowseEntry;
>
> my $fontname = shift || 'Arial';
>
> my $fontsize = shift || '8';
>
> my $font = "{$fontname} $fontsize";
>
> my $mw = MainWindow->new;
>
> $mw->optionAdd("*font", $font, "userDefault");
>
> my $tframe = $mw->Frame->pack;
> my $fontlist = $tframe->BrowseEntry(
> -label => 'Font',
> -variable=> \$fontname
> )->grid(-row=>1, -column=>1, -pady => 5);
>
> $fontlist->insert ('end', sort($mw->fontFamilies));
>
> $tframe->Label(
> -text => 'Point Size',
> )->grid(-row=>1, -column=>2, -pady => 5);
>
> $tframe->Entry(
> -width => 4,
> -textvariable=> \$fontsize,
> -validate => 'key',
> -vcmd => sub{ return 0 if $_[0] =~ /\D/; return 1},
> )->grid(-row=>1, -column=>3, -pady => 5);
>
> $tframe->Button(
> -text => 'Ok',
> -command => sub{$font = "{$fontname} $fontsize"; conf($mw)},
> )->grid(-row=>1, -column=>4, -padx => 15);
>
> my @labels;
>
> my $bframe = $mw->Frame->pack;
>
> for my $col (1 .. 5){
> for my $row (1 .. 5){
> push @labels, $bframe->Label(
> -text => " < Label $row : $col > ",
> )->grid(-row => $row, -column => $col);
> }
> }
>
> MainLoop;
>
> sub conf{
> my $container = shift;
> for my $widget($container->children){
> if ($widget->isa('Tk::Frame') or $widget->isa('Tk::Pane')){
> conf($widget);
> next;
> }
> my %confighash = $widget->ConfigSpecs;
> $widget->configure(-font => $font) if (exists

$confighash{'-font'});
> }
> }


lobita

2005-05-14, 7:13 pm

Hello,

I just find out that on AIX the $widget->fontFamilies list is the same
as the xfontsel list but on the LINUX platform, the two lists are
different.

The Linux perl/Tk is problably not looking at the correct
path/configuration of Fonts.

Any hints on how to point to the correct fonts is appreciated.

Thanks again,
FEL

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com