|
|
@ -21,6 +21,8 @@ PDFReader = {
|
|
|
|
globalzoom = 1.0,
|
|
|
|
globalzoom = 1.0,
|
|
|
|
globalzoommode = -1, -- ZOOM_FIT_TO_PAGE
|
|
|
|
globalzoommode = -1, -- ZOOM_FIT_TO_PAGE
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
globalrotate = 0,
|
|
|
|
|
|
|
|
|
|
|
|
-- gamma setting:
|
|
|
|
-- gamma setting:
|
|
|
|
globalgamma = 1.0, -- GAMMA_NO_GAMMA
|
|
|
|
globalgamma = 1.0, -- GAMMA_NO_GAMMA
|
|
|
|
|
|
|
|
|
|
|
@ -82,9 +84,9 @@ function PDFReader:cacheclaim(size)
|
|
|
|
return true
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
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
|
|
|
|
-- 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
|
|
|
|
if self.cache[hash] == nil then
|
|
|
|
-- not in cache, so prepare cache slot...
|
|
|
|
-- not in cache, so prepare cache slot...
|
|
|
|
self:cacheclaim(width * height / 2);
|
|
|
|
self:cacheclaim(width * height / 2);
|
|
|
@ -107,9 +109,9 @@ function PDFReader:draworcache(no, zoom, offset_x, offset_y, width, height, gamm
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
-- calculate a hash for our current state
|
|
|
|
-- 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...
|
|
|
|
-- 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
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
-- blank the cache
|
|
|
|
-- blank the cache
|
|
|
@ -186,6 +188,7 @@ function PDFReader:setzoom(page)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
dc:setZoom(self.globalzoom)
|
|
|
|
dc:setZoom(self.globalzoom)
|
|
|
|
|
|
|
|
dc:setRotate(self.globalrotate);
|
|
|
|
dc:setOffset(self.offset_x, self.offset_y)
|
|
|
|
dc:setOffset(self.offset_x, self.offset_y)
|
|
|
|
self.fullwidth, self.fullheight = page:getSize(dc)
|
|
|
|
self.fullwidth, self.fullheight = page:getSize(dc)
|
|
|
|
self.min_offset_x = fb.bb:getWidth() - self.fullwidth
|
|
|
|
self.min_offset_x = fb.bb:getWidth() - self.fullwidth
|
|
|
@ -209,9 +212,9 @@ end
|
|
|
|
function PDFReader:show(no)
|
|
|
|
function PDFReader:show(no)
|
|
|
|
local slot
|
|
|
|
local slot
|
|
|
|
if self.globalzoommode ~= self.ZOOM_BY_VALUE then
|
|
|
|
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
|
|
|
|
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
|
|
|
|
end
|
|
|
|
fb.bb:blitFullFrom(self.cache[slot].bb)
|
|
|
|
fb.bb:blitFullFrom(self.cache[slot].bb)
|
|
|
|
if self.rcount == self.rcountmax then
|
|
|
|
if self.rcount == self.rcountmax then
|
|
|
@ -236,9 +239,9 @@ function PDFReader:goto(no)
|
|
|
|
if no < self.doc:getPages() then
|
|
|
|
if no < self.doc:getPages() then
|
|
|
|
if self.globalzoommode ~= self.ZOOM_BY_VALUE then
|
|
|
|
if self.globalzoommode ~= self.ZOOM_BY_VALUE then
|
|
|
|
-- pre-cache next page
|
|
|
|
-- 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
|
|
|
|
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
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
@ -267,6 +270,11 @@ function PDFReader:setglobalzoom(zoom)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function PDFReader:setrotate(rotate)
|
|
|
|
|
|
|
|
self.globalrotate = rotate
|
|
|
|
|
|
|
|
self:goto(self.pageno)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
-- wait for input and handle it
|
|
|
|
-- wait for input and handle it
|
|
|
|
function PDFReader:inputloop()
|
|
|
|
function PDFReader:inputloop()
|
|
|
|
while 1 do
|
|
|
|
while 1 do
|
|
|
@ -280,7 +288,7 @@ function PDFReader:inputloop()
|
|
|
|
elseif ev.code == KEY_PGFWD then
|
|
|
|
elseif ev.code == KEY_PGFWD then
|
|
|
|
if self.shiftmode then
|
|
|
|
if self.shiftmode then
|
|
|
|
self:setglobalzoom(self.globalzoom*1.2)
|
|
|
|
self:setglobalzoom(self.globalzoom*1.2)
|
|
|
|
elseif altmode then
|
|
|
|
elseif self.altmode then
|
|
|
|
self:setglobalzoom(self.globalzoom*1.1)
|
|
|
|
self:setglobalzoom(self.globalzoom*1.1)
|
|
|
|
else
|
|
|
|
else
|
|
|
|
self:goto(self.pageno + 1)
|
|
|
|
self:goto(self.pageno + 1)
|
|
|
@ -288,7 +296,7 @@ function PDFReader:inputloop()
|
|
|
|
elseif ev.code == KEY_PGBCK then
|
|
|
|
elseif ev.code == KEY_PGBCK then
|
|
|
|
if self.shiftmode then
|
|
|
|
if self.shiftmode then
|
|
|
|
self:setglobalzoom(self.globalzoom*0.8)
|
|
|
|
self:setglobalzoom(self.globalzoom*0.8)
|
|
|
|
elseif altmode then
|
|
|
|
elseif self.altmode then
|
|
|
|
self:setglobalzoom(self.globalzoom*0.9)
|
|
|
|
self:setglobalzoom(self.globalzoom*0.9)
|
|
|
|
else
|
|
|
|
else
|
|
|
|
self:goto(self.pageno - 1)
|
|
|
|
self:goto(self.pageno - 1)
|
|
|
@ -326,6 +334,11 @@ function PDFReader:inputloop()
|
|
|
|
else
|
|
|
|
else
|
|
|
|
self:setglobalzoommode(self.ZOOM_FIT_TO_PAGE_HEIGHT)
|
|
|
|
self:setglobalzoommode(self.ZOOM_FIT_TO_PAGE_HEIGHT)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
elseif ev.code == KEY_J then
|
|
|
|
|
|
|
|
self:setrotate( self.globalrotate + 10 )
|
|
|
|
|
|
|
|
elseif ev.code == KEY_K then
|
|
|
|
|
|
|
|
self:setrotate( self.globalrotate - 10 )
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
if self.globalzoommode == self.ZOOM_BY_VALUE then
|
|
|
|
if self.globalzoommode == self.ZOOM_BY_VALUE then
|
|
|
|