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