mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Merge branch 'master' into 35_manual_crop
This commit is contained in:
6
.gitignore
vendored
6
.gitignore
vendored
@@ -3,16 +3,10 @@ lua
|
||||
lua-*
|
||||
lsqlite3*
|
||||
sqlite-amalgamation*
|
||||
mupdf/
|
||||
djvulibre/
|
||||
luafilesystem/
|
||||
.reader.kpdfview.lua
|
||||
kpdfview
|
||||
djvulibre*
|
||||
|
||||
|
||||
/.cproject
|
||||
/.project
|
||||
/.reader.kpdfview
|
||||
/luafilesystem
|
||||
/mupdf
|
||||
|
||||
9
.gitmodules
vendored
Normal file
9
.gitmodules
vendored
Normal file
@@ -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
|
||||
7
Makefile
7
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
|
||||
|
||||
2
djvu.c
2
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) {
|
||||
|
||||
1
djvulibre
Submodule
1
djvulibre
Submodule
Submodule djvulibre added at 6c9aae4bac
1
luafilesystem
Submodule
1
luafilesystem
Submodule
Submodule luafilesystem added at 149e0fb8ec
1
mupdf
Submodule
1
mupdf
Submodule
Submodule mupdf added at ea671d1254
@@ -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()
|
||||
|
||||
126
unireader.lua
126
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,
|
||||
@@ -117,6 +120,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
|
||||
@@ -254,26 +264,39 @@ 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
|
||||
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)
|
||||
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.offset_y = -1 * y0 * self.globalzoom + (height - (self.globalzoom * (y1 - y0))) / 2
|
||||
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)
|
||||
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
|
||||
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
|
||||
@@ -416,6 +439,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)
|
||||
@@ -541,11 +615,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
|
||||
@@ -553,11 +625,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
|
||||
@@ -575,22 +645,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(self.doc:getPages()/90*10)
|
||||
elseif ev.code == KEY_3 then
|
||||
self:goto(self.doc:getPages()/90*20)
|
||||
elseif ev.code == KEY_4 then
|
||||
self:goto(self.doc:getPages()/90*30)
|
||||
elseif ev.code == KEY_5 then
|
||||
self:goto(self.doc:getPages()/90*40)
|
||||
elseif ev.code == KEY_6 then
|
||||
self:goto(self.doc:getPages()/90*50)
|
||||
elseif ev.code == KEY_7 then
|
||||
self:goto(self.doc:getPages()/90*60)
|
||||
elseif ev.code == KEY_8 then
|
||||
self:goto(self.doc:getPages()/90*70)
|
||||
elseif ev.code == KEY_9 then
|
||||
self:goto(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
|
||||
|
||||
Reference in New Issue
Block a user