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?
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-dependant  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.
31
32       font configure fontname ?option? ?value option value ...?
33              Query or modify the desired attributes for the named font called
34              fontname.  If no option is specified, returns a list  describing
35              all  the  options  and  their  values for fontname.  If a single
36              option is specified with no  value,  then  returns  the  current
37              value  of that attribute.  If one or more option-value pairs are
38              specified, then the command modifies the  given  named  font  to
39              have the given values; in this case, all widgets using that font
40              will redisplay themselves using the new attributes for the font.
41              See FONT OPTIONS below for a list of the possible attributes.
42
43       font create ?fontname? ?option value ...?
44              Creates  a new named font and returns its name.  fontname speci‐
45              fies the name for the font; if it is omitted, then Tk  generates
46              a  new name of the form fontx, where x is an integer.  There may
47              be any number of option-value pairs, which provide  the  desired
48              attributes for the new named font.  See FONT OPTIONS below for a
49              list of the possible attributes.
50
51       font delete fontname ?fontname ...?
52              Delete the specified named fonts.  If there  are  widgets  using
53              the  named  font, the named font won't actually be deleted until
54              all the instances are released.  Those widgets will continue  to
55              display  using  the  last known values for the named font.  If a
56              deleted named font is subsequently recreated with  another  call
57              to  font  create,  the  widgets  will use the new named font and
58              redisplay themselves using the new attributes of that font.
59
60       font families ?-displayof window?
61              The return value is a list of the case-insensitive names of  all
62              font  families  that  exist  on window's display.  If the window
63              argument is omitted, it defaults to the main window.
64
65       font measure font ?-displayof window? text
66              Measures the amount of space the string text would  use  in  the
67              given  font  when  displayed in window.  font is a font descrip‐
68              tion; see FONT DESCRIPTIONS below.  If the  window  argument  is
69              omitted,  it  defaults  to the main window.  The return value is
70              the total width in pixels of text, not including the extra  pix‐
71              els used by highly exaggerated characters such as cursive ``f''.
72              If the string contains newlines or tabs,  those  characters  are
73              not expanded or treated specially when measuring the string.
74
75       font metrics font ?-displayof window? ?option?
76              Returns  information about the metrics (the font-specific data),
77              for font when it is used on window's display.  font  is  a  font
78              description;  see  FONT DESCRIPTIONS below.  If the window argu‐
79              ment is omitted, it defaults to the main window.  If  option  is
80              specified,  returns  the value of that metric; if it is omitted,
81              the return value is a list of all the metrics and their  values.
82              See FONT METRICS below for a list of the possible metrics.
83
84       font names
85              The  return value is a list of all the named fonts that are cur‐
86              rently defined.
87

FONT DESCRIPTION

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

FONT METRICS

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

FONT OPTIONS

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

PLATFORM-SPECIFIC ISSUES

243       The following named system fonts are supported:
244
245              X Windows:
246                     All  valid  X  font names, including those listed by xls‐
247                     fonts(1), are available.
248
249              MS Windows:
250                     system      ansi        device          systemfixed ansi‐
251                     fixed   oemfixed
252
253              Macintosh:
254                     system      application
255

EXAMPLE

257       Fill  a text widget with lots of font demonstrators, one for every font
258       family installed on your system:
259              pack [text .t -wrap none] -fill both -expand 1
260              set count 0
261              set tabwidth 0
262              foreach family [lsort -dictionary [font families]] {
263                  .t tag configure f[incr count] -font [list $family 10]
264                  .t insert end ${family}:\t {} \
265                          "This is a simple sampler\n" f$count
266                  set w [font measure [.t cget -font] ${family}:]
267                  if {$w+5 > $tabwidth} {
268                      set tabwidth [expr {$w+5}]
269                      .t configure -tabs $tabwidth
270                  }
271              }
272
273

SEE ALSO

275       options(n)
276
277

KEYWORDS

279       font
280
281
282
283Tk                                    8.0                              font(n)
Impressum