From 4e321697d373291618f1d666716dc4bbee0c1718 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Fri, 25 Oct 2013 21:56:32 -0300 Subject: [PATCH] Renamed Font:hasGlyph to Font:hasGlyphs, and expanded it to accept multiple arguments and full strings. Resolves issue #762. --- src/modules/font/Rasterizer.cpp | 17 ++++++++++++----- src/modules/font/Rasterizer.h | 6 +++--- src/modules/font/wrap_Rasterizer.cpp | 21 +++++++++++++++------ src/modules/font/wrap_Rasterizer.h | 2 +- src/modules/graphics/opengl/Font.cpp | 4 ++-- src/modules/graphics/opengl/Font.h | 2 +- src/modules/graphics/opengl/wrap_Font.cpp | 23 ++++++++++++++++------- src/modules/graphics/opengl/wrap_Font.h | 2 +- 8 files changed, 51 insertions(+), 26 deletions(-) diff --git a/src/modules/font/Rasterizer.cpp b/src/modules/font/Rasterizer.cpp index b8bb01fc4..d0d42a5cf 100644 --- a/src/modules/font/Rasterizer.cpp +++ b/src/modules/font/Rasterizer.cpp @@ -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 i(text.begin(), text.begin(), text.end()); + utf8::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 diff --git a/src/modules/font/Rasterizer.h b/src/modules/font/Rasterizer.h index 11c59356e..f8766bbb8 100644 --- a/src/modules/font/Rasterizer.h +++ b/src/modules/font/Rasterizer.h @@ -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: diff --git a/src/modules/font/wrap_Rasterizer.cpp b/src/modules/font/wrap_Rasterizer.cpp index 43b023413..4e32a7a73 100644 --- a/src/modules/font/wrap_Rasterizer.cpp +++ b/src/modules/font/wrap_Rasterizer.cpp @@ -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 } }; diff --git a/src/modules/font/wrap_Rasterizer.h b/src/modules/font/wrap_Rasterizer.h index f092e66b1..aea8ca63f 100644 --- a/src/modules/font/wrap_Rasterizer.h +++ b/src/modules/font/wrap_Rasterizer.h @@ -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 diff --git a/src/modules/graphics/opengl/Font.cpp b/src/modules/graphics/opengl/Font.cpp index 79736f4c6..76686b61f 100644 --- a/src/modules/graphics/opengl/Font.cpp +++ b/src/modules/graphics/opengl/Font.cpp @@ -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 diff --git a/src/modules/graphics/opengl/Font.h b/src/modules/graphics/opengl/Font.h index e139c1c8a..109343afa 100644 --- a/src/modules/graphics/opengl/Font.h +++ b/src/modules/graphics/opengl/Font.h @@ -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: diff --git a/src/modules/graphics/opengl/wrap_Font.cpp b/src/modules/graphics/opengl/wrap_Font.cpp index 38c5fd218..cee0c0339 100644 --- a/src/modules/graphics/opengl/wrap_Font.cpp +++ b/src/modules/graphics/opengl/wrap_Font.cpp @@ -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 } }; diff --git a/src/modules/graphics/opengl/wrap_Font.h b/src/modules/graphics/opengl/wrap_Font.h index 8cd05fe65..406896da6 100644 --- a/src/modules/graphics/opengl/wrap_Font.h +++ b/src/modules/graphics/opengl/wrap_Font.h @@ -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