aboutsummaryrefslogtreecommitdiff
path: root/libjin/Graphics/Font.h
diff options
context:
space:
mode:
Diffstat (limited to 'libjin/Graphics/Font.h')
-rw-r--r--libjin/Graphics/Font.h89
1 files changed, 37 insertions, 52 deletions
diff --git a/libjin/Graphics/Font.h b/libjin/Graphics/Font.h
index c04d64a..a39e6a6 100644
--- a/libjin/Graphics/Font.h
+++ b/libjin/Graphics/Font.h
@@ -16,90 +16,75 @@ namespace graphics
struct GlyphVertex
{
- float x, y;
- float u, v;
- GlyphVertex(float _x, float _y, float _u, float _v)
- {
- set(_x, _y, _u, _v);
- }
- void set(float _x, float _y, float _u, float _v)
- {
- x = _x;
- y = _y;
- u = _u;
- v = _v;
- }
+ int x, y; // screen coordinates
+ float u, v; // texture uv
};
struct GlyphArrayDrawInfo
{
GLuint texture;
- int startvertex;
- int vertexcount;
- };
-
- struct GlyphBox
- {
- float xoff, yoff;
- float width, height;
- void set(float x, float y, float w, float h)
- {
- xoff = x;
- yoff = y;
- width = w;
- height = h;
- }
+ unsigned int start;
+ unsigned int count;
};
struct Glyph
{
- GLuint atlas; // texture where this glyph rendered
- GlyphBox box; // glyph box
+ GLuint atlas;
+ /* normalized coordinates */
+ struct Bbox
+ {
+ float x, y;
+ float width, height;
+ } bbox;
+ /* glyph size in pixel */
+ unsigned int width, height;
};
class Font
{
- private:
- static const int DEFAULT_FONT_SIZE = 12;
-
public:
- static Font* createFont(FontData* fontData, unsigned int fontSzie = DEFAULT_FONT_SIZE);
+ typedef unsigned int Codepoint;
- void print(const char* text, int x, int y);
+ static Font* createFont(FontData* fontData, unsigned int fontSzie);
+ void print(const char* text, int x, int y);
#if defined(font_debug)
void drawAtlas();
#endif
private:
-
/* font atlas levels */
- //static const int TEXTURE_SIZE_LEVELS_COUNT = 7;
- //static const int TEXTURE_SIZE_LEVEL_MAX = TEXTURE_SIZE_LEVELS_COUNT - 1;
- //static const int TEXTURE_WIDTHS[TEXTURE_SIZE_LEVELS_COUNT];
- //static const int TEXTURE_HEIGHTS[TEXTURE_SIZE_LEVELS_COUNT];
- //static const int SPACES_PER_TAB = 4;
- static const int TEXTURE_SIZE = 512;
-
- Font(FontData* font, unsigned int fontSize);
+ static const int TEXTURE_SIZE_LEVELS_COUNT = 7;
+ static const int TEXTURE_SIZE_LEVEL_MAX = TEXTURE_SIZE_LEVELS_COUNT - 1;
+ static const int TEXTURE_WIDTHS[TEXTURE_SIZE_LEVELS_COUNT];
+ static const int TEXTURE_HEIGHTS[TEXTURE_SIZE_LEVELS_COUNT];
+
+ Font(FontData* font, Codepoint fontSize);
~Font();
+ void estimateSize();
bool createAtlas();
- Glyph* bakeGlyph(unsigned int character);
- Glyph* findGlyph(unsigned int character);
+ Glyph* bakeGlyph(Codepoint character);
+ Glyph* findGlyph(Codepoint character);
- //float getCharWidth(int c, int last);
- //int getTextWidth(const char* text);
+ int getCharWidth(int c);
+ int getCharHeight(int c);
+ int getTextWidth(const char* text);
+ int getTextHeight(const char* text);
+ void getTextBox(const char* text, int* w, int* h);
+ int textureWidth;
+ int textureHeight;
std::vector<GLuint> atlases;
- std::map<unsigned int, Glyph*> glyphs; // map glyph codepoint to Glyph
+ /* map unicode codepoint to glyph */
+ std::map<Codepoint, Glyph*> glyphs;
FontData* font;
const unsigned int fontsize;
- unsigned int baseline;
+ int baseline;
+ int descent;
/* cursor helped render to texture */
- float xoffset;
- float yoffset;
+ math::Vector2<float> cursor;
};