@ -1,11 +1,12 @@
local TileCacheItem = require ( " document/tilecacheitem " )
local DrawContext = require ( " ffi/drawcontext " )
local Configurable = require ( " configurable " )
local Blitbuffer = require ( " ffi/blitbuffer " )
local Cache = require ( " cache " )
local lfs = require ( " libs/libkoreader-lfs " )
local CacheItem = require ( " cacheitem " )
local TileCacheItem = require ( " document/tilecacheitem " )
local Geom = require ( " ui/geometry " )
local Configurable = require ( " configurable " )
local Math = require ( " optmath " )
local Cache = require ( " cache " )
local DEBUG = require ( " dbg " )
--[[
@ -114,6 +115,7 @@ function Document:getNativePageDimensions(pageno)
end
function Document : _readMetadata ( )
self.mod_time = lfs.attributes ( self.file , " modification " )
self.info . number_of_pages = self._document : getPages ( )
return true
end
@ -215,8 +217,13 @@ function Document:getCoverPageImage()
return nil
end
function Document : getFullPageHash ( pageno , zoom , rotation , gamma , render_mode )
return " renderpg| " .. self.file .. " | " .. self.mod_time .. " | " .. pageno .. " | "
.. zoom .. " | " .. rotation .. " | " .. gamma .. " | " .. render_mode
end
function Document : renderPage ( pageno , rect , zoom , rotation , gamma , render_mode )
local hash = " renderpg| " .. self.file .. " | " .. pageno .. " | " .. zoom .. " | " .. rotation .. " | " .. gamma .. " | " .. render_mode
local hash = self : getFullPageHash ( pageno , zoom , rotation , gamma , render_mode )
local page_size = self : getPageDimensions ( pageno , zoom , rotation )
-- this will be the size we actually render
local size = page_size
@ -231,12 +238,13 @@ function Document:renderPage(pageno, rect, zoom, rotation, gamma, render_mode)
return
end
-- only render required part
hash = " renderpg| " .. self.file .. " | " .. pageno .. " | " .. zoom .. " | " .. rotation .. " | " .. gamma .. " | " .. render_mode .. " | " .. tostring ( rect )
hash = self : getFullPageHash ( pageno , zoom , rotation , gamma , render_mode ) .. " | " .. tostring ( rect )
size = rect
end
-- prepare cache item with contained blitbuffer
local tile = TileCacheItem : new {
persistent = true ,
size = size.w * size.h + 64 , -- estimation
excerpt = size ,
pageno = pageno ,
@ -274,7 +282,7 @@ end
-- a hint for the cache engine to paint a full page to the cache
-- TODO: this should trigger a background operation
function Document : hintPage ( pageno , zoom , rotation , gamma , render_mode )
local hash_full_page = " renderpg| " .. self.file .. " | " .. pageno .. " | " .. zoom .. " | " .. rotation .. " | " .. gamma .. " | " .. render_mode
local hash_full_page = self : getFullPageHash ( pageno , zoom , rotation , gamma , render_mode )
if not Cache : check ( hash_full_page , TileCacheItem ) then
DEBUG ( " hinting page " , pageno )
self : renderPage ( pageno , nil , zoom , rotation , gamma , render_mode )
@ -290,7 +298,7 @@ Draw page content to blitbuffer.
@ rect : visible_area inside document page
--]]
function Document : drawPage ( target , x , y , rect , pageno , zoom , rotation , gamma , render_mode )
local hash_full_page = " renderpg| " .. self.file .. " | " .. pageno .. " | " .. zoom .. " | " .. rotation .. " | " .. gamma .. " | " .. render_mode
local hash_full_page = self : getFullPageHash ( pageno , zoom , rotation , gamma , render_mode )
local hash_excerpt = hash_full_page .. " | " .. tostring ( rect )
local tile = Cache : check ( hash_full_page , TileCacheItem )
if not tile then