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