1
/* $Xorg: spglyph.c,v 1.4 2001/02/09 02:04:00 xorgcvs Exp $ */
3
* Copyright 1990, 1991 Network Computing Devices;
4
* Portions Copyright 1987 by Digital Equipment Corporation
6
* Permission to use, copy, modify, distribute, and sell this software and
7
* its documentation for any purpose is hereby granted without fee, provided
8
* that the above copyright notice appear in all copies and that both that
9
* copyright notice and this permission notice appear in supporting
10
* documentation, and that the names of Network Computing Devices or Digital
11
* not be used in advertising or publicity pertaining to distribution of
12
* the software without specific, written prior permission.
14
* NETWORK COMPUTING DEVICES AND DIGITAL DISCLAIM ALL WARRANTIES WITH
15
* REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
16
* AND FITNESS, IN NO EVENT SHALL NETWORK COMPUTING DEVICES OR DIGITAL BE
17
* LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
18
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
19
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
20
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22
* Author: Dave Lemke, Network Computing Devices Inc
27
Copyright 1987, 1998 The Open Group
29
Permission to use, copy, modify, distribute, and sell this software and its
30
documentation for any purpose is hereby granted without fee, provided that
31
the above copyright notice appear in all copies and that both that
32
copyright notice and this permission notice appear in supporting
35
The above copyright notice and this permission notice shall be included
36
in all copies or substantial portions of the Software.
38
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
39
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
40
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
41
IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
42
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
43
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
44
OTHER DEALINGS IN THE SOFTWARE.
46
Except as contained in this notice, the name of The Open Group shall
47
not be used in advertising or otherwise to promote the sale, use or
48
other dealings in this Software without prior written authorization
52
/* $XFree86: xc/lib/font/Speedo/spglyph.c,v 1.6 2001/01/17 19:43:20 dawes Exp $ */
57
#include <X11/X.h> /* for bit order #defines */
59
#include <X11/fonts/fontutil.h>
61
#undef CLIP_BBOX_NOISE
63
static CurrentFontValuesRec current_font_values;
64
static CurrentFontValuesPtr cfv = ¤t_font_values;
78
unsigned long size = 0;
80
SpeedoFontPtr spf = (SpeedoFontPtr) pfont->fontPrivate;
81
FontInfoPtr pinfo = &pfont->info;
84
firstChar = spf->master->first_char_id;
86
/* allocate the space */
92
case BitmapFormatImageRectMin:
94
for (ch = start; ch <= end; ch++) {
95
ci = &spf->encoding[ch - firstChar];
99
charsize = GLYPH_SIZE(ci, scanlinepad);
100
charsize *= cim->ascent + cim->descent;
104
case BitmapFormatImageRectMaxWidth:
105
bpr = GLWIDTHBYTESPADDED(FONT_MAX_WIDTH(pinfo), scanlinepad);
107
for (ch = start; ch <= end; ch++) {
108
ci = &spf->encoding[ch - firstChar];
112
charsize = bpr * (cim->ascent + cim->descent);
116
case BitmapFormatImageRectMax:
117
bpr = GLWIDTHBYTESPADDED(FONT_MAX_WIDTH(pinfo), scanlinepad);
119
size = (end - start + 1) * bpr * FONT_MAX_HEIGHT(pinfo);
129
finish_line(SpeedoFontPtr spf)
132
CharInfoPtr ci = &spf->encoding[cfv->char_id - spf->master->first_char_id];
135
bpr = GLYPH_SIZE(ci, cfv->scanpad);
137
if (bpr) { /* char may not have any metrics... */
138
cfv->bp = (char *)cfv->bp + bpr;
140
assert(cfv->bp - sp_fp_cur->bitmaps <= sp_fp_cur->bitmap_size);
145
sp_set_bitmap_bits(fix15 y, fix15 xbit1, fix15 xbit2)
152
if (xbit1 > cfv->bit_width) {
154
#ifdef CLIP_BBOX_NOISE
155
SpeedoErr("Run wider than bitmap width -- truncated\n");
158
xbit1 = cfv->bit_width;
160
if (xbit2 > cfv->bit_width) {
162
#ifdef CLIP_BBOX_NOISE
163
SpeedoErr("Run wider than bitmap width -- truncated\n");
166
xbit2 = cfv->bit_width;
173
while (cfv->cur_y != y) {
174
finish_line(sp_fp_cur);
179
if (y >= cfv->bit_height) {
181
#ifdef CLIP_BBOX_NOISE
182
SpeedoErr("Y larger than bitmap height -- truncated\n");
188
if (xbit1 < 0) /* XXX this is more than a little bit rude... */
191
nmiddle = (xbit1 >> 3);
192
dst = (CARD8 *)cfv->bp + nmiddle;
193
xbit2 -= (xbit1 & ~7);
194
nmiddle = (xbit2 >> 3);
197
if (bit_order == MSBFirst) {
198
startmask = ((CARD8) ~0) >> xbit1;
199
endmask = ~(((CARD8) ~0) >> xbit2);
201
startmask = ((CARD8) ~0) << xbit1;
202
endmask = ~(((CARD8) ~0) << xbit2);
205
*dst |= endmask & startmask;
216
sp_open_bitmap(fix31 x_set_width, fix31 y_set_width, fix31 xorg, fix31 yorg,
217
fix15 xsize, fix15 ysize)
219
CharInfoPtr ci = &sp_fp_cur->encoding[cfv->char_id - sp_fp_cur->master->first_char_id];
222
* this is set to provide better quality bitmaps. since the Speedo
223
* sp_get_bbox() function returns an approximate (but guarenteed to contain)
224
* set of metrics, some of the bitmaps can be place poorly inside and
227
* with this set, the actual bitmap values are used instead of the bboxes.
228
* it makes things look better, but causes two possible problems:
230
* 1 - the reported min & max bounds may not correspond to the extents
232
* 2 - if the extents are reported before the character is generated,
233
* a client could see them change. this currently never happens,
234
* but will when a desired enhancement (don't reneder till needed)
245
off_horz = (fix15) ((xorg - 32768L) / 65536);
247
off_horz = (fix15) ((xorg + 32768L) / 65536);
249
off_vert = (fix15) ((yorg - 32768L) / 65536);
251
off_vert = (fix15) ((yorg + 32768L) / 65536);
252
if (xsize != 0 || ysize != 0 || ci->metrics.characterWidth)
254
ci->metrics.leftSideBearing = off_horz;
255
ci->metrics.descent = -off_vert;
256
ci->metrics.rightSideBearing = xsize + off_horz;
257
ci->metrics.ascent = ysize + off_vert;
261
/* If setting the proper size would cause the character to appear to
262
be non-existent, fudge things by giving it a pixel to occupy. */
264
ci->metrics.leftSideBearing = ci->metrics.descent = 0;
265
ci->metrics.rightSideBearing = ci->metrics.ascent = 1;
268
cfv->bit_width = xsize;
269
cfv->bit_height = ysize;
271
cfv->bit_width = ci->metrics.rightSideBearing -
272
ci->metrics.leftSideBearing;
273
cfv->bit_height = ci->metrics.ascent + ci->metrics.descent;
276
assert(cfv->bp - sp_fp_cur->bitmaps <= sp_fp_cur->bitmap_size);
277
ci->bits = (char *) cfv->bp;
285
CharInfoPtr ci = &sp_fp_cur->encoding[cfv->char_id - sp_fp_cur->master->first_char_id];
289
bpr = GLYPH_SIZE(ci, cfv->scanpad);
291
finish_line(sp_fp_cur);
294
while (cfv->last_y < cfv->bit_height) {
295
finish_line(sp_fp_cur);
298
if (byte_order != bit_order) {
303
TwoByteSwap(cfv->bp, bpr * cfv->bit_height);
306
FourByteSwap(cfv->bp, bpr * cfv->bit_height);
313
sp_build_all_bitmaps(
315
fsBitmapFormat format,
316
fsBitmapFormatMask fmask)
320
image = BitmapFormatImageRectMin;
321
unsigned long glyph_size;
322
SpeedoFontPtr spf = (SpeedoFontPtr) pfont->fontPrivate;
323
SpeedoMasterFontPtr spmf = spf->master;
330
ret = CheckFSFormat(format, fmask,
331
&bit_order, &byte_order, &scan, &glyph, &image);
333
pfont->bit = bit_order;
334
pfont->byte = byte_order;
335
pfont->glyph = glyph;
337
if (ret != Successful)
338
return BadFontFormat;
340
start = spmf->first_char_id;
342
glyph_size = sp_compute_data_size(pfont, image, glyph, start, end);
344
/* XXX -- MONDO KLUDGE -- add some slop */
346
* not sure why this is wanted, but it keeps the packer from going off the
347
* end and toasting us down the line
352
spf->bitmap_size = glyph_size;
355
bitmaps = (pointer) xalloc(glyph_size);
358
bzero((char *) bitmaps, glyph_size);
360
/* set up some state */
362
spf->bitmaps = bitmaps;
363
cfv->format = format;
364
cfv->scanpad = glyph;
367
for (i = 0; i < spmf->num_chars; i++) {
369
cfv->char_index = spmf->enc[i * 2 + 1];
370
cfv->char_id = spmf->enc[i * 2];
372
fprintf(stderr, "build_all_sp_bitmaps:i = %d, Char ID = %d\n", i, cfv->char_id);
378
* See if this character is in the list of ranges specified in the
381
for (j = 0; j < spf->vals.nranges; j++)
382
if (cfv->char_id >= mincharno(spf->vals.ranges[j]) &&
383
cfv->char_id <= maxcharno(spf->vals.ranges[j]))
386
/* If not, don't realize it. */
387
if (spf->vals.nranges && j == spf->vals.nranges)
390
if (!sp_make_char(cfv->char_index)) {
392
#ifdef DEBUG /* can be very common with some encodings */
393
SpeedoErr("Can't make char %d\n", cfv->char_index);