1font(n)                      Tk Built-In Commands                      font(n)
2
3
4
5______________________________________________________________________________
6

NAME

8       font - Create and inspect fonts.
9

SYNOPSIS

11       font option ?arg arg ...?
12_________________________________________________________________
13

DESCRIPTION

15       The  font  command  provides several facilities for dealing with fonts,
16       such as defining named fonts and inspecting the actual attributes of  a
17       font.  The command has several different forms, determined by the first
18       argument.  The following forms are currently supported:
19
20       font actual font ?-displayof window? ?option? ?--? ?char?
21              Returns  information  about  the  actual  attributes  that   are
22              obtained  when  font  is  used  on  window's display; the actual
23              attributes obtained may differ from the attributes requested due
24              to  platform-dependent  limitations, such as the availability of
25              font families and pointsizes.  font is a font  description;  see
26              FONT  DESCRIPTIONS below.  If the window argument is omitted, it
27              defaults to the main window.  If option  is  specified,  returns
28              the  value of that attribute; if it is omitted, the return value
29              is a list of all the attributes  and  their  values.   See  FONT
30              OPTIONS  below  for  a  list of the possible attributes.  If the
31              char argument is supplied, it must be a  single  character.  The
32              font attributes returned will be those of the specific font used
33              to render that character, which will be different from the  base
34              font  if the base font does not contain the given character.  If
35              char may be a hyphen, it should be preceded by -- to distinguish
36              it from a misspelled option.
37
38       font configure fontname ?option? ?value option value ...?
39              Query or modify the desired attributes for the named font called
40              fontname.  If no option is specified, returns a list  describing
41              all  the  options  and  their  values for fontname.  If a single
42              option is specified with no  value,  then  returns  the  current
43              value  of that attribute.  If one or more option-value pairs are
44              specified, then the command modifies the  given  named  font  to
45              have the given values; in this case, all widgets using that font
46              will redisplay themselves using the new attributes for the font.
47              See FONT OPTIONS below for a list of the possible attributes.
48
49       font create ?fontname? ?option value ...?
50              Creates  a new named font and returns its name.  fontname speci‐
51              fies the name for the font; if it is omitted, then Tk  generates
52              a  new name of the form fontx, where x is an integer.  There may
53              be any number of option-value pairs, which provide  the  desired
54              attributes for the new named font.  See FONT OPTIONS below for a
55              list of the possible attributes.
56
57       font delete fontname ?fontname ...?
58              Delete the specified named fonts.  If there  are  widgets  using
59              the  named  font,  the  named  font will not actually be deleted
60              until all the instances are released.  Those widgets  will  con‐
61              tinue to display using the last known values for the named font.
62              If a deleted named font is subsequently recreated  with  another
63              call to font create, the widgets will use the new named font and
64              redisplay themselves using the new attributes of that font.
65
66       font families ?-displayof window?
67              The return value is a list of the case-insensitive names of  all
68              font  families  that  exist  on window's display.  If the window
69              argument is omitted, it defaults to the main window.
70
71       font measure font ?-displayof window? text
72              Measures the amount of space the string text would  use  in  the
73              given  font  when  displayed in window.  font is a font descrip‐
74              tion; see FONT DESCRIPTIONS below.  If the  window  argument  is
75              omitted,  it  defaults  to the main window.  The return value is
76              the total width in pixels of text, not including the extra  pix‐
77              els  used  by highly exaggerated characters such as cursive “f”.
78              If the string contains newlines or tabs,  those  characters  are
79              not expanded or treated specially when measuring the string.
80
81       font metrics font ?-displayof window? ?option?
82              Returns  information about the metrics (the font-specific data),
83              for font when it is used on window's display.  font  is  a  font
84              description;  see  FONT DESCRIPTIONS below.  If the window argu‐
85              ment is omitted, it defaults to the main window.  If  option  is
86              specified,  returns  the value of that metric; if it is omitted,
87              the return value is a list of all the metrics and their  values.
88              See FONT METRICS below for a list of the possible metrics.
89
90       font names
91              The  return value is a list of all the named fonts that are cur‐
92              rently defined.
93

FONT DESCRIPTION

95       The following formats are accepted as a font description anywhere  font
96       is  specified as an argument above; these same forms are also permitted
97       when specifying the -font option for widgets.
98
99       [1] fontname
100              The name of a named font, created using the font create command.
101              When a widget uses a named font, it is guaranteed that this will
102              never cause an error, as long as the named font exists, no  mat‐
103              ter  what  potentially  invalid or meaningless set of attributes
104              the named font has.  If the named font cannot be displayed  with
105              exactly  the specified attributes, some other close font will be
106              substituted automatically.
107
108       [2] systemfont
109              The platform-specific name of a font, interpreted by the  graph‐
110              ics  server.  This also includes, under X, an XLFD (see [4]) for
111              which a single “*” character was used to  elide  more  than  one
112              field  in  the middle of the name.  See PLATFORM-SPECIFIC issues
113              for a list of the system fonts.
114
115       [3] family ?size? ?style? ?style ...?
116              A properly formed list whose first element is the  desired  font
117              family  and  whose  optional second element is the desired size.
118              The interpretation of the size attribute follows the same  rules
119              described  for  -size  in  FONT  OPTIONS  below.  Any additional
120              optional arguments following the size are font styles.  Possible
121              values for the style arguments are as follows:
122              normal      bold        roman      italic underline   overstrike
123
124       [4] X-font names (XLFD)
125              A   Unix-centric   font   name   of   the   form   -foundry-fam‐
126              ily-weight-slant-setwidth-addstyle-pixel-point-resx-resy-spac‐
127              ing-width-charset-encoding.   The  “*”  character may be used to
128              skip individual fields that the user does not care about.  There
129              must  be  exactly  one “*” for each field skipped, except that a
130*” at the end of the  XLFD  skips  any  remaining  fields;  the
131              shortest  valid  XLFD  is  simply  “*”, signifying all fields as
132              defaults.  Any fields that were skipped are given  default  val‐
133              ues.   For  compatibility,  an XLFD always chooses a font of the
134              specified pixel size (not point size); although this interpreta‐
135              tion  is  not  strictly correct, all existing applications using
136              XLFDs assumed that one “point” was in fact one pixel  and  would
137              display  incorrectly (generally larger) if the correct size font
138              were actually used.
139
140       [5] option value ?option value ...?
141              A properly formed list of option-value pairs  that  specify  the
142              desired  attributes  of  the  font, in the same format used when
143              defining a named font; see FONT OPTIONS below.
144
145       When font description font is used, the system attempts  to  parse  the
146       description  according  to  each  of the above five rules, in the order
147       specified.  Cases [1] and [2] must match the name of an existing  named
148       font  or of a system font.  Cases [3], [4], and [5] are accepted on all
149       platforms and the closest available font will be used.  In some  situa‐
150       tions  it  may  not  be possible to find any close font (e.g., the font
151       family was a  garbage  value);  in  that  case,  some  system-dependent
152       default  font is chosen.  If the font description does not match any of
153       the above patterns, an error is generated.
154

FONT METRICS

156       The following options are used by the font  metrics  command  to  query
157       font-specific data determined when the font was created.  These proper‐
158       ties are for the whole font itself and not  for  individual  characters
159       drawn  in that font.  In the following definitions, the “baseline” of a
160       font is the horizontal line where the bottom of most letters  line  up;
161       certain letters, such as lower-case “g” stick below the baseline.
162
163       -ascent
164              The amount in pixels that the tallest letter sticks up above the
165              baseline of the font, plus any extra blank space  added  by  the
166              designer of the font.
167
168       -descent
169              The  largest  amount in pixels that any letter sticks down below
170              the baseline of the font, plus any extra blank  space  added  by
171              the designer of the font.
172
173       -linespace
174              Returns  how  far  apart  vertically in pixels two lines of text
175              using the same font should be placed so that none of the charac‐
176              ters  in  one  line  overlap  any of the characters in the other
177              line.  This is generally the sum of the ascent above  the  base‐
178              line line plus the descent below the baseline.
179
180       -fixed
181              Returns  a  boolean  flag  that  is “1” if this is a fixed-width
182              font, where each normal character is the same width as  all  the
183              other  characters,  or is “0” if this is a proportionally-spaced
184              font, where individual characters have  different  widths.   The
185              widths  of  control  characters,  tab characters, and other non-
186              printing characters  are  not  included  when  calculating  this
187              value.
188

FONT OPTIONS

190       The following options are supported on all platforms, and are used when
191       constructing a named font or when specifying a font using style [5]  as
192       above:
193
194       -family name
195              The case-insensitive font family name.  Tk guarantees to support
196              the font  families  named  Courier  (a  monospaced  “typewriter”
197              font),  Times  (a  serifed  “newspaper”  font), and Helvetica (a
198              sans-serif “European” font).  The most closely  matching  native
199              font  family  will  automatically be substituted when one of the
200              above font families is used.  The name may also be the name of a
201              native, platform-specific font family; in that case it will work
202              as desired on one platform but  may  not  display  correctly  on
203              other  platforms.  If the family is unspecified or unrecognized,
204              a platform-specific default font will be chosen.
205
206       -size size
207              The desired size of the font.  If the size argument is  a  posi‐
208              tive  number, it is interpreted as a size in points.  If size is
209              a negative number, its absolute value is interpreted as  a  size
210              in pixels.  If a font cannot be displayed at the specified size,
211              a nearby size will be chosen.  If size is unspecified or zero, a
212              platform-dependent default size will be chosen.
213
214              Sizes  should normally be specified in points so the application
215              will remain the same ruler size on the screen, even when  chang‐
216              ing screen resolutions or moving scripts across platforms.  How‐
217              ever, specifying pixels is useful in certain circumstances  such
218              as  when  a  piece of text must line up with respect to a fixed-
219              size bitmap.  The mapping between points and pixels is set  when
220              the  application  starts,  based  on properties of the installed
221              monitor, but it can be overridden by calling the tk scaling com‐
222              mand.
223
224       -weight weight
225              The  nominal thickness of the characters in the font.  The value
226              normal specifies a normal weight font, while  bold  specifies  a
227              bold  font.   The  closest available weight to the one specified
228              will be chosen.  The default weight is normal.
229
230       -slant slant
231              The amount the characters in the font are slanted away from  the
232              vertical.  Valid values for slant are roman and italic.  A roman
233              font is the normal, upright  appearance  of  a  font,  while  an
234              italic  font  is  one that is tilted some number of degrees from
235              upright.  The closest available slant to the one specified  will
236              be chosen.  The default slant is roman.
237
238       -underline boolean
239              The value is a boolean flag that specifies whether characters in
240              this font should be underlined.  The default value for underline
241              is false.
242
243       -overstrike boolean
244              The  value is a boolean flag that specifies whether a horizontal
245              line should be drawn through the middle of  characters  in  this
246              font.  The default value for overstrike is false.
247

STANDARD FONTS

249       The  following named fonts are supported on all systems, and default to
250       values that match appropriate system defaults.
251
252       TkDefaultFont
253              This font is the default for all GUI items not otherwise  speci‐
254              fied.
255
256       TkTextFont
257              This  font  should be used for user text in entry widgets, list‐
258              boxes etc.
259
260       TkFixedFont
261              This font is the standard fixed-width font.
262
263       TkMenuFont
264              This font is used for menu items.
265
266       TkHeadingFont
267              This font should be  used  for  column  headings  in  lists  and
268              tables.
269
270       TkCaptionFont
271              This font should be used for window and dialog caption bars.
272
273       TkSmallCaptionFont
274              This  font  should  be used for captions on contained windows or
275              tool dialogs.
276
277       TkIconFont
278              This font should be used for icon captions.
279
280       TkTooltipFont
281              This font should be used for tooltip windows (transient informa‐
282              tion windows).
283
284       It  is not advised to change these fonts, as they may be modified by Tk
285       itself in response to system changes. Instead, make a copy of the  font
286       and modify that.
287

PLATFORM-SPECIFIC FONTS

289       The following system fonts are supported:
290
291       X Windows
292              All  valid  X font names, including those listed by xlsfonts(1),
293              are available.
294
295       MS Windows
296              The following fonts are supported, and are mapped to the  user's
297              style defaults.
298              system      ansi        device systemfixed ansifixed   oemfixed
299
300       Mac OS X
301              The  following fonts are supported, and are mapped to the user's
302              style defaults.
303              system      application menu
304
305              Additionally, the following named fonts provide  access  to  the
306              Aqua theme fonts: systemSystemFont    systemEmphasizedSystemFont
307              systemSmallSystemFontsystemSmallEmphasizedSystemFont   systemAp‐
308              plicationFontsystemLabelFont   systemViewsFont     systemMenuTi‐
309              tleFont  systemMenuItemFont  systemMenuItemMarkFont  systemMenu‐
310              ItemCmdKeyFontsystemWindowTitleFont systemPushButtonFontsystemU‐
311              tilityWindowTitleFont     systemAlertHeaderFontsystemToolbarFont
312              systemMiniSystemFontsystemDetailSystemFont    systemDetailEmpha‐
313              sizedSystemFont
314

EXAMPLE

316       Fill a text widget with lots of font demonstrators, one for every  font
317       family installed on your system:
318              pack [text .t -wrap none] -fill both -expand 1
319              set count 0
320              set tabwidth 0
321              foreach family [lsort -dictionary [font families]] {
322                  .t tag configure f[incr count] -font [list $family 10]
323                  .t insert end ${family}:\t {} \
324                          "This is a simple sampler\n" f$count
325                  set w [font measure [.t cget -font] ${family}:]
326                  if {$w+5 > $tabwidth} {
327                      set tabwidth [expr {$w+5}]
328                      .t configure -tabs $tabwidth
329                  }
330              }
331
332

SEE ALSO

334       options(n)
335
336

KEYWORDS

338       font
339
340
341
342Tk                                    8.0                              font(n)
Impressum