#ifndef lint static char sccsid[] = "@(#)writebfont.c 9.2 88/01/19 Copyright 1985 Sun Micro"; #endif /* * Copyright (c) 1985 by Sun Microsystems, Inc. */ /*- Write a font in PostScript binary format writebfont.c, Tue Nov 19 15:43:19 1985 James Gosling, Sun Microsystems */ #include #include "fract.h" #include "font.h" writebfont(f, name) register struct font *f; char *name; { register FILE *out = fopen(name, "w"); register struct wglyph *g; register i; struct font temp; #define fsize (sizeof temp - sizeof temp.glyphs) int csize, nsize, pos, round; if (out == 0) return -1; temp = *f; temp.u.magic = NEW_FONT_MAGIC; csize = 0; pos = fsize + f->nglyphs * sizeof(struct wglyph); if (f->comment && f->comment[0]) { csize = strlen(f->comment) + 1; temp.comment = (char *) pos; pos += csize; } else temp.comment = 0; nsize = 0; if (f->name && f->name[0]) { nsize = strlen(f->name) + 1; temp.name = (char *) pos; pos += nsize; } else temp.name = 0; fwrite(&temp, fsize, 1, out); round = 0; if (pos&1) round++, pos++; for (i = 0; i < f->nglyphs; i++) { struct wglyph t; t = *(g = &f->glyphs[i]); if (g->glyph) { t.glyph = (struct glyph *) pos; pos += g->glyph->length; } else t.glyph = 0; fwrite(&t, sizeof t, 1, out); } if (csize) fwrite(f->comment, csize, 1, out); if (nsize) fwrite(f->name, nsize, 1, out); if (round) putc(0,out); for (i = 0; i < f->nglyphs; i++) if ((g = &f->glyphs[i])->glyph) fwrite(g->glyph, g->glyph->length, 1, out); fclose(out); }