diff --git a/djvu.c b/djvu.c index 17610e551..9b9fecd4e 100644 --- a/djvu.c +++ b/djvu.c @@ -230,6 +230,23 @@ static int getUsedBBox(lua_State *L) { return 4; } +static int getOriginalPageSize(lua_State *L) { + DjvuDocument *doc = (DjvuDocument*) luaL_checkudata(L, 1, "djvudocument"); + int pageno = luaL_checkint(L, 2); + + ddjvu_status_t r; + ddjvu_pageinfo_t info; + + while ((r=ddjvu_document_get_pageinfo( + doc->doc_ref, pageno-1, &info))context, TRUE); + } + + lua_pushnumber(L, info.width); + lua_pushnumber(L, info.height); + + return 2; +} /* * Return a table like following: @@ -472,7 +489,7 @@ static int drawPage(lua_State *L) { static int getCacheSize(lua_State *L) { DjvuDocument *doc = (DjvuDocument*) luaL_checkudata(L, 1, "djvudocument"); unsigned long size = ddjvu_cache_get_size(doc->context); - printf("## ddjvu_cache_get_size = %d\n", size); + printf("## ddjvu_cache_get_size = %d\n", (int)size); lua_pushnumber(L, size); return 1; } @@ -494,6 +511,7 @@ static const struct luaL_Reg djvudocument_meth[] = { {"getPages", getNumberOfPages}, {"getToc", getTableOfContent}, {"getPageText", getPageText}, + {"getOriginalPageSize", getOriginalPageSize}, {"close", closeDocument}, {"getCacheSize", getCacheSize}, {"cleanCache", cleanCache}, diff --git a/djvureader.lua b/djvureader.lua index 9da9c511c..034b58c3d 100644 --- a/djvureader.lua +++ b/djvureader.lua @@ -31,3 +31,14 @@ function DJVUReader:getText(pageno) return self.doc:getPageText(pageno) end +-- for incompatible API fixing +function DJVUReader:invertTextYAxel(pageno, text_table) + local _, height = self.doc:getOriginalPageSize(pageno) + for _,text in pairs(text_table) do + for _,line in ipairs(text) do + line.y0, line.y1 = (height - line.y1), (height - line.y0) + end + end + return text_table +end + diff --git a/settings.lua b/settings.lua index 4608ac563..e5e4204ea 100644 --- a/settings.lua +++ b/settings.lua @@ -1,5 +1,5 @@ DocSettings = { - } +} function DocToHistory(fullname) local i,j = 1,0 @@ -47,13 +47,22 @@ function DocSettings:open(docfile) stored.jump_history = stored.jumpstack stored.jumpstack = nil if not stored.jump_history.cur then - stored.jump_history.cur = 1 + -- set up new history head + stored.jump_history.cur = #stored.jump_history + 1 end end + -- update variable name if stored.globalzoommode ~= nil then stored.globalzoom_mode = stored.globalzoommode stored.globalzoommode = nil end + + if stored.highlight ~= nil then + local file_type = string.lower(string.match(docfile, ".+%.([^.]+)")) + if file_type == "djvu" then + stored.highlight.to_fix = {"djvu invert y axle"} + end + end stored.version = 2012.05 debug("upgraded", stored) end diff --git a/unireader.lua b/unireader.lua index a2c1e7f80..8cb3707e5 100644 --- a/unireader.lua +++ b/unireader.lua @@ -990,6 +990,20 @@ function UniReader:loadSettings(filename) local highlight = self.settings:readSetting("highlight") self.highlight = highlight or {} + if self.highlight.to_fix ~= nil then + for _,fix_item in ipairs(self.highlight.to_fix) do + if fix_item == "djvu invert y axle" then + InfoMessage:show("Updating HighLight data...", 1) + for pageno,text_table in pairs(self.highlight) do + if type(pageno) == "number" then + text_table = self:invertTextYAxel(pageno, text_table) + end + end + end + end + debug(self.highlight) + self.highlight.to_fix = nil + end local bbox = self.settings:readSetting("bbox") debug("bbox loaded ", bbox)