mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
PDF written highlights: fix boxes, trash cached tiles
TileCacheItem: add created_ts property. Document: manage a tile_cache_validity_ts and ignore older cached tiles. This timestamps is updated when highlights are written as annotations in, or deleted from, the PDF, so we can get the most current rendered bitmap from MuPDF and avoid highlight ghosts on old tiles. Save this timestamp in doc settings so older cached to disk tiles will also be ignored across re-openings. Bump base for: mupdf.lua: update frontend pboxes with MuPDF adjusted ones.
This commit is contained in:
2
base
2
base
Submodule base updated: 0258347cb0...13f0d3decc
@@ -760,6 +760,7 @@ In combination with zoom to fit page, page height, content height, content or co
|
|||||||
end
|
end
|
||||||
|
|
||||||
function ReaderView:onReadSettings(config)
|
function ReaderView:onReadSettings(config)
|
||||||
|
self.document:setTileCacheValidity(config:readSetting("tile_cache_validity_ts"))
|
||||||
self.render_mode = config:readSetting("render_mode") or 0
|
self.render_mode = config:readSetting("render_mode") or 0
|
||||||
local rotation_mode = nil
|
local rotation_mode = nil
|
||||||
local locked = G_reader_settings:isTrue("lock_rotation")
|
local locked = G_reader_settings:isTrue("lock_rotation")
|
||||||
@@ -888,6 +889,7 @@ function ReaderView:onPageGapUpdate(page_gap)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function ReaderView:onSaveSettings()
|
function ReaderView:onSaveSettings()
|
||||||
|
self.ui.doc_settings:saveSetting("tile_cache_validity_ts", self.document:getTileCacheValidity())
|
||||||
self.ui.doc_settings:saveSetting("render_mode", self.render_mode)
|
self.ui.doc_settings:saveSetting("render_mode", self.render_mode)
|
||||||
-- Don't etch the current rotation in stone when sticky rotation is enabled
|
-- Don't etch the current rotation in stone when sticky rotation is enabled
|
||||||
local locked = G_reader_settings:isTrue("lock_rotation")
|
local locked = G_reader_settings:isTrue("lock_rotation")
|
||||||
|
|||||||
@@ -372,6 +372,18 @@ function Document:postRenderPage()
|
|||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Document:getTileCacheValidity()
|
||||||
|
return self.tile_cache_validity_ts
|
||||||
|
end
|
||||||
|
|
||||||
|
function Document:setTileCacheValidity(ts)
|
||||||
|
self.tile_cache_validity_ts = ts
|
||||||
|
end
|
||||||
|
|
||||||
|
function Document:resetTileCacheValidity()
|
||||||
|
self.tile_cache_validity_ts = os.time()
|
||||||
|
end
|
||||||
|
|
||||||
function Document:getFullPageHash(pageno, zoom, rotation, gamma, render_mode, color)
|
function Document:getFullPageHash(pageno, zoom, rotation, gamma, render_mode, color)
|
||||||
return "renderpg|"..self.file.."|"..self.mod_time.."|"..pageno.."|"
|
return "renderpg|"..self.file.."|"..self.mod_time.."|"..pageno.."|"
|
||||||
..zoom.."|"..rotation.."|"..gamma.."|"..render_mode..(color and "|color" or "")
|
..zoom.."|"..rotation.."|"..gamma.."|"..render_mode..(color and "|color" or "")
|
||||||
@@ -386,7 +398,16 @@ function Document:renderPage(pageno, rect, zoom, rotation, gamma, render_mode)
|
|||||||
hash_excerpt = hash.."|"..tostring(rect)
|
hash_excerpt = hash.."|"..tostring(rect)
|
||||||
tile = DocCache:check(hash_excerpt)
|
tile = DocCache:check(hash_excerpt)
|
||||||
end
|
end
|
||||||
if tile then return tile end
|
if tile then
|
||||||
|
if self.tile_cache_validity_ts then
|
||||||
|
if tile.created_ts and tile.created_ts >= self.tile_cache_validity_ts then
|
||||||
|
return tile
|
||||||
|
end
|
||||||
|
logger.dbg("discarding stale cached tile")
|
||||||
|
else
|
||||||
|
return tile
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
self:preRenderPage()
|
self:preRenderPage()
|
||||||
|
|
||||||
@@ -411,6 +432,7 @@ function Document:renderPage(pageno, rect, zoom, rotation, gamma, render_mode)
|
|||||||
-- prepare cache item with contained blitbuffer
|
-- prepare cache item with contained blitbuffer
|
||||||
tile = TileCacheItem:new{
|
tile = TileCacheItem:new{
|
||||||
persistent = true,
|
persistent = true,
|
||||||
|
created_ts = os.time(),
|
||||||
excerpt = size,
|
excerpt = size,
|
||||||
pageno = pageno,
|
pageno = pageno,
|
||||||
bb = Blitbuffer.new(size.w, size.h, self.render_color and self.color_bb_type or nil)
|
bb = Blitbuffer.new(size.w, size.h, self.render_color and self.color_bb_type or nil)
|
||||||
|
|||||||
@@ -208,6 +208,20 @@ local function _quadpointsFromPboxes(pboxes)
|
|||||||
return quadpoints, n
|
return quadpoints, n
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function _quadpointsToPboxes(quadpoints, n)
|
||||||
|
-- reverse of previous function
|
||||||
|
local pboxes = {}
|
||||||
|
for i=1, n do
|
||||||
|
table.insert(pboxes, {
|
||||||
|
x = quadpoints[8*i-4],
|
||||||
|
y = quadpoints[8*i-3],
|
||||||
|
w = quadpoints[8*i-6] - quadpoints[8*i-4],
|
||||||
|
h = quadpoints[8*i-5] - quadpoints[8*i-3],
|
||||||
|
})
|
||||||
|
end
|
||||||
|
return pboxes
|
||||||
|
end
|
||||||
|
|
||||||
function PdfDocument:saveHighlight(pageno, item)
|
function PdfDocument:saveHighlight(pageno, item)
|
||||||
local can_write = self:_checkIfWritable()
|
local can_write = self:_checkIfWritable()
|
||||||
if can_write ~= true then return can_write end
|
if can_write ~= true then return can_write end
|
||||||
@@ -223,8 +237,12 @@ function PdfDocument:saveHighlight(pageno, item)
|
|||||||
elseif item.drawer == "strikeout" then
|
elseif item.drawer == "strikeout" then
|
||||||
annot_type = C.PDF_ANNOT_STRIKEOUT
|
annot_type = C.PDF_ANNOT_STRIKEOUT
|
||||||
end
|
end
|
||||||
page:addMarkupAnnotation(quadpoints, n, annot_type)
|
page:addMarkupAnnotation(quadpoints, n, annot_type) -- may update/adjust quadpoints
|
||||||
|
-- Update pboxes with the possibly adjusted coordinates (this will have it updated
|
||||||
|
-- in self.view.highlight.saved[page])
|
||||||
|
item.pboxes = _quadpointsToPboxes(quadpoints, n)
|
||||||
page:close()
|
page:close()
|
||||||
|
self:resetTileCacheValidity()
|
||||||
end
|
end
|
||||||
|
|
||||||
function PdfDocument:deleteHighlight(pageno, item)
|
function PdfDocument:deleteHighlight(pageno, item)
|
||||||
@@ -237,6 +255,7 @@ function PdfDocument:deleteHighlight(pageno, item)
|
|||||||
local annot = page:getMarkupAnnotation(quadpoints, n)
|
local annot = page:getMarkupAnnotation(quadpoints, n)
|
||||||
if annot ~= nil then
|
if annot ~= nil then
|
||||||
page:deleteMarkupAnnotation(annot)
|
page:deleteMarkupAnnotation(annot)
|
||||||
|
self:resetTileCacheValidity()
|
||||||
end
|
end
|
||||||
page:close()
|
page:close()
|
||||||
end
|
end
|
||||||
@@ -251,6 +270,7 @@ function PdfDocument:updateHighlightContents(pageno, item, contents)
|
|||||||
local annot = page:getMarkupAnnotation(quadpoints, n)
|
local annot = page:getMarkupAnnotation(quadpoints, n)
|
||||||
if annot ~= nil then
|
if annot ~= nil then
|
||||||
page:updateMarkupAnnotation(annot, contents)
|
page:updateMarkupAnnotation(annot, contents)
|
||||||
|
self:resetTileCacheValidity()
|
||||||
end
|
end
|
||||||
page:close()
|
page:close()
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ function TileCacheItem:totable()
|
|||||||
size = self.size,
|
size = self.size,
|
||||||
pageno = self.pageno,
|
pageno = self.pageno,
|
||||||
excerpt = self.excerpt,
|
excerpt = self.excerpt,
|
||||||
|
created_ts = self.created_ts,
|
||||||
persistent = self.persistent,
|
persistent = self.persistent,
|
||||||
bb = {
|
bb = {
|
||||||
w = self.bb.w,
|
w = self.bb.w,
|
||||||
@@ -51,6 +52,7 @@ function TileCacheItem:fromtable(t)
|
|||||||
self.size = t.size
|
self.size = t.size
|
||||||
self.pageno = t.pageno
|
self.pageno = t.pageno
|
||||||
self.excerpt = t.excerpt
|
self.excerpt = t.excerpt
|
||||||
|
self.created_ts = t.created_ts
|
||||||
self.persistent = t.persistent
|
self.persistent = t.persistent
|
||||||
self.bb = Blitbuffer.fromstring(t.bb.w, t.bb.h, t.bb.fmt, t.bb.data, t.bb.stride)
|
self.bb = Blitbuffer.fromstring(t.bb.w, t.bb.h, t.bb.fmt, t.bb.data, t.bb.stride)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user