fontdumper.c revision 1.2 1 1.1 mw /*
2 1.1 mw * Routine to allow user to select from available fonts that fit restricitons of
3 1.1 mw * NetBSD display code and then dump that font in the format for inclusion in the
4 1.1 mw * kernel. Only character values 32-255 are dumped.
5 1.1 mw *
6 1.1 mw * Current kernel only allows fonts up to 8 pixels wide & non-proportional.
7 1.1 mw * If this changes, the font requestor flags and restriction tests will need updating.
8 1.1 mw * Also the NetBSDwidth value, cursor bits and dumping of font hex values needs updating.
9 1.1 mw *
10 1.1 mw * Author: Alan Bair
11 1.1 mw * Dated: 11/12/1993
12 1.1 mw *
13 1.1 mw * Added printing of some other useful data for future (and current) expansion.
14 1.1 mw * -ch
15 1.1 mw * Dated: 11/17/1993
16 1.1 mw *
17 1.2 chopps * $Id: fontdumper.c,v 1.2 1994/02/11 07:02:57 chopps Exp $
18 1.1 mw */
19 1.1 mw
20 1.1 mw /* Original code by Markus Wild */
21 1.1 mw /* This is a *real* hack to dump the topaz80 kernel font. This one is
22 1.1 mw ways nicer than the ugly Mach font, but we'll have to dump it from a
23 1.1 mw running system to not run against Commodore copyrights. *NEVER* distribute
24 1.1 mw the generated font with BSD, always regenerate! */
25 1.1 mw
26 1.1 mw #include <exec/types.h>
27 1.1 mw #include <exec/memory.h>
28 1.1 mw #include <dos/dos.h>
29 1.1 mw #include <graphics/gfx.h>
30 1.1 mw #include <graphics/rastport.h>
31 1.1 mw #include <graphics/text.h>
32 1.1 mw #include <libraries/asl.h>
33 1.1 mw
34 1.1 mw #include <inline/exec.h>
35 1.1 mw #include <inline/graphics.h>
36 1.1 mw
37 1.1 mw #include <stdio.h>
38 1.1 mw
39 1.1 mw #define NetBSDwidth 8
40 1.1 mw
41 1.1 mw main(int argc, char *argv[])
42 1.1 mw {
43 1.1 mw unsigned char str[256];
44 1.1 mw int i;
45 1.1 mw int j;
46 1.1 mw struct RastPort rp;
47 1.1 mw unsigned char *pp;
48 1.1 mw struct BitMap bm = {
49 1.1 mw 256, /* bytes per row */
50 1.1 mw 8, /* rows */
51 1.1 mw 0, /* flags */
52 1.1 mw 1, /* depth */
53 1.1 mw 0, /* pad */
54 1.1 mw 0 /* planes */
55 1.1 mw };
56 1.1 mw struct TextAttr ta;
57 1.1 mw struct TextFont *tf;
58 1.1 mw struct FontRequester *fr;
59 1.1 mw struct TagItem frtags[] = {
60 1.1 mw ASL_Hail, (ULONG)"NetBSD font choices",
61 1.1 mw ASL_Width, 640,
62 1.1 mw ASL_Height, 400,
63 1.1 mw ASL_LeftEdge, 10,
64 1.1 mw ASL_TopEdge, 10,
65 1.1 mw ASL_OKText, (ULONG)"Dump",
66 1.1 mw ASL_CancelText, (ULONG)"Cancel",
67 1.1 mw ASL_FontName, (ULONG)"topaz.font",
68 1.1 mw ASL_FontHeight, 8L,
69 1.1 mw ASL_FontStyles, FS_NORMAL,
70 1.1 mw ASL_FuncFlags, FONF_STYLES | FONF_FIXEDWIDTH,
71 1.1 mw TAG_DONE
72 1.1 mw };
73 1.1 mw
74 1.1 mw /* Let the user pick a font to dump */
75 1.1 mw if (fr = (struct FontRequester *)
76 1.1 mw AllocAslRequest(ASL_FontRequest, frtags)) {
77 1.1 mw if (!AslRequest(fr, NULL)) {
78 1.1 mw FreeAslRequest(fr);
79 1.1 mw fprintf(stderr, "User requested exit\n");
80 1.1 mw exit (0);
81 1.1 mw }
82 1.1 mw ta.ta_Name = (STRPTR)malloc(strlen(fr->fo_Attr.ta_Name));
83 1.1 mw strcpy(ta.ta_Name, fr->fo_Attr.ta_Name);
84 1.1 mw ta.ta_YSize = fr->fo_Attr.ta_YSize;
85 1.1 mw ta.ta_Style = fr->fo_Attr.ta_Style;
86 1.1 mw ta.ta_Flags = fr->fo_Attr.ta_Flags;
87 1.1 mw FreeAslRequest(fr);
88 1.1 mw } else {
89 1.1 mw fprintf(stderr, "Can't allocate Font Requestor\n");
90 1.1 mw exit (1);
91 1.1 mw }
92 1.1 mw
93 1.1 mw /* Open the selected font */
94 1.1 mw tf = (struct TextFont *)OpenDiskFont (&ta);
95 1.1 mw if (! tf) {
96 1.1 mw fprintf (stderr, "Can't open font: %s\n", ta.ta_Name);
97 1.1 mw exit (1);
98 1.1 mw }
99 1.1 mw #ifdef DEBUG
100 1.1 mw fprintf(stderr, "Information on selected font:\n");
101 1.1 mw fprintf(stderr, "Name=%s\n", ta.ta_Name);
102 1.1 mw fprintf(stderr, "Height=%d tf_Style=%x tf_Flags=%x Width=%d Baseline=%d\n",
103 1.1 mw tf->tf_YSize, tf->tf_Style, tf->tf_Flags, tf->tf_XSize, tf->tf_Baseline);
104 1.1 mw #endif
105 1.1 mw
106 1.1 mw /* Check for NetBSD restrictions */
107 1.1 mw if (tf->tf_Flags & FPF_PROPORTIONAL) {
108 1.1 mw fprintf(stderr, "NetBSD does not support proportional fonts\n");
109 1.1 mw exit (1);
110 1.1 mw }
111 1.1 mw if (tf->tf_XSize > NetBSDwidth) {
112 1.1 mw fprintf(stderr, "NetBSD does not support fonts wider than %d pixels\n", NetBSDwidth);
113 1.1 mw exit (1);
114 1.1 mw }
115 1.1 mw
116 1.1 mw /* Allocate area to render font in */
117 1.1 mw InitBitMap(&bm, 1, 256 * NetBSDwidth, tf->tf_YSize);
118 1.1 mw InitRastPort (&rp);
119 1.1 mw rp.BitMap = &bm;
120 1.1 mw bm.Planes[0] = pp = AllocRaster (256 * NetBSDwidth, tf->tf_YSize);
121 1.1 mw if (!pp) {
122 1.1 mw fprintf (stderr, "Can't allocate raster!\n");
123 1.1 mw exit (1);
124 1.1 mw }
125 1.1 mw
126 1.1 mw /* Initialize string to be rendered */
127 1.1 mw for (i = 32; i < 256; i++) {
128 1.1 mw str[i - 32] = i;
129 1.1 mw }
130 1.1 mw
131 1.1 mw /* Render string with selected font */
132 1.1 mw SetFont (&rp, tf);
133 1.1 mw SetSoftStyle(&rp, ta.ta_Style ^ tf->tf_Style, (FSF_BOLD | FSF_UNDERLINED | FSF_ITALIC));
134 1.1 mw Move (&rp, 0, tf->tf_Baseline);
135 1.1 mw ClearEOL(&rp);
136 1.1 mw if (tf->tf_XSize != NetBSDwidth) {
137 1.1 mw /* right-justify char in cell */
138 1.1 mw Move (&rp, NetBSDwidth - tf->tf_XSize, tf->tf_Baseline);
139 1.1 mw /* Narrow font, put each character in space of normal font */
140 1.1 mw for (i = 0; i < (256 - 32); i++) {
141 1.1 mw Text (&rp, &str[i], 1);
142 1.1 mw Move (&rp, rp.cp_x + (NetBSDwidth - tf->tf_XSize), rp.cp_y);
143 1.1 mw }
144 1.1 mw } else {
145 1.1 mw Text (&rp, str, 256 - 32);
146 1.1 mw }
147 1.1 mw
148 1.1 mw /* Dump them.. */
149 1.1 mw printf ("/* Generated automatically by fontdumper.c. *DONT* distribute\n");
150 1.1 mw printf (" this file, it may contain information Copyright by Commodore!\n");
151 1.1 mw printf ("\n");
152 1.1 mw printf (" Font: %s/%d\n", ta.ta_Name, tf->tf_YSize);
153 1.1 mw printf (" */\n\n");
154 1.1 mw
155 1.1 mw printf ("unsigned char kernel_font_width = %d;\n", tf->tf_XSize);
156 1.1 mw printf ("unsigned char kernel_font_height = %d;\n", tf->tf_YSize);
157 1.1 mw printf ("unsigned char kernel_font_baseline = %d;\n", tf->tf_Baseline);
158 1.1 mw printf ("short kernel_font_boldsmear = %d;\n", tf->tf_BoldSmear);
159 1.1 mw printf ("unsigned char kernel_font_lo = 32;\n");
160 1.1 mw printf ("unsigned char kernel_font_hi = 255;\n\n");
161 1.1 mw
162 1.1 mw printf ("unsigned char kernel_cursor[] = {\n");
163 1.1 mw for (j = 0; j < (tf->tf_YSize -1); j++) {
164 1.1 mw printf ("0xff, ");
165 1.1 mw }
166 1.1 mw printf ("0xff };\n\n");
167 1.1 mw
168 1.1 mw printf ("unsigned char kernel_font[] = {\n");
169 1.1 mw for (i = 0; i < 256 - 32; i++) {
170 1.1 mw printf ("/* %c */", i + 32);
171 1.1 mw for (j = 0; j < tf->tf_YSize; j++) {
172 1.1 mw printf (" 0x%02x,", pp[i+j*256]);
173 1.1 mw }
174 1.1 mw printf ("\n");
175 1.1 mw }
176 1.1 mw printf ("};\n");
177 1.1 mw
178 1.1 mw CloseFont (tf);
179 1.1 mw FreeRaster (pp, 256 * NetBSDwidth, tf->tf_YSize);
180 1.1 mw return (0);
181 1.1 mw }
182