home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 2 / fishmore-publicdomainlibraryvol.ii1991xetec.iso / dirs / fontconvert_393.lzh / FontConvert / FontConvert.c < prev    next >
C/C++ Source or Header  |  1990-10-28  |  19KB  |  820 lines

  1. /* $Revision Header * Header built automatically - do not edit! *************
  2.  *
  3.  *    (C) Copyright 1990 by MXM
  4.  *
  5.  *    Name .....: FontConvert.c
  6.  *    Created ..: Tuesday 25-Sep-90 20:43
  7.  *    Revision .: 0
  8.  *
  9.  *    Date            Author          Comment
  10.  *    =========       ========        ====================
  11.  *    25-Sep-90       Olsen           Created this file!
  12.  *
  13.  * $Revision Header ********************************************************/
  14.  
  15.     /* Global and shared library identifiers. */
  16.  
  17. extern struct ExecBase    *SysBase;
  18. struct ReqLib        *ReqBase;
  19. struct IntuitionBase    *IntuitionBase;
  20. struct GfxBase        *GfxBase;
  21. struct Library        *DiskfontBase;
  22. struct Library        *LayersBase;
  23.  
  24.     /* Process and associated data. */
  25.  
  26. struct Process        *ThisProcess;
  27. APTR             SavePtr;
  28.  
  29.     /* Data associated with the font conversion. */
  30.  
  31. struct TextFont        *DiskFont;
  32. struct BitMap         RasterBitMap;
  33. struct RastPort         RasterPort;
  34.  
  35. struct BitMap         TextBitMap;
  36. struct Layer_Info    *TextLayerInfo;
  37. struct Layer        *TextLayer;
  38.  
  39.     /* Global output file. */
  40.  
  41. BPTR             GlobalOut;
  42.  
  43.     /* Window data. */
  44.  
  45. struct Window        *Window;
  46. struct RastPort        *RPort;
  47. struct IntuiMessage    *Massage;
  48. ULONG             Class,Code,GadgetID;
  49.  
  50.     /* The font requester. */
  51.  
  52. struct FileRequester     FontFileReq;
  53. char             FontName[FCHARS],DirectoryName[DSIZE],Buffer[FCHARS + DSIZE + 2];
  54.  
  55.     /* Printer IO data. */
  56.  
  57. struct IOStdReq        *PrintRequest;
  58. struct MsgPort        *PrintPort;
  59.  
  60.     /* Capture file requester. */
  61.  
  62. struct FileRequester     CaptureFileReq;
  63. char             CaptureName[FCHARS],CaptureDirName[DSIZE],CaptureBuffer[FCHARS + DSIZE + 2];
  64.  
  65.     /* Seven select buttons. */
  66.  
  67. struct TwoImageGadget     Buttons[7];
  68.  
  69.     /* At lease one of these bytes is set TRUE if the character
  70.      * is contained in the font set.
  71.      */
  72.  
  73. BYTE FontFlag[256];
  74.  
  75.     /* Which character belongs to a printer character (dreaded
  76.      * IBM font).
  77.      */
  78.  
  79. UBYTE CharTable[217] =
  80. {
  81.      32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
  82.      48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
  83.      64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
  84.      80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
  85.      96, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111,
  86.     112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,  0,
  87.     199,252,233,226,228,231,229,  0,234,235,232,239,238,236,196,197,
  88.     201,230,198,244,246,242,251,249,255,214,220,162,163,165,  0,  0,
  89.     225,237,243,250,241,209,170,186,191,  0,172,189,188,161,171,187,
  90.       0,127,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
  91.       0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
  92.       0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
  93.       0,223,  0,  0,  0,  0,181,  0,  0,  0,  0,  0,  0,  0,  0,  0,
  94.       0,  0,  0,  0,  0,  0,  0,  0,176
  95. };
  96.  
  97.     /* Select button image data. */
  98.  
  99. USHORT ButtonData[32] =
  100. {
  101.     0xFFFE,0xC006,0xC006,0xC006,0xC006,0xC006,0xFFFE,0x0000,
  102.     0xFFFE,0xC006,0xC006,0xC006,0xC006,0xC006,0xFFFE,0x0000,
  103.  
  104.     0xFFFE,0xC006,0xCFE6,0xCFE6,0xCFE6,0xC006,0xFFFE,0x0000,
  105.     0xFFFE,0xC006,0xCFE6,0xCFE6,0xCFE6,0xC006,0xFFFE,0x0000
  106. };
  107.  
  108.     /* The texts for the seven buttons. */
  109.  
  110. char *ButtonText[7] =
  111. {
  112.     "Make the font underlined",
  113.     "Make the font bold",
  114.     "Make the font italicized",
  115.     "Convert 256 characters",
  116.     "Capture to file",
  117.     "Send font to printer",
  118.     "Start Conversion"
  119. };
  120.  
  121.     /* An empty disk attribute. */
  122.  
  123. struct TextAttr DiskAttribute =
  124. {
  125.     (STRPTR)NULL,
  126.     8,
  127.     FS_NORMAL,
  128.     FPF_DISKFONT
  129. };
  130.  
  131.     /* Our window. */
  132.  
  133. struct NewWindow NewWindow =
  134. {
  135.     0,11,
  136.     224,88,
  137.     -1,-1,
  138.     CLOSEWINDOW | GADGETUP | MOUSEBUTTONS,
  139.     ACTIVATE | RMBTRAP | WINDOWDEPTH | WINDOWDRAG | WINDOWCLOSE,
  140.     (struct Gadget *)NULL,
  141.     (struct Image *)NULL,
  142.     (STRPTR)"FontConvert 1.0",
  143.     (struct Screen *)NULL,
  144.     (struct BitMap *)NULL,
  145.     ~0,~0,
  146.     ~0,~0,
  147.     WBENCHSCREEN
  148. };
  149.  
  150.     /* The wait pointer. */
  151.  
  152. USHORT ElecArtsWaitPointer[(22 + 2) * 2] =
  153. {
  154.     0x0000,0x0000,
  155.  
  156.     0x6700,0xC000,
  157.     0xCFA0,0xC700,
  158.     0xBFF0,0x0FA0,
  159.     0x70F8,0x3FF0,
  160.     0x7DFC,0x3FF8,
  161.     0xFBFC,0x7FF8,
  162.     0x70FC,0x3FF8,
  163.     0x7FFE,0x3FFC,
  164.     0x7F0E,0x3FFC,
  165.     0x3FDF,0x1FFE,
  166.     0x7FBE,0x3FFC,
  167.     0x3F0E,0x1FFC,
  168.     0x1FFC,0x07F8,
  169.     0x07F8,0x01E0,
  170.     0x01E0,0x0080,
  171.     0x07C0,0x0340,
  172.     0x0FE0,0x07C0,
  173.     0x0740,0x0200,
  174.     0x0000,0x0000,
  175.     0x0070,0x0020,
  176.     0x0078,0x0038,
  177.     0x0038,0x0010,
  178.  
  179.     0x0000,0x0000
  180. };
  181.  
  182.     /* Use this macro to attach the sprite pointer to the
  183.      * window.
  184.      */
  185.  
  186. #define SetWait(Window) SetPointer(Window,ElecArtsWaitPointer,22,16,0,0)
  187.  
  188.     /* Calculate the amount of bytes needed to represent a single
  189.      * display line.
  190.      */
  191.  
  192. #define byte(Width) (((Width + 15) >> 4) << 1)
  193.  
  194.     /* CloseAll():
  195.      *
  196.      *    Closes devices and libraries and locks the shop.
  197.      */
  198.  
  199. VOID
  200. CloseAll(BYTE ReturnCode)
  201. {
  202.     if(PrintRequest)
  203.     {
  204.         if(PrintRequest -> io_Device)
  205.             CloseDevice(PrintRequest);
  206.  
  207.         DeleteStdIO(PrintRequest);
  208.     }
  209.  
  210.     if(PrintPort)
  211.         DeletePort(PrintPort);
  212.  
  213.     if(RasterBitMap . Planes[0])
  214.         FreeMem(RasterBitMap . Planes[0],byte(24) * 36);
  215.  
  216.     if(DiskFont)
  217.         CloseFont(DiskFont);
  218.  
  219.     if(Window)
  220.     {
  221.         ThisProcess -> pr_WindowPtr = SavePtr;
  222.  
  223.         CloseWindow(Window);
  224.     }
  225.  
  226.     if(DiskfontBase)
  227.         CloseLibrary(DiskfontBase);
  228.  
  229.     if(LayersBase)
  230.         CloseLibrary(LayersBase);
  231.  
  232.     if(ReqBase)
  233.     {
  234.         PurgeFiles(&FontFileReq);
  235.         PurgeFiles(&CaptureFileReq);
  236.  
  237.         CloseLibrary(ReqBase);
  238.     }
  239.  
  240.     exit(ReturnCode);
  241. }
  242.  
  243.     /* OpenAll():
  244.      *
  245.      *    Opens libraries, devices, the window, the tin can,
  246.      *    the door and various assorted items.
  247.      */
  248.  
  249. VOID
  250. OpenAll()
  251. {
  252.     SHORT i;
  253.  
  254.     if(!(ReqBase = (struct ReqLib *)OpenLibrary("req.library",0)))
  255.         CloseAll(RETURN_FAIL + 0);
  256.  
  257.     if(!(LayersBase = (struct Library *)OpenLibrary("layers.library",0)))
  258.     {
  259.         SimpleRequest("Couldn't open \"layers.library\"!");
  260.         CloseAll(RETURN_FAIL + 1);
  261.     }
  262.  
  263.     if(!(DiskfontBase = (struct Library *)OpenLibrary("diskfont.library",34)))
  264.     {
  265.         SimpleRequest("Couldn't open \"diskfont.library\" (at least 1.3 required)!");
  266.         CloseAll(RETURN_FAIL + 2);
  267.     }
  268.  
  269.     IntuitionBase    = (struct IntuitionBase *)ReqBase -> IntuiLib;
  270.     GfxBase        = (struct GfxBase *)ReqBase -> GfxLib;
  271.  
  272.     Center(&NewWindow,NewWindow . Width >> 1,NewWindow . Height >> 1);
  273.  
  274.     if(!(Window = (struct Window *)OpenWindow(&NewWindow)))
  275.     {
  276.         SimpleRequest("Couldn't open window!");
  277.         CloseAll(RETURN_FAIL + 3);
  278.     }
  279.  
  280.     RPort = Window -> RPort;
  281.  
  282.     SetAPen(RPort,3);
  283.     SetDrMd(RPort,JAM2);
  284.  
  285.     DrawBox(RPort,4,11,NewWindow . Width - 5,11 + 10);
  286.  
  287.     SetAPen(RPort,1);
  288.  
  289.         /* Dynamically create the gadget interface. */
  290.  
  291.     for(i = 0 ; i < 7 ; i++)
  292.     {
  293.         MakeButton(&Buttons[i],&ButtonData[0],&ButtonData[16],16,8,12);
  294.  
  295.         Buttons[i] . Gadget . LeftEdge    = 4;
  296.         Buttons[i] . Gadget . TopEdge    = 12 + 11 + 8 * i;
  297.  
  298.         if(i != 6)
  299.             Buttons[i] . Gadget . Activation |= TOGGLESELECT;
  300.  
  301.         if(i > 3)
  302.             Buttons[i] . Gadget . TopEdge += 8;
  303.  
  304.         AddGadget(Window,&Buttons[i] . Gadget,-1);
  305.  
  306.         Move(RPort,Buttons[i] . Gadget . LeftEdge + 24,Buttons[i] . Gadget . TopEdge + 6);
  307.         Text(RPort,ButtonText[i],strlen(ButtonText[i]));
  308.  
  309.         Buttons[i] . Gadget . GadgetID = i;
  310.     }
  311.  
  312.     Buttons[5] . Gadget . Flags |= SELECTED;
  313.  
  314.     RefreshGadgets(Window -> FirstGadget,Window,NULL);
  315.  
  316.     ThisProcess = (struct Process *)SysBase -> ThisTask;
  317.  
  318.     SavePtr = ThisProcess -> pr_WindowPtr;
  319.  
  320.     ThisProcess -> pr_WindowPtr = (APTR)Window;
  321.  
  322.  
  323.     InitRastPort(&RasterPort);
  324.  
  325.     RasterPort . BitMap = &RasterBitMap;
  326.  
  327.     InitBitMap(&RasterBitMap,1,24,36);
  328.  
  329.     if(!(RasterBitMap . Planes[0] = (PLANEPTR)AllocMem(byte(24) * 36,MEMF_CHIP)))
  330.     {
  331.         SimpleRequest("Not enough memory for character matrix!");
  332.         CloseAll(RETURN_FAIL + 4);
  333.     }
  334.  
  335.     if(!(PrintPort = (struct MsgPort *)CreatePort(NULL,0)))
  336.     {
  337.         SimpleRequest("Printer I/O failure!");
  338.         CloseAll(RETURN_FAIL + 5);
  339.     }
  340.  
  341.     if(!(PrintRequest = (struct IOStdReq *)CreateStdIO(PrintPort)))
  342.     {
  343.         SimpleRequest("Printer I/O failure!");
  344.         CloseAll(RETURN_FAIL + 6);
  345.     }
  346.  
  347.     if(OpenDevice("printer.device",0,PrintRequest,0))
  348.     {
  349.         SimpleRequest("Couldn't open \"printer.device\"\n(printer already in use?)!");
  350.         CloseAll(RETURN_FAIL + 7);
  351.     }
  352.  
  353.     FontFileReq . PathName            = Buffer;
  354.     FontFileReq . Title            = "Load a disk font";
  355.     FontFileReq . fontnamescolor        = 3;
  356.     FontFileReq . fontsizescolor        = 3;
  357.     FontFileReq . Window            = Window;
  358.     FontFileReq . Dir            = DirectoryName;
  359.     FontFileReq . File            = FontName;
  360.     FontFileReq . Flags            = FRQCACHINGM | FRQINFOGADGETM | FRQNOHALFCACHEM | FRQGETFONTSM;
  361.     FontFileReq . blockcolor        = 1;
  362.  
  363.     CaptureFileReq . PathName        = CaptureBuffer;
  364.     CaptureFileReq . Title            = "Select font capture file";
  365.     CaptureFileReq . Window            = Window;
  366.     CaptureFileReq . dirnamescolor        = 3;
  367.     CaptureFileReq . devicenamescolor    = 3;
  368.     CaptureFileReq . Dir            = CaptureDirName;
  369.     CaptureFileReq . File            = CaptureName;
  370.     CaptureFileReq . Flags            = FRQCACHINGM | FRQINFOGADGETM | FRQNOHALFCACHEM | FRQSAVINGM | FRQCACHEPURGEM;
  371.     CaptureFileReq . blockcolor        = 3;
  372.  
  373.     strcpy(DirectoryName,"FONTS:");
  374.  
  375.     DiskAttribute . ta_Name    = (UBYTE *)Buffer;
  376.  
  377.     SetAPen(&RasterPort,1);
  378.     SetBPen(&RasterPort,0);
  379.     SetDrMd(&RasterPort,JAM1);
  380. }
  381.  
  382.     /* PrintWrite():
  383.      *
  384.      *    Send a string to the printer, do the necessary data
  385.      *    conversion on the way.
  386.      */
  387.  
  388. VOID
  389. PrintWrite(char *String)
  390. {
  391.     PrintRequest -> io_Command    = CMD_WRITE;
  392.     PrintRequest -> io_Data        = String;
  393.     PrintRequest -> io_Length    = -1;
  394.  
  395.     DoIO(PrintRequest);
  396. }
  397.  
  398.     /* PrintRawWrite():
  399.      *
  400.      *    Send a string to the printer, don't convert
  401.      *    anything!
  402.      */
  403.  
  404. VOID
  405. PrintRawWrite(APTR String,SHORT Length)
  406. {
  407.         /* Are we to send the string to the capture file? */
  408.  
  409.     if(Buttons[4] . Gadget . Flags & SELECTED)
  410.     {
  411.         if(GlobalOut)
  412.         {
  413.             if(Write(GlobalOut,String,Length) != Length)
  414.             {
  415.                 SimpleRequest("Error writing to capture file!");
  416.  
  417.                 Close(GlobalOut);
  418.  
  419.                 GlobalOut = NULL;
  420.  
  421.                 DeleteFile(CaptureBuffer);
  422.             }
  423.         }
  424.     }
  425.  
  426.     if(Buttons[5] . Gadget . Flags & SELECTED)
  427.     {
  428.         PrintRequest -> io_Command    = PRD_RAWWRITE;
  429.         PrintRequest -> io_Data        = String;
  430.         PrintRequest -> io_Length    = Length;
  431.  
  432.         DoIO(PrintRequest);
  433.     }
  434. }
  435.  
  436. VOID _wb_parse(VOID) {}
  437. VOID _cli_parse(VOID) {}
  438.  
  439.     /* main():
  440.      *
  441.      *    This follows one of the largest main routines ever!
  442.      */
  443.  
  444. void
  445. main()
  446. {
  447.     SHORT     ReadX,ReadY,WriteX,WriteY,AspectRatio,MaxWidth,i;
  448.     char     TempString[20];
  449.     UBYTE     Shuttle[2];
  450.     UBYTE    *Bits,Data[3];
  451.  
  452.     OpenAll();
  453.  
  454.         /* Some more setups. */
  455.  
  456.     Shuttle[1] = 0;
  457.  
  458.     Move(RPort,(Window -> Width >> 1) - 8 * (3),11 + 2 + 6);
  459.     Text(RPort,"Ready.",6);
  460.  
  461.     FOREVER
  462.     {
  463.         WaitPort(Window -> UserPort);
  464.  
  465.         while(Massage = (struct IntuiMessage *)GetMsg(Window -> UserPort))
  466.         {
  467.             Class        = Massage -> Class;
  468.             Code        = Massage -> Code;
  469.             GadgetID    = ((struct Gadget *)Massage -> IAddress) -> GadgetID;
  470.  
  471.             ReplyMsg(Massage);
  472.  
  473.                 /* User made the mistake to press the
  474.                  * right mouse button!
  475.                  */
  476.  
  477.             if(Class == MOUSEBUTTONS && Code == MENUUP)
  478.             {
  479.                 SimpleRequest("            FontConvert 1.0\n\n\
  480.        (c) Copyright 1990 by MXM,\n\
  481.           all rights reserved.\n\n\
  482. This program is SHARE-WARE.  If you like\n\
  483. and  use  it  frequently,  please send a\n\
  484. contribution  of  at  least 10$ US or DM\n\
  485. 15,- to:\n\n\
  486.            Olaf Barthel, MXM\n\
  487.            Brabeckstrasse 35\n\
  488.            D-3000 Hannover 71\n\n\
  489.       Federal Republic of Germany\n");
  490.  
  491.                 continue;
  492.             }
  493.  
  494.                 /* Close the window and terminate the
  495.                  * program?
  496.                  */
  497.  
  498.             if(Class == CLOSEWINDOW)
  499.             {
  500.                 if(TwoGadRequest("Really quit FontConvert 1.0?"))
  501.                 {
  502.                     ClearPointer(Window);
  503.                     CloseAll(RETURN_OK);
  504.                 }
  505.             }
  506.  
  507.                 /* One of those gadgets has been
  508.                  * selected.
  509.                  */
  510.  
  511.             if(Class == GADGETUP)
  512.             {
  513.                     /* Capture the printer data
  514.                      * to a disk file?
  515.                      */
  516.  
  517.                 if(GadgetID == 4)
  518.                 {
  519.                     if(Buttons[4] . Gadget . Flags & SELECTED)
  520.                     {
  521.                         if(FileRequester(&CaptureFileReq))
  522.                             continue;
  523.                     }
  524.  
  525.                     Buttons[4] . Gadget . Flags &= ~SELECTED;
  526.  
  527.                     RefreshGadgets(&Buttons[4] . Gadget,Window,NULL);
  528.                 }
  529.  
  530.                     /* Start the font conversion? */
  531.  
  532.                 if(GadgetID == 6)
  533.                 {
  534.                     if(!(Buttons[4] . Gadget . Flags & SELECTED) && !(Buttons[5] . Gadget . Flags & SELECTED))
  535.                     {
  536.                         SimpleRequest("Font must be sent to a file or\nto the printer!");
  537.                         continue;
  538.                     }
  539.  
  540.                         /* Turn the window off. */
  541.  
  542.                     SetWait(Window);
  543.  
  544.                     for(i = 0 ; i < 7 ; i++)
  545.                         OffGadget(&Buttons[i] . Gadget,Window,NULL);
  546.  
  547.                         /* Did we get a font? */
  548.  
  549.                     if(FileRequester(&FontFileReq))
  550.                     {
  551.                             /* Fill in name and size. */
  552.  
  553.                         DiskAttribute . ta_YSize = FontFileReq . FontYSize;
  554.                         DiskAttribute . ta_Style = FontFileReq . FontStyle;
  555.  
  556.                             /* Open the font. */
  557.  
  558.                         if(!(DiskFont = (struct TextFont *)OpenDiskFont(&DiskAttribute)))
  559.                             SimpleRequest("Couldn't load font \"%s/%ld\"!",DiskAttribute . ta_Name,DiskAttribute . ta_YSize);
  560.                         else
  561.                         {
  562.                             SHORT i,j,CharSpace,Style = 0;
  563.  
  564.                                 /* Erase the message window. */
  565.  
  566.                             SetAPen(RPort,0);
  567.                             RectFill(RPort,4 + 1,11 + 1,NewWindow . Width - 5 - 1,11 + 10 - 1);
  568.                             SetAPen(RPort,1);
  569.  
  570.                                 /* Open the capture file? */
  571.  
  572.                             if(Buttons[4] . Gadget . Flags & SELECTED)
  573.                             {
  574.                                 if(!(GlobalOut = Open(CaptureBuffer,MODE_NEWFILE)))
  575.                                 {
  576.                                     if(!TwoGadRequest("Couldn't open capture file! Do you want\nto continue?"))
  577.                                         continue;
  578.                                 }
  579.                             }
  580.  
  581.                                 /* Clear the font flags. */
  582.  
  583.                             for(i = 0 ; i < 256 ; i++)
  584.                                 FontFlag[i] = FALSE;
  585.  
  586.                                 /* Clear the printer font raster. */
  587.  
  588.                             SetFont(&RasterPort,DiskFont);
  589.  
  590.                                 /* Set the approriate style bits. */
  591.  
  592.                             if(Buttons[0] . Gadget . Flags & SELECTED)
  593.                                 Style |= FSF_UNDERLINED;
  594.  
  595.                             if(Buttons[1] . Gadget . Flags & SELECTED)
  596.                                 Style |= FSF_BOLD;
  597.  
  598.                             if(Buttons[2] . Gadget . Flags & SELECTED)
  599.                                 Style |= FSF_ITALIC;
  600.  
  601.                             SetSoftStyle(&RasterPort,Style,~0);
  602.  
  603.                                 /* Fill in the font flags and determine the
  604.                                  * width of each character.
  605.                                  */
  606.  
  607.                             for(i = DiskFont -> tf_LoChar, MaxWidth = 0 ; i <= DiskFont -> tf_HiChar ; i++)
  608.                             {
  609.                                 Shuttle[0] = i;
  610.  
  611.                                 if((CharSpace = TextLength(&RasterPort,(char *)Shuttle,1)) > MaxWidth)
  612.                                     MaxWidth = CharSpace;
  613.  
  614.                                 if(CharSpace > 0)
  615.                                     FontFlag[i] = TRUE;
  616.                             }
  617.  
  618.                                 /* Rescale the font height until it fits into
  619.                                  * the raster.
  620.                                  */
  621.  
  622.                             AspectRatio = 24;
  623.  
  624.                             while((AspectRatio * MaxWidth) / DiskFont -> tf_YSize > 36)
  625.                                 AspectRatio--;
  626.  
  627.                                 /* Initialize the dummy raster port. */
  628.  
  629.                             InitBitMap(&TextBitMap,1,MaxWidth,DiskFont -> tf_YSize);
  630.  
  631.                             if(TextBitMap . Planes[0] = AllocMem(byte(MaxWidth) * DiskFont -> tf_YSize,MEMF_CHIP | MEMF_PUBLIC))
  632.                             {
  633.                                 if(TextLayerInfo = (struct Layer_Info *)NewLayerInfo())
  634.                                 {
  635.                                     if(TextLayer = (struct Layer *)CreateBehindLayer(TextLayerInfo,&TextBitMap,0,0,MaxWidth - 1,DiskFont -> tf_YSize - 1,LAYERSIMPLE,NULL))
  636.                                     {
  637.                                         SHORT LastChar;
  638.  
  639.                                             /* Setup the necessary things to
  640.                                              * convert the font.
  641.                                              */
  642.  
  643.                                         SetAPen(TextLayer -> rp,1);
  644.                                         SetBPen(TextLayer -> rp,0);
  645.                                         SetDrMd(TextLayer -> rp,JAM2);
  646.  
  647.                                         SetFont(TextLayer -> rp,DiskFont);
  648.  
  649.                                         SetSoftStyle(TextLayer -> rp,Style,~0);
  650.  
  651.                                             /* Are we to convert the whole graphics
  652.                                              * character set?
  653.                                              */
  654.  
  655.                                         if(Buttons[3] . Gadget . Flags & SELECTED)
  656.                                         {
  657.                                             LastChar = 217;
  658.                                             PrintRawWrite("\33@\33!\2\33:\0\0\0\33&\0\40\331",15);
  659.                                         }
  660.                                         else
  661.                                         {
  662.                                             LastChar = 95;
  663.                                             PrintRawWrite("\33@\33!\2\33:\0\0\0\33&\0\40\176",15);
  664.                                         }
  665.  
  666.                                             /* Go into conversion loop... */
  667.  
  668.                                         for(i = 0 ; i < LastChar ; i++)
  669.                                         {
  670.                                                 /* Empy character? Send a row of blanks. */
  671.  
  672.                                             if(!CharTable[i] || !FontFlag[CharTable[i]])
  673.                                             {
  674.                                                 PrintRawWrite("\0\1\0\0\0\0",6);
  675.                                                 continue;
  676.                                             }
  677.  
  678.                                                 /* Right mouse button pressed? */
  679.  
  680.                                             if(Massage = (struct IntuiMessage *)GetMsg(Window -> UserPort))
  681.                                             {
  682.                                                 Class    = Massage -> Class;
  683.                                                 Code    = Massage -> Code;
  684.  
  685.                                                 ReplyMsg((struct Message *)Massage);
  686.  
  687.                                                 if(Class == MOUSEBUTTONS && Code == MENUUP)
  688.                                                 {
  689.                                                     if(TwoGadRequest("Really stop font conversion?"))
  690.                                                     {
  691.                                                             /* Send blanks for the following
  692.                                                              * characters and reset the printer.
  693.                                                              */
  694.  
  695.                                                         for(j = i ; j < LastChar ; j++)
  696.                                                             PrintRawWrite("\0\1\0\0\0\0",6);
  697.  
  698.                                                         PrintRawWrite("\33@",2);
  699.                                                         break;
  700.                                                     }
  701.                                                 }
  702.                                             }
  703.  
  704.                                             Shuttle[0] = CharTable[i];
  705.  
  706.                                             CharSpace = TextLength(TextLayer -> rp,(char *)Shuttle,1);
  707.  
  708.                                                 /* Clear the font raster port and
  709.                                                  * draw the character.
  710.                                                  */
  711.  
  712.                                             SetRast(TextLayer -> rp,0);
  713.                                             Move(TextLayer -> rp,0,DiskFont -> tf_Baseline);
  714.                                             Text(TextLayer -> rp,(char *)Shuttle,1);
  715.  
  716.                                                 /* Say where we are... */
  717.  
  718.                                             Format(TempString,"%03ld '%lc' %2ld × %2ld",Shuttle[0],Shuttle[0],(AspectRatio * CharSpace) / DiskFont -> tf_YSize,AspectRatio);
  719.  
  720.                                             Move(RPort,(Window -> Width >> 1) - 8 * (7) + 4,11 + 2 + 6);
  721.                                             Text(RPort,TempString,15);
  722.  
  723.                                             SetRast(&RasterPort,0);
  724.  
  725.                                                 /* Scan the character line by line including
  726.                                                  * rescaling.
  727.                                                  */
  728.  
  729.                                             for(ReadY = WriteY = 0 ; ReadY < DiskFont -> tf_YSize ; ReadY = ((++WriteY) * DiskFont -> tf_YSize) / AspectRatio)
  730.                                             {
  731.                                                 for(ReadX = WriteX = 0 ; ReadX < CharSpace ; ReadX = ((++WriteX) * DiskFont -> tf_YSize) / AspectRatio)
  732.                                                 {
  733.                                                     if(ReadPixel(TextLayer -> rp,ReadX,ReadY))
  734.                                                         WritePixel(&RasterPort,WriteY,WriteX);
  735.                                                 }
  736.                                             }
  737.  
  738.                                                 /* Say how wide the character is. */
  739.  
  740.                                             Data[0] = Data[2] = 0;
  741.                                             Data[1] = (AspectRatio * CharSpace) / DiskFont -> tf_YSize;
  742.  
  743.                                             PrintRawWrite(Data,3);
  744.  
  745.                                                 /* Send the character bits. */
  746.  
  747.                                             for(j = 0 ; j < Data[1] ; j++)
  748.                                             {
  749.                                                 Bits = (UBYTE *)((ULONG)RasterBitMap . Planes[0] + RasterBitMap . BytesPerRow * j);
  750.  
  751.                                                 PrintRawWrite(Bits,3);
  752.                                             }
  753.                                         }
  754.  
  755.                                             /* Turn on the use font. */
  756.  
  757.                                         PrintRawWrite("\33%1",3);
  758.  
  759.                                             /* Say that we are done. */
  760.  
  761.                                         Move(RPort,(Window -> Width >> 1) - 8 * (12),11 + 2 + 6);
  762.                                         Text(RPort,"Font conversion finished",24);
  763.  
  764.                                             /* Test the printer font? */
  765.  
  766.                                         if(Buttons[5] . Gadget . Flags & SELECTED)
  767.                                         {
  768.                                             if(TwoGadRequest("Font conversion completed.\nTest new printer font?"))
  769.                                             {
  770.                                                 PrintWrite("\nFont \"");
  771.                                                 PrintWrite(Buffer);
  772.                                                 PrintWrite("\":\n");
  773.  
  774.                                                 PrintWrite("!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\n\n");
  775.                                             }
  776.                                         }
  777.  
  778.                                             /* Clean up the font stuff... */
  779.  
  780.                                         DeleteLayer(TextLayerInfo,TextLayer);
  781.                                     }
  782.                                     else
  783.                                         SimpleRequest("Not enough memory for font work area!");
  784.  
  785.                                     DisposeLayerInfo(TextLayerInfo);
  786.                                 }
  787.                                 else
  788.                                     SimpleRequest("Not enough memory for font work area!");
  789.  
  790.                                 FreeMem(TextBitMap . Planes[0],byte(MaxWidth) * DiskFont -> tf_YSize);
  791.                             }
  792.                             else
  793.                                 SimpleRequest("Not enough memory for font work area!");
  794.  
  795.                             CloseFont(DiskFont);
  796.                             DiskFont = NULL;
  797.  
  798.                                 /* Dump file still open? */
  799.  
  800.                             if(GlobalOut)
  801.                             {
  802.                                 Close(GlobalOut);
  803.  
  804.                                 GlobalOut = NULL;
  805.                             }
  806.                         }
  807.                     }
  808.  
  809.                         /* Reenable the window? */
  810.  
  811.                     for(i = 0 ; i < 7 ; i++)
  812.                         OnGadget(&Buttons[i] . Gadget,Window,NULL);
  813.  
  814.                     ClearPointer(Window);
  815.                 }
  816.             }
  817.         }
  818.     }
  819. }
  820.