FSQGlyphs.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 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 = 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(offs); 102 return FSBadAlloc; 103 } 104#endif 105 left = (reply.length << 2) - SIZEOF(fsQueryXBitmaps8Reply) 106 - (SIZEOF(fsOffset32) * reply.num_chars); 107 gd = FSmalloc(left); 108 *glyphdata = gd; 109 if (!gd) { 110 FSfree(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 fsChar2b_version1 *swapped_str; 154 155 if (str_len > SIZE_MAX/SIZEOF(fsChar2b_version1)) 156 return FSBadAlloc; 157 swapped_str = FSmalloc(SIZEOF(fsChar2b_version1) * str_len); 158 if (!swapped_str) 159 return FSBadAlloc; 160 for (i = 0; i < str_len; i++) { 161 swapped_str[i].low = str[i].low; 162 swapped_str[i].high = str[i].high; 163 } 164 _FSSend(svr, (char *)swapped_str, (str_len*SIZEOF(fsChar2b_version1))); 165 FSfree(swapped_str); 166 } else 167 _FSSend(svr, (char *) str, (str_len * SIZEOF(fsChar2b))); 168 169 /* get back the info */ 170 if (!_FSReply(svr, (fsReply *) & reply, 171 (SIZEOF(fsQueryXBitmaps16Reply) - SIZEOF(fsGenericReply)) >> 2, 172 fsFalse)) 173 return FSBadAlloc; 174 175#if SIZE_MAX <= UINT_MAX 176 if(reply.num_chars > SIZE_MAX/sizeof(FSOffset)) 177 return FSBadAlloc; 178#endif 179 offs = FSmalloc(sizeof(FSOffset) * reply.num_chars); 180 *offsets = offs; 181 if (!offs) 182 return FSBadAlloc; 183#if (SIZE_MAX >> 2) <= UINT_MAX 184 /* XXX - this test is incomplete */ 185 if (reply.length > (SIZE_MAX>>2)) { 186 FSfree(offs); 187 return FSBadAlloc; 188 } 189#endif 190 left = (reply.length << 2) - SIZEOF(fsQueryXBitmaps16Reply) 191 - (SIZEOF(fsOffset32) * reply.num_chars); 192 gd = FSmalloc(left); 193 *glyphdata = gd; 194 if (!gd) { 195 FSfree(offs); 196 return FSBadAlloc; 197 } 198 for (i=0; i<reply.num_chars; i++) 199 { 200 _FSReadPad(svr, (char *) &local_offs, (SIZEOF(fsOffset32))); 201 offs->position = local_offs.position; 202 offs->length = local_offs.length; 203 offs++; 204 } 205 _FSReadPad(svr, (char *) gd, left); 206 207 SyncHandle(); 208 return FSSuccess; 209} 210