home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD v1.2 / amidev_cd_12.iso / reference / amiga_mail_vol2 / v-23 / bulletmainfile.c < prev    next >
C/C++ Source or Header  |  1996-01-30  |  9KB  |  202 lines

  1. ;/* BulletMainFile.c - Execute me to compile me with SAS/C 6.56
  2. sc NMINC STRMERGE STREQ NOSTKCHK SAVEDS IGNORE=73 BulletMainFile.c
  3. quit ;*/
  4.  
  5. /* (c)  Copyright 1992 Commodore-Amiga, Inc.   All rights reserved.       */
  6. /* The information contained herein is subject to change without notice,  */
  7. /* and is provided "as is" without warranty of any kind, either expressed */
  8. /* or implied.  The entire risk as to the use of this information is      */
  9. /* assumed by the user.                                                   */
  10.  
  11. #include <exec/types.h>
  12. #include <exec/memory.h>
  13. #include <dos/rdargs.h>
  14. #include <dos/dos.h>
  15. #include <dos/var.h>
  16. #include <diskfont/diskfonttag.h>
  17. #include <diskfont/diskfont.h>
  18. #include <diskfont/glyph.h>
  19. #include <diskfont/oterrors.h>
  20. #include <utility/tagitem.h>
  21. #include <string.h>
  22. #include <graphics/displayinfo.h>
  23. #include <intuition/intuition.h>
  24. #include <intuition/screens.h>
  25.  
  26. #include <clib/dos_protos.h>
  27. #include <clib/graphics_protos.h>
  28. #include <clib/exec_protos.h>
  29. #include <clib/utility_protos.h>
  30. #include <clib/bullet_protos.h>
  31. #include <clib/intuition_protos.h>
  32.  
  33. #define OTAG_ID 0x0f03
  34. #define BUFSIZE     256
  35.  
  36. #ifdef LATTICE
  37. int CXBRK(void) { return (0);} /* Disable Lattice CTRL/C handling */
  38. int chkabort(void) { return (0);}
  39. #endif
  40.  
  41. UBYTE     *readargsstring = "FileName/A,FontName,Size/N,XDPI/N,YDPI/N\n";
  42. UBYTE     *librarystring  = ".library";
  43. UBYTE     *fontstring     = "fonts:cgtimes.font";
  44. UBYTE     *dpivarname = "XYDPI";   /* Name of an X/Y DPI environment variable. */
  45.                                    /* If this ENV: variable exists, this code  */
  46.                                    /* will use the X and Y DPI stored there.   */
  47.                                    /* This code will also save the X and Y DPI */
  48.                                    /* in XYDPI if the user supplies a DPI.     */
  49.                                    /* XYDPI encodes the DPI just like the      */
  50.                                    /* OT_DeviceDPI tag.                        */
  51. extern struct TagItem *AllocOtag(STRPTR);
  52. extern void     FreeOtag(void *);
  53. extern struct Library *OpenScalingLibrary(struct TagItem *);
  54. extern void     CloseScalingLibrary(struct Library *);
  55. extern struct GlyphEngine *GetGlyphEngine(struct TagItem *, STRPTR);
  56. extern void     ReleaseGlyphEngine(struct GlyphEngine *);
  57. extern void
  58. BulletExample(struct GlyphEngine *,
  59.                   struct Window *,
  60.                   struct RastPort *, ULONG, ULONG, ULONG, STRPTR);
  61.  
  62. #define NUM_ARGS    5 /* Arguments for ReadArgs(). */
  63. #define VIEW_FILE   0
  64. #define FONT_NAME   1
  65. #define SIZE        2
  66. #define XDPI        3
  67. #define YDPI        4
  68. LONG            args[NUM_ARGS];
  69. struct RDargs  *myrda;
  70.  
  71. struct Library *BulletBase, *UtilityBase, *GfxBase, *IntuitionBase;
  72.  
  73. UBYTE           buf[BUFSIZE];
  74. BPTR            fontfile, dpifile;
  75. UBYTE          *otagname;
  76. UWORD           fchid;
  77.  
  78. struct GlyphEngine *ge;
  79.  
  80. struct DrawInfo *drawinfo;
  81. struct RastPort rp;
  82.  
  83. void            main(int argc, char **argv)
  84. {
  85.   struct TagItem *ti;
  86.   struct GlyphEngine *ge;
  87.   struct Window  *w;
  88.  
  89.   UBYTE           xydpi[5];
  90.  
  91.   LONG           defpointheight = 36;   /* Default values for ReadArgs() variables. */
  92.   LONG           defxdpi = 68;
  93.   LONG           defydpi = 27;
  94.  
  95.   if (GfxBase = OpenLibrary("graphics.library", 37L))
  96.   {
  97.     if (IntuitionBase = OpenLibrary("intuition.library", 37L))
  98.     {
  99.       if (myrda = ReadArgs(readargsstring, args, NULL))
  100.       {
  101.         if (args[XDPI] && args[YDPI]) /* If the user sets the DPI from the command  */
  102.         {            /* line, make sure the environment variable also gets changed. */
  103.           *(ULONG *)xydpi = ( (*(LONG *)args[XDPI]) << 16 | (*(ULONG *)args[YDPI]) );
  104.           SetVar(dpivarname, xydpi, 5,
  105.               GVF_GLOBAL_ONLY | GVF_BINARY_VAR | GVF_DONT_NULL_TERM);
  106.         }
  107.         else                           /* If the user did NOT set the X OR Y DPI... */
  108.         {
  109.           args[XDPI] = (LONG) &defxdpi;/* ...set to default values and see if there */
  110.           args[YDPI] = (LONG) &defydpi;/* there is an environment variable "XYDPI". */
  111.                                                   /* Read the environment variable, */
  112.           if ((GetVar(dpivarname, xydpi, 5,       /* XYDPI, if it exists.           */
  113.               GVF_GLOBAL_ONLY | GVF_BINARY_VAR | GVF_DONT_NULL_TERM)) != -1)
  114.  
  115. /* BUG! In the original publication of this code, the line above erroneously tested */
  116. /* tested for the wrong return value.  It caused unexpected results when using the  */
  117. /* default X and Y DPI values.  This bug was also present in BulletMain.c.          */
  118.  
  119.           {
  120.             if ( (*(ULONG *)xydpi & 0xFFFF0000) && (*(ULONG *)xydpi & 0x0000FFFF) )
  121.             {          /* Make sure the environment variable is OK to use by making */
  122.                        /* sure that neither X or YDPI is zero. If XYDPI is OK, use  */
  123.               defxdpi = ((*(ULONG *)xydpi) & 0xFFFF0000) >> 16; /* it as a default. */
  124.               defydpi = (*(ULONG *)xydpi) & 0x0000FFFF;
  125.             }
  126.           }
  127.         }
  128.         if (!(args[SIZE]))
  129.           args[SIZE] = (LONG) &defpointheight;
  130.         if (!(args[FONT_NAME]))
  131.           args[FONT_NAME] = (LONG) fontstring;
  132.                                            /* Open the ".font" file which contains  */
  133.                                            /* the FontContentsHeader for this font. */
  134.  
  135.         if (fontfile = Open((STRPTR) args[FONT_NAME], MODE_OLDFILE))
  136.         {
  137.           if (Read(fontfile, &fchid, sizeof(UWORD)))
  138.           {
  139.             if (fchid == OTAG_ID)            /* Does this font have an .otag file? */
  140.             {
  141.               strcpy(buf, (STRPTR) args[FONT_NAME]);   /* Put together the .otag   */
  142.               if (otagname = &(buf[strlen(buf) - 4]))  /* file name from the .font */
  143.               {                                        /* file name.               */
  144.                 strcpy(otagname, "otag");
  145.                 if (UtilityBase = OpenLibrary("utility.library", 37L))
  146.                 {
  147.                   if (ti = AllocOtag(buf))      /* open the otag file and copy its */
  148.                   {                             /* tags into memory.               */
  149.                     if (BulletBase = OpenScalingLibrary(ti)) /* Pass the function  */
  150.                     {                                  /* the OTAG tag list which  */
  151.                       if (ge = GetGlyphEngine(ti, buf))/* it needs to open the     */
  152.                       {                              /* scaling library.  Open the */
  153.                                                      /* library's scaling engine.  */
  154.                         if (w = OpenWindowTags(NULL,
  155.                                                WA_Width,         640,
  156.                                                WA_Height,        200,
  157.                                                WA_SmartRefresh,  TRUE,
  158.                                                WA_SizeGadget,    FALSE,
  159.                                                WA_CloseGadget,   TRUE,
  160.                                                WA_IDCMP,         NULL,
  161.                                                WA_DragBar,       TRUE,
  162.                                                WA_DepthGadget,   TRUE,
  163.                                                WA_Title,         (ULONG)argv[0],
  164.                                                TAG_END))
  165.                         {
  166.                           rp = *(w->RPort);    /* Clone window's RastPort.  The    */
  167.                                                /* second Rastport is for rendering */
  168.                                                /* with the background color.       */
  169.                           if (drawinfo = GetScreenDrawInfo(w->WScreen)) /* Get the */
  170.                           {            /* screen's DrawInfo to get its pen colors. */
  171.                             SetAPen(w->RPort, drawinfo->dri_Pens[TEXTPEN]);
  172.                             SetAPen(&rp, drawinfo->dri_Pens[BACKGROUNDPEN]);
  173.                             FreeScreenDrawInfo(w->WScreen, drawinfo);
  174.                           }
  175.  
  176.                           BulletExample(ge, w, &rp, *(ULONG *) args[SIZE],
  177.                                         *(ULONG *) args[XDPI],
  178.                                         *(ULONG *) args[YDPI],
  179.                                         (STRPTR) args[VIEW_FILE]);
  180.                           CloseWindow(w);
  181.                         }
  182.                         ReleaseGlyphEngine(ge);
  183.                       }
  184.                       CloseScalingLibrary(BulletBase);
  185.                     }
  186.                     FreeOtag(ti);
  187.                   }
  188.                   CloseLibrary(UtilityBase);
  189.                 }
  190.               }
  191.             }
  192.           }
  193.           Close(fontfile);
  194.         }
  195.         FreeArgs(myrda);
  196.       }
  197.       CloseLibrary(IntuitionBase);
  198.     }
  199.     CloseLibrary(GfxBase);
  200.   }
  201. }
  202.