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

« back to all changes in this revision

Viewing changes to unix/xc/extras/X-TrueType/xttprop.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
/* ===EmacsMode: -*- Mode: C; tab-width:4; c-basic-offset: 4; -*- === */
 
2
/* ===FileName: ===
 
3
   Copyright (c) 1998 Go Watanabe, All rights reserved.
 
4
   Copyright (c) 1998 Takuya SHIOZAKI, All rights reserved.
 
5
   Copyright (c) 1998 X-TrueType Server Project, All rights reserved.
 
6
 
 
7
===Notice
 
8
   Redistribution and use in source and binary forms, with or without
 
9
   modification, are permitted provided that the following conditions
 
10
   are met:
 
11
   1. Redistributions of source code must retain the above copyright
 
12
      notice, this list of conditions and the following disclaimer.
 
13
   2. Redistributions in binary form must reproduce the above copyright
 
14
      notice, this list of conditions and the following disclaimer in the
 
15
      documentation and/or other materials provided with the distribution.
 
16
 
 
17
   THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 
18
   ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 
19
   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 
20
   ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 
21
   FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 
22
   DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 
23
   OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 
24
   HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 
25
   LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 
26
   OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 
27
   SUCH DAMAGE.
 
28
 
 
29
   Major Release ID: X-TrueType Server Version 1.3 [Aoi MATSUBARA Release 3]
 
30
 
 
31
Notice===
 
32
*/
 
33
 
 
34
#include "xttversion.h"
 
35
 
 
36
static char const * const releaseID =
 
37
    _XTT_RELEASE_NAME;
 
38
 
 
39
/* THIS FILE IS BASED ON Speedo Font lib spinfo.c */
 
40
 
 
41
/*------------------------- original copyright ------------------------*/
 
42
/*
 
43
 * Copyright 1990, 1991 Network Computing Devices;
 
44
 * Portions Copyright 1987 by Digital Equipment Corporation
 
45
 *
 
46
 * Permission to use, copy, modify, distribute, and sell this software and
 
47
 * its documentation for any purpose is hereby granted without fee, provided
 
48
 * that the above copyright notice appear in all copies and that both that
 
49
 * copyright notice and this permission notice appear in supporting
 
50
 * documentation, and that the names of Network Computing Devices or Digital
 
51
 * not be used in advertising or publicity pertaining to distribution of
 
52
 * the software without specific, written prior permission.
 
53
 *
 
54
 * NETWORK COMPUTING DEVICES AND DIGITAL DISCLAIM ALL WARRANTIES WITH
 
55
 * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
 
56
 * AND FITNESS, IN NO EVENT SHALL NETWORK COMPUTING DEVICES OR DIGITAL BE
 
57
 * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 
58
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
 
59
 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
 
60
 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
61
 *
 
62
 * Author: Dave Lemke, Network Computing Devices, Inc
 
63
 */
 
64
 
 
65
/*
 
66
Copyright (c) 1987  X Consortium
 
67
 
 
68
Permission is hereby granted, free of charge, to any person obtaining
 
69
a copy of this software and associated documentation files (the
 
70
"Software"), to deal in the Software without restriction, including
 
71
without limitation the rights to use, copy, modify, merge, publish,
 
72
distribute, sublicense, and/or sell copies of the Software, and to
 
73
permit persons to whom the Software is furnished to do so, subject to
 
74
the following conditions:
 
75
 
 
76
The above copyright notice and this permission notice shall be included
 
77
in all copies or substantial portions of the Software.
 
78
 
 
79
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 
80
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 
81
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 
82
IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
 
83
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 
84
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 
85
OTHER DEALINGS IN THE SOFTWARE.
 
86
 
 
87
Except as contained in this notice, the name of the X Consortium shall
 
88
not be used in advertising or otherwise to promote the sale, use or
 
89
other dealings in this Software without prior written authorization
 
90
from the X Consortium.
 
91
 
 
92
*/
 
93
 
 
94
#ifndef FONTMODULE
 
95
#include <X11/Xos.h>
 
96
#endif
 
97
#include <X11/X.h>
 
98
#include "fntfilst.h"
 
99
#include "xttcommon.h"
 
100
 
 
101
/* percentage of pointsize used to specify ascent & descent */
 
102
#define STRETCH_FACTOR  120
 
103
 
 
104
enum scaleType {
 
105
    atom, truncate_atom, pixel_size, point_size, resolution_x,
 
106
    resolution_y, average_width
 
107
};
 
108
 
 
109
typedef struct _fontProp {
 
110
    char       *name;
 
111
    long        atom;
 
112
    enum scaleType type;
 
113
} fontProp;
 
114
 
 
115
static fontProp fontNamePropTable[] = {
 
116
    { "FOUNDRY", 0, atom },
 
117
    { "FAMILY_NAME", 0, atom },
 
118
    { "WEIGHT_NAME", 0, atom },
 
119
    { "SLANT", 0, atom },
 
120
    { "SETWIDTH_NAME", 0, atom },
 
121
    { "ADD_STYLE_NAME", 0, atom },
 
122
    { "PIXEL_SIZE", 0, pixel_size },
 
123
    { "POINT_SIZE", 0, point_size },
 
124
    { "RESOLUTION_X", 0, resolution_x },
 
125
    { "RESOLUTION_Y", 0, resolution_y },
 
126
    { "SPACING", 0, atom },
 
127
    { "AVERAGE_WIDTH", 0, average_width },
 
128
    { "CHARSET_REGISTRY", 0, atom },
 
129
    { "CHARSET_ENCODING", 0, truncate_atom },
 
130
};
 
131
 
 
132
/* Warning: following array is closely related to the sequence of
 
133
   defines after it. */
 
134
 
 
135
static fontProp extraProps[] = {
 
136
    { "FONT", 0, 0 },
 
137
    { "COPYRIGHT", 0, 0 },
 
138
    { "RAW_PIXEL_SIZE", 0, 0 },
 
139
    { "RAW_POINT_SIZE", 0, 0 },
 
140
    { "RAW_ASCENT", 0, 0 },
 
141
    { "RAW_DESCENT", 0, 0 },
 
142
    { "RAW_AVERAGE_WIDTH", 0, 0 },
 
143
};
 
144
 
 
145
/* this is a bit kludgy */
 
146
#define FONTPROP    0
 
147
#define COPYRIGHTPROP   1
 
148
#define RAWPIXELPROP    2
 
149
#define RAWPOINTPROP    3
 
150
#define RAWASCENTPROP   4
 
151
#define RAWDESCENTPROP  5
 
152
#define RAWWIDTHPROP    6
 
153
 
 
154
#define NNAMEPROPS (sizeof(fontNamePropTable) / sizeof(fontProp))
 
155
#define NEXTRAPROPS (sizeof(extraProps) / sizeof(fontProp))
 
156
 
 
157
#define NPROPS  (NNAMEPROPS + NEXTRAPROPS)
 
158
 
 
159
extern Atom MakeAtom(char *string, unsigned len, Bool makeit);
 
160
 
 
161
void
 
162
freetype_make_standard_props(void)
 
163
{
 
164
    int         i;
 
165
    fontProp   *t;
 
166
    i = sizeof(fontNamePropTable) / sizeof(fontProp);
 
167
    for (t = fontNamePropTable; i; i--, t++)
 
168
        t->atom = MakeAtom(t->name, (unsigned) strlen(t->name), True);
 
169
    i = sizeof(extraProps) / sizeof(fontProp);
 
170
    for (t = extraProps; i; i--, t++)
 
171
        t->atom = MakeAtom(t->name, (unsigned) strlen(t->name), True);
 
172
}
 
173
 
 
174
void
 
175
freetype_compute_props(FontInfoPtr pinfo,
 
176
                       FontScalablePtr vals,
 
177
                       int raw_width,
 
178
                       int raw_ascent,
 
179
                       int raw_descent,
 
180
                       char *fontname,
 
181
                       char *copyright)
 
182
{
 
183
    FontPropPtr pp;
 
184
    int         i, nprops;
 
185
    fontProp    *fpt;
 
186
    char        *is_str;
 
187
    char        *ptr1 = NULL, *ptr2, *ptr3;
 
188
    /*    FontScalableRec tmpvals;*/
 
189
 
 
190
    nprops = pinfo->nprops = NPROPS;
 
191
    pinfo->isStringProp = (char *) xalloc(sizeof(char) * nprops);
 
192
    pinfo->props = (FontPropPtr) xalloc(sizeof(FontPropRec) * nprops);
 
193
    if (!pinfo->isStringProp || !pinfo->props) {
 
194
        xfree(pinfo->isStringProp);
 
195
        pinfo->isStringProp = (char *) 0;
 
196
        xfree(pinfo->props);
 
197
        pinfo->props = (FontPropPtr) 0;
 
198
        return;
 
199
    }
 
200
    memset(pinfo->isStringProp, 0, (sizeof(char) * nprops));
 
201
 
 
202
    ptr2 = fontname;
 
203
    for (i = NNAMEPROPS, pp = pinfo->props, fpt = fontNamePropTable,
 
204
             is_str = pinfo->isStringProp;   i;
 
205
         i--, pp++, fpt++, is_str++) {
 
206
 
 
207
        if (*ptr2) {
 
208
            ptr1 = ptr2 + 1;
 
209
            if (!(ptr2 = strchr(ptr1, '-'))) ptr2 = strchr(ptr1, '\0');
 
210
        }
 
211
 
 
212
        pp->name = fpt->atom;
 
213
        switch (fpt->type) {
 
214
        case atom:
 
215
            *is_str = True;
 
216
            pp->value = MakeAtom(ptr1, ptr2 - ptr1, True);
 
217
            break;
 
218
        case truncate_atom:
 
219
            *is_str = True;
 
220
            for (ptr3 = ptr1; *ptr3; ptr3++)
 
221
                if (*ptr3 == '[')
 
222
                    break;
 
223
            pp->value = MakeAtom(ptr1, ptr3 - ptr1, True);
 
224
            break;
 
225
        case pixel_size:
 
226
            pp->value = (int)(vals->pixel_matrix[3] +
 
227
                              (vals->pixel_matrix[3] > 0 ? .5 : -.5));
 
228
            break;
 
229
        case point_size:
 
230
            pp->value = (int)(vals->point_matrix[3] * 10.0 +
 
231
                              (vals->point_matrix[3] > 0 ? .5 : -.5));
 
232
            break;
 
233
        case resolution_x:
 
234
            pp->value = vals->x;
 
235
            break;
 
236
        case resolution_y:
 
237
            pp->value = vals->y;
 
238
            break;
 
239
        case average_width:
 
240
            pp->value = vals->width;
 
241
            break;
 
242
        }
 
243
    }
 
244
 
 
245
    for (i=0, fpt = extraProps; i < NEXTRAPROPS; i++, is_str++, pp++, fpt++){
 
246
        pp->name = fpt->atom;
 
247
        switch (i) {
 
248
        case FONTPROP:
 
249
            *is_str = True;
 
250
            pp->value = MakeAtom(fontname, strlen(fontname), True);
 
251
            break;
 
252
        case COPYRIGHTPROP:
 
253
            *is_str = True;
 
254
            pp->value = MakeAtom(copyright,
 
255
                                 strlen(copyright), True);
 
256
            break;
 
257
        case RAWPIXELPROP:
 
258
            *is_str = False;
 
259
            pp->value = 1000;
 
260
            break;
 
261
        case RAWPOINTPROP:
 
262
            *is_str = False;
 
263
            pp->value = (long)(72270.0 / (double)vals->y + .5);
 
264
            break;
 
265
        case RAWASCENTPROP:
 
266
            *is_str = False;
 
267
            pp->value = raw_ascent;
 
268
            break;
 
269
        case RAWDESCENTPROP:
 
270
            *is_str = False;
 
271
            pp->value = raw_descent;
 
272
            break;
 
273
        case RAWWIDTHPROP:
 
274
            *is_str = False;
 
275
            pp->value = raw_width;
 
276
            break;
 
277
        }
 
278
    }
 
279
}
 
280
 
 
281
/* end of file */