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