2
0
mirror of https://github.com/koreader/koreader synced 2024-10-31 21:20:20 +00:00

restrict highlight in current page area

This should fix #588.

Highlight in multiple pages is too complicated and requires large
code refactoring and will not be considered for now.
This commit is contained in:
chrox 2014-07-02 16:38:09 +08:00
parent c1323fb882
commit 27b15b7020
2 changed files with 37 additions and 0 deletions

View File

@ -231,6 +231,13 @@ function ReaderHighlight:onHoldPan(arg, ges)
DEBUG("no previous hold position")
return true
end
local page_area = self.view:getScreenPageArea(self.hold_pos.page)
DEBUG("current page area", page_area)
if ges.pos:notIntersectWith(page_area) then
DEBUG("not inside page area")
return true
end
self.holdpan_pos = self.view:screenToPageTransform(ges.pos)
DEBUG("holdpan position in page", self.holdpan_pos)
self.selected_text = self.ui.document:getTextFromPositions(self.hold_pos, self.holdpan_pos)

View File

@ -177,6 +177,36 @@ function ReaderView:pageToScreenTransform(page, rect)
end
end
--[[
Get page area on screen for a given page number
--]]
function ReaderView:getScreenPageArea(page)
if self.ui.document.info.has_pages then
local area = Geom:new{x = 0, y = 0}
if self.page_scroll then
for _, state in ipairs(self.page_states) do
if page ~= state.page then
area.y = area.y + state.visible_area.h + state.offset.y
area.y = area.y + self.page_gap.height
else
area.x = state.offset.x
area.w = state.visible_area.w
area.h = state.visible_area.h
return area
end
end
else
area.x = self.state.offset.x
area.y = self.state.offset.y
area.w = self.visible_area.w
area.h = self.visible_area.h
return area
end
else
return self.dimen:copy()
end
end
function ReaderView:drawPageBackground(bb, x, y)
bb:paintRect(x, y, self.dimen.w, self.dimen.h, self.page_bgcolor)
end