Merge branch 'master' into djvu

Conflicts:
	reader.lua
pull/2/merge
Qingping Hou 12 years ago
commit 4a1a5233c0

@ -96,9 +96,11 @@ lfs.o: $(LFSDIR)/src/lfs.c
$(CC) -c $(CFLAGS) -I$(LUADIR)/src -I$(LFSDIR)/src $(LFSDIR)/src/lfs.c -o $@ $(CC) -c $(CFLAGS) -I$(LUADIR)/src -I$(LFSDIR)/src $(LFSDIR)/src/lfs.c -o $@
fetchthirdparty: fetchthirdparty:
-rmdir mupdf -rm -Rf mupdf
-rmdir lua -rm -Rf lua lua-5.1.4*
-rm lua -rm -Rf lsqlite3_svn08*
-rm -Rf sqlite-amalgamation-3070900*
-rm -Rf luafilesystem*
git clone git://git.ghostscript.com/mupdf.git git clone git://git.ghostscript.com/mupdf.git
( cd mupdf ; wget http://www.mupdf.com/download/mupdf-thirdparty.zip && unzip mupdf-thirdparty.zip ) ( 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 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

@ -144,10 +144,11 @@ function FileChooser:choose(ypos, height)
fb:refresh(0, 0, ypos, fb.bb:getWidth(), height) fb:refresh(0, 0, ypos, fb.bb:getWidth(), height)
pagedirty = false pagedirty = false
end end
local ev = input.waitForEvent() local ev = input.waitForEvent()
print("key code:"..ev.code)
ev.code = adjustKeyEvents(ev)
if ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_PRESS then if ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_PRESS then
--print("key code:"..ev.code)
ev.code = adjustFWKey(ev.code)
if ev.code == KEY_FW_UP then if ev.code == KEY_FW_UP then
prevItem() prevItem()
elseif ev.code == KEY_FW_DOWN then elseif ev.code == KEY_FW_DOWN then
@ -166,14 +167,7 @@ function FileChooser:choose(ypos, height)
elseif ev.code == KEY_S then -- invoke search input elseif ev.code == KEY_S then -- invoke search input
keywords = InputBox:input(height-100, 100, "Search:") keywords = InputBox:input(height-100, 100, "Search:")
if keywords then -- display search result according to keywords if keywords then -- display search result according to keywords
--[[ FileSearcher:init( self.path )
----------------------------------------------------------------
|| uncomment following line and set the correct path if you want
|| to test search feature in EMU mode
----------------------------------------------------------------
--]]
--FileSearcher:init("/home/dave/documents/kindle/backup/documents")
FileSearcher:init()
file = FileSearcher:choose(ypos, height, keywords) file = FileSearcher:choose(ypos, height, keywords)
if file then if file then
return file return file

@ -43,7 +43,7 @@ function FileSearcher:readdir()
for __, d in pairs(self.dirs) do for __, d in pairs(self.dirs) do
-- handle files in d -- handle files in d
for f in lfs.dir(d) do for f in lfs.dir(d) do
if lfs.attributes(self.path.."/"..f, "mode") == "directory" if lfs.attributes(d.."/"..f, "mode") == "directory"
and f ~= "." and f~= ".." and not string.match(f, "^%.[^.]") then and f ~= "." and f~= ".." and not string.match(f, "^%.[^.]") then
table.insert(new_dirs, d.."/"..f) table.insert(new_dirs, d.."/"..f)
elseif string.match(f, ".+%.[pP][dD][fF]$") then elseif string.match(f, ".+%.[pP][dD][fF]$") then
@ -214,8 +214,8 @@ function FileSearcher:choose(ypos, height, keywords)
end end
local ev = input.waitForEvent() local ev = input.waitForEvent()
ev.code = adjustKeyEvents(ev)
if ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_PRESS then if ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_PRESS then
ev.code = adjustFWKey(ev.code)
if ev.code == KEY_FW_UP then if ev.code == KEY_FW_UP then
prevItem() prevItem()
elseif ev.code == KEY_FW_DOWN then elseif ev.code == KEY_FW_DOWN then

@ -98,14 +98,10 @@ function InputBox:input(ypos, height, title, d_text)
end end
local ev = input.waitForEvent() local ev = input.waitForEvent()
ev.code = adjustKeyEvents(ev)
if ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_PRESS then if ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_PRESS then
ev.code = adjustFWKey(ev.code)
--local secs, usecs = util.gettime() --local secs, usecs = util.gettime()
if ev.code == KEY_SHIFT then if ev.code == KEY_FW_UP then
self.shiftmode = true
elseif ev.code == KEY_ALT then
self.altmode = true
elseif ev.code == KEY_FW_UP then
elseif ev.code == KEY_FW_DOWN then elseif ev.code == KEY_FW_DOWN then
elseif ev.code == KEY_A then elseif ev.code == KEY_A then
self:addChar("a") self:addChar("a")
@ -198,12 +194,6 @@ function InputBox:input(ypos, height, title, d_text)
--local nsecs, nusecs = util.gettime() --local nsecs, nusecs = util.gettime()
--local dur = (nsecs - secs) * 1000000 + nusecs - usecs --local dur = (nsecs - secs) * 1000000 + nusecs - usecs
--print("E: T="..ev.type.." V="..ev.value.." C="..ev.code.." DUR="..dur) --print("E: T="..ev.type.." V="..ev.value.." C="..ev.code.." DUR="..dur)
elseif ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_RELEASE
and ev.code == KEY_SHIFT then
self.shiftmode = false
elseif ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_RELEASE
and ev.code == KEY_ALT then
self.altmode = false
end end
end end
end end

@ -24,6 +24,11 @@
and was licensed under the GPLv2 and was licensed under the GPLv2
]]-- ]]--
Keys = {
altmode = false,
shiftmode = false,
}
KEY_1 = 2 KEY_1 = 2
KEY_2 = 3 KEY_2 = 3
KEY_3 = 4 KEY_3 = 4
@ -115,11 +120,22 @@ function set_emu_keycodes()
KEY_FW_DOWN = 116 KEY_FW_DOWN = 116
KEY_FW_LEFT = 113 KEY_FW_LEFT = 113
KEY_FW_RIGHT = 114 KEY_FW_RIGHT = 114
KEY_FW_PRESS = 36 -- enter for now KEY_FW_PRESS = 115 -- end for now (above arrows)
KEY_SPACE = 65 KEY_SPACE = 65
KEY_ENTER = 36 KEY_ENTER = 36
KEY_1 = 10
KEY_2 = 11
KEY_3 = 12
KEY_4 = 13
KEY_5 = 14
KEY_6 = 15
KEY_7 = 16
KEY_8 = 17
KEY_9 = 18
KEY_0 = 19
KEY_Q = 24 KEY_Q = 24
KEY_W = 25 KEY_W = 25
KEY_E = 26 KEY_E = 26
@ -163,17 +179,17 @@ function getRotationMode()
1 for landscape with bottom on the right side of screen, etc. 1 for landscape with bottom on the right side of screen, etc.
2 2
----------- +-----------+
| ------- | | +-------+ |
| | | | | | | |
| | | | | | | |
| | | | | | | |
3 | | | | 1 3 | | | | 1
| | | | | | | |
| | | | | | | |
| ------- | | +-------+ |
| | | |
----------- +-----------+
0 0
--]] --]]
if KEY_FW_DOWN == 116 then -- in EMU mode always return 0 if KEY_FW_DOWN == 116 then -- in EMU mode always return 0
@ -185,7 +201,23 @@ function getRotationMode()
return mode return mode
end end
function adjustFWKey(code) function adjustKeyEvents(ev)
if ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_PRESS then
if ev.code == KEY_SHIFT then
Keys.shiftmode = true
elseif ev.code == KEY_ALT then
Keys.altmode = true
end
elseif ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_RELEASE then
if ev.code == KEY_SHIFT then
Keys.shiftmode = false
elseif ev.code == KEY_ALT then
Keys.altmode = false
end
end
-- adjust five way key according to rotation mode
local code = ev.code
if getRotationMode() == 0 then if getRotationMode() == 0 then
return code return code
elseif getRotationMode() == 1 then elseif getRotationMode() == 1 then

11
pdf.c

@ -104,6 +104,17 @@ static int walkTableOfContent(lua_State *L, fz_outline* ol, int *count, int dept
lua_pushnumber(L, depth); lua_pushnumber(L, depth);
lua_settable(L, -3); lua_settable(L, -3);
lua_pushstring(L, "title"); lua_pushstring(L, "title");
/* workaround for misplaced carriage ret in toc entry */
int i = 0;
while (ol->title[i]) {
if (ol->title[i] == 0x0d) {
ol->title[i] = ' ';
}
/*printf("%x|", ol->title[i]);*/
i++;
}
lua_pushstring(L, ol->title); lua_pushstring(L, ol->title);
lua_settable(L, -3); lua_settable(L, -3);

@ -11,6 +11,7 @@ PDFReader = {
ZOOM_FIT_TO_CONTENT = -4, ZOOM_FIT_TO_CONTENT = -4,
ZOOM_FIT_TO_CONTENT_WIDTH = -5, ZOOM_FIT_TO_CONTENT_WIDTH = -5,
ZOOM_FIT_TO_CONTENT_HEIGHT = -6, ZOOM_FIT_TO_CONTENT_HEIGHT = -6,
ZOOM_FIT_TO_CONTENT_HALF_WIDTH = -7,
GAMMA_NO_GAMMA = 1.0, GAMMA_NO_GAMMA = 1.0,
@ -39,10 +40,9 @@ PDFReader = {
shift_x = 100, shift_x = 100,
shift_y = 50, shift_y = 50,
pan_by_page = false, -- using shift_[xy] or width/height pan_by_page = false, -- using shift_[xy] or width/height
pan_x = 0, -- top-left offset of page when pan activated
-- keep track of input state: pan_y = 0,
shiftmode = false, -- shift pressed pan_margin = 20,
altmode = false, -- alt pressed
-- the pdf document: -- the pdf document:
doc = nil, doc = nil,
@ -188,6 +188,18 @@ function PDFReader:setzoom(page)
self.offset_x = -1 * x0 * self.globalzoom + (width - (self.globalzoom * (x1 - x0))) / 2 self.offset_x = -1 * x0 * self.globalzoom + (width - (self.globalzoom * (x1 - x0))) / 2
self.offset_y = -1 * y0 * self.globalzoom self.offset_y = -1 * y0 * self.globalzoom
end end
elseif self.globalzoommode == self.ZOOM_FIT_TO_CONTENT_HALF_WIDTH then
local x0, y0, x1, y1 = page:getUsedBBox()
self.globalzoom = width / (x1 - x0 + self.pan_margin)
self.offset_x = -1 * x0 * self.globalzoom * 2 + self.pan_margin
self.globalzoom = height / (y1 - y0)
self.offset_y = -1 * y0 * self.globalzoom * 2 + self.pan_margin
self.globalzoom = width / (x1 - x0 + self.pan_margin) * 2
print("column mode offset:"..self.offset_x.."*"..self.offset_y.." zoom:"..self.globalzoom);
self.globalzoommode = self.ZOOM_BY_VALUE -- enable pan mode
self.pan_x = self.offset_x
self.pan_y = self.offset_y
self.pan_by_page = true
end end
dc:setZoom(self.globalzoom) dc:setZoom(self.globalzoom)
dc:setRotate(self.globalrotate); dc:setRotate(self.globalrotate);
@ -352,30 +364,35 @@ end
function PDFReader:inputloop() function PDFReader:inputloop()
while 1 do while 1 do
local ev = input.waitForEvent() local ev = input.waitForEvent()
ev.code = adjustKeyEvents(ev)
if ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_PRESS then if ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_PRESS then
local secs, usecs = util.gettime() local secs, usecs = util.gettime()
if ev.code == KEY_SHIFT then if ev.code == KEY_PGFWD or ev.code == KEY_LPGFWD then
self.shiftmode = true if Keys.shiftmode then
elseif ev.code == KEY_ALT then self:setglobalzoom(self.globalzoom+0.2)
self.altmode = true elseif Keys.altmode then
elseif ev.code == KEY_PGFWD or ev.code == KEY_LPGFWD then self:setglobalzoom(self.globalzoom+0.1)
if self.shiftmode then
self:setglobalzoom(self.globalzoom*1.2)
elseif self.altmode then
self:setglobalzoom(self.globalzoom*1.1)
else 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) self:goto(self.pageno + 1)
end end
elseif ev.code == KEY_PGBCK or ev.code == KEY_LPGBCK then elseif ev.code == KEY_PGBCK or ev.code == KEY_LPGBCK then
if self.shiftmode then if Keys.shiftmode then
self:setglobalzoom(self.globalzoom*0.8) self:setglobalzoom(self.globalzoom-0.2)
elseif self.altmode then elseif Keys.altmode then
self:setglobalzoom(self.globalzoom*0.9) self:setglobalzoom(self.globalzoom-0.1)
else 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) self:goto(self.pageno - 1)
end end
elseif ev.code == KEY_BACK then elseif ev.code == KEY_BACK then
if self.altmode then if Keys.altmode then
-- altmode, exit pdfreader -- altmode, exit pdfreader
self:clearcache() self:clearcache()
if self.doc ~= nil then if self.doc ~= nil then
@ -398,23 +415,25 @@ function PDFReader:inputloop()
elseif ev.code == KEY_VMINUS then elseif ev.code == KEY_VMINUS then
self:modify_gamma( 0.8 ) self:modify_gamma( 0.8 )
elseif ev.code == KEY_A then elseif ev.code == KEY_A then
if self.shiftmode then if Keys.shiftmode then
self:setglobalzoommode(self.ZOOM_FIT_TO_CONTENT) self:setglobalzoommode(self.ZOOM_FIT_TO_CONTENT)
else else
self:setglobalzoommode(self.ZOOM_FIT_TO_PAGE) self:setglobalzoommode(self.ZOOM_FIT_TO_PAGE)
end end
elseif ev.code == KEY_S then elseif ev.code == KEY_S then
if self.shiftmode then if Keys.shiftmode then
self:setglobalzoommode(self.ZOOM_FIT_TO_CONTENT_WIDTH) self:setglobalzoommode(self.ZOOM_FIT_TO_CONTENT_WIDTH)
else else
self:setglobalzoommode(self.ZOOM_FIT_TO_PAGE_WIDTH) self:setglobalzoommode(self.ZOOM_FIT_TO_PAGE_WIDTH)
end end
elseif ev.code == KEY_D then elseif ev.code == KEY_D then
if self.shiftmode then if Keys.shiftmode then
self:setglobalzoommode(self.ZOOM_FIT_TO_CONTENT_HEIGHT) self:setglobalzoommode(self.ZOOM_FIT_TO_CONTENT_HEIGHT)
else else
self:setglobalzoommode(self.ZOOM_FIT_TO_PAGE_HEIGHT) self:setglobalzoommode(self.ZOOM_FIT_TO_PAGE_HEIGHT)
end end
elseif ev.code == KEY_F then
self:setglobalzoommode(self.ZOOM_FIT_TO_CONTENT_HALF_WIDTH)
elseif ev.code == KEY_T then elseif ev.code == KEY_T then
self:showTOC() self:showTOC()
elseif ev.code == KEY_B then elseif ev.code == KEY_B then
@ -429,15 +448,15 @@ function PDFReader:inputloop()
local x local x
local y local y
if self.shiftmode then -- shift always moves in small steps if Keys.shiftmode then -- shift always moves in small steps
x = self.shift_x / 2 x = self.shift_x / 2
y = self.shift_y / 2 y = self.shift_y / 2
elseif self.altmode then elseif Keys.altmode then
x = self.shift_x / 5 x = self.shift_x / 5
y = self.shift_y / 5 y = self.shift_y / 5
elseif self.pan_by_page then elseif self.pan_by_page then
x = self.width - 5; -- small overlap when moving by page x = width;
y = self.height - 5; y = height - self.pan_margin; -- overlap for lines which didn't fit
else else
x = self.shift_x x = self.shift_x
y = self.shift_y y = self.shift_y
@ -451,11 +470,27 @@ function PDFReader:inputloop()
self.offset_x = self.offset_x + x self.offset_x = self.offset_x + x
if self.offset_x > 0 then if self.offset_x > 0 then
self.offset_x = 0 self.offset_x = 0
if self.pan_by_page and self.pageno > 1 then
self.offset_x = self.pan_x
self.offset_y = self.min_offset_y -- bottom
self:goto(self.pageno - 1)
end
end
if self.pan_by_page then
self.offset_y = self.min_offset_y
end end
elseif ev.code == KEY_FW_RIGHT then elseif ev.code == KEY_FW_RIGHT then
self.offset_x = self.offset_x - x self.offset_x = self.offset_x - x
if self.offset_x < self.min_offset_x then if self.offset_x < self.min_offset_x then
self.offset_x = self.min_offset_x self.offset_x = self.min_offset_x
if self.pan_by_page and self.pageno < self.doc:getPages() then
self.offset_x = self.pan_x
self.offset_y = self.pan_y
self:goto(self.pageno + 1)
end
end
if self.pan_by_page then
self.offset_y = self.pan_y
end end
elseif ev.code == KEY_FW_UP then elseif ev.code == KEY_FW_UP then
self.offset_y = self.offset_y + y self.offset_y = self.offset_y + y
@ -468,11 +503,20 @@ function PDFReader:inputloop()
self.offset_y = self.min_offset_y self.offset_y = self.min_offset_y
end end
elseif ev.code == KEY_FW_PRESS then elseif ev.code == KEY_FW_PRESS then
if self.shiftmode then if Keys.shiftmode then
self.offset_x = 0 if self.pan_by_page then
self.offset_y = 0 self.offset_x = self.pan_x
self.offset_y = self.pan_y
else
self.offset_x = 0
self.offset_y = 0
end
else else
self.pan_by_page = not self.pan_by_page self.pan_by_page = not self.pan_by_page
if self.pan_by_page then
self.pan_x = self.offset_x
self.pan_y = self.offset_y
end
end end
end end
if old_offset_x ~= self.offset_x if old_offset_x ~= self.offset_x
@ -484,11 +528,6 @@ function PDFReader:inputloop()
local nsecs, nusecs = util.gettime() local nsecs, nusecs = util.gettime()
local dur = (nsecs - secs) * 1000000 + nusecs - usecs local dur = (nsecs - secs) * 1000000 + nusecs - usecs
print("E: T="..ev.type.." V="..ev.value.." C="..ev.code.." DUR="..dur) print("E: T="..ev.type.." V="..ev.value.." C="..ev.code.." DUR="..dur)
elseif ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_RELEASE and ev.code == KEY_SHIFT then
print "shift haha"
self.shiftmode = false
elseif ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_RELEASE and ev.code == KEY_ALT then
self.altmode = false
end end
end end
end end

@ -123,4 +123,8 @@ DJVUReader:inputloop()
--reader_settings:close() --reader_settings:close()
--input.closeAll() --input.closeAll()
--[[os.execute('test -e /proc/keypad && echo "send '..KEY_HOME..'" > /proc/keypad ')]] input.closeAll()
--os.execute('test -e /proc/keypad && echo "send '..KEY_HOME..'" > /proc/keypad ')
if optarg["d"] ~= "emu" then
os.execute('echo "send '..KEY_MENU..'" > /proc/keypad;echo "send '..KEY_MENU..'" > /proc/keypad')
end

@ -167,8 +167,8 @@ function SelectMenu:choose(ypos, height)
end end
local ev = input.waitForEvent() local ev = input.waitForEvent()
ev.code = adjustKeyEvents(ev)
if ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_PRESS then if ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_PRESS then
ev.code = adjustFWKey(ev.code)
if ev.code == KEY_FW_UP then if ev.code == KEY_FW_UP then
prevItem() prevItem()
elseif ev.code == KEY_FW_DOWN then elseif ev.code == KEY_FW_DOWN then

Loading…
Cancel
Save