mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
show a box indicator when tapping on a link
only for PDF/DJVU docs for now since there is no easy way to get link box from crengine
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
local InputContainer = require("ui/widget/container/inputcontainer")
|
||||
local GestureRange = require("ui/gesturerange")
|
||||
local LinkBox = require("ui/widget/linkbox")
|
||||
local UIManager = require("ui/uimanager")
|
||||
local Geom = require("ui/geometry")
|
||||
local Screen = require("ui/screen")
|
||||
local Device = require("ui/device")
|
||||
@@ -59,9 +61,18 @@ function ReaderLink:onTap(arg, ges)
|
||||
if self.ui.document.info.has_pages then
|
||||
local pos = self.view:screenToPageTransform(ges.pos)
|
||||
if pos then
|
||||
local link = self.ui.document:getLinkFromPosition(pos.page, pos)
|
||||
if link then
|
||||
return self:onGotoLink(link)
|
||||
local link, lbox = self.ui.document:getLinkFromPosition(pos.page, pos)
|
||||
if link and lbox then
|
||||
-- screen box that holds the link
|
||||
local sbox = self.view:pageToScreenTransform(pos.page, lbox)
|
||||
if sbox then
|
||||
UIManager:show(LinkBox:new{
|
||||
box = sbox,
|
||||
timeout = 0.5,
|
||||
callback = function() self:onGotoLink(link) end
|
||||
})
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
|
||||
@@ -167,6 +167,7 @@ Given rectangle in original page return rectangle on the screen
|
||||
]]--
|
||||
function ReaderView:pageToScreenTransform(page, rect)
|
||||
if self.ui.document.info.has_pages then
|
||||
rect = self.ui.document:nativeToPageRectTransform(page, rect)
|
||||
if self.page_scroll then
|
||||
return self:getScrollPageRect(page, rect)
|
||||
else
|
||||
|
||||
@@ -72,6 +72,10 @@ function DjvuDocument:getPageBoxesFromPositions(pageno, ppos0, ppos1)
|
||||
return self.koptinterface:getPageBoxesFromPositions(self, pageno, ppos0, ppos1)
|
||||
end
|
||||
|
||||
function DjvuDocument:nativeToPageRectTransform(pageno, rect)
|
||||
return self.koptinterface:nativeToPageRectTransform(self, pageno, rect)
|
||||
end
|
||||
|
||||
function DjvuDocument:getOCRWord(pageno, wbox)
|
||||
return self.koptinterface:getOCRWord(self, pageno, wbox)
|
||||
end
|
||||
|
||||
@@ -843,13 +843,13 @@ function KoptInterface:getLinkFromPosition(doc, pageno, pos)
|
||||
local link = page_links[i]
|
||||
-- enlarge tappable link box
|
||||
local lbox = Geom:new{
|
||||
x = link.x0 - Screen:scaleByDPI(15),
|
||||
y = link.y0 - Screen:scaleByDPI(15),
|
||||
w = link.x1 - link.x0 + Screen:scaleByDPI(30),
|
||||
h = link.y1 - link.y0 + Screen:scaleByDPI(30)
|
||||
x = link.x0 - Screen:scaleByDPI(5),
|
||||
y = link.y0 - Screen:scaleByDPI(5),
|
||||
w = link.x1 - link.x0 + Screen:scaleByDPI(10),
|
||||
h = link.y1 - link.y0 + Screen:scaleByDPI(10)
|
||||
}
|
||||
if inside_box(pos, lbox) and link.page then
|
||||
return link
|
||||
return link, lbox
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -972,6 +972,32 @@ function KoptInterface:getPageBoxesFromPositions(doc, pageno, ppos0, ppos1)
|
||||
end
|
||||
end
|
||||
|
||||
--[[
|
||||
get page rect from native rect
|
||||
--]]
|
||||
function KoptInterface:nativeToPageRectTransform(doc, pageno, rect)
|
||||
if doc.configurable.text_wrap == 1 then
|
||||
local pos0 = {
|
||||
x = rect.x + 5, y = rect.y + 5
|
||||
}
|
||||
local pos1 = {
|
||||
x = rect.x + rect.w - 5,
|
||||
y = rect.y + rect.h - 5
|
||||
}
|
||||
local boxes = self:getPageBoxesFromPositions(doc, pageno, pos0, pos1)
|
||||
res_rect = nil
|
||||
if #boxes > 0 then
|
||||
res_rect = boxes[1]
|
||||
for _, box in pairs(boxes) do
|
||||
res_rect = res_rect:combine(box)
|
||||
end
|
||||
end
|
||||
return res_rect
|
||||
else
|
||||
return rect
|
||||
end
|
||||
end
|
||||
|
||||
--[[
|
||||
helper functions
|
||||
--]]
|
||||
|
||||
@@ -97,6 +97,10 @@ function PdfDocument:getPageBoxesFromPositions(pageno, ppos0, ppos1)
|
||||
return self.koptinterface:getPageBoxesFromPositions(self, pageno, ppos0, ppos1)
|
||||
end
|
||||
|
||||
function PdfDocument:nativeToPageRectTransform(pageno, rect)
|
||||
return self.koptinterface:nativeToPageRectTransform(self, pageno, rect)
|
||||
end
|
||||
|
||||
function PdfDocument:getOCRWord(pageno, wbox)
|
||||
return self.koptinterface:getOCRWord(self, pageno, wbox)
|
||||
end
|
||||
|
||||
52
frontend/ui/widget/linkbox.lua
Normal file
52
frontend/ui/widget/linkbox.lua
Normal file
@@ -0,0 +1,52 @@
|
||||
local InputContainer = require("ui/widget/container/inputcontainer")
|
||||
local GestureRange = require("ui/gesturerange")
|
||||
local UIManager = require("ui/uimanager")
|
||||
local Screen = require("ui/screen")
|
||||
local Geom = require("ui/geometry")
|
||||
local Device = require("ui/device")
|
||||
|
||||
local LinkBox = InputContainer:new{
|
||||
box = nil,
|
||||
color = 8,
|
||||
radius = 0,
|
||||
bordersize = 2,
|
||||
}
|
||||
|
||||
function LinkBox:init()
|
||||
if Device:isTouchDevice() then
|
||||
self.ges_events.TapClose = {
|
||||
GestureRange:new{
|
||||
ges = "tap",
|
||||
range = Geom:new{
|
||||
x = 0, y = 0,
|
||||
w = Screen:getWidth(),
|
||||
h = Screen:getHeight(),
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
function LinkBox:paintTo(bb)
|
||||
bb:paintBorder(self.box.x, self.box.y, self.box.w, self.box.h,
|
||||
self.bordersize, self.color, self.radius)
|
||||
end
|
||||
|
||||
function LinkBox:onShow()
|
||||
if self.timeout then
|
||||
UIManager:scheduleIn(self.timeout, function()
|
||||
UIManager:close(self)
|
||||
if self.callback then self.callback() end
|
||||
end)
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
function LinkBox:onTapClose()
|
||||
UIManager:close(self)
|
||||
self.callback = nil
|
||||
return true
|
||||
end
|
||||
|
||||
return LinkBox
|
||||
|
||||
Reference in New Issue
Block a user