mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
PdfDocument: Unbreak highlights (#7457)
Regression since #7411 Fix #7456
This commit is contained in:
@@ -234,7 +234,6 @@ function DocumentRegistry:closeDocument(file)
|
||||
end
|
||||
|
||||
-- load implementations:
|
||||
|
||||
require("document/credocument"):register(DocumentRegistry)
|
||||
require("document/pdfdocument"):register(DocumentRegistry)
|
||||
require("document/djvudocument"):register(DocumentRegistry)
|
||||
|
||||
@@ -175,53 +175,6 @@ function PdfDocument:getPageLinks(pageno)
|
||||
return links
|
||||
end
|
||||
|
||||
function PdfDocument:saveHighlight(pageno, item)
|
||||
local can_write = self:_checkIfWritable()
|
||||
if can_write ~= true then return can_write end
|
||||
|
||||
self.is_edited = true
|
||||
local quadpoints, n = self:_quadpointsFromPboxes(item.pboxes)
|
||||
local page = self._document:openPage(pageno)
|
||||
local annot_type = C.PDF_ANNOT_HIGHLIGHT
|
||||
if item.drawer == "lighten" then
|
||||
annot_type = C.PDF_ANNOT_HIGHLIGHT
|
||||
elseif item.drawer == "underscore" then
|
||||
annot_type = C.PDF_ANNOT_UNDERLINE
|
||||
elseif item.drawer == "strikeout" then
|
||||
annot_type = C.PDF_ANNOT_STRIKEOUT
|
||||
end
|
||||
page:addMarkupAnnotation(quadpoints, n, annot_type)
|
||||
page:close()
|
||||
end
|
||||
|
||||
function Document:deleteHighlight(pageno, item)
|
||||
local can_write = self:_checkIfWritable()
|
||||
if can_write ~= true then return can_write end
|
||||
|
||||
self.is_edited = true
|
||||
local quadpoints, n = self:_quadpointsFromPboxes(item.pboxes)
|
||||
local page = self._document:openPage(pageno)
|
||||
local annot = page:getMarkupAnnotation(quadpoints, n)
|
||||
if annot ~= nil then
|
||||
page:deleteMarkupAnnotation(annot)
|
||||
end
|
||||
page:close()
|
||||
end
|
||||
|
||||
function PdfDocument:updateHighlightContents(pageno, item, contents)
|
||||
local can_write = self:_checkIfWritable()
|
||||
if can_write ~= true then return can_write end
|
||||
|
||||
self.is_edited = true
|
||||
local quadpoints, n = self:_quadpointsFromPboxes(item.pboxes)
|
||||
local page = self._document:openPage(pageno)
|
||||
local annot = page:getMarkupAnnotation(quadpoints, n)
|
||||
if annot ~= nil then
|
||||
page:updateMarkupAnnotation(annot, contents)
|
||||
end
|
||||
page:close()
|
||||
end
|
||||
|
||||
-- returns nil if file is not a pdf, true if document is a writable pdf, false else
|
||||
function PdfDocument:_checkIfWritable()
|
||||
local suffix = util.getFileNameSuffix(self.file)
|
||||
@@ -234,7 +187,7 @@ function PdfDocument:_checkIfWritable()
|
||||
return self.is_writable
|
||||
end
|
||||
|
||||
function PdfDocument:_quadpointsFromPboxes(pboxes)
|
||||
local function _quadpointsFromPboxes(pboxes)
|
||||
-- will also need mupdf_h.lua to be evaluated once
|
||||
-- but this is guaranteed at this point
|
||||
local n = #pboxes
|
||||
@@ -254,6 +207,53 @@ function PdfDocument:_quadpointsFromPboxes(pboxes)
|
||||
return quadpoints, n
|
||||
end
|
||||
|
||||
function PdfDocument:saveHighlight(pageno, item)
|
||||
local can_write = self:_checkIfWritable()
|
||||
if can_write ~= true then return can_write end
|
||||
|
||||
self.is_edited = true
|
||||
local quadpoints, n = _quadpointsFromPboxes(item.pboxes)
|
||||
local page = self._document:openPage(pageno)
|
||||
local annot_type = C.PDF_ANNOT_HIGHLIGHT
|
||||
if item.drawer == "lighten" then
|
||||
annot_type = C.PDF_ANNOT_HIGHLIGHT
|
||||
elseif item.drawer == "underscore" then
|
||||
annot_type = C.PDF_ANNOT_UNDERLINE
|
||||
elseif item.drawer == "strikeout" then
|
||||
annot_type = C.PDF_ANNOT_STRIKEOUT
|
||||
end
|
||||
page:addMarkupAnnotation(quadpoints, n, annot_type)
|
||||
page:close()
|
||||
end
|
||||
|
||||
function PdfDocument:deleteHighlight(pageno, item)
|
||||
local can_write = self:_checkIfWritable()
|
||||
if can_write ~= true then return can_write end
|
||||
|
||||
self.is_edited = true
|
||||
local quadpoints, n = _quadpointsFromPboxes(item.pboxes)
|
||||
local page = self._document:openPage(pageno)
|
||||
local annot = page:getMarkupAnnotation(quadpoints, n)
|
||||
if annot ~= nil then
|
||||
page:deleteMarkupAnnotation(annot)
|
||||
end
|
||||
page:close()
|
||||
end
|
||||
|
||||
function PdfDocument:updateHighlightContents(pageno, item, contents)
|
||||
local can_write = self:_checkIfWritable()
|
||||
if can_write ~= true then return can_write end
|
||||
|
||||
self.is_edited = true
|
||||
local quadpoints, n = _quadpointsFromPboxes(item.pboxes)
|
||||
local page = self._document:openPage(pageno)
|
||||
local annot = page:getMarkupAnnotation(quadpoints, n)
|
||||
if annot ~= nil then
|
||||
page:updateMarkupAnnotation(annot, contents)
|
||||
end
|
||||
page:close()
|
||||
end
|
||||
|
||||
function PdfDocument:writeDocument()
|
||||
logger.info("writing document to", self.file)
|
||||
self._document:writeDocument(self.file)
|
||||
|
||||
Reference in New Issue
Block a user