mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Merge branch 'master' into epub
Conflicts: unireader.lua
This commit is contained in:
22
djvu.c
22
djvu.c
@@ -71,7 +71,7 @@ static int handle(lua_State *L, ddjvu_context_t *ctx, int wait)
|
||||
|
||||
static int openDocument(lua_State *L) {
|
||||
const char *filename = luaL_checkstring(L, 1);
|
||||
/*const char *password = luaL_checkstring(L, 2);*/
|
||||
int cache_size = luaL_optint(L, 2, 10 << 20);
|
||||
|
||||
DjvuDocument *doc = (DjvuDocument*) lua_newuserdata(L, sizeof(DjvuDocument));
|
||||
luaL_getmetatable(L, "djvudocument");
|
||||
@@ -82,6 +82,9 @@ static int openDocument(lua_State *L) {
|
||||
return luaL_error(L, "cannot create context.");
|
||||
}
|
||||
|
||||
printf("## cache_size = %d\n", cache_size);
|
||||
ddjvu_cache_set_size(doc->context, (unsigned long)cache_size);
|
||||
|
||||
doc->doc_ref = ddjvu_document_create_by_filename_utf8(doc->context, filename, TRUE);
|
||||
while (! ddjvu_document_decoding_done(doc->doc_ref))
|
||||
handle(L, doc->context, True);
|
||||
@@ -447,6 +450,21 @@ static int drawPage(lua_State *L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
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);
|
||||
lua_pushnumber(L, size);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int cleanCache(lua_State *L) {
|
||||
DjvuDocument *doc = (DjvuDocument*) luaL_checkudata(L, 1, "djvudocument");
|
||||
printf("## ddjvu_cache_clear\n");
|
||||
ddjvu_cache_clear(doc->context);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct luaL_Reg djvu_func[] = {
|
||||
{"openDocument", openDocument},
|
||||
{NULL, NULL}
|
||||
@@ -458,6 +476,8 @@ static const struct luaL_Reg djvudocument_meth[] = {
|
||||
{"getToc", getTableOfContent},
|
||||
{"getPageText", getPageText},
|
||||
{"close", closeDocument},
|
||||
{"getCacheSize", getCacheSize},
|
||||
{"cleanCache", cleanCache},
|
||||
{"__gc", closeDocument},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
@@ -6,7 +6,7 @@ DJVUReader = UniReader:new{}
|
||||
-- DJVU does not support password yet
|
||||
function DJVUReader:open(filename)
|
||||
local ok
|
||||
ok, self.doc = pcall(djvu.openDocument, filename)
|
||||
ok, self.doc = pcall(djvu.openDocument, filename, self.cache_document_size)
|
||||
if not ok then
|
||||
return ok, self.doc -- this will be the error message instead
|
||||
end
|
||||
|
||||
10
einkfb.c
10
einkfb.c
@@ -150,6 +150,16 @@ static int einkUpdate(lua_State *L) {
|
||||
ioctl(fb->fd, FBIO_EINK_UPDATE_DISPLAY_AREA, &myarea);
|
||||
#else
|
||||
// for now, we only do fullscreen blits in emulation mode
|
||||
if (fxtype == 0) {
|
||||
// simmulate a full screen update in eink screen
|
||||
if(SDL_MUSTLOCK(fb->screen) && (SDL_LockSurface(fb->screen) < 0)) {
|
||||
return luaL_error(L, "can't lock surface.");
|
||||
}
|
||||
SDL_FillRect(fb->screen, NULL, 0x000000);
|
||||
if(SDL_MUSTLOCK(fb->screen)) SDL_UnlockSurface(fb->screen);
|
||||
SDL_Flip(fb->screen);
|
||||
}
|
||||
|
||||
if(SDL_MUSTLOCK(fb->screen) && (SDL_LockSurface(fb->screen) < 0)) {
|
||||
return luaL_error(L, "can't lock surface.");
|
||||
}
|
||||
|
||||
19
pdf.c
19
pdf.c
@@ -164,16 +164,16 @@ fz_alloc_context my_alloc_default =
|
||||
|
||||
static int openDocument(lua_State *L) {
|
||||
char *filename = strdup(luaL_checkstring(L, 1));
|
||||
int cachesize = luaL_optint(L, 2, 64 << 20); // 64 MB limit default
|
||||
int cache_size = luaL_optint(L, 2, 64 << 20); // 64 MB limit default
|
||||
char buf[15];
|
||||
printf("cachesize: %s\n",readable_fs(cachesize,buf));
|
||||
printf("## cache_size: %s\n",readable_fs(cache_size,buf));
|
||||
|
||||
PdfDocument *doc = (PdfDocument*) lua_newuserdata(L, sizeof(PdfDocument));
|
||||
|
||||
luaL_getmetatable(L, "pdfdocument");
|
||||
lua_setmetatable(L, -2);
|
||||
|
||||
doc->context = fz_new_context(&my_alloc_default, NULL, cachesize);
|
||||
doc->context = fz_new_context(&my_alloc_default, NULL, cache_size);
|
||||
|
||||
fz_try(doc->context) {
|
||||
doc->xref = fz_open_document(doc->context, filename);
|
||||
@@ -424,6 +424,17 @@ static int drawPage(lua_State *L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int getCacheSize(lua_State *L) {
|
||||
printf("## mupdf getCacheSize = %d\n", msize);
|
||||
lua_pushnumber(L, msize);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int cleanCache(lua_State *L) {
|
||||
printf("## mupdf cleanCache NOP\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct luaL_Reg pdf_func[] = {
|
||||
{"openDocument", openDocument},
|
||||
{NULL, NULL}
|
||||
@@ -436,6 +447,8 @@ static const struct luaL_Reg pdfdocument_meth[] = {
|
||||
{"getPages", getNumberOfPages},
|
||||
{"getToc", getTableOfContent},
|
||||
{"close", closeDocument},
|
||||
{"getCacheSize", getCacheSize},
|
||||
{"cleanCache", cleanCache},
|
||||
{"__gc", closeDocument},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
@@ -8,7 +8,7 @@ function PDFReader:open(filename)
|
||||
-- muPDF manages its own cache, set second parameter
|
||||
-- to the maximum size you want it to grow
|
||||
local ok
|
||||
ok, self.doc = pcall(pdf.openDocument, filename, 64*1024*1024)
|
||||
ok, self.doc = pcall(pdf.openDocument, filename, self.cache_document_size)
|
||||
if not ok then
|
||||
return false, self.doc -- will contain error message
|
||||
end
|
||||
|
||||
@@ -67,11 +67,12 @@ UniReader = {
|
||||
|
||||
-- tile cache configuration:
|
||||
cache_max_memsize = 1024*1024*5, -- 5MB tile cache
|
||||
cache_item_max_pixels = 1024*1024*2, -- max. size of rendered tiles
|
||||
cache_max_ttl = 20, -- time to live
|
||||
-- tile cache state:
|
||||
cache_current_memsize = 0,
|
||||
cache = {},
|
||||
-- renderer cache size
|
||||
cache_document_size = 1024*1024*8, -- FIXME random, needs testing
|
||||
|
||||
pagehash = nil,
|
||||
|
||||
@@ -107,7 +108,7 @@ end
|
||||
|
||||
-- open a file and its settings store
|
||||
-- tips: you can use self:loadSettings in open() method.
|
||||
function UniReader:open(filename, password)
|
||||
function UniReader:open(filename, cache_size)
|
||||
return false
|
||||
end
|
||||
|
||||
@@ -128,6 +129,18 @@ function UniReader:toggleTextHighLight(word_list)
|
||||
return
|
||||
end
|
||||
|
||||
----------------------------------------------------
|
||||
-- renderer memory
|
||||
----------------------------------------------------
|
||||
|
||||
function UniReader:getCacheSize()
|
||||
return -1
|
||||
end
|
||||
|
||||
function UniReader:cleanCache()
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
--[ following are default methods ]--
|
||||
function UniReader:initGlobalSettings(settings)
|
||||
@@ -145,11 +158,16 @@ function UniReader:initGlobalSettings(settings)
|
||||
if cache_max_ttl then
|
||||
self.cache_max_ttl = cache_max_ttl
|
||||
end
|
||||
|
||||
local rcountmax = settings:readSetting("partial_refresh_count")
|
||||
if rcountmax then
|
||||
self.rcountmax = rcountmax
|
||||
end
|
||||
end
|
||||
|
||||
function UniReader:loadSettings(filename)
|
||||
if self.doc ~= nil then
|
||||
self.settings = DocSettings:open(filename)
|
||||
self.settings = DocSettings:open(filename,self.cache_document_size)
|
||||
|
||||
local gamma = self.settings:readSetting("gamma")
|
||||
if gamma then
|
||||
@@ -198,6 +216,7 @@ function UniReader:cacheClaim(size)
|
||||
else
|
||||
-- cache slot is at end of life, so kick it out
|
||||
self.cache_current_memsize = self.cache_current_memsize - self.cache[k].size
|
||||
self.cache[k].bb:free()
|
||||
self.cache[k] = nil
|
||||
end
|
||||
end
|
||||
@@ -516,7 +535,7 @@ function UniReader:show(no)
|
||||
self:toggleTextHighLight(self.highlight[no])
|
||||
end
|
||||
|
||||
if self.rcount == self.rcountmax then
|
||||
if self.rcount >= self.rcountmax then
|
||||
print("full refresh")
|
||||
self.rcount = 1
|
||||
fb:refresh(0)
|
||||
@@ -800,11 +819,20 @@ end
|
||||
function UniReader:_drawReadingInfo()
|
||||
local ypos = height - 50
|
||||
local load_percent = (self.pageno / self.doc:getPages())
|
||||
|
||||
fb.bb:paintRect(0, ypos, width, 50, 0)
|
||||
|
||||
ypos = ypos + 15
|
||||
local face, fhash = Font:getFaceAndHash(22)
|
||||
|
||||
-- display memory on top of page
|
||||
fb.bb:paintRect(0, 0, width, 15+6*2, 0)
|
||||
renderUtf8Text(fb.bb, 10, 15+6, face, fhash,
|
||||
"Memory: "..
|
||||
math.ceil( self.cache_current_memsize / 1024 ).."/"..math.ceil( self.cache_max_memsize / 1024 )..
|
||||
" "..math.ceil( self.doc:getCacheSize() / 1024 ).."/"..math.ceil( self.cache_document_size / 1024 ).." k",
|
||||
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:getTocTitleByPage(self.pageno)
|
||||
if cur_section ~= "" then
|
||||
cur_section = "Section: "..cur_section
|
||||
@@ -828,6 +856,8 @@ function UniReader:showMenu()
|
||||
if ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_PRESS then
|
||||
if ev.code == KEY_BACK or ev.code == KEY_MENU then
|
||||
return
|
||||
elseif ev.code == KEY_C then
|
||||
self.doc:cleanCache()
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1061,6 +1091,12 @@ function UniReader:addAllCommands()
|
||||
unireader:showHighLight()
|
||||
unireader:goto(unireader.pageno)
|
||||
end)
|
||||
self.commands:add(KEY_R, MOD_SHIFT, "R",
|
||||
"manual full screen refresh",
|
||||
function(unireader)
|
||||
unireader.rcount = 1
|
||||
fb:refresh(0)
|
||||
end)
|
||||
self.commands:add(KEY_HOME,nil,"Home",
|
||||
"exit application",
|
||||
function(unireader)
|
||||
|
||||
Reference in New Issue
Block a user