3 cachechars, agefont, loadchar, Subfont, Fontchar, Font \- font utilities
11 .ta \w'\fLCacheinfo 'u
14 int cachechars(Font *f, char **s, Rune **r, ushort *c, int max,
17 int *widp, char **sfname)
20 int loadchar(Font *f, Rune r, Cacheinfo *c, int h,
23 int noclr, char **sfname)
30 may contain too many characters to hold in memory
32 The graphics library and draw device (see
34 cooperate to solve this problem by maintaining a cache of recently used
36 The details of this cooperation need not be known by most programs:
46 are sufficient for most purposes.
47 The routines described below are used internally by the graphics library
48 to maintain the font cache.
52 is a set of images for a contiguous range of characters, stored as a single
55 placed side-by-side on a common baseline.
56 It is described by the following data structures.
59 .ta 6n +\w'Fontchar 'u +\w'bottom; 'u
62 int x; /* left edge of bits */
63 uchar top; /* first non-zero scan-line */
64 uchar bottom; /* last non-zero scan-line */
65 char left; /* offset of baseline */
66 uchar width; /* width of baseline */
72 short n; /* number of chars in subfont */
73 uchar height; /* height of image */
74 char ascent; /* top of image to baseline */
75 Fontchar *info; /* n+1 Fontchars */
76 Image *bits; /* of font */
80 The image fills the rectangle
81 \fL(0, 0, \fIw\fP, height)\fR,
84 is the sum of the horizontal extents (of non-zero pixels)
86 The pixels to be displayed for character
89 \fL(\fIi\fP->x, \fIi\fP->top, (\fIi\fP+1)->x, \%\fIi\fP->bottom)\fR
94 &subfont->info[\fIc\fP]\fR.
95 When a character is displayed at
99 the character rectangle is placed at
102 and the next character of the string is displayed at
105 The baseline of the characters is
107 rows down from the top of the subfont image.
112 elements, one each for characters 0 to
114 plus an additional entry so the size of the last character
124 .BR s->info[s->n].x .
128 consists of an overall height and ascent
129 and a collection of subfonts together with the ranges of runes (see
132 Fonts are described by the following structures.
135 .ta 6n +\w'Cacheinfo 'u +\w'height; 'u
138 Rune min; /* value of 0th char in subfont */
139 Rune max; /* value+1 of last char in subfont */
140 int offset; /* posn in subfont of char at min */
141 char *name; /* stored in font */
142 char *subfontname; /* to access subfont */
147 ushort x; /* left edge of bits */
148 uchar width; /* width of baseline */
149 schar left; /* offset of baseline */
150 Rune value; /* of char at this slot in cache */
156 ulong age; /* for replacement */
157 Cachefont *cf; /* font info that owns us */
158 Subfont *f; /* attached subfont */
165 short height; /* max ht of image;interline space*/
166 short ascent; /* top of image to baseline */
167 short width; /* widest so far; used in caching */
168 short nsub; /* number of subfonts */
169 ulong age; /* increasing counter; for LRU */
170 int ncache; /* size of cache */
171 int nsubf; /* size of subfont list */
174 Cachefont **sub; /* as read from file */
183 fields of Font are described in
196 inclusive, to the subfont
199 it corresponds to a line of the file describing the font.
202 are taken from the subfont starting at character number
204 (usually zero) in the subfont, permitting selection of parts of subfonts.
212 For each font, the library, with support from the
215 subfonts and a cache of recently used
221 fields are used by the library to maintain these caches.
224 of a font is the maximum of the horizontal extents of the characters
227 draws a string by loading the cache and emitting a sequence of
228 cache indices to draw.
230 guarantees the images for the characters pointed to by
234 (one of these must be nil in each call)
239 to put missing characters into the cache.
241 translates the character string into a set of cache indices
242 which it loads into the array
246 indices or the length of the string.
250 the number of cache indices emitted,
253 to point to the next character to be processed, and sets
255 to the total width of the characters processed.
257 may return before the end of the string if it cannot
258 proceed without destroying active data in the caches.
259 If it needs to load a new subfont, it will fill
261 with the name of the subfont it needs and return \-1.
262 It can return zero if it is unable to make progress because
263 it cannot resize the caches.
266 loads a character image into the character cache.
267 Then it tells the graphics server to copy the character
270 in the character cache.
273 is smaller than the horizontal extent of the character being loaded,
275 clears the cache and resets it to
276 accept characters with the bigger width, unless
278 is set, in which case it just returns \-1.
279 If the character does not exist in the font at all,
281 returns 0; if it is unable to load the character
282 without destroying cached information, it returns \-1,
286 It returns 1 to indicate success.
291 subfonts and characters have been used.
294 is increased every time the font is used
297 A character or subfont
299 is set to the font age at each use.
300 Thus, characters or subfonts with small ages are the best candidates
301 for replacement when the cache is full.
312 All of the functions use the graphics error function (see