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