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:
poire-z
2021-07-18 19:56:19 +02:00
parent eeb09d2150
commit e3bac94db1
5 changed files with 49 additions and 3 deletions

View File

@@ -208,6 +208,20 @@ local function _quadpointsFromPboxes(pboxes)
return quadpoints, n
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)
local can_write = self:_checkIfWritable()
if can_write ~= true then return can_write end
@@ -223,8 +237,12 @@ function PdfDocument:saveHighlight(pageno, item)
elseif item.drawer == "strikeout" then
annot_type = C.PDF_ANNOT_STRIKEOUT
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()
self:resetTileCacheValidity()
end
function PdfDocument:deleteHighlight(pageno, item)
@@ -237,6 +255,7 @@ function PdfDocument:deleteHighlight(pageno, item)
local annot = page:getMarkupAnnotation(quadpoints, n)
if annot ~= nil then
page:deleteMarkupAnnotation(annot)
self:resetTileCacheValidity()
end
page:close()
end
@@ -251,6 +270,7 @@ function PdfDocument:updateHighlightContents(pageno, item, contents)
local annot = page:getMarkupAnnotation(quadpoints, n)
if annot ~= nil then
page:updateMarkupAnnotation(annot, contents)
self:resetTileCacheValidity()
end
page:close()
end