home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / Amiga_Mail_Vol2 / Archives / Plain / ja92 / Bullet / Engine.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-18  |  5.4 KB  |  171 lines

  1. ;/* Engine.c - Execute me to compile me with SAS/C 5.10a
  2. LC -cfistq -v -y -j73 Engine.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.  
  12. #include <exec/types.h>
  13. #include <exec/memory.h>
  14. #include <dos/dostags.h>
  15. #include <dos/dos.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.  
  23. #include <clib/dos_protos.h>
  24. #include <clib/exec_protos.h>
  25. #include <clib/utility_protos.h>
  26. #include <clib/bullet_protos.h>
  27.  
  28. #define OTAG_ID 0x0f03   /* this really belongs in <diskfont/diskfont.h>, */
  29.                          /* but it's not there, yet.                      */
  30.  
  31. extern UBYTE   *librarystring; /* ".library", defined in BulletMain.c. */
  32.  
  33. struct TagItem *AllocOtag(STRPTR);
  34. void            FreeOtag(void *);
  35. struct Library *OpenScalingLibrary(struct TagItem *);
  36. void            CloseScalingLibrary(struct Library *);
  37. struct GlyphEngine *GetGlyphEngine(struct TagItem *, STRPTR);
  38. void            ReleaseGlyphEngine(struct GlyphEngine *);
  39.  
  40. #define BUFSIZE     256
  41.  
  42. extern struct Library *BulletBase, *UtilityBase;
  43.  
  44. /*************************************************************************************/
  45. /* open the otag file, allocate a buffer, read the file into the buffer, verify that */
  46. /* the file is OK, relocate all of the address relocation tags, close the otag file. */
  47. /*************************************************************************************/
  48. struct TagItem *
  49. AllocOtag(STRPTR otagname)
  50. {
  51.   BPTR            otfile;
  52.   struct TagItem *ti, *tip, *returnti;
  53.   struct FileInfoBlock *fib;
  54.  
  55.   ti = NULL;
  56.  
  57.   if (fib = AllocDosObject(DOS_FIB, NULL))    /* The FileInfoBlock of the OTAG file */
  58.   {                                           /* contains the file's size.          */
  59.     if (otfile = Open(otagname, MODE_OLDFILE))
  60.     {
  61.       if (ExamineFH(otfile, fib))
  62.       {
  63.         if (returnti = (struct TagItem *) AllocVec(fib->fib_Size, MEMF_CLEAR))
  64.         {
  65.           if (Read(otfile, (UBYTE *) returnti, fib->fib_Size))
  66.           {
  67.             if ((returnti->ti_Tag == OT_FileIdent)               /* Test to see if */
  68.                 && (returnti->ti_Data == (ULONG) fib->fib_Size)) /* the OTAG file  */
  69.             {                                                    /* is valid.      */
  70.               tip = returnti;
  71.               while (ti = NextTagItem(&tip))     /* Step through and relocate tags */
  72.               {
  73.                 if (ti->ti_Tag & OT_Indirect)
  74.                 {
  75.                   ti->ti_Data = (ULONG) returnti + ti->ti_Data;
  76.                 }
  77.               }
  78.             }
  79.           }
  80.         }
  81.       }
  82.       Close(otfile);
  83.     }
  84.     FreeDosObject(DOS_FIB, fib);
  85.   }
  86.   return (returnti);
  87. }
  88.  
  89. /**************************************************************************/
  90. /*********** Deallocates resources allocated by AllocOtag(). **************/
  91. /**************************************************************************/
  92. void
  93. FreeOtag(void *vector)
  94. {
  95.   FreeVec(vector);
  96. }
  97.  
  98.  
  99. /*****************************************************************************/
  100. /******* Scans through a TagList looking for an scaling engine name. *********/
  101. /*******           If it finds one, it opens that library.           *********/
  102. /*****************************************************************************/
  103. struct Library *
  104. OpenScalingLibrary(struct TagItem * ti)
  105. {
  106.   STRPTR          enginename;
  107.   UBYTE           libnamebuffer[BUFSIZE];
  108.  
  109.   if (enginename = (STRPTR) GetTagData(OT_Engine, NULL, ti))
  110.   {
  111.     strcpy(libnamebuffer, enginename);
  112.     strcat(libnamebuffer, librarystring);
  113.  
  114.     return (OpenLibrary(libnamebuffer, 0L));
  115.   }
  116. }
  117.  
  118. /**************************************************************************/
  119. /******* Deallocates resources allocated by OpenScalingLibrary(). *********/
  120. /**************************************************************************/
  121. void
  122. CloseScalingLibrary(struct Library * bbase)
  123. {
  124.   CloseLibrary(bbase);
  125. }
  126.  
  127.  
  128. /**************************************************************************/
  129. /* Open the glyph engine, give it the tags from the otag file, and set up */
  130. /* a default device dpi so it doesn't crash if someone forgets to set it. */
  131. /**************************************************************************/
  132. struct GlyphEngine *
  133. GetGlyphEngine(struct TagItem * ti, STRPTR otagpath)
  134. {
  135.   struct GlyphEngine *ge = NULL;
  136.   BOOL            ok = TRUE;
  137.  
  138.   if (ge = OpenEngine())
  139.   {
  140.     ok = FALSE;
  141.     if (SetInfo(ge,
  142.                 OT_OTagList, ti,
  143.                 OT_OTagPath, otagpath,
  144.                 TAG_END) == OTERR_Success)
  145.     {
  146.       if (SetInfo(ge,
  147.                   OT_DeviceDPI, ((ULONG) 77) << 16 | 75,
  148.                   TAG_END) == OTERR_Success)
  149.       {
  150.         ok = TRUE;
  151.       }
  152.     }
  153.   }
  154.  
  155.   if (!ok)
  156.   {
  157.     CloseEngine(ge);
  158.     ge = NULL;
  159.   }
  160.   return (ge);
  161. }
  162.  
  163. /**************************************************************************/
  164. /********* Deallocates resources allocated by GetGlyphEngine(). ***********/
  165. /**************************************************************************/
  166. void
  167. ReleaseGlyphEngine(struct GlyphEngine * ge)
  168. {
  169.   CloseEngine(ge);
  170. }
  171.