1Tk_AllocFontFromObj(3)       Tk Library Procedures      Tk_AllocFontFromObj(3)
2
3
4
5______________________________________________________________________________
6

NAME

8       Tk_AllocFontFromObj,   Tk_GetFont,   Tk_GetFontFromObj,  Tk_NameOfFont,
9       Tk_FreeFontFromObj, Tk_FreeFont - maintain database of fonts
10

SYNOPSIS

12       #include <tk.h>
13
14       Tk_Font                                                                 │
15       Tk_AllocFontFromObj(interp, tkwin, objPtr)                              
16
17       Tk_Font                                                                 │
18       Tk_GetFont(interp, tkwin, string)                                       
19
20       Tk_Font                                                                 │
21       Tk_GetFontFromObj(tkwin, objPtr)                                        
22
23       CONST char *
24       Tk_NameOfFont(tkfont)
25
26       Tk_Font                                                                 │
27       Tk_FreeFontFromObj(tkwin, objPtr)                                       
28
29       void
30       Tk_FreeFont(tkfont)
31
32

ARGUMENTS

34       Tcl_Interp   *interp   (in)      Interpreter to use for  error  report‐
35                                        ing.   If NULL, then no error messages
36                                        are left after errors.
37
38       Tk_Window    tkwin     (in)      Token for window in which font will be
39                                        used.
40
41       Tcl_Obj      *objPtr   (in/out)                                         │
42                                        Gives  name  or  description  of font. │
43                                        See documentation for the font command │
44                                        for  details  on  acceptable  formats. │
45                                        Internal rep will be modified to cache │
46                                        corresponding Tk_Font.                 │
47
48       const char   *string   (in)                                             │
49                                        Same  as  objPtr except description of │
50                                        font is passed as a string and result‐ │
51                                        ing Tk_Font isn't cached.
52
53       Tk_Font      tkfont    (in)      Opaque font token.
54_________________________________________________________________
55

DESCRIPTION

57       Tk_AllocFontFromObj  finds  the  font indicated by objPtr and returns a │
58       token that represents the font.  The return value can be used in subse‐ │
59       quent  calls  to procedures such as Tk_GetFontMetrics, Tk_MeasureChars, │
60       and Tk_FreeFont.  The Tk_Font token will remain  valid  until  Tk_Free‐ 
61       FontFromObj or Tk_FreeFont is called to release it.  ObjPtr can contain │
62       either a symbolic name or a font description; see the documentation for │
63       the  font command for a description of the valid formats.  If Tk_Alloc‐ 
64       FontFromObj is unsuccessful (because, for example, objPtr did not  con‐ │
65       tain  a  valid  font  specification) then it returns NULL and leaves an │
66       error message in interp's result if interp isn't  NULL.   Tk_AllocFont‐ 
67       FromObj  caches  information  about  the  return value in objPtr, which │
68       speeds up future calls to procedures such  as  Tk_AllocFontFromObj  and │
69       Tk_GetFontFromObj.                                                      │
70
71       Tk_GetFont is identical to Tk_AllocFontFromObj except that the descrip‐ │
72       tion of the font is specified with a string instead of an object.  This │
73       prevents Tk_GetFont from caching the matching Tk_Font, so Tk_GetFont is │
74       less efficient than Tk_AllocFontFromObj.                                │
75
76       Tk_GetFontFromObj returns the token for an  existing  font,  given  the │
77       window  and  description  used  to  create the font.  Tk_GetFontFromObj 
78       doesn't actually create the font; the font must already have been  cre‐ │
79       ated  with  a  previous call to Tk_AllocFontFromObj or Tk_GetFont.  The │
80       return value is cached in objPtr,  which  speeds  up  future  calls  to │
81       Tk_GetFontFromObj with the same objPtr and tkwin.
82
83       Tk_AllocFontFromObj  and  Tk_GetFont  maintain  a database of all fonts
84       they have allocated.  If the same  font  is  requested  multiple  times
85       (e.g.  by  different  windows or for different purposes), then a single
86       Tk_Font will be shared for all uses.  The underlying resources will  be
87       freed automatically when no-one is using the font anymore.
88
89       The  procedure  Tk_NameOfFont  is  roughly  the  inverse of Tk_GetFont.
90       Given a tkfont that was created by Tk_GetFont (or Tk_AllocFontFromObj),
91       the  return  value is the string argument that was passed to Tk_GetFont
92       to create the font.  The string returned by Tk_NameOfFont is only guar‐
93       anteed  to  persist  until  the tkfont is deleted.  The caller must not
94       modify this string.
95
96       When a font is no  longer  needed,  Tk_FreeFontFromObj  or  Tk_FreeFont 
97       should  be  called  to  release it.  For Tk_FreeFontFromObj the font to │
98       release is specified with the same information used to create  it;  for │
99       Tk_FreeFont  the  font  to release is specified with its Tk_Font token. │
100       There should be exactly one call to Tk_FreeFontFromObj  or  Tk_FreeFont 
101       for each call to Tk_AllocFontFromObj or Tk_GetFont.
102
103

SEE ALSO

105       Tk_FontId(3)
106
107

KEYWORDS

109       font
110
111
112
113Tk                                    8.1               Tk_AllocFontFromObj(3)
Impressum