image fonts now print from the upper left like truetype fonts do (fixes #100)

This commit is contained in:
Bill Meltsner
2010-11-09 19:29:00 -05:00
parent 54f7a83662
commit 500e0f1417
2 changed files with 19 additions and 6 deletions
+11 -6
View File
@@ -19,6 +19,7 @@
**/ **/
#include "Font.h" #include "Font.h"
#include <font/GlyphData.h>
#include <common/math.h> #include <common/math.h>
#include <math.h> #include <math.h>
@@ -34,15 +35,19 @@ namespace opengl
: height(data->getHeight()), lineHeight(1.25), mSpacing(1) : height(data->getHeight()), lineHeight(1.25), mSpacing(1)
{ {
glyphs = new Glyph*[MAX_CHARS]; glyphs = new Glyph*[MAX_CHARS];
type = FONT_UNKNOWN;
love::font::GlyphData * gd;
for(unsigned int i = 0; i < MAX_CHARS; i++) for(unsigned int i = 0; i < MAX_CHARS; i++)
{ {
glyphs[i] = new Glyph(data->getGlyphData(i)); gd = data->getGlyphData(i);
glyphs[i] = new Glyph(gd);
glyphs[i]->load(); glyphs[i]->load();
widths[i] = data->getGlyphData(i)->getWidth(); widths[i] = gd->getWidth();
spacing[i] = data->getGlyphData(i)->getAdvance(); spacing[i] = gd->getAdvance();
bearingX[i] = data->getGlyphData(i)->getBearingX(); bearingX[i] = gd->getBearingX();
bearingY[i] = data->getGlyphData(i)->getBearingY(); bearingY[i] = gd->getBearingY();
if (type == FONT_UNKNOWN) type = (gd->getFormat() == love::font::GlyphData::FORMAT_LUMINANCE_ALPHA ? FONT_TRUETYPE : FONT_IMAGE);
} }
} }
@@ -82,7 +87,7 @@ namespace opengl
} }
if (!glyphs[g]) g = 32; // space if (!glyphs[g]) g = 32; // space
glPushMatrix(); glPushMatrix();
glTranslatef(0, round(getHeight()), 0); if (type == FONT_TRUETYPE) glTranslatef(0, round(getHeight()), 0);
glyphs[g]->draw(0, 0, 0, 1, 1, 0, 0); glyphs[g]->draw(0, 0, 0, 1, 1, 0, 0);
glPopMatrix(); glPopMatrix();
glTranslatef(spacing[g], 0, 0); glTranslatef(spacing[g], 0, 0);
+8
View File
@@ -39,11 +39,19 @@ namespace opengl
{ {
private: private:
enum FontType
{
FONT_TRUETYPE = 1,
FONT_IMAGE,
FONT_UNKNOWN
};
int height; int height;
float lineHeight; float lineHeight;
float mSpacing; // modifies the spacing by multiplying it with this value float mSpacing; // modifies the spacing by multiplying it with this value
Glyph ** glyphs; Glyph ** glyphs;
GLuint list; // the list of glyphs, for quicker drawing GLuint list; // the list of glyphs, for quicker drawing
FontType type;
public: public:
static const unsigned int MAX_CHARS = 256; static const unsigned int MAX_CHARS = 256;