home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 640a.lha / FontConverter / Source.LZH / Source / FC_V2.0.c < prev    next >
C/C++ Source or Header  |  1992-04-26  |  10KB  |  243 lines

  1. /************************************************************************/
  2. /*                                                                      */
  3. /*                         FontConverter V2.0                           */
  4. /*                                                                      */
  5. /*                         Freeware © 1992 by                           */
  6. /*                                                                      */
  7. /*                            Andreas Baum                              */
  8. /*                        Eugen-Roth-Straße 25                          */
  9. /*                           W-8430 Neumarkt                            */
  10. /*                               Germany                                */
  11. /*                                                                      */
  12. /*                      Convert Fonts in C-Source                       */
  13. /*                                                                      */
  14. /*                      Usage: FontConverter_V2.0                       */
  15. /*                                                                      */
  16. /*                              Needs OS2                               */
  17. /*                                                                      */
  18. /*                            Compiler: DICE                            */
  19. /*                                                                      */
  20. /*           Compilerusage: DCC -oFontConverter_V2.0 FC_V2.0.c          */
  21. /*                                                                      */
  22. /************************************************************************/
  23.  
  24.  
  25. #include <libraries/dos.h>
  26. #include <libraries/asl.h>
  27. #include <utility/tagitem.h>
  28.  
  29. struct FontRequester   *FontRequester;
  30. struct FileRequester   *FileRequester;
  31. struct TagItem         *MyTags;
  32. struct WBArg           *fargs;
  33.  
  34. UWORD YSize, XSize, Baseline, BoldSmear, Accessors, Modulo;
  35. UWORD Dat_Value;
  36.  
  37. ULONG Font, CharData, CharLoc, CharSpace, CharKern;
  38. ULONG In_Datei, Out_Datei, Dat_Length;
  39. ULONG x, y;
  40.  
  41. UBYTE Style, Flags, LoChar, HiChar;
  42. UBYTE In_Name[200], Out_Name[200], Font_Name[50], Data[100], Compal[]=":";
  43.  
  44. main()
  45.   {
  46.     printf("\n\033[1m\033[33mFontConverter_V2.0\033[0m\n\n");
  47.     printf("© 1992 by Baum Andreas\n\n");
  48.  
  49.     FontRequester=(struct FontRequester *)AllocAslRequest(ASL_FontRequest,NULL);
  50.  
  51.     MyTags=(struct MyTags *)AllocateTagItems(3);
  52.  
  53.     MyTags[0].ti_Tag=ASL_Hail;
  54.     MyTags[0].ti_Data="Select Font";
  55.     MyTags[1].ti_Tag=ASL_MaxHeight;
  56.     MyTags[1].ti_Data=25;
  57.     MyTags[2].ti_Tag=TAG_DONE;
  58.  
  59.     if(AslRequest(FontRequester, MyTags))
  60.       {
  61.         FreeTagItems(MyTags);
  62.         FreeAslRequest(FontRequester);
  63.  
  64.         sprintf(In_Name,"Fonts:%s/%d",strtok(FontRequester->fo_Attr.ta_Name,"."),FontRequester->fo_Attr.ta_YSize);
  65.         sprintf(Font_Name,"%s%d",strtok(FontRequester->fo_Attr.ta_Name,"."),FontRequester->fo_Attr.ta_YSize);
  66.  
  67.         if(In_Datei=Open(In_Name,MODE_OLDFILE))
  68.           {
  69.             Seek(In_Datei,48,OFFSET_BEGINNING);
  70.             Read(In_Datei,&Font,4);
  71.             if(Font==0x1a0f80)
  72.               {
  73.                 FileRequester=(struct FileRequester *)AllocAslRequest(ASL_FileRequest,NULL);
  74.  
  75.                 MyTags=(struct MyTags *)AllocateTagItems(5);
  76.  
  77.                 MyTags[0].ti_Tag=ASL_Hail;
  78.                 MyTags[0].ti_Data="Select Datei";
  79.                 MyTags[1].ti_Tag=ASL_FuncFlags;
  80.                 MyTags[1].ti_Data=FILF_SAVE;
  81.                 MyTags[2].ti_Tag=ASL_File;
  82.                 MyTags[2].ti_Data="Font.c";
  83.                 MyTags[3].ti_Tag=ASL_Dir;
  84.                 MyTags[3].ti_Data="Ram:";
  85.                 MyTags[4].ti_Tag=TAG_DONE;
  86.  
  87.                 if(AslRequest(FileRequester, MyTags))
  88.                   {
  89.                     printf("\033[3mWorking so hard ... Please Wait\033[0m\n\n");
  90.  
  91.                     FreeTagItems(MyTags);
  92.  
  93.                     FreeAslRequest(FileRequester);
  94.  
  95.                     if(strcmp(FileRequester->rf_Dir[strlen(FileRequester->rf_Dir)-1],Compal[0]))
  96.                       sprintf(Out_Name,"%s/%s",FileRequester->rf_Dir,FileRequester->rf_File);
  97.                     else
  98.                       sprintf(Out_Name,"%s%s",FileRequester->rf_Dir,FileRequester->rf_File);
  99.  
  100.                     Out_Datei=Open(Out_Name,MODE_NEWFILE);
  101.  
  102.                     Seek(In_Datei,110,OFFSET_BEGINNING);
  103.                     Read(In_Datei,&YSize,2);
  104.                     Read(In_Datei,&Style,1);
  105.                     Read(In_Datei,&Flags,1);
  106.                     Read(In_Datei,&XSize,2);
  107.                     Read(In_Datei,&Baseline,2);
  108.                     Read(In_Datei,&BoldSmear,2);
  109.                     Read(In_Datei,&Accessors,2);
  110.                     Read(In_Datei,&LoChar,1);
  111.                     Read(In_Datei,&HiChar,1);
  112.                     Read(In_Datei,&CharData,4);
  113.                     Read(In_Datei,&Modulo,2);
  114.                     Read(In_Datei,&CharLoc,4);
  115.                     Read(In_Datei,&CharSpace,4);
  116.                     Read(In_Datei,&CharKern,4);
  117.  
  118.                     Dat_Length=(Modulo*YSize+(HiChar-LoChar+2)*4)/2;
  119.                     if(CharSpace!=0)
  120.                       Dat_Length=Dat_Length+(HiChar-LoChar+2);
  121.                     if(CharKern!=0)
  122.                       Dat_Length=Dat_Length+(HiChar-LoChar+2);
  123.  
  124.                     sprintf(Data,"/*  FontConverter_V2.0 © 1992 by Andreas Baum  */\n\n");
  125.                     Write(Out_Datei,Data,strlen(Data));
  126.  
  127.                     sprintf(Data,"#include <graphics/text.h>\n\n");
  128.                     Write(Out_Datei,Data,strlen(Data));
  129.  
  130.                     sprintf(Data,"UWORD %sdump[] =\n",Font_Name);
  131.                     Write(Out_Datei,Data,strlen(Data));
  132.  
  133.                     sprintf(Data,"  {\n");
  134.                     Write(Out_Datei,Data,strlen(Data));
  135.  
  136.                     y=1;
  137.                     for(x=0;x<Dat_Length;x++)
  138.                       {
  139.                         Read(In_Datei,&Dat_Value,2);
  140.                         if(x==Dat_Length-1)
  141.                           {
  142.                             sprintf(Data,"\t0x%04x\n",Dat_Value);
  143.                             Write(Out_Datei,Data,strlen(Data));
  144.                             y=9;
  145.                           }
  146.                         if(y<=7)
  147.                           {
  148.                             sprintf(Data,"\t0x%04x,",Dat_Value);
  149.                             Write(Out_Datei,Data,strlen(Data));
  150.                           }
  151.                         if(y==8)
  152.                           {
  153.                             y=0;
  154.                             sprintf(Data,"\t0x%04x,\n",Dat_Value);
  155.                             Write(Out_Datei,Data,strlen(Data));
  156.                           }
  157.                         y++;
  158.                       }
  159.  
  160.                     sprintf(Data,"  };\n\n");
  161.                     Write(Out_Datei,Data,strlen(Data));
  162.  
  163.                     sprintf(Data,"struct TextFont %sFont;\n\n",Font_Name);
  164.                     Write(Out_Datei,Data,strlen(Data));
  165.  
  166.                     sprintf(Data,"FontInit_%s()\n",Font_Name);
  167.                     Write(Out_Datei,Data,strlen(Data));
  168.  
  169.                     sprintf(Data,"  {\n");
  170.                     Write(Out_Datei,Data,strlen(Data));
  171.  
  172.                     sprintf(Data,"\n");
  173.                     Write(Out_Datei,Data,strlen(Data));
  174.  
  175.                     sprintf(Data,"    %sFont.tf_Message.mn_Node.ln_Name = \"%s.font\";\n",Font_Name,Font_Name);
  176.                     Write(Out_Datei,Data,strlen(Data));
  177.  
  178.                     sprintf(Data,"    %sFont.tf_YSize = 0x%04x;\n",Font_Name,YSize);
  179.                     Write(Out_Datei,Data,strlen(Data));
  180.  
  181.                     sprintf(Data,"    %sFont.tf_Style = 0x%02x;\n",Font_Name,Style);
  182.                     Write(Out_Datei,Data,strlen(Data));
  183.  
  184.                     sprintf(Data,"    %sFont.tf_Flags = 0x%02x;\n",Font_Name,Flags);
  185.                     Write(Out_Datei,Data,strlen(Data));
  186.  
  187.                     sprintf(Data,"    %sFont.tf_XSize = 0x%04x;\n",Font_Name,XSize);
  188.                     Write(Out_Datei,Data,strlen(Data));
  189.  
  190.                     sprintf(Data,"    %sFont.tf_Baseline = 0x%04x;\n",Font_Name,Baseline);
  191.                     Write(Out_Datei,Data,strlen(Data));
  192.  
  193.                     sprintf(Data,"    %sFont.tf_BoldSmear = 0x%04x;\n",Font_Name,BoldSmear);
  194.                     Write(Out_Datei,Data,strlen(Data));
  195.  
  196.                     sprintf(Data,"    %sFont.tf_Accessors = 0x%04x;\n",Font_Name,Accessors);
  197.                     Write(Out_Datei,Data,strlen(Data));
  198.  
  199.                     sprintf(Data,"    %sFont.tf_LoChar = 0x%02x;\n",Font_Name,LoChar);
  200.                     Write(Out_Datei,Data,strlen(Data));
  201.  
  202.                     sprintf(Data,"    %sFont.tf_HiChar = 0x%02x;\n",Font_Name,HiChar);
  203.                     Write(Out_Datei,Data,strlen(Data));
  204.  
  205.                     sprintf(Data,"    %sFont.tf_CharData = (APTR)((char *)&%sdump[0]+0x%08x);\n",Font_Name,Font_Name,CharData-110);
  206.                     Write(Out_Datei,Data,strlen(Data));
  207.  
  208.                     sprintf(Data,"    %sFont.tf_Modulo = 0x%04x;\n",Font_Name,Modulo);
  209.                     Write(Out_Datei,Data,strlen(Data));
  210.  
  211.                     sprintf(Data,"    %sFont.tf_CharLoc = (APTR)((char *)&%sdump[0]+0x%08x);\n",Font_Name,Font_Name,CharLoc-110);
  212.                     Write(Out_Datei,Data,strlen(Data));
  213.  
  214.                     sprintf(Data,"    %sFont.tf_CharSpace = (APTR)((char *)&%sdump[0]+0x%08x);\n",Font_Name,Font_Name,CharSpace-110);
  215.                     if(CharKern == 0)
  216.                       sprintf(Data,"    %sFont.tf_CharKern = 0x00000000;\n",Font_Name);
  217.                     Write(Out_Datei,Data,strlen(Data));
  218.  
  219.                     sprintf(Data,"    %sFont.tf_CharKern = (APTR)((char *)&%sdump[0]+0x%08x);\n",Font_Name,Font_Name,CharKern-110);
  220.                     if(CharSpace == 0)
  221.                       sprintf(Data,"    %sFont.tf_CharSpace = 0x00000000;\n",Font_Name);
  222.                     Write(Out_Datei,Data,strlen(Data));
  223.  
  224.                     sprintf(Data,"  }\n");
  225.                     Write(Out_Datei,Data,strlen(Data));
  226.                   }
  227.               }
  228.             else
  229.               printf("\033[1mError: No Font or packed Font or inadmissible Font !\033[0m\n\n");
  230.           }
  231.         else
  232.           printf("\033[1mError: Must be a Ram-Font !\033[0m\n\n");
  233.       }
  234.     close_all();
  235.     exit(0);
  236.   }
  237.  
  238. close_all()
  239.   {
  240.     if(In_Datei) Close(In_Datei);
  241.     if(Out_Datei) Close(Out_Datei);
  242.   }
  243.