mirror of
https://github.com/love2d/love.git
synced 2026-08-16 08:11:02 +02:00
Use unsigned ints instead of unsigned shorts to represent UTF8 font glyphs
This commit is contained in:
@@ -41,8 +41,8 @@ public:
|
||||
|
||||
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;
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace love
|
||||
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)
|
||||
|
||||
@@ -56,7 +56,7 @@ public:
|
||||
FORMAT_RGBA
|
||||
};
|
||||
|
||||
GlyphData(unsigned short glyph, GlyphMetrics glyphMetrics, Format f);
|
||||
GlyphData(unsigned int glyph, GlyphMetrics glyphMetrics, Format f);
|
||||
virtual ~GlyphData();
|
||||
|
||||
// Implements Data.
|
||||
@@ -115,7 +115,7 @@ public:
|
||||
|
||||
private:
|
||||
// The glyph itself
|
||||
unsigned short glyph;
|
||||
unsigned int glyph;
|
||||
|
||||
// Glyph metrics
|
||||
GlyphMetrics metrics;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
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)
|
||||
@@ -62,7 +62,7 @@ int ImageRasterizer::getLineHeight() const
|
||||
return getHeight();
|
||||
}
|
||||
|
||||
GlyphData *ImageRasterizer::getGlyphData(unsigned short glyph) const
|
||||
GlyphData *ImageRasterizer::getGlyphData(unsigned int glyph) const
|
||||
{
|
||||
GlyphMetrics gm;
|
||||
gm.height = metrics.height;
|
||||
|
||||
@@ -43,7 +43,7 @@ private:
|
||||
// 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
|
||||
@@ -54,12 +54,12 @@ private:
|
||||
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;
|
||||
|
||||
@@ -82,7 +82,7 @@ public:
|
||||
* 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.
|
||||
|
||||
@@ -49,7 +49,7 @@ Rasterizer *Font::newRasterizer(Data *data, int size)
|
||||
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];
|
||||
@@ -59,12 +59,12 @@ Rasterizer *Font::newRasterizer(love::image::ImageData *data, std::string glyphs
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -56,8 +56,8 @@ public:
|
||||
// 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;
|
||||
|
||||
@@ -68,7 +68,7 @@ int TrueTypeRasterizer::getLineHeight() const
|
||||
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;
|
||||
|
||||
@@ -50,7 +50,7 @@ public:
|
||||
|
||||
// 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:
|
||||
|
||||
@@ -67,7 +67,7 @@ int w_newRasterizer(lua_State *L)
|
||||
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);
|
||||
|
||||
@@ -160,7 +160,7 @@ void Font::createTexture()
|
||||
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();
|
||||
@@ -233,7 +233,7 @@ Font::Glyph *Font::addGlyph(const int glyph)
|
||||
return g;
|
||||
}
|
||||
|
||||
Font::Glyph *Font::findGlyph(const int glyph)
|
||||
Font::Glyph *Font::findGlyph(unsigned int glyph)
|
||||
{
|
||||
Glyph *g = glyphs[glyph];
|
||||
if (!g)
|
||||
@@ -273,7 +273,7 @@ void Font::print(const std::string &text, float x, float y, float letter_spacing
|
||||
|
||||
while (i != end)
|
||||
{
|
||||
int g = *i++;
|
||||
unsigned int g = *i++;
|
||||
|
||||
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());
|
||||
while (i != end)
|
||||
{
|
||||
int c = *i++;
|
||||
unsigned int c = *i++;
|
||||
g = findGlyph(c);
|
||||
width += static_cast<int>(g->spacing * mSpacing);
|
||||
}
|
||||
@@ -402,7 +402,7 @@ int Font::getWidth(const char *str)
|
||||
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;
|
||||
@@ -574,7 +574,7 @@ bool Font::loadVolatile()
|
||||
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())
|
||||
{
|
||||
|
||||
@@ -78,17 +78,17 @@ public:
|
||||
/**
|
||||
* 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
|
||||
@@ -191,7 +191,7 @@ private:
|
||||
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;
|
||||
|
||||
@@ -214,8 +214,8 @@ private:
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user