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,
|
|
|
|
rcountmax = 5,
|
|
|
|
|
|
|
|
-- zoom state:
|
|
|
|
globalzoom = 1.0,
|
|
|
|
globalzoom_orig = 1.0,
|
|
|
|
globalzoommode = -1, -- ZOOM_FIT_TO_PAGE
|
|
|
|
|
|
|
|
globalrotate = 0,
|
|
|
|
|
|
|
|
-- gamma setting:
|
|
|
|
globalgamma = 1.0, -- GAMMA_NO_GAMMA
|
|
|
|
|
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-03-05 01:46:16 +00:00
|
|
|
offset_x = 0,
|
|
|
|
offset_y = 0,
|
|
|
|
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,
|
|
|
|
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-03-05 13:17:07 +00:00
|
|
|
pan_margin = 20, -- horizontal margin for two-column zoom
|
|
|
|
pan_overlap_vertical = 30,
|
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-03-05 01:46:16 +00:00
|
|
|
jump_stack = {},
|
2012-03-21 02:37:18 +00:00
|
|
|
highlight = {},
|
2012-03-05 05:15:34 +00:00
|
|
|
toc = nil,
|
2012-03-06 22:18:52 +00:00
|
|
|
|
2012-03-06 23:26:56 +00:00
|
|
|
bbox = {}, -- override getUsedBBox
|
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,
|
|
|
|
-- you must always overwrite following two methods:
|
|
|
|
--
|
|
|
|
-- * self:open()
|
|
|
|
-- * self:init()
|
|
|
|
--
|
|
|
|
-- overwrite other methods if needed.
|
|
|
|
----------------------------------------------------
|
2012-03-05 01:46:16 +00:00
|
|
|
function UniReader:init()
|
2012-03-30 06:10:04 +00:00
|
|
|
-- initialize commands
|
|
|
|
self:addAllCommands()
|
2012-03-05 01:46:16 +00:00
|
|
|
end
|
|
|
|
|
2012-03-05 01:58:19 +00:00
|
|
|
-- open a file and its settings store
|
|
|
|
-- tips: you can use self:loadSettings in open() method.
|
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-23 07:51:48 +00:00
|
|
|
----------------------------------------------------
|
|
|
|
-- You need to overwrite following two methods if your
|
|
|
|
-- reader supports highlight feature.
|
|
|
|
----------------------------------------------------
|
2012-03-26 12:25:44 +00:00
|
|
|
|
|
|
|
function UniReader:startHighLightMode()
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2012-03-23 07:51:48 +00:00
|
|
|
function UniReader:highLightText()
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
function UniReader:toggleTextHighLight(word_list)
|
|
|
|
return
|
|
|
|
end
|
2012-03-05 01:58:19 +00:00
|
|
|
|
2012-03-31 10:53:40 +00:00
|
|
|
----------------------------------------------------
|
|
|
|
-- renderer memory
|
|
|
|
----------------------------------------------------
|
|
|
|
|
|
|
|
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-03-05 01:58:19 +00:00
|
|
|
|
|
|
|
--[ following are default methods ]--
|
2012-03-30 05:07:48 +00:00
|
|
|
function UniReader:initGlobalSettings(settings)
|
|
|
|
local pan_overlap_vertical = settings:readSetting("pan_overlap_vertical")
|
|
|
|
if pan_overlap_vertical then
|
|
|
|
self.pan_overlap_vertical = pan_overlap_vertical
|
|
|
|
end
|
|
|
|
|
|
|
|
local cache_max_memsize = settings:readSetting("cache_max_memsize")
|
|
|
|
if cache_max_memsize then
|
|
|
|
self.cache_max_memsize = cache_max_memsize
|
|
|
|
end
|
|
|
|
|
|
|
|
local cache_max_ttl = settings:readSetting("cache_max_ttl")
|
|
|
|
if cache_max_ttl then
|
|
|
|
self.cache_max_ttl = cache_max_ttl
|
|
|
|
end
|
2012-04-01 00:27:25 +00:00
|
|
|
|
|
|
|
local rcountmax = settings:readSetting("partial_refresh_count")
|
|
|
|
if rcountmax then
|
|
|
|
self.rcountmax = rcountmax
|
|
|
|
end
|
2012-03-30 05:07:48 +00:00
|
|
|
end
|
2012-03-05 01:58:19 +00:00
|
|
|
|
|
|
|
function UniReader:loadSettings(filename)
|
|
|
|
if self.doc ~= nil then
|
2012-03-31 12:09:50 +00:00
|
|
|
self.settings = DocSettings:open(filename,self.cache_document_size)
|
2012-03-05 02:48:03 +00:00
|
|
|
|
2012-03-20 19:15:24 +00:00
|
|
|
local gamma = self.settings:readSetting("gamma")
|
2012-03-05 01:58:19 +00:00
|
|
|
if gamma then
|
|
|
|
self.globalgamma = gamma
|
|
|
|
end
|
2012-03-05 02:48:03 +00:00
|
|
|
|
2012-03-20 19:15:24 +00:00
|
|
|
local jumpstack = self.settings:readSetting("jumpstack")
|
2012-03-05 02:48:03 +00:00
|
|
|
self.jump_stack = jumpstack or {}
|
|
|
|
|
2012-03-21 03:20:07 +00:00
|
|
|
local highlight = self.settings:readSetting("highlight")
|
|
|
|
self.highlight = highlight or {}
|
|
|
|
|
2012-03-20 19:15:24 +00:00
|
|
|
local bbox = self.settings:readSetting("bbox")
|
2012-03-07 23:38:34 +00:00
|
|
|
print("# bbox loaded "..dump(bbox))
|
|
|
|
self.bbox = bbox
|
|
|
|
|
2012-03-20 19:15:24 +00:00
|
|
|
self.globalzoom = self.settings:readSetting("globalzoom") or 1.0
|
|
|
|
self.globalzoommode = self.settings:readSetting("globalzoommode") or -1
|
2012-03-08 00:29:17 +00:00
|
|
|
|
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()
|
|
|
|
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)
|
|
|
|
|
|
|
|
-- 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)
|
|
|
|
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
|
|
|
|
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
|
|
|
|
print("E: not enough memory in cache left, probably a bug.")
|
|
|
|
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-03-13 07:37:45 +00:00
|
|
|
--print ("# new biltbuffer:"..dump(self.cache[pagehash]))
|
2012-03-12 23:02:49 +00:00
|
|
|
dc:setOffset(-tile.x, -tile.y)
|
|
|
|
print("# rendering: page="..no)
|
|
|
|
page:draw(dc, self.cache[pagehash].bb, 0, 0)
|
|
|
|
page:close()
|
|
|
|
|
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-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)
|
|
|
|
print("# page::getSize "..pwidth.."*"..pheight);
|
|
|
|
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
|
|
|
|
-- 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-03-06 22:18:52 +00:00
|
|
|
print("# 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
|
|
|
|
print("## bbox from "..self.pageno)
|
|
|
|
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-03-20 19:15:24 +00:00
|
|
|
print("## 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
|
|
|
|
print("## bbox from "..self.pageno - i)
|
|
|
|
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-03-05 01:46:16 +00:00
|
|
|
print("# page::getUsedBBox "..x0.."*"..y0.." "..x1.."*"..y1);
|
|
|
|
|
|
|
|
if self.globalzoommode == self.ZOOM_FIT_TO_PAGE
|
|
|
|
or self.globalzoommode == self.ZOOM_FIT_TO_CONTENT then
|
|
|
|
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-03-05 01:46:16 +00:00
|
|
|
elseif self.globalzoommode == self.ZOOM_FIT_TO_PAGE_WIDTH
|
|
|
|
or self.globalzoommode == self.ZOOM_FIT_TO_CONTENT_WIDTH then
|
|
|
|
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-03-05 01:46:16 +00:00
|
|
|
elseif self.globalzoommode == self.ZOOM_FIT_TO_PAGE_HEIGHT
|
|
|
|
or self.globalzoommode == self.ZOOM_FIT_TO_CONTENT_HEIGHT then
|
|
|
|
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-03-05 01:46:16 +00:00
|
|
|
if self.globalzoommode == self.ZOOM_FIT_TO_CONTENT then
|
|
|
|
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-03-05 01:46:16 +00:00
|
|
|
elseif self.globalzoommode == self.ZOOM_FIT_TO_CONTENT_WIDTH then
|
|
|
|
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
|
|
|
|
self.globalzoommode = self.ZOOM_FIT_TO_CONTENT_WIDTH_PAN
|
|
|
|
elseif self.globalzoommode == self.ZOOM_FIT_TO_CONTENT_WIDTH_PAN then
|
|
|
|
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.
|
|
|
|
-- Since this a real page turn, we need to recalcunate stuff.
|
|
|
|
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
|
|
|
|
elseif self.globalzoommode == self.ZOOM_FIT_TO_CONTENT_HEIGHT then
|
|
|
|
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-03-05 13:17:07 +00:00
|
|
|
elseif self.globalzoommode == self.ZOOM_FIT_TO_CONTENT_HALF_WIDTH
|
|
|
|
or self.globalzoommode == self.ZOOM_FIT_TO_CONTENT_HALF_WIDTH_MARGIN then
|
|
|
|
local margin = self.pan_margin
|
|
|
|
if self.globalzoommode == self.ZOOM_FIT_TO_CONTENT_HALF_WIDTH then margin = 0 end
|
|
|
|
self.globalzoom = width / (x1 - x0 + margin)
|
|
|
|
self.offset_x = -1 * x0 * self.globalzoom * 2 + margin
|
2012-03-05 01:46:16 +00:00
|
|
|
self.globalzoom = height / (y1 - y0)
|
2012-03-05 13:17:07 +00:00
|
|
|
self.offset_y = -1 * y0 * self.globalzoom * 2 + margin
|
|
|
|
self.globalzoom = width / (x1 - x0 + margin) * 2
|
2012-03-05 01:46:16 +00:00
|
|
|
print("column mode offset:"..self.offset_x.."*"..self.offset_y.." zoom:"..self.globalzoom);
|
|
|
|
self.globalzoommode = self.ZOOM_BY_VALUE -- enable pan mode
|
|
|
|
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
|
|
|
|
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-03-20 19:15:24 +00:00
|
|
|
print("# 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
|
|
|
|
print("gamma correction: "..self.globalgamma)
|
|
|
|
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-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
|
|
|
|
local dest_x = 0
|
|
|
|
local dest_y = 0
|
|
|
|
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-03-12 23:02:49 +00:00
|
|
|
dest_x = (width - (bb:getWidth() - offset_x)) / 2
|
|
|
|
end
|
2012-03-20 19:15:24 +00:00
|
|
|
if bb:getHeight() - offset_y < height and
|
2012-03-13 08:21:16 +00:00
|
|
|
self.globalzoommode ~= 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-03-12 23:02:49 +00:00
|
|
|
dest_y = (height - (bb:getHeight() - offset_y)) / 2
|
2012-03-13 08:21:16 +00:00
|
|
|
elseif self.globalzoommode == self.ZOOM_FIT_TO_CONTENT_WIDTH_PAN and
|
|
|
|
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.
|
|
|
|
dest_y = self.offset_y
|
2012-03-05 01:46:16 +00:00
|
|
|
end
|
2012-03-12 23:02:49 +00:00
|
|
|
if dest_x or dest_y then
|
|
|
|
fb.bb:paintRect(0, 0, width, height, 8)
|
2012-03-05 01:46:16 +00:00
|
|
|
end
|
2012-03-13 08:21:16 +00:00
|
|
|
print("# blitFrom dest_off:("..dest_x..", "..dest_y..
|
|
|
|
"), src_off:("..offset_x..", "..offset_y.."), "..
|
|
|
|
"width:"..width..", height:"..height)
|
2012-03-12 23:02:49 +00:00
|
|
|
fb.bb:blitFrom(bb, dest_x, dest_y, offset_x, offset_y, width, height)
|
2012-03-21 02:37:18 +00:00
|
|
|
|
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-03-05 01:46:16 +00:00
|
|
|
print("full refresh")
|
|
|
|
self.rcount = 1
|
|
|
|
fb:refresh(0)
|
|
|
|
else
|
|
|
|
print("partial refresh")
|
|
|
|
self.rcount = self.rcount + 1
|
|
|
|
fb:refresh(1)
|
|
|
|
end
|
|
|
|
self.slot_visible = slot;
|
|
|
|
end
|
|
|
|
|
2012-03-05 03:25:51 +00:00
|
|
|
--[[
|
|
|
|
@ pageno is the page you want to add to jump_stack
|
|
|
|
--]]
|
2012-03-20 19:15:24 +00:00
|
|
|
function UniReader:addJump(pageno, notes)
|
2012-03-05 01:46:16 +00:00
|
|
|
local jump_item = nil
|
2012-03-20 19:15:24 +00:00
|
|
|
local notes_to_add = notes
|
2012-03-05 05:15:34 +00:00
|
|
|
if not notes_to_add then
|
2012-03-29 10:17:32 +00:00
|
|
|
-- no notes given, auto generate from Toc entry
|
2012-03-28 16:09:26 +00:00
|
|
|
notes_to_add = self:getTocTitleByPage(self.pageno)
|
2012-03-05 05:15:34 +00:00
|
|
|
if notes_to_add ~= "" then
|
|
|
|
notes_to_add = "in "..notes_to_add
|
|
|
|
end
|
|
|
|
end
|
|
|
|
-- move pageno page to jump_stack top if already in
|
2012-03-05 01:46:16 +00:00
|
|
|
for _t,_v in ipairs(self.jump_stack) do
|
|
|
|
if _v.page == pageno then
|
|
|
|
jump_item = _v
|
|
|
|
table.remove(self.jump_stack, _t)
|
2012-03-05 05:15:34 +00:00
|
|
|
-- if original notes is not empty, probably defined by users,
|
|
|
|
-- we use the original notes to overwrite auto generated notes
|
2012-03-29 10:17:32 +00:00
|
|
|
-- from Toc entry
|
2012-03-05 05:15:34 +00:00
|
|
|
if jump_item.notes ~= "" then
|
|
|
|
notes_to_add = jump_item.notes
|
|
|
|
end
|
|
|
|
jump_item.notes = notes or notes_to_add
|
2012-03-05 03:25:51 +00:00
|
|
|
break
|
2012-03-05 01:46:16 +00:00
|
|
|
end
|
|
|
|
end
|
2012-03-05 03:25:51 +00:00
|
|
|
-- create a new one if page not found in stack
|
2012-03-05 01:46:16 +00:00
|
|
|
if not jump_item then
|
|
|
|
jump_item = {
|
|
|
|
page = pageno,
|
|
|
|
datetime = os.date("%Y-%m-%d %H:%M:%S"),
|
2012-03-05 05:15:34 +00:00
|
|
|
notes = notes_to_add,
|
2012-03-05 01:46:16 +00:00
|
|
|
}
|
|
|
|
end
|
2012-03-05 03:25:51 +00:00
|
|
|
|
|
|
|
-- insert item at the start
|
2012-03-05 01:46:16 +00:00
|
|
|
table.insert(self.jump_stack, 1, jump_item)
|
2012-03-05 03:25:51 +00:00
|
|
|
|
2012-03-05 01:46:16 +00:00
|
|
|
if #self.jump_stack > 10 then
|
|
|
|
-- remove the last element to keep the size less than 10
|
|
|
|
table.remove(self.jump_stack)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-03-20 19:15:24 +00:00
|
|
|
function UniReader:delJump(pageno)
|
2012-03-05 03:25:51 +00:00
|
|
|
for _t,_v in ipairs(self.jump_stack) do
|
|
|
|
if _v.page == pageno then
|
|
|
|
table.remove(self.jump_stack, _t)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-03-05 01:46:16 +00:00
|
|
|
-- change current page and cache next page after rendering
|
|
|
|
function UniReader:goto(no)
|
|
|
|
if no < 1 or no > self.doc:getPages() then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2012-03-05 03:25:51 +00:00
|
|
|
-- for jump_stack, distinguish jump from normal page turn
|
2012-03-05 01:46:16 +00:00
|
|
|
if self.pageno and math.abs(self.pageno - no) > 1 then
|
2012-03-20 19:15:24 +00:00
|
|
|
self:addJump(self.pageno)
|
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
|
|
|
|
|
|
|
|
if self.globalzoommode == self.ZOOM_FIT_TO_CONTENT_WIDTH_PAN then
|
|
|
|
if self.offset_y <= self.min_offset_y then
|
|
|
|
-- hit content bottom, turn to next page
|
|
|
|
self.globalzoommode = self.ZOOM_FIT_TO_CONTENT_WIDTH
|
|
|
|
pageno = pageno + 1
|
|
|
|
else
|
|
|
|
-- goto next view of current page
|
|
|
|
self.offset_y = self.offset_y - height + self.pan_overlap_vertical
|
|
|
|
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
|
|
|
|
|
|
|
|
if self.globalzoommode == self.ZOOM_FIT_TO_CONTENT_WIDTH_PAN then
|
|
|
|
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
|
|
|
|
self.offset_y = self.offset_y + height - self.pan_overlap_vertical
|
|
|
|
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)
|
|
|
|
print("modifyGamma, gamma="..self.globalgamma.." factor="..factor)
|
2012-03-05 01:46:16 +00:00
|
|
|
self.globalgamma = self.globalgamma * factor;
|
|
|
|
self:goto(self.pageno)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- adjust zoom state and trigger re-rendering
|
2012-03-20 19:15:24 +00:00
|
|
|
function UniReader:setGlobalZoomMode(newzoommode)
|
2012-03-05 01:46:16 +00:00
|
|
|
if self.globalzoommode ~= newzoommode then
|
|
|
|
self.globalzoommode = newzoommode
|
|
|
|
self:goto(self.pageno)
|
|
|
|
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
|
|
|
|
self.globalzoommode = self.ZOOM_BY_VALUE
|
|
|
|
self.globalzoom = zoom
|
|
|
|
self:goto(self.pageno)
|
|
|
|
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
|
|
|
|
self:goto(self.pageno)
|
|
|
|
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-03-08 15:28:16 +00:00
|
|
|
width, height = fb:getSize()
|
2012-03-20 19:15:24 +00:00
|
|
|
self:clearCache()
|
2012-03-08 15:28:16 +00:00
|
|
|
self:goto(self.pageno)
|
|
|
|
end
|
|
|
|
|
2012-03-29 10:17:32 +00:00
|
|
|
function UniReader:cleanUpTocTitle(title)
|
2012-03-05 05:43:23 +00:00
|
|
|
return title:gsub("\13", "")
|
|
|
|
end
|
|
|
|
|
2012-03-29 10:17:32 +00:00
|
|
|
function UniReader:fillToc()
|
|
|
|
self.toc = self.doc:getToc()
|
2012-03-05 05:15:34 +00:00
|
|
|
end
|
|
|
|
|
2012-03-28 16:09:26 +00:00
|
|
|
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-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-03-29 10:17:32 +00:00
|
|
|
function UniReader:showToc()
|
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-03-05 05:15:34 +00:00
|
|
|
end
|
2012-03-05 01:46:16 +00:00
|
|
|
local menu_items = {}
|
2012-03-05 22:36:58 +00:00
|
|
|
local filtered_toc = {}
|
2012-03-05 01:46:16 +00:00
|
|
|
-- build menu items
|
2012-03-26 18:45:44 +00:00
|
|
|
for k,v in ipairs(self.toc) do
|
2012-03-16 04:27:27 +00:00
|
|
|
table.insert(menu_items,
|
2012-03-29 10:17:32 +00:00
|
|
|
(" "):rep(v.depth-1)..self:cleanUpTocTitle(v.title))
|
2012-03-26 18:45:44 +00:00
|
|
|
table.insert(filtered_toc,v.page)
|
2012-03-05 01:46:16 +00:00
|
|
|
end
|
|
|
|
toc_menu = SelectMenu:new{
|
|
|
|
menu_title = "Table of Contents",
|
|
|
|
item_array = menu_items,
|
|
|
|
no_item_msg = "This document does not have a Table of Contents.",
|
|
|
|
}
|
|
|
|
item_no = toc_menu:choose(0, fb.bb:getHeight())
|
|
|
|
if item_no then
|
2012-03-05 22:36:58 +00:00
|
|
|
self:goto(filtered_toc[item_no])
|
2012-03-05 01:46:16 +00:00
|
|
|
else
|
|
|
|
self:goto(self.pageno)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function UniReader:showJumpStack()
|
|
|
|
local menu_items = {}
|
2012-03-26 18:45:44 +00:00
|
|
|
for k,v in ipairs(self.jump_stack) do
|
2012-03-20 19:15:24 +00:00
|
|
|
table.insert(menu_items,
|
2012-03-26 18:45:44 +00:00
|
|
|
v.datetime.." -> Page "..v.page.." "..v.notes)
|
2012-03-05 01:46:16 +00:00
|
|
|
end
|
|
|
|
jump_menu = SelectMenu:new{
|
2012-03-20 19:15:24 +00:00
|
|
|
menu_title = "Jump Keeper (current page: "..self.pageno..")",
|
2012-03-05 01:46:16 +00:00
|
|
|
item_array = menu_items,
|
|
|
|
no_item_msg = "No jump history.",
|
|
|
|
}
|
|
|
|
item_no = jump_menu:choose(0, fb.bb:getHeight())
|
|
|
|
if item_no then
|
|
|
|
local jump_item = self.jump_stack[item_no]
|
|
|
|
self:goto(jump_item.page)
|
|
|
|
else
|
|
|
|
self:goto(self.pageno)
|
|
|
|
end
|
|
|
|
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
|
|
|
|
toc_menu = SelectMenu:new{
|
|
|
|
menu_title = "HighLights",
|
|
|
|
item_array = menu_items,
|
|
|
|
no_item_msg = "No HighLight found.",
|
|
|
|
}
|
|
|
|
item_no = toc_menu:choose(0, fb.bb:getHeight())
|
|
|
|
if item_no then
|
|
|
|
self:goto(highlight_dict[item_no].page)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-03-29 10:17:32 +00:00
|
|
|
-- used in UniReader:showMenu()
|
|
|
|
function UniReader:_drawReadingInfo()
|
2012-03-10 08:41:23 +00:00
|
|
|
local ypos = height - 50
|
|
|
|
local load_percent = (self.pageno / self.doc:getPages())
|
2012-03-31 16:57:22 +00:00
|
|
|
local face, fhash = Font:getFaceAndHash(22)
|
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)
|
|
|
|
renderUtf8Text(fb.bb, 10, 15+6, face, fhash,
|
|
|
|
"Memory: "..
|
|
|
|
math.ceil( self.cache_current_memsize / 1024 ).."/"..math.ceil( self.cache_max_memsize / 1024 )..
|
|
|
|
" "..math.ceil( self.doc:getCacheSize() / 1024 ).."/"..math.ceil( self.cache_document_size / 1024 ).." k",
|
|
|
|
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-03-28 16:09:26 +00:00
|
|
|
local cur_section = self:getTocTitleByPage(self.pageno)
|
2012-03-10 08:41:23 +00:00
|
|
|
if cur_section ~= "" then
|
|
|
|
cur_section = "Section: "..cur_section
|
|
|
|
end
|
|
|
|
renderUtf8Text(fb.bb, 10, ypos+6, face, fhash,
|
|
|
|
"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
|
|
|
|
local ev = input.waitForEvent()
|
|
|
|
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)
|
|
|
|
print("## 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
|
|
|
|
local ev = input.waitForEvent()
|
|
|
|
ev.code = adjustKeyEvents(ev)
|
|
|
|
if ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_PRESS then
|
|
|
|
local secs, usecs = util.gettime()
|
2012-03-20 19:15:24 +00:00
|
|
|
keydef = Keydef:new(ev.code, getKeyModifier())
|
2012-03-13 21:51:25 +00:00
|
|
|
print("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-03-20 19:15:24 +00:00
|
|
|
print("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-03-13 21:51:25 +00:00
|
|
|
print("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
|
|
|
|
print("E: T="..ev.type.." V="..ev.value.." C="..ev.code.." DUR="..dur)
|
|
|
|
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-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-03-05 01:46:16 +00:00
|
|
|
self.settings:savesetting("gamma", self.globalgamma)
|
2012-03-05 02:48:03 +00:00
|
|
|
self.settings:savesetting("jumpstack", self.jump_stack)
|
2012-03-07 23:18:58 +00:00
|
|
|
self.settings:savesetting("bbox", self.bbox)
|
2012-03-08 00:29:17 +00:00
|
|
|
self.settings:savesetting("globalzoom", self.globalzoom)
|
|
|
|
self.settings:savesetting("globalzoommode", self.globalzoommode)
|
2012-03-21 03:20:07 +00:00
|
|
|
self.settings:savesetting("highlight", self.highlight)
|
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-03-27 17:58:29 +00:00
|
|
|
self.commands:add({KEY_PGFWD,KEY_LPGFWD},nil,">",
|
2012-03-13 21:51:25 +00:00
|
|
|
"next page",
|
2012-03-10 09:28:54 +00:00
|
|
|
function(unireader)
|
2012-03-13 21:51:25 +00:00
|
|
|
unireader:goto(unireader:nextView())
|
2012-03-10 09:28:54 +00:00
|
|
|
end)
|
2012-03-27 17:58:29 +00:00
|
|
|
self.commands:add({KEY_PGBCK,KEY_LPGBCK},nil,"<",
|
2012-03-13 21:51:25 +00:00
|
|
|
"previous page",
|
2012-03-10 09:28:54 +00:00
|
|
|
function(unireader)
|
2012-03-13 21:51:25 +00:00
|
|
|
unireader:goto(unireader:prevView())
|
2012-03-10 09:28:54 +00:00
|
|
|
end)
|
2012-03-13 21:51:25 +00:00
|
|
|
self.commands:add(KEY_PGFWD,MOD_ALT,">",
|
|
|
|
"zoom in 10%",
|
2012-03-10 09:28:54 +00:00
|
|
|
function(unireader)
|
2012-03-20 19:15:24 +00:00
|
|
|
unireader:setGlobalZoom(unireader.globalzoom+unireader.globalzoom_orig*0.1)
|
2012-03-10 09:28:54 +00:00
|
|
|
end)
|
2012-03-13 21:51:25 +00:00
|
|
|
self.commands:add(KEY_PGBCK,MOD_ALT,"<",
|
|
|
|
"zoom out 10%",
|
2012-03-10 09:28:54 +00:00
|
|
|
function(unireader)
|
2012-03-20 19:15:24 +00:00
|
|
|
unireader:setGlobalZoom(unireader.globalzoom-unireader.globalzoom_orig*0.1)
|
|
|
|
end)
|
2012-03-13 21:51:25 +00:00
|
|
|
self.commands:add(KEY_PGFWD,MOD_SHIFT,">",
|
|
|
|
"zoom in 20%",
|
2012-03-10 09:28:54 +00:00
|
|
|
function(unireader)
|
2012-03-20 19:15:24 +00:00
|
|
|
unireader:setGlobalZoom(unireader.globalzoom+unireader.globalzoom_orig*0.2)
|
2012-03-10 09:28:54 +00:00
|
|
|
end)
|
2012-03-13 21:51:25 +00:00
|
|
|
self.commands:add(KEY_PGBCK,MOD_SHIFT,"<",
|
|
|
|
"zoom out 20%",
|
2012-03-10 09:28:54 +00:00
|
|
|
function(unireader)
|
2012-03-20 19:15:24 +00:00
|
|
|
unireader:setGlobalZoom(unireader.globalzoom-unireader.globalzoom_orig*0.2)
|
2012-03-10 09:28:54 +00:00
|
|
|
end)
|
2012-03-13 21:51:25 +00:00
|
|
|
self.commands:add(KEY_BACK,nil,"back",
|
|
|
|
"back to last jump",
|
2012-03-10 09:28:54 +00:00
|
|
|
function(unireader)
|
|
|
|
if #unireader.jump_stack ~= 0 then
|
|
|
|
unireader:goto(unireader.jump_stack[1].page)
|
|
|
|
end
|
2012-03-20 19:15:24 +00:00
|
|
|
end)
|
2012-03-13 21:51:25 +00:00
|
|
|
self.commands:add(KEY_BACK,MOD_ALT,"back",
|
|
|
|
"close document",
|
|
|
|
function(unireader)
|
|
|
|
return "break"
|
2012-03-10 09:28:54 +00:00
|
|
|
end)
|
2012-03-13 21:51:25 +00:00
|
|
|
self.commands:add(KEY_VPLUS,nil,"vol+",
|
|
|
|
"increase gamma 25%",
|
2012-03-10 09:28:54 +00:00
|
|
|
function(unireader)
|
2012-03-20 19:15:24 +00:00
|
|
|
unireader:modifyGamma( 1.25 )
|
2012-03-10 09:28:54 +00:00
|
|
|
end)
|
2012-03-13 21:51:25 +00:00
|
|
|
self.commands:add(KEY_VMINUS,nil,"vol-",
|
|
|
|
"decrease gamma 25%",
|
2012-03-10 09:28:54 +00:00
|
|
|
function(unireader)
|
2012-03-20 19:15:24 +00:00
|
|
|
unireader:modifyGamma( 0.80 )
|
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-03-20 19:15:24 +00:00
|
|
|
self.commands:addGroup("[1..0]",numeric_keydefs,
|
2012-03-13 21:51:25 +00:00
|
|
|
"jump to <key>*10% of document",
|
2012-03-10 09:28:54 +00:00
|
|
|
function(unireader,keydef)
|
|
|
|
print('jump to page: '..math.max(math.floor(unireader.doc:getPages()*(keydef.keycode-KEY_1)/9),1)..'/'..unireader.doc:getPages())
|
|
|
|
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
|
|
|
|
self.commands:add(KEY_A,nil,"A",
|
|
|
|
"zoom to fit page",
|
2012-03-10 09:28:54 +00:00
|
|
|
function(unireader)
|
2012-03-20 19:15:24 +00:00
|
|
|
unireader:setGlobalZoomMode(unireader.ZOOM_FIT_TO_PAGE)
|
|
|
|
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-03-20 19:15:24 +00:00
|
|
|
unireader:setGlobalZoomMode(unireader.ZOOM_FIT_TO_CONTENT)
|
|
|
|
end)
|
2012-03-13 21:51:25 +00:00
|
|
|
self.commands:add(KEY_S,nil,"S",
|
|
|
|
"zoom to fit page width",
|
|
|
|
function(unireader)
|
2012-03-20 19:15:24 +00:00
|
|
|
unireader:setGlobalZoomMode(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-03-20 19:15:24 +00:00
|
|
|
unireader:setGlobalZoomMode(unireader.ZOOM_FIT_TO_CONTENT_WIDTH)
|
|
|
|
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-03-20 19:15:24 +00:00
|
|
|
unireader:setGlobalZoomMode(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-03-20 19:15:24 +00:00
|
|
|
unireader:setGlobalZoomMode(unireader.ZOOM_FIT_TO_CONTENT_HEIGHT)
|
|
|
|
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-03-20 19:15:24 +00:00
|
|
|
unireader:setGlobalZoomMode(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-03-20 19:15:24 +00:00
|
|
|
unireader:setGlobalZoomMode(unireader.ZOOM_FIT_TO_CONTENT_HALF_WIDTH)
|
|
|
|
end)
|
2012-03-13 23:07:19 +00:00
|
|
|
self.commands:add(KEY_G,nil,"G",
|
2012-03-13 21:51:25 +00:00
|
|
|
"goto page",
|
2012-03-10 09:28:54 +00:00
|
|
|
function(unireader)
|
2012-03-13 21:51:25 +00:00
|
|
|
local page = InputBox:input(height-100, 100, "Page:")
|
|
|
|
-- convert string to number
|
|
|
|
if not pcall(function () page = page + 0 end) then
|
|
|
|
page = unireader.pageno
|
|
|
|
else
|
|
|
|
if page < 1 or page > unireader.doc:getPages() then
|
|
|
|
page = unireader.pageno
|
|
|
|
end
|
|
|
|
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)
|
|
|
|
HelpPage:show(0,height,unireader.commands)
|
|
|
|
unireader:goto(unireader.pageno)
|
2012-03-20 19:15:24 +00:00
|
|
|
end)
|
2012-03-13 21:51:25 +00:00
|
|
|
self.commands:add(KEY_T,nil,"T",
|
|
|
|
"show table of content",
|
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",
|
|
|
|
"show jump stack",
|
|
|
|
function(unireader)
|
|
|
|
unireader:showJumpStack()
|
|
|
|
end)
|
|
|
|
self.commands:add(KEY_B,MOD_SHIFT,"B",
|
|
|
|
"add jump",
|
|
|
|
function(unireader)
|
2012-03-20 19:15:24 +00:00
|
|
|
unireader:addJump(unireader.pageno)
|
|
|
|
end)
|
2012-03-13 21:51:25 +00:00
|
|
|
self.commands:add(KEY_J,nil,"J",
|
|
|
|
"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)
|
|
|
|
self.commands:add(KEY_J,MOD_SHIFT,"J",
|
|
|
|
"rotate screen 90° clockwise",
|
|
|
|
function(unireader)
|
|
|
|
unireader:screenRotate("clockwise")
|
2012-03-20 19:15:24 +00:00
|
|
|
end)
|
2012-03-13 21:51:25 +00:00
|
|
|
self.commands:add(KEY_K,nil,"K",
|
|
|
|
"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)
|
|
|
|
self.commands:add(KEY_K,MOD_SHIFT,"K",
|
|
|
|
"rotate screen 90° counterclockwise",
|
|
|
|
function(unireader)
|
|
|
|
unireader:screenRotate("anticlockwise")
|
2012-03-20 19:15:24 +00:00
|
|
|
end)
|
2012-03-21 03:20:07 +00:00
|
|
|
self.commands:add(KEY_N, nil, "N",
|
|
|
|
"start highlight mode",
|
|
|
|
function(unireader)
|
|
|
|
unireader:startHighLightMode()
|
2012-03-22 15:12:57 +00:00
|
|
|
unireader:goto(unireader.pageno)
|
2012-03-21 03:20:07 +00:00
|
|
|
end)
|
2012-03-26 18:45:44 +00:00
|
|
|
self.commands:add(KEY_N, MOD_SHIFT, "N",
|
|
|
|
"display all highlights",
|
|
|
|
function(unireader)
|
|
|
|
unireader:showHighLight()
|
|
|
|
unireader:goto(unireader.pageno)
|
|
|
|
end)
|
2012-03-31 13:17:29 +00:00
|
|
|
self.commands:add(KEY_R, MOD_SHIFT, "R",
|
|
|
|
"manual full screen refresh",
|
|
|
|
function(unireader)
|
|
|
|
unireader.rcount = 1
|
|
|
|
fb:refresh(0)
|
|
|
|
end)
|
2012-03-26 18:16:36 +00:00
|
|
|
self.commands:add(KEY_HOME,nil,"Home",
|
2012-03-13 21:51:25 +00:00
|
|
|
"exit application",
|
|
|
|
function(unireader)
|
|
|
|
keep_running = false
|
|
|
|
return "break"
|
|
|
|
end)
|
|
|
|
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
|
|
|
|
bbox["x1"] = bbox["x0"] + width / unireader.globalzoom
|
|
|
|
bbox["y1"] = bbox["y0"] + height / unireader.globalzoom
|
|
|
|
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-03-20 19:15:24 +00:00
|
|
|
print("# bbox " .. unireader.pageno .. dump(unireader.bbox))
|
|
|
|
unireader.globalzoommode = unireader.ZOOM_FIT_TO_CONTENT -- use bbox
|
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;
|
|
|
|
print("# bbox remove "..unireader.pageno .. dump(unireader.bbox));
|
|
|
|
end)
|
|
|
|
self.commands:add(KEY_Z,MOD_ALT,"Z",
|
|
|
|
"toggle crop mode",
|
|
|
|
function(unireader)
|
|
|
|
unireader.bbox.enabled = not unireader.bbox.enabled;
|
|
|
|
print("# bbox override: ", unireader.bbox.enabled);
|
|
|
|
end)
|
|
|
|
self.commands:add(KEY_MENU,nil,"Menu",
|
2012-03-13 23:07:19 +00:00
|
|
|
"open menu",
|
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)
|
2012-03-13 21:51:25 +00:00
|
|
|
-- panning
|
|
|
|
local panning_keys = {Keydef:new(KEY_FW_LEFT,MOD_ANY),Keydef:new(KEY_FW_RIGHT,MOD_ANY),Keydef:new(KEY_FW_UP,MOD_ANY),Keydef:new(KEY_FW_DOWN,MOD_ANY),Keydef:new(KEY_FW_PRESS,MOD_ANY)}
|
2012-03-20 19:15:24 +00:00
|
|
|
self.commands:addGroup("[joypad]",panning_keys,
|
2012-03-13 21:51:25 +00:00
|
|
|
"pan the active view; use Shift or Alt for smaller steps",
|
|
|
|
function(unireader,keydef)
|
|
|
|
if keydef.keycode ~= KEY_FW_PRESS then
|
|
|
|
unireader.globalzoommode = unireader.ZOOM_BY_VALUE
|
|
|
|
end
|
|
|
|
if unireader.globalzoommode == unireader.ZOOM_BY_VALUE then
|
|
|
|
local x
|
|
|
|
local y
|
|
|
|
if keydef.modifier==MOD_SHIFT then -- shift always moves in small steps
|
|
|
|
x = unireader.shift_x / 2
|
|
|
|
y = unireader.shift_y / 2
|
|
|
|
elseif keydef.modifier==MOD_ALT then
|
|
|
|
x = unireader.shift_x / 5
|
|
|
|
y = unireader.shift_y / 5
|
|
|
|
elseif unireader.pan_by_page then
|
|
|
|
x = width;
|
|
|
|
y = height - unireader.pan_overlap_vertical; -- overlap for lines which didn't fit
|
|
|
|
else
|
|
|
|
x = unireader.shift_x
|
|
|
|
y = unireader.shift_y
|
|
|
|
end
|
|
|
|
|
|
|
|
print("offset "..unireader.offset_x.."*"..unireader.offset_x.." shift "..x.."*"..y.." globalzoom="..unireader.globalzoom)
|
|
|
|
local old_offset_x = unireader.offset_x
|
|
|
|
local old_offset_y = unireader.offset_y
|
|
|
|
|
|
|
|
if keydef.keycode == KEY_FW_LEFT then
|
|
|
|
print("# KEY_FW_LEFT "..unireader.offset_x.." + "..x.." > 0");
|
|
|
|
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
|
|
|
|
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
|
|
|
|
print("# KEY_FW_RIGHT "..unireader.offset_x.." - "..x.." < "..unireader.min_offset_x.." - "..unireader.pan_margin);
|
|
|
|
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
|
|
|
|
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
|
|
|
|
unireader.offset_y = 0
|
|
|
|
end
|
|
|
|
elseif keydef.keycode == KEY_FW_DOWN then
|
|
|
|
unireader.offset_y = unireader.offset_y - y
|
|
|
|
if unireader.offset_y < unireader.min_offset_y then
|
|
|
|
unireader.offset_y = unireader.min_offset_y
|
|
|
|
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
|
|
|
|
unireader:goto(unireader.pageno)
|
2012-03-20 19:15:24 +00:00
|
|
|
end
|
|
|
|
end
|
2012-03-13 21:51:25 +00:00
|
|
|
end)
|
2012-03-20 19:15:24 +00:00
|
|
|
-- end panning
|
2012-03-27 17:54:07 +00:00
|
|
|
print("## defined commands "..dump(self.commands.map))
|
2012-03-13 21:14:26 +00:00
|
|
|
end
|