#ifndef lint static char sccsid[] = "@(#)writeafont.c 9.2 88/01/19 Copyright 1985 Sun Micro"; #endif /* * Copyright (c) 1985 by Sun Microsystems, Inc. */ /*- Write ASCII (Adobe) format font. writeafont.c, Tue Nov 19 14:07:42 1985 James Gosling, Sun Microsystems */ #include "fract.h" #include "font.h" #include "stdio.h" #include "NameMap.h" extern unsigned char ReverseBitsInByte[256]; char * FontCharacterName(f, c) register struct font *f; { register struct NameMap *n; register limit; switch (f->encoding) { case AdobeSymbolEncoding: n = AdobeSymbolMap; limit = AdobeSymbolMapSize; break; default: n = AdobeMap; limit = AdobeMapSize; break; } while (--limit >= 0) if (n->index == c) return n->name; else n++; return ""; } writeafont(f, name) register struct font *f; char *name; { register FILE *out = fopen(name, "w"); register struct glyph *g; int i; if (out == 0) return -1; fprintf(out, f->type == PrinterWidthFont ? "StartFontMetrics 1.0\n" : "StartFont 1.4\n"); fprintf(out, "Comment %s\n", f->comment ? f->comment : "No copyright information"); fprintf(out, "Font %s\n", f->name); /* * The size information doesn't take into account any possible rotation or * skew */ if (f->type != PrinterWidthFont) { fprintf(out, "Size %d 72 72\n", roundfr(f->matrix[0][0])); fprintf(out, "Comment size %g %g %g %g\n", floatfr(f->matrix[0][0]), floatfr(f->matrix[0][1]), floatfr(f->matrix[1][0]), floatfr(f->matrix[1][1])); } fprintf(out, "FontBoundingBox %d %d %d %d\n", -f->origin.x, f->origin.y - f->size.y, f->size.x - f->origin.x, f->origin.y); fprintf(out, "Chars %d\n", f->nglyphs); { static char *EncodingTable[] = { "ASCII", /* 8 bit western European ASCII */ "Adobe", /* The Adobe version of ASCII */ "JISC6226", /* Japanese Industrial Standard Kanjii */ "Cyrillic", "Hangul", "Devenageri", "AdobeSymbol", }; fprintf(out, "Comment encoding %s\n", EncodingTable[(int) f->encoding]); } if (f->printermatched) fprintf(out, "Comment PrinterMatched\n"); if (f->type == PrinterWidthFont) { for (i = 0; i < f->nglyphs; i++) if (f->glyphs[i].width.x != 0) { fprintf(out, "C %d ; WX %d ; N %s\n", i, roundfr(f->glyphs[i].width.x * 1000), FontCharacterName(f, i)); } } else for (i = 0; i < f->nglyphs; i++) if (g = f->glyphs[i].glyph) { register char *bits; int r, c, c0; fprintf(out, "StartChar %s\nEncoding %d\nDWidth %g %g\nBBX %d %d %d %d\nBitmap\n", FontCharacterName(f, i), i, floatfr(f->glyphs[i].width.x), floatfr(f->glyphs[i].width.y), g->size.x, g->size.y, -g->origin.x, g->origin.y - g->size.y); bits = (char *) ((struct generic_glyph *) g)->bits; c0 = (g->size.x + 7) >> 3; for (r = g->size.y; --r >= 0;) { for (c = c0; --c >= 0;) { static char hex[] = "0123456789ABCDEF"; #ifdef LITTLEENDIAN putc(hex[(ReverseBitsInByte[*bits] >> 4) & 0xF], out); putc(hex[ReverseBitsInByte[*bits++] & 0xF], out); #else putc(hex[(*bits >> 4) & 0xF], out); putc(hex[*bits++ & 0xF], out); #endif } putc('\n', out); if (c0 & 1) bits++; } fprintf(out, "EndChar\n"); } fprintf(out, "EndFont\n"); fclose(out); return 0; }