1 /* $NetBSD: fontdumper.c,v 1.3 1994/10/26 02:06:59 cgd Exp $ */
4 * Routine to allow user to select from available fonts that fit restricitons of
5 * NetBSD display code and then dump that font in the format for inclusion in
6 * the kernel. Only character values 32-255 are dumped.
8 * Current kernel only allows fonts up to 8 pixels wide & non-proportional.
9 * If this changes, the font requestor flags and restriction tests will need
11 * Also the NetBSDwidth value, cursor bits and dumping of font hex values
17 * Added printing of some other useful data for future (and current) expansion.
22 /* Original code by Markus Wild */
23 /* This is a *real* hack to dump the topaz80 kernel font. This one is
24 ways nicer than the ugly Mach font, but we'll have to dump it from a
25 running system to not run against Commodore copyrights. *NEVER* distribute
26 the generated font with BSD, always regenerate! */
28 #include <exec/types.h>
29 #include <exec/memory.h>
31 #include <graphics/gfx.h>
32 #include <graphics/rastport.h>
33 #include <graphics/text.h>
34 #include <libraries/asl.h>
36 #include <inline/exec.h>
37 #include <inline/graphics.h>
43 main(int argc
, char *argv
[])
45 unsigned char str
[256];
51 256, /* bytes per row */
60 struct FontRequester
*fr
;
61 struct TagItem frtags
[] = {
62 ASL_Hail
, (ULONG
)"NetBSD font choices",
67 ASL_OKText
, (ULONG
)"Dump",
68 ASL_CancelText
, (ULONG
)"Cancel",
69 ASL_FontName
, (ULONG
)"topaz.font",
71 ASL_FontStyles
, FS_NORMAL
,
72 ASL_FuncFlags
, FONF_STYLES
| FONF_FIXEDWIDTH
,
76 /* Let the user pick a font to dump */
77 if (fr
= (struct FontRequester
*)
78 AllocAslRequest(ASL_FontRequest
, frtags
)) {
79 if (!AslRequest(fr
, NULL
)) {
81 fprintf(stderr
, "User requested exit\n");
84 ta
.ta_Name
= (STRPTR
)malloc(strlen(fr
->fo_Attr
.ta_Name
));
85 strcpy(ta
.ta_Name
, fr
->fo_Attr
.ta_Name
);
86 ta
.ta_YSize
= fr
->fo_Attr
.ta_YSize
;
87 ta
.ta_Style
= fr
->fo_Attr
.ta_Style
;
88 ta
.ta_Flags
= fr
->fo_Attr
.ta_Flags
;
91 fprintf(stderr
, "Can't allocate Font Requestor\n");
95 /* Open the selected font */
96 tf
= (struct TextFont
*)OpenDiskFont (&ta
);
98 fprintf (stderr
, "Can't open font: %s\n", ta
.ta_Name
);
102 fprintf(stderr
, "Information on selected font:\n");
103 fprintf(stderr
, "Name=%s\n", ta
.ta_Name
);
104 fprintf(stderr
, "Height=%d tf_Style=%x tf_Flags=%x Width=%d Baseline=%d\n",
105 tf
->tf_YSize
, tf
->tf_Style
, tf
->tf_Flags
, tf
->tf_XSize
, tf
->tf_Baseline
);
108 /* Check for NetBSD restrictions */
109 if (tf
->tf_Flags
& FPF_PROPORTIONAL
) {
110 fprintf(stderr
, "NetBSD does not support proportional fonts\n");
113 if (tf
->tf_XSize
> NetBSDwidth
) {
114 fprintf(stderr
, "NetBSD does not support fonts wider than %d pixels\n", NetBSDwidth
);
118 /* Allocate area to render font in */
119 InitBitMap(&bm
, 1, 256 * NetBSDwidth
, tf
->tf_YSize
);
122 bm
.Planes
[0] = pp
= AllocRaster (256 * NetBSDwidth
, tf
->tf_YSize
);
124 fprintf (stderr
, "Can't allocate raster!\n");
128 /* Initialize string to be rendered */
129 for (i
= 32; i
< 256; i
++) {
133 /* Render string with selected font */
135 SetSoftStyle(&rp
, ta
.ta_Style
^ tf
->tf_Style
,
136 FSF_BOLD
| FSF_UNDERLINED
| FSF_ITALIC
);
137 Move (&rp
, 0, tf
->tf_Baseline
);
139 if (tf
->tf_XSize
!= NetBSDwidth
) {
140 /* right-justify char in cell */
141 Move (&rp
, NetBSDwidth
- tf
->tf_XSize
, tf
->tf_Baseline
);
142 /* Narrow font, put each character in space of normal font */
143 for (i
= 0; i
< (256 - 32); i
++) {
144 Text (&rp
, &str
[i
], 1);
145 Move (&rp
, rp
.cp_x
+ (NetBSDwidth
- tf
->tf_XSize
), rp
.cp_y
);
148 Text (&rp
, str
, 256 - 32);
152 printf ("/* Generated automatically by fontdumper.c. *DONT* distribute\n");
153 printf (" this file, it may contain information Copyright by Commodore!\n");
155 printf (" Font: %s/%d\n", ta
.ta_Name
, tf
->tf_YSize
);
158 printf ("unsigned char kernel_font_width = %d;\n", tf
->tf_XSize
);
159 printf ("unsigned char kernel_font_height = %d;\n", tf
->tf_YSize
);
160 printf ("unsigned char kernel_font_baseline = %d;\n", tf
->tf_Baseline
);
161 printf ("short kernel_font_boldsmear = %d;\n", tf
->tf_BoldSmear
);
162 printf ("unsigned char kernel_font_lo = 32;\n");
163 printf ("unsigned char kernel_font_hi = 255;\n\n");
165 printf ("unsigned char kernel_cursor[] = {\n");
166 for (j
= 0; j
< (tf
->tf_YSize
-1); j
++) {
169 printf ("0xff };\n\n");
171 printf ("unsigned char kernel_font[] = {\n");
172 for (i
= 0; i
< 256 - 32; i
++) {
173 printf ("/* %c */", i
+ 32);
174 for (j
= 0; j
< tf
->tf_YSize
; j
++) {
175 printf (" 0x%02x,", pp
[i
+j
*256]);
182 FreeRaster (pp
, 256 * NetBSDwidth
, tf
->tf_YSize
);