home *** CD-ROM | disk | FTP | other *** search
/ World of A1200 / World_Of_A1200.iso / datafiles / text / c_manual / graphics / fonts / example5.c < prev    next >
C/C++ Source or Header  |  1995-02-27  |  5KB  |  152 lines

  1. /***********************************************************/
  2. /*                                                         */
  3. /* Amiga C Encyclopedia (ACE) V3.0      Amiga C Club (ACC) */
  4. /* -------------------------------      ------------------ */
  5. /*                                                         */
  6. /* Book:    ACM Graphics                Amiga C Club       */
  7. /* Chapter: Fonts                       Tulevagen 22       */
  8. /* File:    Example5.c                  181 41  LIDINGO    */
  9. /* Author:  Anders Bjerin               SWEDEN             */
  10. /* Date:    92-04-28                                       */
  11. /* Version: 1.00                                           */
  12. /*                                                         */
  13. /*   Copyright 1992, Anders Bjerin - Amiga C Club (ACC)    */
  14. /*                                                         */
  15. /* Registered members may use this program freely in their */
  16. /*     own commercial/noncommercial programs/articles.     */
  17. /*                                                         */
  18. /***********************************************************/
  19.  
  20. /* This example demonstrates how to use the AvailFonts() */
  21. /* function. All available fonts (both on the disk as    */
  22. /* well as in the memory) will be listed together with   */
  23. /* some useful information about them.                   */
  24.  
  25.  
  26.  
  27. #include <exec/types.h>              /* Data types               */
  28. #include <exec/memory.h>             /* MEMF_CLEAR               */
  29. #include <libraries/diskfont.h>      /* struct AvailFonts etc... */
  30. #include <graphics/text.h>           /* FS_NORMAL etc...         */
  31.  
  32.  
  33. struct Library *DiskfontBase;    /* OpenDiskFont() etc.      */
  34.  
  35.  
  36. int size=0;
  37. struct AvailFontsHeader *avail_fonts_header;
  38. struct AvailFonts *avail_fonts;
  39.  
  40.  
  41. void main();
  42. void clean_up();
  43.  
  44.  
  45. void main()
  46. {
  47.   int loop;
  48.  
  49.  
  50.   /* Open the DiskFont Library: */
  51.   DiskfontBase = (struct DiskfontBase *)
  52.     OpenLibrary( "diskfont.library", 0 );
  53.   if( !DiskfontBase )
  54.     clean_up( "Could not open Diskfont library!" );
  55.  
  56.  
  57.   /* Check how large buffer we need to allocate.  */
  58.   /* (We give AvailFons() no memory to store the  */
  59.   /* font list in, so it will return the exact    */
  60.   /* number of bytes we need to allocate. This    */
  61.   /* means we have to call the function           */
  62.   /* AvailFonts() twice, but we are sure to get   */
  63.   /* a buffer of the exactly the right size so we */
  64.   /* do not need to waste any memory.)            */
  65.   printf( "Collecting information about all available fonts...\n" );
  66.   size = AvailFonts( NULL, 0, AFF_DISK | AFF_MEMORY );
  67.  
  68.   /* Print the size of the buffer we need to allocate: */
  69.   printf( "Buffer size: %d\n", size );
  70.  
  71.   /* Allocate the buffer: */
  72.   printf( "Storing information about all available fonts...\n" );
  73.   avail_fonts_header = (struct AvailFontsHeadr *)
  74.     AllocMem( size, MEMF_CLEAR );
  75.  
  76.   /* Call the function AvailFonts() again, but this time we give */
  77.   /* it a buffer to store the information in: (Remember to still */
  78.   /* check that the buffer was big enough! Some other task could */
  79.   /* have changed something in the FONTS: device while we        */
  80.   /* allocated the buffer. Never trust the Amiga...              */
  81.   if( AvailFonts( avail_fonts_header, size, AFF_DISK | AFF_MEMORY ) )
  82.     clean_up( "Buffer to small to store the font list in!" );
  83.  
  84.   /* Skip the afh_NumEntries filed: */
  85.   avail_fonts = (struct AvailFonts *) &avail_fonts_header[1];
  86.  
  87.   /* Print some information: */
  88.   printf( "-------------------------------------\n" );
  89.   printf( "|  Here is the complete font list!  |\n" );
  90.   printf( "-------------------------------------\n" );
  91.   
  92.   /* Check all AvailFonts structures: */
  93.   for( loop=0; loop < avail_fonts_header->afh_NumEntries; loop++ )
  94.   {
  95.     printf( "Name:  \"%s\"\n", avail_fonts->af_Attr.ta_Name );
  96.     printf( "Size:  %3d\n", avail_fonts->af_Attr.ta_YSize );
  97.  
  98.     printf( "Flags: " );
  99.     if( avail_fonts->af_Attr.ta_Flags & FPF_REMOVED )
  100.       printf( "Removed " );
  101.     if( avail_fonts->af_Attr.ta_Flags & FPF_REVPATH )
  102.       printf( "Reversed path " );
  103.     if( avail_fonts->af_Attr.ta_Flags & FPF_ROMFONT )
  104.       printf( "ROMFont " );
  105.     if( avail_fonts->af_Attr.ta_Flags & FPF_DISKFONT )
  106.       printf( "DiskFont " );
  107.     if( avail_fonts->af_Attr.ta_Flags & FPF_TALLDOT )
  108.       printf( "HiresNonInterlaced " );
  109.     if( avail_fonts->af_Attr.ta_Flags & FPF_WIDEDOT )
  110.       printf( "LowresInterlaced " );
  111.     if( avail_fonts->af_Attr.ta_Flags & FPF_PROPORTIONAL )
  112.       printf( "Proportional " );
  113.     if( avail_fonts->af_Attr.ta_Flags & FPF_DESIGNED )
  114.       printf( "Designed " );
  115.  
  116.     printf( "\nStyle: " );
  117.     if( avail_fonts->af_Attr.ta_Style & FS_NORMAL )
  118.       printf( "Normal " );
  119.     if( avail_fonts->af_Attr.ta_Style & FSF_EXTENDED )
  120.       printf( "Extended " );
  121.     if( avail_fonts->af_Attr.ta_Style & FSF_ITALIC )
  122.       printf( "Italic " );
  123.     if( avail_fonts->af_Attr.ta_Style & FSF_BOLD )
  124.       printf( "Bold " );
  125.     if( avail_fonts->af_Attr.ta_Style & FSF_UNDERLINED )
  126.       printf( "Underlined " );
  127.  
  128.     printf( "\n-------------------------------------\n" );
  129.  
  130.     /* Step to the next structure: */
  131.     avail_fonts++;
  132.   }
  133.  
  134.   /* Clean up and leave: */
  135.   clean_up( "The End" );
  136. }
  137.  
  138. void clean_up( message )
  139. STRPTR message;
  140. {
  141.   if( avail_fonts_header )
  142.     FreeMem( avail_fonts_header, size);
  143.     
  144.   if( DiskfontBase )
  145.     CloseLibrary( DiskfontBase );
  146.  
  147.   printf( "%s\n", message );
  148.  
  149.   exit();
  150. }
  151.  
  152.