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 point sizes.  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              Note  that on Aqua/Mac OS X, the system fonts (see PLATFORM SPE‐
50              CIFIC FONTS below) may not be actually altered because they  are
51              implemented  by the system theme. To achieve the effect of modi‐
52              fication, use font actual to get their  configuration  and  font
53              create to synthesize a copy of the font which can be modified.
54
55       font create ?fontname? ?option value ...?
56              Creates  a new named font and returns its name.  fontname speci‐
57              fies the name for the font; if it is omitted, then Tk  generates
58              a  new name of the form fontx, where x is an integer.  There may
59              be any number of option-value pairs, which provide  the  desired
60              attributes for the new named font.  See FONT OPTIONS below for a
61              list of the possible attributes.
62
63       font delete fontname ?fontname ...?
64              Delete the specified named fonts.  If there  are  widgets  using
65              the  named  font,  the  named  font will not actually be deleted
66              until all the instances are released.  Those widgets  will  con‐
67              tinue to display using the last known values for the named font.
68              If a deleted named font is subsequently recreated  with  another
69              call to font create, the widgets will use the new named font and
70              redisplay themselves using the new attributes of that font.
71
72       font families ?-displayof window?
73              The return value is a list of the case-insensitive names of  all
74              font  families  that  exist  on window's display.  If the window
75              argument is omitted, it defaults to the main window.
76
77       font measure font ?-displayof window? text
78              Measures the amount of space the string text would  use  in  the
79              given  font  when  displayed in window.  font is a font descrip‐
80              tion; see FONT DESCRIPTIONS below.  If the  window  argument  is
81              omitted,  it  defaults  to the main window.  The return value is
82              the total width in pixels of text, not including the extra  pix‐
83              els  used  by highly exaggerated characters such as cursive “f”.
84              If the string contains newlines or tabs,  those  characters  are
85              not expanded or treated specially when measuring the string.
86
87       font metrics font ?-displayof window? ?option?
88              Returns  information about the metrics (the font-specific data),
89              for font when it is used on window's display.  font  is  a  font
90              description;  see  FONT DESCRIPTIONS below.  If the window argu‐
91              ment is omitted, it defaults to the main window.  If  option  is
92              specified,  returns  the value of that metric; if it is omitted,
93              the return value is a list of all the metrics and their  values.
94              See FONT METRICS below for a list of the possible metrics.
95
96       font names
97              The  return value is a list of all the named fonts that are cur‐
98              rently defined.
99

FONT DESCRIPTIONS

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

FONT METRICS

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

FONT OPTIONS

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

STANDARD FONTS

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

PLATFORM SPECIFIC FONTS

298       The following system fonts are supported:
299
300       X Windows
301              All  valid  X font names, including those listed by xlsfonts(1),
302              are available.
303
304       MS Windows
305              The following fonts are supported, and are mapped to the  user's
306              style defaults.
307
308                     system      ansi        device
309                     systemfixed ansifixed   oemfixed
310
311
312       Mac OS X
313              The  following fonts are supported, and are mapped to the user's
314              style defaults.
315
316                     system      application menu
317
318
319              Additionally, the following named fonts provide  access  to  the
320              Aqua theme fonts:
321
322                     systemSystemFont    systemEmphasizedSystemFont
323                     systemSmallSystemFontsystemSmallEmphasizedSystemFont
324                     systemApplicationFontsystemLabelFont
325                     systemViewsFont     systemMenuTitleFont
326                     systemMenuItemFont  systemMenuItemMarkFont
327                     systemMenuItemCmdKeyFontsystemWindowTitleFont
328                     systemPushButtonFontsystemUtilityWindowTitleFont
329                     systemAlertHeaderFontsystemToolbarFont
330                     systemMiniSystemFontsystemDetailSystemFont
331                     systemDetailEmphasizedSystemFont
332
333

EXAMPLE

335       Fill  a text widget with lots of font demonstrators, one for every font
336       family installed on your system:
337              pack [text .t -wrap none] -fill both -expand 1
338              set count 0
339              set tabwidth 0
340              foreach family [lsort -dictionary [font families]] {
341                  .t tag configure f[incr count] -font [list $family 10]
342                  .t insert end ${family}:\t {} \
343                          "This is a simple sampler\n" f$count
344                  set w [font measure [.t cget -font] ${family}:]
345                  if {$w+5 > $tabwidth} {
346                      set tabwidth [expr {$w+5}]
347                      .t configure -tabs $tabwidth
348                  }
349              }
350

SEE ALSO

352       options(n)
353

KEYWORDS

355       font
356
357
358
359Tk                                    8.0                              font(n)
Impressum