Merge pull request #579 from chrox/master

export highlighted rect in scanned page to Evernote
pull/581/head v2014.05.16-nightly
Qingping Hou 10 years ago
commit 295d0406a2

@ -0,0 +1,6 @@
return {
default = {
verbose = true,
ROOT = "spec/front/unit",
},
}

1
.gitignore vendored

@ -11,6 +11,7 @@ git-rev
tags tags
test/* test/*
*.tar *.tar
spec/unit/data
emu emu

@ -38,6 +38,11 @@ endif
for f in $(INSTALL_FILES); do \ for f in $(INSTALL_FILES); do \
ln -sf ../../$$f $(INSTALL_DIR)/koreader/; \ ln -sf ../../$$f $(INSTALL_DIR)/koreader/; \
done done
# install front spec
cd $(INSTALL_DIR)/koreader/spec && test -e front || \
ln -sf ../../../../spec ./front
cd $(INSTALL_DIR)/koreader/spec/front/unit && test -e data || \
ln -sf ../../test ./data
# install plugins # install plugins
cp -r plugins/* $(INSTALL_DIR)/koreader/plugins/ cp -r plugins/* $(INSTALL_DIR)/koreader/plugins/
cp -rpL resources/fonts/* $(INSTALL_DIR)/koreader/fonts/ cp -rpL resources/fonts/* $(INSTALL_DIR)/koreader/fonts/
@ -54,8 +59,16 @@ endif
$(KOR_BASE)/$(OUTPUT_DIR)/luajit: $(KOR_BASE)/$(OUTPUT_DIR)/luajit:
$(MAKE) -C $(KOR_BASE) $(MAKE) -C $(KOR_BASE)
$(INSTALL_DIR)/koreader/.busted:
test -e $(INSTALL_DIR)/koreader/.busted || \
ln -sf ../../.busted $(INSTALL_DIR)/koreader
testfront: $(INSTALL_DIR)/koreader/.busted
cd $(INSTALL_DIR)/koreader && busted -l ./luajit
test: test:
$(MAKE) -C $(KOR_BASE) test $(MAKE) -C $(KOR_BASE) test
$(MAKE) testfront
.PHONY: test .PHONY: test

@ -132,10 +132,10 @@ function MD5Transform(buf, input)
c = MD5STEP(F4, c, d, a, b, input[2] + 0x2ad7d2bb, 15); c = MD5STEP(F4, c, d, a, b, input[2] + 0x2ad7d2bb, 15);
b = MD5STEP(F4, b, c, d, a, input[9] + 0xeb86d391, 21); b = MD5STEP(F4, b, c, d, a, input[9] + 0xeb86d391, 21);
buf[0] = (buf[0] + a)%0xffffffff; buf[0] = band(buf[0] + a, 0xFFFFFFFF);
buf[1] = (buf[1] + b)%0xffffffff; buf[1] = band(buf[1] + b, 0xFFFFFFFF);
buf[2] = (buf[2] + c)%0xffffffff; buf[2] = band(buf[2] + c, 0xFFFFFFFF);
buf[3] = (buf[3] + d)%0xffffffff; buf[3] = band(buf[3] + d, 0xFFFFFFFF);
end end
function MD5Update(ctx, buf, len) function MD5Update(ctx, buf, len)

@ -354,7 +354,10 @@ function ReaderHighlight:saveHighlight()
hl_item["drawer"] = self.view.highlight.saved_drawer hl_item["drawer"] = self.view.highlight.saved_drawer
table.insert(self.view.highlight.saved[page], hl_item) table.insert(self.view.highlight.saved[page], hl_item)
if self.selected_text.text ~= "" then if self.selected_text.text ~= "" then
self:exportToClippings(page, hl_item) -- disable exporting hightlights to My Clippings
-- since it's not potable and there is a better Evernote plugin
-- to do the same thing
--self:exportToClippings(page, hl_item)
end end
if self.selected_text.pboxes then if self.selected_text.pboxes then
self:exportToDocument(page, hl_item) self:exportToDocument(page, hl_item)
@ -372,7 +375,8 @@ function ReaderHighlight:exportToClippings(page, item)
clippings:write(self.document.file:gsub("(.*/)(.*)", "%2").."\n") clippings:write(self.document.file:gsub("(.*/)(.*)", "%2").."\n")
clippings:write("- Koreader Highlight Page "..page.." ") clippings:write("- Koreader Highlight Page "..page.." ")
clippings:write("| Added on "..os.date("%A, %b %d, %Y %I:%M:%S %p\n\n")) clippings:write("| Added on "..os.date("%A, %b %d, %Y %I:%M:%S %p\n\n"))
clippings:write(item["text"].."\n") -- My Clippings only holds one line of highlight
clippings:write(item["text"]:gsub("\n", " ").."\n")
clippings:write("==========\n") clippings:write("==========\n")
clippings:close() clippings:close()
os.setlocale(current_locale) os.setlocale(current_locale)

@ -1,4 +1,5 @@
local InputContainer = require("ui/widget/container/inputcontainer") local InputContainer = require("ui/widget/container/inputcontainer")
local Cache = require("cache")
local Geom = require("ui/geometry") local Geom = require("ui/geometry")
local Device = require("ui/device") local Device = require("ui/device")
local DocSettings = require("docsettings") local DocSettings = require("docsettings")
@ -301,6 +302,8 @@ function ReaderUI:onClose()
self.start_pos = nil self.start_pos = nil
end end
UIManager:close(self.dialog) UIManager:close(self.dialog)
-- serialize last used items for later launch
Cache:serialize()
return true return true
end end

@ -96,6 +96,14 @@ function DjvuDocument:getUsedBBox(pageno)
return used return used
end end
function DjvuDocument:clipPagePNGFile(pos0, pos1, pboxes, drawer, filename)
return self.koptinterface:clipPagePNGFile(self, pos0, pos1, pboxes, drawer, filename)
end
function DjvuDocument:clipPagePNGString(pos0, pos1, pboxes, drawer)
return self.koptinterface:clipPagePNGString(self, pos0, pos1, pboxes, drawer)
end
function DjvuDocument:getPageBBox(pageno) function DjvuDocument:getPageBBox(pageno)
return self.koptinterface:getPageBBox(self, pageno) return self.koptinterface:getPageBBox(self, pageno)
end end

@ -78,7 +78,6 @@ function Document:close()
self.is_open = false self.is_open = false
self._document:close() self._document:close()
end end
Cache:serialize()
end end
-- this might be overridden by a document implementation -- this might be overridden by a document implementation

@ -630,6 +630,54 @@ function KoptInterface:getOCRText(doc, pageno, tboxes)
DEBUG("Not implemented yet") DEBUG("Not implemented yet")
end end
function KoptInterface:getClipPageContext(doc, pos0, pos1, pboxes, drawer)
assert(pos0.page == pos1.page)
assert(pos0.zoom == pos1.zoom)
local rect = nil
if pboxes and #pboxes > 0 then
local box = pboxes[1]
rect = Geom:new{
x = box.x, y = box.y,
w = box.w, h = box.h,
}
for _, box in ipairs(pboxes) do
rect = rect:combine(Geom:new(box))
end
else
local zoom = pos0.zoom or 1
rect = {
x = math.min(pos0.x, pos1.x)/zoom,
y = math.min(pos0.y, pos1.y)/zoom,
w = math.abs(pos0.x - pos1.x)/zoom,
h = math.abs(pos0.y - pos1.y)/zoom
}
end
local bbox = {
x0 = rect.x, y0 = rect.y,
x1 = rect.x + rect.w,
y1 = rect.y + rect.h
}
local kc = self:createContext(doc, pos0.page, bbox)
local page = doc._document:openPage(pos0.page)
page:getPagePix(kc)
page:close()
return kc, rect
end
function KoptInterface:clipPagePNGFile(doc, pos0, pos1, pboxes, drawer, filename)
local kc = self:getClipPageContext(doc, pos0, pos1, pboxes, drawer)
kc:exportSrcPNGFile(pboxes, drawer, filename)
kc:free()
end
function KoptInterface:clipPagePNGString(doc, pos0, pos1, pboxes, drawer)
local kc = self:getClipPageContext(doc, pos0, pos1, pboxes, drawer)
local png = kc:exportSrcPNGString(pboxes, drawer)
kc:free()
return png
end
--[[ --[[
get index of nearest word box around pos get index of nearest word box around pos
--]] --]]

@ -193,6 +193,14 @@ function PdfDocument:getLinkFromPosition(pageno, pos)
return self.koptinterface:getLinkFromPosition(self, pageno, pos) return self.koptinterface:getLinkFromPosition(self, pageno, pos)
end end
function PdfDocument:clipPagePNGFile(pos0, pos1, pboxes, drawer, filename)
return self.koptinterface:clipPagePNGFile(self, pos0, pos1, pboxes, drawer, filename)
end
function PdfDocument:clipPagePNGString(pos0, pos1, pboxes, drawer)
return self.koptinterface:clipPagePNGString(self, pos0, pos1, pboxes, drawer)
end
function PdfDocument:getPageBBox(pageno) function PdfDocument:getPageBBox(pageno)
return self.koptinterface:getPageBBox(self, pageno) return self.koptinterface:getPageBBox(self, pageno)
end end

@ -2,7 +2,7 @@ local KindlePowerD = require("ui/device/kindlepowerd")
local KoboPowerD = require("ui/device/kobopowerd") local KoboPowerD = require("ui/device/kobopowerd")
local BasePowerD = require("ui/device/basepowerd") local BasePowerD = require("ui/device/basepowerd")
local Screen = require("ui/device/screen") local Screen = require("ui/device/screen")
-- util local util = require("ffi/util")
-- lfs -- lfs
local Device = { local Device = {

@ -3,6 +3,15 @@ local Screen = require("ui/screen")
local UIManager = require("ui/uimanager") local UIManager = require("ui/uimanager")
local DEBUG = require("dbg") local DEBUG = require("dbg")
-- lfs -- lfs
local ffi = require("ffi")
ffi.cdef[[
int strcoll (char *str1, char *str2);
]]
-- string sort function respecting LC_COLLATE
local function strcoll(str1, str2)
return ffi.C.strcoll(ffi.cast("char*", str1), ffi.cast("char*", str2)) <= 0
end
local FileChooser = Menu:extend{ local FileChooser = Menu:extend{
height = Screen:getHeight(), height = Screen:getHeight(),
@ -39,9 +48,9 @@ function FileChooser:genItemTableFromPath(path)
end end
end end
end end
table.sort(dirs) table.sort(dirs, strcoll)
if path ~= "/" then table.insert(dirs, 1, "..") end if path ~= "/" then table.insert(dirs, 1, "..") end
table.sort(files) table.sort(files, strcoll)
local item_table = {} local item_table = {}
for _, dir in ipairs(dirs) do for _, dir in ipairs(dirs) do

@ -1 +1 @@
Subproject commit ac9eea0e045cc6e0a6021850fe804ae1c09748a3 Subproject commit e94fe284a8d1bbbf3b09de2961b086073c0e0319

@ -6,23 +6,28 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: https://github.com/koreader/koreader-base/issues\n" "Report-Msgid-Bugs-To: https://github.com/koreader/koreader-base/issues\n"
"POT-Creation-Date: 2014-04-23 15:01+0000\n" "POT-Creation-Date: 2014-05-15 09:54+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
#: reader.lua:119 #: plugins/evernote.koplugin/main.lua:323
msgid ""
" others."
msgstr ""
#: reader.lua:115
msgid "" msgid ""
"-d start in debug mode" "-d start in debug mode"
msgstr "" msgstr ""
#: reader.lua:121 #: reader.lua:117
msgid "" msgid ""
"-h show this usage help" "-h show this usage help"
msgstr "" msgstr ""
#: reader.lua:120 #: reader.lua:116
msgid "" msgid ""
"-p [rows] enable Lua code profiling" "-p [rows] enable Lua code profiling"
msgstr "" msgstr ""
@ -63,7 +68,7 @@ msgid ""
"Apply" "Apply"
msgstr "" msgstr ""
#: frontend/apps/reader/modules/readertypeset.lua:54 #: frontend/apps/reader/modules/readertypeset.lua:55
msgid "" msgid ""
"Auto" "Auto"
msgstr "" msgstr ""
@ -116,7 +121,7 @@ msgstr ""
#: frontend/apps/reader/modules/readergoto.lua:36 #: frontend/apps/reader/modules/readergoto.lua:36
#: frontend/ui/widget/confirmbox.lua:26 #: frontend/ui/widget/confirmbox.lua:26
#: plugins/evernote.koplugin/main.lua:92 #: plugins/evernote.koplugin/main.lua:123
msgid "" msgid ""
"Cancel" "Cancel"
msgstr "" msgstr ""
@ -203,44 +208,46 @@ msgid ""
"Embedded Style" "Embedded Style"
msgstr "" msgstr ""
#: plugins/evernote.koplugin/main.lua:245 #: plugins/evernote.koplugin/main.lua:327
msgid "" msgid ""
"Error occurs when exporting book:" "Error occurs when exporting book:"
msgstr "" msgstr ""
#: plugins/evernote.koplugin/main.lua:140 #: plugins/evernote.koplugin/main.lua:177
#: plugins/evernote.koplugin/main.lua:152 #: plugins/evernote.koplugin/main.lua:189
msgid "" msgid ""
"Error occurs when login:" "Error occurs when login:"
msgstr "" msgstr ""
#: plugins/evernote.koplugin/main.lua:247 #: plugins/evernote.koplugin/main.lua:329
msgid "" msgid ""
"Errors occur when exporting book:" "Errors occur when exporting book:"
msgstr "" msgstr ""
#: plugins/evernote.koplugin/main.lua:41 #: plugins/evernote.koplugin/main.lua:42
#: plugins/evernote.koplugin/main.lua:52
#: plugins/evernote.koplugin/main.lua:64
msgid "" msgid ""
"Evernote" "Evernote"
msgstr "" msgstr ""
#: plugins/evernote.koplugin/main.lua:56 #: plugins/evernote.koplugin/main.lua:81
msgid "" msgid ""
"Export all notes in this book" "Export all notes in this book"
msgstr "" msgstr ""
#: plugins/evernote.koplugin/main.lua:69 #: plugins/evernote.koplugin/main.lua:97
msgid "" msgid ""
"Export all notes in your library" "Export all notes in your library"
msgstr "" msgstr ""
#: plugins/evernote.koplugin/main.lua:238 #: plugins/evernote.koplugin/main.lua:320
#: plugins/evernote.koplugin/main.lua:240 #: plugins/evernote.koplugin/main.lua:322
msgid "" msgid ""
"Exported notes in book:" "Exported notes in book:"
msgstr "" msgstr ""
#: reader.lua:66 #: reader.lua:62
msgid "" msgid ""
"File does not exist" "File does not exist"
msgstr "" msgstr ""
@ -327,12 +334,12 @@ msgid ""
"Hyphenation" "Hyphenation"
msgstr "" msgstr ""
#: reader.lua:126 #: reader.lua:122
msgid "" msgid ""
"If you don't pass any path, the last viewed document will be opened" "If you don't pass any path, the last viewed document will be opened"
msgstr "" msgstr ""
#: reader.lua:123 #: reader.lua:119
msgid "" msgid ""
"If you give the name of a directory instead of a file path, a file" "If you give the name of a directory instead of a file path, a file"
msgstr "" msgstr ""
@ -357,7 +364,7 @@ msgid ""
"Invert" "Invert"
msgstr "" msgstr ""
#: plugins/evernote.koplugin/main.lua:17 #: plugins/evernote.koplugin/main.lua:16
msgid "" msgid ""
"Koreader Notes" "Koreader Notes"
msgstr "" msgstr ""
@ -387,23 +394,28 @@ msgid ""
"Location" "Location"
msgstr "" msgstr ""
#: plugins/evernote.koplugin/main.lua:45 #: plugins/evernote.koplugin/main.lua:140
#: plugins/evernote.koplugin/main.lua:99 msgid ""
"Logging in please wait..."
msgstr ""
#: plugins/evernote.koplugin/main.lua:55
#: plugins/evernote.koplugin/main.lua:130
msgid "" msgid ""
"Login" "Login"
msgstr "" msgstr ""
#: plugins/evernote.koplugin/main.lua:16 #: plugins/evernote.koplugin/main.lua:15
msgid "" msgid ""
"Login to Evernote" "Login to Evernote"
msgstr "" msgstr ""
#: plugins/evernote.koplugin/main.lua:158 #: plugins/evernote.koplugin/main.lua:195
msgid "" msgid ""
"Login to Evernote successfully" "Login to Evernote successfully"
msgstr "" msgstr ""
#: plugins/evernote.koplugin/main.lua:45 #: plugins/evernote.koplugin/main.lua:54
msgid "" msgid ""
"Logout" "Logout"
msgstr "" msgstr ""
@ -413,7 +425,7 @@ msgid ""
"More" "More"
msgstr "" msgstr ""
#: reader.lua:81 #: reader.lua:77
msgid "" msgid ""
"No reader engine for this file" "No reader engine for this file"
msgstr "" msgstr ""
@ -423,7 +435,7 @@ msgid ""
"Not supported device model!" "Not supported device model!"
msgstr "" msgstr ""
#: plugins/evernote.koplugin/main.lua:258 #: plugins/evernote.koplugin/main.lua:339
msgid "" msgid ""
"Note: " "Note: "
msgstr "" msgstr ""
@ -439,7 +451,7 @@ msgid ""
"Page" "Page"
msgstr "" msgstr ""
#: frontend/ui/widget/touchmenu.lua:345 #: frontend/ui/widget/touchmenu.lua:357
msgid "" msgid ""
"Page " "Page "
msgstr "" msgstr ""
@ -480,7 +492,7 @@ msgid ""
"RTL" "RTL"
msgstr "" msgstr ""
#: reader.lua:117 #: reader.lua:113
msgid "" msgid ""
"Read all the books on your E-Ink reader" "Read all the books on your E-Ink reader"
msgstr "" msgstr ""
@ -500,6 +512,11 @@ msgid ""
"Render Quality" "Render Quality"
msgstr "" msgstr ""
#: plugins/evernote.koplugin/main.lua:48
msgid ""
"Sandbox"
msgstr ""
#: frontend/ui/data/strings.lua:5 #: frontend/ui/data/strings.lua:5
msgid "" msgid ""
"Screen Mode" "Screen Mode"
@ -520,7 +537,7 @@ msgid ""
"Scroll Mode" "Scroll Mode"
msgstr "" msgstr ""
#: reader.lua:129 #: reader.lua:125
msgid "" msgid ""
"See http://github.com/koreader/kindlepdfviewer for more info." "See http://github.com/koreader/kindlepdfviewer for more info."
msgstr "" msgstr ""
@ -587,7 +604,7 @@ msgid ""
"Table of contents" "Table of contents"
msgstr "" msgstr ""
#: frontend/ui/widget/button.lua:78 #: frontend/ui/widget/button.lua:80
msgid "" msgid ""
"Tap Button" "Tap Button"
msgstr "" msgstr ""
@ -597,17 +614,17 @@ msgid ""
"Text Align" "Text Align"
msgstr "" msgstr ""
#: plugins/evernote.koplugin/main.lua:76 #: plugins/evernote.koplugin/main.lua:107
msgid "" msgid ""
"This may take several minutes..." "This may take several minutes..."
msgstr "" msgstr ""
#: plugins/evernote.koplugin/main.lua:63 #: plugins/evernote.koplugin/main.lua:91
msgid "" msgid ""
"This may take several seconds..." "This may take several seconds..."
msgstr "" msgstr ""
#: reader.lua:128 #: reader.lua:124
msgid "" msgid ""
"This software is licensed under the GPLv3." "This software is licensed under the GPLv3."
msgstr "" msgstr ""
@ -678,6 +695,12 @@ msgid ""
"Writing screen to " "Writing screen to "
msgstr "" msgstr ""
#: plugins/evernote.koplugin/main.lua:50
#: plugins/evernote.koplugin/main.lua:71
msgid ""
"Yinxiang"
msgstr ""
#: frontend/apps/reader/modules/readerzooming.lua:311 #: frontend/apps/reader/modules/readerzooming.lua:311
msgid "" msgid ""
"Zoom to fit content" "Zoom to fit content"
@ -708,8 +731,8 @@ msgid ""
"Zoom to fit page width" "Zoom to fit page width"
msgstr "" msgstr ""
#: plugins/evernote.koplugin/main.lua:241 #: plugins/evernote.koplugin/main.lua:323
#: plugins/evernote.koplugin/main.lua:248 #: plugins/evernote.koplugin/main.lua:330
msgid "" msgid ""
"and " "and "
msgstr "" msgstr ""
@ -724,7 +747,7 @@ msgid ""
"cancel" "cancel"
msgstr "" msgstr ""
#: reader.lua:124 #: reader.lua:120
msgid "" msgid ""
"chooser will show up and let you select a file" "chooser will show up and let you select a file"
msgstr "" msgstr ""
@ -740,7 +763,7 @@ msgid ""
"chose selected option" "chose selected option"
msgstr "" msgstr ""
#: frontend/apps/reader/modules/readertypeset.lua:48 #: frontend/apps/reader/modules/readertypeset.lua:49
msgid "" msgid ""
"clear all external styles" "clear all external styles"
msgstr "" msgstr ""
@ -762,7 +785,7 @@ msgid ""
"close document" "close document"
msgstr "" msgstr ""
#: frontend/ui/widget/menu.lua:449 #: frontend/ui/widget/menu.lua:452
msgid "" msgid ""
"close menu" "close menu"
msgstr "" msgstr ""
@ -862,12 +885,12 @@ msgid ""
"go to start" "go to start"
msgstr "" msgstr ""
#: frontend/ui/widget/menu.lua:451 #: frontend/ui/widget/menu.lua:454
msgid "" msgid ""
"goto next page of the menu" "goto next page of the menu"
msgstr "" msgstr ""
#: frontend/ui/widget/menu.lua:454 #: frontend/ui/widget/menu.lua:457
msgid "" msgid ""
"goto previous page of the menu" "goto previous page of the menu"
msgstr "" msgstr ""
@ -967,7 +990,7 @@ msgid ""
"move visible area up" "move visible area up"
msgstr "" msgstr ""
#: frontend/ui/widget/menu.lua:538 #: frontend/ui/widget/menu.lua:541
msgid "" msgid ""
"no choices available" "no choices available"
msgstr "" msgstr ""
@ -987,22 +1010,17 @@ msgid ""
"on" "on"
msgstr "" msgstr ""
#: reader.lua:71 #: reader.lua:67
msgid "" msgid ""
"opening file" "opening file"
msgstr "" msgstr ""
#: plugins/evernote.koplugin/main.lua:241
msgid ""
"others."
msgstr ""
#: frontend/ui/data/strings.lua:55 #: frontend/ui/data/strings.lua:55
msgid "" msgid ""
"page" "page"
msgstr "" msgstr ""
#: frontend/ui/widget/menu.lua:532 #: frontend/ui/widget/menu.lua:535
msgid "" msgid ""
"page " "page "
msgstr "" msgstr ""
@ -1028,7 +1046,7 @@ msgid ""
msgstr "" msgstr ""
#: frontend/ui/widget/configdialog.lua:440 #: frontend/ui/widget/configdialog.lua:440
#: frontend/ui/widget/menu.lua:463 #: frontend/ui/widget/menu.lua:466
msgid "" msgid ""
"select current menu item" "select current menu item"
msgstr "" msgstr ""
@ -1074,7 +1092,7 @@ msgid ""
"toggle bold" "toggle bold"
msgstr "" msgstr ""
#: reader.lua:116 #: reader.lua:112
msgid "" msgid ""
"usage: ./reader.lua [OPTION] ... path" "usage: ./reader.lua [OPTION] ... path"
msgstr "" msgstr ""

@ -1,3 +1,7 @@
local DocumentRegistry = require("document/documentregistry")
local DocSettings = require("docsettings")
local DEBUG = require("dbg")
require("MD5")
-- lfs -- lfs
local MyClipping = { local MyClipping = {
@ -157,7 +161,7 @@ function MyClipping:getTime(line)
for k, v in pairs(months) do for k, v in pairs(months) do
if line:find(k) then if line:find(k) then
month = v month = v
_, _, day = line:find(" (%d%d),") _, _, day = line:find(" (%d?%d),")
_, _, year = line:find(" (%d%d%d%d)") _, _, year = line:find(" (%d%d%d%d)")
break break
end end
@ -206,7 +210,22 @@ function MyClipping:getText(line)
return line:match("^%s*(.-)%s*$") or "" return line:match("^%s*(.-)%s*$") or ""
end end
-- get PNG string and md5 hash
function MyClipping:getImage(image)
--DEBUG("image", image)
local doc = DocumentRegistry:openDocument(image.file)
if doc then
local png = doc:clipPagePNGString(image.pos0, image.pos1,
image.pboxes, image.drawer)
--doc:clipPagePNGFile(image.pos0, image.pos1,
--image.pboxes, image.drawer, "/tmp/"..md5(png)..".png")
doc:close()
if png then return { png = png, hash = md5(png) } end
end
end
function MyClipping:parseHighlight(highlights, book) function MyClipping:parseHighlight(highlights, book)
--DEBUG("book", book.file)
for page, items in pairs(highlights) do for page, items in pairs(highlights) do
for _, item in ipairs(items) do for _, item in ipairs(items) do
local clipping = {} local clipping = {}
@ -214,8 +233,21 @@ function MyClipping:parseHighlight(highlights, book)
clipping.sort = "highlight" clipping.sort = "highlight"
clipping.time = self:getTime(item.datetime or "") clipping.time = self:getTime(item.datetime or "")
clipping.text = self:getText(item.text) clipping.text = self:getText(item.text)
if item.pos0 and item.pos1 and
item.pos0.x and item.pos0.y and
item.pos1.x and item.pos1.y then
-- highlights in reflowing mode don't have page in pos
if item.pos0.page == nil then item.pos0.page = page end
if item.pos1.page == nil then item.pos1.page = page end
local image = {}
image.file = book.file
image.pos0, image.pos1 = item.pos0, item.pos1
image.pboxes = item.pboxes
image.drawer = item.drawer
clipping.image = self:getImage(image)
end
-- TODO: store chapter info when exporting highlights -- TODO: store chapter info when exporting highlights
if clipping.text and clipping.text ~= "" then if clipping.text and clipping.text ~= "" or clipping.image then
table.insert(book, { clipping }) table.insert(book, { clipping })
end end
end end
@ -232,7 +264,10 @@ function MyClipping:parseHistory()
if ok and stored.highlight then if ok and stored.highlight then
local _, _, docname = path:find("%[.*%](.*)%.lua$") local _, _, docname = path:find("%[.*%](.*)%.lua$")
local title, author = self:getTitle(docname) local title, author = self:getTitle(docname)
local path = DocSettings:getPathFromHistory(f)
local name = DocSettings:getNameFromHistory(f)
clippings[title] = { clippings[title] = {
file = path .. "/" .. name,
title = title, title = title,
author = author, author = author,
} }
@ -250,6 +285,7 @@ function MyClipping:parseCurrentDoc(view)
local _, _, docname = path:find(".*/(.*)") local _, _, docname = path:find(".*/(.*)")
local title, author = self:getTitle(docname) local title, author = self:getTitle(docname)
clippings[title] = { clippings[title] = {
file = view.document.file,
title = title, title = title,
author = author, author = author,
} }

@ -38,19 +38,19 @@ function EvernoteExporter:init()
end end
function EvernoteExporter:addToMainMenu(tab_item_table) function EvernoteExporter:addToMainMenu(tab_item_table)
local domain = nil
if self.evernote_domain == "sandbox" then
domain = _("Sandbox")
elseif self.evernote_domain == "yinxiang" then
domain = _("Yinxiang")
else
domain = _("Evernote")
end
table.insert(tab_item_table.plugins, { table.insert(tab_item_table.plugins, {
text = _("Evernote"), text = _("Evernote"),
sub_item_table = { sub_item_table = {
{ {
text_func = function() text_func = function()
local domain = nil
if self.evernote_domain == "sandbox" then
domain = _("Sandbox")
elseif self.evernote_domain == "yinxiang" then
domain = _("Yinxiang")
else
domain = _("Evernote")
end
return self.evernote_token and (_("Logout") .. " " .. domain) return self.evernote_token and (_("Logout") .. " " .. domain)
or _("Login") or _("Login")
end, end,
@ -232,7 +232,8 @@ function EvernoteExporter:exportCurrentNotes(view)
self:exportClippings(client, clippings) self:exportClippings(client, clippings)
end end
function EvernoteExporter:updateClippings(clippings, new_clippings) function EvernoteExporter:updateHistoryClippings(clippings, new_clippings)
-- update clippings from history clippings
for title, booknotes in pairs(new_clippings) do for title, booknotes in pairs(new_clippings) do
for chapter_index, chapternotes in ipairs(booknotes) do for chapter_index, chapternotes in ipairs(booknotes) do
for note_index, note in ipairs(chapternotes) do for note_index, note in ipairs(chapternotes) do
@ -242,6 +243,7 @@ function EvernoteExporter:updateClippings(clippings, new_clippings)
or clippings[title][chapter_index][note_index].time ~= note.time 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].text ~= note.text
or clippings[title][chapter_index][note_index].note ~= note.note then or clippings[title][chapter_index][note_index].note ~= note.note then
DEBUG("found new notes in history", booknotes.title)
clippings[title] = booknotes clippings[title] = booknotes
end end
end end
@ -250,6 +252,18 @@ function EvernoteExporter:updateClippings(clippings, new_clippings)
return clippings return clippings
end end
function EvernoteExporter:updateMyClippings(clippings, new_clippings)
-- only new titles or new notes in My clippings are updated to clippings
-- since appending is the only way to modify notes in My Clippings
for title, booknotes in pairs(new_clippings) do
if clippings[title] == nil or #clippings[title] < #booknotes then
DEBUG("found new notes in MyClipping", booknotes.title)
clippings[title] = booknotes
end
end
return clippings
end
function EvernoteExporter:exportAllNotes() function EvernoteExporter:exportAllNotes()
local EvernoteClient = require("EvernoteClient") local EvernoteClient = require("EvernoteClient")
local client = EvernoteClient:new{ local client = EvernoteClient:new{
@ -258,8 +272,8 @@ function EvernoteExporter:exportAllNotes()
} }
local clippings = self.config:readSetting("clippings") or {} local clippings = self.config:readSetting("clippings") or {}
clippings = self:updateClippings(clippings, self.parser:parseMyClippings()) clippings = self:updateHistoryClippings(clippings, self.parser:parseHistory())
clippings = self:updateClippings(clippings, self.parser:parseHistory()) clippings = self:updateMyClippings(clippings, self.parser:parseMyClippings())
-- remove blank entries -- remove blank entries
for title, booknotes in pairs(clippings) do for title, booknotes in pairs(clippings) do
-- chapter number is zero -- chapter number is zero
@ -277,9 +291,13 @@ function EvernoteExporter:exportClippings(client, clippings)
local export_count, error_count = 0, 0 local export_count, error_count = 0, 0
local export_title, error_title local export_title, error_title
for title, booknotes in pairs(clippings) do for title, booknotes in pairs(clippings) do
-- skip exported booknotes if type(booknotes.exported) ~= "table" then
if booknotes.exported ~= true then booknotes.exported = {}
local ok, err = pcall(self.exportBooknotes, self, end
-- check if booknotes are exported in this notebook
-- so that booknotes will still be exported after switching user account
if booknotes.exported[self.notebook_guid] ~= true then
local ok, err = pcall(self.exportBooknotes, self,
client, title, booknotes) client, title, booknotes)
-- error reporting -- error reporting
if not ok then if not ok then
@ -290,10 +308,8 @@ function EvernoteExporter:exportClippings(client, clippings)
DEBUG("Exported notes in book:", title) DEBUG("Exported notes in book:", title)
export_count = export_count + 1 export_count = export_count + 1
export_title = title export_title = title
booknotes.exported = true booknotes.exported[self.notebook_guid] = true
end end
else
DEBUG("Skip exporting notes in book:", title)
end end
end end
@ -324,10 +340,22 @@ function EvernoteExporter:exportBooknotes(client, title, booknotes)
}) })
--DEBUG("content", content) --DEBUG("content", content)
local note_guid = client:findNoteByTitle(title, self.notebook_guid) local note_guid = client:findNoteByTitle(title, self.notebook_guid)
local resources = {}
for _, chapter in ipairs(booknotes) do
for _, clipping in ipairs(chapter) do
if clipping.image then
table.insert(resources, {
image = clipping.image
})
-- nullify clipping image after passing it to evernote client
clipping.image = nil
end
end
end
if not note_guid then if not note_guid then
client:createNote(title, content, {}, self.notebook_guid) client:createNote(title, content, resources, {}, self.notebook_guid)
else else
client:updateNote(note_guid, title, content, {}, self.notebook_guid) client:updateNote(note_guid, title, content, resources, {}, self.notebook_guid)
end end
end end

@ -43,6 +43,9 @@
</div> </div>
<div style="font-size:12pt"> <div style="font-size:12pt">
<span>#{= htmlescape(clipping.text) }#</span> <span>#{= htmlescape(clipping.text) }#</span>
#{ if clipping.image then }#
<en-media type="image/png" hash="#{= clipping.image.hash }#"/>
#{ end }#
</div> </div>
#{ if clipping.note then }# #{ if clipping.note then }#
<div style="font-size:11pt; margin-top:0.2em;"> <div style="font-size:11pt; margin-top:0.2em;">

@ -0,0 +1,62 @@
require "defaults"
require "libs/libkoreader-luagettext"
package.path = "?.lua;common/?.lua;frontend/?.lua"
package.cpath = "?.so;common/?.so;/usr/lib/lua/?.so"
-- global einkfb for Screen
einkfb = require("ffi/framebuffer")
-- do not show SDL window
einkfb.dummy = true
local Screen = require("ui/screen")
local DocSettings = require("docsettings")
G_reader_settings = DocSettings:open(".reader")
local DocumentRegistry = require("document/documentregistry")
local DEBUG = require("dbg")
-- screen should be inited for crengine
Screen:init()
describe("PDF document module", function()
local sample_pdf = "spec/front/unit/data/tall.pdf"
it("should open document", function()
doc = DocumentRegistry:openDocument(sample_pdf)
assert.truthy(doc)
end)
it("should get page dimensions", function()
local dimen = doc:getPageDimensions(1, 1, 0)
assert.are.same(dimen.w, 567)
assert.are.same(dimen.h, 1418)
end)
local pos0 = {page = 1, x = 0, y = 20}
local pos1 = {page = 1, x = 300, y = 120}
local pboxes = {
{x = 26, y = 42, w = 240, h = 22},
{x = 48, y = 82, w = 185, h = 22},
}
it("should clip page rect to PNG file", function()
doc:clipPagePNGFile(pos0, pos1, nil, nil, "/tmp/clip0.png")
doc:clipPagePNGFile(pos0, pos1, pboxes, "lighten", "/tmp/clip1.png")
end)
it("should clip page rect to PNG string", function()
local clip0 = doc:clipPagePNGString(pos0, pos1, nil, nil)
assert.truthy(clip0)
local clip1 = doc:clipPagePNGString(pos0, pos1, pboxes, "lighten")
assert.truthy(clip1)
end)
it("should close document", function()
doc:close()
end)
end)
describe("EPUB document module", function()
local sample_epub = "spec/front/unit/data/leaves_of_grass.epub"
it("should open document", function()
doc = DocumentRegistry:openDocument(sample_epub)
assert.truthy(doc)
doc:close()
end)
it("should close document", function()
doc:close()
end)
end)
Loading…
Cancel
Save