home *** CD-ROM | disk | FTP | other *** search
/ AMIGA PD 1 / AMIGA-PD-1.iso / NetBSD / Tools / fontdumper.tar.gz / fontdumper.tar / fontdumper.c < prev    next >
C/C++ Source or Header  |  1985-12-12  |  7KB  |  223 lines

  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.  * Compiling GNU: gcc fontdumper.c -o fontdumper -lamy -lauto
  11.  * Compiling SAS: lc fontdumper
  12.  *                blink with fontdumper.lnk
  13.  *                (This produces a bad executable for me, see NOTE in code )
  14.  *
  15.  * Running:   fontdumper >new_kernel_font.c
  16.  *
  17.  * Author: Alan Bair
  18.  * Dated:  11/12/1993
  19.  *
  20.  * Added printing of some other useful data for future (and current) expansion.
  21.  * -ch 
  22.  * Dated:  11/17/1993
  23.  *
  24.  */
  25.  
  26. /* Original code by Markus Wild */
  27. /* This is a *real* hack to dump the topaz80 kernel font. This one is 
  28.    ways nicer than the ugly Mach font, but we'll have to dump it from a
  29.    running system to not run against Commodore copyrights. *NEVER* distribute
  30.    the generated font with BSD, always regenerate! */
  31.  
  32. #include <exec/types.h>
  33. #include <exec/memory.h>
  34. #include <dos/dos.h>
  35. #include <graphics/gfx.h>
  36. #include <graphics/rastport.h>
  37. #include <graphics/text.h>
  38. #include <libraries/asl.h>
  39.  
  40. #ifdef __SASC
  41. #include <proto/exec.h>
  42. #include <proto/graphics.h>
  43. struct Library *AslBase = NULL;
  44. struct Library *DiskFontBase = NULL;
  45. struct Library *GfxBase = NULL;
  46. #else
  47. #include <inline/exec.h>
  48. #include <inline/graphics.h>
  49. #endif
  50.  
  51. #include <stdio.h>
  52.  
  53. #define NetBSDwidth    8
  54.  
  55. main(int argc, char *argv[])
  56. {
  57.     unsigned char str[256];
  58.     int i;
  59.     int j;
  60.     struct RastPort rp;
  61.     unsigned char *pp;
  62.     struct BitMap bm = {
  63.     256,     /* bytes per row */
  64.     8,    /* rows */
  65.     0,    /* flags */
  66.     1,    /* depth */
  67.     0,    /* pad */
  68.     0     /* planes */
  69.     };
  70.     struct TextAttr ta;
  71.     struct TextFont *tf;
  72.     struct FontRequester *fr;
  73.     struct TagItem frtags[] = {
  74.     ASL_Hail, (ULONG)"NetBSD font choices",
  75.     ASL_Width, 640,
  76.     ASL_Height, 400,
  77.     ASL_LeftEdge, 10,
  78.     ASL_TopEdge, 10,
  79.     ASL_OKText, (ULONG)"Dump",
  80.     ASL_CancelText, (ULONG)"Cancel",
  81.     ASL_FontName, (ULONG)"topaz.font",
  82.     ASL_FontHeight, 8L,
  83.     ASL_FontStyles, FS_NORMAL,
  84.     ASL_FuncFlags, FONF_STYLES | FONF_FIXEDWIDTH,
  85.     TAG_DONE
  86.         };
  87.  
  88. #ifdef __SASC
  89.     /* I am ignoring the closing of these libraries in case of errors */
  90.     if ((DiskFontBase = OpenLibrary("diskfont.library", 37L)) == 0) {
  91.     fprintf(stderr, "Can't open diskfont.library\n");
  92.     exit (1);
  93.     }
  94.     if ((GfxBase = OpenLibrary("graphics.library", 37L)) == 0) {
  95.     fprintf(stderr, "Can't open graphics.library\n");
  96.     exit (1);
  97.     }
  98.     if ((AslBase = OpenLibrary("asl.library", 37L)) == 0) {
  99.     fprintf(stderr, "Can't open asl.library\n");
  100.     exit (1);
  101.     }
  102. #endif
  103.  
  104.     /* Let the user pick a font to dump */
  105.     if (fr = (struct FontRequester *)
  106.     AllocAslRequest(ASL_FontRequest, frtags)) {
  107.     if (!AslRequest(fr, NULL)) {
  108.         FreeAslRequest(fr);
  109.         fprintf(stderr, "User requested exit\n");
  110.         exit (0);
  111.     }
  112.     ta.ta_Name = (STRPTR)malloc(strlen(fr->fo_Attr.ta_Name)+1);
  113.     strcpy(ta.ta_Name, fr->fo_Attr.ta_Name);
  114.     ta.ta_YSize = fr->fo_Attr.ta_YSize;
  115.     ta.ta_Style = fr->fo_Attr.ta_Style;
  116.     ta.ta_Flags = fr->fo_Attr.ta_Flags;
  117.     FreeAslRequest(fr);
  118.     } else {
  119.     fprintf(stderr, "Can't allocate Font Requestor\n");
  120.     exit (1);
  121.     }
  122.  
  123.     /* Open the selected font */
  124.     /* SAS/C NOTE: My Amiga hangs executing the next statement.
  125.      * I have tried using Code Probe, but have been unable to figure
  126.      * out what is causing the problem.
  127.      */
  128.     tf = (struct TextFont *)OpenDiskFont (&ta);
  129.     if (! tf) {
  130.     fprintf (stderr, "Can't open font: %s\n", ta.ta_Name);
  131.     exit (1);
  132.     }
  133. #ifdef DEBUG
  134.     fprintf(stderr, "Information on selected font:\n");
  135.     fprintf(stderr, "Name=%s\n", ta.ta_Name);
  136.     fprintf(stderr, "Height=%d tf_Style=%x tf_Flags=%x Width=%d Baseline=%d\n",
  137.         tf->tf_YSize, tf->tf_Style, tf->tf_Flags, tf->tf_XSize, tf->tf_Baseline);
  138. #endif
  139.  
  140.     /* Check for NetBSD restrictions */
  141.     if (tf->tf_Flags & FPF_PROPORTIONAL) {
  142.     fprintf(stderr, "NetBSD does not support proportional fonts\n");
  143.     exit (1);
  144.     }
  145.     if (tf->tf_XSize > NetBSDwidth) {
  146.     fprintf(stderr, "NetBSD does not support fonts wider than %d pixels\n", NetBSDwidth);
  147.     exit (1);
  148.     }
  149.  
  150.     /* Allocate area to render font in */
  151.     InitBitMap(&bm, 1, 256 * NetBSDwidth, tf->tf_YSize);
  152.     InitRastPort (&rp);
  153.     rp.BitMap = &bm;
  154.     bm.Planes[0] = pp = AllocRaster (256 * NetBSDwidth, tf->tf_YSize);
  155.     if (!pp) {
  156.     fprintf (stderr, "Can't allocate raster!\n");
  157.     exit (1);
  158.     }
  159.  
  160.     /* Initialize string to be rendered */
  161.     for (i = 32; i < 256; i++) {
  162.     str[i - 32] = i;
  163.     }
  164.  
  165.     /* Render string with selected font */
  166.     SetFont (&rp, tf);
  167.     SetSoftStyle(&rp, ta.ta_Style ^ tf->tf_Style, (FSF_BOLD | FSF_UNDERLINED | FSF_ITALIC));
  168.     Move (&rp, 0, tf->tf_Baseline);
  169.     ClearEOL(&rp);
  170.     if (tf->tf_XSize != NetBSDwidth) {
  171.     /* Right-justify char in cell */
  172.     Move (&rp, NetBSDwidth - tf->tf_XSize, tf->tf_Baseline);
  173.     /* Narrow font, put each character in space of normal font */
  174.     for (i = 0; i < (256 - 32); i++) {
  175.         Text (&rp, &str[i], 1);
  176.         Move (&rp, rp.cp_x + (NetBSDwidth - tf->tf_XSize), rp.cp_y);
  177.     }
  178.     } else {
  179.     Text (&rp, str, 256 - 32);
  180.     }
  181.   
  182.     /* Dump them.. */
  183.     printf ("/* Generated automatically by fontdumper.c. *DONT* distribute\n");
  184.     printf ("   this file, it may contain information Copyright by Commodore!\n");
  185.     printf ("\n");
  186.     printf ("   Font: %s/%d\n", ta.ta_Name, tf->tf_YSize);
  187.     printf (" */\n\n");
  188.     
  189.     printf ("unsigned char kernel_font_width  = %d;\n", tf->tf_XSize);
  190.     printf ("unsigned char kernel_font_height = %d;\n", tf->tf_YSize);
  191.     printf ("unsigned char kernel_font_baseline = %d;\n", tf->tf_Baseline);
  192.     printf ("short         kernel_font_boldsmear = %d;\n", tf->tf_BoldSmear);
  193.     printf ("unsigned char kernel_font_lo = 32;\n");
  194.     printf ("unsigned char kernel_font_hi = 255;\n\n");
  195.     
  196.     printf ("unsigned char kernel_cursor[] = {\n");
  197.     for (j = 0; j < (tf->tf_YSize -1); j++) {
  198.     printf ("0xff, ");
  199.     }
  200.     printf ("0xff };\n\n");
  201.  
  202.     printf ("unsigned char kernel_font[] = {\n");
  203.     for (i = 0; i < 256 - 32; i++) {
  204.     printf ("/* %c */", i + 32);
  205.     for (j = 0; j < tf->tf_YSize; j++) {
  206.         printf (" 0x%02x,", pp[i+j*256]);
  207.         }
  208.     printf ("\n");
  209.     }
  210.     printf ("};\n");
  211.     
  212.     CloseFont (tf);
  213.     FreeRaster (pp, 256 * NetBSDwidth, tf->tf_YSize);
  214. #ifdef __SASC
  215.     /* I am ignoring the closing of these libraries in case of errors */
  216.     CloseLibrary(AslBase);
  217.     CloseLibrary(GfxBase);
  218.     CloseLibrary(DiskFontBase);
  219. #endif
  220.  
  221.     return (0);
  222. }
  223.