2011-11-14 17:30:16 +00:00
|
|
|
#!./kpdfview
|
|
|
|
--[[
|
|
|
|
KindlePDFViewer: a reader implementation
|
|
|
|
Copyright (C) 2011 Hans-Werner Hilse <hilse@web.de>
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
]]--
|
|
|
|
|
2011-11-16 16:13:08 +00:00
|
|
|
require "alt_getopt"
|
2011-12-07 23:45:39 +00:00
|
|
|
require "pdfreader"
|
2011-12-08 00:17:33 +00:00
|
|
|
require "filechooser"
|
2011-11-21 00:02:03 +00:00
|
|
|
|
2011-11-16 16:13:08 +00:00
|
|
|
-- option parsing:
|
|
|
|
longopts = {
|
|
|
|
password = "p",
|
2011-11-17 10:58:49 +00:00
|
|
|
goto = "g",
|
2011-11-16 16:13:08 +00:00
|
|
|
gamma = "G",
|
|
|
|
device = "d",
|
|
|
|
help = "h"
|
|
|
|
}
|
2011-11-16 19:34:36 +00:00
|
|
|
optarg, optind = alt_getopt.get_opts(ARGV, "p:G:hg:d:", longopts)
|
2011-11-16 16:13:08 +00:00
|
|
|
if optarg["h"] or ARGV[optind] == nil then
|
|
|
|
print("usage: ./reader.lua [OPTION] ... DOCUMENT.PDF")
|
|
|
|
print("Read PDFs on your E-Ink reader")
|
|
|
|
print("")
|
|
|
|
print("-p, --password=PASSWORD set password for reading PDF document")
|
2011-11-16 18:12:35 +00:00
|
|
|
print("-g, --goto=page start reading on page")
|
2011-11-16 16:13:08 +00:00
|
|
|
print("-G, --gamma=GAMMA set gamma correction")
|
|
|
|
print(" (floating point notation, e.g. \"1.5\")")
|
|
|
|
print("-d, --device=DEVICE set device specific configuration,")
|
2011-11-16 22:34:23 +00:00
|
|
|
print(" currently one of \"kdxg\" (default), \"k3\"")
|
2011-11-16 16:13:08 +00:00
|
|
|
print("-h, --help show this usage help")
|
|
|
|
print("")
|
2011-12-08 00:17:33 +00:00
|
|
|
print("If you give the name of a directory instead of a path, a file")
|
|
|
|
print("chooser will show up and let you select a PDF file")
|
|
|
|
print("")
|
2011-11-16 16:13:08 +00:00
|
|
|
print("This software is licensed under the GPLv3.")
|
|
|
|
print("See http://github.com/hwhw/kindlepdfviewer for more info.")
|
|
|
|
return
|
2011-11-14 17:30:16 +00:00
|
|
|
end
|
|
|
|
|
2011-11-16 16:13:08 +00:00
|
|
|
if optarg["d"] == "k3" then
|
|
|
|
-- for now, the only difference is the additional input device
|
|
|
|
input.open("/dev/input/event0")
|
|
|
|
input.open("/dev/input/event1")
|
|
|
|
input.open("/dev/input/event2")
|
2011-11-21 00:02:03 +00:00
|
|
|
set_k3_keycodes()
|
2011-11-16 23:14:36 +00:00
|
|
|
elseif optarg["d"] == "emu" then
|
|
|
|
input.open("")
|
|
|
|
-- SDL key codes
|
2011-11-20 20:40:56 +00:00
|
|
|
set_emu_keycodes()
|
2011-11-16 16:13:08 +00:00
|
|
|
else
|
|
|
|
input.open("/dev/input/event0")
|
|
|
|
input.open("/dev/input/event1")
|
|
|
|
end
|
|
|
|
|
2011-11-20 21:36:31 +00:00
|
|
|
if optarg["G"] ~= nil then
|
|
|
|
globalgamma = optarg["G"]
|
|
|
|
end
|
|
|
|
|
2011-11-14 17:30:16 +00:00
|
|
|
fb = einkfb.open("/dev/fb0")
|
|
|
|
width, height = fb:getSize()
|
|
|
|
|
2011-12-08 00:17:33 +00:00
|
|
|
if lfs.attributes(ARGV[optind], "mode") == "directory" then
|
|
|
|
local running = true
|
2011-12-08 18:01:40 +00:00
|
|
|
FileChooser:setPath(ARGV[optind])
|
2011-12-08 00:17:33 +00:00
|
|
|
while running do
|
2011-12-08 18:01:40 +00:00
|
|
|
local pdffile = FileChooser:choose(0,height)
|
2011-12-08 00:17:33 +00:00
|
|
|
if pdffile ~= nil then
|
2011-12-08 23:10:54 +00:00
|
|
|
if PDFReader:open(pdffile,"") then -- TODO: query for password
|
|
|
|
PDFReader:goto(tonumber(PDFReader.settings:readsetting("last_page") or 1))
|
|
|
|
PDFReader:inputloop()
|
|
|
|
end
|
2011-12-08 00:17:33 +00:00
|
|
|
else
|
|
|
|
running = false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
PDFReader:open(ARGV[optind], optarg["p"])
|
|
|
|
PDFReader:goto(tonumber(optarg["g"]) or tonumber(PDFReader.settings:readsetting("last_page") or 1))
|
|
|
|
PDFReader:inputloop()
|
|
|
|
end
|