diff options
author | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-05-30 18:55:14 +0000 |
---|---|---|
committer | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-05-30 18:55:14 +0000 |
commit | e3823fd901674e22269637a669ac2b3e2667dc9c (patch) | |
tree | f0fa592ea719f95b3ec38a766fab61019d57494c /src/utils/SkLua.cpp | |
parent | 9166bf57d89b9c2cd2c6f8b7dd99a50bf1f01f81 (diff) |
add script to scrape glyph usage in drawText calls
git-svn-id: http://skia.googlecode.com/svn/trunk@9353 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/utils/SkLua.cpp')
-rw-r--r-- | src/utils/SkLua.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/utils/SkLua.cpp b/src/utils/SkLua.cpp index 9aef50e98c..bd453e3d1b 100644 --- a/src/utils/SkLua.cpp +++ b/src/utils/SkLua.cpp @@ -12,6 +12,7 @@ #include "SkMatrix.h" #include "SkRRect.h" #include "SkString.h" +#include "SkTypeface.h" extern "C" { #include "lua.h" @@ -120,6 +121,11 @@ static void setfield_function(lua_State* L, lua_setfield(L, -2, key); } +static void setarray_number(lua_State* L, int index, double value) { + lua_pushnumber(L, value); + lua_rawseti(L, -2, index); +} + void SkLua::pushBool(bool value, const char key[]) { lua_pushboolean(fL, value); CHECK_SETFIELD(key); @@ -130,6 +136,13 @@ void SkLua::pushString(const char str[], const char key[]) { CHECK_SETFIELD(key); } +void SkLua::pushString(const char str[], size_t length, const char key[]) { + // TODO: how to do this w/o making a copy? + SkString s(str, length); + lua_pushstring(fL, s.c_str()); + CHECK_SETFIELD(key); +} + void SkLua::pushString(const SkString& str, const char key[]) { lua_pushstring(fL, str.c_str()); CHECK_SETFIELD(key); @@ -144,11 +157,25 @@ void SkLua::pushColor(SkColor color, const char key[]) { CHECK_SETFIELD(key); } +void SkLua::pushU32(uint32_t value, const char key[]) { + lua_pushnumber(fL, (double)value); + CHECK_SETFIELD(key); +} + void SkLua::pushScalar(SkScalar value, const char key[]) { lua_pushnumber(fL, SkScalarToLua(value)); CHECK_SETFIELD(key); } +void SkLua::pushArrayU16(const uint16_t array[], int count, const char key[]) { + lua_newtable(fL); + for (int i = 0; i < count; ++i) { + // make it base-1 to match lua convention + setarray_number(fL, i + 1, (double)array[i]); + } + CHECK_SETFIELD(key); +} + void SkLua::pushRect(const SkRect& r, const char key[]) { lua_newtable(fL); setfield_number(fL, "left", SkScalarToLua(r.fLeft)); @@ -314,6 +341,22 @@ static int lpaint_setColor(lua_State* L) { return 0; } +static int lpaint_getTextSize(lua_State* L) { + SkLua(L).pushScalar(get_obj<SkPaint>(L, 1)->getTextSize()); + return 1; +} + +static int lpaint_setTextSize(lua_State* L) { + get_obj<SkPaint>(L, 1)->setTextSize(lua2scalar(L, 2)); + return 0; +} + +static int lpaint_getFontID(lua_State* L) { + SkTypeface* face = get_obj<SkPaint>(L, 1)->getTypeface(); + SkLua(L).pushU32(SkTypeface::UniqueID(face)); + return 1; +} + static int lpaint_gc(lua_State* L) { get_obj<SkPaint>(L, 1)->~SkPaint(); return 0; @@ -324,6 +367,9 @@ static const struct luaL_Reg gSkPaint_Methods[] = { { "setAntiAlias", lpaint_setAntiAlias }, { "getColor", lpaint_getColor }, { "setColor", lpaint_setColor }, + { "getTextSize", lpaint_getTextSize }, + { "setTextSize", lpaint_setTextSize }, + { "getFontID", lpaint_getFontID }, { "__gc", lpaint_gc }, { NULL, NULL } }; |