mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Merge pull request #577 from chrox/master
fix page to screen rect transform for highlighting
This commit is contained in:
@@ -61,10 +61,12 @@ function ReaderLink:onTap(arg, ges)
|
||||
if self.ui.document.info.has_pages then
|
||||
local pos = self.view:screenToPageTransform(ges.pos)
|
||||
if pos then
|
||||
-- link box in native page
|
||||
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)
|
||||
local sbox = self.view:pageToScreenTransform(pos.page,
|
||||
self.ui.document:nativeToPageRectTransform(pos.page, lbox))
|
||||
if sbox then
|
||||
UIManager:show(LinkBox:new{
|
||||
box = sbox,
|
||||
|
||||
@@ -167,7 +167,6 @@ 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
|
||||
|
||||
@@ -127,7 +127,6 @@ function CreDocument:loadDocument()
|
||||
end
|
||||
|
||||
function CreDocument:close()
|
||||
self._document:saveDefaults()
|
||||
Document.close(self)
|
||||
end
|
||||
|
||||
@@ -272,7 +271,7 @@ end
|
||||
function CreDocument:setFontFace(new_font_face)
|
||||
if new_font_face then
|
||||
DEBUG("CreDocument: set font face", new_font_face)
|
||||
self._document:setFontFace(new_font_face)
|
||||
self._document:setStringProperty("font.face.default", new_font_face)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -335,13 +334,17 @@ function CreDocument:setStyleSheet(new_css)
|
||||
end
|
||||
|
||||
function CreDocument:setEmbeddedStyleSheet(toggle)
|
||||
-- FIXME: occasional segmentation fault when switching embedded style sheet
|
||||
DEBUG("CreDocument: set embedded style sheet", toggle)
|
||||
self._document:setEmbeddedStyleSheet(toggle)
|
||||
self._document:setIntProperty("crengine.doc.embedded.styles.enabled", toggle)
|
||||
end
|
||||
|
||||
function CreDocument:setPageMargins(left, top, right, bottom)
|
||||
DEBUG("CreDocument: set page margins", left, top, right, bottom)
|
||||
self._document:setPageMargins(left, top, right, bottom)
|
||||
self._document:setIntProperty("crengine.page.margin.left", left)
|
||||
self._document:setIntProperty("crengine.page.margin.top", top)
|
||||
self._document:setIntProperty("crengine.page.margin.right", right)
|
||||
self._document:setIntProperty("crengine.page.margin.bottom", bottom)
|
||||
end
|
||||
|
||||
function CreDocument:setFloatingPunctuation(enabled)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
local InputContainer = require("ui/widget/container/inputcontainer")
|
||||
local LoginDialog = require("ui/widget/logindialog")
|
||||
local InfoMessage = require("ui/widget/infomessage")
|
||||
local DocSettings = require("docsettings")
|
||||
local UIManager = require("ui/uimanager")
|
||||
local Screen = require("ui/screen")
|
||||
local Event = require("ui/event")
|
||||
@@ -33,6 +34,7 @@ function EvernoteExporter:init()
|
||||
history_dir = "./history",
|
||||
}
|
||||
self.template = slt2.loadfile(self.path.."/note.tpl")
|
||||
self.config = DocSettings:open(self.path)
|
||||
end
|
||||
|
||||
function EvernoteExporter:addToMainMenu(tab_item_table)
|
||||
@@ -230,6 +232,24 @@ function EvernoteExporter:exportCurrentNotes(view)
|
||||
self:exportClippings(client, clippings)
|
||||
end
|
||||
|
||||
function EvernoteExporter:updateClippings(clippings, new_clippings)
|
||||
for title, booknotes in pairs(new_clippings) do
|
||||
for chapter_index, chapternotes in ipairs(booknotes) do
|
||||
for note_index, note in ipairs(chapternotes) do
|
||||
if clippings[title] == nil or clippings[title][chapter_index] == nil
|
||||
or clippings[title][chapter_index][note_index] == nil
|
||||
or clippings[title][chapter_index][note_index].page ~= note.page
|
||||
or clippings[title][chapter_index][note_index].time ~= note.time
|
||||
or clippings[title][chapter_index][note_index].text ~= note.text
|
||||
or clippings[title][chapter_index][note_index].note ~= note.note then
|
||||
clippings[title] = booknotes
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return clippings
|
||||
end
|
||||
|
||||
function EvernoteExporter:exportAllNotes()
|
||||
local EvernoteClient = require("EvernoteClient")
|
||||
local client = EvernoteClient:new{
|
||||
@@ -237,10 +257,9 @@ function EvernoteExporter:exportAllNotes()
|
||||
authToken = self.evernote_token,
|
||||
}
|
||||
|
||||
local clippings = self.parser:parseMyClippings()
|
||||
if next(clippings) == nil then
|
||||
clippings = self.parser:parseHistory()
|
||||
end
|
||||
local clippings = self.config:readSetting("clippings") or {}
|
||||
clippings = self:updateClippings(clippings, self.parser:parseMyClippings())
|
||||
clippings = self:updateClippings(clippings, self.parser:parseHistory())
|
||||
-- remove blank entries
|
||||
for title, booknotes in pairs(clippings) do
|
||||
-- chapter number is zero
|
||||
@@ -250,45 +269,52 @@ function EvernoteExporter:exportAllNotes()
|
||||
end
|
||||
--DEBUG("clippings", clippings)
|
||||
self:exportClippings(client, clippings)
|
||||
self.config:saveSetting("clippings", clippings)
|
||||
self.config:flush()
|
||||
end
|
||||
|
||||
function EvernoteExporter:exportClippings(client, clippings)
|
||||
local export_count, error_count = 0, 0
|
||||
local export_title, error_title
|
||||
for title, booknotes in pairs(clippings) do
|
||||
local ok, err = pcall(self.exportBooknotes, self, client, title, booknotes)
|
||||
|
||||
-- error reporting
|
||||
if not ok then
|
||||
DEBUG("Error occurs when exporting book:", title, err)
|
||||
error_count = error_count + 1
|
||||
error_title = title
|
||||
-- skip exported booknotes
|
||||
if booknotes.exported ~= true then
|
||||
local ok, err = pcall(self.exportBooknotes, self,
|
||||
client, title, booknotes)
|
||||
-- error reporting
|
||||
if not ok then
|
||||
DEBUG("Error occurs when exporting book:", title, err)
|
||||
error_count = error_count + 1
|
||||
error_title = title
|
||||
else
|
||||
DEBUG("Exported notes in book:", title)
|
||||
export_count = export_count + 1
|
||||
export_title = title
|
||||
booknotes.exported = true
|
||||
end
|
||||
else
|
||||
DEBUG("Exported notes in book:", title)
|
||||
export_count = export_count + 1
|
||||
export_title = title
|
||||
DEBUG("Skip exporting notes in book:", title)
|
||||
end
|
||||
end
|
||||
|
||||
local msg = ""
|
||||
local msg = "Not exported anything."
|
||||
local all_count = export_count + error_count
|
||||
if export_count > 0 and error_count == 0 then
|
||||
if all_count == 1 then
|
||||
msg = _("Exported notes in book:") .. "\n" .. export_title
|
||||
else
|
||||
msg = _("Exported notes in book:") .. "\n" .. export_title
|
||||
msg = msg .. "\n" .. _("and ") .. all_count-1 .. _("others.")
|
||||
msg = msg .. "\n" .. _("and ") .. all_count-1 .. _(" others.")
|
||||
end
|
||||
elseif error_count > 0 then
|
||||
if all_count == 1 then
|
||||
msg = _("Error occurs when exporting book:") .. "\n" .. error_title
|
||||
else
|
||||
msg = _("Errors occur when exporting book:") .. "\n" .. error_title
|
||||
msg = msg .. "\n" .. _("and ") .. error_count-1 .. ("others.")
|
||||
msg = msg .. "\n" .. _("and ") .. error_count-1 .. (" others.")
|
||||
end
|
||||
end
|
||||
UIManager:show(InfoMessage:new{ text = msg })
|
||||
|
||||
end
|
||||
|
||||
function EvernoteExporter:exportBooknotes(client, title, booknotes)
|
||||
|
||||
Reference in New Issue
Block a user