1Tk::FontDialog(3)     User Contributed Perl Documentation    Tk::FontDialog(3)
2
3
4

NAME

6       Tk::FontDialog - a font dialog widget for perl/Tk
7

SYNOPSIS

9           use Tk::FontDialog;
10           $font = $top->FontDialog->Show;
11

DESCRIPTION

13       Tk::FontDialog implements a font dialog widget.
14
15       The dialog is displayed by calling the Show method. The returned value
16       is either the selected font (if the dialog was closed with the Ok
17       button) or undef (otherwise). The exact type of the return value is
18       either a Tk::Font object (in Tk800) or a font name string (usually
19       something like "font1"). Both can be used as values in Tk "-font"
20       options. See "GetDescriptiveFontName"
21
22       In the Family and Size listboxes, the font family and font size can be
23       specified. The checkbuttons on the right turn on bold, italic,
24       underlined and overstriked variants of the chosen font. A sample of the
25       font is shown in the middle area.
26
27       With the "Alt sample" checkbutton, it is possible to show all
28       characters in the charset instead of the default text. "Fixed only"
29       restricts the font family list to fixed fonts only. If the "Nicefonts"
30       checkbutton is set, then the font names in the listbox are displayed in
31       the corresponding font. Note that this option can be slow if a lot of
32       fonts are installed or for 16 bit fonts.
33
34       A click with the right button in the font size listbox pops up a window
35       to enter arbitrary font sizes.
36

WIDGET-SPECIFIC OPTIONS

38       -font
39           The dialog font.
40
41       -initfont
42           The initial font.
43
44       -fontsizes
45           A list of font sizes. The default contains sizes from 0 to 72
46           points (XXX or pixels?).
47
48       -nicefont
49           If set, font names are displayed in its font style. This may be
50           slow, especially if you have many fonts or 16 bit fonts (e.g. Asian
51           fonts).
52
53       -nicefontsbutton
54           If set to false, then the "Nice fonts" button is not displayed.
55
56       -fixedfont
57           If set, proportional font families are not listed, leaving only the
58           fixed fonts. This is slow, as each font must be checked to see if
59           it is fixed or proportional.
60
61       -fixedfontsbutton
62           If set to false, then the "Fixed fonts" button is not displayed.
63
64       -sampletext
65           The sample text which should contain all letters. The default is
66           "The Quick Brown Fox Jumps Over The Lazy Dog" German readers may
67           probably use "Franz jagt im komplett verwahrlosten Taxi quer durch
68           Bayern".
69

INTERNATIONALIZATION

71       There are a couple of options to change the labels of the dialog. Note
72       that you can prepend a tilde ("~") to get an accelerator key with
73       "Alt". Here is a list of these options with the default (English)
74       setting:
75
76       -familylabel (Family:)
77       -sizelabel (Size:)
78       -weightlabel (Bold)
79       -slantlabel (Italic)
80       -underlinelabel (Underline)
81       -overstrikelabel (Overstrike)
82       -oklabel (OK)
83       -applylabel (Apply)
84       -cancellabel (Cancel)
85       -altsamplelabel (Alt sample)
86       -nicefontslabel (Nicefonts)
87       -fixedfontslabel (Fixed Only)
88       -title (Choose font)
89       -customsizetitle (Choose font size)
90

METHODS IN Tk::Widget

92       RefontTree(-font => $font)
93           Additionaly, the convenience method RefontTree is defined in the
94           Tk::Widget namespace. Using this method a font definition could be
95           applied to a complete subtree of a widget. This is similar to the
96           method RecolorTree. Calling RefontTree looks like this:
97
98               $font = $mw->FontDialog->Show;
99               $mainwindow->RefontTree(-font => $font) if defined $font;
100
101           By default RefontTree does not change the font of canvas elements.
102           This can be done by specifying "-canvas => 1".
103
104       GetDescriptiveFontName($fontname)
105           Return a "descriptive" font name (just like form [3] as described
106           in Tk::Font). The return value from the Show() method has the
107           disadvantage that it is only valid for the current Tk session. A
108           "descriptive" font name may be stored and reused later.
109

CAVEAT

111       Note that font names with whitespace like "New century schoolbook" or
112       "MS Sans Serif" can cause problems when using in a -font option. The
113       solution is to put the names in Tcl-like braces, like
114
115           -font => "{New century schoolbook} 10"
116

EXAMPLES

118       To apply a selected font to a specific widget, use the following
119       snippet:
120
121           $font = $mw->FontDialog->Show;
122           if (defined $font) {
123               $button->configure(-font => $font);
124           }
125
126       This example uses the convenience method RefontTree to apply the new
127       font to the whole application:
128
129           use Tk;
130           use Tk::FontDialog;
131           $mw = tkinit;
132           $mw->Label(-text => "Test")->pack;
133           $mw->Button(-text => "Another test")->pack;
134           $mw->Button(-text => "Use Tk::FontDialog",
135                       -command => sub {
136                           my $font = $mw->FontDialog->Show;
137                           if (defined $font) {
138                               $mw->RefontTree(-font => $font);
139                           }
140                       })->pack;
141           MainLoop;
142
143       To get the "descriptive" font name:
144
145           $font = $mw->FontDialog->Show;
146           if (defined $font) {
147               $font_descriptive = $mw->GetDescriptiveFontName($font);
148               print $font_descriptive, "\n";
149           }
150

AVAILABILITY

152       The latest released version is available from cpan (e.g.
153       <http://search.cpan.org/~srezic/>). The latest development version is
154       available from github (<http://github.com/eserte/tk-fontdialog>).
155

BUGS/TODO

157         - ConfigSpecs handling is poor
158           put at least -font into configspecs
159         - run test, call dialog for 2nd time: immediate change of font?
160         - better name for nicefont
161         - restrict on charsets and encodings (xlsfonts? X11::Protocol::ListFonts?)
162           difficult because core Tk font handling ignores charsets and encodings
163

SEE ALSO

165       Tk::Font
166

AUTHOR

168       Slaven Rezic <slaven@rezic.de>
169
170       Suggestions by Michael Houghton, Martin Thurn, Jack, Justin Kozlowitz
171       and others.
172
174       Copyright (c) 1998,1999,2003,2004,2005,2010 Slaven Rezic. All rights
175       reserved.  This module is free software; you can redistribute it and/or
176       modify it under the same terms as Perl itself.
177
178
179
180perl v5.30.0                      2019-07-26                 Tk::FontDialog(3)
Impressum