1XLoadFont(3) XLIB FUNCTIONS XLoadFont(3)
2
3
4
6 XLoadFont, XQueryFont, XLoadQueryFont, XFreeFont, XGetFontProperty,
7 XUnloadFont, XCharStruct, XFontProp, XChar2b, XFontStruct - load or un‐
8 load fonts and font metric structures
9
11 Font XLoadFont(Display *display, _Xconst char *name);
12
13 XFontStruct *XQueryFont(Display *display, XID font_ID);
14
15 XFontStruct *XLoadQueryFont(Display *display, _Xconst char *name);
16
17 int XFreeFont(Display *display, XFontStruct *font_struct);
18
19 Bool XGetFontProperty(XFontStruct *font_struct, Atom atom, unsigned
20 long *value_return);
21
22 int XUnloadFont(Display *display, Font font);
23
25 atom Specifies the atom for the property name you want returned.
26
27 display Specifies the connection to the X server.
28
29 font Specifies the font.
30
31 font_ID Specifies the font ID or the GContext ID.
32
33 font_struct
34 Specifies the storage associated with the font.
35
36 gc Specifies the GC.
37
38 name Specifies the name of the font, which is a null-terminated
39 string.
40
41 value_return
42 Returns the value of the font property.
43
45 The XLoadFont function loads the specified font and returns its associ‐
46 ated font ID. If the font name is not in the Host Portable Character
47 Encoding, the result is implementation-dependent. Use of uppercase or
48 lowercase does not matter. When the characters “?” and “” are used in
49 a font name, a pattern match is performed and any matching font is
50 used. In the pattern, the “?” character will match any single charac‐
51 ter, and the “*” character will match any number of characters. A
52 structured format for font names is specified in the X Consortium stan‐
53 dard X Logical Font Description Conventions. If XLoadFont was unsuc‐
54 cessful at loading the specified font, a BadName error results. Fonts
55 are not associated with a particular screen and can be stored as a com‐
56 ponent of any GC. When the font is no longer needed, call XUnloadFont.
57
58 XLoadFont can generate BadAlloc and BadName errors.
59
60 The XQueryFont function returns a pointer to the XFontStruct structure,
61 which contains information associated with the font. You can query a
62 font or the font stored in a GC. The font ID stored in the XFontStruct
63 structure will be the GContext ID, and you need to be careful when us‐
64 ing this ID in other functions (see XGContextFromGC). If the font does
65 not exist, XQueryFont returns NULL. To free this data, use XFree‐
66 FontInfo.
67
68 XLoadQueryFont can generate a BadAlloc error.
69
70 The XLoadQueryFont function provides the most common way for accessing
71 a font. XLoadQueryFont both opens (loads) the specified font and re‐
72 turns a pointer to the appropriate XFontStruct structure. If the font
73 name is not in the Host Portable Character Encoding, the result is im‐
74 plementation-dependent. If the font does not exist, XLoadQueryFont re‐
75 turns NULL.
76
77 The XFreeFont function deletes the association between the font re‐
78 source ID and the specified font and frees the XFontStruct structure.
79 The font itself will be freed when no other resource references it.
80 The data and the font should not be referenced again.
81
82 XFreeFont can generate a BadFont error.
83
84 Given the atom for that property, the XGetFontProperty function returns
85 the value of the specified font property. XGetFontProperty also re‐
86 turns False if the property was not defined or True if it was defined.
87 A set of predefined atoms exists for font properties, which can be
88 found in This set contains the standard properties associated with a
89 font. Although it is not guaranteed, it is likely that the predefined
90 font properties will be present.
91
92 The XUnloadFont function deletes the association between the font re‐
93 source ID and the specified font. The font itself will be freed when
94 no other resource references it. The font should not be referenced
95 again.
96
97 XUnloadFont can generate a BadFont error.
98
100 The XFontStruct structure contains all of the information for the font
101 and consists of the font-specific information as well as a pointer to
102 an array of XCharStruct structures for the characters contained in the
103 font. The XFontStruct, XFontProp, and XCharStruct structures contain:
104
105 typedef struct {
106 short lbearing; /* origin to left edge of raster */
107 short rbearing; /* origin to right edge of raster */
108 short width; /* advance to next char's origin */
109 short ascent; /* baseline to top edge of raster */
110 short descent; /* baseline to bottom edge of raster */
111 unsigned short attributes; /* per char flags (not predefined) */
112 } XCharStruct;
113
114 typedef struct {
115 Atom name;
116 unsigned long card32;
117 } XFontProp;
118
119 typedef struct { /* normal 16 bit characters are two bytes */
120 unsigned char byte1;
121 unsigned char byte2;
122 } XChar2b;
123
124 typedef struct {
125 XExtData *ext_data; /* hook for extension to hang data */
126 Font fid; /* Font id for this font */
127 unsigned direction; /* hint about the direction font is painted */
128 unsigned min_char_or_byte2; /* first character */
129 unsigned max_char_or_byte2; /* last character */
130 unsigned min_byte1; /* first row that exists */
131 unsigned max_byte1; /* last row that exists */
132 Bool all_chars_exist; /* flag if all characters have nonzero size */
133 unsigned default_char; /* char to print for undefined character */
134 int n_properties; /* how many properties there are */
135 XFontProp *properties; /* pointer to array of additional properties */
136 XCharStruct min_bounds; /* minimum bounds over all existing char */
137 XCharStruct max_bounds; /* maximum bounds over all existing char */
138 XCharStruct *per_char; /* first_char to last_char information */
139 int ascent; /* logical extent above baseline for spacing */
140 int descent; /* logical decent below baseline for spacing */
141 } XFontStruct;
142
143 X supports single byte/character, two bytes/character matrix, and
144 16-bit character text operations. Note that any of these forms can be
145 used with a font, but a single byte/character text request can only
146 specify a single byte (that is, the first row of a 2-byte font). You
147 should view 2-byte fonts as a two-dimensional matrix of defined charac‐
148 ters: byte1 specifies the range of defined rows and byte2 defines the
149 range of defined columns of the font. Single byte/character fonts have
150 one row defined, and the byte2 range specified in the structure defines
151 a range of characters.
152
153 The bounding box of a character is defined by the XCharStruct of that
154 character. When characters are absent from a font, the default_char is
155 used. When fonts have all characters of the same size, only the infor‐
156 mation in the XFontStruct min and max bounds are used.
157
158 The members of the XFontStruct have the following semantics:
159
160 • The direction member can be either FontLeftToRight or FontRight‐
161 ToLeft. It is just a hint as to whether most XCharStruct elements
162 have a positive or a negative character width metric. The core
163 protocol defines no support for vertical text.
164
165 • If the min_byte1 and max_byte1 members are both zero,
166 min_char_or_byte2 specifies the linear character index correspond‐
167 ing to the first element of the per_char array, and
168 max_char_or_byte2 specifies the linear character index of the last
169 element.
170
171 If either min_byte1 or max_byte1 are nonzero, both
172 min_char_or_byte2 and max_char_or_byte2 are less than 256, and the
173 2-byte character index values corresponding to the per_char array
174 element N (counting from 0) are:
175
176 byte1 = N/D + min_byte1
177 byte2 = N\D + min_char_or_byte2
178 where:
179 D = max_char_or_byte2 - min_char_or_byte2 + 1
180 / = integer division
181 \\ = integer modulus
182
183 • If the per_char pointer is NULL, all glyphs between the first and
184 last character indexes inclusive have the same information, as
185 given by both min_bounds and max_bounds.
186
187 • If all_chars_exist is True, all characters in the per_char array
188 have nonzero bounding boxes.
189
190 • The default_char member specifies the character that will be used
191 when an undefined or nonexistent character is printed. The de‐
192 fault_char is a 16-bit character (not a 2-byte character). For a
193 font using 2-byte matrix format, the default_char has byte1 in the
194 most-significant byte and byte2 in the least significant byte. If
195 the default_char itself specifies an undefined or nonexistent
196 character, no printing is performed for an undefined or nonexis‐
197 tent character.
198
199 • The min_bounds and max_bounds members contain the most extreme
200 values of each individual XCharStruct component over all elements
201 of this array (and ignore nonexistent characters). The bounding
202 box of the font (the smallest rectangle enclosing the shape ob‐
203 tained by superimposing all of the characters at the same origin
204 [x,y]) has its upper-left coordinate at:
205 [x + min_bounds.lbearing, y - max_bounds.ascent]
206
207 Its width is:
208 max_bounds.rbearing - min_bounds.lbearing
209
210 Its height is:
211 max_bounds.ascent + max_bounds.descent
212
213 • The ascent member is the logical extent of the font above the
214 baseline that is used for determining line spacing. Specific
215 characters may extend beyond this.
216
217 • The descent member is the logical extent of the font at or below
218 the baseline that is used for determining line spacing. Specific
219 characters may extend beyond this.
220
221 • If the baseline is at Y-coordinate y, the logical extent of the
222 font is inclusive between the Y-coordinate values (y - font.as‐
223 cent) and (y + font.descent - 1). Typically, the minimum inter‐
224 line spacing between rows of text is given by ascent + descent.
225
226 For a character origin at [x,y], the bounding box of a character (that
227 is, the smallest rectangle that encloses the character's shape) de‐
228 scribed in terms of XCharStruct components is a rectangle with its up‐
229 per-left corner at:
230
231 [x + lbearing, y - ascent]
232
233 Its width is:
234
235 rbearing - lbearing
236
237 Its height is:
238
239 ascent + descent
240
241 The origin for the next character is defined to be:
242
243 [x + width, y]
244
245 The lbearing member defines the extent of the left edge of the charac‐
246 ter ink from the origin. The rbearing member defines the extent of the
247 right edge of the character ink from the origin. The ascent member de‐
248 fines the extent of the top edge of the character ink from the origin.
249 The descent member defines the extent of the bottom edge of the charac‐
250 ter ink from the origin. The width member defines the logical width of
251 the character.
252
254 BadAlloc The server failed to allocate the requested resource or
255 server memory.
256
257 BadFont A value for a Font or GContext argument does not name a de‐
258 fined Font.
259
260 BadName A font or color of the specified name does not exist.
261
263 XCreateGC(3), XListFonts(3), XSetFontPath(3)
264 Xlib - C Language X Interface
265
266
267
268X Version 11 libX11 1.7.0 XLoadFont(3)