
#ifndef SPECTRE_GRAPHCIS_FONT_H
#define SPECTRE_GRAPHCIS_FONT_H

#include <map>
#include <vector>
#include <string>

#include <Spectre/Math/Vector4.h>
#include <Spectre/Math/Vector2.h>
#include <Spectre/Graphics/Texture.h>

class FontDriver;

// TODO: Fixup this api :)

class Font
{
public :

	struct Info {
		std::string name;
	};

	struct Glyph {
		vec2b size;		// Width, Height of bounding box.
		vec2b offset;		// Offset from cursor where the box begins.
		unsigned char advance;

		//vec4u tex_coords;
		vec2u texture_origin;
		const Texture* texture; // Texture atlas.
	};

	Font();
	~Font();

	bool loadFromFile(const std::string& filename);

	bool loadFromMemory(const void *data);

	Glyph getGlyph(unsigned int code) const;

	const Texture* getTexture() const;

protected :

	bool loadData();

	void loadChar(unsigned char code) const;

	void createTexture();

	void resizeTexture() const;

	Vector2u findTextureRegion(const Image& img) const;

protected :

	struct CacheTexture {
		vec2u		texpos;
		unsigned	shelf;
		Texture		texture;
	};

	FontDriver *m_driver;

	mutable std::map<unsigned char, Glyph> m_charset;

	// Alpha Cache texture.
	mutable CacheTexture m_cacheTextureA;

	std::vector<unsigned char> m_rawData;
};

#endif /* SPECTRE_GRAPHCIS_FONT_H */
