mirror of
https://github.com/love2d/love.git
synced 2026-08-19 12:14:20 +02:00
Renamed Font:hasGlyph to Font:hasGlyphs, and expanded it to accept multiple arguments and full strings. Resolves issue #762.
This commit is contained in:
@@ -69,23 +69,30 @@ GlyphData *Rasterizer::getGlyphData(const std::string &text) const
|
|||||||
return getGlyphData(codepoint);
|
return getGlyphData(codepoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Rasterizer::hasGlyph(const std::string &text) const
|
bool Rasterizer::hasGlyphs(const std::string &text) const
|
||||||
{
|
{
|
||||||
if (text.size() == 0)
|
if (text.size() == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
uint32 codepoint = 0;
|
|
||||||
|
|
||||||
try
|
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)
|
catch (utf8::exception &e)
|
||||||
{
|
{
|
||||||
throw love::Exception("Decoding error: %s", e.what());
|
throw love::Exception("Decoding error: %s", e.what());
|
||||||
}
|
}
|
||||||
|
|
||||||
return hasGlyph(codepoint);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // font
|
} // font
|
||||||
|
|||||||
@@ -100,10 +100,10 @@ public:
|
|||||||
virtual bool hasGlyph(uint32 glyph) const = 0;
|
virtual bool hasGlyph(uint32 glyph) const = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets whether this Rasterizer has a specific glyph.
|
* Gets whether this Rasterizer has all the glyphs in a string.
|
||||||
* @param text The (UNICODE) glyph character.
|
* @param text The (UTF-8) string.
|
||||||
**/
|
**/
|
||||||
virtual bool hasGlyph(const std::string &text) const;
|
virtual bool hasGlyphs(const std::string &text) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
|||||||
@@ -97,17 +97,26 @@ int w_Rasterizer_getGlyphCount(lua_State *L)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int w_Rasterizer_hasGlyph(lua_State *L)
|
int w_Rasterizer_hasGlyphs(lua_State *L)
|
||||||
{
|
{
|
||||||
Rasterizer *t = luax_checkrasterizer(L, 1);
|
Rasterizer *t = luax_checkrasterizer(L, 1);
|
||||||
|
|
||||||
bool hasglyph = false;
|
bool hasglyph = false;
|
||||||
|
|
||||||
|
int count = lua_gettop(L) - 1;
|
||||||
|
count = count < 1 ? 1 : count;
|
||||||
|
|
||||||
EXCEPT_GUARD(
|
EXCEPT_GUARD(
|
||||||
if (lua_type(L, 2) == LUA_TSTRING)
|
for (int i = 2; i < count + 2; i++)
|
||||||
hasglyph = t->hasGlyph(luax_checkstring(L, 2));
|
{
|
||||||
else
|
if (lua_type(L, i) == LUA_TSTRING)
|
||||||
hasglyph = t->hasGlyph((uint32) luaL_checknumber(L, 2));
|
hasglyph = t->hasGlyphs(luax_checkstring(L, i));
|
||||||
|
else
|
||||||
|
hasglyph = t->hasGlyph((uint32) luaL_checknumber(L, i));
|
||||||
|
|
||||||
|
if (!hasglyph)
|
||||||
|
break;
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
luax_pushboolean(L, hasglyph);
|
luax_pushboolean(L, hasglyph);
|
||||||
@@ -123,7 +132,7 @@ static const luaL_Reg functions[] =
|
|||||||
{ "getLineHeight", w_Rasterizer_getLineHeight },
|
{ "getLineHeight", w_Rasterizer_getLineHeight },
|
||||||
{ "getGlyphData", w_Rasterizer_getGlyphData },
|
{ "getGlyphData", w_Rasterizer_getGlyphData },
|
||||||
{ "getGlyphCount", w_Rasterizer_getGlyphCount },
|
{ "getGlyphCount", w_Rasterizer_getGlyphCount },
|
||||||
{ "hasGlyph", w_Rasterizer_hasGlyph },
|
{ "hasGlyphs", w_Rasterizer_hasGlyphs },
|
||||||
{ 0, 0 }
|
{ 0, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ int w_Rasterizer_getDescent(lua_State *L);
|
|||||||
int w_Rasterizer_getLineHeight(lua_State *L);
|
int w_Rasterizer_getLineHeight(lua_State *L);
|
||||||
int w_Rasterizer_getGlyphData(lua_State *L);
|
int w_Rasterizer_getGlyphData(lua_State *L);
|
||||||
int w_Rasterizer_getGlyphCount(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);
|
extern "C" int luaopen_rasterizer(lua_State *L);
|
||||||
|
|
||||||
} // font
|
} // font
|
||||||
|
|||||||
@@ -557,9 +557,9 @@ bool Font::hasGlyph(uint32 glyph) const
|
|||||||
return rasterizer->hasGlyph(glyph);
|
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
|
} // opengl
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ public:
|
|||||||
float getBaseline() const;
|
float getBaseline() const;
|
||||||
|
|
||||||
bool hasGlyph(uint32 glyph) const;
|
bool hasGlyph(uint32 glyph) const;
|
||||||
bool hasGlyph(const std::string &text) const;
|
bool hasGlyphs(const std::string &text) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|||||||
@@ -135,17 +135,26 @@ int w_Font_getBaseline(lua_State *L)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int w_Font_hasGlyph(lua_State *L)
|
int w_Font_hasGlyphs(lua_State *L)
|
||||||
{
|
{
|
||||||
Font *t = luax_checkfont(L, 1);
|
Font *t = luax_checkfont(L, 1);
|
||||||
bool hasglyph = false;
|
bool hasglyph = false;
|
||||||
|
|
||||||
|
int count = lua_gettop(L) - 1;
|
||||||
|
count = count < 1 ? 1 : count;
|
||||||
|
|
||||||
EXCEPT_GUARD(
|
EXCEPT_GUARD(
|
||||||
if (lua_type(L, 2) == LUA_TSTRING)
|
for (int i = 2; i < count + 2; i++)
|
||||||
hasglyph = t->hasGlyph(luax_checkstring(L, 2));
|
{
|
||||||
else
|
if (lua_type(L, i) == LUA_TSTRING)
|
||||||
hasglyph = t->hasGlyph((uint32) luaL_checknumber(L, 2));
|
hasglyph = t->hasGlyphs(luax_checkstring(L, i));
|
||||||
)
|
else
|
||||||
|
hasglyph = t->hasGlyph((uint32) luaL_checknumber(L, i));
|
||||||
|
|
||||||
|
if (!hasglyph)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
luax_pushboolean(L, hasglyph);
|
luax_pushboolean(L, hasglyph);
|
||||||
return 1;
|
return 1;
|
||||||
@@ -163,7 +172,7 @@ static const luaL_Reg functions[] =
|
|||||||
{ "getAscent", w_Font_getAscent },
|
{ "getAscent", w_Font_getAscent },
|
||||||
{ "getDescent", w_Font_getDescent },
|
{ "getDescent", w_Font_getDescent },
|
||||||
{ "getBaseline", w_Font_getBaseline },
|
{ "getBaseline", w_Font_getBaseline },
|
||||||
{ "hasGlyph", w_Font_hasGlyph },
|
{ "hasGlyphs", w_Font_hasGlyphs },
|
||||||
{ 0, 0 }
|
{ 0, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ int w_Font_getFilter(lua_State *L);
|
|||||||
int w_Font_getAscent(lua_State *L);
|
int w_Font_getAscent(lua_State *L);
|
||||||
int w_Font_getDescent(lua_State *L);
|
int w_Font_getDescent(lua_State *L);
|
||||||
int w_Font_getBaseline(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);
|
extern "C" int luaopen_font(lua_State *L);
|
||||||
|
|
||||||
} // opengl
|
} // opengl
|
||||||
|
|||||||
Reference in New Issue
Block a user