/*---------------------------------------------------------------------------------
 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_TEXT_H__
#define __BAG_TEXT_H__


#ifdef __cplusplus
extern "C" {
#endif


#include "../Display.h"
#include "FTText/FTTextSys.h"
#include "BitText/BitTextSys.h"

#define DEFAULT_UNICODE 8
#define DEFAULT_BITTEXT_SIZE 16
#define DEFAULT_FREETYPE_SIZE 16

typedef enum{
	TYPE_BITMAP,
	TYPE_FREETYPE,	
}FONT_TYPES;

typedef enum{
	TEXTROT_NORM,
	TEXTROT_RIGHT,
	TEXTROT_LEFT,
}FONT_ROTS;

struct FNTChar_s{
	//current character info
	char utf, rot;
	char character, character_uni16[2], character_uni32[4];
	FTFnt_t *freetype_font;
    BitFnt_t *bitmap_font;
	int drawx, drawy, x2, y2, newlinePos;
	u16 color;
	void (*blitChar) (u16 *, FT_Bitmap *, int, int, s16, s16, u16);
    void (*blitCharBit) (u16 *, int, int, BitFnt_t *, char, int, int, int, int, unsigned short);
} __attribute__ ((aligned (4)));

typedef struct FNTObj_s{
	char type;//bitmap or freetype system
	char utf;//unicode mode
	char rotMode;//rotated text mode
	FTFnt_t *freetype_font;
	BitFnt_t *bitmap_font;
	
	int (*loadFont) (const char *, struct FNTObj_s *);
	void (*unloadFont) (struct FNTObj_s *);
	void (*setRot)	(struct FNTChar_s *, char);
	struct FNTChar_s *(*drawChar) (u16 *, int, int, struct FNTChar_s *);
}FNTObj_t __attribute__ ((aligned (4)));




extern char *BAG_Font_GetType(FNTObj_t *font);
extern char *BAG_Font_GetRotMode(FNTObj_t *font);
extern char *BAG_Font_GetUnicode(FNTObj_t *font);

extern int BAG_Font_LoadFontExt(const char *filename, FNTObj_t *font);
extern int BAG_Font_LoadFontEx(const char *filename, FNTObj_t *font, char type, int size);
extern void BAG_Font_UnloadFont(FNTObj_t *font);
extern struct FNTChar_s BAG_Font_DrawCharacter(u16 *dest, int destWd, int destHt, FNTObj_t *font, char *output, int x, int y, int x2, int y2, u16 color);
extern int BAG_Font_DrawStringEx(u16 *dest, int destWd, int destHt, FNTObj_t *font, char *string, int x1, int y1, int x2, int y2, int length, u16 color);
extern int BAG_Print(u16 *dest, FNTObj_t *font, char *string, int x, int y, int x2, int y2, u16 color);


#ifdef __cplusplus
}
#endif


#endif
