From c2207f0e673d5d26a7af44c619e800f94698064e Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Wed, 14 Dec 2011 21:32:45 +0100 Subject: [PATCH 1/7] rotate page using J and K keys --- keys.lua | 4 ++++ pdfreader.lua | 29 +++++++++++++++++++++-------- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/keys.lua b/keys.lua index 15e8debf3..bd56f53b4 100644 --- a/keys.lua +++ b/keys.lua @@ -121,6 +121,10 @@ function set_emu_keycodes() KEY_A = 38 KEY_S = 39 KEY_D = 40 + + KEY_J = 44 + KEY_K = 45 + KEY_SHIFT = 50 -- left shift KEY_ALT = 64 -- left alt KEY_VPLUS = 95 -- F11 diff --git a/pdfreader.lua b/pdfreader.lua index df1182838..4249f2775 100644 --- a/pdfreader.lua +++ b/pdfreader.lua @@ -21,6 +21,8 @@ PDFReader = { globalzoom = 1.0, globalzoommode = -1, -- ZOOM_FIT_TO_PAGE + globalrotate = 0, + -- gamma setting: globalgamma = 1.0, -- GAMMA_NO_GAMMA @@ -82,9 +84,9 @@ function PDFReader:cacheclaim(size) return true end -function PDFReader:draworcache(no, zoom, offset_x, offset_y, width, height, gamma) +function PDFReader:draworcache(no, zoom, offset_x, offset_y, width, height, gamma, rotate) -- hash draw state - local hash = self:cachehash(no, zoom, offset_x, offset_y, width, height, gamma) + local hash = self:cachehash(no, zoom, offset_x, offset_y, width, height, gamma, rotate) if self.cache[hash] == nil then -- not in cache, so prepare cache slot... self:cacheclaim(width * height / 2); @@ -107,9 +109,9 @@ function PDFReader:draworcache(no, zoom, offset_x, offset_y, width, height, gamm end -- calculate a hash for our current state -function PDFReader:cachehash(no, zoom, offset_x, offset_y, width, height, gamma) +function PDFReader:cachehash(no, zoom, offset_x, offset_y, width, height, gamma, rotate) -- TODO (?): make this a "real" hash... - return no..'_'..zoom..'_'..offset_x..','..offset_y..'-'..width..'x'..height..'_'..gamma; + return no..'_'..zoom..'_'..offset_x..','..offset_y..'-'..width..'x'..height..'_'..gamma..'_'..rotate end -- blank the cache @@ -186,6 +188,7 @@ function PDFReader:setzoom(page) end end dc:setZoom(self.globalzoom) + dc:setRotate(self.globalrotate); dc:setOffset(self.offset_x, self.offset_y) self.fullwidth, self.fullheight = page:getSize(dc) self.min_offset_x = fb.bb:getWidth() - self.fullwidth @@ -209,9 +212,9 @@ end function PDFReader:show(no) local slot if self.globalzoommode ~= self.ZOOM_BY_VALUE then - slot = self:draworcache(no,self.globalzoommode,self.offset_x,self.offset_y,width,height,self.globalgamma) + slot = self:draworcache(no,self.globalzoommode,self.offset_x,self.offset_y,width,height,self.globalgamma,self.globalrotate) else - slot = self:draworcache(no,self.globalzoom,self.offset_x,self.offset_y,width,height,self.globalgamma) + slot = self:draworcache(no,self.globalzoom,self.offset_x,self.offset_y,width,height,self.globalgamma,self.globalrotate) end fb.bb:blitFullFrom(self.cache[slot].bb) if self.rcount == self.rcountmax then @@ -236,9 +239,9 @@ function PDFReader:goto(no) if no < self.doc:getPages() then if self.globalzoommode ~= self.ZOOM_BY_VALUE then -- pre-cache next page - self:draworcache(no+1,self.globalzoommode,self.offset_x,self.offset_y,width,height,self.globalgamma) + self:draworcache(no+1,self.globalzoommode,self.offset_x,self.offset_y,width,height,self.globalgamma,self.globalrotate) else - self:draworcache(no,self.globalzoom,self.offset_x,self.offset_y,width,height,self.globalgamma) + self:draworcache(no,self.globalzoom,self.offset_x,self.offset_y,width,height,self.globalgamma,self.globalrotate) end end end @@ -267,6 +270,11 @@ function PDFReader:setglobalzoom(zoom) end end +function PDFReader:setrotate(rotate) + self.globalrotate = rotate + self:goto(self.pageno) +end + -- wait for input and handle it function PDFReader:inputloop() while 1 do @@ -326,6 +334,11 @@ function PDFReader:inputloop() else self:setglobalzoommode(self.ZOOM_FIT_TO_PAGE_HEIGHT) end + + elseif ev.code == KEY_J then + self:setrotate( self.globalrotate + 10 ) + elseif ev.code == KEY_K then + self:setrotate( self.globalrotate - 10 ) end if self.globalzoommode == self.ZOOM_BY_VALUE then From 5a384bc6d9e0ac2800ed2b9cd68e69484570421b Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Fri, 23 Dec 2011 22:47:48 +0100 Subject: [PATCH 2/7] open /mnt/us/documents by default This option also removed fb save/reload which speeds up startup and exit --- launchpad/kpdf.sh | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/launchpad/kpdf.sh b/launchpad/kpdf.sh index 9bed33e3b..d2b94d902 100755 --- a/launchpad/kpdf.sh +++ b/launchpad/kpdf.sh @@ -2,13 +2,5 @@ echo unlock > /proc/keypad echo unlock > /proc/fiveway cd /mnt/us/test/ -cat /dev/fb0 > /tmp/screen.fb0 & -if [ "x$1" == "x" ] ; then - pdf=`lsof | grep /mnt/us/documents | cut -c81- | sort -u` -else - pdf="$1" -fi -./reader.lua "$pdf" -cat /tmp/screen.fb0 > /dev/fb0 -rm /tmp/screen.fb0 +./reader.lua /mnt/us/documents echo 1 > /proc/eink_fb/update_display From 1a2f51cafb78d0137fb9e901c1e8891c4f8b2b8f Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Fri, 23 Dec 2011 23:27:26 +0100 Subject: [PATCH 3/7] auto-detect Kindle 3 based on /dev/input/event2 This is somewhat important, because if we are started without explicit -d k3 all key mappings are wrong, and user can't exit --- reader.lua | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/reader.lua b/reader.lua index 325f359b6..b589fe761 100755 --- a/reader.lua +++ b/reader.lua @@ -63,6 +63,15 @@ elseif optarg["d"] == "emu" then else input.open("/dev/input/event0") input.open("/dev/input/event1") + + -- check if we are running on Kindle 3 (additional volume input) + local f=lfs.attributes("/dev/input/event2") + print(f) + if f then + print("Auto-detected Kindle 3") + set_k3_keycodes() + end + end if optarg["G"] ~= nil then From 287aa5873169b1d9b33f3c4794688c682a43ce93 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Thu, 19 Jan 2012 18:17:16 +0100 Subject: [PATCH 4/7] document --device emu option --- reader.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/reader.lua b/reader.lua index b589fe761..1a5d99174 100755 --- a/reader.lua +++ b/reader.lua @@ -40,6 +40,7 @@ if optarg["h"] or ARGV[optind] == nil then print(" (floating point notation, e.g. \"1.5\")") print("-d, --device=DEVICE set device specific configuration,") print(" currently one of \"kdxg\" (default), \"k3\"") + print(" \"emu\" (DXG emulation)") print("-h, --help show this usage help") print("") print("If you give the name of a directory instead of a path, a file") From 9fc7f4add3c5ad9f42848628e043d317460d0434 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Thu, 19 Jan 2012 18:26:24 +0100 Subject: [PATCH 5/7] example for Kindle 3 resolution emulator --- README.TXT | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.TXT b/README.TXT index 9356eedb9..a06c75335 100644 --- a/README.TXT +++ b/README.TXT @@ -61,3 +61,9 @@ The reader.lua script needs a device argument in order to cope with some slight differences between actual readers and the emulation. Run it like this: ./reader.lua -d emu /PATH/TO/PDF.pdf + +By default emulation will provide DXG resolution of 824*1200. It can be +specified at compile time, this is example for Kindle 3: + + EMULATE_READER_W=600 EMULATE_READER_H=800 EMULATE_READER=1 make kpdfview + From 70ae351702fd2f0c3458cabda84f4c9900b069d2 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Thu, 19 Jan 2012 18:39:15 +0100 Subject: [PATCH 6/7] fix zomming with alt --- pdfreader.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pdfreader.lua b/pdfreader.lua index 4249f2775..9e1352f30 100644 --- a/pdfreader.lua +++ b/pdfreader.lua @@ -288,7 +288,7 @@ function PDFReader:inputloop() elseif ev.code == KEY_PGFWD then if self.shiftmode then self:setglobalzoom(self.globalzoom*1.2) - elseif altmode then + elseif self.altmode then self:setglobalzoom(self.globalzoom*1.1) else self:goto(self.pageno + 1) @@ -296,7 +296,7 @@ function PDFReader:inputloop() elseif ev.code == KEY_PGBCK then if self.shiftmode then self:setglobalzoom(self.globalzoom*0.8) - elseif altmode then + elseif self.altmode then self:setglobalzoom(self.globalzoom*0.9) else self:goto(self.pageno - 1) From f74def7a69cd6365a08048b5ea8492167fe347f3 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Thu, 19 Jan 2012 19:33:37 +0100 Subject: [PATCH 7/7] create customupdate package for launchpad installation This change also modifies installation directory for install and customupdate make targets to /mnt/us/kindlepdfviewer --- Makefile | 13 ++++++++++++- launchpad/kpdf.sh | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 0b2e09b41..5d9771fc5 100644 --- a/Makefile +++ b/Makefile @@ -127,8 +127,19 @@ $(LUALIB): thirdparty: $(MUPDFLIBS) $(THIRDPARTYLIBS) $(LUALIBS) +INSTALL_DIR=kindlepdfviewer + install: # install to kindle using USB networking - scp kpdfview *.lua root@192.168.2.2:/mnt/us/test/ + scp kpdfview *.lua root@192.168.2.2:/mnt/us/$(INSTALL_DIR)/ scp launchpad/* root@192.168.2.2:/mnt/us/launchpad/ +VERSION?=$(shell git rev-parse --short HEAD) +customupdate: kpdfview + # ensure that build binary is for ARM + file kpdfview | grep ARM || exit 1 + mkdir $(INSTALL_DIR) + cp -p README.TXT COPYING kpdfview *.lua $(INSTALL_DIR) + zip -r kindlepdfviewer-$(VERSION).zip $(INSTALL_DIR) launchpad/ + rm -Rf $(INSTALL_DIR) + @echo "copy kindlepdfviewer-$(VERSION).zip to /mnt/us/customupdates and install with shift+shift+I" diff --git a/launchpad/kpdf.sh b/launchpad/kpdf.sh index d2b94d902..e89a329fd 100755 --- a/launchpad/kpdf.sh +++ b/launchpad/kpdf.sh @@ -1,6 +1,6 @@ #!/bin/sh echo unlock > /proc/keypad echo unlock > /proc/fiveway -cd /mnt/us/test/ +cd /mnt/us/kindlepdfviewer/ ./reader.lua /mnt/us/documents echo 1 > /proc/eink_fb/update_display