O'Reilly logo

Mastering Perl/Tk by Nancy Walsh, Stephen Lidie

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Font Manipulation Methods

Once you’ve created a font using fontCreate, you can use the following methods.

For a description of the font’s attributes (some or all), use fontActual to query the font:

$mw->fontCreate('bigfont', -family => 'Arial', -size => 48);

%big = $mw->fontActual('bigfont');
print %big;
# prints:
-size 48 -overstrike 0 -underline 0 
-weight normal -slant roman -family Arial

$size = $mw->fontActual('bigfont', -size);
print $size;
#prints: 
48

To change (or query) a property of a font once it has been created, use fontConfigure:

if ($mw->fontConfigure('bigfont', -size) < 24) {
  $mw->fontConfigure('bigfont', -size => 48);
}

# same as $mw->fontActual('bigfont');
%bigfont = $mw->fontConfigure('bigfont');

If you’d like to delete a font definition, use fontDelete:

$mw->fontDelete('bigfont');

If you delete a font that is being used, the widgets using it won’t change what they display. They display whatever font they were last. If you try to manipulate the font programmatically after it’s been deleted, you will get an error.

To get a list of all the font families available on your system, use fontFamilies:

@families = $mw->fontFamilies;

To get a list of the currently defined named fonts on your system, use fontNames:

@definedfonts = $mw->fontNames;

The fontNames method returns a list of object references to Font objects. The list will be empty if there aren’t any fonts defined on your system. Keep in mind this list contains only those fonts defined using the fontCreate ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required