1Tk_AllocFontFromObj(3) Tk Library Procedures Tk_AllocFontFromObj(3)
2
3
4
5______________________________________________________________________________
6
8 Tk_AllocFontFromObj, Tk_GetFont, Tk_GetFontFromObj, Tk_NameOfFont,
9 Tk_FreeFontFromObj, Tk_FreeFont - maintain database of fonts
10
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
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) Gives name or description of font.
42 See documentation for the font command
43 for details on acceptable formats.
44 Internal rep will be modified to cache
45 corresponding Tk_Font.
46
47 const char *string (in) Same as objPtr except description of
48 font is passed as a string and result‐
49 ing Tk_Font is not cached.
50
51 Tk_Font tkfont (in) Opaque font token.
52_________________________________________________________________
53
55 Tk_AllocFontFromObj finds the font indicated by objPtr and returns a
56 token that represents the font. The return value can be used in subse‐
57 quent calls to procedures such as Tk_GetFontMetrics, Tk_MeasureChars,
58 and Tk_FreeFont. The Tk_Font token will remain valid until Tk_Free‐
59 FontFromObj or Tk_FreeFont is called to release it. ObjPtr can contain
60 either a symbolic name or a font description; see the documentation for
61 the font command for a description of the valid formats. If Tk_Alloc‐
62 FontFromObj is unsuccessful (because, for example, objPtr did not con‐
63 tain a valid font specification) then it returns NULL and leaves an
64 error message in interp's result if interp is not NULL. Tk_AllocFont‐
65 FromObj caches information about the return value in objPtr, which
66 speeds up future calls to procedures such as Tk_AllocFontFromObj and
67 Tk_GetFontFromObj.
68
69 Tk_GetFont is identical to Tk_AllocFontFromObj except that the descrip‐
70 tion of the font is specified with a string instead of an object. This
71 prevents Tk_GetFont from caching the matching Tk_Font, so Tk_GetFont is
72 less efficient than Tk_AllocFontFromObj.
73
74 Tk_GetFontFromObj returns the token for an existing font, given the
75 window and description used to create the font. Tk_GetFontFromObj does
76 not actually create the font; the font must already have been created
77 with a previous call to Tk_AllocFontFromObj or Tk_GetFont. The return
78 value is cached in objPtr, which speeds up future calls to Tk_GetFont‐
79 FromObj with the same objPtr and tkwin.
80
81 Tk_AllocFontFromObj and Tk_GetFont maintain a database of all fonts
82 they have allocated. If the same font is requested multiple times
83 (e.g. by different windows or for different purposes), then a single
84 Tk_Font will be shared for all uses. The underlying resources will be
85 freed automatically when no-one is using the font anymore.
86
87 The procedure Tk_NameOfFont is roughly the inverse of Tk_GetFont.
88 Given a tkfont that was created by Tk_GetFont (or Tk_AllocFontFromObj),
89 the return value is the string argument that was passed to Tk_GetFont
90 to create the font. The string returned by Tk_NameOfFont is only guar‐
91 anteed to persist until the tkfont is deleted. The caller must not
92 modify this string.
93
94 When a font is no longer needed, Tk_FreeFontFromObj or Tk_FreeFont
95 should be called to release it. For Tk_FreeFontFromObj the font to
96 release is specified with the same information used to create it; for
97 Tk_FreeFont the font to release is specified with its Tk_Font token.
98 There should be exactly one call to Tk_FreeFontFromObj or Tk_FreeFont
99 for each call to Tk_AllocFontFromObj or Tk_GetFont.
100
101
103 Tk_FontId(3)
104
106 font
107
108
109
110Tk 8.1 Tk_AllocFontFromObj(3)