#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "FSlibint.h"
static void
_FS_convert_char_info(fsXCharInfo *src, FSXCharInfo *dst)
{
dst->ascent = src->ascent;
dst->descent = src->descent;
dst->left = src->left;
dst->right = src->right;
dst->width = src->width;
dst->attributes = src->attributes;
}
int
FSQueryXExtents8(
FSServer *svr,
Font fid,
Bool range_type,
unsigned char *str,
unsigned long str_len,
FSXCharInfo **extents)
{
fsQueryXExtents8Req *req;
fsQueryXExtents8Reply reply;
FSXCharInfo *ext;
fsXCharInfo local_exts;
int i;
GetReq(QueryXExtents8, req);
req->fid = fid;
req->range = range_type;
req->num_ranges = str_len;
req->length += (str_len + 3) >> 2;
_FSSend(svr, (char *) str, str_len);
if (!_FSReply(svr, (fsReply *) & reply,
(SIZEOF(fsQueryXExtents8Reply) - SIZEOF(fsGenericReply)) >> 2,
fsFalse))
return FSBadAlloc;
#if SIZE_MAX <= UINT_MAX
if (reply.num_extents > SIZE_MAX / sizeof(FSXCharInfo))
return FSBadAlloc;
#endif
ext = (FSXCharInfo *) FSmalloc(sizeof(FSXCharInfo) * reply.num_extents);
*extents = ext;
if (!ext)
return FSBadAlloc;
for (i = 0; i < reply.num_extents; i++) {
_FSReadPad(svr, (char *) &local_exts, SIZEOF(fsXCharInfo));
_FS_convert_char_info(&local_exts, &ext[i]);
}
SyncHandle();
return FSSuccess;
}
int
FSQueryXExtents16(
FSServer *svr,
Font fid,
Bool range_type,
FSChar2b *str,
unsigned long str_len,
FSXCharInfo **extents)
{
fsQueryXExtents16Req *req;
fsQueryXExtents16Reply reply;
FSXCharInfo *ext;
fsXCharInfo local_exts;
int i;
GetReq(QueryXExtents16, req);
req->fid = fid;
req->range = range_type;
req->num_ranges = str_len;
req->length += ((str_len * SIZEOF(fsChar2b)) + 3) >> 2;
if (FSProtocolVersion(svr) == 1)
{
fsChar2b_version1 *swapped_str;
swapped_str = (fsChar2b_version1 *)
FSmalloc(SIZEOF(fsChar2b_version1) * str_len);
if (!swapped_str)
return FSBadAlloc;
for (i = 0; i < str_len; i++) {
swapped_str[i].low = str[i].low;
swapped_str[i].high = str[i].high;
}
_FSSend(svr, (char *)swapped_str, (str_len*SIZEOF(fsChar2b_version1)));
FSfree(swapped_str);
} else
_FSSend(svr, (char *) str, (str_len * SIZEOF(fsChar2b)));
if (!_FSReply(svr, (fsReply *) & reply,
(SIZEOF(fsQueryXExtents16Reply) - SIZEOF(fsGenericReply)) >> 2,
fsFalse))
return FSBadAlloc;
#if SIZE_MAX <= UINT_MAX
if (reply.num_extents > SIZE_MAX/sizeof(FSXCharInfo))
return FSBadAlloc;
#endif
ext = (FSXCharInfo *) FSmalloc(sizeof(FSXCharInfo) * reply.num_extents);
*extents = ext;
if (!ext)
return FSBadAlloc;
for (i = 0; i < reply.num_extents; i++) {
_FSReadPad(svr, (char *) &local_exts, SIZEOF(fsXCharInfo));
_FS_convert_char_info(&local_exts, &ext[i]);
}
SyncHandle();
return FSSuccess;
}