1 /**
2 ** dumpfna.c ---- write an ascii font file from a font in memory
3 **
4 ** Copyright (C) 2002 Dimitar Zhekov
5 ** E-Mail: jimmy@is-vn.bg
6 **
7 ** This file is part of the GRX graphics library.
8 **
9 ** The GRX graphics library is free software; you can redistribute it
10 ** and/or modify it under some conditions; see the "copying.grx" file
11 ** for details.
12 **
13 ** This library is distributed in the hope that it will be useful,
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 **
17 **/
18
19 #include <ctype.h>
20 #include <stdio.h>
21
22 #include "libgrx.h"
23
GrDumpFnaFont(const GrFont * f,char * fileName)24 void GrDumpFnaFont(const GrFont *f, char *fileName)
25 {
26 int chr;
27 int x, y, width, bytes;
28 char *buffer;
29 FILE *fp = fopen(fileName, "w");
30 if(!fp) return;
31 /* write header */
32 fprintf(fp, "name %s\n", f->h.name);
33 fprintf(fp, "family %s\n", f->h.family);
34 fprintf(fp, "isfixed %d\n", !f->h.proportional);
35 if(f->h.proportional) {
36 fprintf(fp, "minwidth %d\n", f->minwidth);
37 fprintf(fp, "maxwidth %d\n", f->maxwidth);
38 fprintf(fp, "avg");
39 }
40 fprintf(fp, "width %d\n", f->h.width);
41 fprintf(fp, "height %d\n", f->h.height);
42 fprintf(fp, "minchar %d\n", f->h.minchar);
43 fprintf(fp, "maxchar %d\n", f->h.minchar + f->h.numchars - 1);
44 fprintf(fp, "baseline %d\n", f->h.baseline);
45 fprintf(fp, "undwidth %d\n", f->h.ulheight);
46 /* write characters */
47 for(chr = f->h.minchar; chr < f->h.minchar + f->h.numchars; chr++) {
48 width = GrFontCharWidth(f, chr);
49 bytes = (width - 1) / 8 + 1;
50 buffer = GrFontCharBitmap(f, chr);
51 /* write character header */
52 fprintf(fp, "\n; character %d", chr);
53 if(isgraph(chr)) fprintf(fp, " (%c)", chr);
54 fprintf(fp, " width = %d\n", width);
55 /* write character data */
56 for(y = 0; y < f->h.height; y++) {
57 for(x = 0; x < width; x++)
58 putc(buffer[x >> 3] & (1 << (7 - (x & 7))) ? '#' : '.', fp);
59 putc('\n', fp);
60 buffer += bytes;
61 }
62 }
63 fclose(fp);
64 }
65