/*
 * File      : font.h
 * This file is part of RT-Thread RTOS
 * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
 *
 * The license and distribution terms for this file may be
 * found in the file LICENSE in this distribution or at
 * http://www.rt-thread.org/license/LICENSE
 *
 * Change Logs:
 * Date           Author       Notes
 * 2009-10-16     Bernard      first version
 */
#ifndef __RTGUI_FONT_H__
#define __RTGUI_FONT_H__

#include <rtgui/rtgui.h>
#include <rtgui/list.h>

struct rtgui_font;
struct rtgui_dc;
struct rtgui_rect;

struct rtgui_font_engine
{
	/* font engine function */
	void (*font_init)(struct rtgui_font* font);
	void (*font_load)(struct rtgui_font* font);

	void (*font_draw_text)(struct rtgui_font* font, struct rtgui_dc* dc, const rt_uint8_t* text,
		rt_ubase_t len, struct rtgui_rect* rect);
	void (*font_get_metrics)(struct rtgui_font* font, const rt_uint8_t* text, struct rtgui_rect* rect);
};

/*
 * bitmap font engine
 */
/* bitmap font private data */
struct rtgui_font_bitmap
{
	/* bitmap data */
	const rt_uint8_t* bmp;

	rt_uint16_t width;
	rt_uint16_t height;

	rt_uint8_t first_char;
	rt_uint8_t last_char;
};
extern struct rtgui_font_engine bmp_font_engine;

struct rtgui_font
{
	/* font name */
	char* family;

	/* font height */
	rt_uint16_t height;

	/* refer count */
	rt_uint32_t refer_count;

	/* font engine */
	struct rtgui_font_engine* engine;

	/* font private data */
	void* data;

	/* the font list */
	rtgui_list_t list;
};
typedef struct rtgui_font rtgui_font_t;

void rtgui_font_system_init(void);
void rtgui_font_system_add_font(struct rtgui_font* font);
void rtgui_font_system_remove_font(struct rtgui_font* font);
struct rtgui_font* rtgui_font_default(void);
void rtgui_font_set_defaut(struct rtgui_font* font);

struct rtgui_font* rtgui_font_refer(const rt_uint8_t* family, rt_uint16_t height);
void rtgui_font_derefer(struct rtgui_font* font);

/* draw a text */
void rtgui_font_draw(struct rtgui_font* font, struct rtgui_dc* dc, const rt_uint8_t* text, rt_ubase_t len, struct rtgui_rect* rect);
int  rtgui_font_get_string_width(struct rtgui_font* font, const rt_uint8_t* text);
void rtgui_font_get_metrics(struct rtgui_font* font, const rt_uint8_t* text, struct rtgui_rect* rect);

#endif
