/*---------------------------------------------------------------------------------
 libBAG  Copyright (C) 2010 - 2012		
  BassAceGold - <BassAceGold@gmail.com>

  This software is provided 'as-is', without any express or implied
  warranty.  In no event will the authors be held liable for any
  damages arising from the use of this software.

  Permission is granted to anyone to use this software for any
  purpose, including commercial applications, and to alter it and
  redistribute it freely, subject to the following restrictions:

  1. The origin of this software must not be misrepresented; you
     must not claim that you wrote the original software. If you use
     this software in a product, an acknowledgment in the product
     documentation would be appreciated but is not required.
	 
  2. Altered source versions must be plainly marked as such, and
     must not be misrepresented as being the original software.
	 
  3. Restricting the usage of or portions of code in this library
     from other software developers and or content creators
     is strictly prohibited in applications with software creation capabilities
     and or with the intent to profit from said restrictions.
	 
  4. This notice may not be removed or altered from any source
     distribution.
---------------------------------------------------------------------------------*/

#ifndef _BAG_FT_WRAPPER_
#define _BAG_FT_WRAPPER_

//freetype 2 required stuff

#include "ds2sdk.h"
#include "../../../../include/ft2build.h"

#include FT_FREETYPE_H

#define FT_FLOOR(x) (((x) & -64) >> 6)
#define FT_CEIL(x) ((((x) + 63) & -64) >> 6)
#define FT_FIXED(x)     ((x) << 6)

#ifdef __cplusplus
extern "C" {
#endif


typedef struct FTFnt_s
{
	FT_Error err;
	FT_Library ft_lib;
	FT_Face ft_face;
	u32 size, fontSize;
	u8* buffer;
	bool init;
}FTFnt_t __attribute__ ((aligned (4)));


/** @defgroup FTWrappers Freetype Wrapper
 *  Wrappers for freetype library -not very optimized!
 *  @{
 */

/*! \fn void BAG_FT_FontFatUnload(FT_FNT *Font)
    \brief
		unloads a freetype font 
*/	
//extern void BAG_FT_FontFatUnload(FT_FNT *Font);




/*! \fn s8 BAG_FT_FontFatLoad(const char *filename, FT_FNT *Font)
    \brief
		Loads a TTF font from a file to specified Font struct.
	
	\~\param filename
		The name and path of font on the filesystem
	\~\param Font
		Font handle
		
	\~\return
		1 if successful
*/	
//extern s8 BAG_FT_FontFatLoad(const char *filename, FT_FNT *Font);




/*! \fn char BAG_FT_OutputText(u16 *Dest, int destWd, s16 x1, s16 y1, s16 x2, s16 y2, unsigned char *string, int fontsize, FT_FNT *Font, u16 color)
	\brief
		Standard output of text with freetype with AA support.
	\~\param Dest
		Destination display buffer
	\~\param destWd
		Width of display buffer in pixels
	\~\param x1
		Initial x position for displaying text
	\~\param y1
		Initial y position for displaying text
	\~\param x2
		A final X position limit
	\~\param y2
		A final Y position limit
	\~\param string
		Your text
	\~\param fontisze
		A size supplied as FT_FIXED(x) 
	\~\param Font
		Font handle
	\~\param color
		A 16 bit color value to print the text in
	\~\return
		How many characters are printed.
*/	
//extern s8 BAG_FT_OutputText(u16 *Dest, int destWd, s16 x1, s16 y1, s16 x2, s16 y2, unsigned char *string, int fontsize, FT_FNT *Font, u16 color);




/*! \def BAG_FT_ScrnOutputText( Dest, x1, y1, x2, y2, string, fontsize, Font, color )
    \brief
		Standard output of text with freetype. The destination width is predetermined to the screen width ( 256 )
		
	\~\param Dest
		Destination display buffer
	\~\param x1
		Initial x position for displaying text
	\~\param y1
		Initial y position for displaying text
	\~\param x2
		A final X position limit
	\~\param y2
		A final Y position limit
	\~\param string
		Your text
	\~\param fontisze
		A size supplied as FT_FIXED(x) 
	\~\param Font
		Font handle
	\~\param color
		A 16 bit color value to print the text in
		
	\~\return
		How many characters are printed.
*/	
/*#define BAG_FT_ScrnOutputText( Dest, x1, y1, x2, y2, string, fontsize, Font, color ) \
			BAG_FT_OutputText( Dest, 256, x1, y1, x2, y2, string, fontsize, Font, color);*/


			
			
/*! \fn char BAG_FT_OutputTextEx(u16 *Dest, int destWd, s16 x1,s16 y1,s16 x2, s16 y2,unsigned char *string,int fontsize, FT_FNT *Font,u16 color, int length)
    \brief
		Outputs a specified length of text with freetype.
		
	\~\param Dest
		Destination display buffer
	\~\param destWd
		Width of display buffer in pixels
	\~\param x1
		Initial x position for displaying text
	\~\param y1
		Initial y position for displaying text
	\~\param x2
		A final X position limit
	\~\param y2
		A final Y position limit
	\~\param string
		Your text
	\~\param fontisze
		A size supplied as FT_FIXED(x) 
	\~\param Font
		Font handle
	\~\param color
		A 16 bit color value to print the text in
	\~\param length
		Number of characters to output
		
	\~\return
		How many characters are printed.
*/	
//extern s8 BAG_FT_OutputTextEx(u16 *Dest, int destWd, s16 x1,s16 y1,s16 x2, s16 y2,unsigned char *string,int fontsize, FT_FNT *Font,u16 color, int length);




/*! \def #define BAG_FT_ScrnOutputTextEx( Dest, x1, y1, x2, y2, string, fontsize, Font, color )
    \brief
		Outputs a specified length of text with freetype. The destination width is predetermined to the screen width ( 256 )
		
	\~\param Dest
		Destination display buffer

	\~\param x1
		Initial x position for displaying text
	\~\param y1
		Initial y position for displaying text
	\~\param x2
		A final X position limit
	\~\param y2
		A final Y position limit
	\~\param string
		Your text
	\~\param fontisze
		A size supplied as FT_FIXED(x) 
	\~\param Font
		Font handle
	\~\param color
		A 16 bit color value to print the text in
	\~\param length
		Number of characters to output
*/	
/*#define BAG_FT_ScrnOutputTextEx( Dest, x1, y1, x2, y2, string, fontsize, Font, color , length) \
			BAG_FT_OutputTextEx( Dest, 256, x1, y1, x2, y2, string, fontsize, Font, color, length);*/

			


//function s16 forms
/*#ifdef BAG_SHORTFORM

	#define BAG_FTUnload				BAG_FT_FontFatUnload
	#define BAG_FTLoad 				BAG_FT_FontFatLoad
	#define BAG_FTPrint					BAG_FT_OutputText
	#define BAG_FTPrintScrn			BAG_FT_ScrnOutputText
	#define BAG_FTPrintEx				BAG_FT_OutputTextEx
	#define BAG_FTPrintScrnEx		BAG_FT_ScrnOutputTextEx

#endif*/

/** @} */ // end of Freetype wrapper


#ifdef __cplusplus
}
#endif

#endif

