#include <exec/types.h>
#include <exec/memory.h>
#include <dos/dos.h>
#include <graphics/gfx.h>
#include <graphics/rastport.h>
#include <graphics/text.h>
#include <libraries/asl.h>
#include <inline/exec.h>
#include <inline/graphics.h>
#include <stdio.h>
#define NetBSDwidth 8
main(int argc, char *argv[])
{
unsigned char str[256];
int i;
int j;
struct RastPort rp;
unsigned char *pp;
struct BitMap bm = {
256,
8,
0,
1,
0,
0
};
struct TextAttr ta;
struct TextFont *tf;
struct FontRequester *fr;
struct TagItem frtags[] = {
ASL_Hail, (ULONG)"NetBSD font choices",
ASL_Width, 640,
ASL_Height, 400,
ASL_LeftEdge, 10,
ASL_TopEdge, 10,
ASL_OKText, (ULONG)"Dump",
ASL_CancelText, (ULONG)"Cancel",
ASL_FontName, (ULONG)"topaz.font",
ASL_FontHeight, 8L,
ASL_FontStyles, FS_NORMAL,
ASL_FuncFlags, FONF_STYLES | FONF_FIXEDWIDTH,
TAG_DONE
};
if (fr = (struct FontRequester *)
AllocAslRequest(ASL_FontRequest, frtags)) {
if (!AslRequest(fr, NULL)) {
FreeAslRequest(fr);
fprintf(stderr, "User requested exit\n");
exit (0);
}
ta.ta_Name = (STRPTR)malloc(strlen(fr->fo_Attr.ta_Name));
strcpy(ta.ta_Name, fr->fo_Attr.ta_Name);
ta.ta_YSize = fr->fo_Attr.ta_YSize;
ta.ta_Style = fr->fo_Attr.ta_Style;
ta.ta_Flags = fr->fo_Attr.ta_Flags;
FreeAslRequest(fr);
} else {
fprintf(stderr, "Can't allocate Font Requestor\n");
exit (1);
}
tf = (struct TextFont *)OpenDiskFont (&ta);
if (! tf) {
fprintf (stderr, "Can't open font: %s\n", ta.ta_Name);
exit (1);
}
#ifdef DEBUG
fprintf(stderr, "Information on selected font:\n");
fprintf(stderr, "Name=%s\n", ta.ta_Name);
fprintf(stderr, "Height=%d tf_Style=%x tf_Flags=%x Width=%d Baseline=%d\n",
tf->tf_YSize, tf->tf_Style, tf->tf_Flags, tf->tf_XSize, tf->tf_Baseline);
#endif
if (tf->tf_Flags & FPF_PROPORTIONAL) {
fprintf(stderr, "NetBSD does not support proportional fonts\n");
exit (1);
}
if (tf->tf_XSize > NetBSDwidth) {
fprintf(stderr, "NetBSD does not support fonts wider than %d pixels\n", NetBSDwidth);
exit (1);
}
InitBitMap(&bm, 1, 256 * NetBSDwidth, tf->tf_YSize);
InitRastPort (&rp);
rp.BitMap = &bm;
bm.Planes[0] = pp = AllocRaster (256 * NetBSDwidth, tf->tf_YSize);
if (!pp) {
fprintf (stderr, "Can't allocate raster!\n");
exit (1);
}
for (i = 32; i < 256; i++) {
str[i - 32] = i;
}
SetFont (&rp, tf);
SetSoftStyle(&rp, ta.ta_Style ^ tf->tf_Style,
FSF_BOLD | FSF_UNDERLINED | FSF_ITALIC);
Move (&rp, 0, tf->tf_Baseline);
ClearEOL(&rp);
if (tf->tf_XSize != NetBSDwidth) {
Move (&rp, NetBSDwidth - tf->tf_XSize, tf->tf_Baseline);
for (i = 0; i < (256 - 32); i++) {
Text (&rp, &str[i], 1);
Move (&rp, rp.cp_x + (NetBSDwidth - tf->tf_XSize), rp.cp_y);
}
} else {
Text (&rp, str, 256 - 32);
}
printf ("/* Generated automatically by fontdumper.c. *DONT* distribute\n");
printf (" this file, it may contain information Copyright by Commodore!\n");
printf ("\n");
printf (" Font: %s/%d\n", ta.ta_Name, tf->tf_YSize);
printf (" */\n\n");
printf ("unsigned char kernel_font_width = %d;\n", tf->tf_XSize);
printf ("unsigned char kernel_font_height = %d;\n", tf->tf_YSize);
printf ("unsigned char kernel_font_baseline = %d;\n", tf->tf_Baseline);
printf ("short kernel_font_boldsmear = %d;\n", tf->tf_BoldSmear);
printf ("unsigned char kernel_font_lo = 32;\n");
printf ("unsigned char kernel_font_hi = 255;\n\n");
printf ("unsigned char kernel_cursor[] = {\n");
for (j = 0; j < (tf->tf_YSize -1); j++) {
printf ("0xff, ");
}
printf ("0xff };\n\n");
printf ("unsigned char kernel_font[] = {\n");
for (i = 0; i < 256 - 32; i++) {
printf ("/* %c */", i + 32);
for (j = 0; j < tf->tf_YSize; j++) {
printf (" 0x%02x,", pp[i+j*256]);
}
printf ("\n");
}
printf ("};\n");
CloseFont (tf);
FreeRaster (pp, 256 * NetBSDwidth, tf->tf_YSize);
return (0);
}