home *** CD-ROM | disk | FTP | other *** search
- /***********************************************************/
- /* */
- /* Amiga C Encyclopedia (ACE) V3.0 Amiga C Club (ACC) */
- /* ------------------------------- ------------------ */
- /* */
- /* Book: ACM Graphics Amiga C Club */
- /* Chapter: Fonts Tulevagen 22 */
- /* File: Example5.c 181 41 LIDINGO */
- /* Author: Anders Bjerin SWEDEN */
- /* Date: 92-04-28 */
- /* Version: 1.00 */
- /* */
- /* Copyright 1992, Anders Bjerin - Amiga C Club (ACC) */
- /* */
- /* Registered members may use this program freely in their */
- /* own commercial/noncommercial programs/articles. */
- /* */
- /***********************************************************/
-
- /* This example demonstrates how to use the AvailFonts() */
- /* function. All available fonts (both on the disk as */
- /* well as in the memory) will be listed together with */
- /* some useful information about them. */
-
-
-
- #include <exec/types.h> /* Data types */
- #include <exec/memory.h> /* MEMF_CLEAR */
- #include <libraries/diskfont.h> /* struct AvailFonts etc... */
- #include <graphics/text.h> /* FS_NORMAL etc... */
-
-
- struct Library *DiskfontBase; /* OpenDiskFont() etc. */
-
-
- int size=0;
- struct AvailFontsHeader *avail_fonts_header;
- struct AvailFonts *avail_fonts;
-
-
- void main();
- void clean_up();
-
-
- void main()
- {
- int loop;
-
-
- /* Open the DiskFont Library: */
- DiskfontBase = (struct DiskfontBase *)
- OpenLibrary( "diskfont.library", 0 );
- if( !DiskfontBase )
- clean_up( "Could not open Diskfont library!" );
-
-
- /* Check how large buffer we need to allocate. */
- /* (We give AvailFons() no memory to store the */
- /* font list in, so it will return the exact */
- /* number of bytes we need to allocate. This */
- /* means we have to call the function */
- /* AvailFonts() twice, but we are sure to get */
- /* a buffer of the exactly the right size so we */
- /* do not need to waste any memory.) */
- printf( "Collecting information about all available fonts...\n" );
- size = AvailFonts( NULL, 0, AFF_DISK | AFF_MEMORY );
-
- /* Print the size of the buffer we need to allocate: */
- printf( "Buffer size: %d\n", size );
-
- /* Allocate the buffer: */
- printf( "Storing information about all available fonts...\n" );
- avail_fonts_header = (struct AvailFontsHeadr *)
- AllocMem( size, MEMF_CLEAR );
-
- /* Call the function AvailFonts() again, but this time we give */
- /* it a buffer to store the information in: (Remember to still */
- /* check that the buffer was big enough! Some other task could */
- /* have changed something in the FONTS: device while we */
- /* allocated the buffer. Never trust the Amiga... */
- if( AvailFonts( avail_fonts_header, size, AFF_DISK | AFF_MEMORY ) )
- clean_up( "Buffer to small to store the font list in!" );
-
- /* Skip the afh_NumEntries filed: */
- avail_fonts = (struct AvailFonts *) &avail_fonts_header[1];
-
- /* Print some information: */
- printf( "-------------------------------------\n" );
- printf( "| Here is the complete font list! |\n" );
- printf( "-------------------------------------\n" );
-
- /* Check all AvailFonts structures: */
- for( loop=0; loop < avail_fonts_header->afh_NumEntries; loop++ )
- {
- printf( "Name: \"%s\"\n", avail_fonts->af_Attr.ta_Name );
- printf( "Size: %3d\n", avail_fonts->af_Attr.ta_YSize );
-
- printf( "Flags: " );
- if( avail_fonts->af_Attr.ta_Flags & FPF_REMOVED )
- printf( "Removed " );
- if( avail_fonts->af_Attr.ta_Flags & FPF_REVPATH )
- printf( "Reversed path " );
- if( avail_fonts->af_Attr.ta_Flags & FPF_ROMFONT )
- printf( "ROMFont " );
- if( avail_fonts->af_Attr.ta_Flags & FPF_DISKFONT )
- printf( "DiskFont " );
- if( avail_fonts->af_Attr.ta_Flags & FPF_TALLDOT )
- printf( "HiresNonInterlaced " );
- if( avail_fonts->af_Attr.ta_Flags & FPF_WIDEDOT )
- printf( "LowresInterlaced " );
- if( avail_fonts->af_Attr.ta_Flags & FPF_PROPORTIONAL )
- printf( "Proportional " );
- if( avail_fonts->af_Attr.ta_Flags & FPF_DESIGNED )
- printf( "Designed " );
-
- printf( "\nStyle: " );
- if( avail_fonts->af_Attr.ta_Style & FS_NORMAL )
- printf( "Normal " );
- if( avail_fonts->af_Attr.ta_Style & FSF_EXTENDED )
- printf( "Extended " );
- if( avail_fonts->af_Attr.ta_Style & FSF_ITALIC )
- printf( "Italic " );
- if( avail_fonts->af_Attr.ta_Style & FSF_BOLD )
- printf( "Bold " );
- if( avail_fonts->af_Attr.ta_Style & FSF_UNDERLINED )
- printf( "Underlined " );
-
- printf( "\n-------------------------------------\n" );
-
- /* Step to the next structure: */
- avail_fonts++;
- }
-
- /* Clean up and leave: */
- clean_up( "The End" );
- }
-
- void clean_up( message )
- STRPTR message;
- {
- if( avail_fonts_header )
- FreeMem( avail_fonts_header, size);
-
- if( DiskfontBase )
- CloseLibrary( DiskfontBase );
-
- printf( "%s\n", message );
-
- exit();
- }
-
-