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


		#include "font/font_extended.h"

		using namespace GS;


//------------------------------------------------------------------------------
bool			FontEx::SetPixelSize(int size)
{
	pixel_size = size;
	return current_glyph_font.IsValid() ? current_glyph_font->SetPixelSize(size) : font->SetPixelSize(size);
}
bool			FontEx::HasKerning() const
{	return current_glyph_font.IsValid() ? current_glyph_font->HasKerning() : font->HasKerning();	}
int				FontEx::GetKerning(uint previous_codepoint, uint codepoint) const
{	return current_glyph_font.IsValid() ? current_glyph_font->GetKerning(previous_codepoint, codepoint) : font->GetKerning(previous_codepoint, codepoint);	}

int				FontEx::GetHeight() const
{	return current_glyph_font.IsValid() ? current_glyph_font->GetHeight() : font->GetHeight();	}
int				FontEx::GetAdvance() const
{	return current_glyph_font.IsValid() ? current_glyph_font->GetAdvance() : font->GetAdvance();	}

bool			FontEx::LoadGlyph(uint codepoint, bool for_render)
{
	current_glyph_font = font;
	if	(font->LoadGlyph(codepoint, for_render))
		return true;

	// Synchronize and try fallback.
	if	(fallback.IsNull())
		return false;

	fallback->SetPixelSize(pixel_size);
	bool r = fallback->LoadGlyph(codepoint, for_render);

	if	(r)
		current_glyph_font = fallback;
	return r;
}
bool			FontEx::RenderCurrentGlyph(Picture &picture, const iPoint &position, const iRect &clip, const Color &color)
{	return current_glyph_font.IsValid() ? current_glyph_font->RenderCurrentGlyph(picture, position, clip, color) : font->RenderCurrentGlyph(picture, position, clip, color);	}
//------------------------------------------------------------------------------
