2012-05-18 22:50:26 +00:00
|
|
|
ReaderZooming = InputContainer:new{
|
|
|
|
zoom = 1.0,
|
2012-12-04 07:19:50 +00:00
|
|
|
-- default to nil so we can trigger ZoomModeUpdate events on start up
|
|
|
|
zoom_mode = nil,
|
|
|
|
DEFAULT_ZOOM_MODE = "page",
|
2012-05-18 22:50:26 +00:00
|
|
|
current_page = 1,
|
|
|
|
rotation = 0
|
|
|
|
}
|
|
|
|
|
2012-12-15 01:30:48 +00:00
|
|
|
function ReaderZooming:init()
|
2013-02-02 06:36:29 +00:00
|
|
|
if Device:hasKeyboard() then
|
|
|
|
self.key_events = {
|
|
|
|
ZoomIn = {
|
2013-03-14 05:58:42 +00:00
|
|
|
{ "Shift", Input.group.PgFwd },
|
2013-04-08 07:21:59 +00:00
|
|
|
doc = _("zoom in"),
|
2013-03-14 05:58:42 +00:00
|
|
|
event = "Zoom", args = "in"
|
2013-02-02 06:36:29 +00:00
|
|
|
},
|
|
|
|
ZoomOut = {
|
2013-03-14 05:58:42 +00:00
|
|
|
{ "Shift", Input.group.PgBack },
|
2013-04-08 07:21:59 +00:00
|
|
|
doc = _("zoom out"),
|
2013-03-14 05:58:42 +00:00
|
|
|
event = "Zoom", args = "out"
|
2013-02-02 06:36:29 +00:00
|
|
|
},
|
|
|
|
ZoomToFitPage = {
|
2013-03-14 05:58:42 +00:00
|
|
|
{ "A" },
|
2013-04-08 07:21:59 +00:00
|
|
|
doc = _("zoom to fit page"),
|
2013-03-14 05:58:42 +00:00
|
|
|
event = "SetZoomMode", args = "page"
|
2013-02-02 06:36:29 +00:00
|
|
|
},
|
|
|
|
ZoomToFitContent = {
|
2013-03-14 05:58:42 +00:00
|
|
|
{ "Shift", "A" },
|
2013-04-08 07:21:59 +00:00
|
|
|
doc = _("zoom to fit content"),
|
2013-03-14 05:58:42 +00:00
|
|
|
event = "SetZoomMode", args = "content"
|
2013-02-02 06:36:29 +00:00
|
|
|
},
|
|
|
|
ZoomToFitPageWidth = {
|
2013-03-14 05:58:42 +00:00
|
|
|
{ "S" },
|
2013-04-08 07:21:59 +00:00
|
|
|
doc = _("zoom to fit page width"),
|
2013-03-14 05:58:42 +00:00
|
|
|
event = "SetZoomMode", args = "pagewidth"
|
2013-02-02 06:36:29 +00:00
|
|
|
},
|
|
|
|
ZoomToFitContentWidth = {
|
|
|
|
{ "Shift", "S" },
|
2013-04-08 07:21:59 +00:00
|
|
|
doc = _("zoom to fit content width"),
|
2013-02-02 06:36:29 +00:00
|
|
|
event = "SetZoomMode", args = "contentwidth"
|
|
|
|
},
|
|
|
|
ZoomToFitPageHeight = {
|
2013-03-14 05:58:42 +00:00
|
|
|
{ "D" },
|
2013-04-08 07:21:59 +00:00
|
|
|
doc = _("zoom to fit page height"),
|
2013-03-14 05:58:42 +00:00
|
|
|
event = "SetZoomMode", args = "pageheight"
|
2013-02-02 06:36:29 +00:00
|
|
|
},
|
|
|
|
ZoomToFitContentHeight = {
|
|
|
|
{ "Shift", "D" },
|
2013-04-08 07:21:59 +00:00
|
|
|
doc = _("zoom to fit content height"),
|
2013-02-02 06:36:29 +00:00
|
|
|
event = "SetZoomMode", args = "contentheight"
|
|
|
|
},
|
|
|
|
}
|
|
|
|
end
|
2013-03-28 13:42:23 +00:00
|
|
|
if Device:isTouchDevice() then
|
|
|
|
self.ges_events = {
|
|
|
|
Spread = {
|
|
|
|
GestureRange:new{
|
|
|
|
ges = "spread",
|
|
|
|
range = Geom:new{
|
|
|
|
x = 0, y = 0,
|
|
|
|
w = Screen:getWidth(),
|
|
|
|
h = Screen:getHeight(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Pinch = {
|
|
|
|
GestureRange:new{
|
|
|
|
ges = "pinch",
|
|
|
|
range = Geom:new{
|
|
|
|
x = 0, y = 0,
|
|
|
|
w = Screen:getWidth(),
|
|
|
|
h = Screen:getHeight(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
end
|
2012-12-15 01:30:48 +00:00
|
|
|
self.ui.menu:registerToMainMenu(self)
|
|
|
|
end
|
|
|
|
|
2012-12-04 07:19:50 +00:00
|
|
|
function ReaderZooming:onReadSettings(config)
|
|
|
|
-- @TODO config file from old code base uses globalzoom_mode
|
2013-03-14 05:58:42 +00:00
|
|
|
-- instead of zoom_mode, we need to handle this imcompatibility
|
2012-12-04 07:19:50 +00:00
|
|
|
-- 04.12 2012 (houqp)
|
|
|
|
local zoom_mode = config:readSetting("zoom_mode")
|
|
|
|
if not zoom_mode then
|
|
|
|
zoom_mode = self.DEFAULT_ZOOM_MODE
|
|
|
|
end
|
2013-02-02 20:42:59 +00:00
|
|
|
self.ui:handleEvent(Event:new("SetZoomMode", zoom_mode))
|
2012-12-04 07:19:50 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderZooming:onCloseDocument()
|
|
|
|
self.ui.doc_settings:saveSetting("zoom_mode", self.zoom_mode)
|
|
|
|
end
|
|
|
|
|
2013-03-28 13:42:23 +00:00
|
|
|
function ReaderZooming:onSpread(arg, ges)
|
|
|
|
if ges.direction == "horizontal" then
|
2013-06-26 07:54:24 +00:00
|
|
|
self:genSetZoomModeCallBack("contentwidth")()
|
2013-03-28 13:42:23 +00:00
|
|
|
elseif ges.direction == "vertical" then
|
2013-06-26 07:54:24 +00:00
|
|
|
self:genSetZoomModeCallBack("contentheight")()
|
2013-03-28 13:42:23 +00:00
|
|
|
elseif ges.direction == "diagonal" then
|
2013-06-26 07:54:24 +00:00
|
|
|
self:genSetZoomModeCallBack("content")()
|
2013-03-28 13:42:23 +00:00
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderZooming:onPinch(arg, ges)
|
|
|
|
if ges.direction == "diagonal" then
|
2013-06-26 07:54:24 +00:00
|
|
|
self:genSetZoomModeCallBack("page")()
|
2013-03-28 13:42:23 +00:00
|
|
|
elseif ges.direction == "horizontal" then
|
2013-06-26 07:54:24 +00:00
|
|
|
self:genSetZoomModeCallBack("pagewidth")()
|
2013-03-28 13:42:23 +00:00
|
|
|
elseif ges.direction == "vertical" then
|
2013-06-26 07:54:24 +00:00
|
|
|
self:genSetZoomModeCallBack("pageheight")()
|
2013-03-28 13:42:23 +00:00
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2012-05-18 22:50:26 +00:00
|
|
|
function ReaderZooming:onSetDimensions(dimensions)
|
|
|
|
-- we were resized
|
|
|
|
self.dimen = dimensions
|
2012-12-04 07:19:50 +00:00
|
|
|
self:setZoom()
|
2012-05-18 22:50:26 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderZooming:onRotationUpdate(rotation)
|
|
|
|
self.rotation = rotation
|
|
|
|
self:setZoom()
|
|
|
|
end
|
|
|
|
|
2012-12-04 07:19:50 +00:00
|
|
|
function ReaderZooming:onZoom(direction)
|
|
|
|
DEBUG("zoom", direction)
|
|
|
|
if direction == "in" then
|
|
|
|
self.zoom = self.zoom * 1.333333
|
|
|
|
elseif direction == "out" then
|
|
|
|
self.zoom = self.zoom * 0.75
|
|
|
|
end
|
|
|
|
DEBUG("zoom is now at", self.zoom)
|
|
|
|
self:onSetZoomMode("free")
|
|
|
|
self.view:onZoomUpdate(self.zoom)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderZooming:onSetZoomMode(new_mode)
|
2013-02-20 11:39:09 +00:00
|
|
|
self.view.zoom_mode = new_mode
|
2012-12-04 07:19:50 +00:00
|
|
|
if self.zoom_mode ~= new_mode then
|
|
|
|
DEBUG("setting zoom mode to", new_mode)
|
|
|
|
self.zoom_mode = new_mode
|
|
|
|
self:setZoom()
|
|
|
|
self.ui:handleEvent(Event:new("ZoomModeUpdate", new_mode))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderZooming:onPageUpdate(new_page_no)
|
|
|
|
self.current_page = new_page_no
|
|
|
|
self:setZoom()
|
|
|
|
end
|
|
|
|
|
2013-04-14 07:16:42 +00:00
|
|
|
function ReaderZooming:onReZoom()
|
|
|
|
self:setZoom()
|
2013-04-20 08:17:38 +00:00
|
|
|
self.ui:handleEvent(Event:new("InitScrollPageStates"))
|
2013-04-14 07:16:42 +00:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2013-03-10 06:21:32 +00:00
|
|
|
function ReaderZooming:getZoom(pageno)
|
2012-05-18 22:50:26 +00:00
|
|
|
-- check if we're in bbox mode and work on bbox if that's the case
|
2013-03-10 06:21:32 +00:00
|
|
|
local zoom = nil
|
2012-05-18 22:50:26 +00:00
|
|
|
local page_size = {}
|
2013-03-14 05:58:42 +00:00
|
|
|
if self.zoom_mode == "content"
|
2012-11-26 07:30:24 +00:00
|
|
|
or self.zoom_mode == "contentwidth"
|
|
|
|
or self.zoom_mode == "contentheight" then
|
2013-03-10 06:21:32 +00:00
|
|
|
local ubbox_dimen = self.ui.document:getUsedBBoxDimensions(pageno, 1)
|
2012-12-02 09:09:32 +00:00
|
|
|
--self.view:handleEvent(Event:new("BBoxUpdate", page_size))
|
|
|
|
self.view:onBBoxUpdate(ubbox_dimen)
|
|
|
|
page_size = ubbox_dimen
|
2012-05-18 22:50:26 +00:00
|
|
|
else
|
|
|
|
-- otherwise, operate on full page
|
2012-12-02 09:09:32 +00:00
|
|
|
self.view:onBBoxUpdate(nil)
|
2013-03-10 06:21:32 +00:00
|
|
|
page_size = self.ui.document:getNativePageDimensions(pageno)
|
2012-05-18 22:50:26 +00:00
|
|
|
end
|
|
|
|
-- calculate zoom value:
|
|
|
|
local zoom_w = self.dimen.w / page_size.w
|
|
|
|
local zoom_h = self.dimen.h / page_size.h
|
|
|
|
if self.rotation % 180 ~= 0 then
|
|
|
|
-- rotated by 90 or 270 degrees
|
|
|
|
zoom_w = self.dimen.w / page_size.h
|
|
|
|
zoom_h = self.dimen.h / page_size.w
|
|
|
|
end
|
|
|
|
if self.zoom_mode == "content" or self.zoom_mode == "page" then
|
|
|
|
if zoom_w < zoom_h then
|
2013-03-10 06:21:32 +00:00
|
|
|
zoom = zoom_w
|
2012-05-18 22:50:26 +00:00
|
|
|
else
|
2013-03-10 06:21:32 +00:00
|
|
|
zoom = zoom_h
|
2012-05-18 22:50:26 +00:00
|
|
|
end
|
|
|
|
elseif self.zoom_mode == "contentwidth" or self.zoom_mode == "pagewidth" then
|
2013-03-10 06:21:32 +00:00
|
|
|
zoom = zoom_w
|
2012-05-18 22:50:26 +00:00
|
|
|
elseif self.zoom_mode == "contentheight" or self.zoom_mode == "pageheight" then
|
2013-03-10 06:21:32 +00:00
|
|
|
zoom = zoom_h
|
|
|
|
end
|
|
|
|
return zoom
|
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderZooming:setZoom()
|
|
|
|
-- nothing to do in free zoom mode
|
|
|
|
if self.zoom_mode == "free" then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if not self.dimen then
|
|
|
|
self.dimen = self.ui.dimen
|
2012-05-18 22:50:26 +00:00
|
|
|
end
|
2013-03-10 06:21:32 +00:00
|
|
|
self.zoom = self:getZoom(self.current_page)
|
2013-02-02 20:42:59 +00:00
|
|
|
self.ui:handleEvent(Event:new("ZoomUpdate", self.zoom))
|
2012-05-18 22:50:26 +00:00
|
|
|
end
|
|
|
|
|
2012-12-15 01:26:40 +00:00
|
|
|
function ReaderZooming:genSetZoomModeCallBack(mode)
|
|
|
|
return function()
|
2013-03-28 13:42:23 +00:00
|
|
|
self:setZoomMode(mode)
|
2012-12-15 01:26:40 +00:00
|
|
|
end
|
|
|
|
end
|
2012-05-18 22:50:26 +00:00
|
|
|
|
2013-03-28 13:42:23 +00:00
|
|
|
function ReaderZooming:setZoomMode(mode)
|
|
|
|
self.ui:handleEvent(Event:new("SetZoomMode", mode))
|
|
|
|
self.ui:handleEvent(Event:new("InitScrollPageStates"))
|
|
|
|
end
|
|
|
|
|
2013-03-14 05:58:42 +00:00
|
|
|
function ReaderZooming:addToMainMenu(tab_item_table)
|
2012-12-15 01:26:40 +00:00
|
|
|
if self.ui.document.info.has_pages then
|
2013-03-14 05:58:42 +00:00
|
|
|
table.insert(tab_item_table.typeset, {
|
2013-04-08 07:21:59 +00:00
|
|
|
text = _("Switch zoom mode"),
|
2012-12-15 01:26:40 +00:00
|
|
|
sub_item_table = {
|
|
|
|
{
|
2013-04-08 07:21:59 +00:00
|
|
|
text = _("Zoom to fit content width"),
|
2012-12-15 01:26:40 +00:00
|
|
|
callback = self:genSetZoomModeCallBack("contentwidth")
|
|
|
|
},
|
|
|
|
{
|
2013-04-08 07:21:59 +00:00
|
|
|
text = _("Zoom to fit content height"),
|
2012-12-15 01:26:40 +00:00
|
|
|
callback = self:genSetZoomModeCallBack("contentheight")
|
|
|
|
},
|
|
|
|
{
|
2013-04-08 07:21:59 +00:00
|
|
|
text = _("Zoom to fit page width"),
|
2012-12-15 01:26:40 +00:00
|
|
|
callback = self:genSetZoomModeCallBack("pagewidth")
|
|
|
|
},
|
|
|
|
{
|
2013-04-08 07:21:59 +00:00
|
|
|
text = _("Zoom to fit page height"),
|
2012-12-15 01:26:40 +00:00
|
|
|
callback = self:genSetZoomModeCallBack("pageheight")
|
|
|
|
},
|
|
|
|
{
|
2013-04-08 07:21:59 +00:00
|
|
|
text = _("Zoom to fit content"),
|
2012-12-15 01:26:40 +00:00
|
|
|
callback = self:genSetZoomModeCallBack("content")
|
|
|
|
},
|
|
|
|
{
|
2013-04-08 07:21:59 +00:00
|
|
|
text = _("Zoom to fit page"),
|
2012-12-15 01:26:40 +00:00
|
|
|
callback = self:genSetZoomModeCallBack("page")
|
|
|
|
},
|
|
|
|
}
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|