1/* $NetBSD: fontdumper.c,v 1.3 1994/10/26 02:06:59 cgd Exp $ */ 2 3/* 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. 7 * 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 10 * updating. 11 * Also the NetBSDwidth value, cursor bits and dumping of font hex values 12 * needs updating. 13 * 14 * Author: Alan Bair 15 * Dated: 11/12/1993 16 * 17 * Added printing of some other useful data for future (and current) expansion. 18 * -ch 19 * Dated: 11/17/1993 20 */ 21 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! */ 27 28#include <exec/types.h> 29#include <exec/memory.h> 30#include <dos/dos.h> 31#include <graphics/gfx.h> 32#include <graphics/rastport.h> 33#include <graphics/text.h> 34#include <libraries/asl.h> 35 36#include <inline/exec.h> 37#include <inline/graphics.h> 38 39#include <stdio.h> 40 41#define NetBSDwidth 8 42 43main(int argc, char *argv[]) 44{ 45 unsigned char str[256]; 46 int i; 47 int j; 48 struct RastPort rp; 49 unsigned char *pp; 50 struct BitMap bm = { 51 256, /* bytes per row */ 52 8, /* rows */ 53 0, /* flags */ 54 1, /* depth */ 55 0, /* pad */ 56 0 /* planes */ 57 }; 58 struct TextAttr ta; 59 struct TextFont *tf; 60 struct FontRequester *fr; 61 struct TagItem frtags[] = { 62 ASL_Hail, (ULONG)"NetBSD font choices", 63 ASL_Width, 640, 64 ASL_Height, 400, 65 ASL_LeftEdge, 10, 66 ASL_TopEdge, 10, 67 ASL_OKText, (ULONG)"Dump", 68 ASL_CancelText, (ULONG)"Cancel", 69 ASL_FontName, (ULONG)"topaz.font", 70 ASL_FontHeight, 8L, 71 ASL_FontStyles, FS_NORMAL, 72 ASL_FuncFlags, FONF_STYLES | FONF_FIXEDWIDTH, 73 TAG_DONE 74 }; 75 76 /* Let the user pick a font to dump */ 77 if (fr = (struct FontRequester *) 78 AllocAslRequest(ASL_FontRequest, frtags)) { 79 if (!AslRequest(fr, NULL)) { 80 FreeAslRequest(fr); 81 fprintf(stderr, "User requested exit\n"); 82 exit (0); 83 } 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; 89 FreeAslRequest(fr); 90 } else { 91 fprintf(stderr, "Can't allocate Font Requestor\n"); 92 exit (1); 93 } 94 95 /* Open the selected font */ 96 tf = (struct TextFont *)OpenDiskFont (&ta); 97 if (! tf) { 98 fprintf (stderr, "Can't open font: %s\n", ta.ta_Name); 99 exit (1); 100 } 101#ifdef DEBUG 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); 106#endif 107 108 /* Check for NetBSD restrictions */ 109 if (tf->tf_Flags & FPF_PROPORTIONAL) { 110 fprintf(stderr, "NetBSD does not support proportional fonts\n"); 111 exit (1); 112 } 113 if (tf->tf_XSize > NetBSDwidth) { 114 fprintf(stderr, "NetBSD does not support fonts wider than %d pixels\n", NetBSDwidth); 115 exit (1); 116 } 117 118 /* Allocate area to render font in */ 119 InitBitMap(&bm, 1, 256 * NetBSDwidth, tf->tf_YSize); 120 InitRastPort (&rp); 121 rp.BitMap = &bm; 122 bm.Planes[0] = pp = AllocRaster (256 * NetBSDwidth, tf->tf_YSize); 123 if (!pp) { 124 fprintf (stderr, "Can't allocate raster!\n"); 125 exit (1); 126 } 127 128 /* Initialize string to be rendered */ 129 for (i = 32; i < 256; i++) { 130 str[i - 32] = i; 131 } 132 133 /* Render string with selected font */ 134 SetFont (&rp, tf); 135 SetSoftStyle(&rp, ta.ta_Style ^ tf->tf_Style, 136 FSF_BOLD | FSF_UNDERLINED | FSF_ITALIC); 137 Move (&rp, 0, tf->tf_Baseline); 138 ClearEOL(&rp); 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); 146 } 147 } else { 148 Text (&rp, str, 256 - 32); 149 } 150 151 /* Dump them.. */ 152 printf ("/* Generated automatically by fontdumper.c. *DONT* distribute\n"); 153 printf (" this file, it may contain information Copyright by Commodore!\n"); 154 printf ("\n"); 155 printf (" Font: %s/%d\n", ta.ta_Name, tf->tf_YSize); 156 printf (" */\n\n"); 157 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"); 164 165 printf ("unsigned char kernel_cursor[] = {\n"); 166 for (j = 0; j < (tf->tf_YSize -1); j++) { 167 printf ("0xff, "); 168 } 169 printf ("0xff };\n\n"); 170 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]); 176 } 177 printf ("\n"); 178 } 179 printf ("};\n"); 180 181 CloseFont (tf); 182 FreeRaster (pp, 256 * NetBSDwidth, tf->tf_YSize); 183 return (0); 184} 185