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: Example4.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 opens disk fonts and prints some interesting */
- /* information about them. (Height, width, flags, style, */
- /* etc...) Syntax: Example4 [font1] [font2] [font3] ... */
- /* (The largest size of each font will be used.) */
-
-
-
- #include <intuition/intuitionbase.h>
-
-
- struct Intuition *IntuitionBase; /* Running under Intuition. */
- struct GfxBase *GfxBase; /* Move() and Text(). */
- struct Library *DiskfontBase; /* OpenDiskFont() etc. */
- /* NOTE! If you want to use the functions OpenDiskFont() or */
- /* AvailFonts() you have to open the Diskfont Library! */
-
-
- /* The new font's attributes: */
- struct TextAttr my_font_attr=
- {
- "", /* Fontname, will be changed. */
- 100, /* Largest possible size. (Max 100) */
- FS_NORMAL, /* Normal style. */
- FPF_DISKFONT /* Exist on Disk. */
- };
-
- /* Pointer to our new font: */
- struct TextFont *my_font;
-
-
- /* Declare a pointer to a Window structure: */
- struct Window *my_window;
-
- /* Declare and initialize your NewWindow structure: */
- struct NewWindow my_new_window=
- {
- 0, /* LeftEdge x position of the window. */
- 12, /* TopEdge y positio of the window. */
- 640, /* Width 640 pixels wide. */
- 100, /* Height 100 lines high. */
- 0, /* DetailPen Text should be drawn with colour reg. 0 */
- 1, /* BlockPen Blocks should be drawn with colour reg. 1 */
- CLOSEWINDOW, /* IDCMPFlags The window will give us a message if the */
- /* user has selected the Close window gad. */
- SMART_REFRESH| /* Flags Intuition should refresh the window. */
- WINDOWCLOSE| /* Close Gadget. */
- WINDOWDRAG| /* Drag gadget. */
- WINDOWDEPTH| /* Depth arrange Gadgets. */
- ACTIVATE, /* The window should be Active when opened. */
- NULL, /* FirstGadget No Custom gadgets. */
- NULL, /* CheckMark Use Intuition's default CheckMark. */
- "Font Test", /* Title Title of the window. */
- NULL, /* Screen Connected to the Workbench Screen. */
- NULL, /* BitMap No Custom BitMap. */
- 0, /* MinWidth No sizing gadget. */
- 0, /* MinHeight -"- */
- 0, /* MaxWidth -"- */
- 0, /* MaxHeight -"- */
- WBENCHSCREEN /* Type Connected to the Workbench Screen. */
- };
-
-
-
- void main();
- void clean_up();
-
-
- void main( argc, argv )
- int argc;
- char *argv[];
- {
- BOOL close_me; /* Used in the loop. */
- ULONG class; /* IDCMP flag. */
- struct IntuiMessage *my_message; /* IntuiMessage structure. */
- UBYTE count = 1; /* Counter. */
- char font_name[ 50 ]; /* Font name plus the extension ".font". */
-
-
- /* Open the necessary libraries: */
- IntuitionBase = (struct IntuitionBase *)
- OpenLibrary( "intuition.library", 0 );
- if( !IntuitionBase )
- clean_up( "Could not open Intuition library!" );
-
- GfxBase = (struct GfxBase *)
- OpenLibrary( "graphics.library", 0 );
- if( !GfxBase )
- clean_up( "Could not open Graphics library!" );
-
- DiskfontBase = (struct DiskfontBase *)
- OpenLibrary( "diskfont.library", 0 );
- if( !DiskfontBase )
- clean_up( "Could not open Diskfont library!" );
-
-
- /* Examine font after font... */
- while( count < argc )
- {
- /* Print the name of the font: */
- printf( "\nFont: %s\n", argv[ count ] );
-
- /* Add the extension ".font": */
- strcpy( font_name, argv[ count ] );
- strcat( font_name, ".font" );
-
- /* Set desired font: */
- my_font_attr.ta_Name = font_name;
-
-
- /* Try to open a disk font: */
- my_font = (struct TextFont *)
- OpenDiskFont( &my_font_attr );
-
- /* Have we opened the font successfully? */
- if( !my_font )
- clean_up( "Could not open the font!" );
-
-
- /* Set the height of the window: */
- my_new_window.Height = my_font->tf_YSize + 30;
-
- /* Open a window in which we will display the new font: */
- my_window = (struct Window *) OpenWindow( &my_new_window );
-
- /* Have we opened the window succesfully? */
- if(my_window == NULL)
- clean_up( "Could not open the window!" );
-
-
- /* Set colour and draw mode: */
- SetAPen( my_window->RPort, 1 );
- SetDrMd( my_window->RPort, JAM1 );
-
-
- /* Change the window's default font: */
- SetFont( my_window->RPort, my_font );
-
-
- /* Position the cursor, and print some characters: */
- Move( my_window->RPort, 10, my_font->tf_Baseline + 20 );
- Text( my_window->RPort, "ABCDE abcde", 11 );
-
-
- /* Give the user some information about the font: */
- printf( "YSize: %d\n", my_font->tf_YSize );
- printf( "XSize: %d\n", my_font->tf_XSize );
- printf( "Baseline: %d\n", my_font->tf_Baseline );
- printf( "Accessors: %d\n", my_font->tf_Accessors );
- printf( "LoChar: %d\n", my_font->tf_LoChar );
- printf( "HiChar: %d\n", my_font->tf_HiChar );
- printf( "Modulo: %d\n", my_font->tf_Modulo );
- printf( "Style:\n%s%s%s%s%s",
- my_font->tf_Style & FSF_UNDERLINED ? " Underlined\n" : "",
- my_font->tf_Style & FSF_BOLD ? " Bold\n" : "",
- my_font->tf_Style & FSF_ITALIC ? " Italic\n" : "",
- my_font->tf_Style & FSF_EXTENDED ? " Extended\n" : "",
- !my_font->tf_Style ? " Normal\n" : "" );
- printf( "Flags:\n%s%s%s%s%s%s%s",
- my_font->tf_Flags & FPF_ROMFONT ? " ROM Font\n" : "",
- my_font->tf_Flags & FPF_DISKFONT ? " Disk Font\n" : "",
- my_font->tf_Flags & FPF_REVPATH ? " Reversed path\n" : "",
- my_font->tf_Flags & FPF_TALLDOT ? " Hiresolution, Non-Interlaced\n" : "",
- my_font->tf_Flags & FPF_WIDEDOT ? " Lowresolution, Interlaced\n" : "",
- my_font->tf_Flags & FPF_PROPORTIONAL ? " Proportional\n" : "",
- my_font->tf_Flags & FPF_DESIGNED ? " Designed\n" : "" );
-
-
- /* Wait until the user closes the window: */
- close_me = FALSE;
- while( close_me == FALSE )
- {
- /* Wait until we have recieved a message: */
- Wait( 1 << my_window->UserPort->mp_SigBit );
-
- /* Collect the message: */
- while( (my_message = (struct IntuiMessage *) GetMsg( my_window->UserPort )) )
- {
- /* After we have collected the message we can read it, and save any */
- /* important values which we maybe want to check later: */
- class = my_message->Class;
-
- /* After we have read it we reply as fast as possible: */
- /* REMEMBER! Do never try to read a message after you have replied! */
- /* Some other process has maybe changed it. */
- ReplyMsg( my_message );
-
- /* Check which IDCMP flag was sent: */
- if( class == CLOSEWINDOW )
- close_me=TRUE; /* The user selected the Close window gadget! */
- }
- }
-
-
- /* Close the font: */
- CloseFont( my_font );
- my_font = NULL;
-
-
- /* Close the window: */
- CloseWindow( my_window );
- my_window = NULL;
-
- count++;
- }
-
- /* No arguments? */
- if( argc == 1 )
- {
- printf( "Which font(s) do you want to examine?\n" );
- printf( "Syntax: Example4 [font1] [font2] [font3] ...\n" );
- }
-
- /* Was it started from Workbench? */
- if( !argc )
- {
- printf( "Sorry, can not be used from Worbench.\n" );
-
- /* Wait 5 seconds: */
- Delay( 5 * 50 );
- }
-
- clean_up( "The End" );
- }
-
- void clean_up( message )
- STRPTR message;
- {
- if( my_window )
- CloseWindow( my_window );
-
- if( my_font )
- CloseFont( my_font );
-
- if( DiskfontBase )
- CloseLibrary( DiskfontBase );
-
- if( GfxBase )
- CloseLibrary( GfxBase );
-
- if( IntuitionBase )
- CloseLibrary( IntuitionBase );
-
- printf( "%s\n", message );
-
- exit();
- }
-
-