|
|
1.1 ! root 1: #ifdef sun ! 2: /* ! 3: * The Sun X drivers are a product of Sun Microsystems, Inc. and are provided ! 4: * for unrestricted use provided that this legend is included on all tape ! 5: * media and as a part of the software program in whole or part. Users ! 6: * may copy or modify these drivers without charge, but are not authorized ! 7: * to license or distribute them to anyone else except as part of a product or ! 8: * program developed by the user. ! 9: * ! 10: * THE SUN X DRIVERS ARE PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND ! 11: * INCLUDING THE WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A ! 12: * PARTICULAR PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE ! 13: * PRACTICE. ! 14: * ! 15: * The Sun X Drivers are provided with no support and without any obligation ! 16: * on the part of Sun Microsystems, Inc. to assist in their use, correction, ! 17: * modification or enhancement. ! 18: * ! 19: * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE ! 20: * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY THE SUN X ! 21: * DRIVERS OR ANY PART THEREOF. ! 22: * ! 23: * In no event will Sun Microsystems, Inc. be liable for any lost revenue ! 24: * or profits or other special, indirect and consequential damages, even if ! 25: * Sun has been advised of the possibility of such damages. ! 26: * ! 27: * Sun Microsystems, Inc. ! 28: * 2550 Garcia Avenue ! 29: * Mountain View, California 94043 ! 30: */ ! 31: ! 32: #ifndef lint ! 33: static char sccsid[] = "@(#)font.c 2.1 86/01/28 Copyright 1986 Sun Micro"; ! 34: #endif ! 35: ! 36: /*- ! 37: * Copyright 1985, Massachusetts Institute of Technology ! 38: * Copyright (c) 1986 by Sun Microsystems, Inc. ! 39: */ ! 40: ! 41: /* font.c Reads a font from a file and stores it on the workstation ! 42: * ! 43: * GetFont Takes a font name and stores it ! 44: * FreeFont Frees the storage taken by a font ! 45: * ! 46: */ ! 47: ! 48: /* ! 49: * ToDo: ! 50: * Use Sun fonts too ! 51: */ ! 52: ! 53: #include "Xsun.h" ! 54: #include "vssite.h" ! 55: #include "../libvs100/param.h" ! 56: #include <errno.h> ! 57: ! 58: extern int errno; ! 59: ! 60: char *Xalloc(), *strcpy(), *strcat(); ! 61: long lseek(); ! 62: ! 63: #define CHARPERFONT 256 ! 64: ! 65: static short ReverseBitsInByte[256] = { ! 66: 0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0, 0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0, ! 67: 0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8, 0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8, ! 68: 0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4, 0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4, ! 69: 0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec, 0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc, ! 70: 0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2, 0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2, ! 71: 0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea, 0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa, ! 72: 0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6, 0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6, ! 73: 0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee, 0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe, ! 74: 0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1, 0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1, ! 75: 0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9, 0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9, ! 76: 0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5, 0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5, ! 77: 0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed, 0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd, ! 78: 0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3, 0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3, ! 79: 0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb, 0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb, ! 80: 0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7, 0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7, ! 81: 0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef, 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff, ! 82: }; ! 83: ! 84: #define ReverseBitsInShort(s) ((ReverseBitsInByte[(unsigned char)(s)]<<8)|ReverseBitsInByte[(unsigned char)((s)>>8)]) ! 85: ! 86: /* ! 87: * this routine converts strike format into Sun font format ! 88: * XXX - it's embarrasingly slow, but I'm in too much of a hurry ! 89: * to do anything better for now. The font stuff is for the deep ! 90: * six anyway..... (DSHR). ! 91: */ ! 92: struct pixfont * ! 93: striketopixfont(fn) ! 94: FONT *fn; ! 95: { ! 96: register FontPriv *fp = (FontPriv *)fn->data; ! 97: register struct pixfont *pf; ! 98: register int fheight = fn->height; ! 99: register int i, j; ! 100: ! 101: ((struct pixfont *)fn->data) = pf = (struct pixfont *) Xalloc(sizeof(struct pixfont)); ! 102: if (pf != NULL) { ! 103: extern struct pixrectops mem_ops; ! 104: static struct mpr_data mprd; ! 105: static struct pixrect spr = {&mem_ops,2000,1000,1,(caddr_t)&mprd}; ! 106: { register short *sh = (short *) fp->fltable[0]; ! 107: register short limit = (fp->wpitch>>1)*fheight; ! 108: do *sh = ReverseBitsInShort(*sh), sh++; ! 109: while (--limit != -1); ! 110: } ! 111: mprd.md_linebytes = fp->wpitch; ! 112: mprd.md_image = (short *) fp->fltable[0]; ! 113: bzero((caddr_t) pf, sizeof(struct pixfont)); ! 114: pf->pf_defaultsize.y = fheight; ! 115: if (fn->fixed) ! 116: pf->pf_defaultsize.x = fn->avg_width; ! 117: for (i = fn->first; i <= fn->last; i++) { ! 118: register w = fp->widths[i]; ! 119: #ifdef undef ! 120: register offset = fp->leftarray[i]; ! 121: #endif ! 122: register struct pixchar *pc = &(pf->pf_char[i]); ! 123: ! 124: if (w < 0) ! 125: continue; /* Sanity check */ ! 126: pc->pc_pr = mem_create(w, fheight, 1); ! 127: pc->pc_home.x = 0; ! 128: pc->pc_home.y = fheight - fn->base; ! 129: pc->pc_adv.x = w; ! 130: pc->pc_adv.y = 0; ! 131: pr_rop(pc->pc_pr,0,0,w,fheight,PIX_SRC, ! 132: &spr, fp->leftarray[i], 0); ! 133: #ifdef undef ! 134: for (j = 0; j < fheight; j++) { ! 135: register int k; ! 136: for (k = 0; k < w; k++) { ! 137: int bit; ! 138: ! 139: bit = (*((u_short *)fp->fltable[j] + ((offset+k) >> 4))); ! 140: bit >>= ((offset + k) % 16); ! 141: bit &= 1; ! 142: pr_put(pc->pc_pr, k, j, bit); ! 143: ! 144: } ! 145: } ! 146: #endif ! 147: } ! 148: } ! 149: free((caddr_t) fp); ! 150: return ((struct pixfont *)fn->data); ! 151: } ! 152: ! 153: FONT *GetFont (name) ! 154: char *name; ! 155: { ! 156: char fontname[256]; ! 157: int fontfile = -1; ! 158: FontData font; ! 159: #define chars ((BitMap *) font.f_characters) ! 160: int fontsize, leftsize, width, i, j; ! 161: char *fontarea; ! 162: register short *leftarea, *leftarray; ! 163: register FONT *fd; ! 164: register FontPriv *fpriv; ! 165: int tablesize = (CHARPERFONT + 1) * sizeof(short); ! 166: extern char *getenv(), *index(); ! 167: static char *Fontpath = NULL; ! 168: char *fontpath; ! 169: ! 170: if (!Fontpath) { ! 171: char *temp = getenv("XFONTPATH"); ! 172: ! 173: if (temp) { ! 174: Fontpath = Xalloc(strlen(temp) + 1); ! 175: strcpy(Fontpath, temp); ! 176: } ! 177: } ! 178: ! 179: if ((fontpath = Fontpath) == NULL) ! 180: fontpath = DEFAULT_FONT_PATH; ! 181: ! 182: fontfile = open (name, 0, 0); ! 183: ! 184: while (fontfile < 0) { ! 185: char *fend; ! 186: ! 187: if ((fend = index(fontpath, ':')) != 0) ! 188: *fend = '\0'; ! 189: if (*fontpath == '\0') { ! 190: errno = EINVAL; ! 191: return (NULL); ! 192: } ! 193: ! 194: if (*fontpath == '~') { ! 195: /* XXX - should implement ~foobar as well */ ! 196: strcpy (fontname, getenv("HOME")); ! 197: strcat (fontname, "/"); ! 198: fontpath++; ! 199: } else ! 200: *fontname = '\0'; ! 201: strcat (fontname, fontpath); ! 202: strcat (fontname, "/"); ! 203: strcat (fontname, name); ! 204: strcat (fontname, DEFAULT_FONT_SUFFIX); ! 205: ! 206: fontfile = open (fontname, 0, 0); ! 207: if (fend) { ! 208: *fend = ':'; ! 209: fontpath = ++fend; ! 210: } else ! 211: break; ! 212: } ! 213: ! 214: if (read (fontfile, (caddr_t) &font, sizeof (FontData)) != sizeof (FontData)) { ! 215: close (fontfile); ! 216: errno = EINVAL; ! 217: return (NULL); ! 218: } ! 219: Swap_shorts((short *) &font, sizeof (FontData)>>1); ! 220: ! 221: fontsize = BitmapSize(chars->bm_width, chars->bm_height); ! 222: fontarea = (char *) Xalloc (fontsize); ! 223: lseek (fontfile, (long) font.f_characters[0], 0); ! 224: if (read (fontfile, fontarea, fontsize) != fontsize) { ! 225: close (fontfile); ! 226: free (fontarea); ! 227: errno = EINVAL; ! 228: return (NULL); ! 229: } ! 230: Swap_shorts((short *)fontarea, fontsize>>1); ! 231: ! 232: leftarea = (short *) Xalloc (tablesize); ! 233: bzero(leftarea, tablesize); ! 234: leftarray = (short *) Xalloc (tablesize); ! 235: if (font.f_fixedWidth == 0) { ! 236: leftsize = (font.f_lastChar - font.f_firstChar + 2) * sizeof (short); ! 237: lseek (fontfile, (long) font.f_leftArray[0], 0); ! 238: if (read (fontfile, & leftarea[font.f_firstChar], leftsize) ! 239: != leftsize) { ! 240: close (fontfile); ! 241: free (fontarea); ! 242: free ((caddr_t) leftarea); ! 243: free ((caddr_t) leftarray); ! 244: errno = EINVAL; ! 245: return (NULL); ! 246: } ! 247: Swap_shorts(((short *)& leftarea[font.f_firstChar]), leftsize>>1); ! 248: } else { /* if fixed with font, generate leftarray for use later */ ! 249: j = 0; ! 250: for (i = font.f_firstChar; i <= font.f_lastChar + 1; i++) { ! 251: leftarea[i] = j; ! 252: j += font.f_fixedWidth; ! 253: } ! 254: } ! 255: bcopy(leftarea, leftarray, tablesize); ! 256: ! 257: close (fontfile); ! 258: ! 259: fd = (FONT *) Xalloc (sizeof (FONT)); ! 260: ! 261: fd->height = chars->bm_height; ! 262: fd->first = font.f_firstChar; ! 263: fd->last = font.f_lastChar; ! 264: ! 265: fd->base = font.f_baseline; ! 266: fd->space = font.f_spaceIndex; ! 267: fd->space += fd->first; ! 268: fpriv = (FontPriv *) Xalloc (sizeof (FontPriv)); ! 269: if (fd->avg_width = font.f_fixedWidth) { ! 270: fd->fixed = 1; ! 271: fpriv->maxwidth = fd->avg_width; ! 272: } ! 273: else ! 274: fd->fixed = 0; ! 275: ! 276: fd->refcnt = 1; ! 277: fd->data = (caddr_t) fpriv; ! 278: fpriv->widths = leftarea; ! 279: fpriv->leftarray = leftarray; ! 280: ! 281: if ((fpriv->strike = (BITMAP *) Xalloc(sizeof(BITMAP))) == NULL) { ! 282: free (fontarea); ! 283: free ((caddr_t) leftarea); ! 284: free ((caddr_t) leftarray); ! 285: free ((caddr_t) fd); ! 286: free ((caddr_t) fpriv); ! 287: errno = EINVAL; ! 288: return (NULL); ! 289: } ! 290: fpriv->wpitch = (((chars->bm_width + 15) >> 3) & ~1); ! 291: fpriv->strike->width = chars->bm_width; ! 292: fpriv->strike->height = chars->bm_height; ! 293: fpriv->strike->refcnt = 1; ! 294: fpriv->strike->data = (caddr_t) fontarea; ! 295: /* ! 296: * compute line table for font to eliminate multiply to find beginning ! 297: * of line. ! 298: */ ! 299: fpriv->fltable = (char **)Xalloc(chars->bm_height * sizeof(caddr_t)); ! 300: for (i = 0; i < chars->bm_height; i++) ! 301: fpriv->fltable[i] = ((caddr_t) fontarea) + i * fpriv->wpitch; ! 302: ! 303: fd->name = (char *) Xalloc (strlen (name) + 1); ! 304: strcpy (fd->name, name); ! 305: ! 306: fpriv->maxwidth = 0; ! 307: ! 308: /* convert the leftarray to the width table */ ! 309: for (i = fd->first; i <= fd->last; i++) { ! 310: width = fpriv->leftarray[i + 1] - fpriv->leftarray[i]; ! 311: if (width > fpriv->maxwidth) fpriv->maxwidth = width; ! 312: if (width < 0) { ! 313: width = 0; /* font sanity check */ ! 314: #ifdef notdef ! 315: DeviceError ("Bad font leftarray!\n"); ! 316: #else ! 317: errno = EINVAL; ! 318: return(NULL); ! 319: #endif ! 320: } ! 321: fpriv->widths[i] = width; ! 322: } ! 323: ! 324: fd->avg_width = ((fpriv->leftarray[fd->last] - ! 325: fpriv->leftarray[fd->first]) / (fd->last - fd->first)); ! 326: ! 327: striketopixfont(fd); ! 328: return (fd); ! 329: #undef chars ! 330: } ! 331: ! 332: FreeFont (font) ! 333: register FONT *font; ! 334: { ! 335: free ((caddr_t) font->data); ! 336: free (font->name); ! 337: free ((caddr_t) font); ! 338: } ! 339: #endif sun
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.