#ifndef lint static char sccsid[] = "@(#)rdcmufont.c 9.2 88/01/19 Copyright 1985 Sun Micro"; #endif /* * Copyright (c) 1985 by Sun Microsystems, Inc. */ /*- Read a font in CMU's funny format rdcmufont.c, Wed Nov 20 09:44:35 1985 James Gosling, Sun Microsystems */ #include #ifdef REF #include #include #endif #include "fract.h" #include "font.h" #include "cmufont.h" struct font * cst_readcmufont(cf) register struct cmufont *cf; { register struct font *f; f = (struct font *) snoopalloc("rdcmufont.c", sizeof *f + cf->size * sizeof f->glyphs[0]); f->u.magic = NEW_FONT_MAGIC; f->type = LRbitmapFont; f->encoding = ASCIIencoding; f->printermatched = 0; { char buf[200]; register char *s = cf->fn.fname, *d = buf; int length; while (*s && s < &cf->fn.fname[cmufnamesize]) *d++ = *s++; if (strncmp(d - 5, "Roman", 5) == 0) { d -= 5; if (cf->fn.flags == 0) for (s = "-Roman"; *s; *d++ = *s++); } if (cf->fn.flags & BoldFace) for (s = "-Bold"; *s; *d++ = *s++); if (cf->fn.flags & ItalicFace) for (s = "-Italic"; *s; *d++ = *s++); if (cf->fn.flags & FixedWidthFace) for (s = "-Fixed"; *s; *d++ = *s++); *d++ = 0; if (islower(buf[0])) buf[0] += 'A' - 'a'; length = strlen(buf) + 1; f->name = (char *) snoopalloc("rdcmufont.c", length); bcopy(buf, f->name, length); } f->matrix[0][0] = fracti(cf->fn.height); f->matrix[0][1] = 0; f->matrix[1][0] = 0; f->matrix[1][1] = f->matrix[0][0]; f->comment = "Originally CMU/ITC font."; f->nglyphs = cf->size; { register i; for (i = 0; i < f->nglyphs; i++) if (i>=' ' && cf->chars[i].goff && cf->chars[i].soff) { register struct glyph *g; register struct cmubmiconsp *sp; register struct cmuicongp *gp; unsigned short *top; int colcnt, rowcnt, colreset, rowreset; int gsize; sp = (struct cmubmiconsp *) (((int) &cf->chars[i]) + cf->chars[i].soff); gp = (struct cmuicongp *) (((int) &cf->chars[i]) + cf->chars[i].goff); colreset = (sp->sx + 15) >> 4; rowreset = sp->sy; gsize = sizeof *g + rowreset * colreset * sizeof(short); g = (struct glyph *) snoopalloc("rdcmufont.c", gsize); f->glyphs[i].glyph = g; g->length = gsize; g->origin.x = sp->ox; g->origin.y = sp->oy; g->size.x = sp->sx; g->size.y = sp->sy; f->glyphs[i].width.x = fracti(gp->width.x); f->glyphs[i].width.y = fracti(gp->width.y); gp = (struct cmuicongp *) sp->bits; top = ((struct generic_glyph *) g)->bits; for (colcnt = colreset; --colcnt >= 0;) { sp = (struct cmubmiconsp *) top; top++; for (rowcnt = rowreset; --rowcnt >= 0;) { *sp = *((struct cmubmiconsp *) gp)++; sp = (struct cmubmiconsp *) ((int) sp + colreset); } } } else f->glyphs[i].glyph = 0; } return f; }