readerview: draw annotations

reviewable/pr11563/r4
hius07 2 months ago committed by GitHub
parent aab5b77fc8
commit 603db3e2cc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -522,6 +522,7 @@ function ReaderView:drawTempHighlight(bb, x, y)
end end
function ReaderView:drawSavedHighlight(bb, x, y) function ReaderView:drawSavedHighlight(bb, x, y)
if #self.ui.annotation.annotations == 0 then return end
if self.ui.paging then if self.ui.paging then
self:drawPageSavedHighlight(bb, x, y) self:drawPageSavedHighlight(bb, x, y)
else else
@ -535,18 +536,13 @@ function ReaderView:getPageSavedHighlights(page)
local highlights = {} local highlights = {}
local is_reflow = self.document.configurable.text_wrap local is_reflow = self.document.configurable.text_wrap
self.document.configurable.text_wrap = 0 self.document.configurable.text_wrap = 0
for page_num, page_highlights in pairs(self.highlight.saved) do for i, highlight in ipairs(self.ui.annotation.annotations) do
for i, highlight in ipairs(page_highlights) do if highlight.pos0.page <= page and page <= highlight.pos1.page then
-- old single-page reflow highlights do not have page in position if highlight.pos0.page == highlight.pos1.page then -- single-page highlight
local pos0_page = highlight.pos0.page or page_num table.insert(highlights, highlight)
local pos1_page = highlight.pos1.page or page_num else -- multi-page highlight
if pos0_page <= page and page <= pos1_page then local item = self.ui.highlight:getSavedExtendedHighlightPage(highlight, page, i)
if pos0_page == pos1_page then -- single-page highlight table.insert(highlights, item)
table.insert(highlights, highlight)
else -- multi-page highlight
local item = self.ui.highlight:getSavedExtendedHighlightPage(highlight, page, i)
table.insert(highlights, item)
end
end end
end end
end end
@ -558,16 +554,14 @@ function ReaderView:drawPageSavedHighlight(bb, x, y)
local pages = self:getCurrentPageList() local pages = self:getCurrentPageList()
for _, page in ipairs(pages) do for _, page in ipairs(pages) do
local items = self:getPageSavedHighlights(page) local items = self:getPageSavedHighlights(page)
for _, item in ipairs(items) do for __, item in ipairs(items) do
local boxes = self.document:getPageBoxesFromPositions(page, item.pos0, item.pos1) local boxes = self.document:getPageBoxesFromPositions(page, item.pos0, item.pos1)
if boxes then if boxes then
local drawer = item.drawer or self.highlight.saved_drawer local draw_note_mark = self.highlight.note_mark and not self.ui.bookmark:isAnnotationAutoText(item)
local draw_note_mark = self.highlight.note_mark and for ___, box in ipairs(boxes) do
self.ui.bookmark:getBookmarkNote({datetime = item.datetime})
for _, box in ipairs(boxes) do
local rect = self:pageToScreenTransform(page, box) local rect = self:pageToScreenTransform(page, box)
if rect then if rect then
self:drawHighlightRect(bb, x, y, rect, drawer, draw_note_mark) self:drawHighlightRect(bb, x, y, rect, item.drawer, draw_note_mark)
if draw_note_mark and self.highlight.note_mark == "sidemark" then if draw_note_mark and self.highlight.note_mark == "sidemark" then
draw_note_mark = false -- side mark in the first line only draw_note_mark = false -- side mark in the first line only
end end
@ -583,48 +577,38 @@ function ReaderView:drawXPointerSavedHighlight(bb, x, y)
-- showing menu...). We might want to cache these boxes per page (and -- showing menu...). We might want to cache these boxes per page (and
-- clear that cache when page layout change or highlights are added -- clear that cache when page layout change or highlights are added
-- or removed). -- or removed).
local cur_view_top, cur_view_bottom -- Even in page mode, it's safer to use pos and ui.dimen.h
for _, items in pairs(self.highlight.saved) do -- than pages' xpointers pos, even if ui.dimen.h is a bit
if items then -- larger than pages' heights
for j = 1, #items do local cur_view_top = self.document:getCurrentPos()
local item = items[j] local cur_view_bottom
local pos0, pos1 = item.pos0, item.pos1 if self.view_mode == "page" and self.document:getVisiblePageCount() > 1 then
-- document:getScreenBoxesFromPositions() is expensive, so we cur_view_bottom = cur_view_top + 2 * self.ui.dimen.h
-- first check this item is on current page else
if not cur_view_top then cur_view_bottom = cur_view_top + self.ui.dimen.h
-- Even in page mode, it's safer to use pos and ui.dimen.h end
-- than pages' xpointers pos, even if ui.dimen.h is a bit for _, item in ipairs(self.ui.annotation.annotations) do
-- larger than pages' heights if item.drawer then
cur_view_top = self.document:getCurrentPos() -- document:getScreenBoxesFromPositions() is expensive, so we
if self.view_mode == "page" and self.document:getVisiblePageCount() > 1 then -- first check if this item is on current page
cur_view_bottom = cur_view_top + 2 * self.ui.dimen.h local start_pos = self.document:getPosFromXPointer(item.pos0)
else local end_pos = self.document:getPosFromXPointer(item.pos1)
cur_view_bottom = cur_view_top + self.ui.dimen.h if start_pos <= cur_view_bottom and end_pos >= cur_view_top then
end local boxes = self.document:getScreenBoxesFromPositions(item.pos0, item.pos1, true) -- get_segments=true
end if boxes then
local spos0 = self.document:getPosFromXPointer(pos0) local draw_note_mark = self.highlight.note_mark and not self.ui.bookmark:isAnnotationAutoText(item)
local spos1 = self.document:getPosFromXPointer(pos1) for __, box in ipairs(boxes) do
local start_pos = math.min(spos0, spos1) if box.h ~= 0 then
local end_pos = math.max(spos0, spos1) self:drawHighlightRect(bb, x, y, box, item.drawer, draw_note_mark)
if start_pos <= cur_view_bottom and end_pos >= cur_view_top then if draw_note_mark and self.highlight.note_mark == "sidemark" then
local boxes = self.document:getScreenBoxesFromPositions(pos0, pos1, true) -- get_segments=true draw_note_mark = false -- side mark in the first line only
if boxes then
local drawer = item.drawer or self.highlight.saved_drawer
local draw_note_mark = self.highlight.note_mark and
self.ui.bookmark:getBookmarkNote({datetime = item.datetime})
for _, box in ipairs(boxes) do
if box.h ~= 0 then
self:drawHighlightRect(bb, x, y, box, drawer, draw_note_mark)
if draw_note_mark and self.highlight.note_mark == "sidemark" then
draw_note_mark = false -- side mark in the first line only
end
end end
end -- end for each box end
end -- end if boxes end
end end
end -- end for each highlight end
end end
end -- end for all saved highlight end
end end
function ReaderView:drawHighlightRect(bb, _x, _y, rect, drawer, draw_note_mark) function ReaderView:drawHighlightRect(bb, _x, _y, rect, drawer, draw_note_mark)

Loading…
Cancel
Save