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