From e1fc748faf4642cf7d3ea354c1932528d79e352f Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Fri, 21 Sep 2012 12:01:16 +0200 Subject: [PATCH 01/20] fix indenting to tabs --- pdf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pdf.c b/pdf.c index 0de2150d9..48d7608a9 100644 --- a/pdf.c +++ b/pdf.c @@ -492,9 +492,9 @@ static int getUsedBBox(lua_State *L) { return luaL_error(L, "cannot calculate bbox for page"); } - lua_pushnumber(L, ((double)result.x0)/100); + lua_pushnumber(L, ((double)result.x0)/100); lua_pushnumber(L, ((double)result.y0)/100); - lua_pushnumber(L, ((double)result.x1)/100); + lua_pushnumber(L, ((double)result.x1)/100); lua_pushnumber(L, ((double)result.y1)/100); return 4; From 71ff602cd5f6cbe6b01106e2e2b9c4e508ab197c Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Fri, 21 Sep 2012 13:28:13 +0200 Subject: [PATCH 02/20] getPageLinks implementation for mupdf #72 This is rough first draft, and provides just dump of all links available on pdf page. Binding to Shift+L is temporary and just for debugging! --- pdf.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++ pdfreader.lua | 13 +++++++++++++ unireader.lua | 12 ++++++++++++ 3 files changed, 79 insertions(+) diff --git a/pdf.c b/pdf.c index 48d7608a9..faf813a9b 100644 --- a/pdf.c +++ b/pdf.c @@ -577,6 +577,59 @@ static int cleanCache(lua_State *L) { return 0; } + +static int getPageLinks(lua_State *L) { + fz_link *page_links; + fz_link *link; + + int link_count; + + PdfPage *page = (PdfPage*) luaL_checkudata(L, 1, "pdfpage"); + + page_links = fz_load_links(page->doc->xref, page->page); // page->doc->xref? + + lua_newtable(L); // all links + + link_count = 0; + + for (link = page_links; link; link = link->next) { + lua_newtable(L); // new link + + lua_pushstring(L, "x0"); + lua_pushinteger(L, link->rect.x0); + lua_settable(L, -3); + lua_pushstring(L, "y0"); + lua_pushinteger(L, link->rect.y0); + lua_settable(L, -3); + lua_pushstring(L, "x1"); + lua_pushinteger(L, link->rect.x1); + lua_settable(L, -3); + lua_pushstring(L, "y1"); + lua_pushinteger(L, link->rect.y1); + lua_settable(L, -3); + + if (link->dest.kind == FZ_LINK_URI) { + lua_pushstring(L, "uri"); + lua_pushstring(L, link->dest.ld.uri.uri); + lua_settable(L, -3); + } else if (link->dest.kind == FZ_LINK_GOTO) { + lua_pushstring(L, "page"); + lua_pushinteger(L, link->dest.ld.gotor.page); // FIXME page+1? + lua_settable(L, -3); + } else { + printf("ERROR: unkown link kind: %x", link->dest.kind); + } + + lua_rawseti(L, -2, ++link_count); + } + + printf("## getPageLinks found %d links in document", link_count); + + fz_drop_link(page->doc->context, page_links); + + return 1; +} + static const struct luaL_Reg pdf_func[] = { {"openDocument", openDocument}, {NULL, NULL} @@ -599,6 +652,7 @@ static const struct luaL_Reg pdfpage_meth[] = { {"getSize", getPageSize}, {"getUsedBBox", getUsedBBox}, {"getPageText", getPageText}, + {"getPageLinks", getPageLinks}, {"close", closePage}, {"__gc", closePage}, {"draw", drawPage}, diff --git a/pdfreader.lua b/pdfreader.lua index b14d0a94a..12961d438 100644 --- a/pdfreader.lua +++ b/pdfreader.lua @@ -45,3 +45,16 @@ function PDFReader:getText(pageno) page:close() return text end + +function PDFReader:getPageLinks(pageno) + local ok, page = pcall(self.doc.openPage, self.doc, pageno) + if not ok then + -- TODO: error handling + return nil + end + local links = page:getPageLinks() + Debug("## page:getPageLinks ", links) + page:close() + return links +end + diff --git a/unireader.lua b/unireader.lua index 5e4263714..a9a73f22a 100644 --- a/unireader.lua +++ b/unireader.lua @@ -2062,6 +2062,11 @@ function UniReader:searchHighLight(search) end +function UniReader:getPageLinks(pageno) + Debug("getPageLinks not supported in this format") + return nil +end + -- used in UniReader:showMenu() function UniReader:_drawReadingInfo() local width, height = G_width, G_height @@ -2855,6 +2860,13 @@ function UniReader:addAllCommands() end end ) + self.commands:add(KEY_L, MOD_SHIFT, "L", + "page links", + function(unireader) + Debug("unireader", unireader) + unireader:getPageLinks( unireader.pageno ) + end + ) self.commands:add(KEY_BACK,MOD_ALT,"Back", "close document", function(unireader) From 46afa82b526dfda6c51f5ef6c54aebdfa5decafa Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Mon, 24 Sep 2012 16:35:27 +0200 Subject: [PATCH 03/20] add LF to end of debug message --- pdf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pdf.c b/pdf.c index faf813a9b..0477a6e03 100644 --- a/pdf.c +++ b/pdf.c @@ -623,7 +623,7 @@ static int getPageLinks(lua_State *L) { lua_rawseti(L, -2, ++link_count); } - printf("## getPageLinks found %d links in document", link_count); + printf("## getPageLinks found %d links in document\n", link_count); fz_drop_link(page->doc->context, page_links); From 0828468b121f28ab5d135c503fcbb0309efa4f0b Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Mon, 24 Sep 2012 16:35:48 +0200 Subject: [PATCH 04/20] try to draw inverted rectangles over links This commit nicely shows that we need to translate link coordinates --- unireader.lua | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/unireader.lua b/unireader.lua index a9a73f22a..cc7d189ee 100644 --- a/unireader.lua +++ b/unireader.lua @@ -2860,11 +2860,19 @@ function UniReader:addAllCommands() end end ) - self.commands:add(KEY_L, MOD_SHIFT, "L", + self.commands:add(KEY_L, nil, "L", "page links", function(unireader) - Debug("unireader", unireader) - unireader:getPageLinks( unireader.pageno ) + local links = unireader:getPageLinks( unireader.pageno ) + if next(links) == nil then + showInfoMsgWithDelay("No links on this page", 2000, 1) + else + for i, link in ipairs(links) do + Debug("link", i, link) + fb.bb:invertRect(link.x0, link.y0, link.x1 - link.x0, link.y1 - link.y0) + fb:refresh(1, link.x0, link.y0, link.x1 - link.x0, link.y1 - link.y0) + end + end end ) self.commands:add(KEY_BACK,MOD_ALT,"Back", From 2774350ec60a15aadfbc0b65edcd24c5233248bc Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Mon, 24 Sep 2012 17:49:00 +0200 Subject: [PATCH 05/20] transform coordinates to on-screen values --- unireader.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/unireader.lua b/unireader.lua index cc7d189ee..81379fc15 100644 --- a/unireader.lua +++ b/unireader.lua @@ -2869,8 +2869,9 @@ function UniReader:addAllCommands() else for i, link in ipairs(links) do Debug("link", i, link) - fb.bb:invertRect(link.x0, link.y0, link.x1 - link.x0, link.y1 - link.y0) - fb:refresh(1, link.x0, link.y0, link.x1 - link.x0, link.y1 - link.y0) + local x,y,w,h = self:zoomedRectCoordTransform( link.x0,link.y0, link.x1,link.y1 ) + fb.bb:invertRect(x,y, w,h) + fb:refresh(1, x,y, w,h) end end end From f2eeca73aa0016c2cf217ee6daca34ce3c506f61 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Mon, 24 Sep 2012 20:26:55 +0200 Subject: [PATCH 06/20] overlay keyboard shortcuts on top of links This is example of user interface discussed in #309 --- unireader.lua | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/unireader.lua b/unireader.lua index 81379fc15..67ed4b38c 100644 --- a/unireader.lua +++ b/unireader.lua @@ -2867,12 +2867,61 @@ function UniReader:addAllCommands() if next(links) == nil then showInfoMsgWithDelay("No links on this page", 2000, 1) else + local font_size = math.ceil( (links[1].y1 - links[1].y0) * 1.6 ) + Debug("font_size",font_size) + Debug("shortcuts",SelectMenu.item_shortcuts) + local face = Font:getFace("rifont", font_size) + for i, link in ipairs(links) do Debug("link", i, link) local x,y,w,h = self:zoomedRectCoordTransform( link.x0,link.y0, link.x1,link.y1 ) - fb.bb:invertRect(x,y, w,h) + Debug("box",x,y,w,h) + + fb.bb:dimRect(x,y,w,h) -- black 50% + fb.bb:dimRect(x,y,w,h) -- black 25% + + renderUtf8Text(fb.bb, x + w - font_size, y + font_size, face, SelectMenu.item_shortcuts[i]) + fb:refresh(1, x,y, w,h) end + + local goto_page = nil + + while not goto_page do + + local ev = input.saveWaitForEvent() + ev.code = adjustKeyEvents(ev) + Debug("ev",ev) + + local link = nil + + if ev.type == EV_KEY and ev.value ~= EVENT_VALUE_KEY_RELEASE then + if ev.code >= KEY_Q and ev.code <= KEY_P then + link = ev.code - KEY_Q + 1 + elseif ev.code >= KEY_A and ev.code <= KEY_L then + link = ev.code - KEY_A + 11 + elseif ev.code == KEY_SLASH then + link = 20 + elseif ev.code >= KEY_Z and ev.code <= KEY_M then + link = ev.code - KEY_Z + 21 + elseif ev.code == KEY_DOT then + link = 29 + elseif ev.code == KEY_SYM then + link = 30 + elseif ev.code == KEY_BACK then + goto_page = unireader.pageno + end + end + + if link then + goto_page = links[ link ].page + 1 + end + + Debug("goto_page", goto_page, "now on", unireader.pageno, "link", link) + end + + unireader:goto(goto_page) + end end ) From 1916f5038b5d0d950503721583b3e99a17b253ac Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Mon, 24 Sep 2012 23:24:10 +0200 Subject: [PATCH 07/20] draw links on page as underline --- unireader.lua | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/unireader.lua b/unireader.lua index 67ed4b38c..486e973cc 100644 --- a/unireader.lua +++ b/unireader.lua @@ -1389,6 +1389,14 @@ function UniReader:show(no) self:toggleTextHighLight(self.highlight[no]) end + -- draw links on page + local links = self:getPageLinks( no ) + for i, link in ipairs(links) do + local x,y,w,h = self:zoomedRectCoordTransform( link.x0,link.y0, link.x1,link.y1 ) + fb.bb:invertRect(x,y+h-3, w,1) + fb:refresh(1, x,y+h-3, w,1) + end + if self.rcount >= self.rcountmax then Debug("full refresh") self.rcount = 0 From a3f5de9e7acee78c6ca1c50a8ba4e40a006fef0c Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Mon, 24 Sep 2012 23:57:42 +0200 Subject: [PATCH 08/20] fix size of fonts according to globalzoom And a few of one pixel up, one pixel down adjustemts, so that all underlines get dimmed. --- unireader.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/unireader.lua b/unireader.lua index 486e973cc..c1f361b79 100644 --- a/unireader.lua +++ b/unireader.lua @@ -1393,8 +1393,8 @@ function UniReader:show(no) local links = self:getPageLinks( no ) for i, link in ipairs(links) do local x,y,w,h = self:zoomedRectCoordTransform( link.x0,link.y0, link.x1,link.y1 ) - fb.bb:invertRect(x,y+h-3, w,1) - fb:refresh(1, x,y+h-3, w,1) + fb.bb:invertRect(x,y+h-2, w,1) + fb:refresh(1, x,y+h-2, w,1) end if self.rcount >= self.rcountmax then @@ -2875,7 +2875,7 @@ function UniReader:addAllCommands() if next(links) == nil then showInfoMsgWithDelay("No links on this page", 2000, 1) else - local font_size = math.ceil( (links[1].y1 - links[1].y0) * 1.6 ) + local font_size = math.ceil( (links[1].y1 - links[1].y0 - 2) * unireader.globalzoom ) Debug("font_size",font_size) Debug("shortcuts",SelectMenu.item_shortcuts) local face = Font:getFace("rifont", font_size) @@ -2888,7 +2888,7 @@ function UniReader:addAllCommands() fb.bb:dimRect(x,y,w,h) -- black 50% fb.bb:dimRect(x,y,w,h) -- black 25% - renderUtf8Text(fb.bb, x + w - font_size, y + font_size, face, SelectMenu.item_shortcuts[i]) + renderUtf8Text(fb.bb, x, y + font_size - 1, face, SelectMenu.item_shortcuts[i]) fb:refresh(1, x,y, w,h) end From 8a7f2bd562eca9624db097d91fd5d2ed74132c65 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Tue, 25 Sep 2012 00:03:32 +0200 Subject: [PATCH 09/20] go only to page links --- unireader.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unireader.lua b/unireader.lua index c1f361b79..74fec8e55 100644 --- a/unireader.lua +++ b/unireader.lua @@ -2921,7 +2921,7 @@ function UniReader:addAllCommands() end end - if link then + if link and links[link] ~= nil and links[link].page ~= nil then goto_page = links[ link ].page + 1 end From ac14ac4a2136314bb4cac4606a8044c41cf7a0b5 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Tue, 25 Sep 2012 00:04:11 +0200 Subject: [PATCH 10/20] show only page links --- unireader.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/unireader.lua b/unireader.lua index 74fec8e55..ea2d06116 100644 --- a/unireader.lua +++ b/unireader.lua @@ -1393,8 +1393,10 @@ function UniReader:show(no) local links = self:getPageLinks( no ) for i, link in ipairs(links) do local x,y,w,h = self:zoomedRectCoordTransform( link.x0,link.y0, link.x1,link.y1 ) - fb.bb:invertRect(x,y+h-2, w,1) - fb:refresh(1, x,y+h-2, w,1) + if link.page then -- skip non-page links + fb.bb:invertRect(x,y+h-2, w,1) + fb:refresh(1, x,y+h-2, w,1) + end end if self.rcount >= self.rcountmax then From cc222c65253989bdc6b30ac8c1761e219dca10a7 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Tue, 25 Sep 2012 15:00:58 +0200 Subject: [PATCH 11/20] fix DOT and SYM bindings, added ENTER --- unireader.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/unireader.lua b/unireader.lua index ea2d06116..977bb7c1e 100644 --- a/unireader.lua +++ b/unireader.lua @@ -2915,8 +2915,10 @@ function UniReader:addAllCommands() elseif ev.code >= KEY_Z and ev.code <= KEY_M then link = ev.code - KEY_Z + 21 elseif ev.code == KEY_DOT then - link = 29 + link = 28 elseif ev.code == KEY_SYM then + link = 29 + elseif ev.code == KEY_ENTER then link = 30 elseif ev.code == KEY_BACK then goto_page = unireader.pageno From 01b1f5ba6608c59b9907d1c271d00ce35a143be2 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Tue, 25 Sep 2012 15:36:13 +0200 Subject: [PATCH 12/20] move 30 link shortcuts around using fireway --- unireader.lua | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/unireader.lua b/unireader.lua index 977bb7c1e..a395e0efa 100644 --- a/unireader.lua +++ b/unireader.lua @@ -2883,18 +2883,31 @@ function UniReader:addAllCommands() local face = Font:getFace("rifont", font_size) for i, link in ipairs(links) do - Debug("link", i, link) local x,y,w,h = self:zoomedRectCoordTransform( link.x0,link.y0, link.x1,link.y1 ) - Debug("box",x,y,w,h) - fb.bb:dimRect(x,y,w,h) -- black 50% fb.bb:dimRect(x,y,w,h) -- black 25% - - renderUtf8Text(fb.bb, x, y + font_size - 1, face, SelectMenu.item_shortcuts[i]) - - fb:refresh(1, x,y, w,h) end + Screen:saveCurrentBB() -- save dimmed links + + local shortcut_offset = 0 + + local render_shortcuts = function() + Screen:restoreFromSavedBB() + + for i = 1, #SelectMenu.item_shortcuts, 1 do + local link = links[ i + shortcut_offset ] + if link == nil then break end + Debug("link", i, shortcut_offset, link) + local x,y,w,h = self:zoomedRectCoordTransform( link.x0,link.y0, link.x1,link.y1 ) + renderUtf8Text(fb.bb, x, y + font_size - 1, face, SelectMenu.item_shortcuts[i]) + end + + fb:refresh(1) + end + + render_shortcuts() + local goto_page = nil while not goto_page do @@ -2922,11 +2935,17 @@ function UniReader:addAllCommands() link = 30 elseif ev.code == KEY_BACK then goto_page = unireader.pageno + elseif ( ev.code == KEY_FW_RIGHT or ev.code == KEY_FW_DOWN ) and shortcut_offset <= #links - 30 then + shortcut_offset = shortcut_offset + 30 + render_shortcuts() + elseif ( ev.code == KEY_FW_LEFT or ev.code == KEY_FW_UP ) and shortcut_offset >= 30 then + shortcut_offset = shortcut_offset - 30 + render_shortcuts() end end if link and links[link] ~= nil and links[link].page ~= nil then - goto_page = links[ link ].page + 1 + goto_page = links[ link + shortcut_offset ].page + 1 end Debug("goto_page", goto_page, "now on", unireader.pageno, "link", link) From 16c5171432169e62a3efef286a78f5ab80332f7d Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Tue, 25 Sep 2012 15:39:13 +0200 Subject: [PATCH 13/20] removed refresh which will be called after anyway --- unireader.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/unireader.lua b/unireader.lua index a395e0efa..add6ccfe2 100644 --- a/unireader.lua +++ b/unireader.lua @@ -1395,7 +1395,6 @@ function UniReader:show(no) local x,y,w,h = self:zoomedRectCoordTransform( link.x0,link.y0, link.x1,link.y1 ) if link.page then -- skip non-page links fb.bb:invertRect(x,y+h-2, w,1) - fb:refresh(1, x,y+h-2, w,1) end end From fc22f5ed93c84061634e43008d698b5e2914eb85 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Tue, 25 Sep 2012 18:30:09 +0200 Subject: [PATCH 14/20] check if getPageLinks returned links before use --- unireader.lua | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/unireader.lua b/unireader.lua index add6ccfe2..1aeed82aa 100644 --- a/unireader.lua +++ b/unireader.lua @@ -1391,10 +1391,12 @@ function UniReader:show(no) -- draw links on page local links = self:getPageLinks( no ) - for i, link in ipairs(links) do - local x,y,w,h = self:zoomedRectCoordTransform( link.x0,link.y0, link.x1,link.y1 ) - if link.page then -- skip non-page links - fb.bb:invertRect(x,y+h-2, w,1) + if links ~= nil then + for i, link in ipairs(links) do + local x,y,w,h = self:zoomedRectCoordTransform( link.x0,link.y0, link.x1,link.y1 ) + if link.page then -- skip non-page links + fb.bb:invertRect(x,y+h-2, w,1) + end end end @@ -2873,7 +2875,7 @@ function UniReader:addAllCommands() "page links", function(unireader) local links = unireader:getPageLinks( unireader.pageno ) - if next(links) == nil then + if links == nil or next(links) == nil then showInfoMsgWithDelay("No links on this page", 2000, 1) else local font_size = math.ceil( (links[1].y1 - links[1].y0 - 2) * unireader.globalzoom ) From ee7b0ca41e46260f942051b91286d05b3edaef9f Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Tue, 25 Sep 2012 19:04:46 +0200 Subject: [PATCH 15/20] ignore all non-page links --- unireader.lua | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/unireader.lua b/unireader.lua index 1aeed82aa..e8a2d22cb 100644 --- a/unireader.lua +++ b/unireader.lua @@ -1393,8 +1393,8 @@ function UniReader:show(no) local links = self:getPageLinks( no ) if links ~= nil then for i, link in ipairs(links) do - local x,y,w,h = self:zoomedRectCoordTransform( link.x0,link.y0, link.x1,link.y1 ) if link.page then -- skip non-page links + local x,y,w,h = self:zoomedRectCoordTransform( link.x0,link.y0, link.x1,link.y1 ) fb.bb:invertRect(x,y+h-2, w,1) end end @@ -2884,9 +2884,11 @@ function UniReader:addAllCommands() local face = Font:getFace("rifont", font_size) for i, link in ipairs(links) do - local x,y,w,h = self:zoomedRectCoordTransform( link.x0,link.y0, link.x1,link.y1 ) - fb.bb:dimRect(x,y,w,h) -- black 50% - fb.bb:dimRect(x,y,w,h) -- black 25% + if link.page then + local x,y,w,h = self:zoomedRectCoordTransform( link.x0,link.y0, link.x1,link.y1 ) + fb.bb:dimRect(x,y,w,h) -- black 50% + fb.bb:dimRect(x,y,w,h) -- black 25% + end end Screen:saveCurrentBB() -- save dimmed links @@ -2900,8 +2902,10 @@ function UniReader:addAllCommands() local link = links[ i + shortcut_offset ] if link == nil then break end Debug("link", i, shortcut_offset, link) - local x,y,w,h = self:zoomedRectCoordTransform( link.x0,link.y0, link.x1,link.y1 ) - renderUtf8Text(fb.bb, x, y + font_size - 1, face, SelectMenu.item_shortcuts[i]) + if link.page then + local x,y,w,h = self:zoomedRectCoordTransform( link.x0,link.y0, link.x1,link.y1 ) + renderUtf8Text(fb.bb, x, y + font_size - 1, face, SelectMenu.item_shortcuts[i]) + end end fb:refresh(1) From 88828fd478d65a4bfbd54b02ff170ae2ff7e2c27 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Tue, 25 Sep 2012 19:28:16 +0200 Subject: [PATCH 16/20] check if there is at least one page link before drawing shortcuts --- unireader.lua | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/unireader.lua b/unireader.lua index e8a2d22cb..4e85f2950 100644 --- a/unireader.lua +++ b/unireader.lua @@ -2883,14 +2883,22 @@ function UniReader:addAllCommands() Debug("shortcuts",SelectMenu.item_shortcuts) local face = Font:getFace("rifont", font_size) + local page_links = 0 + for i, link in ipairs(links) do if link.page then local x,y,w,h = self:zoomedRectCoordTransform( link.x0,link.y0, link.x1,link.y1 ) fb.bb:dimRect(x,y,w,h) -- black 50% fb.bb:dimRect(x,y,w,h) -- black 25% + page_links = page_links + 1 end end + if page_links == 0 then + showInfoMsgWithDelay("No links on this page", 2000, 1) + return + end + Screen:saveCurrentBB() -- save dimmed links local shortcut_offset = 0 From d936f86f04c30ea496fb83099a805ec58d10a3db Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Tue, 25 Sep 2012 21:16:03 +0200 Subject: [PATCH 17/20] fix shortcuts beyond last one --- unireader.lua | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/unireader.lua b/unireader.lua index 4e85f2950..19109edca 100644 --- a/unireader.lua +++ b/unireader.lua @@ -2957,8 +2957,13 @@ function UniReader:addAllCommands() end end - if link and links[link] ~= nil and links[link].page ~= nil then - goto_page = links[ link + shortcut_offset ].page + 1 + if link then + link = link + shortcut_offset + if links[link] ~= nil and links[link].page ~= nil then + goto_page = links[link].page + 1 + else + Debug("missing link", link) + end end Debug("goto_page", goto_page, "now on", unireader.pageno, "link", link) From 771901d56e370a5f7f1283f7ddc91149b8ee5c44 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Wed, 26 Sep 2012 10:48:07 +0200 Subject: [PATCH 18/20] use all shortcuts, skipping uri links --- unireader.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/unireader.lua b/unireader.lua index 19109edca..b95832884 100644 --- a/unireader.lua +++ b/unireader.lua @@ -2906,13 +2906,16 @@ function UniReader:addAllCommands() local render_shortcuts = function() Screen:restoreFromSavedBB() + local shortcut_nr = 1 + for i = 1, #SelectMenu.item_shortcuts, 1 do local link = links[ i + shortcut_offset ] if link == nil then break end Debug("link", i, shortcut_offset, link) if link.page then local x,y,w,h = self:zoomedRectCoordTransform( link.x0,link.y0, link.x1,link.y1 ) - renderUtf8Text(fb.bb, x, y + font_size - 1, face, SelectMenu.item_shortcuts[i]) + renderUtf8Text(fb.bb, x, y + font_size - 1, face, SelectMenu.item_shortcuts[shortcut_nr]) + shortcut_nr = shortcut_nr + 1 end end From 51e2a0c13b20f34ab00670c4d0c8762384d51816 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Wed, 26 Sep 2012 10:55:03 +0200 Subject: [PATCH 19/20] use shortcut_map to track page links --- unireader.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/unireader.lua b/unireader.lua index b95832884..fefef4780 100644 --- a/unireader.lua +++ b/unireader.lua @@ -2902,11 +2902,13 @@ function UniReader:addAllCommands() Screen:saveCurrentBB() -- save dimmed links local shortcut_offset = 0 + local shortcut_map local render_shortcuts = function() Screen:restoreFromSavedBB() local shortcut_nr = 1 + shortcut_map = {} for i = 1, #SelectMenu.item_shortcuts, 1 do local link = links[ i + shortcut_offset ] @@ -2915,10 +2917,13 @@ function UniReader:addAllCommands() if link.page then local x,y,w,h = self:zoomedRectCoordTransform( link.x0,link.y0, link.x1,link.y1 ) renderUtf8Text(fb.bb, x, y + font_size - 1, face, SelectMenu.item_shortcuts[shortcut_nr]) + shortcut_map[shortcut_nr] = i shortcut_nr = shortcut_nr + 1 end end + Debug("shortcut_map", shortcut_map) + fb:refresh(1) end @@ -2961,7 +2966,7 @@ function UniReader:addAllCommands() end if link then - link = link + shortcut_offset + link = shortcut_map[ link + shortcut_offset ] if links[link] ~= nil and links[link].page ~= nil then goto_page = links[link].page + 1 else From 929334c00c25fbe500d8aba0f98d33edb3a5c843 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Wed, 26 Sep 2012 11:42:15 +0200 Subject: [PATCH 20/20] shortcut_offset should be added directly to shortcut_map --- unireader.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/unireader.lua b/unireader.lua index fefef4780..c73381faa 100644 --- a/unireader.lua +++ b/unireader.lua @@ -2917,7 +2917,7 @@ function UniReader:addAllCommands() if link.page then local x,y,w,h = self:zoomedRectCoordTransform( link.x0,link.y0, link.x1,link.y1 ) renderUtf8Text(fb.bb, x, y + font_size - 1, face, SelectMenu.item_shortcuts[shortcut_nr]) - shortcut_map[shortcut_nr] = i + shortcut_map[shortcut_nr] = i + shortcut_offset shortcut_nr = shortcut_nr + 1 end end @@ -2966,7 +2966,7 @@ function UniReader:addAllCommands() end if link then - link = shortcut_map[ link + shortcut_offset ] + link = shortcut_map[link] if links[link] ~= nil and links[link].page ~= nil then goto_page = links[link].page + 1 else