diff --git a/cre.cpp b/cre.cpp index ffb1c8316..aaa6a8050 100644 --- a/cre.cpp +++ b/cre.cpp @@ -44,12 +44,11 @@ static int initCache(lua_State *L) { return 0; } -static int openDocument(lua_State *L) { - const char *file_name = luaL_checkstring(L, 1); - const char *style_sheet = luaL_checkstring(L, 2); - int width = luaL_checkint(L, 3); - int height = luaL_checkint(L, 4); - LVDocViewMode view_mode = (LVDocViewMode)luaL_checkint(L, 5); +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; CreDocument *doc = (CreDocument*) lua_newuserdata(L, sizeof(CreDocument)); @@ -66,11 +65,7 @@ static int openDocument(lua_State *L) { } doc->text_view->setViewMode(view_mode, -1); doc->text_view->Resize(width, height); - doc->text_view->LoadDocument(file_name); doc->text_view->setPageHeaderInfo(PGHDR_AUTHOR|PGHDR_TITLE|PGHDR_PAGE_NUMBER|PGHDR_PAGE_COUNT|PGHDR_CHAPTER_MARKS|PGHDR_CLOCK); - doc->text_view->setStatusFontFace(lString8("Droid Sans")); - doc->dom_doc = doc->text_view->getDocument(); - doc->text_view->Render(); return 1; } @@ -89,6 +84,17 @@ static int setGammaIndex(lua_State *L) { return 0; } +static int loadDocument(lua_State *L) { + CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument"); + const char *file_name = luaL_checkstring(L, 2); + + doc->text_view->LoadDocument(file_name); + doc->dom_doc = doc->text_view->getDocument(); + doc->text_view->Render(); + + return 0; +} + static int closeDocument(lua_State *L) { CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument"); @@ -637,7 +643,7 @@ static int findText(lua_State *L) { static const struct luaL_Reg cre_func[] = { {"initCache", initCache}, - {"openDocument", openDocument}, + {"newDocView", newDocView}, {"getFontFaces", getFontFaces}, {"getGammaIndex", getGammaIndex}, {"setGammaIndex", setGammaIndex}, @@ -646,6 +652,7 @@ static const struct luaL_Reg cre_func[] = { }; static const struct luaL_Reg credocument_meth[] = { + {"loadDocument", loadDocument}, /*--- get methods ---*/ {"getPages", getNumberOfPages}, {"getCurrentPage", getCurrentPage}, diff --git a/frontend/cache.lua b/frontend/cache.lua index 88e922a6a..9d51b2b42 100644 --- a/frontend/cache.lua +++ b/frontend/cache.lua @@ -30,6 +30,7 @@ Cache = { } function Cache:insert(key, object) + --@TODO add cache for different types of item 09.01 2013 (houqp) -- guarantee that we have enough memory in cache if(object.size > self.max_memsize) then -- we're not allowed to claim this much at all diff --git a/frontend/document/credocument.lua b/frontend/document/credocument.lua index f6ef05b56..2b5c05e53 100644 --- a/frontend/document/credocument.lua +++ b/frontend/document/credocument.lua @@ -80,6 +80,7 @@ CreDocument = Document:new{ line_space_percent = 100, default_font = "Droid Sans Fallback", + header_font = "Droid Sans Fallback", options = CreOptions, configurable = Configurable, } @@ -120,6 +121,11 @@ function CreDocument:engineInit() self.default_font = default_font end + local header_font = G_reader_settings:readSetting("header_font") + if header_font then + self.header_font = header_font + end + engine_initilized = true end end @@ -133,7 +139,7 @@ function CreDocument:init() if file_type == "zip" then -- NuPogodi, 20.05.12: read the content of zip-file -- and return extention of the 1st file - file_type = self:zipContentExt(filename) + file_type = self:zipContentExt(self.file) end -- these two format use the same css file if file_type == "html" then @@ -147,7 +153,7 @@ function CreDocument:init() -- @TODO check the default view_mode to a global user configurable -- variable 22.12 2012 (houqp) - ok, self._document = pcall(cre.openDocument, self.file, style_sheet, + ok, self._document = pcall(cre.newDocView, style_sheet, Screen:getWidth(), Screen:getHeight(), self.PAGE_VIEW_MODE) if not ok then self.error_message = self.doc -- will contain error message @@ -162,6 +168,10 @@ function CreDocument:init() --self._document:setDefaultInterlineSpace(self.line_space_percent) end +function CreDocument:loadDocument() + self._document:loadDocument(self.file) +end + function CreDocument:drawCurrentView(target, x, y, rect, pos) tile_bb = Blitbuffer.new(rect.w, rect.h) self._document:drawCurrentPage(tile_bb) @@ -249,6 +259,12 @@ function CreDocument:setViewMode(new_mode) end end +function CreDocument:setHeaderFont(new_font) + if new_font then + self._document:setHeaderFont(new_font) + end +end + function CreDocument:zoomFont(delta) self._document:zoomFont(delta) end @@ -261,6 +277,10 @@ function CreDocument:toggleFontBolder() self._document:toggleFontBolder() end +function CreDocument:setGammaIndex(index) + cre.setGammaIndex(index) +end + DocumentRegistry:addProvider("txt", "application/txt", CreDocument) DocumentRegistry:addProvider("epub", "application/epub", CreDocument) DocumentRegistry:addProvider("html", "application/html", CreDocument) diff --git a/frontend/ui/reader/readerfont.lua b/frontend/ui/reader/readerfont.lua index 8235498dd..5b221fb2d 100644 --- a/frontend/ui/reader/readerfont.lua +++ b/frontend/ui/reader/readerfont.lua @@ -5,7 +5,7 @@ ReaderFont = InputContainer:new{ font_menu_title = "Font Menu", face_table = nil, -- default gamma from crengine's lvfntman.cpp - gamma_index = 15, + gamma_index = nil, } function ReaderFont:init() @@ -57,22 +57,39 @@ function ReaderFont:onReadSettings(config) end self.ui.document:setFontFace(self.font_face) + self.header_font_face = config:readSetting("header_font_face") + if not self.header_font_face then + self.header_font_face = self.ui.document.header_font + end + self.ui.document:setHeaderFont(self.header_font_face) + self.font_size = config:readSetting("font_size") if not self.font_size then - self.font_size = self.ui.document:getFontSize() + --@TODO change this! 12.01 2013 (houqp) + self.font_size = 29 end self.ui.document:setFontSize(self.font_size) self.line_space_percent = config:readSetting("line_space_percent") if not self.line_space_percent then self.line_space_percent = 100 + else + self.ui.document:setInterlineSpacePercent(self.line_space_percent) end + self.gamma_index = config:readSetting("gamma_index") + if not self.gamma_index then + self.gamma_index = 15 + end + self.ui.document:setGammaIndex(self.gamma_index) + -- Dirty hack: we have to add folloing call in order to set -- m_is_rendered(member of LVDocView) to true. Otherwise position inside -- document will be reset to 0 on first view render. -- So far, I don't know why this call will alter the value of m_is_rendered. - self.ui:handleEvent(Event:new("UpdatePos")) + table.insert(self.ui.postInitCallback, function() + self.ui:handleEvent(Event:new("UpdatePos")) + end) end function ReaderFont:onShowFontMenu() @@ -176,10 +193,11 @@ function ReaderFont:onChangeFontGamma(direction) end function ReaderFont:onCloseDocument() - --@TODO save gamma index (houqp) self.ui.doc_settings:saveSetting("font_face", self.font_face) + self.ui.doc_settings:saveSetting("header_font_face", self.header_font_face) self.ui.doc_settings:saveSetting("font_size", self.font_size) self.ui.doc_settings:saveSetting("line_space_percent", self.line_space_percent) + self.ui.doc_settings:saveSetting("gamma_index", self.gamma_index) end function ReaderFont:setFont(face) diff --git a/frontend/ui/reader/readerrolling.lua b/frontend/ui/reader/readerrolling.lua index 892066332..afca73e2e 100644 --- a/frontend/ui/reader/readerrolling.lua +++ b/frontend/ui/reader/readerrolling.lua @@ -94,20 +94,26 @@ function ReaderRolling:onReadSettings(config) if not soe then self.show_overlap_enable = soe end - -- we read last_percent just for backward compatibility - local last_per = config:readSetting("last_percent") - if last_per then - self:gotoPercent(last_per) - -- we have to do a real pos change in self.ui.document._document to - -- update status information in CREngine. - self.ui.document:gotoPos(self.current_pos) - end local last_xp = config:readSetting("last_xpointer") if last_xp then - self:gotoXPointer(last_xp) - -- we have to do a real jump in self.ui.document._document to - -- update status information in CREngine. - self.ui.document:gotoXPointer(last_xp) + table.insert(self.ui.postInitCallback, function() + self:gotoXPointer(last_xp) + -- we have to do a real jump in self.ui.document._document to + -- update status information in CREngine. + self.ui.document:gotoXPointer(last_xp) + end) + end + -- we read last_percent just for backward compatibility + if not last_xp then + local last_per = config:readSetting("last_percent") + if last_per then + table.insert(self.ui.postInitCallback, function() + self:gotoPercent(last_per) + -- we have to do a real pos change in self.ui.document._document + -- to update status information in CREngine. + self.ui.document:gotoPos(self.current_pos) + end) + end end if self.view_mode == "page" then self.ui:handleEvent(Event:new("PageUpdate", self.ui.document:getCurrentPage())) diff --git a/frontend/ui/readerui.lua b/frontend/ui/readerui.lua index 220725677..876a1564a 100644 --- a/frontend/ui/readerui.lua +++ b/frontend/ui/readerui.lua @@ -34,9 +34,12 @@ ReaderUI = InputContainer:new{ start_pos = nil, -- password for document unlock password = nil, + + postInitCallback = nil, } function ReaderUI:init() + self.postInitCallback = {} -- if we are not the top level dialog ourselves, it must be given in the table if not self.dialog then self.dialog = self @@ -109,6 +112,10 @@ function ReaderUI:init() } table.insert(self, panner) else + -- make sure we load document first before calling any callback + table.insert(self.postInitCallback, function() + self.document:loadDocument() + end) -- rolling controller local roller = ReaderRolling:new{ dialog = self.dialog, @@ -144,6 +151,10 @@ function ReaderUI:init() self:handleEvent(Event:new("ReadSettings", self.doc_settings)) -- notify childs of dimensions self:handleEvent(Event:new("SetDimensions", self.dimen)) + + for _,v in ipairs(self.postInitCallback) do + v() + end end function ReaderUI:onSetDimensions(dimen)