mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Merge pull request #463 from chrox/master
page links for crereader and pdfreader
This commit is contained in:
@@ -7,24 +7,24 @@
|
||||
{
|
||||
"name": "Start the filemanager",
|
||||
"priority": 1,
|
||||
"action": "/mnt/us/koreader/koreader.sh",
|
||||
"action": "nice -n -7 /mnt/us/koreader/koreader.sh",
|
||||
"params": "/mnt/us/documents"
|
||||
},
|
||||
{
|
||||
"name": "Open the last document",
|
||||
"priority": 2,
|
||||
"action": "/mnt/us/koreader/koreader.sh"
|
||||
"action": "nice -n -7 /mnt/us/koreader/koreader.sh"
|
||||
},
|
||||
{
|
||||
"name": "Start the filemanager (no framework)",
|
||||
"priority": 3,
|
||||
"action": "/mnt/us/koreader/koreader.sh",
|
||||
"action": "nice -n -7 /mnt/us/koreader/koreader.sh",
|
||||
"params": "--framework_stop /mnt/us/documents"
|
||||
},
|
||||
{
|
||||
"name": "Open the last document (no framework)",
|
||||
"priority": 4,
|
||||
"action": "/mnt/us/koreader/koreader.sh",
|
||||
"action": "nice -n -7 /mnt/us/koreader/koreader.sh",
|
||||
"params": "--framework_stop"
|
||||
}
|
||||
]
|
||||
|
||||
@@ -348,6 +348,11 @@ function CreDocument:setBatteryState(state)
|
||||
self._document:setBatteryState(state)
|
||||
end
|
||||
|
||||
function CreDocument:isXPointerInCurrentPage(xp)
|
||||
DEBUG("CreDocument: check in page", xp)
|
||||
return self._document:isXPointerInCurrentPage(xp)
|
||||
end
|
||||
|
||||
function CreDocument:register(registry)
|
||||
registry:addProvider("txt", "application/txt", self)
|
||||
registry:addProvider("epub", "application/epub", self)
|
||||
|
||||
@@ -36,6 +36,8 @@ local Document = {
|
||||
author = "",
|
||||
date = ""
|
||||
},
|
||||
|
||||
links = {},
|
||||
|
||||
GAMMA_NO_GAMMA = 1.0,
|
||||
|
||||
@@ -171,6 +173,10 @@ function Document:getToc()
|
||||
return self._document:getToc()
|
||||
end
|
||||
|
||||
function Document:getPageLinks(pageno)
|
||||
return nil
|
||||
end
|
||||
|
||||
function Document:getTextBoxes(pageno)
|
||||
return nil
|
||||
end
|
||||
|
||||
@@ -97,6 +97,21 @@ function PdfDocument:getUsedBBox(pageno)
|
||||
return used
|
||||
end
|
||||
|
||||
function PdfDocument:getPageLinks(pageno)
|
||||
local hash = "pglinks|"..self.file.."|"..pageno
|
||||
local cached = Cache:check(hash)
|
||||
if cached then
|
||||
return cached.links
|
||||
end
|
||||
local page = self._document:openPage(pageno)
|
||||
local links = page:getPageLinks()
|
||||
Cache:insert(hash, CacheItem:new{
|
||||
links = links,
|
||||
})
|
||||
page:close()
|
||||
return links
|
||||
end
|
||||
|
||||
function PdfDocument:getPageBBox(pageno)
|
||||
return self.koptinterface:getPageBBox(self, pageno)
|
||||
end
|
||||
|
||||
@@ -7,6 +7,7 @@ local Geom = require("ui/geometry")
|
||||
local Screen = require("ui/screen")
|
||||
local UIManager = require("ui/uimanager")
|
||||
local Event = require("ui/event")
|
||||
local DEBUG = require("dbg")
|
||||
local _ = require("gettext")
|
||||
|
||||
local ReaderBookmark = InputContainer:new{
|
||||
@@ -35,10 +36,10 @@ end
|
||||
|
||||
function ReaderBookmark:onToggleBookmark()
|
||||
local pn_or_xp = nil
|
||||
if self.ui.document.getXPointer then
|
||||
pn_or_xp = self.ui.document:getXPointer()
|
||||
else
|
||||
if self.ui.document.info.has_pages then
|
||||
pn_or_xp = self.view.state.page
|
||||
else
|
||||
pn_or_xp = self.ui.document:getXPointer()
|
||||
end
|
||||
self:toggleBookmark(pn_or_xp)
|
||||
self.view.dogear_visible = not self.view.dogear_visible
|
||||
@@ -55,14 +56,20 @@ function ReaderBookmark:setDogearVisibility(pn_or_xp)
|
||||
end
|
||||
|
||||
function ReaderBookmark:onPageUpdate(pageno)
|
||||
self:setDogearVisibility(pageno)
|
||||
if self.ui.document.info.has_pages then
|
||||
self:setDogearVisibility(pageno)
|
||||
else
|
||||
-- FIXME: this is a dirty hack to prevent crash in isXPointerInCurrentPage
|
||||
if pageno ~= 1 then
|
||||
self:setDogearVisibility("dummy")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function ReaderBookmark:onPosUpdate(pos)
|
||||
-- TODO: cannot check if this pos is bookmarked or not.
|
||||
self:setDogearVisibility("dummy")
|
||||
end
|
||||
|
||||
|
||||
function ReaderBookmark:onShowBookmark()
|
||||
-- build up item_table
|
||||
for k, v in ipairs(self.bookmarks) do
|
||||
@@ -124,7 +131,8 @@ end
|
||||
|
||||
function ReaderBookmark:isBookmarked(pn_or_xp)
|
||||
for k,v in ipairs(self.bookmarks) do
|
||||
if v.page == pn_or_xp then
|
||||
if (type(pn_or_xp) == "number" and v.page == pn_or_xp) or
|
||||
(type(pn_or_xp) == "string" and self.ui.document:isXPointerInCurrentPage(v.page)) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
@@ -155,7 +163,8 @@ end
|
||||
|
||||
function ReaderBookmark:toggleBookmark(pn_or_xp)
|
||||
for k,v in ipairs(self.bookmarks) do
|
||||
if v.page == pn_or_xp then
|
||||
if (type(pn_or_xp) == "number" and v.page == pn_or_xp) or
|
||||
(type(pn_or_xp) == "string" and self.ui.document:isXPointerInCurrentPage(v.page)) then
|
||||
table.remove(self.bookmarks, k)
|
||||
return
|
||||
end
|
||||
|
||||
@@ -53,7 +53,7 @@ function ReaderDictionary:showDict(results, box)
|
||||
dialog = self.dialog,
|
||||
results = results,
|
||||
dictionary = self.default_dictionary,
|
||||
width = Screen:getWidth() - Screen:scaleByDPI(120),
|
||||
width = Screen:getWidth() - Screen:scaleByDPI(80),
|
||||
height = math.min(region.h*0.7, Screen:getHeight()*0.5),
|
||||
region = region,
|
||||
align = align,
|
||||
|
||||
@@ -2,6 +2,7 @@ local InputContainer = require("ui/widget/container/inputcontainer")
|
||||
local RightContainer = require("ui/widget/container/rightcontainer")
|
||||
local ImageWidget = require("ui/widget/imagewidget")
|
||||
local GestureRange = require("ui/gesturerange")
|
||||
local UIManager = require("ui/uimanager")
|
||||
local Device = require("ui/device")
|
||||
local Geom = require("ui/geometry")
|
||||
local Screen = require("ui/screen")
|
||||
@@ -57,6 +58,7 @@ end
|
||||
|
||||
function ReaderDogear:onSetDogearVisibility(visible)
|
||||
self.view.dogear_visible = visible
|
||||
UIManager:setDirty(self.view.dialog, "partial")
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
@@ -6,7 +6,9 @@ local Device = require("ui/device")
|
||||
local Event = require("ui/event")
|
||||
local DEBUG = require("dbg")
|
||||
|
||||
local ReaderLink = InputContainer:new{}
|
||||
local ReaderLink = InputContainer:new{
|
||||
link_states = {}
|
||||
}
|
||||
|
||||
function ReaderLink:init()
|
||||
if Device:isTouchDevice() then
|
||||
@@ -27,6 +29,16 @@ function ReaderLink:initGesListener()
|
||||
}
|
||||
}
|
||||
},
|
||||
Swipe = {
|
||||
GestureRange:new{
|
||||
ges = "swipe",
|
||||
range = Geom:new{
|
||||
x = 0, y = 0,
|
||||
w = Screen:getWidth(),
|
||||
h = Screen:getHeight(),
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
end
|
||||
end
|
||||
@@ -49,22 +61,71 @@ function ReaderLink:onTap(arg, ges)
|
||||
end
|
||||
end
|
||||
end
|
||||
if self.view.links then
|
||||
local pos = self.view:screenToPageTransform(ges.pos)
|
||||
for i = 1, #self.view.links do
|
||||
local link = self.view.links[i]
|
||||
-- enlarge tappable link box
|
||||
local lbox = Geom:new{
|
||||
x = link.start_x - Screen:scaleByDPI(15),
|
||||
y = link.start_y - Screen:scaleByDPI(15),
|
||||
w = link.end_x - link.start_x + Screen:scaleByDPI(30),
|
||||
h = link.end_y - link.start_y > 0
|
||||
and link.end_y - link.start_y + Screen:scaleByDPI(30)
|
||||
or Screen:scaleByDPI(50),
|
||||
}
|
||||
if inside_box(pos, lbox) then
|
||||
DEBUG("goto link", link)
|
||||
self.document:gotoLink(link.section)
|
||||
local pos = self.view:screenToPageTransform(ges.pos)
|
||||
if self.ui.document.info.has_pages then
|
||||
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
|
||||
end
|
||||
else
|
||||
if self.view.links then
|
||||
for i = 1, #self.view.links do
|
||||
local link = self.view.links[i]
|
||||
-- enlarge tappable link box
|
||||
local lbox = Geom:new{
|
||||
x = link.start_x - Screen:scaleByDPI(15),
|
||||
y = link.start_y - Screen:scaleByDPI(15),
|
||||
w = link.end_x - link.start_x + Screen:scaleByDPI(30),
|
||||
h = link.end_y - link.start_y > 0
|
||||
and link.end_y - link.start_y + Screen:scaleByDPI(30)
|
||||
or Screen:scaleByDPI(50),
|
||||
}
|
||||
if inside_box(pos, lbox) then
|
||||
return self:onGotoLink(link)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function ReaderLink:onGotoLink(link)
|
||||
DEBUG("goto link", link)
|
||||
if self.ui.document.info.has_pages then
|
||||
table.insert(self.link_states, self.view.state.page)
|
||||
self.ui:handleEvent(Event:new("PageUpdate", link.page + 1))
|
||||
else
|
||||
table.insert(self.link_states, self.ui.document:getXPointer())
|
||||
self.document:gotoLink(link.section)
|
||||
self.ui:handleEvent(Event:new("UpdateXPointer"))
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
function ReaderLink:onSwipe(arg, ges)
|
||||
if ges.direction == "east" then
|
||||
if self.ui.document.info.has_pages then
|
||||
local last_page = table.remove(self.link_states)
|
||||
if last_page then
|
||||
self.ui:handleEvent(Event:new("PageUpdate", last_page))
|
||||
return true
|
||||
end
|
||||
else
|
||||
local last_xp = table.remove(self.link_states)
|
||||
if last_xp then
|
||||
self.ui.document:gotoXPointer(last_xp)
|
||||
self.ui:handleEvent(Event:new("UpdateXPointer"))
|
||||
return true
|
||||
end
|
||||
|
||||
@@ -183,16 +183,10 @@ function ReaderRolling:onTapBackward()
|
||||
end
|
||||
|
||||
function ReaderRolling:onSwipe(arg, ges)
|
||||
if ges.direction == "north" then
|
||||
if ges.direction == "west" or ges.direction == "north" then
|
||||
self:onGotoViewRel(1)
|
||||
elseif ges.direction == "south" then
|
||||
elseif ges.direction == "east" or ges.direction == "south" then
|
||||
self:onGotoViewRel(-1)
|
||||
elseif ges.direction == "west" then
|
||||
self.ui.document:goForward()
|
||||
self:onUpdateXPointer()
|
||||
elseif ges.direction == "east" then
|
||||
self.ui.document:goBack()
|
||||
self:onUpdateXPointer()
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
Submodule koreader-base updated: ff06119483...aa1328ca5d
Reference in New Issue
Block a user