diff --git a/frontend/apps/reader/modules/readerlink.lua b/frontend/apps/reader/modules/readerlink.lua index f6ca63853..c43a73d29 100644 --- a/frontend/apps/reader/modules/readerlink.lua +++ b/frontend/apps/reader/modules/readerlink.lua @@ -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 diff --git a/frontend/apps/reader/modules/readerview.lua b/frontend/apps/reader/modules/readerview.lua index e6c806295..c96f9d5e7 100644 --- a/frontend/apps/reader/modules/readerview.lua +++ b/frontend/apps/reader/modules/readerview.lua @@ -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 diff --git a/frontend/document/djvudocument.lua b/frontend/document/djvudocument.lua index 43a8af236..015f89613 100644 --- a/frontend/document/djvudocument.lua +++ b/frontend/document/djvudocument.lua @@ -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 diff --git a/frontend/document/koptinterface.lua b/frontend/document/koptinterface.lua index 3d92e0882..86eff3435 100644 --- a/frontend/document/koptinterface.lua +++ b/frontend/document/koptinterface.lua @@ -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 --]] diff --git a/frontend/document/pdfdocument.lua b/frontend/document/pdfdocument.lua index 791a63683..7a6018c10 100644 --- a/frontend/document/pdfdocument.lua +++ b/frontend/document/pdfdocument.lua @@ -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 diff --git a/frontend/ui/widget/linkbox.lua b/frontend/ui/widget/linkbox.lua new file mode 100644 index 000000000..e3f3aa797 --- /dev/null +++ b/frontend/ui/widget/linkbox.lua @@ -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 +