|
|
1.1 root 1: #include "copyright.h"
2:
3: /* $Header: XPolyTxt.c,v 11.12 87/09/01 15:01:44 newman Locked $ */
4: /* Copyright Massachusetts Institute of Technology 1986 */
5:
6: #include "Xlibint.h"
7:
8: XDrawText(dpy, d, gc, x, y, items, nitems)
9: register Display *dpy;
10: Drawable d;
11: GC gc;
12: int x, y;
13: XTextItem *items;
14: int nitems;
15: {
16: register int i;
17: register XTextItem *item;
18: int length = 0;
19: register xPolyText8Req *req;
20:
21: LockDisplay(dpy);
22: FlushGC(dpy, gc);
23: GetReq (PolyText8, req);
24: req->drawable = d;
25: req->gc = gc->gid;
26: req->x = x;
27: req->y = y;
28:
29: item = items;
30: for (i=0; i < nitems; i++) {
31: if (item->font)
32: length += 5; /* a 255 byte, plus size of Font id */
33: if (item->delta)
34: {
35: if (item->delta > 0)
36: {
37: length += sizeof(xTextElt) * ((item->delta + 126) / 127);
38: }
39: else
40: {
41: length += sizeof(xTextElt) * ((abs(item->delta) + 127) / 128);
42: }
43: }
44: if (item->nchars > 0)
45: {
46: length += sizeof(xTextElt) * ((item->nchars + 253) / 254 - 1);
47: if (!item->delta) length += sizeof(xTextElt);
48: length += item->nchars;
49: }
50: item++;
51: }
52:
53: req->length += (length + 3)>>2; /* convert to number of 32-bit words */
54:
55:
56: /*
57: * If the entire request does not fit into the remaining space in the
58: * buffer, flush the buffer first. If the request does fit into the
59: * empty buffer, then we won't have to flush it at the end to keep
60: * the buffer 32-bit aligned.
61: */
62:
63: if (dpy->bufptr + length > dpy->bufmax)
64: _XFlush (dpy);
65:
66: item = items;
67: for (i=0; i< nitems; i++) {
68:
69: if (item->font) {
70: /* to mark a font shift, write a 255 byte followed by
71: the 4 bytes of font ID, big-end first */
72: register unsigned char *f;
73: BufAlloc (unsigned char *, f, 5);
74:
75: f[0] = 255;
76: f[1] = (item->font & 0xff000000) >> 24;
77: f[2] = (item->font & 0x00ff0000) >> 16;
78: f[3] = (item->font & 0x0000ff00) >> 8;
79: f[4] = item->font & 0x000000ff;
80:
81: /* update GC shadow */
82: gc->values.font = item->font;
83: }
84:
85: {
86: int nbytes = sizeof (xTextElt);
87: int PartialNChars = item->nchars;
88: int PartialDelta = item->delta;
89: register xTextElt *elt;
90: int FirstTimeThrough = True;
91: char *CharacterOffset = item->chars;
92:
93: while((PartialDelta < -128) || (PartialDelta > 127))
94: {
95: int nb = sizeof (xTextElt);
96:
97: BufAlloc (xTextElt *, elt, nb);
98: elt->len = 0;
99: if (PartialDelta > 0 )
100: {
101: elt->delta = 127;
102: PartialDelta = PartialDelta - 127;
103: }
104: else
105: {
106: elt->delta = -128;
107: PartialDelta = PartialDelta + 128;
108: }
109: }
110: if (PartialDelta)
111: {
112: BufAlloc (xTextElt *, elt, nbytes);
113: elt->len = 0;
114: elt->delta = PartialDelta;
115: }
116: while(PartialNChars > 254)
117: {
118: nbytes = 254;
119: if (FirstTimeThrough)
120: {
121: FirstTimeThrough = False;
122: if (!item->delta)
123: {
124: nbytes += sizeof(xTextElt);
125: BufAlloc (xTextElt *, elt, nbytes);
126: elt->delta = 0;
127: }
128: else
129: {
130: char *DummyChar;
131: BufAlloc(char *, DummyChar, nbytes);
132: }
133: }
134: else
135: {
136: nbytes += sizeof(xTextElt);
137: BufAlloc (xTextElt *, elt, nbytes);
138: elt->delta = 0;
139: }
140: elt->len = 254;
141: bcopy (CharacterOffset, (char *) (elt + 1), 254);
142: PartialNChars = PartialNChars - 254;
143: CharacterOffset += 254;
144:
145: }
146: if (PartialNChars)
147: {
148: nbytes = PartialNChars;
149: if (FirstTimeThrough)
150: {
151: FirstTimeThrough = False;
152: if (!item->delta)
153: {
154: nbytes += sizeof(xTextElt);
155: BufAlloc (xTextElt *, elt, nbytes);
156: elt->delta = 0;
157: }
158: else
159: {
160: char *DummyChar;
161: BufAlloc(char *, DummyChar, nbytes);
162: }
163: }
164: else
165: {
166: nbytes += sizeof(xTextElt);
167: BufAlloc (xTextElt *, elt, nbytes);
168: elt->delta = 0;
169: }
170: elt->len = PartialNChars;
171: bcopy (CharacterOffset, (char *) (elt + 1), PartialNChars);
172: }
173: }
174: item++;
175: }
176:
177: /* Pad request out to a 32-bit boundary */
178:
179: if (length &= 3) {
180: char *pad;
181: /*
182: * BufAlloc is a macro that uses its last argument more than
183: * once, otherwise I'd write "BufAlloc (char *, pad, 4-length)"
184: */
185: length = 4 - length;
186: BufAlloc (char *, pad, length);
187: /*
188: * if there are 3 bytes of padding, the first byte MUST be 0
189: * so the pad bytes aren't mistaken for a final xTextElt
190: */
191: *pad = 0;
192: }
193:
194: /*
195: * If the buffer pointer is not now pointing to a 32-bit boundary,
196: * we must flush the buffer so that it does point to a 32-bit boundary
197: * at the end of this routine.
198: */
199:
200: if ((dpy->bufptr - dpy->buffer) & 3)
201: _XFlush (dpy);
202: UnlockDisplay(dpy);
203: SyncHandle();
204: return;
205: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.