|
|
1.1 root 1: #include "copyright.h"
2:
3: /* $Header: XFontInfo.c,v 11.8 87/09/11 08:08:46 toddb Exp $ */
4: /* Copyright Massachusetts Institute of Technology 1986 */
5: #define NEED_REPLIES
6: #include "Xlibint.h"
7:
8: char **XListFontsWithInfo(dpy, pattern, maxNames, actualCount, info)
9: register Display *dpy;
10: char *pattern; /* null-terminated */
11: int maxNames;
12: int *actualCount;
13: XFontStruct **info;
14: {
15: register long nbytes;
16: register int i;
17: register XFontStruct *fs;
18: register int size = 0;
19: XFontStruct *finfo = NULL;
20: char **flist = NULL;
21: xListFontsWithInfoReply reply;
22: register xListFontsReq *req;
23:
24: LockDisplay(dpy);
25: GetReq(ListFontsWithInfo, req);
26: req->maxNames = maxNames;
27: nbytes = req->nbytes = strlen (pattern);;
28: req->length += (nbytes + 3) >> 2;
29: _XSend (dpy, pattern, nbytes);
30: /* use _XSend instead of Data, since subsequent _XReply will flush buffer */
31:
32: for (i = 0; ; i++) {
33: if (!_XReply (dpy, (xReply *) &reply,
34: ((sizeof (reply) - sizeof (xGenericReply)) >> 2), xFalse))
35: return (NULL);
36: if (reply.nameLength == 0)
37: break;
38: if ((i + reply.nReplies) >= size) {
39: size = i + reply.nReplies + 1;
40: if (finfo) {
41: finfo = (XFontStruct *) Xrealloc ((char *) finfo,
42: sizeof (XFontStruct) * size);
43: flist = (char **) Xrealloc ((char *) flist,
44: sizeof (char *) * size);
45: } else {
46: finfo = (XFontStruct *) Xmalloc (sizeof (XFontStruct) * size);
47: flist = (char **) Xmalloc (sizeof (char *) * size);
48: }
49: }
50: fs = &finfo[i];
51:
52: fs->ext_data = NULL;
53: fs->per_char = NULL;
54: fs->fid = None;
55: fs->direction = reply.drawDirection;
56: fs->min_char_or_byte2 = reply.minCharOrByte2;
57: fs->max_char_or_byte2 = reply.maxCharOrByte2;
58: fs->min_byte1 = reply.minByte1;
59: fs->max_byte1 = reply.maxByte1;
60: fs->default_char = reply.defaultChar;
61: fs->all_chars_exist = reply.allCharsExist;
62: fs->ascent = reply.fontAscent;
63: fs->descent = reply.fontDescent;
64:
65: /* XXX the next two statements won't work if short isn't 16 bits */
66:
67: fs->min_bounds = * (XCharStruct *) &reply.minBounds;
68: fs->max_bounds = * (XCharStruct *) &reply.maxBounds;
69:
70: fs->n_properties = reply.nFontProps;
71: if (fs->n_properties > 0) {
72: nbytes = reply.nFontProps * sizeof (XFontProp);
73: fs->properties = (XFontProp *) Xmalloc ((unsigned int) nbytes);
74: _XRead (dpy, (char *)fs->properties, nbytes);
75: } else
76: fs->properties = NULL;
77: flist[i] = (char *) Xmalloc ((unsigned int) (reply.nameLength + 1));
78: flist[i][reply.nameLength] = '\0';
79: _XReadPad (dpy, flist[i], reply.nameLength);
80: }
81: *info = finfo;
82: *actualCount = i;
83: UnlockDisplay(dpy);
84: SyncHandle();
85: return (flist);
86: }
87:
88: XFreeFontInfo (names, info, actualCount)
89: char **names;
90: XFontStruct *info;
91: int actualCount;
92: {
93: register int i;
94: if (names != NULL) {
95: for (i = 0; i < actualCount; i++) {
96: Xfree (names[i]);
97: }
98: Xfree((char *) names);
99: }
100: if (info != NULL) {
101: for (i = 0; i < actualCount; i++) {
102: if (info[i].properties != NULL)
103: Xfree ((char *) info[i].properties);
104: }
105: Xfree((char *) info);
106: }
107: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.