From 8771bb8e656de3f0e7707e4a22e138c1d9977b3f Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Tue, 22 Jan 2013 06:26:28 +0800 Subject: [PATCH] API changes in cre.cpp * now css argument is removed from newDocView call. * when setStyleSheet method cannot read given css file, it clears all the applied style. * add setEmbeddedStyleSheet method. --- cre.cpp | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/cre.cpp b/cre.cpp index 6b9e02ef7..960b67844 100644 --- a/cre.cpp +++ b/cre.cpp @@ -45,11 +45,9 @@ static int initCache(lua_State *L) { } static int newDocView(lua_State *L) { - const char *style_sheet = luaL_checkstring(L, 1); - int width = luaL_checkint(L, 2); - int height = luaL_checkint(L, 3); - LVDocViewMode view_mode = (LVDocViewMode)luaL_checkint(L, 4); - lString8 css; + int width = luaL_checkint(L, 1); + int height = luaL_checkint(L, 2); + LVDocViewMode view_mode = (LVDocViewMode)luaL_checkint(L, 3); CreDocument *doc = (CreDocument*) lua_newuserdata(L, sizeof(CreDocument)); luaL_getmetatable(L, "credocument"); @@ -58,11 +56,8 @@ static int newDocView(lua_State *L) { doc->text_view = new LVDocView(); //doc->text_view->setBackgroundColor(0xFFFFFF); //doc->text_view->setTextColor(0x000000); - if (LVLoadStylesheetFile(lString16(style_sheet), css)){ - if (!css.empty()){ - doc->text_view->setStyleSheet(css); - } - } + //doc->text_view->doCommand(DCMD_SET_DOC_FONTS, 1); + //doc->text_view->doCommand(DCMD_SET_INTERNAL_STYLES, 1); doc->text_view->setViewMode(view_mode, -1); doc->text_view->Resize(width, height); doc->text_view->setPageHeaderInfo(PGHDR_AUTHOR|PGHDR_TITLE|PGHDR_PAGE_NUMBER|PGHDR_PAGE_COUNT|PGHDR_CHAPTER_MARKS|PGHDR_CLOCK); @@ -98,7 +93,7 @@ static int loadDocument(lua_State *L) { static int closeDocument(lua_State *L) { CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument"); - // should be save if called twice + /* should be save if called twice */ if(doc->text_view != NULL) { delete doc->text_view; doc->text_view = NULL; @@ -413,11 +408,21 @@ static int setStyleSheet(lua_State *L) { if (LVLoadStylesheetFile(lString16(style_sheet), css)){ doc->text_view->setStyleSheet(css); + } else { + doc->text_view->setStyleSheet(lString8()); } return 0; } +static int setEmbeddedStyleSheet(lua_State *L) { + CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument"); + + doc->text_view->doCommand(DCMD_SET_INTERNAL_STYLES, luaL_checkint(L, 2)); + + return 0; +} + static int toggleFontBolder(lua_State *L) { CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument"); @@ -677,6 +682,7 @@ static const struct luaL_Reg credocument_meth[] = { {"setFontSize", setFontSize}, {"setDefaultInterlineSpace", setDefaultInterlineSpace}, {"setStyleSheet", setStyleSheet}, + {"setEmbeddedStyleSheet", setEmbeddedStyleSheet}, /* --- control methods ---*/ {"gotoPage", gotoPage}, {"gotoPercent", gotoPercent}, @@ -705,7 +711,6 @@ int luaopen_cre(lua_State *L) { lua_pop(L, 1); luaL_register(L, "cre", cre_func); - /* initialize font manager for CREngine */ InitFontManager(lString8());