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

Annotations: fix exporting (#12261)

This commit is contained in:
hius07 2024-08-01 13:14:46 +03:00 committed by GitHub
parent e5fb836a81
commit a24bb70066
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 34 additions and 6 deletions

View File

@ -17,6 +17,7 @@ function ReaderAnnotation:buildAnnotation(bm, highlights, init)
end end
local chapter = bm.chapter local chapter = bm.chapter
local hl, pageno = self:getHighlightForBookmark(highlights, bm) local hl, pageno = self:getHighlightForBookmark(highlights, bm)
local pageref
if init then if init then
if note and self.ui.bookmark:isBookmarkAutoText(bm) then if note and self.ui.bookmark:isBookmarkAutoText(bm) then
note = nil note = nil
@ -24,7 +25,12 @@ function ReaderAnnotation:buildAnnotation(bm, highlights, init)
if chapter == nil then if chapter == nil then
chapter = self.ui.toc:getTocTitleByPage(bm.page) chapter = self.ui.toc:getTocTitleByPage(bm.page)
end end
pageno = self.ui.bookmark:getBookmarkPageString(bm.page) if self.ui.rolling then
pageno = self.document:getPageFromXPointer(bm.page)
pageref = self:getPageRef(bm.page, pageno)
else
pageno = bm.page
end
end end
if self.ui.paging and bm.pos0 and not bm.pos0.page then if self.ui.paging and bm.pos0 and not bm.pos0.page then
-- old single-page reflow highlights do not have page in position -- old single-page reflow highlights do not have page in position
@ -53,7 +59,8 @@ function ReaderAnnotation:buildAnnotation(bm, highlights, init)
text_edited = hl.edited, -- true if highlighted text has been edited text_edited = hl.edited, -- true if highlighted text has been edited
note = note, -- user's note, editable note = note, -- user's note, editable
chapter = chapter, -- book chapter title chapter = chapter, -- book chapter title
pageno = pageno, -- book page number (honors reference pages and hidden flows) pageno = pageno, -- book page number (continuous numbering, used by KOHighlights)
pageref = pageref, -- book page number (iff: reference pages or hidden flows)
page = bm.page, -- highlight location, xPointer or number (pdf) page = bm.page, -- highlight location, xPointer or number (pdf)
pos0 = bm.pos0, -- highlight start position, xPointer (== page) or table (pdf) pos0 = bm.pos0, -- highlight start position, xPointer (== page) or table (pdf)
pos1 = bm.pos1, -- highlight end position, xPointer or table (pdf) pos1 = bm.pos1, -- highlight end position, xPointer or table (pdf)
@ -231,7 +238,8 @@ function ReaderAnnotation:updatePageNumbers(force_update)
if self.ui.paging then return end if self.ui.paging then return end
if force_update or self.needs_update then -- triggered by ReaderRolling on document layout change if force_update or self.needs_update then -- triggered by ReaderRolling on document layout change
for _, item in ipairs(self.annotations) do for _, item in ipairs(self.annotations) do
item.pageno = self.ui.bookmark:getBookmarkPageString(item.page) item.pageno = self.document:getPageFromXPointer(item.page)
item.pageref = self:getPageRef(item.page, item.pageno)
end end
end end
self.needs_update = nil self.needs_update = nil
@ -266,7 +274,8 @@ function ReaderAnnotation:updateItemByXPointer(item)
item.text = chapter and T(_("in %1"), chapter) or nil item.text = chapter and T(_("in %1"), chapter) or nil
end end
item.chapter = chapter item.chapter = chapter
item.pageno = self.ui.bookmark:getBookmarkPageString(item.page) item.pageno = self.document:getPageFromXPointer(item.page)
item.pageref = self:getPageRef(item.page, item.pageno)
end end
function ReaderAnnotation:isItemInPositionOrderRolling(a, b) function ReaderAnnotation:isItemInPositionOrderRolling(a, b)
@ -397,7 +406,12 @@ end
function ReaderAnnotation:addItem(item) function ReaderAnnotation:addItem(item)
item.datetime = os.date("%Y-%m-%d %H:%M:%S") item.datetime = os.date("%Y-%m-%d %H:%M:%S")
item.pageno = self.ui.bookmark:getBookmarkPageString(item.page) if self.ui.rolling then
item.pageno = self.document:getPageFromXPointer(item.page)
item.pageref = self:getPageRef(item.page, item.pageno)
else
item.pageno = item.page
end
local index = self:getInsertionIndex(item) local index = self:getInsertionIndex(item)
table.insert(self.annotations, index, item) table.insert(self.annotations, index, item)
return index return index
@ -405,6 +419,20 @@ end
-- info -- info
function ReaderAnnotation:getPageRef(xp, pn) -- same as ReaderBookmark:getBookmarkPageString()
local pageref
if self.ui.pagemap:wantsPageLabels() then
pageref = self.ui.pagemap:getXPointerPageLabel(xp, true)
elseif self.ui.document:hasHiddenFlows() then
pageref = tostring(self.ui.document:getPageNumberInFlow(pn))
local flow = self.ui.document:getPageFlow(pn)
if flow > 0 then
pageref = T("[%1]%2", pageref, flow)
end
end
return pageref
end
function ReaderAnnotation:hasAnnotations() function ReaderAnnotation:hasAnnotations()
return #self.annotations > 0 return #self.annotations > 0
end end

View File

@ -240,7 +240,7 @@ function MyClipping:parseAnnotations(annotations, book)
if item.drawer then if item.drawer then
local clipping = { local clipping = {
sort = "highlight", sort = "highlight",
page = item.pageno, page = item.pageref or item.pageno,
time = self:getTime(item.datetime), time = self:getTime(item.datetime),
text = self:getText(item.text), text = self:getText(item.text),
note = item.note and self:getText(item.note), note = item.note and self:getText(item.note),