~ubuntu-branches/ubuntu/gutsy/vnc4/gutsy

« back to all changes in this revision

Viewing changes to unix/xc/lib/Xft1/xftrender.c

  • Committer: Bazaar Package Importer
  • Author(s): Ola Lundqvist
  • Date: 2006-05-15 20:35:17 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060515203517-l4lre1ku942mn26k
Tags: 4.1.1+X4.3.0-10
* Correction of critical security issue. Thanks to Martin Kogler
  <e9925248@student.tuwien.ac.at> that informed me about the issue,
  and provided the patch.
  This flaw was originally found by Steve Wiseman of intelliadmin.com.
* Applied patch from Javier Kohen <jkohen@users.sourceforge.net> that
  inform the user that only 8 first characters of the password will
  actually be used when typing more than 8 characters, closes:
  #355619.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * $XFree86: xc/lib/Xft1/xftrender.c,v 1.1.1.1 2002/02/15 01:26:15 keithp Exp $
 
3
 *
 
4
 * Copyright � 2000 Keith Packard, member of The XFree86 Project, Inc.
 
5
 *
 
6
 * Permission to use, copy, modify, distribute, and sell this software and its
 
7
 * documentation for any purpose is hereby granted without fee, provided that
 
8
 * the above copyright notice appear in all copies and that both that
 
9
 * copyright notice and this permission notice appear in supporting
 
10
 * documentation, and that the name of Keith Packard not be used in
 
11
 * advertising or publicity pertaining to distribution of the software without
 
12
 * specific, written prior permission.  Keith Packard makes no
 
13
 * representations about the suitability of this software for any purpose.  It
 
14
 * is provided "as is" without express or implied warranty.
 
15
 *
 
16
 * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 
17
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
 
18
 * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
 
19
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
 
20
 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
 
21
 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 
22
 * PERFORMANCE OF THIS SOFTWARE.
 
23
 */
 
24
 
 
25
#include <stdlib.h>
 
26
#include "xftint.h"
 
27
 
 
28
void
 
29
XftRenderString8 (Display *dpy, Picture src, 
 
30
                  XftFontStruct *font, Picture dst,
 
31
                  int srcx, int srcy,
 
32
                  int x, int y,
 
33
                  XftChar8 *string, int len)
 
34
{
 
35
    XftChar32       missing[XFT_NMISSING];
 
36
    int             nmissing;
 
37
    XftChar8        *s;
 
38
    int             l;
 
39
 
 
40
    s = string;
 
41
    l = len;
 
42
    nmissing = 0;
 
43
    while (l--)
 
44
        XftGlyphCheck (dpy, font, (XftChar32) *s++, missing, &nmissing);
 
45
    if (nmissing)
 
46
        XftGlyphLoad (dpy, font, missing, nmissing);
 
47
    XRenderCompositeString8 (dpy, PictOpOver, src, dst,
 
48
                             font->format, font->glyphset,
 
49
                             srcx, srcy, x, y, (char *) string, len);
 
50
}
 
51
 
 
52
void
 
53
XftRenderString16 (Display *dpy, Picture src, 
 
54
                   XftFontStruct *font, Picture dst,
 
55
                   int srcx, int srcy,
 
56
                   int x, int y,
 
57
                   XftChar16 *string, int len)
 
58
{
 
59
    XftChar32       missing[XFT_NMISSING];
 
60
    int             nmissing;
 
61
    XftChar16       *s;
 
62
    int             l;
 
63
 
 
64
    s = string;
 
65
    l = len;
 
66
    nmissing = 0;
 
67
    while (l--)
 
68
        XftGlyphCheck (dpy, font, (XftChar32) *s++, missing, &nmissing);
 
69
    if (nmissing)
 
70
        XftGlyphLoad (dpy, font, missing, nmissing);
 
71
    XRenderCompositeString16 (dpy, PictOpOver, src, dst,
 
72
                              font->format, font->glyphset,
 
73
                              srcx, srcy, x, y, string, len);
 
74
}
 
75
 
 
76
void
 
77
XftRenderString32 (Display *dpy, Picture src, 
 
78
                   XftFontStruct *font, Picture dst,
 
79
                   int srcx, int srcy,
 
80
                   int x, int y,
 
81
                   XftChar32 *string, int len)
 
82
{
 
83
    XftChar32       missing[XFT_NMISSING];
 
84
    int             nmissing;
 
85
    XftChar32       *s;
 
86
    int             l;
 
87
 
 
88
    s = string;
 
89
    l = len;
 
90
    nmissing = 0;
 
91
    while (l--)
 
92
        XftGlyphCheck (dpy, font, (XftChar32) *s++, missing, &nmissing);
 
93
    if (nmissing)
 
94
        XftGlyphLoad (dpy, font, missing, nmissing);
 
95
    XRenderCompositeString32 (dpy, PictOpOver, src, dst,
 
96
                              font->format, font->glyphset,
 
97
                              srcx, srcy, x, y, string, len);
 
98
}
 
99
 
 
100
void
 
101
XftRenderStringUtf8 (Display *dpy, Picture src, 
 
102
                     XftFontStruct *font, Picture dst,
 
103
                     int srcx, int srcy,
 
104
                     int x, int y,
 
105
                     XftChar8 *string, int len)
 
106
{
 
107
    XftChar8    *s;
 
108
    XftChar32   c;
 
109
    XftChar32   lbuf[4096];
 
110
    XftChar32   *d;
 
111
    XftChar8    *dst8;
 
112
    XftChar16   *dst16;
 
113
    XftChar32   *dst32;
 
114
    int         rlen, clen;
 
115
    int         width = 1;
 
116
    int         n;
 
117
 
 
118
    /* compute needed width */
 
119
    if (!XftUtf8Len (string, len, &n, &width))
 
120
        return;
 
121
    
 
122
    d = lbuf;
 
123
    if (n * width > sizeof (lbuf))
 
124
    {
 
125
        d = (XftChar32 *) malloc (n * width);
 
126
        if (!d)
 
127
            return;
 
128
    }
 
129
    
 
130
    switch (width) {
 
131
    case 4:
 
132
        s = string;
 
133
        rlen = len;
 
134
        dst32 = d;
 
135
        while (rlen)
 
136
        {
 
137
            clen = XftUtf8ToUcs4 (s, &c, rlen);
 
138
            if (clen <= 0)      /* malformed UTF8 string */
 
139
                return;
 
140
            *dst32++ = c;
 
141
            s += clen;
 
142
            rlen -= clen;
 
143
        }
 
144
        dst32 = d;
 
145
        XftRenderString32 (dpy, src, font, dst, srcx, srcy, x, y,
 
146
                         dst32, n);
 
147
        break;
 
148
    case 2:
 
149
        s = string;
 
150
        rlen = len;
 
151
        dst16 = (XftChar16 *) d;
 
152
        while (rlen)
 
153
        {
 
154
            clen = XftUtf8ToUcs4 (s, &c, rlen);
 
155
            if (clen <= 0)      /* malformed UTF8 string */
 
156
                return;
 
157
            *dst16++ = c;
 
158
            s += clen;
 
159
            rlen -= clen;
 
160
        }
 
161
        dst16 = (XftChar16 *) d;
 
162
        XftRenderString16 (dpy, src, font, dst, srcx, srcy, x, y,
 
163
                           dst16, n);
 
164
        break;
 
165
    case 1:
 
166
        s = string;
 
167
        rlen = len;
 
168
        dst8 = (XftChar8 *) d;
 
169
        while (rlen)
 
170
        {
 
171
            clen = XftUtf8ToUcs4 (s, &c, rlen);
 
172
            if (clen <= 0)      /* malformed UTF8 string */
 
173
                return;
 
174
            *dst8++ = c;
 
175
            s += clen;
 
176
            rlen -= clen;
 
177
        }
 
178
        dst8 = (XftChar8 *) d;
 
179
        XftRenderString8 (dpy, src, font, dst, srcx, srcy, x, y,
 
180
                          dst8, n);
 
181
        break;
 
182
    }
 
183
    if (d != lbuf)
 
184
        free (d);
 
185
}
 
186
   
 
187
void
 
188
XftRenderExtents8 (Display          *dpy,
 
189
                   XftFontStruct    *font,
 
190
                   XftChar8    *string, 
 
191
                   int              len,
 
192
                   XGlyphInfo       *extents)
 
193
{
 
194
    XftChar32       missing[XFT_NMISSING];
 
195
    int             nmissing;
 
196
    XftChar8        *s, c;
 
197
    int             l;
 
198
    XGlyphInfo      *gi;
 
199
    int             x, y;
 
200
    int             left, right, top, bottom;
 
201
    int             overall_left, overall_right;
 
202
    int             overall_top, overall_bottom;
 
203
 
 
204
    s = string;
 
205
    l = len;
 
206
    nmissing = 0;
 
207
    while (l--)
 
208
        XftGlyphCheck (dpy, font, (XftChar32) *s++, missing, &nmissing);
 
209
    if (nmissing)
 
210
        XftGlyphLoad (dpy, font, missing, nmissing);
 
211
    
 
212
    gi = 0;
 
213
    while (len)
 
214
    {
 
215
        c = *string++;
 
216
        len--;
 
217
        gi = c < font->nrealized ? font->realized[c] : 0;
 
218
        if (gi)
 
219
            break;
 
220
    }
 
221
    if (len == 0 && !gi)
 
222
    {
 
223
        extents->width = 0;
 
224
        extents->height = 0;
 
225
        extents->x = 0;
 
226
        extents->y = 0;
 
227
        extents->yOff = 0;
 
228
        extents->xOff = 0;
 
229
        return;
 
230
    }
 
231
    x = 0;
 
232
    y = 0;
 
233
    overall_left = x - gi->x;
 
234
    overall_top = y - gi->y;
 
235
    overall_right = overall_left + (int) gi->width;
 
236
    overall_bottom = overall_top + (int) gi->height;
 
237
    x += gi->xOff;
 
238
    y += gi->yOff;
 
239
    while (len--)
 
240
    {
 
241
        c = *string++;
 
242
        gi = c < font->nrealized ? font->realized[c] : 0;
 
243
        if (!gi)
 
244
            continue;
 
245
        left = x - gi->x;
 
246
        top = y - gi->y;
 
247
        right = left + (int) gi->width;
 
248
        bottom = top + (int) gi->height;
 
249
        if (left < overall_left)
 
250
            overall_left = left;
 
251
        if (top < overall_top)
 
252
            overall_top = top;
 
253
        if (right > overall_right)
 
254
            overall_right = right;
 
255
        if (bottom > overall_bottom)
 
256
            overall_bottom = bottom;
 
257
        x += gi->xOff;
 
258
        y += gi->yOff;
 
259
    }
 
260
    extents->x = -overall_left;
 
261
    extents->y = -overall_top;
 
262
    extents->width = overall_right - overall_left;
 
263
    extents->height = overall_bottom - overall_top;
 
264
    extents->xOff = x;
 
265
    extents->yOff = y;
 
266
}
 
267
 
 
268
void
 
269
XftRenderExtents16 (Display         *dpy,
 
270
                    XftFontStruct   *font,
 
271
                    XftChar16       *string,
 
272
                    int             len,
 
273
                    XGlyphInfo      *extents)
 
274
{
 
275
    XftChar32       missing[XFT_NMISSING];
 
276
    int             nmissing;
 
277
    XftChar16       *s, c;
 
278
    int             l;
 
279
    XGlyphInfo      *gi;
 
280
    int             x, y;
 
281
    int             left, right, top, bottom;
 
282
    int             overall_left, overall_right;
 
283
    int             overall_top, overall_bottom;
 
284
 
 
285
    s = string;
 
286
    l = len;
 
287
    nmissing = 0;
 
288
    while (l--)
 
289
        XftGlyphCheck (dpy, font, (XftChar32) *s++, missing, &nmissing);
 
290
    if (nmissing)
 
291
        XftGlyphLoad (dpy, font, missing, nmissing);
 
292
    
 
293
    gi = 0;
 
294
    while (len)
 
295
    {
 
296
        c = *string++;
 
297
        len--;
 
298
        gi = c < font->nrealized ? font->realized[c] : 0;
 
299
        if (gi)
 
300
            break;
 
301
    }
 
302
    if (len == 0 && !gi)
 
303
    {
 
304
        extents->width = 0;
 
305
        extents->height = 0;
 
306
        extents->x = 0;
 
307
        extents->y = 0;
 
308
        extents->yOff = 0;
 
309
        extents->xOff = 0;
 
310
        return;
 
311
    }
 
312
    x = 0;
 
313
    y = 0;
 
314
    overall_left = x - gi->x;
 
315
    overall_top = y - gi->y;
 
316
    overall_right = overall_left + (int) gi->width;
 
317
    overall_bottom = overall_top + (int) gi->height;
 
318
    x += gi->xOff;
 
319
    y += gi->yOff;
 
320
    while (len--)
 
321
    {
 
322
        c = *string++;
 
323
        gi = c < font->nrealized ? font->realized[c] : 0;
 
324
        if (!gi)
 
325
            continue;
 
326
        left = x - gi->x;
 
327
        top = y - gi->y;
 
328
        right = left + (int) gi->width;
 
329
        bottom = top + (int) gi->height;
 
330
        if (left < overall_left)
 
331
            overall_left = left;
 
332
        if (top < overall_top)
 
333
            overall_top = top;
 
334
        if (right > overall_right)
 
335
            overall_right = right;
 
336
        if (bottom > overall_bottom)
 
337
            overall_bottom = bottom;
 
338
        x += gi->xOff;
 
339
        y += gi->yOff;
 
340
    }
 
341
    extents->x = -overall_left;
 
342
    extents->y = -overall_top;
 
343
    extents->width = overall_right - overall_left;
 
344
    extents->height = overall_bottom - overall_top;
 
345
    extents->xOff = x;
 
346
    extents->yOff = y;
 
347
}
 
348
 
 
349
void
 
350
XftRenderExtents32 (Display         *dpy,
 
351
                    XftFontStruct   *font,
 
352
                    XftChar32       *string,
 
353
                    int             len,
 
354
                    XGlyphInfo      *extents)
 
355
{
 
356
    XftChar32       missing[XFT_NMISSING];
 
357
    int             nmissing;
 
358
    XftChar32       *s, c;
 
359
    int             l;
 
360
    XGlyphInfo      *gi;
 
361
    int             x, y;
 
362
    int             left, right, top, bottom;
 
363
    int             overall_left, overall_right;
 
364
    int             overall_top, overall_bottom;
 
365
 
 
366
    s = string;
 
367
    l = len;
 
368
    nmissing = 0;
 
369
    while (l--)
 
370
        XftGlyphCheck (dpy, font, (XftChar32) *s++, missing, &nmissing);
 
371
    if (nmissing)
 
372
        XftGlyphLoad (dpy, font, missing, nmissing);
 
373
    
 
374
    gi = 0;
 
375
    while (len)
 
376
    {
 
377
        c = *string++;
 
378
        len--;
 
379
        gi = c < font->nrealized ? font->realized[c] : 0;
 
380
        if (gi)
 
381
            break;
 
382
    }
 
383
    if (len == 0 && !gi)
 
384
    {
 
385
        extents->width = 0;
 
386
        extents->height = 0;
 
387
        extents->x = 0;
 
388
        extents->y = 0;
 
389
        extents->yOff = 0;
 
390
        extents->xOff = 0;
 
391
        return;
 
392
    }
 
393
    x = 0;
 
394
    y = 0;
 
395
    overall_left = x - gi->x;
 
396
    overall_top = y - gi->y;
 
397
    overall_right = overall_left + (int) gi->width;
 
398
    overall_bottom = overall_top + (int) gi->height;
 
399
    x += gi->xOff;
 
400
    y += gi->yOff;
 
401
    while (len--)
 
402
    {
 
403
        c = *string++;
 
404
        gi = c < font->nrealized ? font->realized[c] : 0;
 
405
        if (!gi)
 
406
            continue;
 
407
        left = x - gi->x;
 
408
        top = y - gi->y;
 
409
        right = left + (int) gi->width;
 
410
        bottom = top + (int) gi->height;
 
411
        if (left < overall_left)
 
412
            overall_left = left;
 
413
        if (top < overall_top)
 
414
            overall_top = top;
 
415
        if (right > overall_right)
 
416
            overall_right = right;
 
417
        if (bottom > overall_bottom)
 
418
            overall_bottom = bottom;
 
419
        x += gi->xOff;
 
420
        y += gi->yOff;
 
421
    }
 
422
    extents->x = -overall_left;
 
423
    extents->y = -overall_top;
 
424
    extents->width = overall_right - overall_left;
 
425
    extents->height = overall_bottom - overall_top;
 
426
    extents->xOff = x;
 
427
    extents->yOff = y;
 
428
}
 
429
 
 
430
void
 
431
XftRenderExtentsUtf8 (Display       *dpy,
 
432
                      XftFontStruct *font,
 
433
                      XftChar8      *string, 
 
434
                      int           len,
 
435
                      XGlyphInfo    *extents)
 
436
{
 
437
    XftChar32       missing[XFT_NMISSING];
 
438
    int             nmissing;
 
439
    XftChar8        *s;
 
440
    XftChar32       c;
 
441
    int             l, clen;
 
442
    XGlyphInfo      *gi;
 
443
    int             x, y;
 
444
    int             left, right, top, bottom;
 
445
    int             overall_left, overall_right;
 
446
    int             overall_top, overall_bottom;
 
447
 
 
448
    s = string;
 
449
    l = len;
 
450
    nmissing = 0;
 
451
    while (l)
 
452
    {
 
453
        clen = XftUtf8ToUcs4 (s, &c, l);
 
454
        if (clen < 0)
 
455
            break;
 
456
        XftGlyphCheck (dpy, font, (XftChar32) c, missing, &nmissing);
 
457
        s += clen;
 
458
        l -= clen;
 
459
    }
 
460
    if (nmissing)
 
461
        XftGlyphLoad (dpy, font, missing, nmissing);
 
462
    
 
463
    gi = 0;
 
464
    while (len)
 
465
    {
 
466
        clen = XftUtf8ToUcs4 (string, &c, len);
 
467
        if (clen < 0)
 
468
        {
 
469
            len = 0;
 
470
            break;
 
471
        }
 
472
        len -= clen;
 
473
        string += clen;
 
474
        gi = c < font->nrealized ? font->realized[c] : 0;
 
475
        if (gi)
 
476
            break;
 
477
    }
 
478
    if (len == 0 && !gi)
 
479
    {
 
480
        extents->width = 0;
 
481
        extents->height = 0;
 
482
        extents->x = 0;
 
483
        extents->y = 0;
 
484
        extents->yOff = 0;
 
485
        extents->xOff = 0;
 
486
        return;
 
487
    }
 
488
    x = 0;
 
489
    y = 0;
 
490
    overall_left = x - gi->x;
 
491
    overall_top = y - gi->y;
 
492
    overall_right = overall_left + (int) gi->width;
 
493
    overall_bottom = overall_top + (int) gi->height;
 
494
    x += gi->xOff;
 
495
    y += gi->yOff;
 
496
    while (len)
 
497
    {
 
498
        clen = XftUtf8ToUcs4 (string, &c, len);
 
499
        if (clen < 0)
 
500
            break;
 
501
        len -= clen;
 
502
        string += clen;
 
503
        gi = c < font->nrealized ? font->realized[c] : 0;
 
504
        if (!gi)
 
505
            continue;
 
506
        left = x - gi->x;
 
507
        top = y - gi->y;
 
508
        right = left + (int) gi->width;
 
509
        bottom = top + (int) gi->height;
 
510
        if (left < overall_left)
 
511
            overall_left = left;
 
512
        if (top < overall_top)
 
513
            overall_top = top;
 
514
        if (right > overall_right)
 
515
            overall_right = right;
 
516
        if (bottom > overall_bottom)
 
517
            overall_bottom = bottom;
 
518
        x += gi->xOff;
 
519
        y += gi->yOff;
 
520
    }
 
521
    extents->x = -overall_left;
 
522
    extents->y = -overall_top;
 
523
    extents->width = overall_right - overall_left;
 
524
    extents->height = overall_bottom - overall_top;
 
525
    extents->xOff = x;
 
526
    extents->yOff = y;
 
527
}