From d24d5e413ef8e891b7603082c277d8729bfe32fc Mon Sep 17 00:00:00 2001 From: chrox Date: Tue, 21 Jan 2014 11:59:17 +0800 Subject: [PATCH] add following page link in reflowed page --- frontend/document/koptinterface.lua | 35 +++++++++++++++++++++++++++++ frontend/document/pdfdocument.lua | 4 ++++ frontend/ui/reader/readerlink.lua | 29 +++--------------------- 3 files changed, 42 insertions(+), 26 deletions(-) diff --git a/frontend/document/koptinterface.lua b/frontend/document/koptinterface.lua index 76736d552..940921dba 100644 --- a/frontend/document/koptinterface.lua +++ b/frontend/document/koptinterface.lua @@ -746,6 +746,41 @@ function KoptInterface:getWordFromNativePosition(doc, boxes, pos) return word_box end +--[[ +get link from position in screen page +]]-- +function KoptInterface:getLinkFromPosition(doc, pageno, pos) + local function inside_box(pos, box) + if pos then + local x, y = pos.x, pos.y + if box.x <= x and box.y <= y + and box.x + box.w >= x + and box.y + box.h >= y then + return true + end + end + end + local page_links = doc:getPageLinks(pageno) + if page_links then + if doc.configurable.text_wrap == 1 then + pos = self:reflowToNativePosTransform(doc, pageno, pos, {x=0.5, y=0.5}) + end + for i = 1, #page_links do + 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) + } + if inside_box(pos, lbox) and link.page then + return link + end + end + end +end + --[[ transform position in native page to reflowed page ]]-- diff --git a/frontend/document/pdfdocument.lua b/frontend/document/pdfdocument.lua index bc9d2367c..f70f1485c 100644 --- a/frontend/document/pdfdocument.lua +++ b/frontend/document/pdfdocument.lua @@ -112,6 +112,10 @@ function PdfDocument:getPageLinks(pageno) return links end +function PdfDocument:getLinkFromPosition(pageno, pos) + return self.koptinterface:getLinkFromPosition(self, pageno, pos) +end + function PdfDocument:getPageBBox(pageno) return self.koptinterface:getPageBBox(self, pageno) end diff --git a/frontend/ui/reader/readerlink.lua b/frontend/ui/reader/readerlink.lua index 789233688..bcb7aa0a1 100644 --- a/frontend/ui/reader/readerlink.lua +++ b/frontend/ui/reader/readerlink.lua @@ -51,34 +51,11 @@ function ReaderLink:onSetDimensions(dimen) end function ReaderLink:onTap(arg, ges) - local function inside_box(pos, box) - if pos then - local x, y = pos.x, pos.y - if box.x <= x and box.y <= y - and box.x + box.w >= x - and box.y + box.h >= y then - return true - end - end - end if self.ui.document.info.has_pages then local pos = self.view:screenToPageTransform(ges.pos) - local page_links = self.ui.document:getPageLinks(pos.page) - --DEBUG("page links", page_links) - if page_links then - for i = 1, #page_links do - 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) - } - if inside_box(pos, lbox) and link.page then - return self:onGotoLink(link) - end - end + local link = self.ui.document:getLinkFromPosition(pos.page, pos) + if link then + return self:onGotoLink(link) end else local link = self.ui.document:getLinkFromPosition(ges.pos)