
#ifndef SPECTRE_GRAPHICS_FONT_H
#define SPECTRE_GRAPHICS_FONT_H

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

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

namespace sp {

class FontEngine;

// TODO: Fixup this api :)

class Font
{
public :

	struct Info {
		std::string name;
	};

	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;
	};

	FontEngine *m_engine;

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

	// Alpha Cache texture.
	mutable CacheTexture m_cacheTextureA;

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

}

#endif /* SPECTRE_GRAPHICS_FONT_H */
