#include <exec/types.h>
#include <intuition/intuition.h>
#include <graphics/text.h>

#define INOM "intuition.library"
#define GNOM "graphics.library"
#define DNOM "diskfont.library"
#define RP wdw->RPort

#ifdef LATTICE
#include <proto/graphics.h>
#include <proto/intuition.h>
#include <proto/exec.h>
#include <proto/diskfont.h>
#include <string.h>
#else
#include <functions.h>
#endif

struct GfxBase *GfxBase;
struct IntuitionBase *IntuitionBase;
struct DiskfontBase *DiskfontBase;
struct Window *wdw;
struct TextAttr TopazStruct = {
 (STRPTR) "topaz.font", TOPAZ_EIGHTY,
 FS_NORMAL, FPF_ROMFONT
};

struct TextAttr DiamondStruct = {
 (STRPTR) "diamond.font", 20,
 FS_NORMAL, FPF_DISKFONT
};
struct NewWindow NWStruct = {
 0,10, 600,200, -1,-1, CLOSEWINDOW,
 WINDOWCLOSE | ACTIVATE | SMART_REFRESH,
 NULL, NULL, (UBYTE *) "Demo Testo",
 NULL, NULL, 0,0, 0,0, WBENCHSCREEN
};

void die( n )
long n;
{
 if ( wdw ) CloseWindow( wdw );
 if ( DiskfontBase ) CloseLibrary( DiskfontBase );
 if ( IntuitionBase ) CloseLibrary( IntuitionBase );
 if ( GfxBase ) CloseLibrary( GfxBase );
 _exit( n );
}

void PrintAt( x, y, s )
unsigned x, y;
char *s;
{
 Move( RP, x, y ); Text( RP, s, strlen( s ) );
}

void main()
{
 struct TextFont *FontP;
 LONG mask;
 
 GfxBase = (struct GfxBase *) OpenLibrary( GNOM, 33L );
 if ( ! GfxBase ) die( 10 );

 IntuitionBase = (struct IntuitionBase *) OpenLibrary(INOM, 33L);
 if ( ! IntuitionBase ) die( 11 );

 DiskfontBase = (struct DiskfontBase *) OpenLibrary( DNOM, 33L );
 if ( ! DiskfontBase ) die( 12 );

 wdw = (struct Window *) OpenWindow( &NWStruct );
 if ( ! wdw ) die( 13 ); /* Finestra inapribile */

/* Incominciamo col fissare i colori e posizione */
 SetAPen( RP, 1 ); SetBPen( RP, 0 );
 PrintAt( 10, 30, "Scritto in posizione (10,30)" );

/* Attiviamo fonte topaz poi cambiamo stili algoritmici */

 FontP = (struct TextFont *) OpenFont( &TopazStruct );
 if ( ! FontP ) die( 14 ); /* topaz.8 inapribile */

 SetFont( RP, FontP ); /* Seleziona topaz.8 */

 mask = AskSoftStyle( RP );
 SetSoftStyle( RP, FSF_UNDERLINED, mask );
 PrintAt( 10, 50, "Topaz.8 sottolineato" );

 SetSoftStyle( RP, FSF_BOLD, mask );
 PrintAt( 10, 70, "Topaz.8 grassetto" );

 CloseFont( FontP );

/* Cambiamo fonte usando l'altra in ROM a 60 colonne */

 TopazStruct.ta_YSize = 9;
 FontP = (struct TextFont *) OpenFont( &TopazStruct );
 if ( ! FontP ) die( 15 ); /* topaz 9 inapribile */

 mask = AskSoftStyle( RP );
 SetSoftStyle( RP, FS_NORMAL, mask ); 
 PrintAt( 400, 30, "Topaz.9 normale" );

 SetSoftStyle( RP, FSF_ITALIC, mask );
 PrintAt( 400, 50, "Topaz.9 corsivo" );
 CloseFont( FontP );

/* Ora selezioniamo una fonte su dischetto */

 FontP = (struct TextFont *) OpenDiskFont( &DiamondStruct );

 if ( ! FontP ) die( 16 ); /* Diamond.20 inapribile */

 SetFont( RP, FontP ); 
 PrintAt( 10, 100, "Questa e' Diamond.20" );
 CloseFont( FontP );
 DiamondStruct.ta_YSize = 12;
 SetFont( RP, ( FontP = OpenDiskFont( &DiamondStruct ) ) );
 PrintAt( 340, 100, "Questa e' Diamond.12" );

 CloseFont( FontP );

/* Ora selezioniamo riformulando la struttura */

 DiamondStruct.ta_Name = (STRPTR) "sapphire.font";
 DiamondStruct.ta_YSize= 20;
 DiamondStruct.ta_Style= FS_NORMAL;
 DiamondStruct.ta_Flags= FPF_DISKFONT;
 FontP = (struct TextFont *) OpenDiskFont( &DiamondStruct );
 if ( ! FontP ) die( 17 );

 SetFont( RP, FontP );
 PrintAt( 10, 130, "Questa e' Sapphire.12" );
 CloseFont( FontP );

/* Attendiamo evento CLOSEWINDOW per uscire */

 Wait( 1L << wdw -> UserPort -> mp_SigBit );
 die( 0 );
}
