/*****************************************************************************
 * $LastChangedDate: 2011-04-23 21:07:07 -0400 (Sat, 23 Apr 2011) $
 * @file
 * @author  Jim E. Brooks  http://www.palomino3d.org
 * @brief   Font parameters.
 *//*
 * LEGAL:   COPYRIGHT (C) 2009 JIM E. BROOKS
 *          THIS SOURCE CODE IS RELEASED UNDER THE TERMS
 *          OF THE GNU GENERAL PUBLIC LICENSE VERSION 2 (GPL 2).
 *****************************************************************************/

#ifndef HUD_FONT_HH
#define HUD_FONT_HH 1

#include <map>
#include <fstream>
#include "base/singleton.hh"

namespace hud {

#define GET_FONT_MAP() (hud::FontMap::GetInstance())

class FontMap;

////////////////////////////////////////////////////////////////////////////////
/// @brief Font parameters.
///
/// Font ctor is private.  To obtain a Font object, call FontMap::GetFont().
///
/// Implementation:
/// Font names are mapped to the hidden implementation-specific parameters by FontMap.
///
class Font
{
COPYABLE(Font)
friend class FontMap;
private:
                    Font( const string& name, const fp size,
                          const fp widthRatio, const fp heightRatio, const string& pathName );
public:
                    ~Font();
    void            SetSize( const fp fontSize )
                    {
                    ASSERT( fontSize > 0 );
                        mSize = fontSize;
                    }
    fp              GetSize( void ) const
                    {
                    ASSERT( mSize > 0 );  // overall size
                        return mSize;
                    }
    fp              GetWidth( void ) const
                    {
                        const fp width = mSize * mWidthRatio;
                        ASSERT( width > 0 );
                        return width;
                    }
    fp              GetHeight( void ) const
                    {
                        const fp height = mSize * mHeightRatio;
                        ASSERT( height > 0 );
                        return height;
                    }
    const string&   GetPathName( void ) const
                    {
                    ASSERT( not mPathName.empty() );
                        return mPathName;
                    }
private:
    string    mName;          ///< don't allow changing name to prevent inconsistent parameters
    fp        mSize;          ///< overall font size
    fp        mWidthRatio;    ///< hidden font parameter
    fp        mHeightRatio;   ///< hidden font parameter
    string    mPathName;      ///< pathname of font file
};

////////////////////////////////////////////////////////////////////////////////
/// @brief Font map.
///
/// A map of font parameters is built at startup by reading a configuration file (.conf).
/// Font names are mapped to the hidden parameters of the Font class.
///
class FontMap
{
PREVENT_COPYING(FontMap)
    FontMap( void );
    ~FontMap();
public:
// Interface:
                DEFINE_GetInstance( FontMap )
    Font        GetFont( const string& fontName ) const;
    Font        GetDefaultFont( void ) const;

// For configuration:
    bool        ParseFont( std::ifstream& conf );

private:
    CLASS_VAR FontMap*  msInstance;
    typedef std::map<string,Font> FontMapType;
    FontMapType         mFontMap;
    string              mDefaultFontName;
};

} // namespace hud

#endif // HUD_FONT_HH
