2012-04-09 17:04:26 +00:00
|
|
|
require "font"
|
2012-03-28 16:16:00 +00:00
|
|
|
require "unireader"
|
|
|
|
require "inputbox"
|
2012-04-06 10:05:54 +00:00
|
|
|
require "selectmenu"
|
2012-10-05 09:59:37 +00:00
|
|
|
require "dialog"
|
2012-03-28 16:16:00 +00:00
|
|
|
|
|
|
|
CREReader = UniReader:new{
|
2012-12-21 00:47:02 +00:00
|
|
|
-- this is defined in kpvcrlib/crengine/crengine/include/lvdocview.h
|
|
|
|
SCROLL_VIEW_MODE = 0,
|
|
|
|
PAGE_VIEW_MODE = 1,
|
|
|
|
|
2012-04-07 14:55:56 +00:00
|
|
|
pos = nil,
|
2012-03-31 12:22:22 +00:00
|
|
|
percent = 0,
|
2012-04-06 11:11:18 +00:00
|
|
|
|
2012-04-06 11:30:10 +00:00
|
|
|
gamma_index = 15,
|
2012-12-21 18:24:52 +00:00
|
|
|
header_font = "Droid Sans",
|
2012-04-06 11:11:18 +00:00
|
|
|
font_face = nil,
|
2012-06-02 21:51:55 +00:00
|
|
|
default_font = "Droid Sans",
|
2012-05-17 09:25:20 +00:00
|
|
|
font_zoom = 0,
|
2012-04-13 22:38:18 +00:00
|
|
|
|
|
|
|
line_space_percent = 100,
|
2012-12-08 17:45:25 +00:00
|
|
|
view_mode = DCREREADER_VIEW_MODE,
|
2012-12-19 18:31:41 +00:00
|
|
|
view_pan_step = nil,
|
2012-03-28 16:16:00 +00:00
|
|
|
}
|
|
|
|
|
2012-03-30 04:06:33 +00:00
|
|
|
function CREReader:init()
|
2012-03-30 06:10:04 +00:00
|
|
|
self:addAllCommands()
|
2012-03-30 04:06:33 +00:00
|
|
|
self:adjustCreReaderCommands()
|
2012-09-10 13:45:05 +00:00
|
|
|
|
2012-12-19 22:25:54 +00:00
|
|
|
-- initialize cache and hyphenation engine
|
2012-09-10 13:45:05 +00:00
|
|
|
cre.initCache(1024*1024*64)
|
2012-04-09 17:04:26 +00:00
|
|
|
-- we need to initialize the CRE font list
|
|
|
|
local fonts = Font:getFontList()
|
|
|
|
for _k, _v in ipairs(fonts) do
|
2012-10-03 16:29:09 +00:00
|
|
|
if _v ~= "Dingbats.cff" and _v ~= "StandardSymL.cff" then
|
|
|
|
local ok, err = pcall(cre.registerFont, Font.fontdir..'/'.._v)
|
|
|
|
if not ok then
|
|
|
|
Debug(err)
|
|
|
|
end
|
2012-04-09 17:04:26 +00:00
|
|
|
end
|
|
|
|
end
|
2012-06-02 21:51:55 +00:00
|
|
|
|
|
|
|
local default_font = G_reader_settings:readSetting("cre_font")
|
|
|
|
if default_font then
|
|
|
|
self.default_font = default_font
|
|
|
|
end
|
2012-12-19 18:31:41 +00:00
|
|
|
|
2012-12-21 18:24:52 +00:00
|
|
|
local header_font = G_reader_settings:readSetting("header_font")
|
|
|
|
if header_font then
|
|
|
|
self.header_font = header_font
|
|
|
|
end
|
|
|
|
|
2012-12-19 18:31:41 +00:00
|
|
|
if G_width > G_height then
|
|
|
|
-- in landscape mode, crengine will render in two column mode
|
|
|
|
self.view_pan_step = G_height * 2
|
|
|
|
else
|
|
|
|
self.view_pan_step = G_height
|
|
|
|
end
|
2012-03-30 04:06:33 +00:00
|
|
|
end
|
2012-09-24 19:07:23 +00:00
|
|
|
|
2012-08-31 17:41:36 +00:00
|
|
|
-- inspect the zipfile content
|
2012-05-20 12:37:08 +00:00
|
|
|
function CREReader:ZipContentExt(fname)
|
2012-09-24 15:07:41 +00:00
|
|
|
local i, s = 1
|
2012-09-25 10:55:16 +00:00
|
|
|
local tmp = io.popen('unzip -l \"'..fname..'\"', "r")
|
|
|
|
while true do
|
|
|
|
s = tmp:read("*line")
|
|
|
|
if i > 3 then tmp:close(); break; end
|
|
|
|
i = i + 1
|
|
|
|
end
|
2012-09-25 16:06:49 +00:00
|
|
|
if s then
|
|
|
|
local ext = string.match(s, ".+%.([^.]+)")
|
|
|
|
if ext then
|
|
|
|
ext = string.lower(ext)
|
|
|
|
return ext
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return nil
|
2012-05-20 12:37:08 +00:00
|
|
|
end
|
|
|
|
|
2012-03-28 16:16:00 +00:00
|
|
|
-- open a CREngine supported file and its settings store
|
|
|
|
function CREReader:open(filename)
|
|
|
|
local ok
|
2012-09-05 16:49:43 +00:00
|
|
|
local file_type = string.lower(string.match(filename, ".+%.([^.]+)") or "")
|
|
|
|
-- check zips for potential problems - wrong zip & wrong content
|
2012-04-30 08:58:05 +00:00
|
|
|
if file_type == "zip" then
|
2012-05-20 12:37:08 +00:00
|
|
|
file_type = self:ZipContentExt(filename)
|
2012-05-19 10:59:38 +00:00
|
|
|
end
|
2012-09-05 16:49:43 +00:00
|
|
|
if not file_type then
|
|
|
|
return false, "Error unzipping file. "
|
|
|
|
end
|
|
|
|
-- if the zip entry is not cre-document
|
2012-10-22 05:08:36 +00:00
|
|
|
if ReaderChooser:getReaderByType(file_type) ~= CREReader then
|
2012-09-05 16:49:43 +00:00
|
|
|
return false, "Zip contains improper content. "
|
|
|
|
end
|
2012-05-19 10:59:38 +00:00
|
|
|
-- these two format use the same css file
|
|
|
|
if file_type == "html" then
|
|
|
|
file_type = "htm"
|
|
|
|
end
|
2012-05-17 09:25:20 +00:00
|
|
|
-- if native css-file doesn't exist, one needs to use default cr3.css
|
2012-05-19 10:59:38 +00:00
|
|
|
if not io.open("./data/"..file_type..".css") then
|
|
|
|
file_type = "cr3"
|
|
|
|
end
|
|
|
|
local style_sheet = "./data/"..file_type..".css"
|
2012-12-21 00:47:02 +00:00
|
|
|
-- default to scroll mode
|
|
|
|
local view_mode = self.SCROLL_VIEW_MODE
|
2012-12-10 18:43:34 +00:00
|
|
|
if self.view_mode == "page" then
|
2012-12-21 00:47:02 +00:00
|
|
|
view_mode = self.PAGE_VIEW_MODE
|
2012-12-10 18:43:34 +00:00
|
|
|
end
|
2013-01-12 07:20:37 +00:00
|
|
|
ok, self.doc = pcall(cre.newDocView, style_sheet, G_width, G_height, view_mode)
|
2012-03-28 16:16:00 +00:00
|
|
|
if not ok then
|
2012-09-05 16:49:43 +00:00
|
|
|
return false, "Error opening cre-document. " -- self.doc, will contain error message
|
2012-03-28 16:16:00 +00:00
|
|
|
end
|
2012-12-21 18:24:52 +00:00
|
|
|
self.doc:setHeaderFont(self.header_font)
|
2013-01-12 07:20:37 +00:00
|
|
|
self.filename = filename
|
2012-03-28 16:16:00 +00:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2012-04-07 14:55:56 +00:00
|
|
|
----------------------------------------------------
|
|
|
|
-- setting related methods
|
|
|
|
----------------------------------------------------
|
2012-12-12 17:33:48 +00:00
|
|
|
function CREReader:preLoadSettings(filename)
|
|
|
|
self.settings = DocSettings:open(filename)
|
|
|
|
local view_mode = self.settings:readSetting("view_mode")
|
2012-12-18 21:46:14 +00:00
|
|
|
if view_mode then
|
|
|
|
if view_mode == "scroll" then
|
|
|
|
self.view_mode = "scroll"
|
|
|
|
else
|
|
|
|
self.view_mode = "page"
|
|
|
|
end
|
2012-12-12 18:09:34 +00:00
|
|
|
else
|
2012-12-21 00:34:06 +00:00
|
|
|
self.view_mode = DCREREADER_VIEW_MODE
|
2013-01-08 10:57:18 +00:00
|
|
|
end
|
2012-12-12 17:33:48 +00:00
|
|
|
end
|
|
|
|
|
2012-04-06 11:11:18 +00:00
|
|
|
function CREReader:loadSpecialSettings()
|
|
|
|
local font_face = self.settings:readSetting("font_face")
|
2012-06-02 21:51:55 +00:00
|
|
|
if not font_face then
|
|
|
|
font_face = self.default_font
|
|
|
|
end
|
|
|
|
self.font_face = font_face
|
2012-04-06 11:11:18 +00:00
|
|
|
self.doc:setFontFace(self.font_face)
|
2012-04-06 11:30:10 +00:00
|
|
|
|
|
|
|
local gamma_index = self.settings:readSetting("gamma_index")
|
|
|
|
self.gamma_index = gamma_index or self.gamma_index
|
|
|
|
cre.setGammaIndex(self.gamma_index)
|
2012-04-13 22:38:18 +00:00
|
|
|
|
|
|
|
local line_space_percent = self.settings:readSetting("line_space_percent")
|
|
|
|
self.line_space_percent = line_space_percent or self.line_space_percent
|
2013-01-13 05:19:13 +00:00
|
|
|
self.doc:setDefaultInterlineSpace(self.line_space_percent)
|
2012-05-28 17:19:21 +00:00
|
|
|
|
2012-05-17 09:25:20 +00:00
|
|
|
self.font_zoom = self.settings:readSetting("font_zoom") or 0
|
|
|
|
if self.font_zoom ~= 0 then
|
|
|
|
local i = math.abs(self.font_zoom)
|
|
|
|
local step = self.font_zoom / i
|
|
|
|
while i>0 do
|
|
|
|
self.doc:zoomFont(step)
|
|
|
|
i=i-1
|
|
|
|
end
|
|
|
|
end
|
2013-01-12 07:20:37 +00:00
|
|
|
self.doc:loadDocument(self.filename)
|
2012-04-06 11:11:18 +00:00
|
|
|
end
|
|
|
|
|
2012-03-30 06:25:36 +00:00
|
|
|
function CREReader:getLastPageOrPos()
|
2012-05-28 17:19:21 +00:00
|
|
|
local last_percent = self.settings:readSetting("last_percent")
|
2013-01-11 17:15:46 +00:00
|
|
|
local last_xp = self.settings:readSetting("last_xpointer")
|
|
|
|
|
|
|
|
if last_xp then
|
|
|
|
return last_xp
|
|
|
|
end
|
|
|
|
-- read last_percent for backward compatibility
|
2012-03-31 12:22:22 +00:00
|
|
|
if last_percent then
|
2013-01-11 17:15:46 +00:00
|
|
|
return math.floor((last_percent * self.doc:getPages()) / 10000)
|
2012-03-31 12:22:22 +00:00
|
|
|
else
|
2013-01-08 10:57:18 +00:00
|
|
|
return (self.view_mode == "scroll" and 0) or 1
|
2012-03-31 12:22:22 +00:00
|
|
|
end
|
2012-03-30 06:25:36 +00:00
|
|
|
end
|
|
|
|
|
2012-04-06 12:26:53 +00:00
|
|
|
function CREReader:saveSpecialSettings()
|
2012-04-19 12:37:25 +00:00
|
|
|
self.settings:saveSetting("font_face", self.font_face)
|
|
|
|
self.settings:saveSetting("gamma_index", self.gamma_index)
|
|
|
|
self.settings:saveSetting("line_space_percent", self.line_space_percent)
|
2012-05-17 09:31:48 +00:00
|
|
|
self.settings:saveSetting("font_zoom", self.font_zoom)
|
2012-12-11 07:03:15 +00:00
|
|
|
self.settings:saveSetting("view_mode", self.view_mode)
|
2012-04-06 12:26:53 +00:00
|
|
|
end
|
|
|
|
|
2012-03-30 06:25:36 +00:00
|
|
|
function CREReader:saveLastPageOrPos()
|
2013-01-11 17:15:46 +00:00
|
|
|
-- last_percent is deprecated
|
2013-01-12 07:09:21 +00:00
|
|
|
self.settings:saveSetting("last_percent", self.percent)
|
2013-01-11 17:15:46 +00:00
|
|
|
self.settings:saveSetting("last_xpointer", self.doc:getXPointer())
|
2012-03-30 06:25:36 +00:00
|
|
|
end
|
|
|
|
|
2012-04-07 14:55:56 +00:00
|
|
|
----------------------------------------------------
|
|
|
|
-- render related methods
|
|
|
|
----------------------------------------------------
|
|
|
|
-- we don't need setzoom in CREReader
|
2012-03-29 10:17:32 +00:00
|
|
|
function CREReader:setzoom(page, preCache)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2012-04-07 14:55:56 +00:00
|
|
|
function CREReader:redrawCurrentPage()
|
2013-01-13 05:24:16 +00:00
|
|
|
if self.view_mode == "page" then
|
|
|
|
self:goto(self.pageno)
|
|
|
|
else
|
|
|
|
self:goto(self.pos)
|
|
|
|
end
|
2012-03-30 06:25:36 +00:00
|
|
|
end
|
|
|
|
|
2012-04-10 13:34:38 +00:00
|
|
|
-- there is no zoom mode in CREReader
|
|
|
|
function CREReader:setGlobalZoomMode()
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2012-04-07 14:55:56 +00:00
|
|
|
----------------------------------------------------
|
|
|
|
-- goto related methods
|
|
|
|
----------------------------------------------------
|
2012-04-18 15:54:17 +00:00
|
|
|
function CREReader:goto(pos, is_ignore_jump, pos_type)
|
2012-04-07 14:55:56 +00:00
|
|
|
local prev_xpointer = self.doc:getXPointer()
|
2012-04-09 07:42:19 +00:00
|
|
|
local width, height = G_width, G_height
|
2013-01-08 10:57:18 +00:00
|
|
|
|
2012-04-07 14:55:56 +00:00
|
|
|
if pos_type == "xpointer" then
|
|
|
|
self.doc:gotoXPointer(pos)
|
|
|
|
pos = self.doc:getCurrentPos()
|
2012-10-09 22:13:09 +00:00
|
|
|
elseif pos_type == "link" then
|
|
|
|
self.doc:gotoLink(pos)
|
|
|
|
pos = self.doc:getCurrentPos()
|
2013-01-08 10:57:18 +00:00
|
|
|
elseif self.view_mode == "page" then
|
|
|
|
pos = math.max(pos,1)
|
|
|
|
self.doc:gotoPage(pos)
|
2012-04-19 02:31:38 +00:00
|
|
|
else -- pos_type is position within document
|
2012-04-09 07:06:52 +00:00
|
|
|
pos = math.min(pos, self.doc:getFullHeight() - height)
|
2012-04-07 14:55:56 +00:00
|
|
|
pos = math.max(pos, 0)
|
|
|
|
self.doc:gotoPos(pos)
|
|
|
|
end
|
2012-04-18 16:04:41 +00:00
|
|
|
-- add to jump history, distinguish jump from normal page turn
|
2012-04-07 14:55:56 +00:00
|
|
|
-- NOTE:
|
2012-05-28 17:19:21 +00:00
|
|
|
-- even though we have called gotoPos() or gotoXPointer() previously,
|
2012-04-07 14:55:56 +00:00
|
|
|
-- self.pos hasn't been updated yet here, so we can still make use of it.
|
2012-04-18 15:54:17 +00:00
|
|
|
if not is_ignore_jump then
|
|
|
|
if self.pos and math.abs(self.pos - pos) > height then
|
|
|
|
self:addJump(prev_xpointer)
|
|
|
|
end
|
2012-03-29 11:35:56 +00:00
|
|
|
end
|
2012-03-28 16:16:00 +00:00
|
|
|
self.doc:drawCurrentPage(self.nulldc, fb.bb)
|
|
|
|
|
2012-06-03 22:49:23 +00:00
|
|
|
Debug("## self.show_overlap "..self.show_overlap)
|
2012-12-11 07:03:15 +00:00
|
|
|
if self.show_overlap < 0
|
|
|
|
and self.show_overlap_enable
|
|
|
|
and self.view_mode ~= "page" then
|
2012-04-09 13:52:36 +00:00
|
|
|
fb.bb:dimRect(0,0, width, -self.show_overlap)
|
2012-12-11 07:03:15 +00:00
|
|
|
elseif self.show_overlap > 0
|
2013-01-08 10:57:18 +00:00
|
|
|
and self.show_overlap_enable
|
2012-12-11 07:03:15 +00:00
|
|
|
and self.view_mode ~= "page" then
|
2012-04-09 13:52:36 +00:00
|
|
|
fb.bb:dimRect(0,height - self.show_overlap, width, self.show_overlap)
|
2012-04-09 13:06:05 +00:00
|
|
|
end
|
|
|
|
self.show_overlap = 0
|
|
|
|
|
2012-04-19 06:14:08 +00:00
|
|
|
if self.rcount >= self.rcountmax then
|
2012-06-03 22:49:23 +00:00
|
|
|
Debug("full refresh")
|
2012-04-19 06:14:08 +00:00
|
|
|
self.rcount = 0
|
2012-03-28 16:16:00 +00:00
|
|
|
fb:refresh(0)
|
|
|
|
else
|
2012-06-03 22:49:23 +00:00
|
|
|
Debug("partial refresh")
|
2012-03-28 16:16:00 +00:00
|
|
|
self.rcount = self.rcount + 1
|
|
|
|
fb:refresh(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
self.pos = pos
|
|
|
|
self.pageno = self.doc:getCurrentPage()
|
2012-04-07 14:55:56 +00:00
|
|
|
self.percent = self.doc:getCurrentPercent()
|
2012-03-28 16:16:00 +00:00
|
|
|
end
|
|
|
|
|
2012-04-07 14:55:56 +00:00
|
|
|
function CREReader:gotoPercent(percent)
|
2013-01-11 06:14:31 +00:00
|
|
|
if self.view_mode == "page" then
|
|
|
|
self:goto(percent * self.doc:getPages() / 10000)
|
|
|
|
else
|
|
|
|
self:goto(percent * self.doc:getFullHeight() / 10000)
|
|
|
|
end
|
2012-04-07 14:55:56 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function CREReader:gotoTocEntry(entry)
|
2013-01-11 06:12:29 +00:00
|
|
|
if self.view_mode == "scroll" then
|
2013-01-08 10:57:18 +00:00
|
|
|
self:goto(entry.xpointer, nil, "xpointer")
|
|
|
|
else
|
|
|
|
self:goto(entry.page, nil, "xpage")
|
|
|
|
end
|
2012-04-07 14:55:56 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function CREReader:nextView()
|
2013-01-08 10:57:18 +00:00
|
|
|
if self.view_mode == "scroll" then
|
|
|
|
self.show_overlap = -self.pan_overlap_vertical
|
|
|
|
return self.pos + self.view_pan_step - self.pan_overlap_vertical
|
|
|
|
else
|
|
|
|
return self.pageno + ((G_width > G_height) and 2 or 1)
|
|
|
|
end
|
2012-04-07 14:55:56 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function CREReader:prevView()
|
2013-01-08 10:57:18 +00:00
|
|
|
if self.view_mode == "scroll" then
|
|
|
|
self.show_overlap = self.pan_overlap_vertical
|
|
|
|
return self.pos - self.view_pan_step + self.pan_overlap_vertical
|
|
|
|
else
|
|
|
|
return self.pageno - 1
|
|
|
|
end
|
2012-04-07 14:55:56 +00:00
|
|
|
end
|
|
|
|
|
2012-12-20 22:12:32 +00:00
|
|
|
function CREReader:screenRotate(orien)
|
|
|
|
local prev_xpointer = self.doc:getXPointer()
|
|
|
|
Screen:screenRotate(orien)
|
|
|
|
G_width, G_height = fb:getSize()
|
|
|
|
self:goto(prev_xpointer, nil, "xpointer")
|
|
|
|
self.pos = self.doc:getCurrentPos()
|
|
|
|
if G_width > G_height then
|
|
|
|
-- in landscape mode, crengine will render in two column mode
|
|
|
|
self.view_pan_step = G_height * 2
|
|
|
|
else
|
|
|
|
self.view_pan_step = G_height
|
|
|
|
end
|
2013-01-08 10:57:18 +00:00
|
|
|
self.toc = nil
|
2012-12-20 22:12:32 +00:00
|
|
|
end
|
|
|
|
|
2012-04-07 14:55:56 +00:00
|
|
|
----------------------------------------------------
|
2012-04-18 16:04:41 +00:00
|
|
|
-- jump history related methods
|
2012-04-07 14:55:56 +00:00
|
|
|
----------------------------------------------------
|
|
|
|
function CREReader:isSamePage(p1, p2)
|
|
|
|
return self.doc:getPageFromXPointer(p1) == self.doc:getPageFromXPointer(p2)
|
2012-03-28 16:16:00 +00:00
|
|
|
end
|
|
|
|
|
2012-04-18 15:54:17 +00:00
|
|
|
function CREReader:showJumpHist()
|
2012-04-07 14:55:56 +00:00
|
|
|
local menu_items = {}
|
2012-04-18 15:54:17 +00:00
|
|
|
for k,v in ipairs(self.jump_history) do
|
|
|
|
if k == self.jump_history.cur then
|
|
|
|
cur_sign = "*(Cur) "
|
|
|
|
else
|
|
|
|
cur_sign = ""
|
|
|
|
end
|
2012-04-07 14:55:56 +00:00
|
|
|
table.insert(menu_items,
|
2012-04-18 15:54:17 +00:00
|
|
|
cur_sign..v.datetime.." -> Page "
|
|
|
|
..self.doc:getPageFromXPointer(v.page).." "..v.notes)
|
2012-04-07 14:55:56 +00:00
|
|
|
end
|
2012-04-17 06:39:17 +00:00
|
|
|
|
|
|
|
if #menu_items == 0 then
|
2012-11-15 13:35:41 +00:00
|
|
|
InfoMessage:inform("No jump history found ", DINFO_DELAY, 1, MSG_WARN)
|
2012-04-07 14:55:56 +00:00
|
|
|
else
|
2012-04-18 15:54:17 +00:00
|
|
|
-- if cur points to head, draw entry for current page
|
|
|
|
if self.jump_history.cur > #self.jump_history then
|
|
|
|
table.insert(menu_items,
|
|
|
|
"Current Page "..self.pageno)
|
|
|
|
end
|
|
|
|
|
2012-04-17 06:39:17 +00:00
|
|
|
jump_menu = SelectMenu:new{
|
2012-04-18 15:54:17 +00:00
|
|
|
menu_title = "Jump History",
|
2012-04-17 06:39:17 +00:00
|
|
|
item_array = menu_items,
|
|
|
|
}
|
2012-08-31 17:41:36 +00:00
|
|
|
item_no = jump_menu:choose(0, G_height)
|
2012-04-18 15:54:17 +00:00
|
|
|
if item_no and item_no <= #self.jump_history then
|
|
|
|
local jump_item = self.jump_history[item_no]
|
|
|
|
self.jump_history.cur = item_no
|
|
|
|
self:goto(jump_item.page, true, "xpointer")
|
|
|
|
else
|
|
|
|
self:redrawCurrentPage()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
----------------------------------------------------
|
|
|
|
-- bookmarks related methods
|
|
|
|
----------------------------------------------------
|
2012-06-06 08:21:25 +00:00
|
|
|
function CREReader:isBookmarkInSequence(a, b)
|
|
|
|
return self.doc:getPosFromXPointer(a.page) < self.doc:getPosFromXPointer(b.page)
|
|
|
|
end
|
|
|
|
|
|
|
|
function CREReader:nextBookMarkedPage()
|
|
|
|
for k,v in ipairs(self.bookmarks) do
|
|
|
|
if self.pos < self.doc:getPosFromXPointer(v.page) then
|
|
|
|
return v
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
|
|
|
function CREReader:prevBookMarkedPage()
|
|
|
|
local pre_item = nil
|
|
|
|
for k,v in ipairs(self.bookmarks) do
|
2012-06-06 11:52:41 +00:00
|
|
|
if self.pos <= self.doc:getPosFromXPointer(v.page) then
|
2012-06-06 12:16:40 +00:00
|
|
|
if not pre_item then
|
|
|
|
break
|
|
|
|
elseif self.doc:getPosFromXPointer(pre_item.page) < self.pos then
|
2012-06-06 08:21:25 +00:00
|
|
|
return pre_item
|
|
|
|
end
|
|
|
|
end
|
|
|
|
pre_item = v
|
|
|
|
end
|
2012-06-06 12:16:40 +00:00
|
|
|
return pre_item
|
2012-06-06 08:21:25 +00:00
|
|
|
end
|
|
|
|
|
2012-04-18 15:54:17 +00:00
|
|
|
function CREReader:showBookMarks()
|
|
|
|
local menu_items = {}
|
2012-11-20 09:48:56 +00:00
|
|
|
local ret_code, item_no = -1, -1
|
|
|
|
|
2012-04-18 15:54:17 +00:00
|
|
|
-- build menu items
|
|
|
|
for k,v in ipairs(self.bookmarks) do
|
|
|
|
table.insert(menu_items,
|
|
|
|
"Page "..self.doc:getPageFromXPointer(v.page)
|
|
|
|
.." "..v.notes.." @ "..v.datetime)
|
|
|
|
end
|
|
|
|
if #menu_items == 0 then
|
2012-11-20 09:48:56 +00:00
|
|
|
return InfoMessage:inform("No bookmark found ", DINFO_DELAY, 1, MSG_WARN)
|
|
|
|
end
|
|
|
|
while true do
|
2012-08-31 17:41:36 +00:00
|
|
|
local bkmk_menu = SelectMenu:new{
|
2012-11-20 09:48:56 +00:00
|
|
|
menu_title = "Bookmarks ("..tostring(#menu_items).." items)",
|
2012-04-18 15:54:17 +00:00
|
|
|
item_array = menu_items,
|
2012-11-20 09:48:56 +00:00
|
|
|
deletable = true,
|
2012-04-18 15:54:17 +00:00
|
|
|
}
|
2012-11-20 09:48:56 +00:00
|
|
|
ret_code, item_no = bkmk_menu:choose(0, G_height)
|
|
|
|
if ret_code then -- normal item selection
|
|
|
|
return self:goto(self.bookmarks[ret_code].page, nil, "xpointer")
|
|
|
|
elseif item_no then -- delete item
|
|
|
|
table.remove(menu_items, item_no)
|
|
|
|
table.remove(self.bookmarks, item_no)
|
|
|
|
if #menu_items == 0 then
|
|
|
|
return self:redrawCurrentPage()
|
|
|
|
end
|
|
|
|
else -- return via Back
|
|
|
|
return self:redrawCurrentPage()
|
2012-04-17 06:39:17 +00:00
|
|
|
end
|
2012-04-07 14:55:56 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
----------------------------------------------------
|
|
|
|
-- TOC related methods
|
|
|
|
----------------------------------------------------
|
2012-04-19 01:49:46 +00:00
|
|
|
function CREReader:getTocTitleByPage(page_or_xpoint)
|
|
|
|
local page = 1
|
|
|
|
-- tranform xpointer to page
|
|
|
|
if type(page_or_xpoint) == "string" then
|
|
|
|
page = self.doc:getPageFromXPointer(page_or_xpoint)
|
|
|
|
else
|
|
|
|
page = page_or_xpoint
|
|
|
|
end
|
|
|
|
return self:_getTocTitleByPage(page)
|
|
|
|
end
|
|
|
|
|
2012-04-07 14:55:56 +00:00
|
|
|
function CREReader:getTocTitleOfCurrentPage()
|
2012-04-19 02:23:39 +00:00
|
|
|
return self:getTocTitleByPage(self.doc:getXPointer())
|
2012-04-07 14:55:56 +00:00
|
|
|
end
|
|
|
|
|
2012-09-01 10:01:17 +00:00
|
|
|
--[[ function to scroll chapters without calling TOC-menu,
|
2012-08-31 17:41:36 +00:00
|
|
|
direction is either +1 (next chapter) or -1 (previous one).
|
|
|
|
Jump over several chapters is principally possible when direction > 1 ]]
|
|
|
|
|
|
|
|
function CREReader:gotoPrevNextTocEntry(direction)
|
|
|
|
if not self.toc then
|
|
|
|
self:fillToc()
|
|
|
|
end
|
|
|
|
if #self.toc == 0 then
|
2012-11-15 13:35:41 +00:00
|
|
|
InfoMessage:inform("No Table of Contents ", DINFO_DELAY, 1, MSG_WARN)
|
2012-08-31 17:41:36 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
-- search for current TOC-entry
|
|
|
|
local item_no = 0
|
2013-01-08 10:57:18 +00:00
|
|
|
local right_pageno = self.pageno
|
|
|
|
if self.view_mode == "page" and G_width > G_height then
|
|
|
|
right_pageno = right_pageno + 1
|
|
|
|
end
|
2012-08-31 17:41:36 +00:00
|
|
|
for k,v in ipairs(self.toc) do
|
2013-01-08 10:57:18 +00:00
|
|
|
if v.page <=right_pageno then
|
2012-08-31 17:41:36 +00:00
|
|
|
item_no = item_no + 1
|
|
|
|
else
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
2012-09-01 10:01:17 +00:00
|
|
|
-- minor correction when current page is not the page opening current chapter
|
2013-01-08 10:57:18 +00:00
|
|
|
if right_pageno > self.toc[item_no].page and direction < 0 then
|
2012-08-31 17:41:36 +00:00
|
|
|
direction = direction + 1
|
|
|
|
end
|
|
|
|
-- define the jump target
|
|
|
|
item_no = item_no + direction
|
|
|
|
if item_no > #self.toc then -- jump to last page
|
2013-01-08 10:57:18 +00:00
|
|
|
if self.view_mode == "scroll" then
|
|
|
|
self:goto(self.doc:getFullHeight()-G_height)
|
|
|
|
else
|
|
|
|
self:goto(self.doc:getPages())
|
|
|
|
end
|
2012-08-31 17:41:36 +00:00
|
|
|
elseif item_no > 0 then
|
|
|
|
self:gotoTocEntry(self.toc[item_no])
|
|
|
|
else
|
|
|
|
self:goto(0) -- jump to first page
|
|
|
|
end
|
|
|
|
end
|
2012-04-07 14:55:56 +00:00
|
|
|
|
|
|
|
----------------------------------------------------
|
|
|
|
-- menu related methods
|
|
|
|
----------------------------------------------------
|
2012-03-30 06:00:41 +00:00
|
|
|
-- used in CREReader:showMenu()
|
|
|
|
function CREReader:_drawReadingInfo()
|
2012-11-01 10:58:17 +00:00
|
|
|
local width = G_width
|
2012-03-31 12:22:22 +00:00
|
|
|
local load_percent = self.percent/100
|
2012-11-01 10:58:17 +00:00
|
|
|
local rss, data, stack, lib, totalvm = memUsage()
|
|
|
|
local face = Font:getFace("rifont", 20)
|
2012-03-29 10:17:32 +00:00
|
|
|
|
2012-11-01 10:58:17 +00:00
|
|
|
-- display page number, date and memory stats at the top
|
|
|
|
fb.bb:paintRect(0, 0, width, 40+6*2, 0)
|
|
|
|
renderUtf8Text(fb.bb, 10, 15+6, face, "p."..self.pageno.."/"..self.doc:getPages(), true)
|
|
|
|
local txt = os.date("%a %d %b %Y %T").." ["..BatteryLevel().."]"
|
|
|
|
local w = sizeUtf8Text(0, width, face, txt, true).x
|
|
|
|
renderUtf8Text(fb.bb, width - w - 10, 15+6, face, txt, true)
|
|
|
|
renderUtf8Text(fb.bb, 10, 15+6+22, face,
|
|
|
|
"RSS:"..rss.." DAT:"..data.." STK:"..stack.." LIB:"..lib.." TOT:"..totalvm.."k", true)
|
|
|
|
|
|
|
|
-- display reading progress at the bottom
|
|
|
|
local ypos = G_height - 50
|
|
|
|
fb.bb:paintRect(0, ypos, width, 50, 0)
|
2012-03-29 10:17:32 +00:00
|
|
|
|
|
|
|
ypos = ypos + 15
|
2012-05-19 10:59:38 +00:00
|
|
|
|
2012-04-07 14:55:56 +00:00
|
|
|
local cur_section = self:getTocTitleOfCurrentPage()
|
2012-03-29 10:17:32 +00:00
|
|
|
if cur_section ~= "" then
|
2012-11-01 10:58:17 +00:00
|
|
|
cur_section = " Sec: "..cur_section
|
2012-03-29 10:17:32 +00:00
|
|
|
end
|
2012-11-01 10:58:17 +00:00
|
|
|
local footer = load_percent.."%"..cur_section
|
2012-05-17 09:25:20 +00:00
|
|
|
if sizeUtf8Text(10, fb.bb:getWidth(), face, footer, true).x < (fb.bb:getWidth() - 20) then
|
|
|
|
renderUtf8Text(fb.bb, 10, ypos+6, face, footer, true)
|
|
|
|
else
|
|
|
|
local gapx = sizeUtf8Text(10, fb.bb:getWidth(), face, "...", true).x
|
|
|
|
gapx = 10 + renderUtf8TextWidth(fb.bb, 10, ypos+6, face, footer, true, fb.bb:getWidth() - 30 - gapx).x
|
|
|
|
renderUtf8Text(fb.bb, gapx, ypos+6, face, "...", true)
|
|
|
|
end
|
2012-03-29 10:17:32 +00:00
|
|
|
ypos = ypos + 15
|
2012-11-01 10:58:17 +00:00
|
|
|
blitbuffer.progressBar(fb.bb, 10, ypos, width - 20, 15, 5, 4, load_percent/100, 8)
|
2012-03-28 16:16:00 +00:00
|
|
|
end
|
|
|
|
|
2012-09-22 17:33:09 +00:00
|
|
|
function CREReader:showMenu()
|
2012-09-22 08:40:13 +00:00
|
|
|
self:_drawReadingInfo()
|
|
|
|
fb:refresh(1)
|
|
|
|
while true do
|
|
|
|
local ev = input.saveWaitForEvent()
|
|
|
|
ev.code = adjustKeyEvents(ev)
|
|
|
|
if ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_PRESS then
|
|
|
|
if ev.code == KEY_BACK or ev.code == KEY_MENU then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-03-30 04:06:33 +00:00
|
|
|
function CREReader:adjustCreReaderCommands()
|
2012-04-06 12:13:46 +00:00
|
|
|
self.commands:delGroup("[joypad]")
|
2012-10-15 20:11:19 +00:00
|
|
|
self.commands:delGroup(MOD_ALT.."H/J")
|
2012-03-30 04:06:33 +00:00
|
|
|
self.commands:del(KEY_G, nil, "G")
|
2012-04-13 04:46:33 +00:00
|
|
|
self.commands:del(KEY_J, MOD_SHIFT, "J")
|
|
|
|
self.commands:del(KEY_K, MOD_SHIFT, "K")
|
2012-03-30 04:06:33 +00:00
|
|
|
self.commands:del(KEY_Z, nil, "Z")
|
|
|
|
self.commands:del(KEY_Z, MOD_SHIFT, "Z")
|
|
|
|
self.commands:del(KEY_Z, MOD_ALT, "Z")
|
|
|
|
self.commands:del(KEY_A, nil, "A")
|
|
|
|
self.commands:del(KEY_A, MOD_SHIFT, "A")
|
|
|
|
self.commands:del(KEY_A, MOD_ALT, "A")
|
|
|
|
self.commands:del(KEY_S, nil, "S")
|
|
|
|
self.commands:del(KEY_S, MOD_SHIFT, "S")
|
|
|
|
self.commands:del(KEY_S, MOD_ALT, "S")
|
|
|
|
self.commands:del(KEY_D, nil, "D")
|
|
|
|
self.commands:del(KEY_D, MOD_SHIFT, "D")
|
|
|
|
self.commands:del(KEY_D, MOD_ALT, "D")
|
2012-04-27 03:18:59 +00:00
|
|
|
self.commands:del(KEY_X, nil, "X")
|
2012-03-30 04:06:33 +00:00
|
|
|
self.commands:del(KEY_F, MOD_SHIFT, "F")
|
|
|
|
self.commands:del(KEY_F, MOD_ALT, "F")
|
2012-08-31 17:41:36 +00:00
|
|
|
self.commands:del(KEY_N, nil, "N")
|
|
|
|
self.commands:del(KEY_N, MOD_SHIFT, "N")
|
2012-10-15 10:45:30 +00:00
|
|
|
self.commands:del(KEY_X, MOD_SHIFT, "X")
|
2012-10-13 13:12:06 +00:00
|
|
|
self.commands:del(KEY_L, MOD_SHIFT, "L")
|
2012-09-01 10:01:17 +00:00
|
|
|
self.commands:del(KEY_M, nil, "M")
|
2012-11-01 17:23:38 +00:00
|
|
|
self.commands:del(KEY_U, nil,"U")
|
2012-10-31 20:45:23 +00:00
|
|
|
self.commands:del(KEY_C, nil, "C")
|
2012-11-08 23:58:40 +00:00
|
|
|
self.commands:del(KEY_P, nil, "P")
|
2013-01-08 10:57:18 +00:00
|
|
|
|
2012-08-31 17:41:36 +00:00
|
|
|
-- CCW-rotation
|
|
|
|
self.commands:add(KEY_K, nil, "K",
|
|
|
|
"rotate screen counterclockwise",
|
|
|
|
function(self)
|
2012-12-20 22:12:32 +00:00
|
|
|
self:screenRotate("anticlockwise")
|
2013-01-12 07:16:45 +00:00
|
|
|
self.toc = nil
|
2012-08-31 17:41:36 +00:00
|
|
|
end
|
|
|
|
)
|
|
|
|
-- CW-rotation
|
|
|
|
self.commands:add(KEY_J, nil, "J",
|
|
|
|
"rotate screen clockwise",
|
|
|
|
function(self)
|
2012-12-20 22:12:32 +00:00
|
|
|
self:screenRotate("clockwise")
|
2013-01-12 07:16:45 +00:00
|
|
|
self.toc = nil
|
2012-08-31 17:41:36 +00:00
|
|
|
end
|
|
|
|
)
|
|
|
|
-- navigate between chapters by Shift+Up & Shift-Down
|
|
|
|
self.commands:addGroup(MOD_SHIFT.."up/down",{
|
|
|
|
Keydef:new(KEY_FW_UP,MOD_SHIFT), Keydef:new(KEY_FW_DOWN,MOD_SHIFT)},
|
|
|
|
"scroll to previous/next chapter",
|
|
|
|
function(self)
|
2013-01-08 10:57:18 +00:00
|
|
|
if keydef.keycode == KEY_FW_UP then
|
|
|
|
local toc_no = -1
|
|
|
|
if G_width > G_height and G_width > G_height then
|
|
|
|
for k,v in ipairs(self.toc) do
|
|
|
|
if v.page == self.pageno then
|
|
|
|
toc_no = -2
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
self:gotoPrevNextTocEntry(toc_no)
|
|
|
|
else
|
|
|
|
self:gotoPrevNextTocEntry(1)
|
|
|
|
end
|
2012-08-31 17:41:36 +00:00
|
|
|
end
|
|
|
|
)
|
|
|
|
-- fast navigation by Shift+Left & Shift-Right
|
|
|
|
local scrollpages = 10
|
|
|
|
self.commands:addGroup(MOD_SHIFT.."left/right",
|
|
|
|
{Keydef:new(KEY_FW_LEFT,MOD_SHIFT),Keydef:new(KEY_FW_RIGHT,MOD_SHIFT)},
|
|
|
|
"scroll "..scrollpages.." pages backwards/forward",
|
|
|
|
function(self)
|
2013-01-08 10:57:18 +00:00
|
|
|
if self.view_mode == "scroll" then
|
|
|
|
if keydef.keycode == KEY_FW_LEFT then
|
|
|
|
self:goto(math.max(0, self.pos - scrollpages*G_height))
|
|
|
|
else
|
|
|
|
self:goto(math.min(self.pos + scrollpages*G_height, self.doc:getFullHeight()-G_height))
|
|
|
|
end
|
2012-08-31 17:41:36 +00:00
|
|
|
else
|
2013-01-08 10:57:18 +00:00
|
|
|
if keydef.keycode == KEY_FW_LEFT then
|
|
|
|
self:goto(math.max(0, self.pageno - scrollpages))
|
|
|
|
else
|
|
|
|
self:goto(math.min(self.pageno + scrollpages, self.doc:getPages()))
|
|
|
|
end
|
2012-08-31 17:41:36 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
)
|
2013-01-08 10:57:18 +00:00
|
|
|
|
2012-04-25 06:08:33 +00:00
|
|
|
self.commands:addGroup(MOD_SHIFT.."< >",{
|
|
|
|
Keydef:new(KEY_PGBCK,MOD_SHIFT),Keydef:new(KEY_PGFWD,MOD_SHIFT),
|
|
|
|
Keydef:new(KEY_LPGBCK,MOD_SHIFT),Keydef:new(KEY_LPGFWD,MOD_SHIFT)},
|
2012-06-06 12:43:11 +00:00
|
|
|
"increase/decrease font size",
|
|
|
|
function(self)
|
|
|
|
local delta = 1
|
2012-10-05 09:59:37 +00:00
|
|
|
local change = "Increasing"
|
2012-06-06 12:43:11 +00:00
|
|
|
if keydef.keycode == KEY_PGBCK or keydef.keycode == KEY_LPGBCK then
|
2012-10-05 09:59:37 +00:00
|
|
|
delta = -1
|
|
|
|
change = "Decreasing"
|
2012-04-13 22:38:18 +00:00
|
|
|
end
|
2012-06-06 12:43:11 +00:00
|
|
|
self.font_zoom = self.font_zoom + delta
|
2012-11-15 13:35:41 +00:00
|
|
|
InfoMessage:inform(change.." font size to "..self.font_zoom..". ", DINFO_NODELAY, 1, MSG_AUX)
|
2012-08-31 17:41:36 +00:00
|
|
|
Debug("font zoomed to", self.font_zoom)
|
|
|
|
local prev_xpointer = self.doc:getXPointer()
|
2012-06-06 12:43:11 +00:00
|
|
|
self.doc:zoomFont(delta)
|
2013-01-12 07:16:45 +00:00
|
|
|
self.toc = nil
|
2012-08-31 17:41:36 +00:00
|
|
|
self:goto(prev_xpointer, nil, "xpointer")
|
2012-04-13 22:38:18 +00:00
|
|
|
end
|
|
|
|
)
|
2012-04-25 06:08:33 +00:00
|
|
|
self.commands:addGroup(MOD_ALT.."< >",{
|
|
|
|
Keydef:new(KEY_PGBCK,MOD_ALT),Keydef:new(KEY_PGFWD,MOD_ALT),
|
|
|
|
Keydef:new(KEY_LPGBCK,MOD_ALT),Keydef:new(KEY_LPGFWD,MOD_ALT)},
|
|
|
|
"increase/decrease line spacing",
|
2012-04-20 02:00:20 +00:00
|
|
|
function(self)
|
2012-04-25 06:08:33 +00:00
|
|
|
if keydef.keycode == KEY_PGBCK or keydef.keycode == KEY_LPGBCK then
|
|
|
|
self.line_space_percent = self.line_space_percent - 10
|
2012-05-19 10:59:38 +00:00
|
|
|
self.line_space_percent = math.max(self.line_space_percent, 80)
|
2012-04-25 06:08:33 +00:00
|
|
|
else
|
|
|
|
self.line_space_percent = self.line_space_percent + 10
|
2012-05-19 10:59:38 +00:00
|
|
|
self.line_space_percent = math.min(self.line_space_percent, 200)
|
2012-04-13 22:38:18 +00:00
|
|
|
end
|
2012-11-15 13:35:41 +00:00
|
|
|
InfoMessage:inform("Changing line space to "..self.line_space_percent.."% ", DINFO_NODELAY, 1, MSG_AUX)
|
2012-06-03 22:49:23 +00:00
|
|
|
Debug("line spacing set to", self.line_space_percent)
|
2012-08-31 17:41:36 +00:00
|
|
|
local prev_xpointer = self.doc:getXPointer()
|
2012-04-20 02:00:20 +00:00
|
|
|
self.doc:setDefaultInterlineSpace(self.line_space_percent)
|
2013-01-12 07:16:45 +00:00
|
|
|
self.toc = nil
|
2012-08-31 17:41:36 +00:00
|
|
|
self:goto(prev_xpointer, nil, "xpointer")
|
2012-03-30 04:31:09 +00:00
|
|
|
end
|
|
|
|
)
|
2012-03-30 04:38:41 +00:00
|
|
|
local numeric_keydefs = {}
|
2012-05-28 17:19:21 +00:00
|
|
|
for i=1,10 do
|
|
|
|
numeric_keydefs[i]=Keydef:new(KEY_1+i-1, nil, tostring(i%10))
|
2012-03-30 04:38:41 +00:00
|
|
|
end
|
2012-10-05 09:59:37 +00:00
|
|
|
self.commands:addGroup("[1, 2 .. 9, 0]",numeric_keydefs,
|
|
|
|
"jump to 0%, 10% .. 90%, 100% of document",
|
2012-04-20 02:00:20 +00:00
|
|
|
function(self, keydef)
|
2012-06-03 22:49:23 +00:00
|
|
|
Debug('jump to position: '..
|
2012-04-20 02:00:20 +00:00
|
|
|
math.floor(self.doc:getFullHeight()*(keydef.keycode-KEY_1)/9)..
|
|
|
|
'/'..self.doc:getFullHeight())
|
2013-01-08 10:57:18 +00:00
|
|
|
if self.view_mode == "scroll" then
|
|
|
|
self:goto(math.floor(self.doc:getFullHeight()*(keydef.keycode-KEY_1)/9))
|
|
|
|
else
|
|
|
|
self:goto(math.floor(self.doc:getPages()*(keydef.keycode-KEY_1)/9))
|
|
|
|
end
|
2012-03-30 04:38:41 +00:00
|
|
|
end
|
|
|
|
)
|
2012-06-02 22:39:17 +00:00
|
|
|
self.commands:add(KEY_G,nil,"G",
|
|
|
|
"open 'go to position' input box",
|
|
|
|
function(unireader)
|
|
|
|
local height = self.doc:getFullHeight()
|
|
|
|
local position = NumInputBox:input(G_height-100, 100,
|
|
|
|
"Position in percent:", "current: "..math.floor((self.pos / height)*100), true)
|
|
|
|
-- convert string to number
|
|
|
|
if position and pcall(function () position = position + 0 end) then
|
|
|
|
if position >= 0 and position <= 100 then
|
2013-01-11 06:14:31 +00:00
|
|
|
if self.view_mode == "page" then
|
|
|
|
self:goto(math.floor(self.doc:getPages() * position / 100))
|
|
|
|
else
|
|
|
|
self:goto(math.floor(height * position / 100))
|
|
|
|
end
|
2012-06-02 22:39:17 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
self:redrawCurrentPage()
|
|
|
|
end
|
|
|
|
)
|
2013-01-08 10:57:18 +00:00
|
|
|
self.commands:add(KEY_F, nil, "F",
|
2012-04-16 19:56:16 +00:00
|
|
|
"change document font",
|
2012-04-20 02:00:20 +00:00
|
|
|
function(self)
|
2012-04-06 10:05:54 +00:00
|
|
|
local face_list = cre.getFontFaces()
|
2013-01-08 10:57:18 +00:00
|
|
|
-- define the current font in face_list
|
2012-05-19 10:59:38 +00:00
|
|
|
local item_no = 0
|
2013-01-08 10:57:18 +00:00
|
|
|
while face_list[item_no] ~= self.font_face and item_no < #face_list do
|
|
|
|
item_no = item_no + 1
|
2012-05-19 10:59:38 +00:00
|
|
|
end
|
2012-04-06 10:05:54 +00:00
|
|
|
local fonts_menu = SelectMenu:new{
|
2012-12-21 18:24:52 +00:00
|
|
|
menu_title = "Text Font",
|
2013-01-08 10:57:18 +00:00
|
|
|
item_array = face_list,
|
2012-05-19 10:59:38 +00:00
|
|
|
current_entry = item_no - 1,
|
2012-04-06 10:05:54 +00:00
|
|
|
}
|
2012-05-28 17:19:21 +00:00
|
|
|
item_no = fonts_menu:choose(0, G_height)
|
2012-08-31 17:41:36 +00:00
|
|
|
local prev_xpointer = self.doc:getXPointer()
|
2012-04-06 10:05:54 +00:00
|
|
|
if item_no then
|
2012-08-31 17:41:36 +00:00
|
|
|
Debug(face_list[item_no])
|
2012-12-21 18:24:52 +00:00
|
|
|
InfoMessage:inform("Formatting with "..face_list[item_no].." ", DINFO_NODELAY, 1, MSG_AUX)
|
2012-04-20 02:00:20 +00:00
|
|
|
self.doc:setFontFace(face_list[item_no])
|
2012-04-06 11:11:18 +00:00
|
|
|
self.font_face = face_list[item_no]
|
2012-04-06 10:05:54 +00:00
|
|
|
end
|
2013-01-12 07:16:45 +00:00
|
|
|
self.toc = nil
|
2012-08-31 17:41:36 +00:00
|
|
|
self:goto(prev_xpointer, nil, "xpointer")
|
2012-04-06 10:05:54 +00:00
|
|
|
end
|
|
|
|
)
|
2012-12-21 18:24:52 +00:00
|
|
|
self.commands:add(KEY_H, MOD_SHIFT, "H",
|
|
|
|
"change header font",
|
|
|
|
function(self)
|
|
|
|
local face_list = cre.getFontFaces()
|
2013-01-08 10:57:18 +00:00
|
|
|
-- define the current font in face_list
|
2012-12-21 18:24:52 +00:00
|
|
|
local item_no = 0
|
2013-01-08 10:57:18 +00:00
|
|
|
while face_list[item_no] ~= self.header_font and item_no < #face_list do
|
|
|
|
item_no = item_no + 1
|
2012-12-21 18:24:52 +00:00
|
|
|
end
|
|
|
|
local fonts_menu = SelectMenu:new{
|
|
|
|
menu_title = "Header Font ",
|
2013-01-08 10:57:18 +00:00
|
|
|
item_array = face_list,
|
2012-12-21 18:24:52 +00:00
|
|
|
current_entry = item_no - 1,
|
|
|
|
}
|
|
|
|
item_no = fonts_menu:choose(0, G_height)
|
|
|
|
local prev_xpointer = self.doc:getXPointer()
|
|
|
|
if item_no then
|
|
|
|
Debug(face_list[item_no])
|
|
|
|
InfoMessage:inform("Formatting with "..face_list[item_no].." ", DINFO_NODELAY, 1, MSG_AUX)
|
|
|
|
self.header_font = face_list[item_no]
|
|
|
|
G_reader_settings:saveSetting("header_font", self.header_font)
|
|
|
|
self.doc:setHeaderFont(self.header_font)
|
|
|
|
end
|
2013-01-12 07:16:45 +00:00
|
|
|
self.toc = nil
|
2012-12-21 18:24:52 +00:00
|
|
|
self:goto(prev_xpointer, nil, "xpointer")
|
|
|
|
end
|
|
|
|
)
|
2012-06-02 21:51:55 +00:00
|
|
|
self.commands:add(KEY_F, MOD_SHIFT, "F",
|
|
|
|
"use document font as default font",
|
|
|
|
function(self)
|
2012-06-03 00:20:19 +00:00
|
|
|
self.default_font = self.font_face
|
2012-06-02 21:51:55 +00:00
|
|
|
G_reader_settings:saveSetting("cre_font", self.font_face)
|
2012-11-15 13:35:41 +00:00
|
|
|
InfoMessage:inform("Default document font set ", DINFO_DELAY, 1, MSG_WARN)
|
2012-06-02 21:51:55 +00:00
|
|
|
end
|
|
|
|
)
|
2012-04-06 10:05:54 +00:00
|
|
|
self.commands:add(KEY_F, MOD_ALT, "F",
|
2012-08-31 17:41:36 +00:00
|
|
|
"toggle font-weight: bold <> normal",
|
2012-04-20 02:00:20 +00:00
|
|
|
function(self)
|
2012-11-15 13:35:41 +00:00
|
|
|
InfoMessage:inform("Changing font-weight...", DINFO_NODELAY, 1, MSG_AUX)
|
2012-08-31 17:41:36 +00:00
|
|
|
local prev_xpointer = self.doc:getXPointer()
|
2012-04-20 02:00:20 +00:00
|
|
|
self.doc:toggleFontBolder()
|
2013-01-12 07:16:45 +00:00
|
|
|
self.toc = nil
|
2012-08-31 17:41:36 +00:00
|
|
|
self:goto(prev_xpointer, nil, "xpointer")
|
2012-04-06 10:05:54 +00:00
|
|
|
end
|
|
|
|
)
|
2012-04-18 15:54:17 +00:00
|
|
|
self.commands:add(KEY_B, MOD_ALT, "B",
|
2012-04-20 10:29:08 +00:00
|
|
|
"add bookmark to current page",
|
2012-04-20 02:00:20 +00:00
|
|
|
function(self)
|
|
|
|
ok = self:addBookmark(self.doc:getXPointer())
|
2012-04-18 15:54:17 +00:00
|
|
|
if not ok then
|
2012-11-19 20:07:47 +00:00
|
|
|
InfoMessage:drawTopMsg("Bookmark already exists")
|
2012-04-18 15:54:17 +00:00
|
|
|
else
|
2012-11-19 20:07:47 +00:00
|
|
|
InfoMessage:drawTopMsg("Bookmark added")
|
2012-04-18 15:54:17 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
)
|
2012-10-15 20:25:31 +00:00
|
|
|
self.commands:addGroup(MOD_ALT.."K/L",{
|
|
|
|
Keydef:new(KEY_K,MOD_ALT), Keydef:new(KEY_L,MOD_ALT)},
|
2012-10-14 18:26:12 +00:00
|
|
|
"Jump between bookmarks",
|
|
|
|
function(unireader,keydef)
|
2012-10-15 20:16:37 +00:00
|
|
|
local bm = nil
|
2012-10-15 20:25:31 +00:00
|
|
|
if keydef.keycode == KEY_K then
|
2012-10-14 18:26:12 +00:00
|
|
|
bm = self:prevBookMarkedPage()
|
|
|
|
else
|
|
|
|
bm = self:nextBookMarkedPage()
|
|
|
|
end
|
2012-10-14 23:34:55 +00:00
|
|
|
if bm then self:goto(bm.page, true, "xpointer") end
|
2012-10-14 18:26:12 +00:00
|
|
|
end)
|
2012-04-18 15:54:17 +00:00
|
|
|
self.commands:add(KEY_BACK, nil, "Back",
|
|
|
|
"go backward in jump history",
|
2012-04-20 02:00:20 +00:00
|
|
|
function(self)
|
2012-09-27 12:10:28 +00:00
|
|
|
local prev_jump_no = 0
|
|
|
|
if self.jump_history.cur > #self.jump_history then
|
|
|
|
-- if cur points to head, put current page in history
|
|
|
|
self:addJump(self.doc:getXPointer())
|
|
|
|
prev_jump_no = self.jump_history.cur - 2
|
|
|
|
else
|
|
|
|
prev_jump_no = self.jump_history.cur - 1
|
|
|
|
end
|
|
|
|
|
2012-04-18 15:54:17 +00:00
|
|
|
if prev_jump_no >= 1 then
|
2012-04-20 02:00:20 +00:00
|
|
|
self.jump_history.cur = prev_jump_no
|
|
|
|
self:goto(self.jump_history[prev_jump_no].page, true, "xpointer")
|
2012-04-18 15:54:17 +00:00
|
|
|
else
|
2012-11-15 13:35:41 +00:00
|
|
|
InfoMessage:inform("Already first jump ", DINFO_DELAY, 1, MSG_WARN)
|
2012-04-18 15:54:17 +00:00
|
|
|
end
|
2012-04-07 15:03:29 +00:00
|
|
|
end
|
|
|
|
)
|
2012-04-18 15:54:17 +00:00
|
|
|
self.commands:add(KEY_BACK, MOD_SHIFT, "Back",
|
|
|
|
"go forward in jump history",
|
2012-04-20 02:00:20 +00:00
|
|
|
function(self)
|
|
|
|
local next_jump_no = self.jump_history.cur + 1
|
2012-04-18 15:54:17 +00:00
|
|
|
if next_jump_no <= #self.jump_history then
|
2012-04-20 02:00:20 +00:00
|
|
|
self.jump_history.cur = next_jump_no
|
|
|
|
self:goto(self.jump_history[next_jump_no].page, true, "xpointer")
|
2012-04-18 15:54:17 +00:00
|
|
|
else
|
2012-11-15 13:35:41 +00:00
|
|
|
InfoMessage:inform("Already last jump ", DINFO_DELAY, 1, MSG_WARN)
|
2012-04-07 14:55:56 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
)
|
2012-04-21 08:08:25 +00:00
|
|
|
self.commands:addGroup("vol-/+",
|
|
|
|
{Keydef:new(KEY_VPLUS,nil), Keydef:new(KEY_VMINUS,nil)},
|
|
|
|
"decrease/increase gamma",
|
|
|
|
function(self, keydef)
|
|
|
|
local delta = 1
|
|
|
|
if keydef.keycode == KEY_VMINUS then
|
|
|
|
delta = -1
|
|
|
|
end
|
|
|
|
cre.setGammaIndex(self.gamma_index+delta)
|
2012-04-06 11:30:10 +00:00
|
|
|
self.gamma_index = cre.getGammaIndex()
|
2012-11-15 13:35:41 +00:00
|
|
|
InfoMessage:inform("Changing gamma to "..self.gamma_index..". ", DINFO_NODELAY, 1, MSG_AUX)
|
2012-04-20 02:00:20 +00:00
|
|
|
self:redrawCurrentPage()
|
2012-04-06 11:30:10 +00:00
|
|
|
end
|
|
|
|
)
|
2012-04-06 12:26:53 +00:00
|
|
|
self.commands:add(KEY_FW_UP, nil, "joypad up",
|
|
|
|
"pan "..self.shift_y.." pixels upwards",
|
2012-04-20 02:00:20 +00:00
|
|
|
function(self)
|
2013-01-08 10:57:18 +00:00
|
|
|
if self.view_mode == "scroll" then
|
|
|
|
self:goto(self.pos - self.shift_y)
|
|
|
|
end
|
2012-04-06 12:26:53 +00:00
|
|
|
end
|
|
|
|
)
|
|
|
|
self.commands:add(KEY_FW_DOWN, nil, "joypad down",
|
|
|
|
"pan "..self.shift_y.." pixels downwards",
|
2012-04-20 02:00:20 +00:00
|
|
|
function(self)
|
2013-01-08 10:57:18 +00:00
|
|
|
if self.view_mode == "scroll" then
|
|
|
|
self:goto(self.pos + self.shift_y)
|
|
|
|
end
|
2012-04-06 12:26:53 +00:00
|
|
|
end
|
|
|
|
)
|
2012-12-11 07:03:15 +00:00
|
|
|
self.commands:add(KEY_V, nil, "V",
|
2012-12-21 18:24:52 +00:00
|
|
|
"toggle view mode",
|
2012-12-11 07:03:15 +00:00
|
|
|
function(self)
|
2012-12-21 00:47:02 +00:00
|
|
|
local view_mode_code = self.PAGE_VIEW_MODE
|
2012-12-11 07:03:15 +00:00
|
|
|
if self.view_mode == "page" then
|
|
|
|
self.view_mode = "scroll"
|
2012-12-21 00:47:02 +00:00
|
|
|
view_mode_code = self.SCROLL_VIEW_MODE
|
2012-12-11 07:03:15 +00:00
|
|
|
else
|
|
|
|
self.view_mode = "page"
|
|
|
|
end
|
|
|
|
self.settings:saveSetting("view_mode", self.view_mode)
|
2012-12-21 00:47:02 +00:00
|
|
|
InfoMessage:inform("Changing to "..self.view_mode.." mode...", DINFO_DELAY, 1, MSG_AUX)
|
|
|
|
self.doc:setViewMode(view_mode_code)
|
2013-01-12 07:16:45 +00:00
|
|
|
self.toc = nil
|
2012-12-21 00:47:02 +00:00
|
|
|
self:redrawCurrentPage()
|
2012-12-11 07:03:15 +00:00
|
|
|
end
|
|
|
|
)
|
2012-03-30 04:06:33 +00:00
|
|
|
end
|
2012-08-28 18:49:11 +00:00
|
|
|
|
|
|
|
----------------------------------------------------
|
|
|
|
--- search
|
|
|
|
----------------------------------------------------
|
|
|
|
function CREReader:searchHighLight(search)
|
|
|
|
Debug("FIXME CreReader::searchHighLight", search)
|
|
|
|
|
2012-08-28 19:56:46 +00:00
|
|
|
if self.last_search == nil or self.last_search.search == nil then
|
2012-08-28 18:49:11 +00:00
|
|
|
self.last_search = {
|
|
|
|
search = "",
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2012-08-28 19:56:46 +00:00
|
|
|
local origin = 0 -- 0=current 1=next-last -1=first-current
|
|
|
|
if self.last_search.search == search then
|
|
|
|
origin = 1
|
|
|
|
end
|
|
|
|
|
2012-08-28 20:14:57 +00:00
|
|
|
local found, pos = self.doc:findText(
|
2012-08-28 18:49:11 +00:00
|
|
|
search,
|
2012-08-28 19:56:46 +00:00
|
|
|
origin,
|
2012-08-28 18:49:11 +00:00
|
|
|
0, -- reverse: boolean
|
2012-08-28 19:56:46 +00:00
|
|
|
1 -- caseInsensitive: boolean
|
2012-08-28 18:49:11 +00:00
|
|
|
)
|
|
|
|
|
2012-08-28 20:14:57 +00:00
|
|
|
if found then
|
2012-08-28 19:56:46 +00:00
|
|
|
self.pos = pos -- first metch position
|
|
|
|
self:redrawCurrentPage()
|
2012-11-15 13:35:41 +00:00
|
|
|
InfoMessage:inform( found.." hits '"..search.."' pos "..pos, DINFO_DELAY, 1, MSG_WARN)
|
2012-08-28 20:14:57 +00:00
|
|
|
else
|
2012-11-15 13:35:41 +00:00
|
|
|
InfoMessage:inform( "'"..search.."' not found in document ", DINFO_DELAY, 1, MSG_WARN)
|
2012-08-28 19:56:46 +00:00
|
|
|
end
|
2012-08-28 18:49:11 +00:00
|
|
|
|
|
|
|
self.last_search.search = search
|
|
|
|
end
|
2012-10-11 16:21:47 +00:00
|
|
|
|
|
|
|
----------------------------------------------------
|
|
|
|
--- page links
|
|
|
|
----------------------------------------------------
|
|
|
|
function CREReader:getPageLinks()
|
|
|
|
local links = self.doc:getPageLinks()
|
|
|
|
Debug("getPageLinks", links)
|
|
|
|
return links
|
|
|
|
end
|
|
|
|
|
|
|
|
function CREReader:clearSelection()
|
|
|
|
Debug("clearSelection")
|
|
|
|
self.doc:clearSelection()
|
|
|
|
end
|