1 /* $TOG: spfont.c /main/24 1997/06/09 09:38:19 barstow $ */
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
24 /* $XFree86: xc/lib/font/Speedo/spfont.c,v 3.1.8.1 1997/06/11 12:08:38 dawes Exp $ */
28 Copyright (c) 1987 X Consortium
30 Permission is hereby granted, free of charge, to any person obtaining
31 a copy of this software and associated documentation files (the
32 "Software"), to deal in the Software without restriction, including
33 without limitation the rights to use, copy, modify, merge, publish,
34 distribute, sublicense, and/or sell copies of the Software, and to
35 permit persons to whom the Software is furnished to do so, subject to
36 the following conditions:
38 The above copyright notice and this permission notice shall be included
39 in all copies or substantial portions of the Software.
41 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
42 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
43 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
44 IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
45 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
46 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
47 OTHER DEALINGS IN THE SOFTWARE.
49 Except as contained in this notice, the name of the X Consortium shall
50 not be used in advertising or otherwise to promote the sale, use or
51 other dealings in this Software without prior written authorization
52 from the X Consortium.
66 #define _XOPEN_SOURCE /* to get prototype for hypot on some systems */
74 #ifndef DEFAULT_BIT_ORDER
76 #ifdef BITMAP_BIT_ORDER
77 #define DEFAULT_BIT_ORDER BITMAP_BIT_ORDER
79 #define DEFAULT_BIT_ORDER UNKNOWN_BIT_ORDER
84 extern void SpeedoCloseFont();
85 static int sp_get_glyphs();
86 static int sp_get_metrics();
87 static int sp_load_font();
89 static CharInfoRec junkDefault;
92 sp_get_glyphs(pFont, count, chars, charEncoding, glyphCount, glyphs)
95 register unsigned char *chars;
96 FontEncoding charEncoding;
97 unsigned long *glyphCount; /* RETURN */
98 CharInfoPtr *glyphs; /* RETURN */
101 unsigned int firstCol;
102 register unsigned int numCols;
103 unsigned int firstRow;
104 unsigned int numRows;
105 CharInfoPtr *glyphsBase;
106 register unsigned int c;
107 register CharInfoPtr pci;
109 CharInfoPtr encoding;
110 CharInfoPtr pDefault;
112 int err = Successful;
114 spf = (SpeedoFontPtr) pFont->fontPrivate;
115 encoding = spf->encoding;
116 pDefault = spf->pDefault;
117 firstCol = pFont->info.firstCol;
118 numCols = pFont->info.lastCol - firstCol + 1;
122 /* XXX - this should be much smarter */
123 /* make sure the glyphs are there */
124 if (charEncoding == Linear8Bit || charEncoding == TwoD8Bit)
131 err = fs_load_glyphs(NULL, pFont, count, itemSize, chars);
134 if (err != Successful)
137 switch (charEncoding) {
141 if (pFont->info.firstRow > 0)
143 if (pFont->info.allExist && pDefault) {
145 c = (*chars++) - firstCol;
147 *glyphs++ = &encoding[c];
149 *glyphs++ = pDefault;
153 c = (*chars++) - firstCol;
154 if (c < numCols && (pci = &encoding[c])->bits)
157 *glyphs++ = pDefault;
162 if (pFont->info.allExist && pDefault) {
165 c = (c | *chars++) - firstCol;
167 *glyphs++ = &encoding[c];
169 *glyphs++ = pDefault;
174 c = (c | *chars++) - firstCol;
175 if (c < numCols && (pci = &encoding[c])->bits)
178 *glyphs++ = pDefault;
184 firstRow = pFont->info.firstRow;
185 numRows = pFont->info.lastRow - firstRow + 1;
187 r = (*chars++) - firstRow;
188 c = (*chars++) - firstCol;
189 if (r < numRows && c < numCols &&
190 (pci = &encoding[r * numCols + c])->bits)
193 *glyphs++ = pDefault;
197 *glyphCount = glyphs - glyphsBase;
201 static CharInfoRec nonExistantChar;
204 sp_get_metrics(pFont, count, chars, charEncoding, glyphCount, glyphs)
207 register unsigned char *chars;
208 FontEncoding charEncoding;
209 unsigned long *glyphCount; /* RETURN */
210 xCharInfo **glyphs; /* RETURN */
214 CharInfoPtr oldDefault;
216 spf = (SpeedoFontPtr) pFont->fontPrivate;
217 oldDefault = spf->pDefault;
218 spf->pDefault = &nonExistantChar;
219 ret = sp_get_glyphs(pFont, count, chars, charEncoding,
220 glyphCount, (CharInfoPtr *) glyphs);
222 spf->pDefault = oldDefault;
227 sp_open_font(fontname, filename, entry, vals, format, fmask, flags, spfont)
231 FontScalablePtr vals;
232 fsBitmapFormat format;
233 fsBitmapFormatMask fmask;
235 SpeedoFontPtr *spfont;
238 SpeedoMasterFontPtr spmf;
241 int xx8, xy8, yx8, yy8;
244 /* find a master (create it if necessary) */
245 spmf = (SpeedoMasterFontPtr) entry->u.scalable.extra->private;
248 ret = sp_open_master(filename, &spmf);
249 if (ret != Successful)
251 entry->u.scalable.extra->private = (pointer) spmf;
255 spf = (SpeedoFontPtr) xalloc(sizeof(SpeedoFontRec));
258 bzero((char *) spf, sizeof(SpeedoFontRec));
262 /* clobber everything -- this may be leaking, but other wise evil
263 * stuff is left behind -- succesive transformed fonts get mangled */
264 bzero((char *)&sp_globals, sizeof(sp_globals));
269 sp_reset_master(spmf);
270 /* now we've done enough that if we bail out we must call sp_close_font */
276 specs.pfont = &spmf->font;
278 specs.xxmult = (int)(vals->pixel_matrix[0] * (double)(1L << 16));
279 specs.xymult = (int)(vals->pixel_matrix[2] * (double)(1L << 16));
280 specs.yxmult = (int)(vals->pixel_matrix[1] * (double)(1L << 16));
281 specs.yymult = (int)(vals->pixel_matrix[3] * (double)(1L << 16));
283 specs.xoffset = 0L << 16; /* XXX tweak? */
284 specs.yoffset = 0L << 16; /* XXX tweak? */
286 specs.flags = MODE_SCREEN;
287 specs.out_info = NULL;
289 /* When Speedo tries to generate a very small font bitmap, it
290 often crashes or goes into an infinite loop.
291 Don't know why this is so, but until we can fix it properly,
292 return BadFontName for anything smaller than 4 pixels.
294 #define TINY_FACTOR (16 << 16)
295 xx8 = specs.xxmult >> 8;
296 xy8 = specs.xymult >> 8;
297 yx8 = specs.yxmult >> 8;
298 yy8 = specs.yymult >> 8;
299 if (xx8 * xx8 + xy8 * xy8 < TINY_FACTOR ||
300 yx8 * yx8 + yy8 * yy8 < TINY_FACTOR)
306 /* clobber global state to avoid wrecking future transformed fonts */
307 bzero ((char *) &sp_globals, sizeof(sp_globals));
309 if (!sp_set_specs(&specs))
323 sp_load_font(fontname, filename, entry, vals, format, fmask, pfont, flags)
327 FontScalablePtr vals;
328 fsBitmapFormat format;
329 fsBitmapFormatMask fmask;
334 SpeedoMasterFontPtr spmf;
339 ret = sp_open_font(fontname, filename, entry, vals, format, fmask,
342 if (ret != Successful)
346 sp_reset_master(spmf);
347 esize = sizeof(CharInfoRec) * (spmf->max_id - spmf->first_char_id + 1);
349 spf->encoding = (CharInfoPtr) xalloc(esize);
350 if (!spf->encoding) {
354 bzero((char *) spf->encoding, esize);
358 sp_make_header(spf, &pfont->info);
360 sp_compute_bounds(spf, &pfont->info, SaveMetrics, &sWidth);
362 sp_compute_props(spf, fontname, &pfont->info, sWidth);
364 pfont->fontPrivate = (pointer) spf;
367 flags |= FontLoadBitmaps;
369 if (flags & FontLoadBitmaps) {
371 ret = sp_build_all_bitmaps(pfont, format, fmask);
373 if (ret != Successful)
376 /* compute remaining accelerators */
377 FontComputeInfoAccelerators(&pfont->info);
379 pfont->format = format;
381 pfont->get_metrics = sp_get_metrics;
382 pfont->get_glyphs = sp_get_glyphs;
383 pfont->unload_font = SpeedoCloseFont;
384 pfont->unload_glyphs = NULL;
386 pfont->maxPrivate = -1;
387 pfont->devPrivates = (pointer *) 0;
389 /* have to hold on to master for min/max id */
390 sp_close_master_file(spmf);
396 SpeedoFontLoad(ppfont, fontname, filename, entry, vals, format, fmask, flags)
401 FontScalablePtr vals;
402 fsBitmapFormat format;
403 fsBitmapFormatMask fmask;
409 /* Reject ridiculously small sizes that will blow up the math */
410 if (hypot(vals->pixel_matrix[0], vals->pixel_matrix[1]) < 1.0 ||
411 hypot(vals->pixel_matrix[2], vals->pixel_matrix[3]) < 1.0)
414 pfont = (FontPtr) xalloc(sizeof(FontRec));
418 ret = sp_load_font(fontname, filename, entry, vals, format, fmask,
421 if (ret == Successful)
433 SpeedoMasterFontPtr spmf;
437 if (spmf->refcount == 0)
438 sp_close_master_font (spmf);
439 xfree(spf->encoding);
445 SpeedoCloseFont(pfont)
450 spf = (SpeedoFontPtr) pfont->fontPrivate;
452 xfree(pfont->info.isStringProp);
453 xfree(pfont->info.props);
454 xfree(pfont->devPrivates);