Renamed Font:hasGlyph to Font:hasGlyphs, and expanded it to accept multiple arguments and full strings. Resolves issue #762.

This commit is contained in:
Alex Szpakowski
2013-10-25 21:56:32 -03:00
parent b57256b3e5
commit 4e321697d3
8 changed files with 51 additions and 26 deletions
+12 -5
View File
@@ -69,23 +69,30 @@ GlyphData *Rasterizer::getGlyphData(const std::string &text) const
return getGlyphData(codepoint);
}
bool Rasterizer::hasGlyph(const std::string &text) const
bool Rasterizer::hasGlyphs(const std::string &text) const
{
if (text.size() == 0)
return false;
uint32 codepoint = 0;
try
{
codepoint = utf8::peek_next(text.begin(), text.end());
utf8::iterator<std::string::const_iterator> i(text.begin(), text.begin(), text.end());
utf8::iterator<std::string::const_iterator> end(text.end(), text.begin(), text.end());
while (i != end)
{
uint32 codepoint = *i++;
if (!hasGlyph(codepoint))
return false;
}
}
catch (utf8::exception &e)
{
throw love::Exception("Decoding error: %s", e.what());
}
return hasGlyph(codepoint);
return true;
}
} // font
+3 -3
View File
@@ -100,10 +100,10 @@ public:
virtual bool hasGlyph(uint32 glyph) const = 0;
/**
* Gets whether this Rasterizer has a specific glyph.
* @param text The (UNICODE) glyph character.
* Gets whether this Rasterizer has all the glyphs in a string.
* @param text The (UTF-8) string.
**/
virtual bool hasGlyph(const std::string &text) const;
virtual bool hasGlyphs(const std::string &text) const;
protected:
+15 -6
View File
@@ -97,17 +97,26 @@ int w_Rasterizer_getGlyphCount(lua_State *L)
return 1;
}
int w_Rasterizer_hasGlyph(lua_State *L)
int w_Rasterizer_hasGlyphs(lua_State *L)
{
Rasterizer *t = luax_checkrasterizer(L, 1);
bool hasglyph = false;
int count = lua_gettop(L) - 1;
count = count < 1 ? 1 : count;
EXCEPT_GUARD(
if (lua_type(L, 2) == LUA_TSTRING)
hasglyph = t->hasGlyph(luax_checkstring(L, 2));
else
hasglyph = t->hasGlyph((uint32) luaL_checknumber(L, 2));
for (int i = 2; i < count + 2; i++)
{
if (lua_type(L, i) == LUA_TSTRING)
hasglyph = t->hasGlyphs(luax_checkstring(L, i));
else
hasglyph = t->hasGlyph((uint32) luaL_checknumber(L, i));
if (!hasglyph)
break;
}
)
luax_pushboolean(L, hasglyph);
@@ -123,7 +132,7 @@ static const luaL_Reg functions[] =
{ "getLineHeight", w_Rasterizer_getLineHeight },
{ "getGlyphData", w_Rasterizer_getGlyphData },
{ "getGlyphCount", w_Rasterizer_getGlyphCount },
{ "hasGlyph", w_Rasterizer_hasGlyph },
{ "hasGlyphs", w_Rasterizer_hasGlyphs },
{ 0, 0 }
};
+1 -1
View File
@@ -38,7 +38,7 @@ int w_Rasterizer_getDescent(lua_State *L);
int w_Rasterizer_getLineHeight(lua_State *L);
int w_Rasterizer_getGlyphData(lua_State *L);
int w_Rasterizer_getGlyphCount(lua_State *L);
int w_Rasterizer_hasGlyph(lua_State *L);
int w_Rasterizer_hasGlyphs(lua_State *L);
extern "C" int luaopen_rasterizer(lua_State *L);
} // font
+2 -2
View File
@@ -557,9 +557,9 @@ bool Font::hasGlyph(uint32 glyph) const
return rasterizer->hasGlyph(glyph);
}
bool Font::hasGlyph(const std::string &text) const
bool Font::hasGlyphs(const std::string &text) const
{
return rasterizer->hasGlyph(text);
return rasterizer->hasGlyphs(text);
}
} // opengl
+1 -1
View File
@@ -135,7 +135,7 @@ public:
float getBaseline() const;
bool hasGlyph(uint32 glyph) const;
bool hasGlyph(const std::string &text) const;
bool hasGlyphs(const std::string &text) const;
private:
+16 -7
View File
@@ -135,17 +135,26 @@ int w_Font_getBaseline(lua_State *L)
return 1;
}
int w_Font_hasGlyph(lua_State *L)
int w_Font_hasGlyphs(lua_State *L)
{
Font *t = luax_checkfont(L, 1);
bool hasglyph = false;
int count = lua_gettop(L) - 1;
count = count < 1 ? 1 : count;
EXCEPT_GUARD(
if (lua_type(L, 2) == LUA_TSTRING)
hasglyph = t->hasGlyph(luax_checkstring(L, 2));
else
hasglyph = t->hasGlyph((uint32) luaL_checknumber(L, 2));
)
for (int i = 2; i < count + 2; i++)
{
if (lua_type(L, i) == LUA_TSTRING)
hasglyph = t->hasGlyphs(luax_checkstring(L, i));
else
hasglyph = t->hasGlyph((uint32) luaL_checknumber(L, i));
if (!hasglyph)
break;
}
)
luax_pushboolean(L, hasglyph);
return 1;
@@ -163,7 +172,7 @@ static const luaL_Reg functions[] =
{ "getAscent", w_Font_getAscent },
{ "getDescent", w_Font_getDescent },
{ "getBaseline", w_Font_getBaseline },
{ "hasGlyph", w_Font_hasGlyph },
{ "hasGlyphs", w_Font_hasGlyphs },
{ 0, 0 }
};
+1 -1
View File
@@ -43,7 +43,7 @@ int w_Font_getFilter(lua_State *L);
int w_Font_getAscent(lua_State *L);
int w_Font_getDescent(lua_State *L);
int w_Font_getBaseline(lua_State *L);
int w_Font_hasGlyph(lua_State *L);
int w_Font_hasGlyphs(lua_State *L);
extern "C" int luaopen_font(lua_State *L);
} // opengl