FSQGlyphs.c revision ba6a1819
1/* $Xorg: FSQGlyphs.c,v 1.4 2001/02/09 02:03:25 xorgcvs Exp $ */
2/*
3 * Copyright 1990 Network Computing Devices;
4 * Portions Copyright 1987 by Digital Equipment Corporation
5 *
6 * Permission to use, copy, modify, distribute, and sell this software
7 * and its documentation for any purpose is hereby granted without fee,
8 * provided that the above copyright notice appear in all copies and
9 * that both that copyright notice and this permission notice appear
10 * in supporting documentation, and that the names of Network Computing
11 * Devices or Digital not be used in advertising or publicity pertaining
12 * to distribution of the software without specific, written prior
13 * permission. Network Computing Devices or Digital make no representations
14 * about the suitability of this software for any purpose.  It is provided
15 * "as is" without express or implied warranty.
16 *
17 * NETWORK COMPUTING DEVICES AND  DIGITAL DISCLAIM ALL WARRANTIES WITH
18 * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL NETWORK COMPUTING DEVICES
20 * OR DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES
21 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
22 * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
23 * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
24 * SOFTWARE.
25 */
26/* $XFree86: xc/lib/FS/FSQGlyphs.c,v 1.5tsi Exp $ */
27
28/*
29
30Copyright 1987, 1998  The Open Group
31
32Permission to use, copy, modify, distribute, and sell this software and its
33documentation for any purpose is hereby granted without fee, provided that
34the above copyright notice appear in all copies and that both that
35copyright notice and this permission notice appear in supporting
36documentation.
37
38The above copyright notice and this permission notice shall be included in
39all copies or substantial portions of the Software.
40
41THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
42IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
43FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
44OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
45AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
46CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
47
48Except as contained in this notice, the name of The Open Group shall not be
49used in advertising or otherwise to promote the sale, use or other dealings
50in this Software without prior written authorization from The Open Group.
51
52*/
53
54#ifdef HAVE_CONFIG_H
55#include <config.h>
56#endif
57#include "FSlibint.h"
58
59int
60FSQueryXBitmaps8(
61    FSServer		 *svr,
62    Font		  fid,
63    FSBitmapFormat	  format,
64    Bool		  range_type,
65    unsigned char	 *str,
66    unsigned long	  str_len,
67    FSOffset		**offsets,
68    unsigned char	**glyphdata)
69{
70    fsQueryXBitmaps8Req *req;
71    fsQueryXBitmaps8Reply reply;
72    FSOffset   *offs;
73    fsOffset32 local_offs;
74    unsigned char *gd;
75    int         left;
76    int		i;
77
78    GetReq(QueryXBitmaps8, req);
79    req->fid = fid;
80    req->range = range_type;
81    req->format = format;
82    req->num_ranges = str_len;
83    req->length += (str_len + 3) >> 2;
84    _FSSend(svr, (char *) str, str_len);
85
86    /* get back the info */
87    if (!_FSReply(svr, (fsReply *) & reply,
88     (SIZEOF(fsQueryXBitmaps8Reply) - SIZEOF(fsGenericReply)) >> 2, fsFalse))
89	return FSBadAlloc;
90
91#if SIZE_MAX <= UINT_MAX
92    if (reply.num_chars > SIZE_MAX / sizeof(FSOffset))
93	return FSBadAlloc;
94#endif
95
96    offs = (FSOffset *) FSmalloc(sizeof(FSOffset) * reply.num_chars);
97    *offsets = offs;
98    if (!offs)
99	return FSBadAlloc;
100#if (SIZE_MAX >> 2) <= UINT_MAX
101    /* XXX This thest is incomplete */
102    if (reply.length > (SIZE_MAX >> 2)) {
103	FSfree((char *) offs);
104	return FSBadAlloc;
105    }
106#endif
107    left = (reply.length << 2) - SIZEOF(fsQueryXBitmaps8Reply)
108	- (SIZEOF(fsOffset32) * reply.num_chars);
109    gd = (unsigned char *) FSmalloc(left);
110    *glyphdata = gd;
111    if (!gd) {
112	FSfree((char *) offs);
113	return FSBadAlloc;
114    }
115    for (i=0; i<reply.num_chars; i++)
116    {
117	_FSReadPad(svr, (char *) &local_offs, (SIZEOF(fsOffset32)));
118	offs->position = local_offs.position;
119	offs->length = local_offs.length;
120	offs++;
121    }
122    _FSReadPad(svr, (char *) gd, left);
123
124    SyncHandle();
125    return FSSuccess;
126}
127
128int
129FSQueryXBitmaps16(
130    FSServer		 *svr,
131    Font		  fid,
132    FSBitmapFormat	  format,
133    Bool		  range_type,
134    FSChar2b		 *str,
135    unsigned long	  str_len,
136    FSOffset		**offsets,
137    unsigned char	**glyphdata)
138{
139    fsQueryXBitmaps16Req *req;
140    fsQueryXBitmaps16Reply reply;
141    FSOffset   *offs;
142    fsOffset32 local_offs;
143    unsigned char *gd;
144    int         left;
145    int		i;
146
147    GetReq(QueryXBitmaps16, req);
148    req->fid = fid;
149    req->range = range_type;
150    req->format = format;
151    req->num_ranges = str_len;
152    req->length += ((str_len * SIZEOF(fsChar2b)) + 3) >> 2;
153    if (FSProtocolVersion(svr) == 1)
154    {
155	int i;
156	fsChar2b_version1 *swapped_str;
157
158	if (str_len > SIZE_MAX/SIZEOF(fsChar2b_version1))
159	    return FSBadAlloc;
160	swapped_str = (fsChar2b_version1 *)
161	    FSmalloc(SIZEOF(fsChar2b_version1) * str_len);
162	if (!swapped_str)
163	    return FSBadAlloc;
164	for (i = 0; i < str_len; i++) {
165	    swapped_str[i].low = str[i].low;
166	    swapped_str[i].high = str[i].high;
167	}
168	_FSSend(svr, (char *)swapped_str, (str_len*SIZEOF(fsChar2b_version1)));
169	FSfree(swapped_str);
170    } else
171	_FSSend(svr, (char *) str, (str_len * SIZEOF(fsChar2b)));
172
173    /* get back the info */
174    if (!_FSReply(svr, (fsReply *) & reply,
175	      (SIZEOF(fsQueryXBitmaps16Reply) - SIZEOF(fsGenericReply)) >> 2,
176		  fsFalse))
177	return FSBadAlloc;
178
179#if SIZE_MAX <= UINT_MAX
180    if(reply.num_chars > SIZE_MAX/sizeof(FSOffset))
181       return FSBadAlloc;
182#endif
183    offs = (FSOffset *) FSmalloc(sizeof(FSOffset) * reply.num_chars);
184    *offsets = offs;
185    if (!offs)
186	return FSBadAlloc;
187#if (SIZE_MAX >> 2) <= UINT_MAX
188    /* XXX - this test is incomplete */
189    if (reply.length > (SIZE_MAX>>2)) {
190	FSfree((char *) offs);
191	return FSBadAlloc;
192    }
193#endif
194    left = (reply.length << 2) - SIZEOF(fsQueryXBitmaps16Reply)
195	- (SIZEOF(fsOffset32) * reply.num_chars);
196    gd = (unsigned char *) FSmalloc(left);
197    *glyphdata = gd;
198    if (!gd) {
199	FSfree((char *) offs);
200	return FSBadAlloc;
201    }
202    for (i=0; i<reply.num_chars; i++)
203    {
204	_FSReadPad(svr, (char *) &local_offs, (SIZEOF(fsOffset32)));
205	offs->position = local_offs.position;
206	offs->length = local_offs.length;
207	offs++;
208    }
209    _FSReadPad(svr, (char *) gd, left);
210
211    SyncHandle();
212    return FSSuccess;
213}
214