From 20474ce4116f14dd84f7b50e9e60e6ec293bd578 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Wed, 7 Mar 2012 07:37:45 +0800 Subject: [PATCH 1/8] fix: page number in fast jump in percent use math.floor to convert page number to integer --- unireader.lua | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/unireader.lua b/unireader.lua index 9a86e1ae4..a1459ddbb 100644 --- a/unireader.lua +++ b/unireader.lua @@ -544,21 +544,21 @@ function UniReader:inputloop() elseif ev.code == KEY_1 then self:goto(1) elseif ev.code == KEY_2 then - self:goto(self.doc:getPages()/90*10) + self:goto(math.floor(self.doc:getPages()/90*10)) elseif ev.code == KEY_3 then - self:goto(self.doc:getPages()/90*20) + self:goto(math.floor(self.doc:getPages()/90*20)) elseif ev.code == KEY_4 then - self:goto(self.doc:getPages()/90*30) + self:goto(math.floor(self.doc:getPages()/90*30)) elseif ev.code == KEY_5 then - self:goto(self.doc:getPages()/90*40) + self:goto(math.floor(self.doc:getPages()/90*40)) elseif ev.code == KEY_6 then - self:goto(self.doc:getPages()/90*50) + self:goto(math.floor(self.doc:getPages()/90*50)) elseif ev.code == KEY_7 then - self:goto(self.doc:getPages()/90*60) + self:goto(math.floor(self.doc:getPages()/90*60)) elseif ev.code == KEY_8 then - self:goto(self.doc:getPages()/90*70) + self:goto(math.floor(self.doc:getPages()/90*70)) elseif ev.code == KEY_9 then - self:goto(self.doc:getPages()/90*80) + self:goto(math.floor(self.doc:getPages()/90*80)) elseif ev.code == KEY_0 then self:goto(self.doc:getPages()) elseif ev.code == KEY_A then From dce80b7b1c1139abe936e0f079adbe56711bad4b Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Wed, 7 Mar 2012 07:59:03 +0800 Subject: [PATCH 2/8] mod: change default offset in fit_page_width/height mode set to the top of page --- unireader.lua | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/unireader.lua b/unireader.lua index a1459ddbb..eef64d7de 100644 --- a/unireader.lua +++ b/unireader.lua @@ -233,24 +233,22 @@ function UniReader:setzoom(page) if self.globalzoommode == self.ZOOM_FIT_TO_CONTENT then if (x1 - x0) < pwidth then self.globalzoom = width / (x1 - x0) - self.offset_x = -1 * x0 * self.globalzoom - self.offset_y = -1 * y0 * self.globalzoom + (height - (self.globalzoom * (y1 - y0))) / 2 if height / (y1 - y0) < self.globalzoom then self.globalzoom = height / (y1 - y0) - self.offset_x = -1 * x0 * self.globalzoom + (width - (self.globalzoom * (x1 - x0))) / 2 - self.offset_y = -1 * y0 * self.globalzoom end + self.offset_x = -1 * x0 * self.globalzoom + self.offset_y = -1 * y0 * self.globalzoom end elseif self.globalzoommode == self.ZOOM_FIT_TO_CONTENT_WIDTH then if (x1 - x0) < pwidth then self.globalzoom = width / (x1 - x0) self.offset_x = -1 * x0 * self.globalzoom - self.offset_y = -1 * y0 * self.globalzoom + (height - (self.globalzoom * (y1 - y0))) / 2 + self.offset_y = -1 * y0 * self.globalzoom end elseif self.globalzoommode == self.ZOOM_FIT_TO_CONTENT_HEIGHT then if (y1 - y0) < pheight then self.globalzoom = height / (y1 - y0) - self.offset_x = -1 * x0 * self.globalzoom + (width - (self.globalzoom * (x1 - x0))) / 2 + self.offset_x = -1 * x0 * self.globalzoom self.offset_y = -1 * y0 * self.globalzoom end elseif self.globalzoommode == self.ZOOM_FIT_TO_CONTENT_HALF_WIDTH From 2ca5f2302ce917849bb066efbfe0315563f95dc4 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Wed, 7 Mar 2012 11:59:32 +0800 Subject: [PATCH 3/8] fix: set offset to top in unireader set offset to top even usedbox is larger than or equal to pagesize. --- unireader.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/unireader.lua b/unireader.lua index eef64d7de..9d2c26f0f 100644 --- a/unireader.lua +++ b/unireader.lua @@ -236,21 +236,21 @@ function UniReader:setzoom(page) if height / (y1 - y0) < self.globalzoom then self.globalzoom = height / (y1 - y0) end - self.offset_x = -1 * x0 * self.globalzoom - self.offset_y = -1 * y0 * self.globalzoom end + self.offset_x = -1 * x0 * self.globalzoom + self.offset_y = -1 * y0 * self.globalzoom elseif self.globalzoommode == self.ZOOM_FIT_TO_CONTENT_WIDTH then if (x1 - x0) < pwidth then self.globalzoom = width / (x1 - x0) - self.offset_x = -1 * x0 * self.globalzoom - self.offset_y = -1 * y0 * self.globalzoom end + self.offset_x = -1 * x0 * self.globalzoom + self.offset_y = -1 * y0 * self.globalzoom elseif self.globalzoommode == self.ZOOM_FIT_TO_CONTENT_HEIGHT then if (y1 - y0) < pheight then self.globalzoom = height / (y1 - y0) - self.offset_x = -1 * x0 * self.globalzoom - self.offset_y = -1 * y0 * self.globalzoom end + self.offset_x = -1 * x0 * self.globalzoom + self.offset_y = -1 * y0 * self.globalzoom elseif self.globalzoommode == self.ZOOM_FIT_TO_CONTENT_HALF_WIDTH or self.globalzoommode == self.ZOOM_FIT_TO_CONTENT_HALF_WIDTH_MARGIN then local margin = self.pan_margin From 68b94fa3378aa52fd2285dcd322a7270b6fd1e05 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Wed, 7 Mar 2012 17:57:27 +0800 Subject: [PATCH 4/8] mod: code clean up for KEY_2 to KEY_9 bindings inspired by commit: 796b42cc3629b755d7e5e458f779bbddb2deb9a7 --- unireader.lua | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/unireader.lua b/unireader.lua index 9d2c26f0f..bb18797c8 100644 --- a/unireader.lua +++ b/unireader.lua @@ -541,22 +541,8 @@ function UniReader:inputloop() self:modify_gamma( 0.8 ) elseif ev.code == KEY_1 then self:goto(1) - elseif ev.code == KEY_2 then - self:goto(math.floor(self.doc:getPages()/90*10)) - elseif ev.code == KEY_3 then - self:goto(math.floor(self.doc:getPages()/90*20)) - elseif ev.code == KEY_4 then - self:goto(math.floor(self.doc:getPages()/90*30)) - elseif ev.code == KEY_5 then - self:goto(math.floor(self.doc:getPages()/90*40)) - elseif ev.code == KEY_6 then - self:goto(math.floor(self.doc:getPages()/90*50)) - elseif ev.code == KEY_7 then - self:goto(math.floor(self.doc:getPages()/90*60)) - elseif ev.code == KEY_8 then - self:goto(math.floor(self.doc:getPages()/90*70)) - elseif ev.code == KEY_9 then - self:goto(math.floor(self.doc:getPages()/90*80)) + elseif ev.code >= KEY_2 and ev.code <= KEY_9 then + self:goto(math.floor(self.doc:getPages()/90*(ev.code-KEY_1)*10)) elseif ev.code == KEY_0 then self:goto(self.doc:getPages()) elseif ev.code == KEY_A then From f79ae48de8deaeca7d4dc101b040c2cb3a1c3770 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Wed, 7 Mar 2012 18:16:46 +0800 Subject: [PATCH 5/8] add: UniReader:initGlobalSettings() Use this method to read settings that may shared among all readers. For instance, pan_overlap_vertical --- reader.lua | 2 ++ unireader.lua | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/reader.lua b/reader.lua index e2d9db1e3..da64c633c 100755 --- a/reader.lua +++ b/reader.lua @@ -119,6 +119,8 @@ if r_cfont ~=nil then FontChooser.cfont = r_cfont end +-- initialize global settings shared among all readers +UniReader:initGlobalSettings(reader_settings) -- initialize specific readers PDFReader:init() DJVUReader:init() diff --git a/unireader.lua b/unireader.lua index bb18797c8..9d5dd9107 100644 --- a/unireader.lua +++ b/unireader.lua @@ -117,6 +117,13 @@ function UniReader:loadSettings(filename) return false end +function UniReader:initGlobalSettings(settings) + local pan_overlap_vertical = settings:readsetting("pan_overlap_vertical") + if pan_overlap_vertical then + self.pan_overlap_vertical = pan_overlap_vertical + end +end + -- guarantee that we have enough memory in cache function UniReader:cacheclaim(size) if(size > self.cache_max_memsize) then From bf267ef0ef37e2d33a66b7ddc6c16e2f216cabb8 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Wed, 7 Mar 2012 21:44:59 +0800 Subject: [PATCH 6/8] mod: add ZOOM_FIT_TO_CONTENT_WIDTH_PAN mode This mode is used with ZOOM_FIT_TO_CONTENT_WIDTH, so when press KEY_PGFWD, you jump to lower part of current page. When hit page bottom, you do a real page turn. It now behaviors the same like the native reader as I mentioned in issue #41. The first time you set to ZOOM_FIT_TO_CONTENT_WIDTH mode, the reader will setup proper zoom factor and offset, then switch to ZOOM_FIT_TO_CONTENT_WIDTH_PAN mode. When you hit the page bottom, the reader will set the mode back to ZOOM_FIT_TO_CONTENT_WIDTH mode and do a real page turn. --- unireader.lua | 89 ++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 77 insertions(+), 12 deletions(-) diff --git a/unireader.lua b/unireader.lua index 9d5dd9107..7c1c65069 100644 --- a/unireader.lua +++ b/unireader.lua @@ -11,8 +11,10 @@ UniReader = { ZOOM_FIT_TO_CONTENT = -4, ZOOM_FIT_TO_CONTENT_WIDTH = -5, ZOOM_FIT_TO_CONTENT_HEIGHT = -6, - ZOOM_FIT_TO_CONTENT_HALF_WIDTH_MARGIN = -7, - ZOOM_FIT_TO_CONTENT_HALF_WIDTH = -8, + ZOOM_FIT_TO_CONTENT_WIDTH_PAN = -7, + --ZOOM_FIT_TO_CONTENT_HEIGHT_PAN = -8, + ZOOM_FIT_TO_CONTENT_HALF_WIDTH_MARGIN = -9, + ZOOM_FIT_TO_CONTENT_HALF_WIDTH = -10, GAMMA_NO_GAMMA = 1.0, @@ -37,6 +39,7 @@ UniReader = { offset_y = 0, min_offset_x = 0, min_offset_y = 0, + content_top = 0, -- for ZOOM_FIT_TO_CONTENT_WIDTH_PAN (prevView) -- set panning distance shift_x = 100, @@ -252,6 +255,21 @@ function UniReader:setzoom(page) end self.offset_x = -1 * x0 * self.globalzoom self.offset_y = -1 * y0 * self.globalzoom + self.content_top = self.offset_y + -- enable pan mode in ZOOM_FIT_TO_CONTENT_WIDTH + self.globalzoommode = self.ZOOM_FIT_TO_CONTENT_WIDTH_PAN + elseif self.globalzoommode == self.ZOOM_FIT_TO_CONTENT_WIDTH_PAN then + if self.content_top == -2012 then + -- We must handle previous page turn as a special cases, + -- because we want to arrive at the bottom of previous page. + -- Since this a real page turn, we need to recalcunate stuff. + if (x1 - x0) < pwidth then + self.globalzoom = width / (x1 - x0) + end + self.offset_x = -1 * x0 * self.globalzoom + self.content_top = -1 * y0 * self.globalzoom + self.offset_y = fb.bb:getHeight() - self.fullheight + end elseif self.globalzoommode == self.ZOOM_FIT_TO_CONTENT_HEIGHT then if (y1 - y0) < pheight then self.globalzoom = height / (y1 - y0) @@ -398,6 +416,57 @@ function UniReader:goto(no) end end +function UniReader:nextView() + local pageno = self.pageno + + if self.globalzoommode == self.ZOOM_FIT_TO_CONTENT_WIDTH_PAN then + if self.offset_y <= self.min_offset_y then + -- hit content bottom, turn to next page + self.globalzoommode = self.ZOOM_FIT_TO_CONTENT_WIDTH + pageno = pageno + 1 + else + -- goto next view of current page + self.offset_y = self.offset_y - height + self.pan_overlap_vertical + end + else + -- not in fit to content width pan mode, just do a page turn + pageno = pageno + 1 + if self.pan_by_page then + -- we are in two column mode + self.offset_x = self.pan_x + self.offset_y = self.pan_y + end + end + + return pageno +end + +function UniReader:prevView() + local pageno = self.pageno + + if self.globalzoommode == self.ZOOM_FIT_TO_CONTENT_WIDTH_PAN then + if self.offset_y >= self.content_top then + -- hit content top, turn to previous page + -- set self.content_top with magic num to signal self:setzoom + self.content_top = -2012 + pageno = pageno - 1 + else + -- goto previous view of current page + self.offset_y = self.offset_y + height - self.pan_overlap_vertical + end + else + -- not in fit to content width pan mode, just do a page turn + pageno = pageno - 1 + if self.pan_by_page then + -- we are in two column mode + self.offset_x = self.pan_x + self.offset_y = self.pan_y + end + end + + return pageno +end + -- adjust global gamma setting function UniReader:modify_gamma(factor) print("modify_gamma, gamma="..self.globalgamma.." factor="..factor) @@ -514,11 +583,9 @@ function UniReader:inputloop() elseif Keys.altmode then self:setglobalzoom(self.globalzoom+self.globalzoom_orig*0.1) else - if self.pan_by_page then - self.offset_x = self.pan_x - self.offset_y = self.pan_y - end - self:goto(self.pageno + 1) + -- turn page forward + local pageno = self:nextView() + self:goto(pageno) end elseif ev.code == KEY_PGBCK or ev.code == KEY_LPGBCK then if Keys.shiftmode then @@ -526,11 +593,9 @@ function UniReader:inputloop() elseif Keys.altmode then self:setglobalzoom(self.globalzoom-self.globalzoom_orig*0.1) else - if self.pan_by_page then - self.offset_x = self.pan_x - self.offset_y = self.pan_y - end - self:goto(self.pageno - 1) + -- turn page back + local pageno = self:prevView() + self:goto(pageno) end elseif ev.code == KEY_BACK then if Keys.altmode then From 9bd93fe9c179784d7e4f5f62cfb01b25266c762d Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Wed, 7 Mar 2012 17:19:52 +0100 Subject: [PATCH 7/8] move third-party git checkouts into submodules #43 --- .gitignore | 6 ------ .gitmodules | 9 +++++++++ Makefile | 7 +------ djvulibre | 1 + luafilesystem | 1 + mupdf | 1 + 6 files changed, 13 insertions(+), 12 deletions(-) create mode 100644 .gitmodules create mode 160000 djvulibre create mode 160000 luafilesystem create mode 160000 mupdf diff --git a/.gitignore b/.gitignore index b15d2a355..f24e0285c 100644 --- a/.gitignore +++ b/.gitignore @@ -3,16 +3,10 @@ lua lua-* lsqlite3* sqlite-amalgamation* -mupdf/ -djvulibre/ -luafilesystem/ .reader.kpdfview.lua kpdfview -djvulibre* /.cproject /.project /.reader.kpdfview -/luafilesystem -/mupdf diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 000000000..77f6eecd4 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,9 @@ +[submodule "mupdf"] + path = mupdf + url = git://git.ghostscript.com/mupdf.git +[submodule "luafilesystem"] + path = luafilesystem + url = git://github.com/keplerproject/luafilesystem.git +[submodule "djvulibre"] + path = djvulibre + url = git://djvu.git.sourceforge.net/gitroot/djvu/djvulibre.git diff --git a/Makefile b/Makefile index bde046e89..b829c791c 100644 --- a/Makefile +++ b/Makefile @@ -95,15 +95,10 @@ lfs.o: $(LFSDIR)/src/lfs.c $(CC) -c $(CFLAGS) -I$(LUADIR)/src -I$(LFSDIR)/src $(LFSDIR)/src/lfs.c -o $@ fetchthirdparty: - -rm -Rf mupdf -rm -Rf lua lua-5.1.4* - -rm -Rf luafilesystem* - -rm -Rf $(DJVUDIR) - git clone git://git.ghostscript.com/mupdf.git + git submodule update ( cd mupdf ; wget http://www.mupdf.com/download/mupdf-thirdparty.zip && unzip mupdf-thirdparty.zip ) wget http://www.lua.org/ftp/lua-5.1.4.tar.gz && tar xvzf lua-5.1.4.tar.gz && ln -s lua-5.1.4 lua - git clone https://github.com/keplerproject/luafilesystem.git - git clone git://djvu.git.sourceforge.net/gitroot/djvu/djvulibre.git clean: -rm -f *.o kpdfview diff --git a/djvulibre b/djvulibre new file mode 160000 index 000000000..6c9aae4ba --- /dev/null +++ b/djvulibre @@ -0,0 +1 @@ +Subproject commit 6c9aae4baccfac12f076b8317f3177c475c44e57 diff --git a/luafilesystem b/luafilesystem new file mode 160000 index 000000000..149e0fb8e --- /dev/null +++ b/luafilesystem @@ -0,0 +1 @@ +Subproject commit 149e0fb8ec6295325e1e448bbe79b7e9bf2285aa diff --git a/mupdf b/mupdf new file mode 160000 index 000000000..ea671d125 --- /dev/null +++ b/mupdf @@ -0,0 +1 @@ +Subproject commit ea671d1254dad3b9ef5a8fbdd9729c3ada2a49b2 From dd8c1324b763eb4c3ae18e8dc90c23f8d5d6a7d1 Mon Sep 17 00:00:00 2001 From: HW Date: Wed, 7 Mar 2012 19:37:03 +0100 Subject: [PATCH 8/8] djvulibre wants utf8-based filenames to be handed differently. closes #47 --- djvu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/djvu.c b/djvu.c index 30514298e..02299433e 100644 --- a/djvu.c +++ b/djvu.c @@ -89,7 +89,7 @@ static int openDocument(lua_State *L) { return luaL_error(L, "cannot create context."); } - doc->doc_ref = ddjvu_document_create_by_filename(doc->context, filename, TRUE); + 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); if (! doc->doc_ref) {