From 9e786e0eedea50facff9bbef0c8c6a7cc6f53114 Mon Sep 17 00:00:00 2001 From: Tigran Aivazian Date: Thu, 4 Oct 2012 08:26:08 +0100 Subject: [PATCH 01/13] Small typo that wasted millions of instructions. Now that #define CRENGINE_DEBUG is handled correctly, all those pesky messages from crengine are gone and so the performance of crereader should be much better --- remember that under some circumstances crengine generates literally THOUSANDS of debug messages per second (e.g. when complaining about corrupt TOC nodes and there are _plenty_ of fb2 files out there which have an invalid structure). --- cre.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cre.cpp b/cre.cpp index ef3aca8b1..6277233f4 100644 --- a/cre.cpp +++ b/cre.cpp @@ -575,7 +575,7 @@ int luaopen_cre(lua_State *L) { /* initialize font manager for CREngine */ InitFontManager(lString8()); -#ifdef DEBUG_CRENGINE +#if DEBUG_CRENGINE CRLog::setStdoutLogger(); CRLog::setLogLevel(CRLog::LL_DEBUG); #endif From e3d02cd578aef8d212f1c13ea3355977e4b34ae3 Mon Sep 17 00:00:00 2001 From: Tigran Aivazian Date: Thu, 4 Oct 2012 21:08:39 +0100 Subject: [PATCH 02/13] First stage of improving the DjVu status info. Conflicts: djvureader.lua --- djvu.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/djvu.c b/djvu.c index a34c46bfb..6182fb5f7 100644 --- a/djvu.c +++ b/djvu.c @@ -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); } /* @@ -535,6 +546,7 @@ static const struct luaL_Reg djvudocument_meth[] = { {"getToc", getTableOfContent}, {"getPageText", getPageText}, {"getOriginalPageSize", getOriginalPageSize}, + {"getPageInfo", getPageInfo}, {"close", closeDocument}, {"getCacheSize", getCacheSize}, {"cleanCache", cleanCache}, From 5fd9aac78015a3b2e7a26f460409cbaf79ceb67d Mon Sep 17 00:00:00 2001 From: Tigran Aivazian Date: Thu, 4 Oct 2012 22:08:52 +0100 Subject: [PATCH 03/13] Display DjVu info in the status line. The DjVu info shown in the status line includes: 1. Physical page dimensions. 2. Current value of gamma and (in square brackets) the value of the display for which the page was designed. 3. Page resolution (in dpi). 4. Page type. For the end-user probably the most useful bit is the page type as it helps him decide which rendering mode to choose for this page (and also explains why he can't see anything on the page --- e.g. when rendering some COMPOUND or PHOTO pages in B&W mode). For the developer the physical page dimensions are also interesting as they allow to estimate the amount of time needed for page decoding and cache efficiency. Conflicts: djvureader.lua --- djvu.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 50 insertions(+), 6 deletions(-) diff --git a/djvu.c b/djvu.c index 6182fb5f7..066956337 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) { @@ -254,20 +253,65 @@ static int getOriginalPageSize(lua_State *L) { lua_pushnumber(L, info.width); lua_pushnumber(L, info.height); - lua_pushnumber(L, info.dpi); - return 3; + 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) + 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; } /* From e191930684ba6ee08b76bb8ee13d3b5aaf54f960 Mon Sep 17 00:00:00 2001 From: Tigran Aivazian Date: Sat, 6 Oct 2012 13:17:21 +0100 Subject: [PATCH 04/13] Mention patch in the pre-requisites for building. On FC17 patch(1) command is not installed by default. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ee48f0504..e23f0b3a0 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Follow these steps: * install popen_noshell sources into subfolder "popen-noshell" * automatically fetch thirdparty sources with Makefile: - * make sure you have wget, unzip, git and svn installed + * make sure you have patch, wget, unzip, git and svn installed * run `make fetchthirdparty`. * adapt Makefile to your needs From 78c7007f439a004149a9e8d3b163462b12a4a6ad Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Tue, 9 Oct 2012 12:39:09 -0400 Subject: [PATCH 05/13] add todo for kerning in text widgets --- frontend/ui/widget.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/frontend/ui/widget.lua b/frontend/ui/widget.lua index c4ce3713e..630fa0589 100644 --- a/frontend/ui/widget.lua +++ b/frontend/ui/widget.lua @@ -204,6 +204,7 @@ function TextWidget:paintTo(bb, x, y) --self:_render() --end --bb:blitFrom(self._bb, x, y, 0, 0, self._length, self._bb:getHeight()) + --@TODO Don't use kerning for monospaced fonts. (houqp) renderUtf8Text(bb, x, y+self._height*0.7, self.face, self.text, true) end @@ -281,6 +282,8 @@ function TextBoxWidget:_render() for _,l in ipairs(v_list) do pen_x = 0 for _,w in ipairs(l) do + --@TODO Don't use kerning for monospaced fonts. (houqp) + -- refert to cb25029dddc42693cc7aaefbe47e9bd3b7e1a750 in master tree renderUtf8Text(self._bb, pen_x, y*0.8, self.face, w.word, true) pen_x = pen_x + w.width + space_w end From cbfa0d53440faf299bcbd8462d203aa17a3db805 Mon Sep 17 00:00:00 2001 From: Tigran Aivazian Date: Sun, 7 Oct 2012 15:05:00 +0100 Subject: [PATCH 06/13] Generate git-rev file at compile time. The file git-rev containing the program's version should be generated at kpdfview compile time rather than package generation time. Conflicts: Makefile --- Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 0f27d4a1a..3789f8461 100644 --- a/Makefile +++ b/Makefile @@ -109,7 +109,9 @@ POPENNSLIB := $(POPENNSDIR)/libpopen_noshell.a all: kpdfview +VERSION?=$(shell git describe HEAD) kpdfview: kpdfview.o einkfb.o pdf.o blitbuffer.o drawcontext.o input.o $(POPENNSLIB) util.o ft.o lfs.o mupdfimg.o $(MUPDFLIBS) $(THIRDPARTYLIBS) $(LUALIB) djvu.o $(DJVULIBS) cre.o $(CRENGINELIBS) + echo $(VERSION) > git-rev $(CC) \ $(CFLAGS) \ kpdfview.o \ @@ -250,7 +252,6 @@ INSTALL_DIR=kindlepdfviewer LUA_FILES=reader.lua -VERSION?=$(shell git describe HEAD) customupdate: all # ensure that build binary is for ARM file kpdfview | grep ARM || exit 1 @@ -258,12 +259,11 @@ customupdate: all rm -f kindlepdfviewer-$(VERSION).zip rm -rf $(INSTALL_DIR) mkdir -p $(INSTALL_DIR)/{history,screenshots} - echo $(VERSION) > $(INSTALL_DIR)/git-rev cp -p README.md COPYING kpdfview kpdf.sh $(LUA_FILES) $(INSTALL_DIR) mkdir $(INSTALL_DIR)/data cp -rpL data/*.css $(INSTALL_DIR)/data cp -rpL fonts $(INSTALL_DIR) - cp -r resources $(INSTALL_DIR) + cp -r git-rev resources $(INSTALL_DIR) cp -rpL frontend $(INSTALL_DIR) mkdir $(INSTALL_DIR)/fonts/host zip -9 -r kindlepdfviewer-$(VERSION).zip $(INSTALL_DIR) launchpad/ kite/ From 604f635c467379546ee7ea26fca672d87f405d11 Mon Sep 17 00:00:00 2001 From: Tigran Aivazian Date: Mon, 8 Oct 2012 16:41:30 +0100 Subject: [PATCH 07/13] Cleanup of getUsedBBox() function. The function getUsedBBox() does not need to perform any operations on the DjvuPage structure, so there is no need to obtain it from Lua. --- djvu.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/djvu.c b/djvu.c index 066956337..aad2ac722 100644 --- a/djvu.c +++ b/djvu.c @@ -229,13 +229,10 @@ static int getPageSize(lua_State *L) { /* unsupported so fake it */ static int getUsedBBox(lua_State *L) { - DjvuPage *page = (DjvuPage*) luaL_checkudata(L, 1, "djvupage"); - lua_pushnumber(L, (double)0.01); lua_pushnumber(L, (double)0.01); lua_pushnumber(L, (double)-0.01); lua_pushnumber(L, (double)-0.01); - return 4; } From e3b567b2b136e3b8fb3da062d2cea26e4e5c5cf0 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Tue, 9 Oct 2012 16:08:34 -0400 Subject: [PATCH 08/13] fix kerning for Utf8Text family methods from tigran123 refer to master pullrequest #386 and #383, related commits are (all in master(kpv) tree): cb25029dddc42693cc7aaefbe47e9bd3b7e1a750 c7b4cf71f808a40d2461bac4e02bf8d2d4127327 379cba7b68cac6b00cc0ef74a7de6f18a174d838 --- frontend/ui/rendertext.lua | 41 +++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/frontend/ui/rendertext.lua b/frontend/ui/rendertext.lua index 743240916..9b4b492a6 100644 --- a/frontend/ui/rendertext.lua +++ b/frontend/ui/rendertext.lua @@ -47,10 +47,11 @@ function getSubTextByWidth(text, face, width, kerning) end function sizeUtf8Text(x, width, face, text, kerning) - if text == nil then + if not text then DEBUG("sizeUtf8Text called without text"); return end + -- may still need more adaptive pen placement when kerning, -- see: http://freetype.org/freetype2/docs/glyphs/glyphs-4.html local pen_x = 0 @@ -61,48 +62,46 @@ function sizeUtf8Text(x, width, face, text, kerning) if pen_x < (width - x) then local charcode = util.utf8charcode(uchar) local glyph = getGlyph(face, charcode) - if kerning and prevcharcode then - local kern = face.ftface:getKerning(prevcharcode, charcode) - pen_x = pen_x + kern - --DEBUG("prev:"..string.char(prevcharcode).." curr:"..string.char(charcode).." kern:"..kern) - else - --DEBUG("curr:"..string.char(charcode)) + if kerning and (prevcharcode ~= 0) then + pen_x = pen_x + face.ftface:getKerning(prevcharcode, charcode) end pen_x = pen_x + glyph.ax pen_y_top = math.max(pen_y_top, glyph.t) pen_y_bottom = math.max(pen_y_bottom, glyph.bb:getHeight() - glyph.t) --DEBUG("ax:"..glyph.ax.." t:"..glyph.t.." r:"..glyph.r.." h:"..glyph.bb:getHeight().." w:"..glyph.bb:getWidth().." yt:"..pen_y_top.." yb:"..pen_y_bottom) prevcharcode = charcode - end - end + end -- if pen_x < (width - x) + end -- for uchar return { x = pen_x, y_top = pen_y_top, y_bottom = pen_y_bottom} end function renderUtf8Text(buffer, x, y, face, text, kerning) - if text == nil then + if not text then DEBUG("renderUtf8Text called without text"); return 0 end + -- may still need more adaptive pen placement when kerning, -- see: http://freetype.org/freetype2/docs/glyphs/glyphs-4.html local pen_x = 0 local prevcharcode = 0 + local buffer_width = buffer:getWidth() for uchar in string.gfind(text, "([%z\1-\127\194-\244][\128-\191]*)") do - if pen_x < buffer:getWidth() then + if pen_x < buffer_width then local charcode = util.utf8charcode(uchar) local glyph = getGlyph(face, charcode) - if kerning and prevcharcode then - local kern = face.ftface:getKerning(prevcharcode, charcode) - pen_x = pen_x + kern - --DEBUG("prev:"..string.char(prevcharcode).." curr:"..string.char(charcode).." pen_x:"..pen_x.." kern:"..kern) - buffer:addblitFrom(glyph.bb, x + pen_x + glyph.l, y - glyph.t, 0, 0, glyph.bb:getWidth(), glyph.bb:getHeight()) - else - --DEBUG(" curr:"..string.char(charcode)) - buffer:blitFrom(glyph.bb, x + pen_x + glyph.l, y - glyph.t, 0, 0, glyph.bb:getWidth(), glyph.bb:getHeight()) + if kerning and (prevcharcode ~= 0) then + pen_x = pen_x + face.ftface:getKerning(prevcharcode, charcode) end + buffer:addblitFrom( + glyph.bb, + x + pen_x + glyph.l, y - glyph.t, + 0, 0, + glyph.bb:getWidth(), glyph.bb:getHeight()) pen_x = pen_x + glyph.ax prevcharcode = charcode - end - end + end -- if pen_x < buffer_width + end -- for uchar + return pen_x end From f641f50e2a4968245fbd1f95ce44bcc65f01d12f Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Tue, 9 Oct 2012 16:14:09 -0400 Subject: [PATCH 09/13] add comment for build version reading in the future --- reader.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/reader.lua b/reader.lua index e8e06ccc5..d6ae51c9a 100755 --- a/reader.lua +++ b/reader.lua @@ -121,6 +121,8 @@ local last_file = G_reader_settings:readSetting("lastfile") Screen:updateRotationMode() Screen.native_rotation_mode = Screen.cur_rotation_mode +--@TODO we can read version here, refer to commit in master tree: (houqp) +--87712cf0e43fed624f8a9f610be42b1fe174b9fe if ARGV[optind] then From 8ccbfba6cc8f3276d085aa872fed1dc781d6f7f2 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Tue, 9 Oct 2012 16:15:13 -0400 Subject: [PATCH 10/13] Djvu Validate patch from tigran123 refer to commit in master(kpv) tree: 64b6ef4afdd9d41402ad6cfc979f99b5e9e0e6dc --- frontend/document/djvudocument.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/frontend/document/djvudocument.lua b/frontend/document/djvudocument.lua index 31d3aa2e9..d8f627e06 100644 --- a/frontend/document/djvudocument.lua +++ b/frontend/document/djvudocument.lua @@ -9,6 +9,11 @@ DjvuDocument = Document:new{ } function DjvuDocument:init() + if not validDjvuFile(self.file) then + self.error_message = "Not a valid DjVu file" + return + end + local ok ok, self._document = pcall(djvu.openDocument, self.file, self.djvulibre_cache_size) if not ok then @@ -20,6 +25,16 @@ function DjvuDocument:init() self:_readMetadata() end +-- check DjVu magic string to validate +function validDjvuFile(filename) + f = io.open(filename, "r") + if not f then return false end + local magic = f:read(8) + f:close() + if not magic or magic ~= "AT&TFORM" then return false end + return true +end + function DjvuDocument:getUsedBBox(pageno) -- djvu does not support usedbbox, so fake it. local used = {} From 0d740d2b3bde47c1edd1b78c4c69f6eb2f6c7300 Mon Sep 17 00:00:00 2001 From: Tigran Aivazian Date: Tue, 9 Oct 2012 10:23:29 +0100 Subject: [PATCH 11/13] Optimize DjVu drawPage() function We only need to fill the image buffer with white colour if DjVu page rendering function did not fill it in with page data. --- djvu.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/djvu.c b/djvu.c index aad2ac722..27a215b2f 100644 --- a/djvu.c +++ b/djvu.c @@ -476,13 +476,11 @@ static int drawPage(lua_State *L) { unsigned char adjusted_low[16], adjusted_high[16]; int i, adjust_pixels = 0; ddjvu_rect_t pagerect, renderrect; - uint8_t *imagebuffer = malloc((bb->w)*(bb->h)+1); + int bbsize = (bb->w)*(bb->h)+1; + uint8_t *imagebuffer = malloc(bbsize); /*printf("@page %d, @@zoom:%f, offset: (%d, %d)\n", page->num, dc->zoom, dc->offset_x, dc->offset_y);*/ - /* fill pixel map with white color */ - memset(imagebuffer, 0xFF, (bb->w)*(bb->h)+1); - /* render full page into rectangle specified by pagerect */ pagerect.x = 0; pagerect.y = 0; @@ -513,13 +511,8 @@ static int drawPage(lua_State *L) { * So we don't set rotation here. */ - ddjvu_page_render(page->page_ref, - djvu_render_mode, - &pagerect, - &renderrect, - page->doc->pixelformat, - bb->w, - imagebuffer); + if (!ddjvu_page_render(page->page_ref, djvu_render_mode, &pagerect, &renderrect, page->doc->pixelformat, bb->w, imagebuffer)) + memset(imagebuffer, 0xFF, bbsize); uint8_t *bbptr = bb->data; uint8_t *pmptr = imagebuffer; From b012f1b037150ec7d27762f27ea1081ca376bbde Mon Sep 17 00:00:00 2001 From: HW Date: Tue, 9 Oct 2012 18:00:19 +0200 Subject: [PATCH 12/13] changed page number reading this is far from complete since in fact, we read page references which follow a more complex syntax. while specifying page numbers is one option for them, they might also specify page names. we currently do not yet have code for this case and we will return "-1" for all page references we can not parse. --- djvu.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/djvu.c b/djvu.c index 27a215b2f..c2ba5a5ca 100644 --- a/djvu.c +++ b/djvu.c @@ -17,6 +17,7 @@ */ #include #include +#include #include #include @@ -134,17 +135,28 @@ static int walkTableOfContent(lua_State *L, miniexp_t r, int *count, int depth) int length = miniexp_length(r); int counter = 0; - char page_number[6]; + const char* page_name; + int page_number; while(counter < length-1) { lua_pushnumber(L, *count); lua_newtable(L); lua_pushstring(L, "page"); - strcpy(page_number,miniexp_to_str(miniexp_car(miniexp_cdr(miniexp_nth(counter, lista))))); - /* page numbers appear as #11, set # to 0 so strtol works */ - page_number[0]= '0'; - lua_pushnumber(L, strtol(page_number, NULL, 10)); + page_name = miniexp_to_str(miniexp_car(miniexp_cdr(miniexp_nth(counter, lista)))); + if(page_name != NULL && page_name[0] == '#') { + errno = 0; + page_number = strtol(page_name + 1, NULL, 10); + if(!errno) { + lua_pushnumber(L, page_number); + } else { + /* we can not parse this as a number, TODO: parse page names */ + lua_pushnumber(L, -1); + } + } else { + /* something we did not expect here */ + lua_pushnumber(L, -1); + } lua_settable(L, -3); lua_pushstring(L, "depth"); From ea022b651f778f581df81ac060affe7c1517168e Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Tue, 9 Oct 2012 18:26:01 -0400 Subject: [PATCH 13/13] add rendermode support for djvu documents --- frontend/document/document.lua | 8 ++++---- frontend/ui/reader/readerview.lua | 13 +++++++++++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/frontend/document/document.lua b/frontend/document/document.lua index 9a173f183..f9ed27091 100644 --- a/frontend/document/document.lua +++ b/frontend/document/document.lua @@ -128,7 +128,7 @@ function Document:getToc() return self._document:getToc() end -function Document:renderPage(pageno, rect, zoom, rotation) +function Document:renderPage(pageno, rect, zoom, rotation, render_mode) local hash = "renderpg|"..self.file.."|"..pageno.."|"..zoom.."|"..rotation local page_size = self:getPageDimensions(pageno, zoom, rotation) -- this will be the size we actually render @@ -172,7 +172,7 @@ function Document:renderPage(pageno, rect, zoom, rotation) -- render local page = self._document:openPage(pageno) - page:draw(dc, tile.bb, size.x, size.y) + page:draw(dc, tile.bb, size.x, size.y, render_mode) page:close() Cache:insert(hash, tile) @@ -185,7 +185,7 @@ function Document:hintPage(pageno, zoom, rotation) self:renderPage(pageno, nil, zoom, rotation) end -function Document:drawPage(target, x, y, rect, pageno, zoom, rotation) +function Document:drawPage(target, x, y, rect, pageno, zoom, rotation, render_mode) local hash_full_page = "renderpg|"..self.file.."|"..pageno.."|"..zoom.."|"..rotation local hash_excerpt = "renderpg|"..self.file.."|"..pageno.."|"..zoom.."|"..rotation.."|"..tostring(rect) local tile = Cache:check(hash_full_page) @@ -193,7 +193,7 @@ function Document:drawPage(target, x, y, rect, pageno, zoom, rotation) tile = Cache:check(hash_excerpt) if not tile then DEBUG("rendering") - tile = self:renderPage(pageno, rect, zoom, rotation) + tile = self:renderPage(pageno, rect, zoom, rotation, render_mode) end end DEBUG("now painting", tile) diff --git a/frontend/ui/reader/readerview.lua b/frontend/ui/reader/readerview.lua index 1beaf1581..6f9c1ce94 100644 --- a/frontend/ui/reader/readerview.lua +++ b/frontend/ui/reader/readerview.lua @@ -9,8 +9,9 @@ ReaderView = WidgetContainer:new{ offset = {}, bbox = nil, }, - outer_page_color = 7, + -- DjVu page rendering mode (used in djvu.c:drawPage()) + render_mode = 0, -- default to COLOR visible_area = Geom:new{x = 0, y = 0}, page_area = Geom:new{}, @@ -41,7 +42,8 @@ function ReaderView:paintTo(bb, x, y) self.visible_area, self.state.page, self.state.zoom, - self.state.rotation) + self.state.rotation, + self.render_mode) else self.ui.document:drawCurrentView( bb, @@ -88,6 +90,10 @@ function ReaderView:onSetDimensions(dimensions) self:recalculate() end +function ReaderView:onReadSettings(config) + self.render_mode = config:readSetting("render_mode") or 0 +end + function ReaderView:onPageUpdate(new_page_no) self.state.page = new_page_no self:recalculate() @@ -108,3 +114,6 @@ function ReaderView:onRotationUpdate(rotation) self:recalculate() end +function ReaderView:onCloseDocument() + self.ui.doc_settings:saveSetting("render_mode", self.render_mode) +end