Annotation of researchv9/X11/src/X.V11R1/lib/X/XFont.c, revision 1.1.1.1

1.1       root        1: #include "copyright.h"
                      2: 
                      3: /* $Header: XFont.c,v 11.21 87/08/11 13:12:02 newman Exp $ */
                      4: /* Copyright    Massachusetts Institute of Technology    1986  */
                      5: #define NEED_REPLIES
                      6: #include "Xlibint.h"
                      7: 
                      8: XFontStruct *_XQueryFont();
                      9: 
                     10: XFontStruct *XLoadQueryFont(dpy, name)
                     11:    register Display *dpy;
                     12:    char *name;
                     13: {
                     14:     XFontStruct *font_result;
                     15:     register long nbytes;
                     16:     Font fid;
                     17:     xOpenFontReq *req;
                     18: 
                     19:     LockDisplay(dpy);
                     20:     GetReq(OpenFont, req);
                     21:     nbytes = req->nbytes  = strlen(name);
                     22:     req->fid = fid = XAllocID(dpy);
                     23:     req->length += (nbytes+3)>>2;
                     24:     Data (dpy, name, nbytes);
                     25:     dpy->request--;
                     26:     font_result = (_XQueryFont(dpy, fid));
                     27:     dpy->request++;
                     28:     if (!font_result) {
                     29:        /* if _XQueryFont returned NULL, then the OpenFont request got
                     30:           a BadName error.  This means that the following QueryFont
                     31:           request is guaranteed to get a BadFont error, since the id
                     32:           passed to QueryFont wasn't really a valid font id.  To read
                     33:           and discard this second error, we call _XReply again. */
                     34:         xReply reply;
                     35:         (void) _XReply (dpy, &reply, 0, xFalse);
                     36:         }
                     37:     UnlockDisplay(dpy);
                     38:     SyncHandle();
                     39:     return font_result;
                     40: }
                     41: 
                     42: XFreeFont(dpy, fs)
                     43:     register Display *dpy;
                     44:     XFontStruct *fs;
                     45: { 
                     46:     register xResourceReq *req;
                     47:     register _XExtension *ext = dpy->ext_procs;
                     48: 
                     49:     LockDisplay(dpy);
                     50:     while (ext) {              /* call out to any extensions interested */
                     51:        if (ext->free_Font != NULL) (*ext->free_Font)(dpy, fs, &ext->codes);
                     52:        ext = ext->next;
                     53:        }    
                     54:     GetResReq (CloseFont, fs->fid, req);
                     55:     _XFreeExtData(fs->ext_data);
                     56:     if (fs->per_char)
                     57:        Xfree ((char *) fs->per_char);
                     58:     if (fs->properties)
                     59:        Xfree ((char *) fs->properties);
                     60:     Xfree ((char *) fs);
                     61:     ext = dpy->ext_procs;
                     62:     UnlockDisplay(dpy);
                     63:     SyncHandle();
                     64: }
                     65: 
                     66: 
                     67: XFontStruct *_XQueryFont (dpy, fid)    /* Internal-only entry point */
                     68:     register Display *dpy;
                     69:     Font fid;
                     70: 
                     71: {
                     72:     register XFontStruct *fs;
                     73:     register long nbytes;
                     74:     xQueryFontReply reply;
                     75:     register xResourceReq *req;
                     76:     register _XExtension *ext;
                     77: 
                     78:     GetResReq(QueryFont, fid, req);
                     79:     if (!_XReply (dpy, (xReply *) &reply,
                     80:        ((sizeof (reply) - sizeof (xReply)) >> 2), xFalse))
                     81:           return (NULL);
                     82:     fs = (XFontStruct *) Xmalloc (sizeof (XFontStruct));
                     83:     fs->ext_data               = NULL;
                     84:     fs->fid                    = fid;
                     85:     fs->direction              = reply.drawDirection;
                     86:     fs->min_char_or_byte2      = reply.minCharOrByte2;
                     87:     fs->max_char_or_byte2      = reply.maxCharOrByte2;
                     88:     fs->min_byte1              = reply.minByte1;
                     89:     fs->max_byte1              = reply.maxByte1;
                     90:     fs->default_char           = reply.defaultChar;
                     91:     fs->all_chars_exist        = reply.allCharsExist;
                     92:     fs->ascent                         = reply.fontAscent;
                     93:     fs->descent                = reply.fontDescent;
                     94:     
                     95:     /* XXX the next two statements won't work if short isn't 16 bits */
                     96: 
                     97:     fs->min_bounds = * (XCharStruct *) &reply.minBounds;
                     98:     fs->max_bounds = * (XCharStruct *) &reply.maxBounds;
                     99: 
                    100:     fs->n_properties = reply.nFontProps;
                    101:     /* 
                    102:      * if no properties defined for the font, then it is bad
                    103:      * font, but shouldn't try to read nothing.
                    104:      */
                    105:     fs->properties = NULL;
                    106:     if (fs->n_properties > 0) {
                    107:            fs->properties = (XFontProp *) Xmalloc (
                    108:               (unsigned)(nbytes = reply.nFontProps * sizeof (XFontProp)));
                    109:            _XRead (dpy, (char *)fs->properties, nbytes);
                    110:     }
                    111:     /*
                    112:      * If no characters in font, then it is a bad font, but
                    113:      * shouldn't try to read nothing.
                    114:      */
                    115:     /* XXX may have to unpack charinfos on some machines (CRAY) */
                    116:     fs->per_char = NULL;
                    117:     if (reply.nCharInfos > 0){
                    118:            fs->per_char = (XCharStruct *) Xmalloc (
                    119:               (unsigned)(nbytes = reply.nCharInfos * sizeof (XCharStruct)));
                    120:            _XRead (dpy, (char *)fs->per_char, nbytes);
                    121:     }
                    122: 
                    123:     ext = dpy->ext_procs;
                    124:     while (ext) {              /* call out to any extensions interested */
                    125:        if (ext->create_Font != NULL) 
                    126:                (*ext->create_Font)(dpy, fs, &ext->codes);
                    127:        ext = ext->next;
                    128:        }    
                    129:     return (fs);
                    130: }
                    131: 
                    132: 
                    133: XFontStruct *XQueryFont (dpy, fid)
                    134:     register Display *dpy;
                    135:     Font fid;
                    136: {
                    137:     XFontStruct *font_result;
                    138: 
                    139:     LockDisplay(dpy);
                    140:     font_result = _XQueryFont(dpy,fid);
                    141:     UnlockDisplay(dpy);
                    142:     SyncHandle();
                    143:     return font_result;
                    144: }
                    145: 
                    146:    
                    147:    

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.