First stage of improving the DjVu status info.

This commit is contained in:
Tigran Aivazian
2012-10-04 21:08:39 +01:00
parent 723be220ac
commit c7b82f938a
2 changed files with 61 additions and 4 deletions

20
djvu.c
View File

@@ -199,11 +199,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;
@@ -255,8 +254,20 @@ static int getOriginalPageSize(lua_State *L) {
lua_pushnumber(L, info.width);
lua_pushnumber(L, info.height);
lua_pushnumber(L, info.dpi);
return 2;
return 3;
}
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;
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);
}
/*
@@ -527,6 +538,7 @@ static const struct luaL_Reg djvudocument_meth[] = {
{"getToc", getTableOfContent},
{"getPageText", getPageText},
{"getOriginalPageSize", getOriginalPageSize},
{"getPageInfo", getPageInfo},
{"close", closeDocument},
{"getCacheSize", getCacheSize},
{"cleanCache", cleanCache},

View File

@@ -69,3 +69,48 @@ function DJVUReader:invertTextYAxel(pageno, text_table)
end
return text_table
end
-- used in UniReader:showMenu()
---[[
function DJVUReader:_drawReadingInfo()
local secs, usecs = util.gettime()
local width, height = G_width, G_height
local numpages = self.doc:getPages()
local load_percent = self.pageno/numpages
-- changed to be the same font group as originaly intended
local face = Font:getFace("rifont", 20)
--local page_width, page_height, page_dpi = self.doc:getOriginalPageSize(self.pageno)
local page_width, page_height, page_dpi = self.doc:getPageInfo(self.pageno)
-- display memory 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,
"Gamma:"..tostring(self.globalgamma)..", "..
tostring(page_width).."x"..tostring(page_height)..", "..
tostring(page_dpi).."dpi", 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)
local nsecs, nusecs = util.gettime()
local diff = (nsecs - secs)*1000000 + nusecs - usecs
print("DJVUReader:_drawReadingInfo(): "..tostring(diff).." us")
end
--]]