fix bug in addJump and addBookmark

Pointed out by kljohann, thanks.
Now addJump and addBookmark get notes
from specified pageno/xpointer instead
of current page.

* also fixed bug in page number counting
  in cre.cpp
pull/2/merge
Qingping Hou 12 years ago
parent 3306346dba
commit e282179793

@ -108,10 +108,10 @@ static int getPageFromXPointer(lua_State *L) {
CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument");
const char *xpointer_str = luaL_checkstring(L, 2);
int page = 0;
int page = 1;
ldomXPointer xp = doc->dom_doc->createXPointer(lString16(xpointer_str));
page = doc->text_view->getBookmarkPage(xp);
page = doc->text_view->getBookmarkPage(xp) + 1;
lua_pushinteger(L, page);
return 1;
@ -180,7 +180,7 @@ static int walkTableOfContent(lua_State *L, LVTocItem *toc, int *count) {
/* set subtable, Toc entry */
lua_newtable(L);
lua_pushstring(L, "page");
lua_pushnumber(L, toc_tmp->getPercent());
lua_pushnumber(L, toc_tmp->getPage()+1);
lua_settable(L, -3);
lua_pushstring(L, "xpointer");
@ -225,10 +225,6 @@ static int walkTableOfContent(lua_State *L, LVTocItem *toc, int *count) {
* },
* }
*
* Warnning: not like pdf or djvu support, page here refers to the
* percent of height within the document, not the real page number.
* We use page here just to keep consistent with other readers.
*
*/
static int getTableOfContent(lua_State *L) {
CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument");
@ -281,7 +277,7 @@ static int gotoPage(lua_State *L) {
CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument");
int pageno = luaL_checkint(L, 2);
doc->text_view->goToPage(pageno);
doc->text_view->goToPage(pageno-1);
return 0;
}

@ -244,6 +244,17 @@ end
----------------------------------------------------
-- TOC related methods
----------------------------------------------------
function CREReader:getTocTitleByPage(page_or_xpoint)
local page = 1
-- tranform xpointer to page
if type(page_or_xpoint) == "string" then
page = self.doc:getPageFromXPointer(page_or_xpoint)
else
page = page_or_xpoint
end
return self:_getTocTitleByPage(page)
end
function CREReader:getTocTitleOfCurrentPage()
return self:getTocTitleByPage(self.percent)
end

@ -191,7 +191,7 @@ function FileChooser:choose(ypos, height)
--[[
This might looks a little bit dirty for using callback.
But I cannot come up with a better solution for renewing
the height arguemtn according to screen rotation mode.
the height argument according to screen rotation mode.
The callback might also be useful for calling system
settings menu in the future.

@ -1339,7 +1339,7 @@ end
--]]
function UniReader:addJump(pageno)
-- build notes from TOC
local notes = self:getTocTitleOfCurrentPage()
local notes = self:getTocTitleByPage(pageno)
if notes ~= "" then
notes = "in "..notes
end
@ -1387,7 +1387,7 @@ function UniReader:addBookmark(pageno)
end
end
-- build notes from TOC
local notes = self:getTocTitleOfCurrentPage()
local notes = self:getTocTitleByPage(pageno)
if notes ~= "" then
notes = "in "..notes
end
@ -1531,7 +1531,13 @@ function UniReader:fillToc()
self.toc = self.doc:getToc()
end
-- getTocTitleByPage wrapper, so specific reader
-- can tranform pageno according its need
function UniReader:getTocTitleByPage(pageno)
return self:_getTocTitleByPage(pageno)
end
function UniReader:_getTocTitleByPage(pageno)
if not self.toc then
-- build toc when needed.
self:fillToc()

Loading…
Cancel
Save