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

This commit is contained in:
Alex Szpakowski
2013-01-22 23:43:35 -04:00
parent ba4cf6204d
commit 022f549554
13 changed files with 32 additions and 32 deletions
+2 -2
View File
@@ -41,8 +41,8 @@ public:
virtual Rasterizer *newRasterizer(Data *data, int size) = 0; 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, std::string glyphs) = 0;
virtual Rasterizer *newRasterizer(love::image::ImageData *data, unsigned short *glyphs, int length) = 0; virtual Rasterizer *newRasterizer(love::image::ImageData *data, unsigned int *glyphs, int length) = 0;
virtual GlyphData *newGlyphData(Rasterizer *r, unsigned short glyph) = 0; virtual GlyphData *newGlyphData(Rasterizer *r, unsigned int glyph) = 0;
// Implement Module // Implement Module
virtual const char *getName() const = 0; virtual const char *getName() const = 0;
+1 -1
View File
@@ -27,7 +27,7 @@ namespace love
namespace font namespace font
{ {
GlyphData::GlyphData(unsigned short glyph, GlyphMetrics glyphMetrics, GlyphData::Format f) GlyphData::GlyphData(unsigned int glyph, GlyphMetrics glyphMetrics, GlyphData::Format f)
: glyph(glyph) : glyph(glyph)
, metrics(glyphMetrics) , metrics(glyphMetrics)
, data(0) , data(0)
+2 -2
View File
@@ -56,7 +56,7 @@ public:
FORMAT_RGBA FORMAT_RGBA
}; };
GlyphData(unsigned short glyph, GlyphMetrics glyphMetrics, Format f); GlyphData(unsigned int glyph, GlyphMetrics glyphMetrics, Format f);
virtual ~GlyphData(); virtual ~GlyphData();
// Implements Data. // Implements Data.
@@ -115,7 +115,7 @@ public:
private: private:
// The glyph itself // The glyph itself
unsigned short glyph; unsigned int glyph;
// Glyph metrics // Glyph metrics
GlyphMetrics metrics; GlyphMetrics metrics;
+2 -2
View File
@@ -34,7 +34,7 @@ inline bool equal(const love::image::pixel &a, const love::image::pixel &b)
return (a.r == b.r && a.g == b.g && a.b == b.b && a.a == b.a); 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) : imageData(data)
, glyphs(glyphs) , glyphs(glyphs)
, length(length) , length(length)
@@ -62,7 +62,7 @@ int ImageRasterizer::getLineHeight() const
return getHeight(); return getHeight();
} }
GlyphData *ImageRasterizer::getGlyphData(unsigned short glyph) const GlyphData *ImageRasterizer::getGlyphData(unsigned int glyph) const
{ {
GlyphMetrics gm; GlyphMetrics gm;
gm.height = metrics.height; gm.height = metrics.height;
+3 -3
View File
@@ -43,7 +43,7 @@ private:
// The image data // The image data
love::image::ImageData *imageData; love::image::ImageData *imageData;
// The glyphs in the font // The glyphs in the font
unsigned short *glyphs; unsigned int *glyphs;
// The length of the glyph array // The length of the glyph array
unsigned int length; unsigned int length;
// The positions of each glyph // The positions of each glyph
@@ -54,12 +54,12 @@ private:
unsigned int *spacing; unsigned int *spacing;
public: public:
ImageRasterizer(love::image::ImageData *imageData, unsigned short *glyphs, int length); ImageRasterizer(love::image::ImageData *imageData, unsigned int *glyphs, int length);
virtual ~ImageRasterizer(); virtual ~ImageRasterizer();
// Implement Rasterizer // Implement Rasterizer
virtual int getLineHeight() const; virtual int getLineHeight() const;
virtual GlyphData *getGlyphData(unsigned short glyph) const; virtual GlyphData *getGlyphData(unsigned int glyph) const;
virtual int getNumGlyphs() const; virtual int getNumGlyphs() const;
static const unsigned int MAX_CHARS = 256; static const unsigned int MAX_CHARS = 256;
+1 -1
View File
@@ -82,7 +82,7 @@ public:
* Gets a specific glyph. * Gets a specific glyph.
* @param glyph The (UNICODE) glyph to get data for * @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. * Gets the number of glyphs the rasterizer has data for.
+3 -3
View File
@@ -49,7 +49,7 @@ Rasterizer *Font::newRasterizer(Data *data, int size)
Rasterizer *Font::newRasterizer(love::image::ImageData *data, std::string glyphs) Rasterizer *Font::newRasterizer(love::image::ImageData *data, std::string glyphs)
{ {
int length = glyphs.size(); 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++) for (int i = 0; i < length; i++)
{ {
g[i] = (unsigned char)glyphs[i]; g[i] = (unsigned char)glyphs[i];
@@ -59,12 +59,12 @@ Rasterizer *Font::newRasterizer(love::image::ImageData *data, std::string glyphs
return r; 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); 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); return r->getGlyphData(glyph);
} }
+2 -2
View File
@@ -56,8 +56,8 @@ public:
// Implements Font // Implements Font
Rasterizer *newRasterizer(Data *data, int size); Rasterizer *newRasterizer(Data *data, int size);
Rasterizer *newRasterizer(love::image::ImageData *data, std::string glyphs); Rasterizer *newRasterizer(love::image::ImageData *data, std::string glyphs);
Rasterizer *newRasterizer(love::image::ImageData *data, unsigned short *glyphs, int length); Rasterizer *newRasterizer(love::image::ImageData *data, unsigned int *glyphs, int length);
GlyphData *newGlyphData(Rasterizer *r, unsigned short glyph); GlyphData *newGlyphData(Rasterizer *r, unsigned int glyph);
// Implement Module // Implement Module
const char *getName() const; const char *getName() const;
@@ -68,7 +68,7 @@ int TrueTypeRasterizer::getLineHeight() const
return (int)(getHeight() * 1.25); return (int)(getHeight() * 1.25);
} }
GlyphData *TrueTypeRasterizer::getGlyphData(unsigned short glyph) const GlyphData *TrueTypeRasterizer::getGlyphData(unsigned int glyph) const
{ {
love::font::GlyphMetrics glyphMetrics; love::font::GlyphMetrics glyphMetrics;
FT_Glyph ftglyph; FT_Glyph ftglyph;
@@ -50,7 +50,7 @@ public:
// Implement Rasterizer // Implement Rasterizer
virtual int getLineHeight() const; virtual int getLineHeight() const;
virtual GlyphData *getGlyphData(unsigned short glyph) const; virtual GlyphData *getGlyphData(unsigned int glyph) const;
virtual int getNumGlyphs() const; virtual int getNumGlyphs() const;
private: private:
+1 -1
View File
@@ -67,7 +67,7 @@ int w_newRasterizer(lua_State *L)
int w_newGlyphData(lua_State *L) int w_newGlyphData(lua_State *L)
{ {
Rasterizer *r = luax_checkrasterizer(L, 1); 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); GlyphData *t = instance->newGlyphData(r, g);
luax_newtype(L, "GlyphData", FONT_GLYPH_DATA_T, t); luax_newtype(L, "GlyphData", FONT_GLYPH_DATA_T, t);
+6 -6
View File
@@ -160,7 +160,7 @@ void Font::createTexture()
setMipmapSharpness(mipmapsharpness); setMipmapSharpness(mipmapsharpness);
} }
Font::Glyph *Font::addGlyph(const int glyph) Font::Glyph *Font::addGlyph(unsigned int glyph)
{ {
love::font::GlyphData *gd = rasterizer->getGlyphData(glyph); love::font::GlyphData *gd = rasterizer->getGlyphData(glyph);
int w = gd->getWidth(); int w = gd->getWidth();
@@ -233,7 +233,7 @@ Font::Glyph *Font::addGlyph(const int glyph)
return g; return g;
} }
Font::Glyph *Font::findGlyph(const int glyph) Font::Glyph *Font::findGlyph(unsigned int glyph)
{ {
Glyph *g = glyphs[glyph]; Glyph *g = glyphs[glyph];
if (!g) if (!g)
@@ -273,7 +273,7 @@ void Font::print(const std::string &text, float x, float y, float letter_spacing
while (i != end) while (i != end)
{ {
int g = *i++; unsigned int g = *i++;
if (g == '\n') if (g == '\n')
{ {
@@ -380,7 +380,7 @@ int Font::getWidth(const std::string &str)
utf8::iterator<std::string::const_iterator> end(line.end(), line.begin(), line.end()); utf8::iterator<std::string::const_iterator> end(line.end(), line.begin(), line.end());
while (i != end) while (i != end)
{ {
int c = *i++; unsigned int c = *i++;
g = findGlyph(c); g = findGlyph(c);
width += static_cast<int>(g->spacing * mSpacing); width += static_cast<int>(g->spacing * mSpacing);
} }
@@ -402,7 +402,7 @@ int Font::getWidth(const char *str)
return this->getWidth(std::string(str)); return this->getWidth(std::string(str));
} }
int Font::getWidth(const char character) int Font::getWidth(unsigned int character)
{ {
Glyph *g = findGlyph(character); Glyph *g = findGlyph(character);
return g->spacing; return g->spacing;
@@ -574,7 +574,7 @@ bool Font::loadVolatile()
void Font::unloadVolatile() void Font::unloadVolatile()
{ {
// nuke everything from orbit // nuke everything from orbit
std::map<int, Glyph *>::iterator it = glyphs.begin(); std::map<unsigned int, Glyph *>::iterator it = glyphs.begin();
Glyph *g; Glyph *g;
while (it != glyphs.end()) while (it != glyphs.end())
{ {
+7 -7
View File
@@ -78,17 +78,17 @@ public:
/** /**
* Returns the width of the passed string. * 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 std::string &str);
int getWidth(const char *line); int getWidth(const char *str);
/** /**
* Returns the width of the passed character. * Returns the width of the passed character.
* *
* @param character A character. * @param character A character.
**/ **/
int getWidth(const char character); int getWidth(unsigned int character);
/** /**
* Returns the maximal width of a wrapped string * Returns the maximal width of a wrapped string
@@ -191,7 +191,7 @@ private:
int texture_height; int texture_height;
std::vector<GLuint> textures; // vector of packed textures 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; FontType type;
Image::Filter filter; Image::Filter filter;
@@ -214,8 +214,8 @@ private:
bool initializeTexture(GLint format); bool initializeTexture(GLint format);
void createTexture(); void createTexture();
Glyph *addGlyph(const int glyph); Glyph *addGlyph(unsigned int glyph);
Glyph *findGlyph (const int glyph); Glyph *findGlyph(unsigned int glyph);
}; // Font }; // Font
} // opengl } // opengl