/* -----------------------------------------------------------------------------
	GSFramework
	Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
------------------------------------------------------------------------------*/


#ifndef	__FONTEXTENDED__
#define	__FONTEXTENDED__


		#include "font/font_interface.h"
		#include "memory/nauto_ptr.h"
		#include "memory/nweak_ptr.h"


namespace GS {

/*!
	@short	Extended font to help normalization.
	@author	Emmanuel Julien (ejulien@owloh.com)
*/
class	FontEx : public IFont
{
		sIFont		font;
		WeakPtr <IFont> current_glyph_font;

		int			pixel_size;

public:

		WeakPtr <IFont> fallback;		///< Fall-back font when a glyph is not found in the current font.

		float		size_multiplier,	///< Offsets to ease TTF normalization.
					tracking_offset,
					leading_offset;

		/// Return the font name.
		const char	*GetName() const { return font->GetName(); }
		/// Return the bounding rect for a given string.
		iRect		GetTextBoundRect(const char *text) const { return font->GetTextBoundRect(text); }

		/// Set font size in pixels.
		bool		SetPixelSize(int);
		/// Get font height in pixels.
		int			GetHeight() const;
		/// Get font current glyph advance.
		int			GetAdvance() const;

		/// Return true if the font supports kerning.
		bool		HasKerning() const;
		/// Return the kerning for a glyph pair.
		int			GetKerning(uint previous_glyph, uint glyph) const;

		/// Load the glyph corresponding to a UTF-32 codepoint.
		bool		LoadGlyph(uint codepoint, bool for_render);
		/// Render currently loaded glyph to a picture.
		bool		RenderCurrentGlyph(Picture &picture, const iPoint &position, const iRect &clip, const Color &color);

		/// Set a fallback font to query in case a glyph cannot be found in this font.
		void		SetFallback(IFont *f) { fallback = f; }

		FontEx(IFont *f) : font(f), size_multiplier(1), tracking_offset(1), leading_offset(1) {}
};

typedef	SharedPtr <FontEx> sFontEx;

} // GS


#endif	// __FONTEXTENDED__
