FSQGlyphs.c revision 2d8abe4f
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 57int 58FSQueryXBitmaps8( 59 FSServer *svr, 60 Font fid, 61 FSBitmapFormat format, 62 Bool range_type, 63 unsigned char *str, 64 unsigned long str_len, 65 FSOffset **offsets, 66 unsigned char **glyphdata) 67{ 68 fsQueryXBitmaps8Req *req; 69 fsQueryXBitmaps8Reply reply; 70 FSOffset *offs; 71 fsOffset32 local_offs; 72 unsigned char *gd; 73 int left; 74 int i; 75 76 GetReq(QueryXBitmaps8, req); 77 req->fid = fid; 78 req->range = range_type; 79 req->format = format; 80 req->num_ranges = str_len; 81 req->length += (str_len + 3) >> 2; 82 _FSSend(svr, (char *) str, str_len); 83 84 /* get back the info */ 85 if (!_FSReply(svr, (fsReply *) & reply, 86 (SIZEOF(fsQueryXBitmaps8Reply) - SIZEOF(fsGenericReply)) >> 2, fsFalse)) 87 return FSBadAlloc; 88 89#if SIZE_MAX <= UINT_MAX 90 if (reply.num_chars > SIZE_MAX / sizeof(FSOffset)) 91 return FSBadAlloc; 92#endif 93 94 offs = (FSOffset *) FSmalloc(sizeof(FSOffset) * reply.num_chars); 95 *offsets = offs; 96 if (!offs) 97 return FSBadAlloc; 98#if (SIZE_MAX >> 2) <= UINT_MAX 99 /* XXX This thest is incomplete */ 100 if (reply.length > (SIZE_MAX >> 2)) { 101 FSfree((char *) offs); 102 return FSBadAlloc; 103 } 104#endif 105 left = (reply.length << 2) - SIZEOF(fsQueryXBitmaps8Reply) 106 - (SIZEOF(fsOffset32) * reply.num_chars); 107 gd = (unsigned char *) FSmalloc(left); 108 *glyphdata = gd; 109 if (!gd) { 110 FSfree((char *) offs); 111 return FSBadAlloc; 112 } 113 for (i=0; i<reply.num_chars; i++) 114 { 115 _FSReadPad(svr, (char *) &local_offs, (SIZEOF(fsOffset32))); 116 offs->position = local_offs.position; 117 offs->length = local_offs.length; 118 offs++; 119 } 120 _FSReadPad(svr, (char *) gd, left); 121 122 SyncHandle(); 123 return FSSuccess; 124} 125 126int 127FSQueryXBitmaps16( 128 FSServer *svr, 129 Font fid, 130 FSBitmapFormat format, 131 Bool range_type, 132 FSChar2b *str, 133 unsigned long str_len, 134 FSOffset **offsets, 135 unsigned char **glyphdata) 136{ 137 fsQueryXBitmaps16Req *req; 138 fsQueryXBitmaps16Reply reply; 139 FSOffset *offs; 140 fsOffset32 local_offs; 141 unsigned char *gd; 142 int left; 143 int i; 144 145 GetReq(QueryXBitmaps16, req); 146 req->fid = fid; 147 req->range = range_type; 148 req->format = format; 149 req->num_ranges = str_len; 150 req->length += ((str_len * SIZEOF(fsChar2b)) + 3) >> 2; 151 if (FSProtocolVersion(svr) == 1) 152 { 153 int i; 154 fsChar2b_version1 *swapped_str; 155 156 if (str_len > SIZE_MAX/SIZEOF(fsChar2b_version1)) 157 return FSBadAlloc; 158 swapped_str = (fsChar2b_version1 *) 159 FSmalloc(SIZEOF(fsChar2b_version1) * str_len); 160 if (!swapped_str) 161 return FSBadAlloc; 162 for (i = 0; i < str_len; i++) { 163 swapped_str[i].low = str[i].low; 164 swapped_str[i].high = str[i].high; 165 } 166 _FSSend(svr, (char *)swapped_str, (str_len*SIZEOF(fsChar2b_version1))); 167 FSfree(swapped_str); 168 } else 169 _FSSend(svr, (char *) str, (str_len * SIZEOF(fsChar2b))); 170 171 /* get back the info */ 172 if (!_FSReply(svr, (fsReply *) & reply, 173 (SIZEOF(fsQueryXBitmaps16Reply) - SIZEOF(fsGenericReply)) >> 2, 174 fsFalse)) 175 return FSBadAlloc; 176 177#if SIZE_MAX <= UINT_MAX 178 if(reply.num_chars > SIZE_MAX/sizeof(FSOffset)) 179 return FSBadAlloc; 180#endif 181 offs = (FSOffset *) FSmalloc(sizeof(FSOffset) * reply.num_chars); 182 *offsets = offs; 183 if (!offs) 184 return FSBadAlloc; 185#if (SIZE_MAX >> 2) <= UINT_MAX 186 /* XXX - this test is incomplete */ 187 if (reply.length > (SIZE_MAX>>2)) { 188 FSfree((char *) offs); 189 return FSBadAlloc; 190 } 191#endif 192 left = (reply.length << 2) - SIZEOF(fsQueryXBitmaps16Reply) 193 - (SIZEOF(fsOffset32) * reply.num_chars); 194 gd = (unsigned char *) FSmalloc(left); 195 *glyphdata = gd; 196 if (!gd) { 197 FSfree((char *) offs); 198 return FSBadAlloc; 199 } 200 for (i=0; i<reply.num_chars; i++) 201 { 202 _FSReadPad(svr, (char *) &local_offs, (SIZEOF(fsOffset32))); 203 offs->position = local_offs.position; 204 offs->length = local_offs.length; 205 offs++; 206 } 207 _FSReadPad(svr, (char *) gd, left); 208 209 SyncHandle(); 210 return FSSuccess; 211} 212