2012-03-05 01:46:16 +00:00
|
|
|
require "keys"
|
|
|
|
require "settings"
|
|
|
|
require "selectmenu"
|
2012-03-10 09:28:54 +00:00
|
|
|
require "commands"
|
2012-03-13 21:51:25 +00:00
|
|
|
require "helppage"
|
2012-03-05 01:46:16 +00:00
|
|
|
|
|
|
|
UniReader = {
|
|
|
|
-- "constants":
|
|
|
|
ZOOM_BY_VALUE = 0,
|
|
|
|
ZOOM_FIT_TO_PAGE = -1,
|
|
|
|
ZOOM_FIT_TO_PAGE_WIDTH = -2,
|
|
|
|
ZOOM_FIT_TO_PAGE_HEIGHT = -3,
|
|
|
|
ZOOM_FIT_TO_CONTENT = -4,
|
|
|
|
ZOOM_FIT_TO_CONTENT_WIDTH = -5,
|
|
|
|
ZOOM_FIT_TO_CONTENT_HEIGHT = -6,
|
2012-03-07 13:44:59 +00:00
|
|
|
ZOOM_FIT_TO_CONTENT_WIDTH_PAN = -7,
|
|
|
|
--ZOOM_FIT_TO_CONTENT_HEIGHT_PAN = -8,
|
|
|
|
ZOOM_FIT_TO_CONTENT_HALF_WIDTH_MARGIN = -9,
|
|
|
|
ZOOM_FIT_TO_CONTENT_HALF_WIDTH = -10,
|
2012-03-05 01:46:16 +00:00
|
|
|
|
|
|
|
GAMMA_NO_GAMMA = 1.0,
|
|
|
|
|
|
|
|
-- framebuffer update policy state:
|
|
|
|
rcount = 5,
|
unireader: refresh frequency; zoommode-menu, etc.
1. Restored default value rcountmax=5; the function to make manual full screen refresh is no more silent; at first, it asks user to set a number of partial refreshes (rcountmax) and then performs full refresh. TODO: saving parameter 'rcountmax' in the global reader settings (or separately, for each document).
2. The hotkey 'R' and the respective function toggle_render_mode() for djvu-documents are moved to djvureader.
3. Added hotkey 'M' and the respective function that calls menu with zoom-modes. Probably, one needs to remove unappropriate items, like "Fit zoom to page" and, less probably, the hotkeys (A, S, D, F and ^A, ^S, ^D, ^F) to set zoom-mode directly.
2012-09-01 10:39:14 +00:00
|
|
|
rcountmax = 5,
|
2012-03-05 01:46:16 +00:00
|
|
|
|
|
|
|
-- zoom state:
|
|
|
|
globalzoom = 1.0,
|
|
|
|
globalzoom_orig = 1.0,
|
2012-04-21 04:14:35 +00:00
|
|
|
globalzoom_mode = -1, -- ZOOM_FIT_TO_PAGE
|
2012-03-05 01:46:16 +00:00
|
|
|
|
|
|
|
globalrotate = 0,
|
|
|
|
|
|
|
|
-- gamma setting:
|
|
|
|
globalgamma = 1.0, -- GAMMA_NO_GAMMA
|
|
|
|
|
2012-08-28 22:48:56 +00:00
|
|
|
-- DjVu page rendering mode (used in djvu.c:drawPage())
|
2012-08-30 15:11:37 +00:00
|
|
|
-- See comments in djvureader.lua:DJVUReader:select_render_mode()
|
2012-08-28 22:48:56 +00:00
|
|
|
render_mode = 0, -- COLOUR
|
2012-08-27 14:33:32 +00:00
|
|
|
|
2012-03-17 04:17:20 +00:00
|
|
|
-- cached tile size
|
2012-03-05 01:46:16 +00:00
|
|
|
fullwidth = 0,
|
|
|
|
fullheight = 0,
|
2012-03-17 04:17:20 +00:00
|
|
|
-- size of current page for current zoom level in pixels
|
|
|
|
cur_full_width = 0,
|
|
|
|
cur_full_height = 0,
|
2012-04-26 20:16:36 +00:00
|
|
|
cur_bbox = {}, -- current page bbox
|
2012-03-05 01:46:16 +00:00
|
|
|
offset_x = 0,
|
|
|
|
offset_y = 0,
|
2012-04-13 14:49:27 +00:00
|
|
|
dest_x = 0, -- real offset_x when it's smaller than screen, so it's centered
|
|
|
|
dest_y = 0,
|
2012-03-05 01:46:16 +00:00
|
|
|
min_offset_x = 0,
|
|
|
|
min_offset_y = 0,
|
2012-03-07 13:44:59 +00:00
|
|
|
content_top = 0, -- for ZOOM_FIT_TO_CONTENT_WIDTH_PAN (prevView)
|
2012-03-05 01:46:16 +00:00
|
|
|
|
|
|
|
-- set panning distance
|
|
|
|
shift_x = 100,
|
|
|
|
shift_y = 50,
|
storing rcountmax; user-configurable zoom step & pan steps, etc
1. In order to close issue #59, I've introduced user-configurable values for panning steps - for X- & Y-axis, separately. Now panning is called by pressing fiveway without mod_keys. When one presses Shift+FW, he/she changes panning steps in the following way - Shift-Left/Right = decrease / increase X-panning step (divide or multiply on factor 2), Shift-Up/Down = increase / decrease Y-panning step. The lowest value for panning steps is set 1. Both parameters, shift_x & shift_y, are saved to local settings (i.e. history file).
2. Manual zoom step was also made user-configurable. So, instead of two old zooming functions (with fixed 10% and 20%-steps), I made one function to zoom (Shift+<>), while the other (Alt+<>) changes the zoom step downto minimum 1%.
3. Fresh introduced function to change parameter rcountmax was added by storing rcountmax to both setting files - global settings & local ones (i.e. history file) - so that the rcountmax-priority (from low to high) is the following: default rcountmax=5 < its value in global settings < rcountmax stored for each concrete document.
3. Dirty, the extention-based hack to avoid reading not crengine-related parameters stored in history files. TODO: one has to finally introduce loadSpecialSettings() & readSpecialSettings() for PDFReader & DJVUReader and to store therein the reader-specific parameters (like globalgamma, bbox, globalzoom, globalzoom_mode; render_mode = for djvu-files only, etc.)
4. Some lua-code cosmetics (to make code more readable); for example: "self.pan_margin = settings:readSetting("pan_margin") or self.pan_margin" instead of
"local pan_margin = settings:readSetting("pan_margin")
if pan_margin then
self.pan_margin = pan_margin
end"
5. Fix for the today's tigran123 fix: issue #246 (details are included). Added InfoMessage:show() to inform most impatient users that the reader tries to redraw new zoo mode.
6. The fontface for the reading info (called by 'Menu') is restored to be in accordance with original intentions and with the same fontface in crereader.lua - namely, Font:getFace("rifont", 20)
7. Moved the exit hotkeys (Alt+Back & Home) to the end of hotkey list.
2012-09-03 19:23:06 +00:00
|
|
|
-- step to change zoom manually, default = 16%
|
|
|
|
step_manual_zoom = 16,
|
2012-03-05 01:46:16 +00:00
|
|
|
pan_by_page = false, -- using shift_[xy] or width/height
|
|
|
|
pan_x = 0, -- top-left offset of page when pan activated
|
|
|
|
pan_y = 0,
|
2012-04-26 12:13:32 +00:00
|
|
|
pan_margin = 5, -- horizontal margin for two-column zoom (in pixels)
|
2012-03-05 13:17:07 +00:00
|
|
|
pan_overlap_vertical = 30,
|
2012-04-09 13:06:05 +00:00
|
|
|
show_overlap = 0,
|
2012-03-05 01:46:16 +00:00
|
|
|
|
|
|
|
-- the document:
|
|
|
|
doc = nil,
|
|
|
|
-- the document's setting store:
|
|
|
|
settings = nil,
|
2012-03-10 09:28:54 +00:00
|
|
|
-- list of available commands:
|
2012-03-20 19:15:24 +00:00
|
|
|
commands = nil,
|
2012-03-05 01:46:16 +00:00
|
|
|
|
|
|
|
-- we will use this one often, so keep it "static":
|
2012-03-20 19:15:24 +00:00
|
|
|
nulldc = DrawContext.new(),
|
2012-03-05 01:46:16 +00:00
|
|
|
|
|
|
|
-- tile cache configuration:
|
|
|
|
cache_max_memsize = 1024*1024*5, -- 5MB tile cache
|
|
|
|
cache_max_ttl = 20, -- time to live
|
|
|
|
-- tile cache state:
|
|
|
|
cache_current_memsize = 0,
|
|
|
|
cache = {},
|
2012-03-31 11:23:51 +00:00
|
|
|
-- renderer cache size
|
|
|
|
cache_document_size = 1024*1024*8, -- FIXME random, needs testing
|
2012-03-12 23:02:49 +00:00
|
|
|
|
|
|
|
pagehash = nil,
|
|
|
|
|
2012-04-18 09:01:22 +00:00
|
|
|
-- we use array to simluate two stacks,
|
|
|
|
-- one for backwards, one for forwards
|
|
|
|
jump_history = {cur = 1},
|
|
|
|
bookmarks = {},
|
2012-03-21 02:37:18 +00:00
|
|
|
highlight = {},
|
2012-03-05 05:15:34 +00:00
|
|
|
toc = nil,
|
2012-09-14 08:08:47 +00:00
|
|
|
toc_expandable = false, -- if true then TOC contains expandable/collapsible items
|
2012-09-08 22:52:04 +00:00
|
|
|
toc_children = nil, -- each element is the list of children for each TOC node (nil if none)
|
|
|
|
toc_curitem = 0, -- points to the current location in TOC
|
|
|
|
toc_xview = nil, -- fully expanded (and marked with '+') view of TOC
|
|
|
|
toc_cview = nil, -- current view of TOC
|
|
|
|
toc_curidx_to_x = nil, -- current view to expanded view map
|
2012-03-06 22:18:52 +00:00
|
|
|
|
2012-03-06 23:26:56 +00:00
|
|
|
bbox = {}, -- override getUsedBBox
|
2012-08-26 14:19:51 +00:00
|
|
|
|
|
|
|
last_search = {}
|
2012-03-05 01:46:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function UniReader:new(o)
|
|
|
|
o = o or {}
|
|
|
|
setmetatable(o, self)
|
|
|
|
self.__index = self
|
|
|
|
return o
|
|
|
|
end
|
|
|
|
|
2012-03-23 07:51:48 +00:00
|
|
|
----------------------------------------------------
|
|
|
|
-- !!!!!!!!!!!!!!!!!!!!!!!!!
|
|
|
|
--
|
|
|
|
-- For a new specific reader,
|
2012-04-06 11:11:18 +00:00
|
|
|
-- you must always overwrite following method:
|
2012-03-23 07:51:48 +00:00
|
|
|
--
|
|
|
|
-- * self:open()
|
|
|
|
--
|
|
|
|
-- overwrite other methods if needed.
|
|
|
|
----------------------------------------------------
|
2012-03-05 01:46:16 +00:00
|
|
|
|
2012-04-06 11:11:18 +00:00
|
|
|
-- open a file
|
2012-03-31 12:09:50 +00:00
|
|
|
function UniReader:open(filename, cache_size)
|
2012-03-05 01:58:19 +00:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2012-03-05 01:46:16 +00:00
|
|
|
function UniReader:init()
|
2012-04-06 11:11:18 +00:00
|
|
|
-- initialize commands
|
2012-05-18 21:28:00 +00:00
|
|
|
InfoMessage:show("Registering fonts...", 1)
|
2012-04-06 11:11:18 +00:00
|
|
|
self:addAllCommands()
|
2012-03-05 01:46:16 +00:00
|
|
|
end
|
|
|
|
|
2012-04-12 03:23:22 +00:00
|
|
|
----------------------------------------------------
|
|
|
|
-- highlight support
|
|
|
|
----------------------------------------------------
|
2012-04-11 20:52:48 +00:00
|
|
|
|
2012-04-13 16:10:11 +00:00
|
|
|
function UniReader:screenOffset()
|
|
|
|
local x = self.dest_x
|
|
|
|
local y = self.dest_y
|
|
|
|
if self.offset_x < 0 then
|
|
|
|
x = x + self.offset_x
|
|
|
|
end
|
|
|
|
if self.offset_y < 0 then
|
|
|
|
y = y + self.offset_y
|
|
|
|
end
|
2012-06-03 22:49:23 +00:00
|
|
|
Debug("screenOffset", x, y)
|
2012-04-13 16:10:11 +00:00
|
|
|
return x,y
|
|
|
|
end
|
|
|
|
|
2012-03-23 07:51:48 +00:00
|
|
|
----------------------------------------------------
|
2012-04-12 03:34:24 +00:00
|
|
|
-- Given coordinates of four corners in original page
|
2012-04-12 03:23:22 +00:00
|
|
|
-- size and return coordinate of upper left conner in
|
|
|
|
-- zoomed page size with width and height.
|
2012-03-23 07:51:48 +00:00
|
|
|
----------------------------------------------------
|
2012-04-12 03:23:22 +00:00
|
|
|
function UniReader:zoomedRectCoordTransform(x0, y0, x1, y1)
|
2012-04-13 16:10:11 +00:00
|
|
|
local x,y = self:screenOffset()
|
2012-04-13 14:49:27 +00:00
|
|
|
return
|
|
|
|
x0 * self.globalzoom + x,
|
|
|
|
y0 * self.globalzoom + y,
|
2012-04-11 20:52:48 +00:00
|
|
|
(x1 - x0) * self.globalzoom,
|
|
|
|
(y1 - y0) * self.globalzoom
|
|
|
|
end
|
2012-03-26 12:25:44 +00:00
|
|
|
|
2012-04-29 12:23:13 +00:00
|
|
|
----------------------------------------------------
|
|
|
|
-- Given coordinates on the screen return positioni
|
|
|
|
-- in original page
|
|
|
|
----------------------------------------------------
|
|
|
|
function UniReader:screenToPageTransform(x, y)
|
|
|
|
local x_o,y_o = self:screenOffset()
|
|
|
|
local x_p,y_p =
|
|
|
|
( x - x_o ) / self.globalzoom,
|
|
|
|
( y - y_o ) / self.globalzoom
|
2012-06-03 22:49:23 +00:00
|
|
|
Debug("screenToPage", x,y, "offset", x_o,y_o, "page", x_p,y_p)
|
2012-04-29 12:23:13 +00:00
|
|
|
return x_p, y_p
|
|
|
|
end
|
|
|
|
|
2012-04-12 03:23:22 +00:00
|
|
|
----------------------------------------------------
|
2012-04-12 03:34:24 +00:00
|
|
|
-- Given coordinates of four corners in original page
|
|
|
|
-- size and return rectangular area in screen. You
|
2012-04-12 03:23:22 +00:00
|
|
|
-- might want to call this when you want to draw stuff
|
|
|
|
-- on screen.
|
|
|
|
--
|
2012-04-12 03:34:24 +00:00
|
|
|
-- NOTE: this method does not check whether given area
|
2012-04-12 03:23:22 +00:00
|
|
|
-- is can be shown in current screen. Make sure to check
|
2012-04-12 09:31:01 +00:00
|
|
|
-- with _isEntireWordInScreenRange() or _isWordInScreenRange()
|
|
|
|
-- before you want to draw on the returned area.
|
2012-04-12 03:23:22 +00:00
|
|
|
----------------------------------------------------
|
|
|
|
function UniReader:getRectInScreen(x0, y0, x1, y1)
|
|
|
|
x, y, w, h = self:zoomedRectCoordTransform(x0, y0, x1, y1)
|
2012-04-12 09:31:01 +00:00
|
|
|
if x < 0 then
|
|
|
|
w = w + x
|
|
|
|
x = 0
|
|
|
|
end
|
|
|
|
if y < 0 then
|
|
|
|
h = h + y
|
|
|
|
y = 0
|
|
|
|
end
|
|
|
|
if x + w > G_width then w = G_width - x end
|
|
|
|
if y + h > G_height then h = G_height - y end
|
|
|
|
return x, y, w, h
|
2012-04-12 03:23:22 +00:00
|
|
|
end
|
|
|
|
|
2012-04-21 04:14:35 +00:00
|
|
|
-- make sure at least part of the box can be seen in next/previous view
|
|
|
|
-- @FIXME only works in FIT_TO_CONTENT_WIDTH mode 21.04 2012 (houqp)
|
|
|
|
function UniReader:_isBoxInNextView(box)
|
|
|
|
return box.y1 * self.globalzoom > -self.offset_y + G_height
|
|
|
|
end
|
|
|
|
|
|
|
|
function UniReader:_isBoxInPrevView(box)
|
|
|
|
return box.y0 * self.globalzoom < -self.offset_y
|
|
|
|
end
|
|
|
|
|
2012-04-12 07:50:19 +00:00
|
|
|
-- make sure the whole word/line can be seen in screen
|
|
|
|
-- @TODO when not in FIT_TO_CONTENT_WIDTH mode,
|
|
|
|
-- self.offset_{x,y} might be negative. 12.04 2012 (houqp)
|
|
|
|
function UniReader:_isEntireLineInScreenHeightRange(l)
|
|
|
|
return (l ~= nil) and
|
|
|
|
(l.y0 * self.globalzoom) >= -self.offset_y
|
|
|
|
and (l.y1 * self.globalzoom) <= -self.offset_y + G_height
|
|
|
|
end
|
|
|
|
|
2012-04-11 20:52:48 +00:00
|
|
|
function UniReader:_isEntireWordInScreenRange(w)
|
|
|
|
return self:_isEntireWordInScreenHeightRange(w) and
|
|
|
|
self:_isEntireWordInScreenWidthRange(w)
|
2012-03-26 12:25:44 +00:00
|
|
|
end
|
|
|
|
|
2012-04-11 20:52:48 +00:00
|
|
|
function UniReader:_isEntireWordInScreenHeightRange(w)
|
|
|
|
return (w ~= nil) and
|
2012-04-12 07:50:19 +00:00
|
|
|
(w.y0 * self.globalzoom) >= -self.offset_y
|
|
|
|
and (w.y1 * self.globalzoom) <= -self.offset_y + G_height
|
2012-04-11 20:52:48 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function UniReader:_isEntireWordInScreenWidthRange(w)
|
|
|
|
return (w ~= nil) and
|
|
|
|
(w.x0 * self.globalzoom >= -self.offset_x) and
|
|
|
|
(w.x1 * self.globalzoom <= -self.offset_x + G_width)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- make sure at least part of the word can be seen in screen
|
|
|
|
function UniReader:_isWordInScreenRange(w)
|
2012-04-12 09:31:01 +00:00
|
|
|
if not w then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
is_entire_word_out_of_screen_height =
|
|
|
|
(w.y1 * self.globalzoom <= -self.offset_y)
|
|
|
|
or (w.y0 * self.globalzoom >= -self.offset_y + G_height)
|
|
|
|
|
|
|
|
is_entire_word_out_of_screen_width =
|
|
|
|
(w.x0 * self.globalzoom >= -self.offset_x + G_width
|
|
|
|
or w.x1 * self.globalzoom <= -self.offset_x)
|
|
|
|
|
|
|
|
return (not is_entire_word_out_of_screen_height) and
|
|
|
|
(not is_entire_word_out_of_screen_width)
|
2012-03-23 07:51:48 +00:00
|
|
|
end
|
|
|
|
|
2012-04-21 04:14:35 +00:00
|
|
|
function UniReader:_isWordInNextView(w)
|
|
|
|
return self:_isBoxInNextView(w)
|
|
|
|
end
|
|
|
|
|
|
|
|
function UniReader:_isLineInNextView(l)
|
|
|
|
return self:_isBoxInNextView(l)
|
|
|
|
end
|
|
|
|
|
|
|
|
function UniReader:_isLineInPrevView(l)
|
|
|
|
return self:_isBoxInPrevView(l)
|
|
|
|
end
|
|
|
|
|
2012-03-23 07:51:48 +00:00
|
|
|
function UniReader:toggleTextHighLight(word_list)
|
2012-04-11 20:52:48 +00:00
|
|
|
for _,text_item in ipairs(word_list) do
|
|
|
|
for _,line_item in ipairs(text_item) do
|
|
|
|
-- make sure that line is in screen range
|
2012-04-12 09:31:01 +00:00
|
|
|
if self:_isWordInScreenRange(line_item) then
|
2012-04-12 03:23:22 +00:00
|
|
|
local x, y, w, h = self:getRectInScreen(
|
2012-04-11 20:52:48 +00:00
|
|
|
line_item.x0, line_item.y0,
|
|
|
|
line_item.x1, line_item.y1)
|
|
|
|
-- slightly enlarge the highlight height
|
|
|
|
-- for better viewing experience
|
|
|
|
x = x
|
|
|
|
y = y - h * 0.1
|
|
|
|
w = w
|
|
|
|
h = h * 1.2
|
|
|
|
|
|
|
|
self.highlight.drawer = self.highlight.drawer or "underscore"
|
|
|
|
if self.highlight.drawer == "underscore" then
|
|
|
|
self.highlight.line_width = self.highlight.line_width or 2
|
|
|
|
self.highlight.line_color = self.highlight.line_color or 5
|
|
|
|
fb.bb:paintRect(x, y+h-1, w,
|
|
|
|
self.highlight.line_width,
|
|
|
|
self.highlight.line_color)
|
|
|
|
elseif self.highlight.drawer == "marker" then
|
|
|
|
fb.bb:invertRect(x, y, w, h)
|
|
|
|
end
|
2012-04-12 03:23:22 +00:00
|
|
|
end -- if isEntireWordInScreenHeightRange
|
|
|
|
end -- for line_item
|
|
|
|
end -- for text_item
|
2012-04-11 20:52:48 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function UniReader:_wordIterFromRange(t, l0, w0, l1, w1)
|
|
|
|
local i = l0
|
|
|
|
local j = w0 - 1
|
|
|
|
return function()
|
|
|
|
if i <= l1 then
|
|
|
|
-- if in line range, loop through lines
|
|
|
|
if i == l1 then
|
|
|
|
-- in last line
|
|
|
|
if j < w1 then
|
|
|
|
j = j + 1
|
|
|
|
else
|
|
|
|
-- out of range return nil
|
|
|
|
return nil, nil
|
|
|
|
end
|
|
|
|
else
|
|
|
|
if j < #t[i] then
|
|
|
|
j = j + 1
|
|
|
|
else
|
|
|
|
-- goto next line
|
|
|
|
i = i + 1
|
|
|
|
j = 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return i, j
|
|
|
|
end
|
2012-04-12 03:34:24 +00:00
|
|
|
end -- closure
|
2012-04-11 20:52:48 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function UniReader:_toggleWordHighLight(t, l, w)
|
2012-04-12 03:23:22 +00:00
|
|
|
x, y, w, h = self:getRectInScreen(t[l][w].x0, t[l].y0,
|
2012-04-11 20:52:48 +00:00
|
|
|
t[l][w].x1, t[l].y1)
|
|
|
|
-- slightly enlarge the highlight range for better viewing experience
|
|
|
|
x = x - w * 0.05
|
|
|
|
y = y - h * 0.05
|
|
|
|
w = w * 1.1
|
|
|
|
h = h * 1.1
|
|
|
|
|
|
|
|
fb.bb:invertRect(x, y, w, h)
|
2012-03-23 07:51:48 +00:00
|
|
|
end
|
2012-03-05 01:58:19 +00:00
|
|
|
|
2012-04-11 20:52:48 +00:00
|
|
|
function UniReader:_toggleTextHighLight(t, l0, w0, l1, w1)
|
2012-06-03 22:49:23 +00:00
|
|
|
Debug("_toggleTextHighLight range", l0, w0, l1, w1)
|
2012-04-11 20:52:48 +00:00
|
|
|
-- make sure (l0, w0) is smaller than (l1, w1)
|
|
|
|
if l0 > l1 then
|
|
|
|
l0, l1 = l1, l0
|
|
|
|
w0, w1 = w1, w0
|
|
|
|
elseif l0 == l1 and w0 > w1 then
|
|
|
|
w0, w1 = w1, w0
|
|
|
|
end
|
|
|
|
|
|
|
|
for _l, _w in self:_wordIterFromRange(t, l0, w0, l1, w1) do
|
|
|
|
if self:_isWordInScreenRange(t[_l][_w]) then
|
|
|
|
-- blitbuffer module will take care of the out of screen range part.
|
|
|
|
self:_toggleWordHighLight(t, _l, _w)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- remember to clear cursor before calling this
|
|
|
|
function UniReader:drawCursorAfterWord(t, l, w)
|
2012-04-12 03:23:22 +00:00
|
|
|
-- get height of line t[l][w] is in
|
|
|
|
local _, _, _, h = self:zoomedRectCoordTransform(0, t[l].y0, 0, t[l].y1)
|
|
|
|
-- get rect of t[l][w]
|
2012-04-12 07:50:19 +00:00
|
|
|
local x, y, wd, _ = self:getRectInScreen(t[l][w].x0, t[l][w].y0, t[l][w].x1, t[l][w].y1)
|
2012-04-11 20:52:48 +00:00
|
|
|
self.cursor:setHeight(h)
|
2012-04-11 21:33:47 +00:00
|
|
|
self.cursor:moveTo(x+wd, y)
|
2012-05-28 17:45:08 +00:00
|
|
|
self.cursor:draw(true)
|
2012-04-11 20:52:48 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function UniReader:drawCursorBeforeWord(t, l, w)
|
2012-04-12 03:23:22 +00:00
|
|
|
-- get height of line t[l][w] is in
|
|
|
|
local _, _, _, h = self:zoomedRectCoordTransform(0, t[l].y0, 0, t[l].y1)
|
|
|
|
-- get rect of t[l][w]
|
2012-04-12 07:50:19 +00:00
|
|
|
local x, y, _, _ = self:getRectInScreen(t[l][w].x0, t[l][w].y0, t[l][w].x1, t[l][w].y1)
|
2012-04-11 20:52:48 +00:00
|
|
|
self.cursor:setHeight(h)
|
|
|
|
self.cursor:moveTo(x, y)
|
2012-05-28 17:45:08 +00:00
|
|
|
self.cursor:draw(true)
|
2012-04-11 20:52:48 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function UniReader:getText(pageno)
|
|
|
|
-- define a sensible implementation when your reader supports it
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
|
|
|
function UniReader:startHighLightMode()
|
|
|
|
local t = self:getText(self.pageno)
|
|
|
|
if not t or #t == 0 then
|
2012-04-17 16:58:49 +00:00
|
|
|
showInfoMsgWithDelay("No text available for highlight", 2000, 1);
|
2012-04-11 20:52:48 +00:00
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
|
|
|
local function _findFirstWordInView(t)
|
|
|
|
for i=1, #t, 1 do
|
|
|
|
if self:_isEntireWordInScreenRange(t[i][1]) then
|
|
|
|
return i, 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-04-17 16:58:49 +00:00
|
|
|
showInfoMsgWithDelay("No visible text for highlight", 2000, 1);
|
2012-06-03 22:49:23 +00:00
|
|
|
Debug("_findFirstWordInView none found in", t)
|
2012-04-13 21:54:06 +00:00
|
|
|
|
2012-04-11 20:52:48 +00:00
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
2012-04-12 07:50:19 +00:00
|
|
|
local function _isMovingForward(l, w)
|
|
|
|
return l.cur > l.start or (l.cur == l.start and w.cur > w.start)
|
|
|
|
end
|
|
|
|
|
|
|
|
---------------------------------------
|
|
|
|
-- some word handling help functions
|
|
|
|
---------------------------------------
|
2012-04-11 20:52:48 +00:00
|
|
|
local function _prevWord(t, cur_l, cur_w)
|
|
|
|
if cur_l == 1 then
|
|
|
|
if cur_w == 1 then
|
|
|
|
-- already the first word
|
|
|
|
return 1, 1
|
|
|
|
else
|
|
|
|
-- in first line, but not first word
|
|
|
|
return cur_l, cur_w -1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if cur_w <= 1 then
|
|
|
|
-- first word in current line, goto previous line
|
|
|
|
return cur_l - 1, #t[cur_l-1]
|
|
|
|
else
|
|
|
|
return cur_l, cur_w - 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function _nextWord(t, cur_l, cur_w)
|
|
|
|
if cur_l == #t then
|
|
|
|
if cur_w == #(t[cur_l]) then
|
|
|
|
-- already the last word
|
|
|
|
return cur_l, cur_w
|
|
|
|
else
|
|
|
|
-- in last line, but not last word
|
|
|
|
return cur_l, cur_w + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if cur_w < #t[cur_l] then
|
|
|
|
return cur_l, cur_w + 1
|
|
|
|
else
|
|
|
|
-- last word in current line, move to next line
|
|
|
|
return cur_l + 1, 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function _wordInNextLine(t, cur_l, cur_w)
|
|
|
|
if cur_l == #t then
|
|
|
|
-- already in last line, return the last word
|
|
|
|
return cur_l, #(t[cur_l])
|
|
|
|
else
|
|
|
|
return cur_l + 1, math.min(cur_w, #t[cur_l+1])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function _wordInPrevLine(t, cur_l, cur_w)
|
|
|
|
if cur_l == 1 then
|
|
|
|
-- already in first line, return the first word
|
|
|
|
return 1, 1
|
|
|
|
else
|
|
|
|
return cur_l - 1, math.min(cur_w, #t[cur_l-1])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-04-12 07:50:19 +00:00
|
|
|
---------------------------------------
|
|
|
|
-- some gap handling help functions
|
|
|
|
---------------------------------------
|
|
|
|
local function _nextGap(t, cur_l, cur_w)
|
|
|
|
local is_meet_end = false
|
|
|
|
|
|
|
|
-- handle left end of line as special case.
|
|
|
|
if cur_w == 0 then
|
|
|
|
if cur_l == #t and #t[cur_l] == 1 then
|
|
|
|
is_meet_end = true
|
|
|
|
end
|
|
|
|
return cur_l, 1, is_meet_end
|
|
|
|
end
|
|
|
|
|
|
|
|
cur_l, cur_w = _nextWord(t, cur_l, cur_w)
|
|
|
|
if cur_w == 1 then
|
|
|
|
cur_w = 0
|
|
|
|
end
|
|
|
|
if cur_w ~= 0 and cur_l == #t and cur_w == #t[cur_l] then
|
|
|
|
is_meet_end = true
|
|
|
|
end
|
|
|
|
return cur_l, cur_w, is_meet_end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function _prevGap(t, cur_l, cur_w)
|
|
|
|
local is_meet_start = false
|
|
|
|
|
|
|
|
-- handle left end of line as special case.
|
|
|
|
if cur_l == 1 and (cur_w == 1 or cur_w == 0) then -- in the first line
|
|
|
|
is_meet_start = true
|
|
|
|
return cur_l, 0, is_meet_start
|
|
|
|
end
|
|
|
|
if cur_w == 1 then -- not in the first line
|
|
|
|
return cur_l, 0, is_meet_start
|
|
|
|
elseif cur_w == 0 then
|
|
|
|
-- set to 1 so _prevWord() can find previous word in previous line
|
|
|
|
cur_w = 1
|
|
|
|
end
|
|
|
|
|
|
|
|
cur_l, cur_w = _prevWord(t, cur_l, cur_w)
|
|
|
|
return cur_l, cur_w, is_meet_end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function _gapInNextLine(t, cur_l, cur_w)
|
|
|
|
local is_meet_end = false
|
|
|
|
|
|
|
|
if cur_l == #t then
|
|
|
|
-- already in last line
|
|
|
|
cur_w = #t[cur_l]
|
|
|
|
is_meet_end = true
|
|
|
|
else
|
|
|
|
-- handle left end of line as special case.
|
|
|
|
if cur_w == 0 then
|
|
|
|
cur_l = math.min(cur_l + 1, #t)
|
|
|
|
else
|
|
|
|
cur_l, cur_w = _wordInNextLine(t, cur_l, cur_w)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return cur_l, cur_w, is_meet_end
|
2012-04-11 20:52:48 +00:00
|
|
|
end
|
|
|
|
|
2012-04-12 07:50:19 +00:00
|
|
|
local function _gapInPrevLine(t, cur_l, cur_w)
|
|
|
|
local is_meet_start = false
|
|
|
|
|
|
|
|
if cur_l == 1 then
|
|
|
|
-- already in first line
|
|
|
|
is_meet_start = true
|
|
|
|
cur_w = 0
|
|
|
|
else
|
|
|
|
if cur_w == 0 then
|
|
|
|
-- goto left end of previous line
|
|
|
|
cur_l = math.max(cur_l - 1, 1)
|
|
|
|
else
|
|
|
|
cur_l, cur_w = _wordInPrevLine(t, cur_l, cur_w)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return cur_l, cur_w, is_meet_start
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2012-04-11 20:52:48 +00:00
|
|
|
local l = {}
|
|
|
|
local w = {}
|
|
|
|
|
|
|
|
l.start, w.start = _findFirstWordInView(t)
|
|
|
|
if not l.start then
|
2012-06-03 22:49:23 +00:00
|
|
|
Debug("no text in current view!")
|
2012-04-17 16:08:49 +00:00
|
|
|
-- InfoMessage about reason already shown
|
2012-04-11 20:52:48 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2012-04-17 10:05:12 +00:00
|
|
|
w.start = 0
|
2012-04-11 20:52:48 +00:00
|
|
|
l.cur, w.cur = l.start, w.start
|
|
|
|
l.new, w.new = l.cur, w.cur
|
|
|
|
local is_meet_start = false
|
|
|
|
local is_meet_end = false
|
|
|
|
local running = true
|
|
|
|
|
2012-04-12 03:23:22 +00:00
|
|
|
local cx, cy, cw, ch = self:getRectInScreen(
|
2012-04-17 10:05:12 +00:00
|
|
|
t[l.cur][1].x0,
|
|
|
|
t[l.cur][1].y0,
|
|
|
|
t[l.cur][1].x1,
|
|
|
|
t[l.cur][1].y1)
|
2012-04-11 20:52:48 +00:00
|
|
|
|
|
|
|
self.cursor = Cursor:new {
|
2012-04-17 10:05:12 +00:00
|
|
|
x_pos = cx,
|
2012-04-11 20:52:48 +00:00
|
|
|
y_pos = cy,
|
|
|
|
h = ch,
|
|
|
|
line_width_factor = 4,
|
|
|
|
}
|
2012-05-28 17:45:08 +00:00
|
|
|
self.cursor:draw(true)
|
2012-04-11 20:52:48 +00:00
|
|
|
|
|
|
|
-- first use cursor to place start pos for highlight
|
|
|
|
while running do
|
2012-04-12 19:00:44 +00:00
|
|
|
local ev = input.saveWaitForEvent()
|
2012-04-11 20:52:48 +00:00
|
|
|
ev.code = adjustKeyEvents(ev)
|
2012-04-27 21:45:07 +00:00
|
|
|
if ev.type == EV_KEY and ev.value ~= EVENT_VALUE_KEY_RELEASE then
|
2012-04-12 05:43:20 +00:00
|
|
|
if ev.code == KEY_FW_LEFT and not is_meet_start then
|
|
|
|
is_meet_end = false
|
2012-04-12 07:50:19 +00:00
|
|
|
l.new, w.new, is_meet_start = _prevGap(t, l.cur, w.cur)
|
2012-04-11 20:52:48 +00:00
|
|
|
|
2012-05-28 17:45:08 +00:00
|
|
|
self.cursor:clear(true)
|
2012-04-11 20:52:48 +00:00
|
|
|
if w.new ~= 0
|
2012-04-21 04:14:35 +00:00
|
|
|
and self:_isLineInPrevView(t[l.new])
|
2012-04-11 20:52:48 +00:00
|
|
|
and self:_isEntireWordInScreenWidthRange(t[l.new][w.new]) then
|
|
|
|
-- word is in previous view
|
|
|
|
local pageno = self:prevView()
|
|
|
|
self:goto(pageno)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- update cursor
|
2012-04-12 07:50:19 +00:00
|
|
|
if w.new == 0 then
|
2012-04-11 20:52:48 +00:00
|
|
|
-- meet line left end, must be handled as special case
|
2012-04-12 07:50:19 +00:00
|
|
|
if self:_isEntireWordInScreenRange(t[l.new][1]) then
|
|
|
|
self:drawCursorBeforeWord(t, l.new, 1)
|
2012-04-11 20:52:48 +00:00
|
|
|
end
|
|
|
|
else
|
|
|
|
if self:_isEntireWordInScreenRange(t[l.new][w.new]) then
|
|
|
|
self:drawCursorAfterWord(t, l.new, w.new)
|
|
|
|
end
|
|
|
|
end
|
2012-04-12 05:43:20 +00:00
|
|
|
elseif ev.code == KEY_FW_RIGHT and not is_meet_end then
|
|
|
|
is_meet_start = false
|
2012-04-12 07:50:19 +00:00
|
|
|
l.new, w.new, is_meet_end = _nextGap(t, l.cur, w.cur)
|
2012-04-11 20:52:48 +00:00
|
|
|
|
2012-05-28 17:45:08 +00:00
|
|
|
self.cursor:clear(true)
|
2012-04-12 07:50:19 +00:00
|
|
|
-- we want to check whether the word is in screen range,
|
|
|
|
-- so trun gap into word
|
2012-04-11 20:52:48 +00:00
|
|
|
local tmp_w = w.new
|
2012-04-12 07:50:19 +00:00
|
|
|
if tmp_w == 0 then
|
2012-04-11 20:52:48 +00:00
|
|
|
tmp_w = 1
|
|
|
|
end
|
2012-04-21 04:14:35 +00:00
|
|
|
if self:_isLineInNextView(t[l.new])
|
2012-04-11 20:52:48 +00:00
|
|
|
and self:_isEntireWordInScreenWidthRange(t[l.new][tmp_w]) then
|
|
|
|
local pageno = self:nextView()
|
|
|
|
self:goto(pageno)
|
|
|
|
end
|
|
|
|
|
2012-04-12 07:50:19 +00:00
|
|
|
if w.new == 0 then
|
2012-04-11 20:52:48 +00:00
|
|
|
-- meet line left end, must be handled as special case
|
|
|
|
if self:_isEntireWordInScreenRange(t[l.new][1]) then
|
|
|
|
self:drawCursorBeforeWord(t, l.new, 1)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
if self:_isEntireWordInScreenRange(t[l.new][w.new]) then
|
|
|
|
self:drawCursorAfterWord(t, l.new, w.new)
|
|
|
|
end
|
|
|
|
end
|
2012-04-12 05:43:20 +00:00
|
|
|
elseif ev.code == KEY_FW_UP and not is_meet_start then
|
|
|
|
is_meet_end = false
|
2012-04-12 07:50:19 +00:00
|
|
|
l.new, w.new, is_meet_start = _gapInPrevLine(t, l.cur, w.cur)
|
2012-04-11 20:52:48 +00:00
|
|
|
|
2012-05-28 17:45:08 +00:00
|
|
|
self.cursor:clear(true)
|
2012-04-11 20:52:48 +00:00
|
|
|
|
|
|
|
local tmp_w = w.new
|
2012-04-12 07:50:19 +00:00
|
|
|
if tmp_w == 0 then
|
2012-04-11 20:52:48 +00:00
|
|
|
tmp_w = 1
|
|
|
|
end
|
2012-04-21 04:14:35 +00:00
|
|
|
if self:_isLineInPrevView(t[l.new])
|
2012-04-11 20:52:48 +00:00
|
|
|
and self:_isEntireWordInScreenWidthRange(t[l.new][tmp_w]) then
|
|
|
|
-- goto next view of current page
|
|
|
|
local pageno = self:prevView()
|
|
|
|
self:goto(pageno)
|
|
|
|
end
|
|
|
|
|
|
|
|
if w.new == 0 then
|
|
|
|
if self:_isEntireWordInScreenRange(t[l.new][1]) then
|
|
|
|
self:drawCursorBeforeWord(t, l.new, 1)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
if self:_isEntireWordInScreenRange(t[l.new][w.new]) then
|
|
|
|
self:drawCursorAfterWord(t, l.new, w.new)
|
|
|
|
end
|
|
|
|
end
|
2012-04-12 05:43:20 +00:00
|
|
|
elseif ev.code == KEY_FW_DOWN and not is_meet_end then
|
|
|
|
is_meet_start = false
|
2012-04-12 07:50:19 +00:00
|
|
|
l.new, w.new, is_meet_end = _gapInNextLine(t, l.cur, w.cur)
|
2012-04-11 20:52:48 +00:00
|
|
|
|
2012-05-28 17:45:08 +00:00
|
|
|
self.cursor:clear(true)
|
2012-04-11 20:52:48 +00:00
|
|
|
|
|
|
|
local tmp_w = w.new
|
|
|
|
if w.cur == 0 then
|
|
|
|
tmp_w = 1
|
|
|
|
end
|
2012-04-21 04:14:35 +00:00
|
|
|
if self:_isLineInNextView(t[l.new])
|
2012-04-11 20:52:48 +00:00
|
|
|
and self:_isEntireWordInScreenWidthRange(t[l.new][tmp_w]) then
|
|
|
|
-- goto next view of current page
|
|
|
|
local pageno = self:nextView()
|
|
|
|
self:goto(pageno)
|
|
|
|
end
|
|
|
|
|
|
|
|
if w.cur == 0 then
|
|
|
|
if self:_isEntireWordInScreenRange(t[l.new][1]) then
|
|
|
|
self:drawCursorBeforeWord(t, l.new, 1)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
if self:_isEntireWordInScreenRange(t[l.new][w.new]) then
|
|
|
|
self:drawCursorAfterWord(t, l.new, w.new)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
elseif ev.code == KEY_DEL then
|
2012-04-21 01:46:30 +00:00
|
|
|
-- handle left end of line as special case
|
|
|
|
if w.cur == 0 then
|
|
|
|
w.cur = 1
|
|
|
|
end
|
2012-04-11 20:52:48 +00:00
|
|
|
if self.highlight[self.pageno] then
|
|
|
|
for k, text_item in ipairs(self.highlight[self.pageno]) do
|
|
|
|
for _, line_item in ipairs(text_item) do
|
|
|
|
if t[l.cur][w.cur].y0 >= line_item.y0
|
|
|
|
and t[l.cur][w.cur].y1 <= line_item.y1
|
|
|
|
and t[l.cur][w.cur].x0 >= line_item.x0
|
|
|
|
and t[l.cur][w.cur].x1 <= line_item.x1 then
|
|
|
|
self.highlight[self.pageno][k] = nil
|
2012-04-21 01:46:30 +00:00
|
|
|
-- remove page entry if empty
|
|
|
|
if #self.highlight[self.pageno] == 0 then
|
|
|
|
self.highlight[self.pageno] = nil
|
|
|
|
end
|
|
|
|
return
|
2012-04-11 20:52:48 +00:00
|
|
|
end
|
2012-04-12 05:43:20 +00:00
|
|
|
end -- for line_item
|
|
|
|
end -- for text_item
|
|
|
|
end -- if not highlight table
|
2012-04-11 20:52:48 +00:00
|
|
|
elseif ev.code == KEY_FW_PRESS then
|
|
|
|
l.new, w.new = l.cur, w.cur
|
|
|
|
l.start, w.start = l.cur, w.cur
|
|
|
|
running = false
|
2012-05-28 17:45:08 +00:00
|
|
|
self.cursor:clear(true)
|
2012-04-11 20:52:48 +00:00
|
|
|
elseif ev.code == KEY_BACK then
|
|
|
|
running = false
|
|
|
|
return
|
2012-04-12 05:43:20 +00:00
|
|
|
end -- if check key event
|
2012-04-11 20:52:48 +00:00
|
|
|
l.cur, w.cur = l.new, w.new
|
|
|
|
end
|
2012-04-12 05:43:20 +00:00
|
|
|
end -- while running
|
2012-06-03 22:49:23 +00:00
|
|
|
Debug("start", l.cur, w.cur, l.start, w.start)
|
2012-04-11 20:52:48 +00:00
|
|
|
|
|
|
|
-- two helper functions for highlight
|
|
|
|
local function _togglePrevWordHighLight(t, l, w)
|
2012-04-12 05:43:20 +00:00
|
|
|
if w.cur == 0 then
|
|
|
|
if l.cur == 1 then
|
|
|
|
-- already at the begin of first line, nothing to toggle
|
2012-04-12 07:50:19 +00:00
|
|
|
return l, w, true
|
2012-04-12 05:43:20 +00:00
|
|
|
else
|
|
|
|
w.cur = 1
|
|
|
|
end
|
|
|
|
end
|
2012-04-11 20:52:48 +00:00
|
|
|
l.new, w.new = _prevWord(t, l.cur, w.cur)
|
|
|
|
|
|
|
|
if l.cur == 1 and w.cur == 1 then
|
|
|
|
is_meet_start = true
|
|
|
|
-- left end of first line must be handled as special case
|
|
|
|
w.new = 0
|
|
|
|
end
|
|
|
|
|
|
|
|
if w.new ~= 0 and
|
2012-04-21 04:14:35 +00:00
|
|
|
self:_isLineInPrevView(t[l.new]) then
|
2012-04-11 20:52:48 +00:00
|
|
|
-- word out of left and right sides of current view should
|
|
|
|
-- not trigger pan by page
|
|
|
|
if self:_isEntireWordInScreenWidthRange(t[l.new][w.new]) then
|
|
|
|
-- word is in previous view
|
|
|
|
local pageno = self:prevView()
|
|
|
|
self:goto(pageno)
|
|
|
|
end
|
|
|
|
|
|
|
|
local l0 = l.start
|
|
|
|
local w0 = w.start
|
|
|
|
local l1 = l.cur
|
|
|
|
local w1 = w.cur
|
|
|
|
if _isMovingForward(l, w) then
|
|
|
|
l0, w0 = _nextWord(t, l0, w0)
|
|
|
|
l1, w1 = l.new, w.new
|
|
|
|
end
|
|
|
|
self:_toggleTextHighLight(t, l0, w0,
|
|
|
|
l1, w1)
|
|
|
|
else
|
|
|
|
self:_toggleWordHighLight(t, l.cur, w.cur)
|
|
|
|
end
|
|
|
|
|
|
|
|
l.cur, w.cur = l.new, w.new
|
|
|
|
return l, w, (is_meet_start or false)
|
|
|
|
end
|
|
|
|
|
|
|
|
local function _toggleNextWordHighLight(t, l, w)
|
|
|
|
if w.cur == 0 then
|
|
|
|
w.new = 1
|
|
|
|
else
|
|
|
|
l.new, w.new = _nextWord(t, l.cur, w.cur)
|
|
|
|
end
|
|
|
|
if l.new == #t and w.new == #t[#t] then
|
|
|
|
is_meet_end = true
|
|
|
|
end
|
|
|
|
|
2012-04-21 04:14:35 +00:00
|
|
|
if self:_isLineInNextView(t[l.new]) then
|
2012-04-11 20:52:48 +00:00
|
|
|
if self:_isEntireWordInScreenWidthRange(t[l.new][w.new]) then
|
|
|
|
local pageno = self:nextView()
|
|
|
|
self:goto(pageno)
|
|
|
|
end
|
|
|
|
|
|
|
|
local tmp_l = l.start
|
|
|
|
local tmp_w = w.start
|
|
|
|
if _isMovingForward(l, w) then
|
|
|
|
tmp_l, tmp_w = _nextWord(t, tmp_l, tmp_w)
|
|
|
|
end
|
|
|
|
self:_toggleTextHighLight(t, tmp_l, tmp_w,
|
|
|
|
l.new, w.new)
|
|
|
|
else
|
|
|
|
self:_toggleWordHighLight(t, l.new, w.new)
|
|
|
|
end
|
|
|
|
|
|
|
|
l.cur, w.cur = l.new, w.new
|
|
|
|
return l, w, (is_meet_end or false)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
-- go into highlight mode
|
|
|
|
running = true
|
|
|
|
while running do
|
2012-04-12 19:00:44 +00:00
|
|
|
local ev = input.saveWaitForEvent()
|
2012-04-11 20:52:48 +00:00
|
|
|
ev.code = adjustKeyEvents(ev)
|
2012-04-27 21:45:07 +00:00
|
|
|
if ev.type == EV_KEY and ev.value ~= EVENT_VALUE_KEY_RELEASE then
|
2012-04-11 20:52:48 +00:00
|
|
|
if ev.code == KEY_FW_LEFT then
|
|
|
|
is_meet_end = false
|
|
|
|
if not is_meet_start then
|
|
|
|
l, w, is_meet_start = _togglePrevWordHighLight(t, l, w)
|
|
|
|
end
|
|
|
|
elseif ev.code == KEY_FW_RIGHT then
|
|
|
|
is_meet_start = false
|
|
|
|
if not is_meet_end then
|
|
|
|
l, w, is_meet_end = _toggleNextWordHighLight(t, l, w)
|
2012-04-12 05:43:20 +00:00
|
|
|
end -- if not is_meet_end
|
2012-04-11 20:52:48 +00:00
|
|
|
elseif ev.code == KEY_FW_UP then
|
|
|
|
is_meet_end = false
|
|
|
|
if not is_meet_start then
|
|
|
|
if l.cur == 1 then
|
|
|
|
-- handle left end of first line as special case
|
|
|
|
tmp_l = 1
|
|
|
|
tmp_w = 0
|
|
|
|
else
|
|
|
|
tmp_l, tmp_w = _wordInPrevLine(t, l.cur, w.cur)
|
|
|
|
end
|
|
|
|
while not (tmp_l == l.cur and tmp_w == w.cur) do
|
|
|
|
l, w, is_meet_start = _togglePrevWordHighLight(t, l, w)
|
|
|
|
end
|
2012-04-12 05:43:20 +00:00
|
|
|
end -- not is_meet_start
|
2012-04-11 20:52:48 +00:00
|
|
|
elseif ev.code == KEY_FW_DOWN then
|
|
|
|
is_meet_start = false
|
|
|
|
if not is_meet_end then
|
2012-04-12 09:31:01 +00:00
|
|
|
-- handle left end of first line as special case
|
2012-04-11 20:52:48 +00:00
|
|
|
if w.cur == 0 then
|
|
|
|
tmp_w = 1
|
|
|
|
else
|
2012-04-12 09:31:01 +00:00
|
|
|
tmp_w = w.cur
|
2012-04-11 20:52:48 +00:00
|
|
|
end
|
2012-04-12 09:31:01 +00:00
|
|
|
tmp_l, tmp_w = _wordInNextLine(t, l.cur, tmp_w)
|
2012-04-11 20:52:48 +00:00
|
|
|
while not (tmp_l == l.cur and tmp_w == w.cur) do
|
|
|
|
l, w, is_meet_end = _toggleNextWordHighLight(t, l, w)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
elseif ev.code == KEY_FW_PRESS then
|
|
|
|
local l0, w0, l1, w1
|
|
|
|
|
|
|
|
-- find start and end of highlight text
|
|
|
|
if _isMovingForward(l, w) then
|
|
|
|
l0, w0 = _nextWord(t, l.start, w.start)
|
|
|
|
l1, w1 = l.cur, w.cur
|
|
|
|
else
|
|
|
|
l0, w0 = _nextWord(t, l.cur, w.cur)
|
|
|
|
l1, w1 = l.start, w.start
|
|
|
|
end
|
|
|
|
-- remove selection area
|
|
|
|
self:_toggleTextHighLight(t, l0, w0, l1, w1)
|
|
|
|
|
|
|
|
-- put text into highlight table of current page
|
|
|
|
local hl_item = {}
|
|
|
|
local s = ""
|
|
|
|
local prev_l = l0
|
|
|
|
local prev_w = w0
|
|
|
|
local l_item = {
|
|
|
|
x0 = t[l0][w0].x0,
|
|
|
|
y0 = t[l0].y0,
|
|
|
|
y1 = t[l0].y1,
|
|
|
|
}
|
|
|
|
for _l,_w in self:_wordIterFromRange(t, l0, w0, l1, w1) do
|
|
|
|
local word_item = t[_l][_w]
|
|
|
|
if _l > prev_l then
|
|
|
|
-- in next line, add previous line to highlight item
|
|
|
|
l_item.x1 = t[prev_l][prev_w].x1
|
|
|
|
table.insert(hl_item, l_item)
|
|
|
|
-- re initialize l_item for new line
|
|
|
|
l_item = {
|
|
|
|
x0 = word_item.x0,
|
|
|
|
y0 = t[_l].y0,
|
|
|
|
y1 = t[_l].y1,
|
|
|
|
}
|
|
|
|
end
|
|
|
|
s = s .. word_item.word .. " "
|
|
|
|
prev_l, prev_w = _l, _w
|
|
|
|
end
|
|
|
|
-- insert last line of text in line item
|
|
|
|
l_item.x1 = t[prev_l][prev_w].x1
|
|
|
|
table.insert(hl_item, l_item)
|
|
|
|
hl_item.text = s
|
|
|
|
|
|
|
|
if not self.highlight[self.pageno] then
|
|
|
|
self.highlight[self.pageno] = {}
|
|
|
|
end
|
|
|
|
table.insert(self.highlight[self.pageno], hl_item)
|
|
|
|
|
|
|
|
running = false
|
|
|
|
elseif ev.code == KEY_BACK then
|
|
|
|
running = false
|
2012-04-12 03:23:22 +00:00
|
|
|
end -- if key event
|
2012-04-11 20:52:48 +00:00
|
|
|
fb:refresh(1)
|
|
|
|
end
|
|
|
|
end -- EOF while
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2012-03-31 10:53:40 +00:00
|
|
|
----------------------------------------------------
|
2012-04-06 11:11:18 +00:00
|
|
|
-- Renderer memory
|
2012-03-31 10:53:40 +00:00
|
|
|
----------------------------------------------------
|
|
|
|
|
|
|
|
function UniReader:getCacheSize()
|
|
|
|
return -1
|
|
|
|
end
|
2012-03-05 01:58:19 +00:00
|
|
|
|
2012-03-31 11:38:33 +00:00
|
|
|
function UniReader:cleanCache()
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2012-04-06 11:11:18 +00:00
|
|
|
----------------------------------------------------
|
|
|
|
-- Setting related methods
|
|
|
|
----------------------------------------------------
|
|
|
|
|
|
|
|
-- load special settings for specific reader
|
|
|
|
function UniReader:loadSpecialSettings()
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
-- save special settings for specific reader
|
|
|
|
function UniReader:saveSpecialSettings()
|
2012-03-05 01:58:19 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
--[ following are default methods ]--
|
|
|
|
|
2012-03-30 05:07:48 +00:00
|
|
|
function UniReader:initGlobalSettings(settings)
|
storing rcountmax; user-configurable zoom step & pan steps, etc
1. In order to close issue #59, I've introduced user-configurable values for panning steps - for X- & Y-axis, separately. Now panning is called by pressing fiveway without mod_keys. When one presses Shift+FW, he/she changes panning steps in the following way - Shift-Left/Right = decrease / increase X-panning step (divide or multiply on factor 2), Shift-Up/Down = increase / decrease Y-panning step. The lowest value for panning steps is set 1. Both parameters, shift_x & shift_y, are saved to local settings (i.e. history file).
2. Manual zoom step was also made user-configurable. So, instead of two old zooming functions (with fixed 10% and 20%-steps), I made one function to zoom (Shift+<>), while the other (Alt+<>) changes the zoom step downto minimum 1%.
3. Fresh introduced function to change parameter rcountmax was added by storing rcountmax to both setting files - global settings & local ones (i.e. history file) - so that the rcountmax-priority (from low to high) is the following: default rcountmax=5 < its value in global settings < rcountmax stored for each concrete document.
3. Dirty, the extention-based hack to avoid reading not crengine-related parameters stored in history files. TODO: one has to finally introduce loadSpecialSettings() & readSpecialSettings() for PDFReader & DJVUReader and to store therein the reader-specific parameters (like globalgamma, bbox, globalzoom, globalzoom_mode; render_mode = for djvu-files only, etc.)
4. Some lua-code cosmetics (to make code more readable); for example: "self.pan_margin = settings:readSetting("pan_margin") or self.pan_margin" instead of
"local pan_margin = settings:readSetting("pan_margin")
if pan_margin then
self.pan_margin = pan_margin
end"
5. Fix for the today's tigran123 fix: issue #246 (details are included). Added InfoMessage:show() to inform most impatient users that the reader tries to redraw new zoo mode.
6. The fontface for the reading info (called by 'Menu') is restored to be in accordance with original intentions and with the same fontface in crereader.lua - namely, Font:getFace("rifont", 20)
7. Moved the exit hotkeys (Alt+Back & Home) to the end of hotkey list.
2012-09-03 19:23:06 +00:00
|
|
|
self.pan_margin = settings:readSetting("pan_margin") or self.pan_margin
|
|
|
|
self.pan_overlap_vertical = settings:readSetting("pan_overlap_vertical") or self.pan_overlap_vertical
|
|
|
|
self.cache_max_memsize = settings:readSetting("cache_max_memsize") or self.cache_max_memsize
|
|
|
|
self.cache_max_ttl = settings:readSetting("cache_max_ttl") or self.cache_max_ttl
|
|
|
|
self.rcountmax = settings:readSetting("rcountmax") or self.rcountmax
|
2012-03-30 05:07:48 +00:00
|
|
|
end
|
2012-03-05 01:58:19 +00:00
|
|
|
|
2012-04-19 06:39:50 +00:00
|
|
|
-- Method to load settings before document open
|
|
|
|
function UniReader:preLoadSettings(filename)
|
|
|
|
self.settings = DocSettings:open(filename)
|
storing rcountmax; user-configurable zoom step & pan steps, etc
1. In order to close issue #59, I've introduced user-configurable values for panning steps - for X- & Y-axis, separately. Now panning is called by pressing fiveway without mod_keys. When one presses Shift+FW, he/she changes panning steps in the following way - Shift-Left/Right = decrease / increase X-panning step (divide or multiply on factor 2), Shift-Up/Down = increase / decrease Y-panning step. The lowest value for panning steps is set 1. Both parameters, shift_x & shift_y, are saved to local settings (i.e. history file).
2. Manual zoom step was also made user-configurable. So, instead of two old zooming functions (with fixed 10% and 20%-steps), I made one function to zoom (Shift+<>), while the other (Alt+<>) changes the zoom step downto minimum 1%.
3. Fresh introduced function to change parameter rcountmax was added by storing rcountmax to both setting files - global settings & local ones (i.e. history file) - so that the rcountmax-priority (from low to high) is the following: default rcountmax=5 < its value in global settings < rcountmax stored for each concrete document.
3. Dirty, the extention-based hack to avoid reading not crengine-related parameters stored in history files. TODO: one has to finally introduce loadSpecialSettings() & readSpecialSettings() for PDFReader & DJVUReader and to store therein the reader-specific parameters (like globalgamma, bbox, globalzoom, globalzoom_mode; render_mode = for djvu-files only, etc.)
4. Some lua-code cosmetics (to make code more readable); for example: "self.pan_margin = settings:readSetting("pan_margin") or self.pan_margin" instead of
"local pan_margin = settings:readSetting("pan_margin")
if pan_margin then
self.pan_margin = pan_margin
end"
5. Fix for the today's tigran123 fix: issue #246 (details are included). Added InfoMessage:show() to inform most impatient users that the reader tries to redraw new zoo mode.
6. The fontface for the reading info (called by 'Menu') is restored to be in accordance with original intentions and with the same fontface in crereader.lua - namely, Font:getFace("rifont", 20)
7. Moved the exit hotkeys (Alt+Back & Home) to the end of hotkey list.
2012-09-03 19:23:06 +00:00
|
|
|
self.cache_document_size = self.settings:readSetting("cache_document_size") or self.cache_document_size
|
2012-04-19 06:39:50 +00:00
|
|
|
end
|
|
|
|
|
2012-04-06 11:11:18 +00:00
|
|
|
-- This is a low-level method that can be shared with all readers.
|
2012-03-05 01:58:19 +00:00
|
|
|
function UniReader:loadSettings(filename)
|
|
|
|
if self.doc ~= nil then
|
storing rcountmax; user-configurable zoom step & pan steps, etc
1. In order to close issue #59, I've introduced user-configurable values for panning steps - for X- & Y-axis, separately. Now panning is called by pressing fiveway without mod_keys. When one presses Shift+FW, he/she changes panning steps in the following way - Shift-Left/Right = decrease / increase X-panning step (divide or multiply on factor 2), Shift-Up/Down = increase / decrease Y-panning step. The lowest value for panning steps is set 1. Both parameters, shift_x & shift_y, are saved to local settings (i.e. history file).
2. Manual zoom step was also made user-configurable. So, instead of two old zooming functions (with fixed 10% and 20%-steps), I made one function to zoom (Shift+<>), while the other (Alt+<>) changes the zoom step downto minimum 1%.
3. Fresh introduced function to change parameter rcountmax was added by storing rcountmax to both setting files - global settings & local ones (i.e. history file) - so that the rcountmax-priority (from low to high) is the following: default rcountmax=5 < its value in global settings < rcountmax stored for each concrete document.
3. Dirty, the extention-based hack to avoid reading not crengine-related parameters stored in history files. TODO: one has to finally introduce loadSpecialSettings() & readSpecialSettings() for PDFReader & DJVUReader and to store therein the reader-specific parameters (like globalgamma, bbox, globalzoom, globalzoom_mode; render_mode = for djvu-files only, etc.)
4. Some lua-code cosmetics (to make code more readable); for example: "self.pan_margin = settings:readSetting("pan_margin") or self.pan_margin" instead of
"local pan_margin = settings:readSetting("pan_margin")
if pan_margin then
self.pan_margin = pan_margin
end"
5. Fix for the today's tigran123 fix: issue #246 (details are included). Added InfoMessage:show() to inform most impatient users that the reader tries to redraw new zoo mode.
6. The fontface for the reading info (called by 'Menu') is restored to be in accordance with original intentions and with the same fontface in crereader.lua - namely, Font:getFace("rifont", 20)
7. Moved the exit hotkeys (Alt+Back & Home) to the end of hotkey list.
2012-09-03 19:23:06 +00:00
|
|
|
-- moved "gamma" to not-crengine related parameters
|
|
|
|
self.jump_history = self.settings:readSetting("jump_history") or {cur = 1}
|
|
|
|
self.bookmarks = self.settings:readSetting("bookmarks") or {}
|
2012-03-05 02:48:03 +00:00
|
|
|
|
2012-04-18 09:29:27 +00:00
|
|
|
-- clear obselate jumpstack settings
|
|
|
|
-- move jump_stack to bookmarks incase users used
|
|
|
|
-- it as bookmark feature before.
|
|
|
|
local jump_stack = self.settings:readSetting("jumpstack")
|
|
|
|
if jump_stack then
|
|
|
|
if #self.bookmarks == 0 then
|
|
|
|
self.bookmarks = jump_stack
|
|
|
|
end
|
|
|
|
self.settings:delSetting("jumpstack")
|
|
|
|
end
|
|
|
|
|
storing rcountmax; user-configurable zoom step & pan steps, etc
1. In order to close issue #59, I've introduced user-configurable values for panning steps - for X- & Y-axis, separately. Now panning is called by pressing fiveway without mod_keys. When one presses Shift+FW, he/she changes panning steps in the following way - Shift-Left/Right = decrease / increase X-panning step (divide or multiply on factor 2), Shift-Up/Down = increase / decrease Y-panning step. The lowest value for panning steps is set 1. Both parameters, shift_x & shift_y, are saved to local settings (i.e. history file).
2. Manual zoom step was also made user-configurable. So, instead of two old zooming functions (with fixed 10% and 20%-steps), I made one function to zoom (Shift+<>), while the other (Alt+<>) changes the zoom step downto minimum 1%.
3. Fresh introduced function to change parameter rcountmax was added by storing rcountmax to both setting files - global settings & local ones (i.e. history file) - so that the rcountmax-priority (from low to high) is the following: default rcountmax=5 < its value in global settings < rcountmax stored for each concrete document.
3. Dirty, the extention-based hack to avoid reading not crengine-related parameters stored in history files. TODO: one has to finally introduce loadSpecialSettings() & readSpecialSettings() for PDFReader & DJVUReader and to store therein the reader-specific parameters (like globalgamma, bbox, globalzoom, globalzoom_mode; render_mode = for djvu-files only, etc.)
4. Some lua-code cosmetics (to make code more readable); for example: "self.pan_margin = settings:readSetting("pan_margin") or self.pan_margin" instead of
"local pan_margin = settings:readSetting("pan_margin")
if pan_margin then
self.pan_margin = pan_margin
end"
5. Fix for the today's tigran123 fix: issue #246 (details are included). Added InfoMessage:show() to inform most impatient users that the reader tries to redraw new zoo mode.
6. The fontface for the reading info (called by 'Menu') is restored to be in accordance with original intentions and with the same fontface in crereader.lua - namely, Font:getFace("rifont", 20)
7. Moved the exit hotkeys (Alt+Back & Home) to the end of hotkey list.
2012-09-03 19:23:06 +00:00
|
|
|
self.highlight = self.settings:readSetting("highlight") or {}
|
2012-05-23 05:04:05 +00:00
|
|
|
if self.highlight.to_fix ~= nil then
|
|
|
|
for _,fix_item in ipairs(self.highlight.to_fix) do
|
|
|
|
if fix_item == "djvu invert y axle" then
|
|
|
|
InfoMessage:show("Updating HighLight data...", 1)
|
|
|
|
for pageno,text_table in pairs(self.highlight) do
|
|
|
|
if type(pageno) == "number" then
|
|
|
|
text_table = self:invertTextYAxel(pageno, text_table)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-06-03 22:49:23 +00:00
|
|
|
Debug(self.highlight)
|
2012-05-23 05:04:05 +00:00
|
|
|
self.highlight.to_fix = nil
|
|
|
|
end
|
2012-03-21 03:20:07 +00:00
|
|
|
|
storing rcountmax; user-configurable zoom step & pan steps, etc
1. In order to close issue #59, I've introduced user-configurable values for panning steps - for X- & Y-axis, separately. Now panning is called by pressing fiveway without mod_keys. When one presses Shift+FW, he/she changes panning steps in the following way - Shift-Left/Right = decrease / increase X-panning step (divide or multiply on factor 2), Shift-Up/Down = increase / decrease Y-panning step. The lowest value for panning steps is set 1. Both parameters, shift_x & shift_y, are saved to local settings (i.e. history file).
2. Manual zoom step was also made user-configurable. So, instead of two old zooming functions (with fixed 10% and 20%-steps), I made one function to zoom (Shift+<>), while the other (Alt+<>) changes the zoom step downto minimum 1%.
3. Fresh introduced function to change parameter rcountmax was added by storing rcountmax to both setting files - global settings & local ones (i.e. history file) - so that the rcountmax-priority (from low to high) is the following: default rcountmax=5 < its value in global settings < rcountmax stored for each concrete document.
3. Dirty, the extention-based hack to avoid reading not crengine-related parameters stored in history files. TODO: one has to finally introduce loadSpecialSettings() & readSpecialSettings() for PDFReader & DJVUReader and to store therein the reader-specific parameters (like globalgamma, bbox, globalzoom, globalzoom_mode; render_mode = for djvu-files only, etc.)
4. Some lua-code cosmetics (to make code more readable); for example: "self.pan_margin = settings:readSetting("pan_margin") or self.pan_margin" instead of
"local pan_margin = settings:readSetting("pan_margin")
if pan_margin then
self.pan_margin = pan_margin
end"
5. Fix for the today's tigran123 fix: issue #246 (details are included). Added InfoMessage:show() to inform most impatient users that the reader tries to redraw new zoo mode.
6. The fontface for the reading info (called by 'Menu') is restored to be in accordance with original intentions and with the same fontface in crereader.lua - namely, Font:getFace("rifont", 20)
7. Moved the exit hotkeys (Alt+Back & Home) to the end of hotkey list.
2012-09-03 19:23:06 +00:00
|
|
|
self.rcountmax = self.settings:readSetting("rcountmax") or self.rcountmax
|
|
|
|
|
|
|
|
-- other parameters are reader-specific --> @TODO: move to proper place, like loadSpecialSettings()
|
|
|
|
-- since DJVUReader still has no loadSpecialSettings(), just a quick solution is
|
|
|
|
local ftype = string.lower(string.match(filename, ".+%.([^.]+)") or "")
|
|
|
|
if ext:getReader(ftype) ~= CREReader then
|
|
|
|
self.globalgamma = self.settings:readSetting("gamma") or self.globalgamma
|
|
|
|
local bbox = self.settings:readSetting("bbox")
|
|
|
|
Debug("bbox loaded ", bbox)
|
|
|
|
self.bbox = bbox
|
2012-03-07 23:38:34 +00:00
|
|
|
|
storing rcountmax; user-configurable zoom step & pan steps, etc
1. In order to close issue #59, I've introduced user-configurable values for panning steps - for X- & Y-axis, separately. Now panning is called by pressing fiveway without mod_keys. When one presses Shift+FW, he/she changes panning steps in the following way - Shift-Left/Right = decrease / increase X-panning step (divide or multiply on factor 2), Shift-Up/Down = increase / decrease Y-panning step. The lowest value for panning steps is set 1. Both parameters, shift_x & shift_y, are saved to local settings (i.e. history file).
2. Manual zoom step was also made user-configurable. So, instead of two old zooming functions (with fixed 10% and 20%-steps), I made one function to zoom (Shift+<>), while the other (Alt+<>) changes the zoom step downto minimum 1%.
3. Fresh introduced function to change parameter rcountmax was added by storing rcountmax to both setting files - global settings & local ones (i.e. history file) - so that the rcountmax-priority (from low to high) is the following: default rcountmax=5 < its value in global settings < rcountmax stored for each concrete document.
3. Dirty, the extention-based hack to avoid reading not crengine-related parameters stored in history files. TODO: one has to finally introduce loadSpecialSettings() & readSpecialSettings() for PDFReader & DJVUReader and to store therein the reader-specific parameters (like globalgamma, bbox, globalzoom, globalzoom_mode; render_mode = for djvu-files only, etc.)
4. Some lua-code cosmetics (to make code more readable); for example: "self.pan_margin = settings:readSetting("pan_margin") or self.pan_margin" instead of
"local pan_margin = settings:readSetting("pan_margin")
if pan_margin then
self.pan_margin = pan_margin
end"
5. Fix for the today's tigran123 fix: issue #246 (details are included). Added InfoMessage:show() to inform most impatient users that the reader tries to redraw new zoo mode.
6. The fontface for the reading info (called by 'Menu') is restored to be in accordance with original intentions and with the same fontface in crereader.lua - namely, Font:getFace("rifont", 20)
7. Moved the exit hotkeys (Alt+Back & Home) to the end of hotkey list.
2012-09-03 19:23:06 +00:00
|
|
|
self.globalzoom = self.settings:readSetting("globalzoom") or 1.0
|
|
|
|
self.globalzoom_mode = self.settings:readSetting("globalzoom_mode") or -1
|
|
|
|
self.render_mode = self.settings:readSetting("render_mode") or 0
|
|
|
|
self.shift_x = self.settings:readSetting("shift_x") or self.shift_x
|
|
|
|
self.shift_y = self.settings:readSetting("shift_y") or self.shift_y
|
|
|
|
self.step_manual_zoom = self.settings:readSetting("step_manual_zoom") or self.step_manual_zoom
|
|
|
|
end
|
2012-03-08 00:29:17 +00:00
|
|
|
|
2012-04-06 11:11:18 +00:00
|
|
|
self:loadSpecialSettings()
|
2012-03-05 01:58:19 +00:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2012-03-30 05:07:48 +00:00
|
|
|
function UniReader:getLastPageOrPos()
|
|
|
|
return self.settings:readSetting("last_page") or 1
|
|
|
|
end
|
2012-03-09 06:06:05 +00:00
|
|
|
|
2012-03-30 05:07:48 +00:00
|
|
|
function UniReader:saveLastPageOrPos()
|
2012-04-18 09:29:27 +00:00
|
|
|
self.settings:saveSetting("last_page", self.pageno)
|
2012-03-07 10:16:46 +00:00
|
|
|
end
|
|
|
|
|
2012-03-05 01:46:16 +00:00
|
|
|
-- guarantee that we have enough memory in cache
|
2012-03-20 19:15:24 +00:00
|
|
|
function UniReader:cacheClaim(size)
|
2012-03-05 01:46:16 +00:00
|
|
|
if(size > self.cache_max_memsize) then
|
|
|
|
-- we're not allowed to claim this much at all
|
|
|
|
error("too much memory claimed")
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
while self.cache_current_memsize + size > self.cache_max_memsize do
|
|
|
|
-- repeat this until we have enough free memory
|
|
|
|
for k, _ in pairs(self.cache) do
|
|
|
|
if self.cache[k].ttl > 0 then
|
|
|
|
-- reduce ttl
|
|
|
|
self.cache[k].ttl = self.cache[k].ttl - 1
|
|
|
|
else
|
|
|
|
-- cache slot is at end of life, so kick it out
|
|
|
|
self.cache_current_memsize = self.cache_current_memsize - self.cache[k].size
|
2012-03-31 16:57:22 +00:00
|
|
|
self.cache[k].bb:free()
|
2012-03-05 01:46:16 +00:00
|
|
|
self.cache[k] = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
self.cache_current_memsize = self.cache_current_memsize + size
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2012-03-20 19:15:24 +00:00
|
|
|
function UniReader:drawOrCache(no, preCache)
|
2012-03-12 23:02:49 +00:00
|
|
|
-- our general caching strategy is as follows:
|
|
|
|
-- #1 goal: we must render the needed area.
|
|
|
|
-- #2 goal: we render as much of the requested page as we can
|
|
|
|
-- #3 goal: we render the full page
|
|
|
|
-- #4 goal: we render next page, too. (TODO)
|
|
|
|
|
2012-09-09 17:04:06 +00:00
|
|
|
local pg_w = G_width / ( self.doc:getPages() )
|
|
|
|
local page_indicator = function()
|
|
|
|
fb.bb:invertRect( pg_w*(no-1),0, pg_w,10)
|
|
|
|
fb:refresh(1, pg_w*(no-1),0, pg_w,10)
|
|
|
|
Debug('page_indicator',no)
|
|
|
|
end
|
|
|
|
page_indicator()
|
|
|
|
|
2012-03-12 23:02:49 +00:00
|
|
|
-- ideally, this should be factored out and only be called when needed (TODO)
|
2012-03-19 23:10:19 +00:00
|
|
|
local ok, page = pcall(self.doc.openPage, self.doc, no)
|
2012-04-09 07:42:19 +00:00
|
|
|
local width, height = G_width, G_height
|
2012-03-19 23:10:19 +00:00
|
|
|
if not ok then
|
|
|
|
-- TODO: error handling
|
|
|
|
return nil
|
|
|
|
end
|
2012-03-20 08:42:22 +00:00
|
|
|
local dc = self:setzoom(page, preCache)
|
2012-03-12 23:02:49 +00:00
|
|
|
|
2012-03-13 07:37:45 +00:00
|
|
|
-- offset_x_in_page & offset_y_in_page is the offset within zoomed page
|
2012-03-20 19:15:24 +00:00
|
|
|
-- they are always positive.
|
|
|
|
-- you can see self.offset_x_& self.offset_y as the offset within
|
2012-03-13 07:37:45 +00:00
|
|
|
-- draw space, which includes the page. So it can be negative and positive.
|
|
|
|
local offset_x_in_page = -self.offset_x
|
|
|
|
local offset_y_in_page = -self.offset_y
|
|
|
|
if offset_x_in_page < 0 then offset_x_in_page = 0 end
|
2012-03-13 08:21:16 +00:00
|
|
|
if offset_y_in_page < 0 then offset_y_in_page = 0 end
|
2012-03-13 07:37:45 +00:00
|
|
|
|
2012-03-12 23:02:49 +00:00
|
|
|
-- check if we have relevant cache contents
|
|
|
|
local pagehash = no..'_'..self.globalzoom..'_'..self.globalrotate..'_'..self.globalgamma
|
|
|
|
if self.cache[pagehash] ~= nil then
|
|
|
|
-- we have something in cache, check if it contains the requested part
|
2012-03-13 07:37:45 +00:00
|
|
|
if self.cache[pagehash].x <= offset_x_in_page
|
|
|
|
and self.cache[pagehash].y <= offset_y_in_page
|
|
|
|
and ( self.cache[pagehash].x + self.cache[pagehash].w >= offset_x_in_page + width
|
2012-03-12 23:11:31 +00:00
|
|
|
or self.cache[pagehash].w >= self.fullwidth - 1)
|
2012-03-13 07:37:45 +00:00
|
|
|
and ( self.cache[pagehash].y + self.cache[pagehash].h >= offset_y_in_page + height
|
2012-03-12 23:11:31 +00:00
|
|
|
or self.cache[pagehash].h >= self.fullheight - 1)
|
2012-03-12 23:02:49 +00:00
|
|
|
then
|
|
|
|
-- requested part is within cached tile
|
|
|
|
-- ...so properly clean page
|
|
|
|
page:close()
|
|
|
|
-- ...and give it more time to live (ttl), except if we're precaching
|
|
|
|
if not preCache then
|
|
|
|
self.cache[pagehash].ttl = self.cache_max_ttl
|
|
|
|
end
|
|
|
|
-- ...and return blitbuffer plus offset into it
|
2012-09-09 17:04:06 +00:00
|
|
|
|
|
|
|
page_indicator()
|
|
|
|
|
2012-03-12 23:02:49 +00:00
|
|
|
return pagehash,
|
2012-03-13 07:37:45 +00:00
|
|
|
offset_x_in_page - self.cache[pagehash].x,
|
|
|
|
offset_y_in_page - self.cache[pagehash].y
|
2012-03-12 23:02:49 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
-- okay, we do not have it in cache yet.
|
|
|
|
-- so render now.
|
|
|
|
-- start off with the requested area
|
2012-03-20 19:15:24 +00:00
|
|
|
local tile = { x = offset_x_in_page, y = offset_y_in_page,
|
2012-03-13 09:07:55 +00:00
|
|
|
w = width, h = height }
|
2012-03-12 23:02:49 +00:00
|
|
|
-- can we cache the full page?
|
|
|
|
local max_cache = self.cache_max_memsize
|
|
|
|
if preCache then
|
|
|
|
max_cache = max_cache - self.cache[self.pagehash].size
|
|
|
|
end
|
|
|
|
if (self.fullwidth * self.fullheight / 2) <= max_cache then
|
|
|
|
-- yes we can, so do this with offset 0, 0
|
|
|
|
tile.x = 0
|
|
|
|
tile.y = 0
|
|
|
|
tile.w = self.fullwidth
|
|
|
|
tile.h = self.fullheight
|
2012-04-03 15:55:19 +00:00
|
|
|
elseif (tile.w*tile.h / 2) < max_cache then
|
2012-03-12 23:02:49 +00:00
|
|
|
-- no, we can't. so generate a tile as big as we can go
|
|
|
|
-- grow area in steps of 10px
|
|
|
|
while ((tile.w+10) * (tile.h+10) / 2) < max_cache do
|
|
|
|
if tile.x > 0 then
|
|
|
|
tile.x = tile.x - 5
|
|
|
|
tile.w = tile.w + 5
|
|
|
|
end
|
|
|
|
if tile.x + tile.w < self.fullwidth then
|
|
|
|
tile.w = tile.w + 5
|
|
|
|
end
|
|
|
|
if tile.y > 0 then
|
|
|
|
tile.y = tile.y - 5
|
|
|
|
tile.h = tile.h + 5
|
|
|
|
end
|
2012-04-03 15:55:19 +00:00
|
|
|
if tile.y + tile.h < self.fullheight then
|
2012-03-12 23:02:49 +00:00
|
|
|
tile.h = tile.h + 5
|
|
|
|
end
|
|
|
|
end
|
2012-03-05 01:46:16 +00:00
|
|
|
else
|
2012-03-12 23:02:49 +00:00
|
|
|
if not preCache then
|
2012-06-03 22:49:23 +00:00
|
|
|
Debug("ERROR not enough memory in cache left, probably a bug.")
|
2012-03-12 23:02:49 +00:00
|
|
|
end
|
|
|
|
return nil
|
2012-03-05 01:46:16 +00:00
|
|
|
end
|
2012-03-20 19:15:24 +00:00
|
|
|
self:cacheClaim(tile.w * tile.h / 2);
|
2012-03-12 23:02:49 +00:00
|
|
|
self.cache[pagehash] = {
|
|
|
|
x = tile.x,
|
|
|
|
y = tile.y,
|
|
|
|
w = tile.w,
|
|
|
|
h = tile.h,
|
|
|
|
ttl = self.cache_max_ttl,
|
|
|
|
size = tile.w * tile.h / 2,
|
|
|
|
bb = Blitbuffer.new(tile.w, tile.h)
|
|
|
|
}
|
2012-04-18 16:16:49 +00:00
|
|
|
--debug ("# new biltbuffer:"..dump(self.cache[pagehash]))
|
2012-03-12 23:02:49 +00:00
|
|
|
dc:setOffset(-tile.x, -tile.y)
|
2012-06-03 22:49:23 +00:00
|
|
|
Debug("rendering page", no)
|
2012-08-27 14:33:32 +00:00
|
|
|
page:draw(dc, self.cache[pagehash].bb, 0, 0, self.render_mode)
|
2012-03-12 23:02:49 +00:00
|
|
|
page:close()
|
|
|
|
|
2012-09-09 17:04:06 +00:00
|
|
|
page_indicator()
|
|
|
|
|
2012-03-13 08:21:16 +00:00
|
|
|
-- return hash and offset within blitbuffer
|
2012-03-12 23:02:49 +00:00
|
|
|
return pagehash,
|
2012-03-13 07:37:45 +00:00
|
|
|
offset_x_in_page - tile.x,
|
|
|
|
offset_y_in_page - tile.y
|
2012-03-05 01:46:16 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
-- blank the cache
|
2012-03-20 19:15:24 +00:00
|
|
|
function UniReader:clearCache()
|
2012-04-09 17:58:34 +00:00
|
|
|
for k, _ in pairs(self.cache) do
|
|
|
|
self.cache[k].bb:free()
|
|
|
|
end
|
2012-03-05 01:46:16 +00:00
|
|
|
self.cache = {}
|
|
|
|
self.cache_current_memsize = 0
|
|
|
|
end
|
|
|
|
|
|
|
|
-- set viewer state according to zoom state
|
2012-03-17 04:17:20 +00:00
|
|
|
function UniReader:setzoom(page, preCache)
|
2012-03-19 17:59:36 +00:00
|
|
|
local dc = DrawContext.new()
|
2012-03-05 01:46:16 +00:00
|
|
|
local pwidth, pheight = page:getSize(self.nulldc)
|
2012-04-09 07:42:19 +00:00
|
|
|
local width, height = G_width, G_height
|
2012-06-03 22:49:23 +00:00
|
|
|
Debug("page::getSize",pwidth,pheight)
|
2012-03-05 01:46:16 +00:00
|
|
|
local x0, y0, x1, y1 = page:getUsedBBox()
|
|
|
|
if x0 == 0.01 and y0 == 0.01 and x1 == -0.01 and y1 == -0.01 then
|
|
|
|
x0 = 0
|
|
|
|
y0 = 0
|
|
|
|
x1 = pwidth
|
|
|
|
y1 = pheight
|
|
|
|
end
|
2012-04-06 13:17:25 +00:00
|
|
|
if x1 == 0 then x1 = pwidth end
|
|
|
|
if y1 == 0 then y1 = pheight end
|
2012-03-05 01:46:16 +00:00
|
|
|
-- clamp to page BBox
|
|
|
|
if x0 < 0 then x0 = 0 end
|
|
|
|
if x1 > pwidth then x1 = pwidth end
|
|
|
|
if y0 < 0 then y0 = 0 end
|
|
|
|
if y1 > pheight then y1 = pheight end
|
|
|
|
|
2012-03-07 23:55:12 +00:00
|
|
|
if self.bbox.enabled then
|
2012-06-03 22:49:23 +00:00
|
|
|
Debug("ORIGINAL page::getUsedBBox", x0,y0, x1,y1 )
|
2012-03-06 23:26:56 +00:00
|
|
|
local bbox = self.bbox[self.pageno] -- exact
|
2012-03-07 17:48:45 +00:00
|
|
|
|
2012-03-20 19:15:24 +00:00
|
|
|
local oddEven = self:oddEven(self.pageno)
|
2012-03-07 17:48:45 +00:00
|
|
|
if bbox ~= nil then
|
2012-06-03 22:49:23 +00:00
|
|
|
Debug("bbox from", self.pageno)
|
2012-03-07 17:48:45 +00:00
|
|
|
else
|
2012-03-20 19:15:24 +00:00
|
|
|
bbox = self.bbox[oddEven] -- odd/even
|
2012-03-06 23:26:56 +00:00
|
|
|
end
|
2012-03-07 17:48:45 +00:00
|
|
|
if bbox ~= nil then -- last used up to this page
|
2012-06-03 22:49:23 +00:00
|
|
|
Debug("bbox from", oddEven)
|
2012-03-07 17:48:45 +00:00
|
|
|
else
|
2012-03-06 23:26:56 +00:00
|
|
|
for i = 0,self.pageno do
|
|
|
|
bbox = self.bbox[ self.pageno - i ]
|
2012-03-07 17:48:45 +00:00
|
|
|
if bbox ~= nil then
|
2012-06-03 22:49:23 +00:00
|
|
|
Debug("bbox from", self.pageno - i)
|
2012-03-07 17:48:45 +00:00
|
|
|
break
|
|
|
|
end
|
2012-03-06 23:26:56 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
if bbox ~= nil then
|
|
|
|
x0 = bbox["x0"]
|
|
|
|
y0 = bbox["y0"]
|
|
|
|
x1 = bbox["x1"]
|
|
|
|
y1 = bbox["y1"]
|
|
|
|
end
|
2012-03-06 22:18:52 +00:00
|
|
|
end
|
|
|
|
|
2012-06-03 22:49:23 +00:00
|
|
|
Debug("page::getUsedBBox", x0, y0, x1, y1 )
|
2012-03-05 01:46:16 +00:00
|
|
|
|
2012-04-21 04:14:35 +00:00
|
|
|
if self.globalzoom_mode == self.ZOOM_FIT_TO_PAGE
|
|
|
|
or self.globalzoom_mode == self.ZOOM_FIT_TO_CONTENT then
|
2012-03-05 01:46:16 +00:00
|
|
|
self.globalzoom = width / pwidth
|
|
|
|
self.offset_x = 0
|
|
|
|
self.offset_y = (height - (self.globalzoom * pheight)) / 2
|
|
|
|
if height / pheight < self.globalzoom then
|
|
|
|
self.globalzoom = height / pheight
|
|
|
|
self.offset_x = (width - (self.globalzoom * pwidth)) / 2
|
|
|
|
self.offset_y = 0
|
|
|
|
end
|
2012-03-05 02:33:56 +00:00
|
|
|
self.pan_by_page = false
|
2012-04-21 04:14:35 +00:00
|
|
|
elseif self.globalzoom_mode == self.ZOOM_FIT_TO_PAGE_WIDTH
|
|
|
|
or self.globalzoom_mode == self.ZOOM_FIT_TO_CONTENT_WIDTH then
|
2012-03-05 01:46:16 +00:00
|
|
|
self.globalzoom = width / pwidth
|
|
|
|
self.offset_x = 0
|
|
|
|
self.offset_y = (height - (self.globalzoom * pheight)) / 2
|
2012-03-05 02:33:56 +00:00
|
|
|
self.pan_by_page = false
|
2012-04-21 04:14:35 +00:00
|
|
|
elseif self.globalzoom_mode == self.ZOOM_FIT_TO_PAGE_HEIGHT
|
|
|
|
or self.globalzoom_mode == self.ZOOM_FIT_TO_CONTENT_HEIGHT then
|
2012-03-05 01:46:16 +00:00
|
|
|
self.globalzoom = height / pheight
|
|
|
|
self.offset_x = (width - (self.globalzoom * pwidth)) / 2
|
|
|
|
self.offset_y = 0
|
2012-03-05 02:33:56 +00:00
|
|
|
self.pan_by_page = false
|
2012-03-05 01:46:16 +00:00
|
|
|
end
|
2012-03-05 02:33:56 +00:00
|
|
|
|
2012-04-21 04:14:35 +00:00
|
|
|
if self.globalzoom_mode == self.ZOOM_FIT_TO_CONTENT then
|
2012-03-05 01:46:16 +00:00
|
|
|
if (x1 - x0) < pwidth then
|
|
|
|
self.globalzoom = width / (x1 - x0)
|
|
|
|
if height / (y1 - y0) < self.globalzoom then
|
|
|
|
self.globalzoom = height / (y1 - y0)
|
|
|
|
end
|
|
|
|
end
|
2012-03-07 03:59:32 +00:00
|
|
|
self.offset_x = -1 * x0 * self.globalzoom
|
|
|
|
self.offset_y = -1 * y0 * self.globalzoom
|
2012-04-21 04:14:35 +00:00
|
|
|
elseif self.globalzoom_mode == self.ZOOM_FIT_TO_CONTENT_WIDTH then
|
2012-03-05 01:46:16 +00:00
|
|
|
if (x1 - x0) < pwidth then
|
|
|
|
self.globalzoom = width / (x1 - x0)
|
|
|
|
end
|
2012-03-07 03:59:32 +00:00
|
|
|
self.offset_x = -1 * x0 * self.globalzoom
|
|
|
|
self.offset_y = -1 * y0 * self.globalzoom
|
2012-03-07 13:44:59 +00:00
|
|
|
self.content_top = self.offset_y
|
|
|
|
-- enable pan mode in ZOOM_FIT_TO_CONTENT_WIDTH
|
2012-04-21 04:14:35 +00:00
|
|
|
self.globalzoom_mode = self.ZOOM_FIT_TO_CONTENT_WIDTH_PAN
|
|
|
|
elseif self.globalzoom_mode == self.ZOOM_FIT_TO_CONTENT_WIDTH_PAN then
|
2012-03-07 13:44:59 +00:00
|
|
|
if self.content_top == -2012 then
|
|
|
|
-- We must handle previous page turn as a special cases,
|
|
|
|
-- because we want to arrive at the bottom of previous page.
|
2012-04-10 13:34:38 +00:00
|
|
|
-- Since this a real page turn, we need to recalculate stuff.
|
2012-03-07 13:44:59 +00:00
|
|
|
if (x1 - x0) < pwidth then
|
|
|
|
self.globalzoom = width / (x1 - x0)
|
|
|
|
end
|
2012-03-05 01:46:16 +00:00
|
|
|
self.offset_x = -1 * x0 * self.globalzoom
|
2012-03-07 13:44:59 +00:00
|
|
|
self.content_top = -1 * y0 * self.globalzoom
|
|
|
|
self.offset_y = fb.bb:getHeight() - self.fullheight
|
2012-03-05 01:46:16 +00:00
|
|
|
end
|
2012-04-21 04:14:35 +00:00
|
|
|
elseif self.globalzoom_mode == self.ZOOM_FIT_TO_CONTENT_HEIGHT then
|
2012-03-05 01:46:16 +00:00
|
|
|
if (y1 - y0) < pheight then
|
|
|
|
self.globalzoom = height / (y1 - y0)
|
|
|
|
end
|
2012-03-07 03:59:32 +00:00
|
|
|
self.offset_x = -1 * x0 * self.globalzoom
|
|
|
|
self.offset_y = -1 * y0 * self.globalzoom
|
2012-04-21 04:14:35 +00:00
|
|
|
elseif self.globalzoom_mode == self.ZOOM_FIT_TO_CONTENT_HALF_WIDTH
|
|
|
|
or self.globalzoom_mode == self.ZOOM_FIT_TO_CONTENT_HALF_WIDTH_MARGIN then
|
2012-03-05 13:17:07 +00:00
|
|
|
local margin = self.pan_margin
|
2012-04-21 04:14:35 +00:00
|
|
|
if self.globalzoom_mode == self.ZOOM_FIT_TO_CONTENT_HALF_WIDTH then margin = 0 end
|
2012-04-26 12:13:32 +00:00
|
|
|
self.globalzoom = width / (x1 - x0 + margin)
|
2012-03-05 13:17:07 +00:00
|
|
|
self.offset_x = -1 * x0 * self.globalzoom * 2 + margin
|
2012-04-26 12:13:32 +00:00
|
|
|
self.globalzoom = height / (y1 - y0 + margin)
|
2012-03-05 13:17:07 +00:00
|
|
|
self.offset_y = -1 * y0 * self.globalzoom * 2 + margin
|
2012-04-26 12:13:32 +00:00
|
|
|
self.globalzoom = width / (x1 - x0 + margin) * 2
|
2012-06-03 22:49:23 +00:00
|
|
|
Debug("column mode offset:", self.offset_x, self.offset_y, " zoom:", self.globalzoom);
|
2012-04-21 04:14:35 +00:00
|
|
|
self.globalzoom_mode = self.ZOOM_BY_VALUE -- enable pan mode
|
2012-03-05 01:46:16 +00:00
|
|
|
self.pan_x = self.offset_x
|
|
|
|
self.pan_y = self.offset_y
|
|
|
|
self.pan_by_page = true
|
|
|
|
end
|
2012-03-05 02:37:29 +00:00
|
|
|
|
2012-03-05 01:46:16 +00:00
|
|
|
dc:setZoom(self.globalzoom)
|
2012-03-05 02:37:29 +00:00
|
|
|
self.globalzoom_orig = self.globalzoom
|
|
|
|
|
2012-03-05 01:46:16 +00:00
|
|
|
dc:setRotate(self.globalrotate);
|
|
|
|
self.fullwidth, self.fullheight = page:getSize(dc)
|
2012-03-17 04:17:20 +00:00
|
|
|
if not preCache then -- save current page fullsize
|
|
|
|
self.cur_full_width = self.fullwidth
|
|
|
|
self.cur_full_height = self.fullheight
|
2012-04-26 20:16:36 +00:00
|
|
|
|
|
|
|
self.cur_bbox = {
|
|
|
|
["x0"] = x0,
|
|
|
|
["y0"] = y0,
|
|
|
|
["x1"] = x1,
|
|
|
|
["y1"] = y1,
|
|
|
|
}
|
2012-06-03 22:49:23 +00:00
|
|
|
Debug("cur_bbox", self.cur_bbox)
|
2012-04-26 20:16:36 +00:00
|
|
|
|
2012-03-17 04:17:20 +00:00
|
|
|
end
|
2012-03-05 01:46:16 +00:00
|
|
|
self.min_offset_x = fb.bb:getWidth() - self.fullwidth
|
|
|
|
self.min_offset_y = fb.bb:getHeight() - self.fullheight
|
|
|
|
if(self.min_offset_x > 0) then
|
|
|
|
self.min_offset_x = 0
|
|
|
|
end
|
|
|
|
if(self.min_offset_y > 0) then
|
|
|
|
self.min_offset_y = 0
|
|
|
|
end
|
|
|
|
|
2012-06-03 22:49:23 +00:00
|
|
|
Debug("Reader:setZoom globalzoom:", self.globalzoom, " globalrotate:", self.globalrotate, " offset:", self.offset_x, self.offset_y, " pagesize:", self.fullwidth, self.fullheight, " min_offset:", self.min_offset_x, self.min_offset_y)
|
2012-03-05 01:46:16 +00:00
|
|
|
|
|
|
|
-- set gamma here, we don't have any other good place for this right now:
|
|
|
|
if self.globalgamma ~= self.GAMMA_NO_GAMMA then
|
2012-06-03 22:49:23 +00:00
|
|
|
Debug("gamma correction: ", self.globalgamma)
|
2012-03-05 01:46:16 +00:00
|
|
|
dc:setGamma(self.globalgamma)
|
|
|
|
end
|
|
|
|
return dc
|
|
|
|
end
|
|
|
|
|
|
|
|
-- render and blit a page
|
|
|
|
function UniReader:show(no)
|
2012-03-20 19:15:24 +00:00
|
|
|
local pagehash, offset_x, offset_y = self:drawOrCache(no)
|
2012-04-09 07:42:19 +00:00
|
|
|
local width, height = G_width, G_height
|
|
|
|
|
2012-03-19 23:10:19 +00:00
|
|
|
if not pagehash then
|
|
|
|
return
|
|
|
|
end
|
2012-03-12 23:02:49 +00:00
|
|
|
self.pagehash = pagehash
|
|
|
|
local bb = self.cache[pagehash].bb
|
2012-04-13 14:49:27 +00:00
|
|
|
self.dest_x = 0
|
|
|
|
self.dest_y = 0
|
2012-03-12 23:02:49 +00:00
|
|
|
if bb:getWidth() - offset_x < width then
|
2012-03-13 08:21:16 +00:00
|
|
|
-- we can't fill the whole output width, center the content
|
2012-04-13 14:49:27 +00:00
|
|
|
self.dest_x = (width - (bb:getWidth() - offset_x)) / 2
|
2012-03-12 23:02:49 +00:00
|
|
|
end
|
2012-03-20 19:15:24 +00:00
|
|
|
if bb:getHeight() - offset_y < height and
|
2012-04-21 04:14:35 +00:00
|
|
|
self.globalzoom_mode ~= self.ZOOM_FIT_TO_CONTENT_WIDTH_PAN then
|
2012-03-20 19:15:24 +00:00
|
|
|
-- we can't fill the whole output height and not in
|
2012-03-13 08:21:16 +00:00
|
|
|
-- ZOOM_FIT_TO_CONTENT_WIDTH_PAN mode, center the content
|
2012-04-13 14:49:27 +00:00
|
|
|
self.dest_y = (height - (bb:getHeight() - offset_y)) / 2
|
2012-04-21 04:14:35 +00:00
|
|
|
elseif self.globalzoom_mode == self.ZOOM_FIT_TO_CONTENT_WIDTH_PAN and
|
2012-03-13 08:21:16 +00:00
|
|
|
self.offset_y > 0 then
|
|
|
|
-- if we are in ZOOM_FIT_TO_CONTENT_WIDTH_PAN mode and turning to
|
2012-03-20 19:15:24 +00:00
|
|
|
-- the top of the page, we might leave an empty space between the
|
2012-03-13 08:21:16 +00:00
|
|
|
-- page top and screen top.
|
2012-04-13 14:49:27 +00:00
|
|
|
self.dest_y = self.offset_y
|
2012-03-05 01:46:16 +00:00
|
|
|
end
|
2012-04-13 14:49:27 +00:00
|
|
|
if self.dest_x or self.dest_y then
|
2012-03-12 23:02:49 +00:00
|
|
|
fb.bb:paintRect(0, 0, width, height, 8)
|
2012-03-05 01:46:16 +00:00
|
|
|
end
|
2012-06-03 22:49:23 +00:00
|
|
|
Debug("blitFrom dest_off:", self.dest_x, self.dest_y,
|
2012-04-17 16:52:27 +00:00
|
|
|
"src_off:", offset_x, offset_y,
|
|
|
|
"width:", width, "height:", height)
|
2012-04-13 14:49:27 +00:00
|
|
|
fb.bb:blitFrom(bb, self.dest_x, self.dest_y, offset_x, offset_y, width, height)
|
2012-03-21 02:37:18 +00:00
|
|
|
|
2012-06-03 22:49:23 +00:00
|
|
|
Debug("self.show_overlap", self.show_overlap)
|
2012-04-09 13:06:05 +00:00
|
|
|
if self.show_overlap < 0 then
|
2012-04-13 14:49:27 +00:00
|
|
|
fb.bb:dimRect(0,0, width, self.dest_y - self.show_overlap)
|
2012-04-09 13:06:05 +00:00
|
|
|
elseif self.show_overlap > 0 then
|
2012-04-13 14:49:27 +00:00
|
|
|
fb.bb:dimRect(0,self.dest_y + height - self.show_overlap, width, self.show_overlap)
|
2012-04-09 13:06:05 +00:00
|
|
|
end
|
|
|
|
self.show_overlap = 0
|
|
|
|
|
2012-03-23 07:51:48 +00:00
|
|
|
-- render highlights to page
|
2012-03-21 02:37:18 +00:00
|
|
|
if self.highlight[no] then
|
2012-03-23 07:51:48 +00:00
|
|
|
self:toggleTextHighLight(self.highlight[no])
|
2012-03-21 02:37:18 +00:00
|
|
|
end
|
|
|
|
|
2012-03-31 13:12:31 +00:00
|
|
|
if self.rcount >= self.rcountmax then
|
2012-06-03 22:49:23 +00:00
|
|
|
Debug("full refresh")
|
2012-04-19 06:10:37 +00:00
|
|
|
self.rcount = 0
|
2012-03-05 01:46:16 +00:00
|
|
|
fb:refresh(0)
|
|
|
|
else
|
2012-06-03 22:49:23 +00:00
|
|
|
Debug("partial refresh")
|
2012-03-05 01:46:16 +00:00
|
|
|
self.rcount = self.rcount + 1
|
|
|
|
fb:refresh(1)
|
|
|
|
end
|
|
|
|
self.slot_visible = slot;
|
|
|
|
end
|
|
|
|
|
2012-04-07 14:55:56 +00:00
|
|
|
function UniReader:isSamePage(p1, p2)
|
|
|
|
return p1 == p2
|
|
|
|
end
|
|
|
|
|
2012-03-05 03:25:51 +00:00
|
|
|
--[[
|
2012-04-18 09:01:22 +00:00
|
|
|
@ pageno is the page you want to add to jump_history, this will
|
|
|
|
clear the forward stack since pageno is the new head.
|
2012-04-07 14:55:56 +00:00
|
|
|
NOTE: for CREReader, pageno refers to xpointer
|
2012-03-05 03:25:51 +00:00
|
|
|
--]]
|
2012-04-18 09:01:22 +00:00
|
|
|
function UniReader:addJump(pageno)
|
|
|
|
-- build notes from TOC
|
2012-04-19 01:49:46 +00:00
|
|
|
local notes = self:getTocTitleByPage(pageno)
|
2012-04-18 09:01:22 +00:00
|
|
|
if notes ~= "" then
|
2012-04-18 12:05:12 +00:00
|
|
|
notes = "in "..notes
|
2012-04-18 09:01:22 +00:00
|
|
|
end
|
|
|
|
-- create a head
|
|
|
|
jump_item = {
|
|
|
|
page = pageno,
|
|
|
|
datetime = os.date("%Y-%m-%d %H:%M:%S"),
|
|
|
|
notes = notes,
|
|
|
|
}
|
|
|
|
-- clear forward stack if it is not empty
|
|
|
|
if self.jump_history.cur < #self.jump_history then
|
|
|
|
for i=self.jump_history.cur+1, #self.jump_history do
|
|
|
|
self.jump_history[i] = nil
|
2012-03-05 01:46:16 +00:00
|
|
|
end
|
|
|
|
end
|
2012-04-18 09:01:22 +00:00
|
|
|
-- keep the size less than 10
|
|
|
|
if #self.jump_history > 10 then
|
|
|
|
table.remove(self.jump_history)
|
2012-03-05 01:46:16 +00:00
|
|
|
end
|
2012-04-18 09:01:22 +00:00
|
|
|
-- set up new head
|
|
|
|
-- if backward stack top is the same as page to record, remove it
|
|
|
|
if #self.jump_history ~= 0 and
|
2012-04-18 16:04:41 +00:00
|
|
|
self:isSamePage(self.jump_history[#self.jump_history].page, pageno) then
|
2012-04-18 09:01:22 +00:00
|
|
|
self.jump_history[#self.jump_history] = nil
|
2012-03-05 01:46:16 +00:00
|
|
|
end
|
2012-04-18 09:01:22 +00:00
|
|
|
table.insert(self.jump_history, jump_item)
|
|
|
|
self.jump_history.cur = #self.jump_history + 1
|
|
|
|
return true
|
2012-03-05 01:46:16 +00:00
|
|
|
end
|
|
|
|
|
2012-03-20 19:15:24 +00:00
|
|
|
function UniReader:delJump(pageno)
|
2012-04-18 09:01:22 +00:00
|
|
|
for _t,_v in ipairs(self.jump_history) do
|
2012-03-05 03:25:51 +00:00
|
|
|
if _v.page == pageno then
|
2012-04-18 09:01:22 +00:00
|
|
|
table.remove(self.jump_history, _t)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-06-06 08:21:25 +00:00
|
|
|
function UniReader:isBookmarkInSequence(a, b)
|
|
|
|
return a.page < b.page
|
|
|
|
end
|
|
|
|
|
2012-04-18 09:01:22 +00:00
|
|
|
-- return nil if page already marked
|
|
|
|
-- otherwise, return true
|
|
|
|
function UniReader:addBookmark(pageno)
|
|
|
|
for k,v in ipairs(self.bookmarks) do
|
|
|
|
if v.page == pageno then
|
|
|
|
return nil
|
2012-03-05 03:25:51 +00:00
|
|
|
end
|
|
|
|
end
|
2012-04-18 09:01:22 +00:00
|
|
|
-- build notes from TOC
|
2012-04-19 01:49:46 +00:00
|
|
|
local notes = self:getTocTitleByPage(pageno)
|
2012-04-18 09:01:22 +00:00
|
|
|
if notes ~= "" then
|
2012-04-18 12:05:12 +00:00
|
|
|
notes = "in "..notes
|
2012-04-18 09:01:22 +00:00
|
|
|
end
|
|
|
|
mark_item = {
|
|
|
|
page = pageno,
|
|
|
|
datetime = os.date("%Y-%m-%d %H:%M:%S"),
|
|
|
|
notes = notes,
|
|
|
|
}
|
|
|
|
table.insert(self.bookmarks, mark_item)
|
2012-06-06 08:21:25 +00:00
|
|
|
table.sort(self.bookmarks, function(a,b)
|
|
|
|
return self:isBookmarkInSequence(a, b)
|
|
|
|
end)
|
2012-04-18 09:01:22 +00:00
|
|
|
return true
|
2012-03-05 03:25:51 +00:00
|
|
|
end
|
|
|
|
|
2012-03-05 01:46:16 +00:00
|
|
|
-- change current page and cache next page after rendering
|
2012-04-18 09:01:22 +00:00
|
|
|
function UniReader:goto(no, is_ignore_jump)
|
2012-03-05 01:46:16 +00:00
|
|
|
if no < 1 or no > self.doc:getPages() then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2012-04-18 09:01:22 +00:00
|
|
|
-- for jump_history
|
|
|
|
if not is_ignore_jump then
|
|
|
|
-- distinguish jump from normal page turn
|
|
|
|
if self.pageno and math.abs(self.pageno - no) > 1 then
|
|
|
|
self:addJump(self.pageno)
|
|
|
|
end
|
2012-03-05 01:46:16 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
self.pageno = no
|
|
|
|
self:show(no)
|
2012-03-05 03:25:51 +00:00
|
|
|
|
2012-03-12 23:02:49 +00:00
|
|
|
-- TODO: move the following to a more appropriate place
|
|
|
|
-- into the caching section
|
2012-03-05 01:46:16 +00:00
|
|
|
if no < self.doc:getPages() then
|
2012-03-12 23:02:49 +00:00
|
|
|
if #self.bbox == 0 or not self.bbox.enabled then
|
|
|
|
-- pre-cache next page, but if we will modify bbox don't!
|
2012-03-20 19:15:24 +00:00
|
|
|
self:drawOrCache(no+1, true)
|
2012-03-05 01:46:16 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-03-28 16:09:26 +00:00
|
|
|
function UniReader:redrawCurrentPage()
|
|
|
|
self:goto(self.pageno)
|
|
|
|
end
|
|
|
|
|
2012-03-07 13:44:59 +00:00
|
|
|
function UniReader:nextView()
|
|
|
|
local pageno = self.pageno
|
|
|
|
|
2012-04-21 04:14:35 +00:00
|
|
|
if self.globalzoom_mode == self.ZOOM_FIT_TO_CONTENT_WIDTH_PAN then
|
2012-03-07 13:44:59 +00:00
|
|
|
if self.offset_y <= self.min_offset_y then
|
|
|
|
-- hit content bottom, turn to next page
|
2012-04-21 04:14:35 +00:00
|
|
|
self.globalzoom_mode = self.ZOOM_FIT_TO_CONTENT_WIDTH
|
2012-03-07 13:44:59 +00:00
|
|
|
pageno = pageno + 1
|
|
|
|
else
|
|
|
|
-- goto next view of current page
|
2012-04-09 07:42:19 +00:00
|
|
|
self.offset_y = self.offset_y - G_height
|
|
|
|
+ self.pan_overlap_vertical
|
2012-04-09 13:06:05 +00:00
|
|
|
self.show_overlap = -self.pan_overlap_vertical -- top < 0
|
2012-03-07 13:44:59 +00:00
|
|
|
end
|
|
|
|
else
|
|
|
|
-- not in fit to content width pan mode, just do a page turn
|
|
|
|
pageno = pageno + 1
|
|
|
|
if self.pan_by_page then
|
|
|
|
-- we are in two column mode
|
|
|
|
self.offset_x = self.pan_x
|
|
|
|
self.offset_y = self.pan_y
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return pageno
|
|
|
|
end
|
|
|
|
|
|
|
|
function UniReader:prevView()
|
|
|
|
local pageno = self.pageno
|
|
|
|
|
2012-04-21 04:14:35 +00:00
|
|
|
if self.globalzoom_mode == self.ZOOM_FIT_TO_CONTENT_WIDTH_PAN then
|
2012-03-07 13:44:59 +00:00
|
|
|
if self.offset_y >= self.content_top then
|
|
|
|
-- hit content top, turn to previous page
|
2012-03-20 19:15:24 +00:00
|
|
|
-- set self.content_top with magic num to signal self:setZoom
|
2012-03-07 13:44:59 +00:00
|
|
|
self.content_top = -2012
|
|
|
|
pageno = pageno - 1
|
|
|
|
else
|
|
|
|
-- goto previous view of current page
|
2012-04-09 07:42:19 +00:00
|
|
|
self.offset_y = self.offset_y + G_height
|
|
|
|
- self.pan_overlap_vertical
|
2012-04-09 13:06:05 +00:00
|
|
|
self.show_overlap = self.pan_overlap_vertical -- bottom > 0
|
2012-03-07 13:44:59 +00:00
|
|
|
end
|
|
|
|
else
|
|
|
|
-- not in fit to content width pan mode, just do a page turn
|
|
|
|
pageno = pageno - 1
|
|
|
|
if self.pan_by_page then
|
|
|
|
-- we are in two column mode
|
|
|
|
self.offset_x = self.pan_x
|
|
|
|
self.offset_y = self.pan_y
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return pageno
|
|
|
|
end
|
|
|
|
|
2012-03-05 01:46:16 +00:00
|
|
|
-- adjust global gamma setting
|
2012-03-20 19:15:24 +00:00
|
|
|
function UniReader:modifyGamma(factor)
|
2012-06-03 22:49:23 +00:00
|
|
|
Debug("modifyGamma, gamma=", self.globalgamma, " factor=", factor)
|
2012-03-05 01:46:16 +00:00
|
|
|
self.globalgamma = self.globalgamma * factor;
|
2012-09-09 19:04:55 +00:00
|
|
|
InfoMessage:show("New gamma = "..self.globalgamma, 1) -- we don't want delay here
|
2012-08-27 14:33:32 +00:00
|
|
|
self:redrawCurrentPage()
|
|
|
|
end
|
|
|
|
|
2012-03-05 01:46:16 +00:00
|
|
|
-- adjust zoom state and trigger re-rendering
|
2012-04-21 04:14:35 +00:00
|
|
|
function UniReader:setglobalzoom_mode(newzoommode)
|
|
|
|
if self.globalzoom_mode ~= newzoommode then
|
|
|
|
self.globalzoom_mode = newzoommode
|
2012-04-07 15:28:56 +00:00
|
|
|
self:redrawCurrentPage()
|
2012-03-05 01:46:16 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- adjust zoom state and trigger re-rendering
|
2012-03-20 19:15:24 +00:00
|
|
|
function UniReader:setGlobalZoom(zoom)
|
2012-03-05 01:46:16 +00:00
|
|
|
if self.globalzoom ~= zoom then
|
2012-04-21 04:14:35 +00:00
|
|
|
self.globalzoom_mode = self.ZOOM_BY_VALUE
|
2012-03-05 01:46:16 +00:00
|
|
|
self.globalzoom = zoom
|
2012-04-07 15:28:56 +00:00
|
|
|
self:redrawCurrentPage()
|
2012-03-05 01:46:16 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-03-20 19:15:24 +00:00
|
|
|
function UniReader:setRotate(rotate)
|
2012-03-05 01:46:16 +00:00
|
|
|
self.globalrotate = rotate
|
2012-04-07 15:28:56 +00:00
|
|
|
self:redrawCurrentPage()
|
2012-03-05 01:46:16 +00:00
|
|
|
end
|
|
|
|
|
2012-03-08 15:28:16 +00:00
|
|
|
-- @ orien: 1 for clockwise rotate, -1 for anti-clockwise
|
|
|
|
function UniReader:screenRotate(orien)
|
2012-03-09 01:40:46 +00:00
|
|
|
Screen:screenRotate(orien)
|
2012-04-09 07:42:19 +00:00
|
|
|
-- update global width and height variable
|
|
|
|
G_width, G_height = fb:getSize()
|
2012-03-20 19:15:24 +00:00
|
|
|
self:clearCache()
|
2012-03-08 15:28:16 +00:00
|
|
|
end
|
|
|
|
|
2012-03-29 10:17:32 +00:00
|
|
|
function UniReader:cleanUpTocTitle(title)
|
2012-09-08 22:53:28 +00:00
|
|
|
local s, _ = title:gsub("\13", "")
|
|
|
|
return s
|
2012-03-05 05:43:23 +00:00
|
|
|
end
|
|
|
|
|
2012-03-29 10:17:32 +00:00
|
|
|
function UniReader:fillToc()
|
2012-09-10 22:36:58 +00:00
|
|
|
InfoMessage:show("Retrieving TOC...", 1)
|
2012-09-14 08:08:47 +00:00
|
|
|
self.toc_expandable = false
|
2012-03-29 10:17:32 +00:00
|
|
|
self.toc = self.doc:getToc()
|
2012-09-10 22:36:58 +00:00
|
|
|
self.toc_children = {}
|
|
|
|
self.toc_xview = {}
|
|
|
|
self.toc_cview = {}
|
|
|
|
self.toc_curidx_to_x = {}
|
|
|
|
|
|
|
|
-- To combine the forest represented by the array of depths
|
|
|
|
-- (self.toc[].depth) into a single tree we introduce a virtual head
|
|
|
|
-- of depth=0 at position index=0 (The Great Parent)
|
|
|
|
local prev, prev_depth = 0, 0
|
|
|
|
self.toc_xview[0] = "_HEAD"
|
|
|
|
|
|
|
|
-- the parent[] array is only needed for the calculation of
|
|
|
|
-- self.toc_children[] arrays.
|
|
|
|
local parent = {}
|
|
|
|
for k,v in ipairs(self.toc) do
|
|
|
|
table.insert(self.toc_xview,
|
|
|
|
(" "):rep(v.depth-1)..self:cleanUpTocTitle(v.title))
|
|
|
|
if (v.depth > prev_depth) then --> k is a child of prev
|
|
|
|
if not self.toc_children[prev] then
|
|
|
|
self.toc_children[prev] = {}
|
|
|
|
end
|
|
|
|
table.insert(self.toc_children[prev], k)
|
|
|
|
parent[k] = prev
|
|
|
|
self.toc_xview[prev] = "+ "..self.toc_xview[prev]
|
2012-09-14 08:08:47 +00:00
|
|
|
if prev > 0 then
|
|
|
|
self.toc_expandable = true
|
|
|
|
end
|
2012-09-10 22:36:58 +00:00
|
|
|
elseif (v.depth == prev_depth) then --> k and prev are siblings
|
|
|
|
parent[k] = parent[prev]
|
|
|
|
table.insert(self.toc_children[parent[k]], k)
|
|
|
|
else --> k and prev must have a common (possibly virtual) ancestor
|
|
|
|
local par = parent[prev]
|
|
|
|
while (self.toc[par].depth > v.depth) do
|
|
|
|
par = parent[par]
|
|
|
|
end
|
|
|
|
parent[k] = parent[par]
|
|
|
|
table.insert(self.toc_children[parent[k]], k)
|
|
|
|
end
|
|
|
|
prev = k
|
|
|
|
prev_depth = self.toc[prev].depth
|
|
|
|
end -- for k,v in ipairs(self.toc)
|
|
|
|
if (self.toc_children[0]) then
|
|
|
|
self.toc_curidx_to_x = self.toc_children[0]
|
|
|
|
for i=1,#self.toc_children[0] do
|
|
|
|
table.insert(self.toc_cview, self.toc_xview[self.toc_children[0][i]])
|
|
|
|
end
|
|
|
|
end
|
2012-03-05 05:15:34 +00:00
|
|
|
end
|
|
|
|
|
2012-04-19 01:49:46 +00:00
|
|
|
-- getTocTitleByPage wrapper, so specific reader
|
|
|
|
-- can tranform pageno according its need
|
2012-03-28 16:09:26 +00:00
|
|
|
function UniReader:getTocTitleByPage(pageno)
|
2012-04-19 01:49:46 +00:00
|
|
|
return self:_getTocTitleByPage(pageno)
|
|
|
|
end
|
|
|
|
|
|
|
|
function UniReader:_getTocTitleByPage(pageno)
|
2012-03-05 05:15:34 +00:00
|
|
|
if not self.toc then
|
|
|
|
-- build toc when needed.
|
2012-03-29 10:17:32 +00:00
|
|
|
self:fillToc()
|
2012-09-10 22:36:58 +00:00
|
|
|
self:redrawCurrentPage()
|
2012-03-05 05:15:34 +00:00
|
|
|
end
|
2012-03-10 10:20:03 +00:00
|
|
|
|
|
|
|
-- no table of content
|
|
|
|
if #self.toc == 0 then
|
|
|
|
return ""
|
|
|
|
end
|
2012-03-20 19:15:24 +00:00
|
|
|
|
2012-03-10 10:20:03 +00:00
|
|
|
local pre_entry = self.toc[1]
|
2012-03-05 05:15:34 +00:00
|
|
|
for _k,_v in ipairs(self.toc) do
|
2012-03-10 10:20:03 +00:00
|
|
|
if _v.page > pageno then
|
|
|
|
break
|
2012-03-05 05:15:34 +00:00
|
|
|
end
|
2012-03-10 10:20:03 +00:00
|
|
|
pre_entry = _v
|
2012-03-05 05:15:34 +00:00
|
|
|
end
|
2012-03-29 10:17:32 +00:00
|
|
|
return self:cleanUpTocTitle(pre_entry.title)
|
2012-03-05 05:15:34 +00:00
|
|
|
end
|
|
|
|
|
2012-04-07 14:55:56 +00:00
|
|
|
function UniReader:getTocTitleOfCurrentPage()
|
|
|
|
return self:getTocTitleByPage(self.pageno)
|
2012-03-05 05:15:34 +00:00
|
|
|
end
|
|
|
|
|
2012-04-07 14:55:56 +00:00
|
|
|
function UniReader:gotoTocEntry(entry)
|
|
|
|
self:goto(entry.page)
|
|
|
|
end
|
|
|
|
|
2012-09-08 22:52:04 +00:00
|
|
|
-- expand TOC item to one level down
|
|
|
|
function UniReader:expandTOCItem(xidx, item_no)
|
|
|
|
if string.find(self.toc_cview[item_no], "^+ ") then
|
|
|
|
for i=#self.toc_children[xidx],1,-1 do
|
|
|
|
table.insert(self.toc_cview, item_no+1,
|
|
|
|
self.toc_xview[self.toc_children[xidx][i]])
|
|
|
|
table.insert(self.toc_curidx_to_x, item_no+1,
|
|
|
|
self.toc_children[xidx][i])
|
|
|
|
end
|
|
|
|
self.toc_cview[item_no] = string.gsub(self.toc_cview[item_no], "^+ ", "- ", 1)
|
2012-03-05 05:15:34 +00:00
|
|
|
end
|
2012-09-08 22:52:04 +00:00
|
|
|
end
|
2012-04-07 14:55:56 +00:00
|
|
|
|
2012-09-08 22:52:04 +00:00
|
|
|
-- collapse TOC item AND all its descendants to all levels, recursively
|
|
|
|
function UniReader:collapseTOCItem(xidx, item_no)
|
|
|
|
if string.find(self.toc_cview[item_no], "^- ") then
|
|
|
|
for i=1,#self.toc_children[xidx] do
|
|
|
|
self:collapseTOCItem(self.toc_curidx_to_x[item_no+1], item_no+1)
|
|
|
|
table.remove(self.toc_cview, item_no+1)
|
|
|
|
table.remove(self.toc_curidx_to_x, item_no+1)
|
|
|
|
end
|
|
|
|
self.toc_cview[item_no] = string.gsub(self.toc_cview[item_no], "^- ", "+ ", 1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- calculate the position as index into self.toc_cview[],
|
|
|
|
-- corresponding to the current page.
|
|
|
|
function UniReader:findTOCpos()
|
|
|
|
local pos, found_pos = 0, false
|
|
|
|
|
|
|
|
-- find the index into toc_xview first
|
2012-03-26 18:45:44 +00:00
|
|
|
for k,v in ipairs(self.toc) do
|
2012-09-08 22:52:04 +00:00
|
|
|
if v.page > self.pageno then
|
|
|
|
pos = k - 1
|
2012-09-10 22:36:58 +00:00
|
|
|
found_pos = true
|
2012-09-08 22:52:04 +00:00
|
|
|
break
|
2012-08-29 20:47:16 +00:00
|
|
|
end
|
2012-03-05 01:46:16 +00:00
|
|
|
end
|
2012-04-07 14:55:56 +00:00
|
|
|
|
2012-09-10 22:36:58 +00:00
|
|
|
if not found_pos then
|
2012-09-08 22:52:04 +00:00
|
|
|
pos = #self.toc
|
|
|
|
end
|
2012-04-15 03:02:42 +00:00
|
|
|
|
2012-09-10 22:36:58 +00:00
|
|
|
found_pos = false
|
|
|
|
|
2012-09-08 22:52:04 +00:00
|
|
|
-- now map it to toc_cview[]
|
|
|
|
for k,v in ipairs(self.toc_curidx_to_x) do
|
|
|
|
if v == pos then
|
|
|
|
pos = k
|
|
|
|
found_pos = true
|
|
|
|
break
|
|
|
|
elseif v > pos then
|
|
|
|
pos = k - 1
|
|
|
|
found_pos = true
|
|
|
|
break
|
2012-04-15 03:02:42 +00:00
|
|
|
end
|
2012-03-05 01:46:16 +00:00
|
|
|
end
|
2012-09-08 22:52:04 +00:00
|
|
|
|
|
|
|
if not found_pos then
|
|
|
|
pos = #self.toc_cview
|
|
|
|
end
|
|
|
|
|
|
|
|
return pos
|
|
|
|
end
|
|
|
|
|
|
|
|
function UniReader:showToc()
|
|
|
|
if not self.toc then
|
|
|
|
self:fillToc() -- fill self.toc(title,page,depth) from physical TOC
|
|
|
|
end
|
|
|
|
|
|
|
|
if #self.toc == 0 then
|
2012-09-09 14:00:17 +00:00
|
|
|
showInfoMsgWithDelay("No Table of Contents", 1500, 1)
|
|
|
|
return self:redrawCurrentPage()
|
2012-09-08 22:52:04 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
self.toc_curitem = self:findTOCpos()
|
|
|
|
|
|
|
|
while true do
|
|
|
|
local ret_code = -1
|
|
|
|
toc_menu = SelectMenu:new{
|
|
|
|
menu_title = "Table of Contents (" .. tostring(#self.toc_cview) .. "/" .. tostring(#self.toc) .. " items)",
|
|
|
|
item_array = self.toc_cview,
|
|
|
|
current_entry = self.toc_curitem-1,
|
2012-09-14 08:08:47 +00:00
|
|
|
expandable = self.toc_expandable
|
2012-09-08 22:52:04 +00:00
|
|
|
}
|
|
|
|
ret_code, item_no = toc_menu:choose(0, fb.bb:getHeight())
|
|
|
|
if ret_code then -- normal item selection
|
|
|
|
return self:gotoTocEntry(self.toc[self.toc_curidx_to_x[ret_code]])
|
|
|
|
elseif item_no then -- expand or collapse item
|
|
|
|
local abs_item_no = math.abs(item_no)
|
|
|
|
local xidx = self.toc_curidx_to_x[abs_item_no]
|
|
|
|
if self.toc_children[xidx] then
|
|
|
|
if item_no > 0 then
|
|
|
|
self:expandTOCItem(xidx, item_no)
|
|
|
|
else
|
|
|
|
self:collapseTOCItem(xidx, abs_item_no)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
self.toc_curitem = abs_item_no
|
|
|
|
else -- return from menu via Back
|
|
|
|
return self:redrawCurrentPage()
|
|
|
|
end -- if ret_code
|
|
|
|
end -- while true
|
2012-03-05 01:46:16 +00:00
|
|
|
end
|
|
|
|
|
2012-04-18 09:01:22 +00:00
|
|
|
function UniReader:showJumpHist()
|
2012-03-05 01:46:16 +00:00
|
|
|
local menu_items = {}
|
2012-04-18 09:01:22 +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-03-20 19:15:24 +00:00
|
|
|
table.insert(menu_items,
|
2012-04-18 09:01:22 +00:00
|
|
|
cur_sign..v.datetime.." -> Page "..v.page.." "..v.notes)
|
2012-03-05 01:46:16 +00:00
|
|
|
end
|
2012-04-15 03:02:42 +00:00
|
|
|
|
|
|
|
if #menu_items == 0 then
|
2012-04-18 09:01:22 +00:00
|
|
|
showInfoMsgWithDelay("No jump history found.", 2000, 1)
|
2012-03-05 01:46:16 +00:00
|
|
|
else
|
2012-04-18 09:01:22 +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-15 03:02:42 +00:00
|
|
|
jump_menu = SelectMenu:new{
|
2012-04-18 09:01:22 +00:00
|
|
|
menu_title = "Jump History",
|
2012-04-15 03:02:42 +00:00
|
|
|
item_array = menu_items,
|
|
|
|
}
|
|
|
|
item_no = jump_menu:choose(0, fb.bb:getHeight())
|
2012-04-18 09:01:22 +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)
|
2012-04-30 12:33:10 +00:00
|
|
|
-- set new head if we reached the top of backward stack
|
|
|
|
if self.jump_history.cur == #self.jump_history then
|
|
|
|
self.jump_history.cur = self.jump_history.cur + 1
|
|
|
|
end
|
2012-04-18 09:01:22 +00:00
|
|
|
else
|
|
|
|
self:redrawCurrentPage()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function UniReader:showBookMarks()
|
|
|
|
local menu_items = {}
|
2012-09-09 18:46:24 +00:00
|
|
|
local ret_code, item_no = -1, -1
|
|
|
|
|
2012-04-18 09:01:22 +00:00
|
|
|
-- build menu items
|
|
|
|
for k,v in ipairs(self.bookmarks) do
|
|
|
|
table.insert(menu_items,
|
|
|
|
"Page "..v.page.." "..v.notes.." @ "..v.datetime)
|
|
|
|
end
|
|
|
|
if #menu_items == 0 then
|
2012-09-09 18:46:24 +00:00
|
|
|
return showInfoMsgWithDelay("No bookmarks found", 1500, 1)
|
|
|
|
end
|
|
|
|
while true do
|
|
|
|
bm_menu = SelectMenu:new{
|
2012-04-18 09:01:22 +00:00
|
|
|
menu_title = "Bookmarks",
|
|
|
|
item_array = menu_items,
|
2012-09-09 18:46:24 +00:00
|
|
|
deletable = true,
|
2012-04-18 09:01:22 +00:00
|
|
|
}
|
2012-09-09 18:46:24 +00:00
|
|
|
ret_code, item_no = bm_menu:choose(0, fb.bb:getHeight())
|
|
|
|
if ret_code then -- normal item selection
|
|
|
|
return self:goto(self.bookmarks[ret_code].page)
|
|
|
|
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-15 03:02:42 +00:00
|
|
|
end
|
2012-03-05 01:46:16 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-06-06 07:29:57 +00:00
|
|
|
function UniReader:nextBookMarkedPage()
|
|
|
|
for k,v in ipairs(self.bookmarks) do
|
|
|
|
if self.pageno < v.page then
|
|
|
|
return v
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
|
|
|
function UniReader:prevBookMarkedPage()
|
|
|
|
local pre_item = nil
|
|
|
|
for k,v in ipairs(self.bookmarks) do
|
|
|
|
if self.pageno <= v.page then
|
2012-06-06 12:16:40 +00:00
|
|
|
if not pre_item then
|
|
|
|
break
|
|
|
|
elseif pre_item.page < self.pageno then
|
2012-06-06 07:29:57 +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 07:29:57 +00:00
|
|
|
end
|
|
|
|
|
2012-03-26 18:45:44 +00:00
|
|
|
function UniReader:showHighLight()
|
|
|
|
local menu_items = {}
|
|
|
|
local highlight_dict = {}
|
|
|
|
-- build menu items
|
|
|
|
for k,v in pairs(self.highlight) do
|
|
|
|
if type(k) == "number" then
|
|
|
|
for k1,v1 in ipairs(v) do
|
|
|
|
table.insert(menu_items, v1.text)
|
|
|
|
table.insert(highlight_dict, {page=k, start=v1[1]})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-04-15 03:02:42 +00:00
|
|
|
if #menu_items == 0 then
|
|
|
|
showInfoMsgWithDelay(
|
|
|
|
"No HighLights found.", 2000, 1)
|
|
|
|
else
|
|
|
|
toc_menu = SelectMenu:new{
|
|
|
|
menu_title = "HighLights",
|
|
|
|
item_array = menu_items,
|
|
|
|
}
|
|
|
|
item_no = toc_menu:choose(0, fb.bb:getHeight())
|
|
|
|
if item_no then
|
|
|
|
self:goto(highlight_dict[item_no].page)
|
|
|
|
else
|
|
|
|
self:redrawCurrentPage()
|
|
|
|
end
|
2012-03-26 18:45:44 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-08-26 12:48:51 +00:00
|
|
|
|
|
|
|
function UniReader:searchHighLight(search)
|
|
|
|
|
2012-08-26 14:03:55 +00:00
|
|
|
search = string.lower(search) -- case in-sensitive
|
2012-08-26 12:48:51 +00:00
|
|
|
|
2012-08-26 13:16:08 +00:00
|
|
|
local old_highlight = self.highlight
|
|
|
|
self.highlight = {} -- FIXME show only search results?
|
|
|
|
|
2012-08-26 14:03:55 +00:00
|
|
|
local pageno = self.pageno -- start search at current page
|
|
|
|
local max_pageno = self.doc:getPages()
|
|
|
|
local found = 0
|
|
|
|
|
2012-08-26 14:19:51 +00:00
|
|
|
if self.last_search then
|
|
|
|
Debug("self.last_search",self.last_search)
|
|
|
|
if self.last_search.pageno == self.pageno
|
|
|
|
and self.last_search.search == search
|
|
|
|
then
|
|
|
|
pageno = pageno + 1
|
|
|
|
Debug("continue search for ", search)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-08-26 14:03:55 +00:00
|
|
|
while found == 0 do
|
2012-08-26 13:16:08 +00:00
|
|
|
|
2012-08-26 14:03:55 +00:00
|
|
|
local t = self:getText(pageno)
|
2012-08-26 12:48:51 +00:00
|
|
|
|
2012-08-26 14:03:55 +00:00
|
|
|
if t ~= nil and #t > 0 then
|
2012-08-26 12:48:51 +00:00
|
|
|
|
2012-08-26 14:03:55 +00:00
|
|
|
Debug("self:getText", pageno, #t)
|
|
|
|
|
|
|
|
for i = 1, #t, 1 do
|
|
|
|
for j = 1, #t[i], 1 do
|
|
|
|
local e = t[i][j]
|
|
|
|
if e.word ~= nil then
|
|
|
|
if string.match( string.lower(e.word), search ) then
|
|
|
|
|
|
|
|
if not self.highlight[pageno] then
|
|
|
|
self.highlight[pageno] = {}
|
|
|
|
end
|
2012-08-26 12:48:51 +00:00
|
|
|
|
2012-08-26 14:03:55 +00:00
|
|
|
local hl_item = {
|
|
|
|
text = e.word,
|
|
|
|
[1] = {
|
|
|
|
x0 = e.x0,
|
|
|
|
y0 = e.y0,
|
|
|
|
x1 = e.x1,
|
|
|
|
y1 = e.y1,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
table.insert(self.highlight[pageno], hl_item)
|
|
|
|
found = found + 1
|
|
|
|
end
|
|
|
|
end
|
2012-08-26 12:48:51 +00:00
|
|
|
end
|
|
|
|
end
|
2012-08-26 14:03:55 +00:00
|
|
|
|
|
|
|
else
|
|
|
|
Debug("self:getText", pageno, 'empty')
|
2012-08-26 12:48:51 +00:00
|
|
|
end
|
2012-08-26 14:03:55 +00:00
|
|
|
|
|
|
|
if found > 0 then
|
|
|
|
Debug("self.highlight", self.highlight);
|
|
|
|
self.pageno = pageno
|
|
|
|
else
|
|
|
|
pageno = math.mod( pageno + 1, max_pageno + 1 )
|
|
|
|
Debug("next page", pageno, max_pageno)
|
|
|
|
if pageno == self.pageno then -- wrap around, stop
|
|
|
|
found = -1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-08-26 12:48:51 +00:00
|
|
|
end
|
|
|
|
|
2012-08-29 10:26:25 +00:00
|
|
|
self.highlight.drawer = "marker" -- show as inverted block instead of underline
|
|
|
|
|
2012-08-26 14:03:55 +00:00
|
|
|
self:goto(self.pageno) -- show highlights, remove input
|
2012-08-26 13:16:08 +00:00
|
|
|
if found > 0 then
|
2012-08-26 14:03:55 +00:00
|
|
|
showInfoMsgWithDelay( found.." hits '"..search.."' page "..self.pageno, 2000, 1)
|
2012-08-26 14:19:51 +00:00
|
|
|
self.last_search = {
|
|
|
|
pageno = self.pageno,
|
|
|
|
search = search,
|
|
|
|
hits = found,
|
|
|
|
}
|
2012-08-26 13:16:08 +00:00
|
|
|
else
|
2012-08-26 14:03:55 +00:00
|
|
|
showInfoMsgWithDelay( "'"..search.."' not found in document", 2000, 1)
|
2012-08-26 13:16:08 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
self.highlight = old_highlight -- will not remove search highlights until page refresh
|
2012-08-26 12:48:51 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2012-03-29 10:17:32 +00:00
|
|
|
-- used in UniReader:showMenu()
|
|
|
|
function UniReader:_drawReadingInfo()
|
2012-04-09 07:42:19 +00:00
|
|
|
local width, height = G_width, G_height
|
2012-03-10 08:41:23 +00:00
|
|
|
local load_percent = (self.pageno / self.doc:getPages())
|
storing rcountmax; user-configurable zoom step & pan steps, etc
1. In order to close issue #59, I've introduced user-configurable values for panning steps - for X- & Y-axis, separately. Now panning is called by pressing fiveway without mod_keys. When one presses Shift+FW, he/she changes panning steps in the following way - Shift-Left/Right = decrease / increase X-panning step (divide or multiply on factor 2), Shift-Up/Down = increase / decrease Y-panning step. The lowest value for panning steps is set 1. Both parameters, shift_x & shift_y, are saved to local settings (i.e. history file).
2. Manual zoom step was also made user-configurable. So, instead of two old zooming functions (with fixed 10% and 20%-steps), I made one function to zoom (Shift+<>), while the other (Alt+<>) changes the zoom step downto minimum 1%.
3. Fresh introduced function to change parameter rcountmax was added by storing rcountmax to both setting files - global settings & local ones (i.e. history file) - so that the rcountmax-priority (from low to high) is the following: default rcountmax=5 < its value in global settings < rcountmax stored for each concrete document.
3. Dirty, the extention-based hack to avoid reading not crengine-related parameters stored in history files. TODO: one has to finally introduce loadSpecialSettings() & readSpecialSettings() for PDFReader & DJVUReader and to store therein the reader-specific parameters (like globalgamma, bbox, globalzoom, globalzoom_mode; render_mode = for djvu-files only, etc.)
4. Some lua-code cosmetics (to make code more readable); for example: "self.pan_margin = settings:readSetting("pan_margin") or self.pan_margin" instead of
"local pan_margin = settings:readSetting("pan_margin")
if pan_margin then
self.pan_margin = pan_margin
end"
5. Fix for the today's tigran123 fix: issue #246 (details are included). Added InfoMessage:show() to inform most impatient users that the reader tries to redraw new zoo mode.
6. The fontface for the reading info (called by 'Menu') is restored to be in accordance with original intentions and with the same fontface in crereader.lua - namely, Font:getFace("rifont", 20)
7. Moved the exit hotkeys (Alt+Back & Home) to the end of hotkey list.
2012-09-03 19:23:06 +00:00
|
|
|
-- changed to be the same font group as originaly intended
|
|
|
|
local face = Font:getFace("rifont", 20)
|
2012-03-10 08:41:23 +00:00
|
|
|
|
2012-03-31 16:57:22 +00:00
|
|
|
-- display memory on top of page
|
|
|
|
fb.bb:paintRect(0, 0, width, 15+6*2, 0)
|
2012-04-09 17:04:26 +00:00
|
|
|
renderUtf8Text(fb.bb, 10, 15+6, face,
|
2012-08-27 14:27:51 +00:00
|
|
|
"M: "..
|
2012-03-31 16:57:22 +00:00
|
|
|
math.ceil( self.cache_current_memsize / 1024 ).."/"..math.ceil( self.cache_max_memsize / 1024 )..
|
2012-08-27 14:27:51 +00:00
|
|
|
" "..math.ceil( self.doc:getCacheSize() / 1024 ).."/"..math.ceil( self.cache_document_size / 1024 ).."k "..os.date("%a %d %b %Y %T").." ["..BatteryLevel().."]",
|
2012-03-31 16:57:22 +00:00
|
|
|
true)
|
2012-03-10 08:41:23 +00:00
|
|
|
|
2012-03-31 16:57:22 +00:00
|
|
|
-- display reading progress on bottom of page
|
|
|
|
local ypos = height - 50
|
|
|
|
fb.bb:paintRect(0, ypos, width, 50, 0)
|
2012-03-10 08:41:23 +00:00
|
|
|
ypos = ypos + 15
|
2012-04-07 14:55:56 +00:00
|
|
|
local cur_section = self:getTocTitleOfCurrentPage()
|
2012-03-10 08:41:23 +00:00
|
|
|
if cur_section ~= "" then
|
2012-08-27 14:27:51 +00:00
|
|
|
cur_section = "Sec: "..cur_section
|
2012-03-10 08:41:23 +00:00
|
|
|
end
|
2012-04-09 17:04:26 +00:00
|
|
|
renderUtf8Text(fb.bb, 10, ypos+6, face,
|
2012-03-10 08:41:23 +00:00
|
|
|
"Page: "..self.pageno.."/"..self.doc:getPages()..
|
|
|
|
" "..cur_section, true)
|
|
|
|
|
|
|
|
ypos = ypos + 15
|
2012-03-20 19:15:24 +00:00
|
|
|
blitbuffer.progressBar(fb.bb, 10, ypos, width-20, 15,
|
2012-03-10 08:41:23 +00:00
|
|
|
5, 4, load_percent, 8)
|
2012-03-29 10:17:32 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function UniReader:showMenu()
|
|
|
|
self:_drawReadingInfo()
|
|
|
|
|
2012-03-10 08:41:23 +00:00
|
|
|
fb:refresh(1)
|
|
|
|
while 1 do
|
2012-04-13 02:37:50 +00:00
|
|
|
local ev = input.saveWaitForEvent()
|
2012-03-10 08:41:23 +00:00
|
|
|
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
|
2012-03-31 11:38:33 +00:00
|
|
|
elseif ev.code == KEY_C then
|
|
|
|
self.doc:cleanCache()
|
2012-03-10 08:41:23 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-03-20 19:15:24 +00:00
|
|
|
function UniReader:oddEven(number)
|
2012-06-03 22:49:23 +00:00
|
|
|
Debug("oddEven", number)
|
2012-03-06 23:26:56 +00:00
|
|
|
if number % 2 == 1 then
|
|
|
|
return "odd"
|
|
|
|
else
|
|
|
|
return "even"
|
|
|
|
end
|
|
|
|
end
|
2012-03-05 01:46:16 +00:00
|
|
|
|
|
|
|
-- wait for input and handle it
|
2012-03-20 19:15:24 +00:00
|
|
|
function UniReader:inputLoop()
|
2012-03-05 01:46:16 +00:00
|
|
|
local keep_running = true
|
|
|
|
while 1 do
|
2012-04-12 19:00:44 +00:00
|
|
|
local ev = input.saveWaitForEvent()
|
2012-03-05 01:46:16 +00:00
|
|
|
ev.code = adjustKeyEvents(ev)
|
2012-04-27 18:37:07 +00:00
|
|
|
if ev.type == EV_KEY and ev.value ~= EVENT_VALUE_KEY_RELEASE then
|
2012-03-05 01:46:16 +00:00
|
|
|
local secs, usecs = util.gettime()
|
2012-03-20 19:15:24 +00:00
|
|
|
keydef = Keydef:new(ev.code, getKeyModifier())
|
2012-06-03 22:49:23 +00:00
|
|
|
Debug("key pressed:", tostring(keydef))
|
2012-03-20 19:15:24 +00:00
|
|
|
command = self.commands:getByKeydef(keydef)
|
2012-03-10 09:28:54 +00:00
|
|
|
if command ~= nil then
|
2012-06-03 22:49:23 +00:00
|
|
|
Debug("command to execute:", tostring(command))
|
2012-03-10 09:28:54 +00:00
|
|
|
ret_code = command.func(self,keydef)
|
|
|
|
if ret_code == "break" then
|
|
|
|
break;
|
|
|
|
end
|
|
|
|
else
|
2012-06-03 22:49:23 +00:00
|
|
|
Debug("command not found:", tostring(command))
|
2012-03-05 01:46:16 +00:00
|
|
|
end
|
2012-03-20 19:15:24 +00:00
|
|
|
|
2012-03-05 01:46:16 +00:00
|
|
|
local nsecs, nusecs = util.gettime()
|
|
|
|
local dur = (nsecs - secs) * 1000000 + nusecs - usecs
|
2012-06-03 22:49:23 +00:00
|
|
|
Debug("E: T="..ev.type, " V="..ev.value, " C="..ev.code, " DUR=", dur)
|
2012-04-27 18:38:24 +00:00
|
|
|
|
|
|
|
if ev.value == EVENT_VALUE_KEY_REPEAT then
|
|
|
|
self.rcount = 0
|
2012-06-03 22:49:23 +00:00
|
|
|
Debug("prevent full screen refresh", self.rcount)
|
2012-04-27 18:38:24 +00:00
|
|
|
end
|
|
|
|
else
|
2012-06-03 22:49:23 +00:00
|
|
|
Debug("ignored ev ",ev)
|
2012-03-05 01:46:16 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-03-05 05:15:34 +00:00
|
|
|
-- do clean up stuff
|
2012-03-20 19:15:24 +00:00
|
|
|
self:clearCache()
|
2012-03-05 05:15:34 +00:00
|
|
|
self.toc = nil
|
2012-09-14 08:08:47 +00:00
|
|
|
self.toc_expandable = false
|
2012-09-08 22:52:04 +00:00
|
|
|
self.toc_children = nil
|
|
|
|
self.toc_curitem = 0
|
|
|
|
self.toc_xview = nil
|
|
|
|
self.toc_cview = nil
|
|
|
|
self.toc_curidx_to_x = nil
|
|
|
|
self.toc_xidx_to_cur = nil
|
2012-03-05 01:46:16 +00:00
|
|
|
if self.doc ~= nil then
|
|
|
|
self.doc:close()
|
|
|
|
end
|
|
|
|
if self.settings ~= nil then
|
2012-03-30 05:07:48 +00:00
|
|
|
self:saveLastPageOrPos()
|
2012-04-18 09:29:27 +00:00
|
|
|
self.settings:saveSetting("jump_history", self.jump_history)
|
|
|
|
self.settings:saveSetting("bookmarks", self.bookmarks)
|
storing rcountmax; user-configurable zoom step & pan steps, etc
1. In order to close issue #59, I've introduced user-configurable values for panning steps - for X- & Y-axis, separately. Now panning is called by pressing fiveway without mod_keys. When one presses Shift+FW, he/she changes panning steps in the following way - Shift-Left/Right = decrease / increase X-panning step (divide or multiply on factor 2), Shift-Up/Down = increase / decrease Y-panning step. The lowest value for panning steps is set 1. Both parameters, shift_x & shift_y, are saved to local settings (i.e. history file).
2. Manual zoom step was also made user-configurable. So, instead of two old zooming functions (with fixed 10% and 20%-steps), I made one function to zoom (Shift+<>), while the other (Alt+<>) changes the zoom step downto minimum 1%.
3. Fresh introduced function to change parameter rcountmax was added by storing rcountmax to both setting files - global settings & local ones (i.e. history file) - so that the rcountmax-priority (from low to high) is the following: default rcountmax=5 < its value in global settings < rcountmax stored for each concrete document.
3. Dirty, the extention-based hack to avoid reading not crengine-related parameters stored in history files. TODO: one has to finally introduce loadSpecialSettings() & readSpecialSettings() for PDFReader & DJVUReader and to store therein the reader-specific parameters (like globalgamma, bbox, globalzoom, globalzoom_mode; render_mode = for djvu-files only, etc.)
4. Some lua-code cosmetics (to make code more readable); for example: "self.pan_margin = settings:readSetting("pan_margin") or self.pan_margin" instead of
"local pan_margin = settings:readSetting("pan_margin")
if pan_margin then
self.pan_margin = pan_margin
end"
5. Fix for the today's tigran123 fix: issue #246 (details are included). Added InfoMessage:show() to inform most impatient users that the reader tries to redraw new zoo mode.
6. The fontface for the reading info (called by 'Menu') is restored to be in accordance with original intentions and with the same fontface in crereader.lua - namely, Font:getFace("rifont", 20)
7. Moved the exit hotkeys (Alt+Back & Home) to the end of hotkey list.
2012-09-03 19:23:06 +00:00
|
|
|
self.settings:saveSetting("highlight", self.highlight)
|
|
|
|
-- other parameters are reader-specific --> @TODO: move to a proper place, like saveSpecialSettings()
|
|
|
|
self.settings:saveSetting("gamma", self.globalgamma)
|
2012-04-18 09:29:27 +00:00
|
|
|
self.settings:saveSetting("bbox", self.bbox)
|
|
|
|
self.settings:saveSetting("globalzoom", self.globalzoom)
|
2012-04-21 04:14:35 +00:00
|
|
|
self.settings:saveSetting("globalzoom_mode", self.globalzoom_mode)
|
storing rcountmax; user-configurable zoom step & pan steps, etc
1. In order to close issue #59, I've introduced user-configurable values for panning steps - for X- & Y-axis, separately. Now panning is called by pressing fiveway without mod_keys. When one presses Shift+FW, he/she changes panning steps in the following way - Shift-Left/Right = decrease / increase X-panning step (divide or multiply on factor 2), Shift-Up/Down = increase / decrease Y-panning step. The lowest value for panning steps is set 1. Both parameters, shift_x & shift_y, are saved to local settings (i.e. history file).
2. Manual zoom step was also made user-configurable. So, instead of two old zooming functions (with fixed 10% and 20%-steps), I made one function to zoom (Shift+<>), while the other (Alt+<>) changes the zoom step downto minimum 1%.
3. Fresh introduced function to change parameter rcountmax was added by storing rcountmax to both setting files - global settings & local ones (i.e. history file) - so that the rcountmax-priority (from low to high) is the following: default rcountmax=5 < its value in global settings < rcountmax stored for each concrete document.
3. Dirty, the extention-based hack to avoid reading not crengine-related parameters stored in history files. TODO: one has to finally introduce loadSpecialSettings() & readSpecialSettings() for PDFReader & DJVUReader and to store therein the reader-specific parameters (like globalgamma, bbox, globalzoom, globalzoom_mode; render_mode = for djvu-files only, etc.)
4. Some lua-code cosmetics (to make code more readable); for example: "self.pan_margin = settings:readSetting("pan_margin") or self.pan_margin" instead of
"local pan_margin = settings:readSetting("pan_margin")
if pan_margin then
self.pan_margin = pan_margin
end"
5. Fix for the today's tigran123 fix: issue #246 (details are included). Added InfoMessage:show() to inform most impatient users that the reader tries to redraw new zoo mode.
6. The fontface for the reading info (called by 'Menu') is restored to be in accordance with original intentions and with the same fontface in crereader.lua - namely, Font:getFace("rifont", 20)
7. Moved the exit hotkeys (Alt+Back & Home) to the end of hotkey list.
2012-09-03 19:23:06 +00:00
|
|
|
self.settings:saveSetting("render_mode", self.render_mode) -- djvu-related only
|
2012-09-08 22:52:04 +00:00
|
|
|
--[[ the following parameters were already stored when user changed defaults
|
storing rcountmax; user-configurable zoom step & pan steps, etc
1. In order to close issue #59, I've introduced user-configurable values for panning steps - for X- & Y-axis, separately. Now panning is called by pressing fiveway without mod_keys. When one presses Shift+FW, he/she changes panning steps in the following way - Shift-Left/Right = decrease / increase X-panning step (divide or multiply on factor 2), Shift-Up/Down = increase / decrease Y-panning step. The lowest value for panning steps is set 1. Both parameters, shift_x & shift_y, are saved to local settings (i.e. history file).
2. Manual zoom step was also made user-configurable. So, instead of two old zooming functions (with fixed 10% and 20%-steps), I made one function to zoom (Shift+<>), while the other (Alt+<>) changes the zoom step downto minimum 1%.
3. Fresh introduced function to change parameter rcountmax was added by storing rcountmax to both setting files - global settings & local ones (i.e. history file) - so that the rcountmax-priority (from low to high) is the following: default rcountmax=5 < its value in global settings < rcountmax stored for each concrete document.
3. Dirty, the extention-based hack to avoid reading not crengine-related parameters stored in history files. TODO: one has to finally introduce loadSpecialSettings() & readSpecialSettings() for PDFReader & DJVUReader and to store therein the reader-specific parameters (like globalgamma, bbox, globalzoom, globalzoom_mode; render_mode = for djvu-files only, etc.)
4. Some lua-code cosmetics (to make code more readable); for example: "self.pan_margin = settings:readSetting("pan_margin") or self.pan_margin" instead of
"local pan_margin = settings:readSetting("pan_margin")
if pan_margin then
self.pan_margin = pan_margin
end"
5. Fix for the today's tigran123 fix: issue #246 (details are included). Added InfoMessage:show() to inform most impatient users that the reader tries to redraw new zoo mode.
6. The fontface for the reading info (called by 'Menu') is restored to be in accordance with original intentions and with the same fontface in crereader.lua - namely, Font:getFace("rifont", 20)
7. Moved the exit hotkeys (Alt+Back & Home) to the end of hotkey list.
2012-09-03 19:23:06 +00:00
|
|
|
self.settings:saveSetting("shift_x", self.shift_x)
|
|
|
|
self.settings:saveSetting("shift_y", self.shift_y)
|
|
|
|
self.settings:saveSetting("step_manual_zoom", self.step_manual_zoom)
|
|
|
|
self.settings:saveSetting("rcountmax", self.rcountmax)
|
|
|
|
]]
|
2012-04-06 11:11:18 +00:00
|
|
|
self:saveSpecialSettings()
|
2012-03-05 01:46:16 +00:00
|
|
|
self.settings:close()
|
|
|
|
end
|
|
|
|
|
|
|
|
return keep_running
|
|
|
|
end
|
2012-03-10 09:28:54 +00:00
|
|
|
|
|
|
|
-- command definitions
|
2012-03-20 19:15:24 +00:00
|
|
|
function UniReader:addAllCommands()
|
2012-03-13 21:51:25 +00:00
|
|
|
self.commands = Commands:new()
|
2012-04-20 02:16:14 +00:00
|
|
|
self.commands:addGroup("< >",{
|
|
|
|
Keydef:new(KEY_PGBCK,nil),Keydef:new(KEY_LPGBCK,nil),
|
|
|
|
Keydef:new(KEY_PGFWD,nil),Keydef:new(KEY_LPGFWD,nil)},
|
2012-04-15 14:07:39 +00:00
|
|
|
"previous/next page",
|
|
|
|
function(unireader,keydef)
|
2012-04-17 09:47:19 +00:00
|
|
|
unireader:goto(
|
2012-04-19 05:57:30 +00:00
|
|
|
(keydef.keycode == KEY_PGBCK or keydef.keycode == KEY_LPGBCK)
|
2012-04-17 09:47:19 +00:00
|
|
|
and unireader:prevView() or unireader:nextView())
|
2012-03-20 19:15:24 +00:00
|
|
|
end)
|
2012-09-05 17:54:49 +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)},
|
storing rcountmax; user-configurable zoom step & pan steps, etc
1. In order to close issue #59, I've introduced user-configurable values for panning steps - for X- & Y-axis, separately. Now panning is called by pressing fiveway without mod_keys. When one presses Shift+FW, he/she changes panning steps in the following way - Shift-Left/Right = decrease / increase X-panning step (divide or multiply on factor 2), Shift-Up/Down = increase / decrease Y-panning step. The lowest value for panning steps is set 1. Both parameters, shift_x & shift_y, are saved to local settings (i.e. history file).
2. Manual zoom step was also made user-configurable. So, instead of two old zooming functions (with fixed 10% and 20%-steps), I made one function to zoom (Shift+<>), while the other (Alt+<>) changes the zoom step downto minimum 1%.
3. Fresh introduced function to change parameter rcountmax was added by storing rcountmax to both setting files - global settings & local ones (i.e. history file) - so that the rcountmax-priority (from low to high) is the following: default rcountmax=5 < its value in global settings < rcountmax stored for each concrete document.
3. Dirty, the extention-based hack to avoid reading not crengine-related parameters stored in history files. TODO: one has to finally introduce loadSpecialSettings() & readSpecialSettings() for PDFReader & DJVUReader and to store therein the reader-specific parameters (like globalgamma, bbox, globalzoom, globalzoom_mode; render_mode = for djvu-files only, etc.)
4. Some lua-code cosmetics (to make code more readable); for example: "self.pan_margin = settings:readSetting("pan_margin") or self.pan_margin" instead of
"local pan_margin = settings:readSetting("pan_margin")
if pan_margin then
self.pan_margin = pan_margin
end"
5. Fix for the today's tigran123 fix: issue #246 (details are included). Added InfoMessage:show() to inform most impatient users that the reader tries to redraw new zoo mode.
6. The fontface for the reading info (called by 'Menu') is restored to be in accordance with original intentions and with the same fontface in crereader.lua - namely, Font:getFace("rifont", 20)
7. Moved the exit hotkeys (Alt+Back & Home) to the end of hotkey list.
2012-09-03 19:23:06 +00:00
|
|
|
"zoom out/in ".. self.step_manual_zoom .."% ",
|
|
|
|
function(unireader,keydef)
|
|
|
|
local is_zoom_out = (keydef.keycode == KEY_PGBCK or keydef.keycode == KEY_LPGBCK)
|
|
|
|
unireader:setGlobalZoom(unireader.globalzoom_orig * (1 + (is_zoom_out and -1 or 1)*unireader.step_manual_zoom/100))
|
|
|
|
end)
|
|
|
|
-- NuPogodi, 03.09.12: make zoom step user-configurable
|
2012-09-05 17:54:49 +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)},
|
storing rcountmax; user-configurable zoom step & pan steps, etc
1. In order to close issue #59, I've introduced user-configurable values for panning steps - for X- & Y-axis, separately. Now panning is called by pressing fiveway without mod_keys. When one presses Shift+FW, he/she changes panning steps in the following way - Shift-Left/Right = decrease / increase X-panning step (divide or multiply on factor 2), Shift-Up/Down = increase / decrease Y-panning step. The lowest value for panning steps is set 1. Both parameters, shift_x & shift_y, are saved to local settings (i.e. history file).
2. Manual zoom step was also made user-configurable. So, instead of two old zooming functions (with fixed 10% and 20%-steps), I made one function to zoom (Shift+<>), while the other (Alt+<>) changes the zoom step downto minimum 1%.
3. Fresh introduced function to change parameter rcountmax was added by storing rcountmax to both setting files - global settings & local ones (i.e. history file) - so that the rcountmax-priority (from low to high) is the following: default rcountmax=5 < its value in global settings < rcountmax stored for each concrete document.
3. Dirty, the extention-based hack to avoid reading not crengine-related parameters stored in history files. TODO: one has to finally introduce loadSpecialSettings() & readSpecialSettings() for PDFReader & DJVUReader and to store therein the reader-specific parameters (like globalgamma, bbox, globalzoom, globalzoom_mode; render_mode = for djvu-files only, etc.)
4. Some lua-code cosmetics (to make code more readable); for example: "self.pan_margin = settings:readSetting("pan_margin") or self.pan_margin" instead of
"local pan_margin = settings:readSetting("pan_margin")
if pan_margin then
self.pan_margin = pan_margin
end"
5. Fix for the today's tigran123 fix: issue #246 (details are included). Added InfoMessage:show() to inform most impatient users that the reader tries to redraw new zoo mode.
6. The fontface for the reading info (called by 'Menu') is restored to be in accordance with original intentions and with the same fontface in crereader.lua - namely, Font:getFace("rifont", 20)
7. Moved the exit hotkeys (Alt+Back & Home) to the end of hotkey list.
2012-09-03 19:23:06 +00:00
|
|
|
"decrease/increase zoom step",
|
2012-04-15 14:07:39 +00:00
|
|
|
function(unireader,keydef)
|
storing rcountmax; user-configurable zoom step & pan steps, etc
1. In order to close issue #59, I've introduced user-configurable values for panning steps - for X- & Y-axis, separately. Now panning is called by pressing fiveway without mod_keys. When one presses Shift+FW, he/she changes panning steps in the following way - Shift-Left/Right = decrease / increase X-panning step (divide or multiply on factor 2), Shift-Up/Down = increase / decrease Y-panning step. The lowest value for panning steps is set 1. Both parameters, shift_x & shift_y, are saved to local settings (i.e. history file).
2. Manual zoom step was also made user-configurable. So, instead of two old zooming functions (with fixed 10% and 20%-steps), I made one function to zoom (Shift+<>), while the other (Alt+<>) changes the zoom step downto minimum 1%.
3. Fresh introduced function to change parameter rcountmax was added by storing rcountmax to both setting files - global settings & local ones (i.e. history file) - so that the rcountmax-priority (from low to high) is the following: default rcountmax=5 < its value in global settings < rcountmax stored for each concrete document.
3. Dirty, the extention-based hack to avoid reading not crengine-related parameters stored in history files. TODO: one has to finally introduce loadSpecialSettings() & readSpecialSettings() for PDFReader & DJVUReader and to store therein the reader-specific parameters (like globalgamma, bbox, globalzoom, globalzoom_mode; render_mode = for djvu-files only, etc.)
4. Some lua-code cosmetics (to make code more readable); for example: "self.pan_margin = settings:readSetting("pan_margin") or self.pan_margin" instead of
"local pan_margin = settings:readSetting("pan_margin")
if pan_margin then
self.pan_margin = pan_margin
end"
5. Fix for the today's tigran123 fix: issue #246 (details are included). Added InfoMessage:show() to inform most impatient users that the reader tries to redraw new zoo mode.
6. The fontface for the reading info (called by 'Menu') is restored to be in accordance with original intentions and with the same fontface in crereader.lua - namely, Font:getFace("rifont", 20)
7. Moved the exit hotkeys (Alt+Back & Home) to the end of hotkey list.
2012-09-03 19:23:06 +00:00
|
|
|
if keydef.keycode == KEY_PGFWD or keydef.keycode == KEY_LPGFWD then
|
|
|
|
unireader.step_manual_zoom = unireader.step_manual_zoom * 2
|
|
|
|
self.settings:saveSetting("step_manual_zoom", self.step_manual_zoom)
|
|
|
|
--showInfoMsgWithDelay("New zoom step is "..unireader.step_manual_zoom.."%. ", 2000, 1)
|
|
|
|
else
|
|
|
|
local minstep = 1
|
|
|
|
if unireader.step_manual_zoom > 2*minstep then
|
|
|
|
unireader.step_manual_zoom = unireader.step_manual_zoom / 2
|
|
|
|
self.settings:saveSetting("step_manual_zoom", self.step_manual_zoom)
|
|
|
|
--showInfoMsgWithDelay("New zoom step is "..unireader.step_manual_zoom.."%. ", 2000, 1)
|
|
|
|
else
|
|
|
|
showInfoMsgWithDelay("Minimum zoom step is "..minstep.."%. ", 2000, 1)
|
|
|
|
end
|
|
|
|
end
|
2012-03-10 09:28:54 +00:00
|
|
|
end)
|
2012-04-15 14:07:39 +00:00
|
|
|
self.commands:add(KEY_BACK,nil,"Back",
|
2012-04-18 09:01:22 +00:00
|
|
|
"go backward in jump history",
|
|
|
|
function(unireader)
|
2012-04-30 12:33:10 +00:00
|
|
|
local prev_jump_no = 0
|
|
|
|
if unireader.jump_history.cur > #unireader.jump_history then
|
|
|
|
-- if cur points to head, put current page in history
|
|
|
|
unireader:addJump(self.pageno)
|
|
|
|
prev_jump_no = unireader.jump_history.cur - 2
|
|
|
|
else
|
|
|
|
prev_jump_no = unireader.jump_history.cur - 1
|
|
|
|
end
|
|
|
|
|
2012-04-18 09:01:22 +00:00
|
|
|
if prev_jump_no >= 1 then
|
|
|
|
unireader.jump_history.cur = prev_jump_no
|
|
|
|
unireader:goto(unireader.jump_history[prev_jump_no].page, true)
|
|
|
|
else
|
|
|
|
showInfoMsgWithDelay("Already first jump!", 2000, 1)
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
self.commands:add(KEY_BACK,MOD_SHIFT,"Back",
|
|
|
|
"go forward in jump history",
|
2012-03-10 09:28:54 +00:00
|
|
|
function(unireader)
|
2012-04-18 09:01:22 +00:00
|
|
|
local next_jump_no = unireader.jump_history.cur + 1
|
|
|
|
if next_jump_no <= #self.jump_history then
|
|
|
|
unireader.jump_history.cur = next_jump_no
|
|
|
|
unireader:goto(unireader.jump_history[next_jump_no].page, true)
|
2012-04-30 12:33:10 +00:00
|
|
|
-- set new head if we reached the top of backward stack
|
|
|
|
if unireader.jump_history.cur == #unireader.jump_history then
|
|
|
|
unireader.jump_history.cur = unireader.jump_history.cur + 1
|
|
|
|
end
|
2012-04-18 09:01:22 +00:00
|
|
|
else
|
|
|
|
showInfoMsgWithDelay("Already last jump!", 2000, 1)
|
2012-03-10 09:28:54 +00:00
|
|
|
end
|
2012-03-20 19:15:24 +00:00
|
|
|
end)
|
storing rcountmax; user-configurable zoom step & pan steps, etc
1. In order to close issue #59, I've introduced user-configurable values for panning steps - for X- & Y-axis, separately. Now panning is called by pressing fiveway without mod_keys. When one presses Shift+FW, he/she changes panning steps in the following way - Shift-Left/Right = decrease / increase X-panning step (divide or multiply on factor 2), Shift-Up/Down = increase / decrease Y-panning step. The lowest value for panning steps is set 1. Both parameters, shift_x & shift_y, are saved to local settings (i.e. history file).
2. Manual zoom step was also made user-configurable. So, instead of two old zooming functions (with fixed 10% and 20%-steps), I made one function to zoom (Shift+<>), while the other (Alt+<>) changes the zoom step downto minimum 1%.
3. Fresh introduced function to change parameter rcountmax was added by storing rcountmax to both setting files - global settings & local ones (i.e. history file) - so that the rcountmax-priority (from low to high) is the following: default rcountmax=5 < its value in global settings < rcountmax stored for each concrete document.
3. Dirty, the extention-based hack to avoid reading not crengine-related parameters stored in history files. TODO: one has to finally introduce loadSpecialSettings() & readSpecialSettings() for PDFReader & DJVUReader and to store therein the reader-specific parameters (like globalgamma, bbox, globalzoom, globalzoom_mode; render_mode = for djvu-files only, etc.)
4. Some lua-code cosmetics (to make code more readable); for example: "self.pan_margin = settings:readSetting("pan_margin") or self.pan_margin" instead of
"local pan_margin = settings:readSetting("pan_margin")
if pan_margin then
self.pan_margin = pan_margin
end"
5. Fix for the today's tigran123 fix: issue #246 (details are included). Added InfoMessage:show() to inform most impatient users that the reader tries to redraw new zoo mode.
6. The fontface for the reading info (called by 'Menu') is restored to be in accordance with original intentions and with the same fontface in crereader.lua - namely, Font:getFace("rifont", 20)
7. Moved the exit hotkeys (Alt+Back & Home) to the end of hotkey list.
2012-09-03 19:23:06 +00:00
|
|
|
-- NuPogodi, 03.09.12 : moved the exit commands from here to the end of hotkey list
|
2012-04-15 14:07:39 +00:00
|
|
|
self.commands:addGroup("vol-/+",{Keydef:new(KEY_VPLUS,nil),Keydef:new(KEY_VMINUS,nil)},
|
|
|
|
"decrease/increase gamma 25%",
|
|
|
|
function(unireader,keydef)
|
|
|
|
unireader:modifyGamma(keydef.keycode==KEY_VPLUS and 1.25 or 0.8)
|
2012-03-10 09:28:54 +00:00
|
|
|
end)
|
|
|
|
--numeric key group
|
|
|
|
local numeric_keydefs = {}
|
2012-03-13 21:51:25 +00:00
|
|
|
for i=1,10 do numeric_keydefs[i]=Keydef:new(KEY_1+i-1,nil,tostring(i%10)) end
|
2012-04-15 14:07:39 +00:00
|
|
|
self.commands:addGroup("[1, 2 .. 9, 0]",numeric_keydefs,
|
|
|
|
"jump to 10%, 20% .. 90%, 100% of document",
|
2012-03-10 09:28:54 +00:00
|
|
|
function(unireader,keydef)
|
2012-06-03 22:49:23 +00:00
|
|
|
Debug('jump to page:', math.max(math.floor(unireader.doc:getPages()*(keydef.keycode-KEY_1)/9),1), '/', unireader.doc:getPages())
|
2012-03-10 09:28:54 +00:00
|
|
|
unireader:goto(math.max(math.floor(unireader.doc:getPages()*(keydef.keycode-KEY_1)/9),1))
|
2012-03-20 19:15:24 +00:00
|
|
|
end)
|
2012-03-13 21:51:25 +00:00
|
|
|
-- end numeric keys
|
unireader: refresh frequency; zoommode-menu, etc.
1. Restored default value rcountmax=5; the function to make manual full screen refresh is no more silent; at first, it asks user to set a number of partial refreshes (rcountmax) and then performs full refresh. TODO: saving parameter 'rcountmax' in the global reader settings (or separately, for each document).
2. The hotkey 'R' and the respective function toggle_render_mode() for djvu-documents are moved to djvureader.
3. Added hotkey 'M' and the respective function that calls menu with zoom-modes. Probably, one needs to remove unappropriate items, like "Fit zoom to page" and, less probably, the hotkeys (A, S, D, F and ^A, ^S, ^D, ^F) to set zoom-mode directly.
2012-09-01 10:39:14 +00:00
|
|
|
|
|
|
|
-- function calls menu to visualize and/or to switch zoom mode
|
|
|
|
self.commands:add(KEY_M, nil, "M",
|
|
|
|
"select zoom mode",
|
|
|
|
function(unireader)
|
|
|
|
local mode_list = {
|
|
|
|
"Zoom by value", -- ZOOM_BY_VALUE = 0, remove?
|
|
|
|
"Fit zoom to page", -- A ZOOM_FIT_TO_PAGE = -1,
|
|
|
|
"Fit zoom to page width", -- S ZOOM_FIT_TO_PAGE_WIDTH = -2,
|
|
|
|
"Fit zoom to page height", -- D ZOOM_FIT_TO_PAGE_HEIGHT = -3,
|
|
|
|
"Fit zoom to content", -- ^A ZOOM_FIT_TO_CONTENT = -4,
|
|
|
|
"Fit zoom to content width", -- ^S ZOOM_FIT_TO_CONTENT_WIDTH = -5,
|
|
|
|
"Fit zoom to content height", -- ^D ZOOM_FIT_TO_CONTENT_HEIGHT = -6,
|
|
|
|
"Fit zoom to content width with panoraming", -- ZOOM_FIT_TO_CONTENT_WIDTH_PAN = -7, remove?
|
|
|
|
"Fit zoom to content height with panoraming", -- ZOOM_FIT_TO_CONTENT_HEIGHT_PAN = -8, remove?
|
|
|
|
"Fit zoom to content half-width with margin", -- F ZOOM_FIT_TO_CONTENT_HALF_WIDTH_MARGIN = -9,
|
|
|
|
"Fit zoom to content half-width" -- ^F ZOOM_FIT_TO_CONTENT_HALF_WIDTH = -10,
|
|
|
|
}
|
|
|
|
local zoom_menu = SelectMenu:new{
|
|
|
|
menu_title = "Select mode to zoom pages",
|
|
|
|
item_array = mode_list,
|
|
|
|
current_entry = - unireader.globalzoom_mode
|
|
|
|
}
|
|
|
|
local re = zoom_menu:choose(0, G_height)
|
storing rcountmax; user-configurable zoom step & pan steps, etc
1. In order to close issue #59, I've introduced user-configurable values for panning steps - for X- & Y-axis, separately. Now panning is called by pressing fiveway without mod_keys. When one presses Shift+FW, he/she changes panning steps in the following way - Shift-Left/Right = decrease / increase X-panning step (divide or multiply on factor 2), Shift-Up/Down = increase / decrease Y-panning step. The lowest value for panning steps is set 1. Both parameters, shift_x & shift_y, are saved to local settings (i.e. history file).
2. Manual zoom step was also made user-configurable. So, instead of two old zooming functions (with fixed 10% and 20%-steps), I made one function to zoom (Shift+<>), while the other (Alt+<>) changes the zoom step downto minimum 1%.
3. Fresh introduced function to change parameter rcountmax was added by storing rcountmax to both setting files - global settings & local ones (i.e. history file) - so that the rcountmax-priority (from low to high) is the following: default rcountmax=5 < its value in global settings < rcountmax stored for each concrete document.
3. Dirty, the extention-based hack to avoid reading not crengine-related parameters stored in history files. TODO: one has to finally introduce loadSpecialSettings() & readSpecialSettings() for PDFReader & DJVUReader and to store therein the reader-specific parameters (like globalgamma, bbox, globalzoom, globalzoom_mode; render_mode = for djvu-files only, etc.)
4. Some lua-code cosmetics (to make code more readable); for example: "self.pan_margin = settings:readSetting("pan_margin") or self.pan_margin" instead of
"local pan_margin = settings:readSetting("pan_margin")
if pan_margin then
self.pan_margin = pan_margin
end"
5. Fix for the today's tigran123 fix: issue #246 (details are included). Added InfoMessage:show() to inform most impatient users that the reader tries to redraw new zoo mode.
6. The fontface for the reading info (called by 'Menu') is restored to be in accordance with original intentions and with the same fontface in crereader.lua - namely, Font:getFace("rifont", 20)
7. Moved the exit hotkeys (Alt+Back & Home) to the end of hotkey list.
2012-09-03 19:23:06 +00:00
|
|
|
if not re or re==(1-unireader.globalzoom_mode) or re==1 or re==8 or re==9 then -- if not proper zoom-mode
|
|
|
|
unireader:redrawCurrentPage()
|
2012-09-08 22:52:04 +00:00
|
|
|
else
|
unireader: refresh frequency; zoommode-menu, etc.
1. Restored default value rcountmax=5; the function to make manual full screen refresh is no more silent; at first, it asks user to set a number of partial refreshes (rcountmax) and then performs full refresh. TODO: saving parameter 'rcountmax' in the global reader settings (or separately, for each document).
2. The hotkey 'R' and the respective function toggle_render_mode() for djvu-documents are moved to djvureader.
3. Added hotkey 'M' and the respective function that calls menu with zoom-modes. Probably, one needs to remove unappropriate items, like "Fit zoom to page" and, less probably, the hotkeys (A, S, D, F and ^A, ^S, ^D, ^F) to set zoom-mode directly.
2012-09-01 10:39:14 +00:00
|
|
|
unireader:setglobalzoom_mode(1-re)
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
-- to leave or to erase 8 hotkeys switching zoom-mode directly?
|
|
|
|
|
2012-03-13 21:51:25 +00:00
|
|
|
self.commands:add(KEY_A,nil,"A",
|
|
|
|
"zoom to fit page",
|
2012-03-10 09:28:54 +00:00
|
|
|
function(unireader)
|
2012-04-21 04:14:35 +00:00
|
|
|
unireader:setglobalzoom_mode(unireader.ZOOM_FIT_TO_PAGE)
|
2012-03-20 19:15:24 +00:00
|
|
|
end)
|
2012-03-13 21:51:25 +00:00
|
|
|
self.commands:add(KEY_A,MOD_SHIFT,"A",
|
|
|
|
"zoom to fit content",
|
2012-03-10 09:28:54 +00:00
|
|
|
function(unireader)
|
2012-04-21 04:14:35 +00:00
|
|
|
unireader:setglobalzoom_mode(unireader.ZOOM_FIT_TO_CONTENT)
|
2012-03-20 19:15:24 +00:00
|
|
|
end)
|
2012-03-13 21:51:25 +00:00
|
|
|
self.commands:add(KEY_S,nil,"S",
|
|
|
|
"zoom to fit page width",
|
|
|
|
function(unireader)
|
2012-04-21 04:14:35 +00:00
|
|
|
unireader:setglobalzoom_mode(unireader.ZOOM_FIT_TO_PAGE_WIDTH)
|
2012-03-13 21:51:25 +00:00
|
|
|
end)
|
|
|
|
self.commands:add(KEY_S,MOD_SHIFT,"S",
|
|
|
|
"zoom to fit content width",
|
2012-03-10 09:28:54 +00:00
|
|
|
function(unireader)
|
2012-04-21 04:14:35 +00:00
|
|
|
unireader:setglobalzoom_mode(unireader.ZOOM_FIT_TO_CONTENT_WIDTH)
|
2012-03-20 19:15:24 +00:00
|
|
|
end)
|
2012-03-13 21:51:25 +00:00
|
|
|
self.commands:add(KEY_D,nil,"D",
|
|
|
|
"zoom to fit page height",
|
2012-03-10 09:28:54 +00:00
|
|
|
function(unireader)
|
2012-04-21 04:14:35 +00:00
|
|
|
unireader:setglobalzoom_mode(unireader.ZOOM_FIT_TO_PAGE_HEIGHT)
|
2012-03-10 09:28:54 +00:00
|
|
|
end)
|
2012-03-13 21:51:25 +00:00
|
|
|
self.commands:add(KEY_D,MOD_SHIFT,"D",
|
|
|
|
"zoom to fit content height",
|
2012-03-10 09:28:54 +00:00
|
|
|
function(unireader)
|
2012-04-21 04:14:35 +00:00
|
|
|
unireader:setglobalzoom_mode(unireader.ZOOM_FIT_TO_CONTENT_HEIGHT)
|
2012-03-20 19:15:24 +00:00
|
|
|
end)
|
2012-03-13 21:51:25 +00:00
|
|
|
self.commands:add(KEY_F,nil,"F",
|
|
|
|
"zoom to fit margin 2-column mode",
|
2012-03-10 09:28:54 +00:00
|
|
|
function(unireader)
|
2012-04-21 04:14:35 +00:00
|
|
|
unireader:setglobalzoom_mode(unireader.ZOOM_FIT_TO_CONTENT_HALF_WIDTH_MARGIN)
|
2012-03-10 09:28:54 +00:00
|
|
|
end)
|
2012-03-13 21:51:25 +00:00
|
|
|
self.commands:add(KEY_F,MOD_SHIFT,"F",
|
|
|
|
"zoom to fit content 2-column mode",
|
2012-03-10 09:28:54 +00:00
|
|
|
function(unireader)
|
2012-04-21 04:14:35 +00:00
|
|
|
unireader:setglobalzoom_mode(unireader.ZOOM_FIT_TO_CONTENT_HALF_WIDTH)
|
2012-03-20 19:15:24 +00:00
|
|
|
end)
|
2012-03-13 23:07:19 +00:00
|
|
|
self.commands:add(KEY_G,nil,"G",
|
2012-04-15 14:07:39 +00:00
|
|
|
"open 'go to page' input box",
|
2012-03-10 09:28:54 +00:00
|
|
|
function(unireader)
|
2012-04-20 06:04:37 +00:00
|
|
|
local page = NumInputBox:input(G_height-100, 100,
|
|
|
|
"Page:", "current page "..self.pageno, true)
|
2012-03-13 21:51:25 +00:00
|
|
|
-- convert string to number
|
2012-09-06 16:49:56 +00:00
|
|
|
if not pcall(function () page = math.floor(page) end)
|
|
|
|
or page < 1 or page > unireader.doc:getPages() then
|
2012-03-13 21:51:25 +00:00
|
|
|
page = unireader.pageno
|
|
|
|
end
|
|
|
|
unireader:goto(page)
|
2012-03-20 19:15:24 +00:00
|
|
|
end)
|
2012-03-13 21:51:25 +00:00
|
|
|
self.commands:add(KEY_H,nil,"H",
|
|
|
|
"show help page",
|
|
|
|
function(unireader)
|
2012-04-09 07:42:19 +00:00
|
|
|
HelpPage:show(0, G_height, unireader.commands)
|
2012-04-07 15:28:56 +00:00
|
|
|
unireader:redrawCurrentPage()
|
2012-03-20 19:15:24 +00:00
|
|
|
end)
|
2012-03-13 21:51:25 +00:00
|
|
|
self.commands:add(KEY_T,nil,"T",
|
2012-09-08 22:52:04 +00:00
|
|
|
"show table of content (TOC)",
|
2012-03-10 09:28:54 +00:00
|
|
|
function(unireader)
|
2012-03-29 10:17:32 +00:00
|
|
|
unireader:showToc()
|
2012-03-13 21:51:25 +00:00
|
|
|
end)
|
|
|
|
self.commands:add(KEY_B,nil,"B",
|
2012-04-20 10:29:08 +00:00
|
|
|
"show bookmarks",
|
2012-04-18 09:01:22 +00:00
|
|
|
function(unireader)
|
|
|
|
unireader:showBookMarks()
|
|
|
|
end)
|
|
|
|
self.commands:add(KEY_B,MOD_ALT,"B",
|
2012-04-20 10:29:08 +00:00
|
|
|
"add bookmark to current page",
|
2012-03-13 21:51:25 +00:00
|
|
|
function(unireader)
|
2012-04-18 09:01:22 +00:00
|
|
|
ok = unireader:addBookmark(self.pageno)
|
|
|
|
if not ok then
|
2012-09-09 18:46:24 +00:00
|
|
|
showInfoMsgWithDelay("Page already marked!", 1500, 1)
|
2012-04-18 09:01:22 +00:00
|
|
|
else
|
2012-09-09 18:46:24 +00:00
|
|
|
showInfoMsgWithDelay("Page marked", 1500, 1)
|
2012-04-18 09:01:22 +00:00
|
|
|
end
|
2012-03-13 21:51:25 +00:00
|
|
|
end)
|
|
|
|
self.commands:add(KEY_B,MOD_SHIFT,"B",
|
2012-04-18 09:01:22 +00:00
|
|
|
"show jump history",
|
2012-03-13 21:51:25 +00:00
|
|
|
function(unireader)
|
2012-04-18 09:01:22 +00:00
|
|
|
unireader:showJumpHist()
|
2012-03-20 19:15:24 +00:00
|
|
|
end)
|
2012-04-10 12:45:22 +00:00
|
|
|
self.commands:add(KEY_J,MOD_SHIFT,"J",
|
2012-03-13 21:51:25 +00:00
|
|
|
"rotate 10° clockwise",
|
|
|
|
function(unireader)
|
2012-03-20 19:15:24 +00:00
|
|
|
unireader:setRotate( unireader.globalrotate + 10 )
|
2012-03-13 21:51:25 +00:00
|
|
|
end)
|
2012-04-10 12:45:22 +00:00
|
|
|
self.commands:add(KEY_J,nil,"J",
|
2012-03-13 21:51:25 +00:00
|
|
|
"rotate screen 90° clockwise",
|
|
|
|
function(unireader)
|
|
|
|
unireader:screenRotate("clockwise")
|
2012-04-21 04:14:35 +00:00
|
|
|
if self.globalzoom_mode == self.ZOOM_FIT_TO_CONTENT_WIDTH_PAN then
|
|
|
|
self:setglobalzoom_mode(self.ZOOM_FIT_TO_CONTENT_WIDTH)
|
2012-04-10 13:34:38 +00:00
|
|
|
else
|
|
|
|
self:redrawCurrentPage()
|
|
|
|
end
|
2012-03-20 19:15:24 +00:00
|
|
|
end)
|
2012-04-10 12:45:22 +00:00
|
|
|
self.commands:add(KEY_K,MOD_SHIFT,"K",
|
2012-03-13 21:51:25 +00:00
|
|
|
"rotate 10° counterclockwise",
|
|
|
|
function(unireader)
|
2012-03-20 19:15:24 +00:00
|
|
|
unireader:setRotate( unireader.globalrotate - 10 )
|
2012-03-13 21:51:25 +00:00
|
|
|
end)
|
2012-04-10 12:45:22 +00:00
|
|
|
self.commands:add(KEY_K,nil,"K",
|
2012-03-13 21:51:25 +00:00
|
|
|
"rotate screen 90° counterclockwise",
|
|
|
|
function(unireader)
|
|
|
|
unireader:screenRotate("anticlockwise")
|
2012-04-21 04:14:35 +00:00
|
|
|
if self.globalzoom_mode == self.ZOOM_FIT_TO_CONTENT_WIDTH_PAN then
|
|
|
|
self:setglobalzoom_mode(self.ZOOM_FIT_TO_CONTENT_WIDTH)
|
2012-04-10 13:34:38 +00:00
|
|
|
else
|
|
|
|
self:redrawCurrentPage()
|
|
|
|
end
|
2012-03-20 19:15:24 +00:00
|
|
|
end)
|
unireader: refresh frequency; zoommode-menu, etc.
1. Restored default value rcountmax=5; the function to make manual full screen refresh is no more silent; at first, it asks user to set a number of partial refreshes (rcountmax) and then performs full refresh. TODO: saving parameter 'rcountmax' in the global reader settings (or separately, for each document).
2. The hotkey 'R' and the respective function toggle_render_mode() for djvu-documents are moved to djvureader.
3. Added hotkey 'M' and the respective function that calls menu with zoom-modes. Probably, one needs to remove unappropriate items, like "Fit zoom to page" and, less probably, the hotkeys (A, S, D, F and ^A, ^S, ^D, ^F) to set zoom-mode directly.
2012-09-01 10:39:14 +00:00
|
|
|
|
2012-03-31 13:17:29 +00:00
|
|
|
self.commands:add(KEY_R, MOD_SHIFT, "R",
|
storing rcountmax; user-configurable zoom step & pan steps, etc
1. In order to close issue #59, I've introduced user-configurable values for panning steps - for X- & Y-axis, separately. Now panning is called by pressing fiveway without mod_keys. When one presses Shift+FW, he/she changes panning steps in the following way - Shift-Left/Right = decrease / increase X-panning step (divide or multiply on factor 2), Shift-Up/Down = increase / decrease Y-panning step. The lowest value for panning steps is set 1. Both parameters, shift_x & shift_y, are saved to local settings (i.e. history file).
2. Manual zoom step was also made user-configurable. So, instead of two old zooming functions (with fixed 10% and 20%-steps), I made one function to zoom (Shift+<>), while the other (Alt+<>) changes the zoom step downto minimum 1%.
3. Fresh introduced function to change parameter rcountmax was added by storing rcountmax to both setting files - global settings & local ones (i.e. history file) - so that the rcountmax-priority (from low to high) is the following: default rcountmax=5 < its value in global settings < rcountmax stored for each concrete document.
3. Dirty, the extention-based hack to avoid reading not crengine-related parameters stored in history files. TODO: one has to finally introduce loadSpecialSettings() & readSpecialSettings() for PDFReader & DJVUReader and to store therein the reader-specific parameters (like globalgamma, bbox, globalzoom, globalzoom_mode; render_mode = for djvu-files only, etc.)
4. Some lua-code cosmetics (to make code more readable); for example: "self.pan_margin = settings:readSetting("pan_margin") or self.pan_margin" instead of
"local pan_margin = settings:readSetting("pan_margin")
if pan_margin then
self.pan_margin = pan_margin
end"
5. Fix for the today's tigran123 fix: issue #246 (details are included). Added InfoMessage:show() to inform most impatient users that the reader tries to redraw new zoo mode.
6. The fontface for the reading info (called by 'Menu') is restored to be in accordance with original intentions and with the same fontface in crereader.lua - namely, Font:getFace("rifont", 20)
7. Moved the exit hotkeys (Alt+Back & Home) to the end of hotkey list.
2012-09-03 19:23:06 +00:00
|
|
|
"full screen refresh",
|
2012-03-31 13:17:29 +00:00
|
|
|
function(unireader)
|
unireader: refresh frequency; zoommode-menu, etc.
1. Restored default value rcountmax=5; the function to make manual full screen refresh is no more silent; at first, it asks user to set a number of partial refreshes (rcountmax) and then performs full refresh. TODO: saving parameter 'rcountmax' in the global reader settings (or separately, for each document).
2. The hotkey 'R' and the respective function toggle_render_mode() for djvu-documents are moved to djvureader.
3. Added hotkey 'M' and the respective function that calls menu with zoom-modes. Probably, one needs to remove unappropriate items, like "Fit zoom to page" and, less probably, the hotkeys (A, S, D, F and ^A, ^S, ^D, ^F) to set zoom-mode directly.
2012-09-01 10:39:14 +00:00
|
|
|
local count = NumInputBox:input(G_height-100, 100,
|
|
|
|
"Full refresh after:", self.rcountmax, true)
|
|
|
|
-- convert string to number
|
|
|
|
if pcall(function () count = count + 0 end) then
|
|
|
|
-- restrict self.rcountmax in reasonable range
|
|
|
|
self.rcountmax = math.max(count, 0)
|
|
|
|
self.rcountmax = math.min(count, 10)
|
storing rcountmax; user-configurable zoom step & pan steps, etc
1. In order to close issue #59, I've introduced user-configurable values for panning steps - for X- & Y-axis, separately. Now panning is called by pressing fiveway without mod_keys. When one presses Shift+FW, he/she changes panning steps in the following way - Shift-Left/Right = decrease / increase X-panning step (divide or multiply on factor 2), Shift-Up/Down = increase / decrease Y-panning step. The lowest value for panning steps is set 1. Both parameters, shift_x & shift_y, are saved to local settings (i.e. history file).
2. Manual zoom step was also made user-configurable. So, instead of two old zooming functions (with fixed 10% and 20%-steps), I made one function to zoom (Shift+<>), while the other (Alt+<>) changes the zoom step downto minimum 1%.
3. Fresh introduced function to change parameter rcountmax was added by storing rcountmax to both setting files - global settings & local ones (i.e. history file) - so that the rcountmax-priority (from low to high) is the following: default rcountmax=5 < its value in global settings < rcountmax stored for each concrete document.
3. Dirty, the extention-based hack to avoid reading not crengine-related parameters stored in history files. TODO: one has to finally introduce loadSpecialSettings() & readSpecialSettings() for PDFReader & DJVUReader and to store therein the reader-specific parameters (like globalgamma, bbox, globalzoom, globalzoom_mode; render_mode = for djvu-files only, etc.)
4. Some lua-code cosmetics (to make code more readable); for example: "self.pan_margin = settings:readSetting("pan_margin") or self.pan_margin" instead of
"local pan_margin = settings:readSetting("pan_margin")
if pan_margin then
self.pan_margin = pan_margin
end"
5. Fix for the today's tigran123 fix: issue #246 (details are included). Added InfoMessage:show() to inform most impatient users that the reader tries to redraw new zoo mode.
6. The fontface for the reading info (called by 'Menu') is restored to be in accordance with original intentions and with the same fontface in crereader.lua - namely, Font:getFace("rifont", 20)
7. Moved the exit hotkeys (Alt+Back & Home) to the end of hotkey list.
2012-09-03 19:23:06 +00:00
|
|
|
-- storing this parameter in both global and local settings
|
|
|
|
G_reader_settings:saveSetting("rcountmax", self.rcountmax)
|
|
|
|
self.settings:saveSetting("rcountmax", self.rcountmax)
|
unireader: refresh frequency; zoommode-menu, etc.
1. Restored default value rcountmax=5; the function to make manual full screen refresh is no more silent; at first, it asks user to set a number of partial refreshes (rcountmax) and then performs full refresh. TODO: saving parameter 'rcountmax' in the global reader settings (or separately, for each document).
2. The hotkey 'R' and the respective function toggle_render_mode() for djvu-documents are moved to djvureader.
3. Added hotkey 'M' and the respective function that calls menu with zoom-modes. Probably, one needs to remove unappropriate items, like "Fit zoom to page" and, less probably, the hotkeys (A, S, D, F and ^A, ^S, ^D, ^F) to set zoom-mode directly.
2012-09-01 10:39:14 +00:00
|
|
|
end
|
|
|
|
-- now, perform full screen refresh
|
|
|
|
self.rcount = self.rcountmax
|
|
|
|
self:redrawCurrentPage()
|
2012-09-01 15:36:52 +00:00
|
|
|
--[[ eink will not refresh if nothing is changed on the screen
|
2012-04-14 06:27:17 +00:00
|
|
|
-- so we fake a change here.
|
|
|
|
fb.bb:invertRect(0, 0, 1, 1)
|
|
|
|
fb:refresh(1)
|
|
|
|
fb.bb:invertRect(0, 0, 1, 1)
|
2012-03-31 13:17:29 +00:00
|
|
|
fb:refresh(0)
|
unireader: refresh frequency; zoommode-menu, etc.
1. Restored default value rcountmax=5; the function to make manual full screen refresh is no more silent; at first, it asks user to set a number of partial refreshes (rcountmax) and then performs full refresh. TODO: saving parameter 'rcountmax' in the global reader settings (or separately, for each document).
2. The hotkey 'R' and the respective function toggle_render_mode() for djvu-documents are moved to djvureader.
3. Added hotkey 'M' and the respective function that calls menu with zoom-modes. Probably, one needs to remove unappropriate items, like "Fit zoom to page" and, less probably, the hotkeys (A, S, D, F and ^A, ^S, ^D, ^F) to set zoom-mode directly.
2012-09-01 10:39:14 +00:00
|
|
|
unireader.rcount = 0 ]]
|
2012-03-20 19:15:24 +00:00
|
|
|
end)
|
unireader: refresh frequency; zoommode-menu, etc.
1. Restored default value rcountmax=5; the function to make manual full screen refresh is no more silent; at first, it asks user to set a number of partial refreshes (rcountmax) and then performs full refresh. TODO: saving parameter 'rcountmax' in the global reader settings (or separately, for each document).
2. The hotkey 'R' and the respective function toggle_render_mode() for djvu-documents are moved to djvureader.
3. Added hotkey 'M' and the respective function that calls menu with zoom-modes. Probably, one needs to remove unappropriate items, like "Fit zoom to page" and, less probably, the hotkeys (A, S, D, F and ^A, ^S, ^D, ^F) to set zoom-mode directly.
2012-09-01 10:39:14 +00:00
|
|
|
|
2012-03-13 21:51:25 +00:00
|
|
|
self.commands:add(KEY_Z,nil,"Z",
|
|
|
|
"set crop mode",
|
|
|
|
function(unireader)
|
|
|
|
local bbox = {}
|
|
|
|
bbox["x0"] = - unireader.offset_x / unireader.globalzoom
|
|
|
|
bbox["y0"] = - unireader.offset_y / unireader.globalzoom
|
2012-04-09 07:42:19 +00:00
|
|
|
bbox["x1"] = bbox["x0"] + G_width / unireader.globalzoom
|
|
|
|
bbox["y1"] = bbox["y0"] + G_height / unireader.globalzoom
|
2012-03-13 21:51:25 +00:00
|
|
|
bbox.pan_x = unireader.pan_x
|
|
|
|
bbox.pan_y = unireader.pan_y
|
|
|
|
unireader.bbox[unireader.pageno] = bbox
|
2012-03-20 19:15:24 +00:00
|
|
|
unireader.bbox[unireader:oddEven(unireader.pageno)] = bbox
|
2012-03-13 21:51:25 +00:00
|
|
|
unireader.bbox.enabled = true
|
2012-06-03 22:49:23 +00:00
|
|
|
Debug("bbox", unireader.pageno, unireader.bbox)
|
2012-04-21 04:14:35 +00:00
|
|
|
unireader.globalzoom_mode = unireader.ZOOM_FIT_TO_CONTENT -- use bbox
|
2012-04-18 09:01:22 +00:00
|
|
|
showInfoMsgWithDelay("Manual crop setting saved.", 2000, 1)
|
2012-03-13 21:51:25 +00:00
|
|
|
end)
|
|
|
|
self.commands:add(KEY_Z,MOD_SHIFT,"Z",
|
|
|
|
"reset crop",
|
|
|
|
function(unireader)
|
|
|
|
unireader.bbox[unireader.pageno] = nil;
|
2012-04-18 09:01:22 +00:00
|
|
|
showInfoMsgWithDelay("Manual crop setting removed.", 2000, 1)
|
2012-06-03 22:49:23 +00:00
|
|
|
Debug("bbox remove", unireader.pageno, unireader.bbox);
|
2012-03-13 21:51:25 +00:00
|
|
|
end)
|
|
|
|
self.commands:add(KEY_Z,MOD_ALT,"Z",
|
|
|
|
"toggle crop mode",
|
|
|
|
function(unireader)
|
|
|
|
unireader.bbox.enabled = not unireader.bbox.enabled;
|
2012-04-17 06:36:37 +00:00
|
|
|
if unireader.bbox.enabled then
|
2012-04-18 09:01:22 +00:00
|
|
|
showInfoMsgWithDelay("Manual crop enabled.", 2000, 1)
|
2012-04-17 06:36:37 +00:00
|
|
|
else
|
2012-04-18 09:01:22 +00:00
|
|
|
showInfoMsgWithDelay("Manual crop disabled.", 2000, 1)
|
2012-04-17 06:36:37 +00:00
|
|
|
end
|
2012-06-03 22:49:23 +00:00
|
|
|
Debug("bbox override", unireader.bbox.enabled);
|
2012-03-13 21:51:25 +00:00
|
|
|
end)
|
2012-04-26 20:16:36 +00:00
|
|
|
self.commands:add(KEY_X,nil,"X",
|
|
|
|
"invert page bbox",
|
|
|
|
function(unireader)
|
|
|
|
local bbox = unireader.cur_bbox
|
2012-06-03 22:49:23 +00:00
|
|
|
Debug("bbox", bbox)
|
2012-04-26 20:27:00 +00:00
|
|
|
x,y,w,h = unireader:getRectInScreen( bbox["x0"], bbox["y0"], bbox["x1"], bbox["y1"] )
|
2012-06-03 22:49:23 +00:00
|
|
|
Debug("inxertRect",x,y,w,h)
|
2012-04-26 20:16:36 +00:00
|
|
|
fb.bb:invertRect( x,y, w,h )
|
2012-04-29 13:56:56 +00:00
|
|
|
fb:refresh(1)
|
2012-04-26 20:16:36 +00:00
|
|
|
end)
|
2012-04-29 12:23:13 +00:00
|
|
|
self.commands:add(KEY_X,MOD_SHIFT,"X",
|
|
|
|
"modify page bbox",
|
|
|
|
function(unireader)
|
|
|
|
local bbox = unireader.cur_bbox
|
2012-06-03 22:49:23 +00:00
|
|
|
Debug("bbox", bbox)
|
2012-04-29 12:23:13 +00:00
|
|
|
x,y,w,h = unireader:getRectInScreen( bbox["x0"], bbox["y0"], bbox["x1"], bbox["y1"] )
|
2012-06-03 22:49:23 +00:00
|
|
|
Debug("getRectInScreen",x,y,w,h)
|
2012-04-29 17:15:53 +00:00
|
|
|
|
2012-04-29 12:23:13 +00:00
|
|
|
local new_bbox = bbox
|
|
|
|
local x_s, y_s = x,y
|
2012-04-29 17:15:53 +00:00
|
|
|
local running_corner = "top-left"
|
2012-04-29 12:23:13 +00:00
|
|
|
|
|
|
|
Screen:saveCurrentBB()
|
|
|
|
|
2012-04-29 17:15:53 +00:00
|
|
|
fb.bb:invertRect( 0,y_s, G_width,1 )
|
|
|
|
fb.bb:invertRect( x_s,0, 1,G_height )
|
|
|
|
InfoMessage:show(running_corner.." bbox");
|
2012-04-29 13:56:56 +00:00
|
|
|
fb:refresh(1)
|
2012-04-29 12:23:13 +00:00
|
|
|
|
2012-04-29 17:15:53 +00:00
|
|
|
local last_direction = { x = 0, y = 0 }
|
|
|
|
|
|
|
|
while running_corner do
|
2012-04-29 12:23:13 +00:00
|
|
|
local ev = input.saveWaitForEvent()
|
2012-06-03 22:49:23 +00:00
|
|
|
Debug("ev",ev)
|
2012-04-29 12:23:13 +00:00
|
|
|
ev.code = adjustKeyEvents(ev)
|
|
|
|
|
|
|
|
if ev.type == EV_KEY and ev.value ~= EVENT_VALUE_KEY_RELEASE then
|
|
|
|
|
2012-04-29 17:15:53 +00:00
|
|
|
fb.bb:invertRect( 0,y_s, G_width,1 )
|
|
|
|
fb.bb:invertRect( x_s,0, 1,G_height )
|
|
|
|
|
|
|
|
local step = 10
|
|
|
|
local factor = 1
|
2012-04-29 12:23:13 +00:00
|
|
|
|
2012-04-29 17:15:53 +00:00
|
|
|
local x_direction, y_direction = 0,0
|
2012-04-29 12:23:13 +00:00
|
|
|
if ev.code == KEY_FW_LEFT then
|
2012-04-29 17:15:53 +00:00
|
|
|
x_direction = -1
|
2012-04-29 12:23:13 +00:00
|
|
|
elseif ev.code == KEY_FW_RIGHT then
|
2012-04-29 17:15:53 +00:00
|
|
|
x_direction = 1
|
2012-04-29 12:23:13 +00:00
|
|
|
elseif ev.code == KEY_FW_UP then
|
2012-04-29 17:15:53 +00:00
|
|
|
y_direction = -1
|
2012-04-29 12:23:13 +00:00
|
|
|
elseif ev.code == KEY_FW_DOWN then
|
2012-04-29 17:15:53 +00:00
|
|
|
y_direction = 1
|
2012-04-29 12:23:13 +00:00
|
|
|
elseif ev.code == KEY_FW_PRESS then
|
|
|
|
local p_x,p_y = unireader:screenToPageTransform(x_s,y_s)
|
2012-04-29 17:15:53 +00:00
|
|
|
if running_corner == "top-left" then
|
2012-04-29 12:23:13 +00:00
|
|
|
new_bbox["x0"] = p_x
|
|
|
|
new_bbox["y0"] = p_y
|
2012-06-03 22:49:23 +00:00
|
|
|
Debug("change top-left", bbox, "to", new_bbox)
|
2012-04-29 17:15:53 +00:00
|
|
|
running_corner = "bottom-right"
|
2012-04-29 12:23:13 +00:00
|
|
|
Screen:restoreFromSavedBB()
|
2012-04-29 17:15:53 +00:00
|
|
|
InfoMessage:show(running_corner.." bbox")
|
2012-04-29 13:56:56 +00:00
|
|
|
fb:refresh(1)
|
2012-04-29 12:23:13 +00:00
|
|
|
x_s = x+w
|
|
|
|
y_s = y+h
|
|
|
|
else
|
|
|
|
new_bbox["x1"] = p_x
|
|
|
|
new_bbox["y1"] = p_y
|
2012-04-29 17:15:53 +00:00
|
|
|
running_corner = false
|
2012-04-29 12:23:13 +00:00
|
|
|
end
|
2012-04-29 17:15:53 +00:00
|
|
|
elseif ev.code >= KEY_Q and ev.code <= KEY_P then
|
|
|
|
factor = ev.code - KEY_Q + 1
|
|
|
|
x_direction = last_direction["x"]
|
|
|
|
y_direction = last_direction["y"]
|
2012-06-03 22:49:23 +00:00
|
|
|
Debug("factor",factor,"deltas",x_direction,y_direction)
|
2012-04-29 17:15:53 +00:00
|
|
|
elseif ev.code >= KEY_A and ev.code <= KEY_L then
|
|
|
|
factor = ev.code - KEY_A + 11
|
|
|
|
x_direction = last_direction["x"]
|
|
|
|
y_direction = last_direction["y"]
|
|
|
|
elseif ev.code >= KEY_Z and ev.code <= KEY_M then
|
|
|
|
factor = ev.code - KEY_Z + 20
|
|
|
|
x_direction = last_direction["x"]
|
|
|
|
y_direction = last_direction["y"]
|
|
|
|
elseif ev.code == KEY_BACK or ev.code == KEY_HOME then
|
|
|
|
running_corner = false
|
2012-04-29 12:23:13 +00:00
|
|
|
end
|
|
|
|
|
2012-06-03 22:49:23 +00:00
|
|
|
Debug("factor",factor,"deltas",x_direction,y_direction)
|
2012-04-29 17:15:53 +00:00
|
|
|
|
|
|
|
if running_corner then
|
|
|
|
local x_o = x_direction * step * factor
|
|
|
|
local y_o = y_direction * step * factor
|
2012-06-03 22:49:23 +00:00
|
|
|
Debug("move slider",x_o,y_o)
|
2012-04-29 12:23:13 +00:00
|
|
|
if x_s+x_o >= 0 and x_s+x_o <= G_width then x_s = x_s + x_o end
|
|
|
|
if y_s+y_o >= 0 and y_s+y_o <= G_height then y_s = y_s + y_o end
|
|
|
|
|
2012-04-29 17:15:53 +00:00
|
|
|
if x_direction ~= 0 or y_direction ~= 0 then
|
|
|
|
Screen:restoreFromSavedBB()
|
|
|
|
end
|
|
|
|
|
|
|
|
fb.bb:invertRect( 0,y_s, G_width,1 )
|
|
|
|
fb.bb:invertRect( x_s,0, 1,G_height )
|
|
|
|
|
|
|
|
if x_direction or y_direction then
|
|
|
|
last_direction = { x = x_direction, y = y_direction }
|
2012-06-03 22:49:23 +00:00
|
|
|
Debug("last_direction",last_direction)
|
2012-04-29 17:15:53 +00:00
|
|
|
|
|
|
|
-- FIXME partial duplicate of SelectMenu.item_shortcuts
|
|
|
|
local keys = {
|
|
|
|
"Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P",
|
|
|
|
"A", "S", "D", "F", "G", "H", "J", "K", "L",
|
|
|
|
"Z", "X", "C", "V", "B", "N", "M",
|
|
|
|
}
|
|
|
|
|
|
|
|
local max = 0
|
|
|
|
if x_direction == 1 then
|
|
|
|
max = G_width - x_s
|
|
|
|
elseif x_direction == -1 then
|
|
|
|
max = x_s
|
|
|
|
elseif y_direction == 1 then
|
|
|
|
max = G_height - y_s
|
|
|
|
elseif y_direction == -1 then
|
|
|
|
max = y_s
|
|
|
|
else
|
|
|
|
print("ERROR: unknown direction!")
|
|
|
|
end
|
|
|
|
|
|
|
|
max = max / step
|
|
|
|
if max > #keys then max = #keys end
|
|
|
|
|
2012-05-02 14:03:01 +00:00
|
|
|
local face = Font:getFace("hpkfont", 11)
|
2012-04-29 17:15:53 +00:00
|
|
|
|
|
|
|
for i = 1, max, 1 do
|
|
|
|
local key = keys[i]
|
|
|
|
local tick = i * step * x_direction
|
|
|
|
if x_direction ~= 0 then
|
|
|
|
local tick = i * step * x_direction
|
2012-06-03 22:49:23 +00:00
|
|
|
Debug("x tick",i,tick,key)
|
2012-04-29 17:15:53 +00:00
|
|
|
if running_corner == "top-left" then -- ticks must be inside page
|
|
|
|
fb.bb:invertRect( x_s+tick, y_s, 1, math.abs(tick))
|
|
|
|
else
|
|
|
|
fb.bb:invertRect( x_s+tick, y_s-math.abs(tick), 1, math.abs(tick))
|
|
|
|
end
|
|
|
|
if x_direction < 0 then tick = tick - step end
|
|
|
|
tick = tick - step * x_direction / 2
|
2012-05-02 14:03:01 +00:00
|
|
|
renderUtf8Text(fb.bb, x_s+tick+2, y_s+4, face, key)
|
2012-04-29 17:15:53 +00:00
|
|
|
else
|
|
|
|
local tick = i * step * y_direction
|
2012-06-03 22:49:23 +00:00
|
|
|
Debug("y tick",i,tick,key)
|
2012-04-29 17:15:53 +00:00
|
|
|
if running_corner == "top-left" then -- ticks must be inside page
|
|
|
|
fb.bb:invertRect( x_s, y_s+tick, math.abs(tick),1)
|
|
|
|
else
|
|
|
|
fb.bb:invertRect( x_s-math.abs(tick), y_s+tick, math.abs(tick),1)
|
|
|
|
end
|
|
|
|
if y_direction > 0 then tick = tick + step end
|
|
|
|
tick = tick - step * y_direction / 2
|
2012-05-02 14:03:01 +00:00
|
|
|
renderUtf8Text(fb.bb, x_s-3, y_s+tick-1, face, key)
|
2012-04-29 17:15:53 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-04-29 12:23:13 +00:00
|
|
|
|
2012-04-29 13:56:56 +00:00
|
|
|
fb:refresh(1)
|
2012-04-29 12:23:13 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
unireader.bbox[unireader.pageno] = new_bbox
|
|
|
|
unireader.bbox[unireader:oddEven(unireader.pageno)] = new_bbox
|
|
|
|
unireader.bbox.enabled = true
|
2012-06-03 22:49:23 +00:00
|
|
|
Debug("crop bbox", bbox, "to", new_bbox)
|
2012-04-29 12:23:13 +00:00
|
|
|
|
|
|
|
Screen:restoreFromSavedBB()
|
|
|
|
x,y,w,h = unireader:getRectInScreen( new_bbox["x0"], new_bbox["y0"], new_bbox["x1"], new_bbox["y1"] )
|
|
|
|
fb.bb:invertRect( x,y, w,h )
|
|
|
|
--fb.bb:invertRect( x+1,y+1, w-2,h-2 ) -- just border?
|
2012-05-02 13:50:06 +00:00
|
|
|
showInfoMsgWithDelay("new page bbox", 2000, 1);
|
|
|
|
self:redrawCurrentPage()
|
2012-04-29 12:23:13 +00:00
|
|
|
|
2012-04-29 17:36:23 +00:00
|
|
|
self.rcount = self.rcountmax -- force next full refresh
|
|
|
|
|
2012-04-29 12:23:13 +00:00
|
|
|
--unireader:setglobalzoom_mode(unireader.ZOOM_FIT_TO_CONTENT)
|
|
|
|
end)
|
2012-03-13 21:51:25 +00:00
|
|
|
self.commands:add(KEY_MENU,nil,"Menu",
|
2012-04-15 14:07:39 +00:00
|
|
|
"toggle info box",
|
2012-03-13 21:51:25 +00:00
|
|
|
function(unireader)
|
2012-03-13 23:07:19 +00:00
|
|
|
unireader:showMenu()
|
2012-03-28 16:09:26 +00:00
|
|
|
unireader:redrawCurrentPage()
|
2012-03-20 19:15:24 +00:00
|
|
|
end)
|
storing rcountmax; user-configurable zoom step & pan steps, etc
1. In order to close issue #59, I've introduced user-configurable values for panning steps - for X- & Y-axis, separately. Now panning is called by pressing fiveway without mod_keys. When one presses Shift+FW, he/she changes panning steps in the following way - Shift-Left/Right = decrease / increase X-panning step (divide or multiply on factor 2), Shift-Up/Down = increase / decrease Y-panning step. The lowest value for panning steps is set 1. Both parameters, shift_x & shift_y, are saved to local settings (i.e. history file).
2. Manual zoom step was also made user-configurable. So, instead of two old zooming functions (with fixed 10% and 20%-steps), I made one function to zoom (Shift+<>), while the other (Alt+<>) changes the zoom step downto minimum 1%.
3. Fresh introduced function to change parameter rcountmax was added by storing rcountmax to both setting files - global settings & local ones (i.e. history file) - so that the rcountmax-priority (from low to high) is the following: default rcountmax=5 < its value in global settings < rcountmax stored for each concrete document.
3. Dirty, the extention-based hack to avoid reading not crengine-related parameters stored in history files. TODO: one has to finally introduce loadSpecialSettings() & readSpecialSettings() for PDFReader & DJVUReader and to store therein the reader-specific parameters (like globalgamma, bbox, globalzoom, globalzoom_mode; render_mode = for djvu-files only, etc.)
4. Some lua-code cosmetics (to make code more readable); for example: "self.pan_margin = settings:readSetting("pan_margin") or self.pan_margin" instead of
"local pan_margin = settings:readSetting("pan_margin")
if pan_margin then
self.pan_margin = pan_margin
end"
5. Fix for the today's tigran123 fix: issue #246 (details are included). Added InfoMessage:show() to inform most impatient users that the reader tries to redraw new zoo mode.
6. The fontface for the reading info (called by 'Menu') is restored to be in accordance with original intentions and with the same fontface in crereader.lua - namely, Font:getFace("rifont", 20)
7. Moved the exit hotkeys (Alt+Back & Home) to the end of hotkey list.
2012-09-03 19:23:06 +00:00
|
|
|
-- panning: NuPogodi, 03.09.2012: since Alt+KEY_FW-keys do not work and Shift+KEY_FW-keys alone
|
|
|
|
-- are not enough to cover the wide range, I've extracted changing pansteps to separate functions
|
|
|
|
local panning_keys = { Keydef:new(KEY_FW_LEFT,nil), Keydef:new(KEY_FW_RIGHT,nil),
|
|
|
|
Keydef:new(KEY_FW_UP,nil), Keydef:new(KEY_FW_DOWN,nil),
|
|
|
|
Keydef:new(KEY_FW_PRESS,MOD_ANY) }
|
|
|
|
|
2012-03-20 19:15:24 +00:00
|
|
|
self.commands:addGroup("[joypad]",panning_keys,
|
storing rcountmax; user-configurable zoom step & pan steps, etc
1. In order to close issue #59, I've introduced user-configurable values for panning steps - for X- & Y-axis, separately. Now panning is called by pressing fiveway without mod_keys. When one presses Shift+FW, he/she changes panning steps in the following way - Shift-Left/Right = decrease / increase X-panning step (divide or multiply on factor 2), Shift-Up/Down = increase / decrease Y-panning step. The lowest value for panning steps is set 1. Both parameters, shift_x & shift_y, are saved to local settings (i.e. history file).
2. Manual zoom step was also made user-configurable. So, instead of two old zooming functions (with fixed 10% and 20%-steps), I made one function to zoom (Shift+<>), while the other (Alt+<>) changes the zoom step downto minimum 1%.
3. Fresh introduced function to change parameter rcountmax was added by storing rcountmax to both setting files - global settings & local ones (i.e. history file) - so that the rcountmax-priority (from low to high) is the following: default rcountmax=5 < its value in global settings < rcountmax stored for each concrete document.
3. Dirty, the extention-based hack to avoid reading not crengine-related parameters stored in history files. TODO: one has to finally introduce loadSpecialSettings() & readSpecialSettings() for PDFReader & DJVUReader and to store therein the reader-specific parameters (like globalgamma, bbox, globalzoom, globalzoom_mode; render_mode = for djvu-files only, etc.)
4. Some lua-code cosmetics (to make code more readable); for example: "self.pan_margin = settings:readSetting("pan_margin") or self.pan_margin" instead of
"local pan_margin = settings:readSetting("pan_margin")
if pan_margin then
self.pan_margin = pan_margin
end"
5. Fix for the today's tigran123 fix: issue #246 (details are included). Added InfoMessage:show() to inform most impatient users that the reader tries to redraw new zoo mode.
6. The fontface for the reading info (called by 'Menu') is restored to be in accordance with original intentions and with the same fontface in crereader.lua - namely, Font:getFace("rifont", 20)
7. Moved the exit hotkeys (Alt+Back & Home) to the end of hotkey list.
2012-09-03 19:23:06 +00:00
|
|
|
"pan the active view",
|
2012-03-13 21:51:25 +00:00
|
|
|
function(unireader,keydef)
|
|
|
|
if keydef.keycode ~= KEY_FW_PRESS then
|
2012-04-21 04:14:35 +00:00
|
|
|
unireader.globalzoom_mode = unireader.ZOOM_BY_VALUE
|
2012-03-13 21:51:25 +00:00
|
|
|
end
|
2012-04-21 04:14:35 +00:00
|
|
|
if unireader.globalzoom_mode == unireader.ZOOM_BY_VALUE then
|
storing rcountmax; user-configurable zoom step & pan steps, etc
1. In order to close issue #59, I've introduced user-configurable values for panning steps - for X- & Y-axis, separately. Now panning is called by pressing fiveway without mod_keys. When one presses Shift+FW, he/she changes panning steps in the following way - Shift-Left/Right = decrease / increase X-panning step (divide or multiply on factor 2), Shift-Up/Down = increase / decrease Y-panning step. The lowest value for panning steps is set 1. Both parameters, shift_x & shift_y, are saved to local settings (i.e. history file).
2. Manual zoom step was also made user-configurable. So, instead of two old zooming functions (with fixed 10% and 20%-steps), I made one function to zoom (Shift+<>), while the other (Alt+<>) changes the zoom step downto minimum 1%.
3. Fresh introduced function to change parameter rcountmax was added by storing rcountmax to both setting files - global settings & local ones (i.e. history file) - so that the rcountmax-priority (from low to high) is the following: default rcountmax=5 < its value in global settings < rcountmax stored for each concrete document.
3. Dirty, the extention-based hack to avoid reading not crengine-related parameters stored in history files. TODO: one has to finally introduce loadSpecialSettings() & readSpecialSettings() for PDFReader & DJVUReader and to store therein the reader-specific parameters (like globalgamma, bbox, globalzoom, globalzoom_mode; render_mode = for djvu-files only, etc.)
4. Some lua-code cosmetics (to make code more readable); for example: "self.pan_margin = settings:readSetting("pan_margin") or self.pan_margin" instead of
"local pan_margin = settings:readSetting("pan_margin")
if pan_margin then
self.pan_margin = pan_margin
end"
5. Fix for the today's tigran123 fix: issue #246 (details are included). Added InfoMessage:show() to inform most impatient users that the reader tries to redraw new zoo mode.
6. The fontface for the reading info (called by 'Menu') is restored to be in accordance with original intentions and with the same fontface in crereader.lua - namely, Font:getFace("rifont", 20)
7. Moved the exit hotkeys (Alt+Back & Home) to the end of hotkey list.
2012-09-03 19:23:06 +00:00
|
|
|
local x, y
|
|
|
|
if unireader.pan_by_page then
|
2012-04-09 13:06:05 +00:00
|
|
|
x = G_width
|
2012-04-09 14:31:55 +00:00
|
|
|
y = G_height - unireader.pan_overlap_vertical -- overlap for lines which didn't fit
|
2012-03-13 21:51:25 +00:00
|
|
|
else
|
|
|
|
x = unireader.shift_x
|
|
|
|
y = unireader.shift_y
|
|
|
|
end
|
|
|
|
|
2012-06-03 22:49:23 +00:00
|
|
|
Debug("offset", unireader.offset_x, unireader.offset_x, " shift", x, y, " globalzoom", unireader.globalzoom)
|
2012-03-13 21:51:25 +00:00
|
|
|
local old_offset_x = unireader.offset_x
|
|
|
|
local old_offset_y = unireader.offset_y
|
|
|
|
|
|
|
|
if keydef.keycode == KEY_FW_LEFT then
|
2012-06-03 22:49:23 +00:00
|
|
|
Debug("KEY_FW_LEFT", unireader.offset_x, "+", x, "> 0");
|
2012-03-13 21:51:25 +00:00
|
|
|
unireader.offset_x = unireader.offset_x + x
|
|
|
|
if unireader.pan_by_page then
|
|
|
|
if unireader.offset_x > 0 and unireader.pageno > 1 then
|
|
|
|
unireader.offset_x = unireader.pan_x
|
|
|
|
unireader.offset_y = unireader.min_offset_y -- bottom
|
|
|
|
unireader:goto(unireader.pageno - 1)
|
|
|
|
else
|
2012-04-13 09:09:15 +00:00
|
|
|
unireader.show_overlap = 0
|
2012-03-13 21:51:25 +00:00
|
|
|
unireader.offset_y = unireader.min_offset_y
|
|
|
|
end
|
|
|
|
elseif unireader.offset_x > 0 then
|
|
|
|
unireader.offset_x = 0
|
|
|
|
end
|
|
|
|
elseif keydef.keycode == KEY_FW_RIGHT then
|
2012-06-03 22:49:23 +00:00
|
|
|
Debug("KEY_FW_RIGHT", unireader.offset_x, "-", x, "<", unireader.min_offset_x, "-", unireader.pan_margin);
|
2012-03-13 21:51:25 +00:00
|
|
|
unireader.offset_x = unireader.offset_x - x
|
|
|
|
if unireader.pan_by_page then
|
|
|
|
if unireader.offset_x < unireader.min_offset_x - unireader.pan_margin and unireader.pageno < unireader.doc:getPages() then
|
|
|
|
unireader.offset_x = unireader.pan_x
|
|
|
|
unireader.offset_y = unireader.pan_y
|
|
|
|
unireader:goto(unireader.pageno + 1)
|
|
|
|
else
|
2012-04-13 09:09:15 +00:00
|
|
|
unireader.show_overlap = 0
|
2012-03-13 21:51:25 +00:00
|
|
|
unireader.offset_y = unireader.pan_y
|
|
|
|
end
|
|
|
|
elseif unireader.offset_x < unireader.min_offset_x then
|
|
|
|
unireader.offset_x = unireader.min_offset_x
|
|
|
|
end
|
|
|
|
elseif keydef.keycode == KEY_FW_UP then
|
|
|
|
unireader.offset_y = unireader.offset_y + y
|
|
|
|
if unireader.offset_y > 0 then
|
2012-04-10 21:15:09 +00:00
|
|
|
if unireader.pan_by_page then
|
|
|
|
unireader.show_overlap = unireader.offset_y + unireader.pan_overlap_vertical
|
|
|
|
end
|
2012-03-13 21:51:25 +00:00
|
|
|
unireader.offset_y = 0
|
2012-04-09 13:06:05 +00:00
|
|
|
elseif unireader.pan_by_page then
|
|
|
|
unireader.show_overlap = unireader.pan_overlap_vertical -- bottom
|
2012-03-13 21:51:25 +00:00
|
|
|
end
|
|
|
|
elseif keydef.keycode == KEY_FW_DOWN then
|
|
|
|
unireader.offset_y = unireader.offset_y - y
|
|
|
|
if unireader.offset_y < unireader.min_offset_y then
|
2012-04-10 21:15:09 +00:00
|
|
|
if unireader.pan_by_page then
|
|
|
|
unireader.show_overlap = unireader.offset_y + y - unireader.min_offset_y - G_height
|
|
|
|
end
|
2012-03-13 21:51:25 +00:00
|
|
|
unireader.offset_y = unireader.min_offset_y
|
2012-04-09 13:06:05 +00:00
|
|
|
elseif unireader.pan_by_page then
|
|
|
|
unireader.show_overlap = -unireader.pan_overlap_vertical -- top
|
2012-03-13 21:51:25 +00:00
|
|
|
end
|
|
|
|
elseif keydef.keycode == KEY_FW_PRESS then
|
|
|
|
if keydef.modifier==MOD_SHIFT then
|
|
|
|
if unireader.pan_by_page then
|
|
|
|
unireader.offset_x = unireader.pan_x
|
|
|
|
unireader.offset_y = unireader.pan_y
|
|
|
|
else
|
|
|
|
unireader.offset_x = 0
|
|
|
|
unireader.offset_y = 0
|
|
|
|
end
|
|
|
|
else
|
|
|
|
unireader.pan_by_page = not unireader.pan_by_page
|
|
|
|
if unireader.pan_by_page then
|
|
|
|
unireader.pan_x = unireader.offset_x
|
|
|
|
unireader.pan_y = unireader.offset_y
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if old_offset_x ~= unireader.offset_x
|
|
|
|
or old_offset_y ~= unireader.offset_y then
|
2012-04-07 15:28:56 +00:00
|
|
|
unireader:redrawCurrentPage()
|
2012-03-20 19:15:24 +00:00
|
|
|
end
|
|
|
|
end
|
2012-03-13 21:51:25 +00:00
|
|
|
end)
|
storing rcountmax; user-configurable zoom step & pan steps, etc
1. In order to close issue #59, I've introduced user-configurable values for panning steps - for X- & Y-axis, separately. Now panning is called by pressing fiveway without mod_keys. When one presses Shift+FW, he/she changes panning steps in the following way - Shift-Left/Right = decrease / increase X-panning step (divide or multiply on factor 2), Shift-Up/Down = increase / decrease Y-panning step. The lowest value for panning steps is set 1. Both parameters, shift_x & shift_y, are saved to local settings (i.e. history file).
2. Manual zoom step was also made user-configurable. So, instead of two old zooming functions (with fixed 10% and 20%-steps), I made one function to zoom (Shift+<>), while the other (Alt+<>) changes the zoom step downto minimum 1%.
3. Fresh introduced function to change parameter rcountmax was added by storing rcountmax to both setting files - global settings & local ones (i.e. history file) - so that the rcountmax-priority (from low to high) is the following: default rcountmax=5 < its value in global settings < rcountmax stored for each concrete document.
3. Dirty, the extention-based hack to avoid reading not crengine-related parameters stored in history files. TODO: one has to finally introduce loadSpecialSettings() & readSpecialSettings() for PDFReader & DJVUReader and to store therein the reader-specific parameters (like globalgamma, bbox, globalzoom, globalzoom_mode; render_mode = for djvu-files only, etc.)
4. Some lua-code cosmetics (to make code more readable); for example: "self.pan_margin = settings:readSetting("pan_margin") or self.pan_margin" instead of
"local pan_margin = settings:readSetting("pan_margin")
if pan_margin then
self.pan_margin = pan_margin
end"
5. Fix for the today's tigran123 fix: issue #246 (details are included). Added InfoMessage:show() to inform most impatient users that the reader tries to redraw new zoo mode.
6. The fontface for the reading info (called by 'Menu') is restored to be in accordance with original intentions and with the same fontface in crereader.lua - namely, Font:getFace("rifont", 20)
7. Moved the exit hotkeys (Alt+Back & Home) to the end of hotkey list.
2012-09-03 19:23:06 +00:00
|
|
|
-- NuPogodi, 03.09.2012: functions to change panning steps
|
|
|
|
self.commands:addGroup("Shift + left/right", {Keydef:new(KEY_FW_LEFT,MOD_SHIFT), Keydef:new(KEY_FW_RIGHT,MOD_SHIFT)},
|
|
|
|
"increase/decrease X-panning step",
|
|
|
|
function(unireader,keydef)
|
|
|
|
unireader.globalzoom_mode = unireader.ZOOM_BY_VALUE
|
|
|
|
local minstep = 1
|
|
|
|
if keydef.keycode == KEY_FW_RIGHT then
|
|
|
|
unireader.shift_x = unireader.shift_x * 2
|
2012-09-05 17:54:49 +00:00
|
|
|
if unireader.shift_x >= G_width then
|
|
|
|
unireader.shift_x = G_width
|
|
|
|
showInfoMsgWithDelay("Maximum X-panning step is "..G_width..". ", 2000, 1)
|
|
|
|
end
|
storing rcountmax; user-configurable zoom step & pan steps, etc
1. In order to close issue #59, I've introduced user-configurable values for panning steps - for X- & Y-axis, separately. Now panning is called by pressing fiveway without mod_keys. When one presses Shift+FW, he/she changes panning steps in the following way - Shift-Left/Right = decrease / increase X-panning step (divide or multiply on factor 2), Shift-Up/Down = increase / decrease Y-panning step. The lowest value for panning steps is set 1. Both parameters, shift_x & shift_y, are saved to local settings (i.e. history file).
2. Manual zoom step was also made user-configurable. So, instead of two old zooming functions (with fixed 10% and 20%-steps), I made one function to zoom (Shift+<>), while the other (Alt+<>) changes the zoom step downto minimum 1%.
3. Fresh introduced function to change parameter rcountmax was added by storing rcountmax to both setting files - global settings & local ones (i.e. history file) - so that the rcountmax-priority (from low to high) is the following: default rcountmax=5 < its value in global settings < rcountmax stored for each concrete document.
3. Dirty, the extention-based hack to avoid reading not crengine-related parameters stored in history files. TODO: one has to finally introduce loadSpecialSettings() & readSpecialSettings() for PDFReader & DJVUReader and to store therein the reader-specific parameters (like globalgamma, bbox, globalzoom, globalzoom_mode; render_mode = for djvu-files only, etc.)
4. Some lua-code cosmetics (to make code more readable); for example: "self.pan_margin = settings:readSetting("pan_margin") or self.pan_margin" instead of
"local pan_margin = settings:readSetting("pan_margin")
if pan_margin then
self.pan_margin = pan_margin
end"
5. Fix for the today's tigran123 fix: issue #246 (details are included). Added InfoMessage:show() to inform most impatient users that the reader tries to redraw new zoo mode.
6. The fontface for the reading info (called by 'Menu') is restored to be in accordance with original intentions and with the same fontface in crereader.lua - namely, Font:getFace("rifont", 20)
7. Moved the exit hotkeys (Alt+Back & Home) to the end of hotkey list.
2012-09-03 19:23:06 +00:00
|
|
|
self.settings:saveSetting("shift_x", self.shift_x)
|
|
|
|
--showInfoMsgWithDelay("New X-panning step is "..unireader.shift_x..". ", 2000, 1)
|
|
|
|
else
|
|
|
|
if unireader.shift_x >= 2*minstep then
|
|
|
|
unireader.shift_x = math.ceil(unireader.shift_x / 2)
|
|
|
|
self.settings:saveSetting("shift_x", self.shift_x)
|
|
|
|
--showInfoMsgWithDelay("New X-panning step is "..unireader.shift_x..". ", 2000, 1)
|
|
|
|
else
|
|
|
|
showInfoMsgWithDelay("Minimum X-panning step is "..minstep..". ", 2000, 1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
self.commands:addGroup("Shift + up/down", {Keydef:new(KEY_FW_DOWN,MOD_SHIFT), Keydef:new(KEY_FW_UP,MOD_SHIFT)},
|
|
|
|
"increase/decrease Y-panning step",
|
|
|
|
function(unireader,keydef)
|
|
|
|
unireader.globalzoom_mode = unireader.ZOOM_BY_VALUE
|
|
|
|
local minstep = 1
|
|
|
|
if keydef.keycode == KEY_FW_UP then
|
|
|
|
unireader.shift_y = unireader.shift_y * 2
|
2012-09-05 17:54:49 +00:00
|
|
|
if unireader.shift_y >= G_height then
|
|
|
|
unireader.shift_y = G_height
|
|
|
|
showInfoMsgWithDelay("Maximum Y-panning step is "..G_height..". ", 2000, 1)
|
|
|
|
end
|
storing rcountmax; user-configurable zoom step & pan steps, etc
1. In order to close issue #59, I've introduced user-configurable values for panning steps - for X- & Y-axis, separately. Now panning is called by pressing fiveway without mod_keys. When one presses Shift+FW, he/she changes panning steps in the following way - Shift-Left/Right = decrease / increase X-panning step (divide or multiply on factor 2), Shift-Up/Down = increase / decrease Y-panning step. The lowest value for panning steps is set 1. Both parameters, shift_x & shift_y, are saved to local settings (i.e. history file).
2. Manual zoom step was also made user-configurable. So, instead of two old zooming functions (with fixed 10% and 20%-steps), I made one function to zoom (Shift+<>), while the other (Alt+<>) changes the zoom step downto minimum 1%.
3. Fresh introduced function to change parameter rcountmax was added by storing rcountmax to both setting files - global settings & local ones (i.e. history file) - so that the rcountmax-priority (from low to high) is the following: default rcountmax=5 < its value in global settings < rcountmax stored for each concrete document.
3. Dirty, the extention-based hack to avoid reading not crengine-related parameters stored in history files. TODO: one has to finally introduce loadSpecialSettings() & readSpecialSettings() for PDFReader & DJVUReader and to store therein the reader-specific parameters (like globalgamma, bbox, globalzoom, globalzoom_mode; render_mode = for djvu-files only, etc.)
4. Some lua-code cosmetics (to make code more readable); for example: "self.pan_margin = settings:readSetting("pan_margin") or self.pan_margin" instead of
"local pan_margin = settings:readSetting("pan_margin")
if pan_margin then
self.pan_margin = pan_margin
end"
5. Fix for the today's tigran123 fix: issue #246 (details are included). Added InfoMessage:show() to inform most impatient users that the reader tries to redraw new zoo mode.
6. The fontface for the reading info (called by 'Menu') is restored to be in accordance with original intentions and with the same fontface in crereader.lua - namely, Font:getFace("rifont", 20)
7. Moved the exit hotkeys (Alt+Back & Home) to the end of hotkey list.
2012-09-03 19:23:06 +00:00
|
|
|
self.settings:saveSetting("shift_y", self.shift_y)
|
|
|
|
--showInfoMsgWithDelay("New Y-panning step is "..unireader.shift_y..". ", 2000, 1)
|
|
|
|
else
|
|
|
|
if unireader.shift_y >= 2*minstep then
|
|
|
|
unireader.shift_y = math.ceil(unireader.shift_y / 2)
|
|
|
|
self.settings:saveSetting("shift_y", self.shift_y)
|
|
|
|
--showInfoMsgWithDelay("New Y-panning step is "..unireader.shift_y..". ", 2000, 1)
|
|
|
|
else
|
|
|
|
showInfoMsgWithDelay("Minimum Y-panning step is "..minstep..". ", 2000, 1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|
2012-03-20 19:15:24 +00:00
|
|
|
-- end panning
|
storing rcountmax; user-configurable zoom step & pan steps, etc
1. In order to close issue #59, I've introduced user-configurable values for panning steps - for X- & Y-axis, separately. Now panning is called by pressing fiveway without mod_keys. When one presses Shift+FW, he/she changes panning steps in the following way - Shift-Left/Right = decrease / increase X-panning step (divide or multiply on factor 2), Shift-Up/Down = increase / decrease Y-panning step. The lowest value for panning steps is set 1. Both parameters, shift_x & shift_y, are saved to local settings (i.e. history file).
2. Manual zoom step was also made user-configurable. So, instead of two old zooming functions (with fixed 10% and 20%-steps), I made one function to zoom (Shift+<>), while the other (Alt+<>) changes the zoom step downto minimum 1%.
3. Fresh introduced function to change parameter rcountmax was added by storing rcountmax to both setting files - global settings & local ones (i.e. history file) - so that the rcountmax-priority (from low to high) is the following: default rcountmax=5 < its value in global settings < rcountmax stored for each concrete document.
3. Dirty, the extention-based hack to avoid reading not crengine-related parameters stored in history files. TODO: one has to finally introduce loadSpecialSettings() & readSpecialSettings() for PDFReader & DJVUReader and to store therein the reader-specific parameters (like globalgamma, bbox, globalzoom, globalzoom_mode; render_mode = for djvu-files only, etc.)
4. Some lua-code cosmetics (to make code more readable); for example: "self.pan_margin = settings:readSetting("pan_margin") or self.pan_margin" instead of
"local pan_margin = settings:readSetting("pan_margin")
if pan_margin then
self.pan_margin = pan_margin
end"
5. Fix for the today's tigran123 fix: issue #246 (details are included). Added InfoMessage:show() to inform most impatient users that the reader tries to redraw new zoo mode.
6. The fontface for the reading info (called by 'Menu') is restored to be in accordance with original intentions and with the same fontface in crereader.lua - namely, Font:getFace("rifont", 20)
7. Moved the exit hotkeys (Alt+Back & Home) to the end of hotkey list.
2012-09-03 19:23:06 +00:00
|
|
|
|
2012-04-11 20:52:48 +00:00
|
|
|
-- highlight mode
|
|
|
|
self.commands:add(KEY_N, nil, "N",
|
|
|
|
"start highlight mode",
|
|
|
|
function(unireader)
|
|
|
|
unireader:startHighLightMode()
|
|
|
|
unireader:goto(unireader.pageno)
|
|
|
|
end
|
|
|
|
)
|
|
|
|
self.commands:add(KEY_N, MOD_SHIFT, "N",
|
|
|
|
"display all highlights",
|
|
|
|
function(unireader)
|
|
|
|
unireader:showHighLight()
|
|
|
|
unireader:goto(unireader.pageno)
|
|
|
|
end
|
|
|
|
)
|
2012-08-26 12:28:03 +00:00
|
|
|
self.commands:add(KEY_DOT, nil, ".",
|
|
|
|
"search and highlight text",
|
|
|
|
function(unireader)
|
2012-08-28 20:14:04 +00:00
|
|
|
Screen:saveCurrentBB()
|
2012-08-26 12:28:03 +00:00
|
|
|
local search = InputBox:input(G_height - 100, 100,
|
2012-08-26 14:19:51 +00:00
|
|
|
"Search:", self.last_search.search )
|
2012-08-28 20:14:04 +00:00
|
|
|
Screen:restoreFromSavedBB()
|
2012-08-26 12:28:03 +00:00
|
|
|
|
2012-08-26 12:48:51 +00:00
|
|
|
if search ~= nil and string.len( search ) > 0 then
|
|
|
|
unireader:searchHighLight(search)
|
2012-08-30 04:43:05 +00:00
|
|
|
else
|
|
|
|
unireader:goto(unireader.pageno)
|
2012-08-26 12:28:03 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
)
|
storing rcountmax; user-configurable zoom step & pan steps, etc
1. In order to close issue #59, I've introduced user-configurable values for panning steps - for X- & Y-axis, separately. Now panning is called by pressing fiveway without mod_keys. When one presses Shift+FW, he/she changes panning steps in the following way - Shift-Left/Right = decrease / increase X-panning step (divide or multiply on factor 2), Shift-Up/Down = increase / decrease Y-panning step. The lowest value for panning steps is set 1. Both parameters, shift_x & shift_y, are saved to local settings (i.e. history file).
2. Manual zoom step was also made user-configurable. So, instead of two old zooming functions (with fixed 10% and 20%-steps), I made one function to zoom (Shift+<>), while the other (Alt+<>) changes the zoom step downto minimum 1%.
3. Fresh introduced function to change parameter rcountmax was added by storing rcountmax to both setting files - global settings & local ones (i.e. history file) - so that the rcountmax-priority (from low to high) is the following: default rcountmax=5 < its value in global settings < rcountmax stored for each concrete document.
3. Dirty, the extention-based hack to avoid reading not crengine-related parameters stored in history files. TODO: one has to finally introduce loadSpecialSettings() & readSpecialSettings() for PDFReader & DJVUReader and to store therein the reader-specific parameters (like globalgamma, bbox, globalzoom, globalzoom_mode; render_mode = for djvu-files only, etc.)
4. Some lua-code cosmetics (to make code more readable); for example: "self.pan_margin = settings:readSetting("pan_margin") or self.pan_margin" instead of
"local pan_margin = settings:readSetting("pan_margin")
if pan_margin then
self.pan_margin = pan_margin
end"
5. Fix for the today's tigran123 fix: issue #246 (details are included). Added InfoMessage:show() to inform most impatient users that the reader tries to redraw new zoo mode.
6. The fontface for the reading info (called by 'Menu') is restored to be in accordance with original intentions and with the same fontface in crereader.lua - namely, Font:getFace("rifont", 20)
7. Moved the exit hotkeys (Alt+Back & Home) to the end of hotkey list.
2012-09-03 19:23:06 +00:00
|
|
|
self.commands:add(KEY_BACK,MOD_ALT,"Back",
|
|
|
|
"close document",
|
|
|
|
function(unireader)
|
|
|
|
return "break"
|
|
|
|
end)
|
|
|
|
self.commands:add(KEY_HOME,nil,"Home",
|
|
|
|
"exit application",
|
|
|
|
function(unireader)
|
|
|
|
keep_running = false
|
|
|
|
return "break"
|
|
|
|
end)
|
2012-04-13 18:46:10 +00:00
|
|
|
-- commands.map is very large, impacts startup performance on device
|
2012-06-03 22:49:23 +00:00
|
|
|
--Debug("defined commands "..dump(self.commands.map))
|
2012-03-13 21:14:26 +00:00
|
|
|
end
|