home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / lib / X / XImText16.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-12  |  2.5 KB  |  104 lines

  1. /* $XConsortium: XImText16.c,v 11.19 91/07/12 16:28:47 rws Exp $ */
  2. /* Copyright    Massachusetts Institute of Technology    1986    */
  3.  
  4. /*
  5. Permission to use, copy, modify, distribute, and sell this software and its
  6. documentation for any purpose is hereby granted without fee, provided that
  7. the above copyright notice appear in all copies and that both that
  8. copyright notice and this permission notice appear in supporting
  9. documentation, and that the name of M.I.T. not be used in advertising or
  10. publicity pertaining to distribution of the software without specific,
  11. written prior permission.  M.I.T. makes no representations about the
  12. suitability of this software for any purpose.  It is provided "as is"
  13. without express or implied warranty.
  14. */
  15.  
  16. #define NEED_REPLIES
  17. #include "Xlibint.h"
  18.  
  19. #if NeedFunctionPrototypes
  20. XDrawImageString16(
  21.     register Display *dpy,
  22.     Drawable d,
  23.     GC gc,
  24.     int x,
  25.     int y,
  26.     _Xconst XChar2b *string,
  27.     int length)
  28. #else
  29. XDrawImageString16(dpy, d, gc, x, y, string, length)
  30.     register Display *dpy;
  31.     Drawable d;
  32.     GC gc;
  33.     int x, y;
  34.     XChar2b *string;
  35.     int length;
  36. #endif
  37. {   
  38.     register xImageText16Req *req;
  39.     xQueryTextExtentsReq *qreq;
  40.     xQueryTextExtentsReply rep;
  41.     XChar2b *CharacterOffset = (XChar2b *)string;
  42.     int FirstTimeThrough = True;
  43.     int lastX = 0;
  44.     char *buf;
  45.     unsigned char *ptr;
  46.     XChar2b *str;
  47.     int i;
  48.  
  49.     LockDisplay(dpy);
  50.     FlushGC(dpy, gc);
  51.     if (length > 255 &&
  52.     ! (buf = _XAllocScratch (dpy, (unsigned long) 512))) {
  53.     UnlockDisplay(dpy);
  54.     SyncHandle();
  55.     return;
  56.     }
  57.  
  58.     while (length > 0) 
  59.     {
  60.     int Unit, Datalength;
  61.  
  62.     if (length > 255) Unit = 255;
  63.     else Unit = length;
  64.  
  65.        if (FirstTimeThrough)
  66.     {
  67.         FirstTimeThrough = False;
  68.         }
  69.     else
  70.     {
  71.         GetReq(QueryTextExtents, qreq);
  72.         qreq->fid = gc->gid;
  73.         qreq->length += (510 + 3)>>2;
  74.         qreq->oddLength = 1;
  75.         str = CharacterOffset - 255;
  76.         for (ptr = (unsigned char *)buf, i = 255; --i >= 0; str++) {
  77.         *ptr++ = str->byte1;
  78.         *ptr++ = str->byte2;
  79.         }
  80.         Data (dpy, buf, 510);
  81.         if (!_XReply (dpy, (xReply *)&rep, 0, xTrue))
  82.         break;
  83.  
  84.         x = lastX + cvtINT32toInt (rep.overallWidth);
  85.     }
  86.  
  87.         GetReq (ImageText16, req);
  88.         req->length += ((Unit << 1) + 3) >> 2;
  89.         req->nChars = Unit;
  90.         req->drawable = d;
  91.         req->gc = gc->gid;
  92.         req->y = y;
  93.  
  94.     lastX = req->x = x;
  95.     Datalength = Unit << 1;
  96.         Data (dpy, (char *)CharacterOffset, (long)Datalength);
  97.         CharacterOffset += Unit;
  98.     length -= Unit;
  99.     }
  100.     UnlockDisplay(dpy);
  101.     SyncHandle();
  102. }
  103.  
  104.