1
/* $Xorg: fontinfo.c,v 1.4 2001/02/09 02:05:42 xorgcvs Exp $ */
7
Copyright 1990, 1991, 1998 The Open Group
9
Permission to use, copy, modify, distribute, and sell this software and its
10
documentation for any purpose is hereby granted without fee, provided that
11
the above copyright notice appear in all copies and that both that
12
copyright notice and this permission notice appear in supporting
15
The above copyright notice and this permission notice shall be included in
16
all copies or substantial portions of the Software.
18
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
Except as contained in this notice, the name of The Open Group shall not be
26
used in advertising or otherwise to promote the sale, use or other dealings
27
in this Software without prior written authorization from The Open Group.
29
* Copyright 1990, 1991 Network Computing Devices;
30
* Portions Copyright 1987 by Digital Equipment Corporation
32
* Permission to use, copy, modify, distribute, and sell this software and
33
* its documentation for any purpose is hereby granted without fee, provided
34
* that the above copyright notice appear in all copies and that both that
35
* copyright notice and this permission notice appear in supporting
36
* documentation, and that the names of Network Computing Devices, or Digital
37
* not be used in advertising or publicity pertaining to distribution
38
* of the software without specific, written prior permission.
40
* NETWORK COMPUTING DEVICES, AND DIGITAL DISCLAIM ALL WARRANTIES WITH
41
* REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
42
* MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL NETWORK COMPUTING DEVICES,
43
* OR DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
44
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
45
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
46
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
49
/* $XFree86: xc/programs/xfs/difs/fontinfo.c,v 1.11 2002/10/15 01:45:02 dawes Exp $ */
55
#include "clientstr.h"
57
#include "fontstruct.h"
70
xCharInfo *src = &ci->metrics;
72
dst->ascent = src->ascent;
73
dst->descent = src->descent;
74
dst->left = src->leftSideBearing;
75
dst->right = src->rightSideBearing;
76
dst->width = src->characterWidth;
77
dst->attributes = src->attributes;
87
int data_len, cur_off;
89
pointer ptr, off_ptr, string_base;
90
fsPropOffset local_offset;
93
* compute the size of the property data
96
for (i = 0; i < pinfo->nprops; i++)
98
data_len += strlen(NameForAtom(pinfo->props[i].name));
99
if (NULL != pinfo->isStringProp && pinfo->isStringProp[i])
100
data_len += strlen(NameForAtom(pinfo->props[i].value));
104
* allocate the single chunk that the difs layer requires
106
ptr = (pointer) fsalloc(SIZEOF(fsPropInfo)
107
+ SIZEOF(fsPropOffset) * pinfo->nprops
111
string_base = (char *)ptr + SIZEOF(fsPropInfo) + SIZEOF(fsPropOffset) * pinfo->nprops;
116
((fsPropInfo *)ptr)->num_offsets = pinfo->nprops;
117
((fsPropInfo *)ptr)->data_len = data_len;
120
* compute the offsets and copy the string data
122
off_ptr = (char *)ptr + SIZEOF(fsPropInfo);
124
for (i = 0; i < pinfo->nprops; i++)
126
local_offset.name.position = cur_off;
127
str = NameForAtom(pinfo->props[i].name);
128
local_offset.name.length = strlen(str);
129
memmove( (char *)string_base+cur_off, str, local_offset.name.length);
130
cur_off += local_offset.name.length;
131
if (NULL != pinfo->isStringProp && pinfo->isStringProp[i])
133
local_offset.value.position = cur_off;
134
str = NameForAtom(pinfo->props[i].value);
135
local_offset.value.length = strlen(str);
136
memmove( (char *)string_base+cur_off, str, local_offset.value.length);
137
cur_off += local_offset.value.length;
138
local_offset.type = PropTypeString;
140
local_offset.value.position = pinfo->props[i].value;
141
local_offset.value.length = 0; /* protocol says must be zero */
142
local_offset.type = PropTypeSigned;
144
memmove( off_ptr, &local_offset, SIZEOF(fsPropOffset));
145
off_ptr = (char *)off_ptr + SIZEOF(fsPropOffset);
148
assert(off_ptr == string_base);
149
assert(cur_off == data_len);
151
*props = (fsPropInfo *) ptr;
157
* does the real work of turning a list of range (or chars) into
169
fsRange *new = (fsRange *) 0,
171
unsigned long src_num;
174
if (type) { /* range flag is set, deal with data as a list
176
char *rp = (char *) src;
184
np = new = (fsRange *) fsalloc(sizeof(fsRange) * (src_num + 1) / 2);
187
/* Build a new range */
188
for (i = 1; i < src_num; i += 2)
190
np->min_char_high = (item_size == 1) ? 0 : *rp++;
191
np->min_char_low = *rp++;
192
np->max_char_high = (item_size == 1) ? 0 : *rp++;
193
np->max_char_low = *rp++;
197
/* If src_num is odd, we need to determine the final range
198
by examining the fontinfo */
201
np->min_char_high = (item_size == 1) ? 0 : *rp++;
202
np->min_char_low = *rp++;
203
np->max_char_high = pfi->lastRow;
204
np->max_char_low = pfi->lastCol;
209
} else { /* deal with data as a list of characters */
210
unsigned char *pp = src;
213
np = new = (fsRange *) fsalloc(SIZEOF(fsRange) * src_num);
217
/* Build a range, with coalescence, from the list of chars */
219
for (i = 0; i < src_num; i++) {
220
if (item_size == 1) {
221
np->min_char_low = *pp;
222
np->min_char_high = 0;
224
np->min_char_low = ((fsChar2b *) pp)->low;
225
np->min_char_high = ((fsChar2b *) pp)->high;
227
np->max_char_high = np->min_char_high;
228
np->max_char_low = np->min_char_low;
229
/* Can we coalesce? */
231
np->max_char_high == np[-1].max_char_high &&
232
np->max_char_low == np[-1].max_char_low + 1)
233
np[-1].max_char_low++; /* Yes */
244
* provide backward compatibility with version 1, which had
245
* the bytes of char2b backwards
248
swap_char2b (fsChar2b *values, int number)
253
for (i = 0; i < number; i++) {
254
temp.low = ((fsChar2b_version1 *)values)->low;
255
temp.high = ((fsChar2b_version1 *)values)->high;
260
#define pPtr ((QEclosurePtr) data)
263
do_query_extents(ClientPtr client, pointer data)
266
unsigned long lendata,
268
fsXCharInfo *extents;
269
fsQueryXExtents8Reply reply;
271
err = GetExtents (pPtr->client, pPtr->pfont,
272
pPtr->flags, pPtr->nranges, pPtr->range, &num_extents, &extents);
273
if (err == Suspended) {
275
pPtr->pfont->unload_glyphs = 0; /* Not a safe call for this font */
277
ClientSleep(client, do_query_extents, (pointer) pPtr);
281
if (err != Successful) {
282
SendErrToClient(pPtr->client, FontToFSError(err), (pointer) 0);
285
reply.type = FS_Reply;
286
reply.sequenceNumber = pPtr->client->sequence;
287
reply.num_extents = num_extents;
288
lendata = SIZEOF(fsXCharInfo) * num_extents;
289
reply.length = (SIZEOF(fsQueryXExtents8Reply) + lendata) >> 2;
291
SwapExtents(extents, num_extents);
292
WriteReplyToClient(pPtr->client, SIZEOF(fsQueryXExtents8Reply), &reply);
293
(void) WriteToClient(pPtr->client, lendata, (char *) extents);
294
fsfree((char *) extents);
297
ClientWakeup(pPtr->client);
298
if (pPtr->pfont->unload_glyphs) /* For rasterizers that want to save memory */
299
(*pPtr->pfont->unload_glyphs)(pPtr->pfont);
315
fsRange *fixed_range;
316
Bool all_glyphs = FALSE;
318
if (item_size == 2 && client->major_version == 1)
319
swap_char2b ((fsChar2b *)range_data, nranges);
321
fixed_range = build_range(range_flag, range_data, item_size,
322
&nranges, &all_glyphs, &cfp->font->info);
324
if (!fixed_range && !all_glyphs) {
325
SendErrToClient(client, FSBadRange, 0);
328
c = (QEclosurePtr) fsalloc(sizeof(QEclosureRec));
333
c->pfont = cfp->font;
334
c->flags = (all_glyphs) ? LoadAll : 0;
335
c->flags |= (item_size == 1) ? EightBitFont : SixteenBitFont;
336
c->nranges = nranges;
337
c->range = fixed_range;
339
(void) do_query_extents(client, (pointer) c);
344
#define pPtr ((QBclosurePtr) data)
347
do_query_bitmaps(ClientPtr client, pointer data)
350
unsigned long num_glyphs;
354
fsQueryXBitmaps8Reply reply;
357
err = GetBitmaps (pPtr->client, pPtr->pfont, pPtr->format,
358
pPtr->flags, pPtr->nranges, pPtr->range,
359
&data_size, &num_glyphs, &offsets, &glyph_data, &freedata);
361
if (err == Suspended) {
363
pPtr->pfont->unload_glyphs = 0; /* Not a safe call for this font */
365
ClientSleep(client, do_query_bitmaps, (pointer) pPtr);
369
if (err != Successful) {
370
SendErrToClient(pPtr->client, FontToFSError(err), (pointer) 0);
373
reply.type = FS_Reply;
374
reply.sequenceNumber = pPtr->client->sequence;
375
reply.replies_hint = 0;
376
reply.num_chars = num_glyphs;
377
reply.nbytes = data_size;
378
reply.length = (SIZEOF(fsQueryXBitmaps8Reply) + data_size +
379
(SIZEOF(fsOffset32) * num_glyphs) + 3) >> 2;
381
WriteReplyToClient(pPtr->client, SIZEOF(fsQueryXBitmaps8Reply), &reply);
383
SwapLongs((long *)offsets, num_glyphs * 2);
384
(void) WriteToClient(pPtr->client, (num_glyphs * SIZEOF(fsOffset32)),
386
(void) WriteToClient(pPtr->client, data_size, (char *) glyph_data);
387
fsfree((char *) offsets);
389
fsfree((char *) glyph_data);
392
ClientWakeup(pPtr->client);
393
if (pPtr->pfont->unload_glyphs) /* For rasterizers that want to save memory */
394
(*pPtr->pfont->unload_glyphs)(pPtr->pfont);
405
fsBitmapFormat format,
411
fsRange *fixed_range;
412
Bool all_glyphs = FALSE;
414
if (item_size == 2 && client->major_version == 1)
415
swap_char2b ((fsChar2b *)range_data, nranges);
417
fixed_range = build_range(range_flag, range_data, item_size,
418
&nranges, &all_glyphs, &cfp->font->info);
420
if (!fixed_range && !all_glyphs) {
421
SendErrToClient(client, FSBadRange, 0);
424
c = (QBclosurePtr) fsalloc(sizeof(QBclosureRec));
429
c->pfont = cfp->font;
430
c->flags = (all_glyphs) ? LoadAll : 0;
431
c->nranges = nranges;
432
c->range = fixed_range;
435
(void) do_query_bitmaps(client, (pointer) c);