#include <WinTen.h>
#include <Windows.h>
#include <ClipApi.h>

#define LF_HEIGHT          1
#define LF_WIDTH           2
#define LF_ESCAPEMENT      3
#define LF_ORIENTATION     4
#define LF_WEIGHT          5
#define LF_ITALIC          6
#define LF_UNDERLINE       7
#define LF_STRIKEOUT       8
#define LF_CHARSET         9
#define LF_OUTPRECISION   10
#define LF_CLIPPRECISION  11
#define LF_QUALITY        12
#define LF_PITCHANDFAMILY 13
#define LF_FACENAME       14

void RegisterResource( HANDLE hRes, LPSTR szType );

//----------------------------------------------------------------------------//

CLIPPER CREATEFONT() // ( aFont ) --> hFont
{
   HFONT hFont = CreateFont( _parni( 1, LF_HEIGHT ),
                             _parni( 1, LF_WIDTH ),
                             _parni( 1, LF_ESCAPEMENT ),
                             _parni( 1, LF_ORIENTATION ),
                             _parni( 1, LF_WEIGHT ),
                             _parl( 1, LF_ITALIC ),
                             _parl( 1, LF_UNDERLINE ),
                             _parl( 1, LF_STRIKEOUT ),
                             _parni( 1, LF_CHARSET ),
                             _parni( 1, LF_OUTPRECISION ),
                             _parni( 1, LF_CLIPPRECISION ),
                             _parni( 1, LF_QUALITY ),
                             _parni( 1, LF_PITCHANDFAMILY ),
                             _parc( 1, LF_FACENAME ) );

   RegisterResource( hFont, "FONT" );

   _retni( hFont );
}

//----------------------------------------------------------------------------//

CLIPPER ADDFONTRES() // OURCE()   cFontFile or hFontResource  --> nFontsAdded
{
   _retni( AddFontResource( IF( ISCHAR( 1 ), _parc( 1 ),
                                MAKEINTRESOURCE( _parni( 1 ) ) ) ) );
}

//----------------------------------------------------------------------------//

CLIPPER REMOVEFONT() // RESOURCE() cFontFile or hFontResource  --> lSuccess
{
   _retl( RemoveFontResource( IF( ISCHAR( 1 ), _parc( 1 ),
                                  MAKEINTRESOURCE( _parni( 1 ) ) ) ) );
}

//----------------------------------------------------------------------------//

CLIPPER GetFontInf() // o( hFont )  --> aInfo
{
   TEXTMETRIC tm;
   HFONT hFont    = _parni( 1 );
   HWND hWnd      = GetActiveWindow();
   HDC hDC        = GetDC( hWnd );
   HFONT hOldFont = SelectObject( hDC, hFont );

   GetTextMetrics( hDC, &tm );
   SelectObject( hDC, hOldFont );
   ReleaseDC( hWnd, hDC );

   _reta( 3 );
   _storni( tm.tmHeight, -1, 1 );
   _storni( tm.tmAveCharWidth, -1, 2 );
   _storl( tm.tmWeight & FW_BOLD, -1, 3 );
}

//----------------------------------------------------------------------------//
