Commits

Bill Meltsner committed 0bba2aa

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

  • Participants
  • Parent commits a559920

Comments (0)

Files changed (2)

File src/modules/graphics/opengl/Font.cpp

 **/
 
 #include "Font.h"
+#include <font/GlyphData.h>
 
 #include <common/math.h>
 #include <math.h>
 	: height(data->getHeight()), lineHeight(1.25), mSpacing(1)
 	{
 		glyphs = new Glyph*[MAX_CHARS];
+		type = FONT_UNKNOWN;
+		love::font::GlyphData * gd;
 
 		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();
-			widths[i] = data->getGlyphData(i)->getWidth();
-			spacing[i] = data->getGlyphData(i)->getAdvance();
-			bearingX[i] = data->getGlyphData(i)->getBearingX();
-			bearingY[i] = data->getGlyphData(i)->getBearingY();
+			widths[i] = gd->getWidth();
+			spacing[i] = gd->getAdvance();
+			bearingX[i] = gd->getBearingX();
+			bearingY[i] = gd->getBearingY();
+			if (type == FONT_UNKNOWN) type = (gd->getFormat() == love::font::GlyphData::FORMAT_LUMINANCE_ALPHA ? FONT_TRUETYPE : FONT_IMAGE);
 		}
 	}
 
 			}
 			if (!glyphs[g]) g = 32; // space
 			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);
 			glPopMatrix();
 			glTranslatef(spacing[g], 0, 0);

File src/modules/graphics/opengl/Font.h

 	class Font : public Object, public Volatile
 	{
 	private:
+		
+		enum FontType
+		{
+			FONT_TRUETYPE = 1,
+			FONT_IMAGE,
+			FONT_UNKNOWN
+		};
 
 		int height;
 		float lineHeight;
 		float mSpacing; // modifies the spacing by multiplying it with this value
 		Glyph ** glyphs;
 		GLuint list; // the list of glyphs, for quicker drawing
+		FontType type;
 
 	public:
 		static const unsigned int MAX_CHARS = 256;