diff --git a/djvu.c b/djvu.c index 93fbd5dc1..fae6c7ad4 100644 --- a/djvu.c +++ b/djvu.c @@ -85,11 +85,10 @@ static int openDocument(lua_State *L) { ddjvu_cache_set_size(doc->context, (unsigned long)cache_size); doc->doc_ref = ddjvu_document_create_by_filename_utf8(doc->context, filename, TRUE); + if (! doc->doc_ref) + return luaL_error(L, "cannot open DjVu file <%s>", filename); while (! ddjvu_document_decoding_done(doc->doc_ref)) handle(L, doc->context, True); - if (! doc->doc_ref) { - return luaL_error(L, "cannot open DjVu file <%s>", filename); - } doc->pixelformat = ddjvu_format_create(DDJVU_FORMAT_GREY8, 0, NULL); if (! doc->pixelformat) { @@ -199,11 +198,10 @@ static int openPage(lua_State *L) { /* djvulibre counts page starts from 0 */ page->page_ref = ddjvu_page_create_by_pageno(doc->doc_ref, pageno - 1); + if (! page->page_ref) + return luaL_error(L, "cannot open page #%d", pageno); while (! ddjvu_page_decoding_done(page->page_ref)) handle(L, doc->context, TRUE); - if (! page->page_ref) { - return luaL_error(L, "cannot open page #%d", pageno); - } page->doc = doc; page->num = pageno; @@ -259,6 +257,63 @@ static int getOriginalPageSize(lua_State *L) { return 2; } +static int getPageInfo(lua_State *L) { + DjvuDocument *doc = (DjvuDocument*) luaL_checkudata(L, 1, "djvudocument"); + int pageno = luaL_checkint(L, 2); + ddjvu_page_t *djvu_page; + int page_width, page_height, page_dpi; + double page_gamma; + ddjvu_page_type_t page_type; + char *page_type_str; + + djvu_page = ddjvu_page_create_by_pageno(doc->doc_ref, pageno - 1); + if (! djvu_page) + return luaL_error(L, "cannot create djvu_page #%d", pageno); + + while (! ddjvu_page_decoding_done(djvu_page)) + handle(L, doc->context, TRUE); + + page_width = ddjvu_page_get_width(djvu_page); + lua_pushnumber(L, page_width); + + page_height = ddjvu_page_get_height(djvu_page); + lua_pushnumber(L, page_height); + + page_dpi = ddjvu_page_get_resolution(djvu_page); + lua_pushnumber(L, page_dpi); + + page_gamma = ddjvu_page_get_gamma(djvu_page); + lua_pushnumber(L, page_gamma); + + page_type = ddjvu_page_get_type(djvu_page); + switch (page_type) { + case DDJVU_PAGETYPE_UNKNOWN: + page_type_str = "UNKNOWN"; + break; + + case DDJVU_PAGETYPE_BITONAL: + page_type_str = "BITONAL"; + break; + + case DDJVU_PAGETYPE_PHOTO: + page_type_str = "PHOTO"; + break; + + case DDJVU_PAGETYPE_COMPOUND: + page_type_str = "COMPOUND"; + break; + + default: + page_type_str = "INVALID"; + break; + } + lua_pushstring(L, page_type_str); + + ddjvu_page_release(djvu_page); + + return 5; +} + /* * Return a table like following: * { @@ -527,6 +582,7 @@ static const struct luaL_Reg djvudocument_meth[] = { {"getToc", getTableOfContent}, {"getPageText", getPageText}, {"getOriginalPageSize", getOriginalPageSize}, + {"getPageInfo", getPageInfo}, {"close", closeDocument}, {"getCacheSize", getCacheSize}, {"cleanCache", cleanCache}, diff --git a/djvureader.lua b/djvureader.lua index 012c0ccc2..82b517686 100644 --- a/djvureader.lua +++ b/djvureader.lua @@ -69,3 +69,39 @@ function DJVUReader:invertTextYAxel(pageno, text_table) end return text_table end + +function DJVUReader:_drawReadingInfo() + local width, height = G_width, G_height + local numpages = self.doc:getPages() + local load_percent = self.pageno/numpages + local face = Font:getFace("rifont", 20) + local page_width, page_height, page_dpi, page_gamma, page_type = self.doc:getPageInfo(self.pageno) + + -- display memory, time, battery and DjVu info on top of page + fb.bb:paintRect(0, 0, width, 40+6*2, 0) + renderUtf8Text(fb.bb, 10, 15+6, face, + "M: ".. + math.ceil( self.cache_current_memsize / 1024 ).."/"..math.ceil( self.cache_max_memsize / 1024 ).."k, ".. + math.ceil( self.doc:getCacheSize() / 1024 ).."/"..math.ceil( self.cache_document_size / 1024 ).."k, ".. + os.date("%a %d %b %Y %T").. + " ["..BatteryLevel().."]", true) + renderUtf8Text(fb.bb, 10, 15+6+22, face, + "Gm:"..string.format("%.1f",self.globalgamma).." ["..tostring(page_gamma).."], ".. + tostring(page_width).."x"..tostring(page_height)..", ".. + tostring(page_dpi).."dpi, "..page_type, true) + + -- display reading progress on bottom of page + local ypos = height - 50 + fb.bb:paintRect(0, ypos, width, 50, 0) + ypos = ypos + 15 + local cur_section = self:getTocTitleOfCurrentPage() + if cur_section ~= "" then + cur_section = "Sec: "..cur_section + end + renderUtf8Text(fb.bb, 10, ypos+6, face, + "Page: "..self.pageno.."/"..numpages.." "..cur_section, true) + + ypos = ypos + 15 + blitbuffer.progressBar(fb.bb, 10, ypos, width-20, 15, + 5, 4, load_percent, 8) +end diff --git a/unireader.lua b/unireader.lua index 218ed7904..f1eaee61d 100644 --- a/unireader.lua +++ b/unireader.lua @@ -2317,9 +2317,9 @@ function UniReader:addAllCommands() end) -- NuPogodi, 03.09.12 : moved the exit commands from here to the end of hotkey list self.commands:addGroup("vol-/+",{Keydef:new(KEY_VPLUS,nil),Keydef:new(KEY_VMINUS,nil)}, - "decrease/increase gamma 25%", + "decrease/increase gamma 10%", function(unireader,keydef) - unireader:modifyGamma(keydef.keycode==KEY_VPLUS and 1.25 or 0.8) + unireader:modifyGamma(keydef.keycode==KEY_VPLUS and 1.1 or 0.9) end) --numeric key group local numeric_keydefs = {}