2
0
mirror of https://github.com/koreader/koreader synced 2024-11-10 01:10:34 +00:00

cache page size after page is reflowed

So that when page dimension is recalculated right page size
other than screen size is returned.
This commit is contained in:
chrox 2012-11-29 21:53:20 +08:00
parent edf898027a
commit aa9fe4b01c

View File

@ -134,8 +134,15 @@ end
-- calculates page dimensions -- calculates page dimensions
function KoptDocument:getPageDimensions(pageno, zoom, rotation) function KoptDocument:getPageDimensions(pageno, zoom, rotation)
DEBUG("Warnning: cannot determine page size before reflowing.") -- check cached page size
return Screen:getSize() local hash = "pgrfsize|"..self.file.."|"..pageno
local cached = Cache:check(hash)
if not cached then
DEBUG("Warnning: cannot determine page size before reflowing.")
return Screen:getSize()
end
DEBUG("Found cached page size on page", pageno, cached[1])
return cached[1]
end end
function KoptDocument:renderPage(pageno, rect, zoom, rotation, render_mode) function KoptDocument:renderPage(pageno, rect, zoom, rotation, render_mode)
@ -148,6 +155,11 @@ function KoptDocument:renderPage(pageno, rect, zoom, rotation, render_mode)
local fullwidth, fullheight = kc:getPageDim() local fullwidth, fullheight = kc:getPageDim()
DEBUG("page::reflowPage:", "fullwidth:", fullwidth, "fullheight:", fullheight) DEBUG("page::reflowPage:", "fullwidth:", fullwidth, "fullheight:", fullheight)
local page_size = Geom:new{ w = fullwidth, h = fullheight } local page_size = Geom:new{ w = fullwidth, h = fullheight }
-- cache reflowed page size
local pgrfsize_hash = "pgrfsize|"..self.file.."|"..pageno
if not Cache:check(pgrfsize_hash) then
Cache:insert(pgrfsize_hash, CacheItem:new{ page_size })
end
-- this will be the size we actually render -- this will be the size we actually render
local size = page_size local size = page_size
-- we prefer to render the full page, if it fits into cache -- we prefer to render the full page, if it fits into cache