Commits

Alex Szpakowski committed 0a944fe

Use unsigned ints instead of unsigned shorts to represent UTF8 font glyphs

Comments (0)

Files changed (13)

src/modules/font/Font.h

 
 	virtual Rasterizer *newRasterizer(Data *data, int size) = 0;
 	virtual Rasterizer *newRasterizer(love::image::ImageData *data, std::string glyphs) = 0;
-	virtual Rasterizer *newRasterizer(love::image::ImageData *data, unsigned short *glyphs, int length) = 0;
-	virtual GlyphData *newGlyphData(Rasterizer *r, unsigned short glyph) = 0;
+	virtual Rasterizer *newRasterizer(love::image::ImageData *data, unsigned int *glyphs, int length) = 0;
+	virtual GlyphData *newGlyphData(Rasterizer *r, unsigned int glyph) = 0;
 
 	// Implement Module
 	virtual const char *getName() const = 0;

src/modules/font/GlyphData.cpp

 namespace font
 {
 
-GlyphData::GlyphData(unsigned short glyph, GlyphMetrics glyphMetrics, GlyphData::Format f)
+GlyphData::GlyphData(unsigned int glyph, GlyphMetrics glyphMetrics, GlyphData::Format f)
 	: glyph(glyph)
 	, metrics(glyphMetrics)
 	, data(0)

src/modules/font/GlyphData.h

 		FORMAT_RGBA
 	};
 
-	GlyphData(unsigned short glyph, GlyphMetrics glyphMetrics, Format f);
+	GlyphData(unsigned int glyph, GlyphMetrics glyphMetrics, Format f);
 	virtual ~GlyphData();
 
 	// Implements Data.
 
 private:
 	// The glyph itself
-	unsigned short glyph;
+	unsigned int glyph;
 
 	// Glyph metrics
 	GlyphMetrics metrics;

src/modules/font/ImageRasterizer.cpp

 	return (a.r == b.r && a.g == b.g && a.b == b.b && a.a == b.a);
 }
 
-ImageRasterizer::ImageRasterizer(love::image::ImageData *data, unsigned short *glyphs, int length)
+ImageRasterizer::ImageRasterizer(love::image::ImageData *data, unsigned int *glyphs, int length)
 	: imageData(data)
 	, glyphs(glyphs)
 	, length(length)
 	return getHeight();
 }
 
-GlyphData *ImageRasterizer::getGlyphData(unsigned short glyph) const
+GlyphData *ImageRasterizer::getGlyphData(unsigned int glyph) const
 {
 	GlyphMetrics gm;
 	gm.height = metrics.height;

src/modules/font/ImageRasterizer.h

 	// The image data
 	love::image::ImageData *imageData;
 	// The glyphs in the font
-	unsigned short *glyphs;
+	unsigned int *glyphs;
 	// The length of the glyph array
 	unsigned int length;
 	// The positions of each glyph
 	unsigned int *spacing;
 
 public:
-	ImageRasterizer(love::image::ImageData *imageData, unsigned short *glyphs, int length);
+	ImageRasterizer(love::image::ImageData *imageData, unsigned int *glyphs, int length);
 	virtual ~ImageRasterizer();
 
 	// Implement Rasterizer
 	virtual int getLineHeight() const;
-	virtual GlyphData *getGlyphData(unsigned short glyph) const;
+	virtual GlyphData *getGlyphData(unsigned int glyph) const;
 	virtual int getNumGlyphs() const;
 
 	static const unsigned int MAX_CHARS = 256;

src/modules/font/Rasterizer.h

 	 * Gets a specific glyph.
 	 * @param glyph The (UNICODE) glyph to get data for
 	 **/
-	virtual GlyphData *getGlyphData(unsigned short glyph) const = 0;
+	virtual GlyphData *getGlyphData(unsigned int glyph) const = 0;
 
 	/**
 	 * Gets the number of glyphs the rasterizer has data for.

src/modules/font/freetype/Font.cpp

 Rasterizer *Font::newRasterizer(love::image::ImageData *data, std::string glyphs)
 {
 	int length = glyphs.size();
-	unsigned short *g = new unsigned short[length];
+	unsigned int *g = new unsigned int[length];
 	for (int i = 0; i < length; i++)
 	{
 		g[i] = (unsigned char)glyphs[i];
 	return r;
 }
 
-Rasterizer *Font::newRasterizer(love::image::ImageData *data, unsigned short *glyphs, int length)
+Rasterizer *Font::newRasterizer(love::image::ImageData *data, unsigned int *glyphs, int length)
 {
 	return new ImageRasterizer(data, glyphs, length);
 }
 
-GlyphData *Font::newGlyphData(Rasterizer *r, unsigned short glyph)
+GlyphData *Font::newGlyphData(Rasterizer *r, unsigned int glyph)
 {
 	return r->getGlyphData(glyph);
 }

src/modules/font/freetype/Font.h

 	// Implements Font
 	Rasterizer *newRasterizer(Data *data, int size);
 	Rasterizer *newRasterizer(love::image::ImageData *data, std::string glyphs);
-	Rasterizer *newRasterizer(love::image::ImageData *data, unsigned short *glyphs, int length);
-	GlyphData *newGlyphData(Rasterizer *r, unsigned short glyph);
+	Rasterizer *newRasterizer(love::image::ImageData *data, unsigned int *glyphs, int length);
+	GlyphData *newGlyphData(Rasterizer *r, unsigned int glyph);
 
 	// Implement Module
 	const char *getName() const;

src/modules/font/freetype/TrueTypeRasterizer.cpp

 	return (int)(getHeight() * 1.25);
 }
 
-GlyphData *TrueTypeRasterizer::getGlyphData(unsigned short glyph) const
+GlyphData *TrueTypeRasterizer::getGlyphData(unsigned int glyph) const
 {
 	love::font::GlyphMetrics glyphMetrics;
 	FT_Glyph ftglyph;

src/modules/font/freetype/TrueTypeRasterizer.h

 
 	// Implement Rasterizer
 	virtual int getLineHeight() const;
-	virtual GlyphData *getGlyphData(unsigned short glyph) const;
+	virtual GlyphData *getGlyphData(unsigned int glyph) const;
 	virtual int getNumGlyphs() const;
 
 private:

src/modules/font/freetype/wrap_Font.cpp

 int w_newGlyphData(lua_State *L)
 {
 	Rasterizer *r = luax_checkrasterizer(L, 1);
-	unsigned short g = (unsigned short)luaL_checkint(L, 2);
+	unsigned int g = (unsigned int)luaL_checknumber(L, 2);
 
 	GlyphData *t = instance->newGlyphData(r, g);
 	luax_newtype(L, "GlyphData", FONT_GLYPH_DATA_T, t);

src/modules/graphics/opengl/Font.cpp

 	setMipmapSharpness(mipmapsharpness);
 }
 
-Font::Glyph *Font::addGlyph(const int glyph)
+Font::Glyph *Font::addGlyph(unsigned int glyph)
 {
 	love::font::GlyphData *gd = rasterizer->getGlyphData(glyph);
 	int w = gd->getWidth();
 	return g;
 }
 
-Font::Glyph *Font::findGlyph(const int glyph)
+Font::Glyph *Font::findGlyph(unsigned int glyph)
 {
 	Glyph *g = glyphs[glyph];
 	if (!g)
 
 		while (i != end)
 		{
-			int g = *i++;
+			unsigned int g = *i++;
 
 			if (g == '\n')
 			{
 			utf8::iterator<std::string::const_iterator> end(line.end(), line.begin(), line.end());
 			while (i != end)
 			{
-				int c = *i++;
+				unsigned int c = *i++;
 				g = findGlyph(c);
 				width += static_cast<int>(g->spacing * mSpacing);
 			}
 	return this->getWidth(std::string(str));
 }
 
-int Font::getWidth(const char character)
+int Font::getWidth(unsigned int character)
 {
 	Glyph *g = findGlyph(character);
 	return g->spacing;
 void Font::unloadVolatile()
 {
 	// nuke everything from orbit
-	std::map<int, Glyph *>::iterator it = glyphs.begin();
+	std::map<unsigned int, Glyph *>::iterator it = glyphs.begin();
 	Glyph *g;
 	while (it != glyphs.end())
 	{

src/modules/graphics/opengl/Font.h

 	/**
 	 * Returns the width of the passed string.
 	 *
-	 * @param line A line of text.
+	 * @param str A string of text.
 	 **/
-	int getWidth(const std::string &line);
-	int getWidth(const char *line);
+	int getWidth(const std::string &str);
+	int getWidth(const char *str);
 
 	/**
 	 * Returns the width of the passed character.
 	 *
 	 * @param character A character.
 	 **/
-	int getWidth(const char character);
+	int getWidth(unsigned int character);
 
 	/**
 	 * Returns the maximal width of a wrapped string
 	int texture_height;
 
 	std::vector<GLuint> textures; // vector of packed textures
-	std::map<int, Glyph *> glyphs; // maps glyphs to quad information
+	std::map<unsigned int, Glyph *> glyphs; // maps glyphs to quad information
 	FontType type;
 	Image::Filter filter;
 
 
 	bool initializeTexture(GLint format);
 	void createTexture();
-	Glyph *addGlyph(const int glyph);
-	Glyph *findGlyph (const int glyph);
+	Glyph *addGlyph(unsigned int glyph);
+	Glyph *findGlyph(unsigned int glyph);
 }; // Font
 
 } // opengl