2017-09-11 08:32:39 +00:00
|
|
|
local BBoxWidget = require("ui/widget/bboxwidget")
|
|
|
|
local Blitbuffer = require("ffi/blitbuffer")
|
|
|
|
local Button = require("ui/widget/button")
|
2013-10-18 20:38:07 +00:00
|
|
|
local Event = require("ui/event")
|
|
|
|
local FrameContainer = require("ui/widget/container/framecontainer")
|
2017-09-11 08:32:39 +00:00
|
|
|
local Geom = require("ui/geometry")
|
|
|
|
local InputContainer = require("ui/widget/container/inputcontainer")
|
2013-10-18 20:38:07 +00:00
|
|
|
local HorizontalGroup = require("ui/widget/horizontalgroup")
|
2013-10-22 15:11:31 +00:00
|
|
|
local HorizontalSpan = require("ui/widget/horizontalspan")
|
2017-09-11 08:32:39 +00:00
|
|
|
local LeftContainer = require("ui/widget/container/leftcontainer")
|
2013-10-23 14:37:55 +00:00
|
|
|
local Math = require("optmath")
|
2017-09-11 08:32:39 +00:00
|
|
|
local RightContainer = require("ui/widget/container/rightcontainer")
|
|
|
|
local UIManager = require("ui/uimanager")
|
|
|
|
local VerticalGroup = require("ui/widget/verticalgroup")
|
|
|
|
local Screen = require("device").screen
|
2013-02-03 04:29:30 +00:00
|
|
|
|
2013-10-18 20:38:07 +00:00
|
|
|
local PageCropDialog = VerticalGroup:new{
|
2014-03-13 13:52:43 +00:00
|
|
|
ok_text = "OK",
|
|
|
|
cancel_text = "Cancel",
|
|
|
|
ok_callback = function() end,
|
|
|
|
cancel_callback = function() end,
|
2014-11-20 22:07:39 +00:00
|
|
|
button_width = math.floor(Screen:scaleBySize(70)),
|
2013-02-21 14:29:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function PageCropDialog:init()
|
2014-03-13 13:52:43 +00:00
|
|
|
local horizontal_group = HorizontalGroup:new{}
|
|
|
|
local ok_button = Button:new{
|
|
|
|
text = self.ok_text,
|
|
|
|
callback = self.ok_callback,
|
|
|
|
width = self.button_width,
|
|
|
|
text_font_face = "cfont",
|
|
|
|
text_font_size = 20,
|
2014-05-01 10:37:12 +00:00
|
|
|
show_parent = self,
|
2014-03-13 13:52:43 +00:00
|
|
|
}
|
|
|
|
local cancel_button = Button:new{
|
|
|
|
text = self.cancel_text,
|
|
|
|
callback = self.cancel_callback,
|
|
|
|
width = self.button_width,
|
|
|
|
text_font_face = "cfont",
|
|
|
|
text_font_size = 20,
|
2014-05-01 10:37:12 +00:00
|
|
|
show_parent = self,
|
2014-03-13 13:52:43 +00:00
|
|
|
}
|
|
|
|
local ok_container = RightContainer:new{
|
|
|
|
dimen = Geom:new{ w = Screen:getWidth()*0.33, h = Screen:getHeight()/12},
|
|
|
|
ok_button,
|
|
|
|
}
|
|
|
|
local cancel_container = LeftContainer:new{
|
|
|
|
dimen = Geom:new{ w = Screen:getWidth()*0.33, h = Screen:getHeight()/12},
|
|
|
|
cancel_button,
|
|
|
|
}
|
|
|
|
table.insert(horizontal_group, ok_container)
|
|
|
|
table.insert(horizontal_group, HorizontalSpan:new{ width = Screen:getWidth()*0.34})
|
|
|
|
table.insert(horizontal_group, cancel_container)
|
|
|
|
self[2] = FrameContainer:new{
|
|
|
|
horizontal_group,
|
2014-10-22 13:34:11 +00:00
|
|
|
background = Blitbuffer.COLOR_WHITE,
|
2014-03-13 13:52:43 +00:00
|
|
|
bordersize = 0,
|
|
|
|
padding = 0,
|
|
|
|
}
|
2013-02-21 14:29:54 +00:00
|
|
|
end
|
|
|
|
|
2014-12-01 14:39:41 +00:00
|
|
|
function PageCropDialog:onCloseWidget()
|
|
|
|
UIManager:setDirty(nil, function()
|
|
|
|
return "partial", self[1].dimen:combine(self[2].dimen)
|
|
|
|
end)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
function PageCropDialog:onShow()
|
|
|
|
UIManager:setDirty(self, function()
|
2015-04-26 18:07:17 +00:00
|
|
|
return "ui", self[1].dimen:combine(self[2].dimen)
|
2014-12-01 14:39:41 +00:00
|
|
|
end)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2016-12-04 06:57:57 +00:00
|
|
|
|
2013-10-18 20:38:07 +00:00
|
|
|
local ReaderCropping = InputContainer:new{}
|
2013-02-02 20:42:59 +00:00
|
|
|
|
|
|
|
function ReaderCropping:onPageCrop(mode)
|
2014-10-10 10:14:16 +00:00
|
|
|
self.ui:handleEvent(Event:new("CloseConfigMenu"))
|
2014-11-06 02:20:55 +00:00
|
|
|
-- backup original zoom mode as cropping use "page" zoom mode
|
|
|
|
self.orig_zoom_mode = self.view.zoom_mode
|
|
|
|
if mode == "auto" then
|
2014-12-03 08:32:38 +00:00
|
|
|
if self.document.configurable.text_wrap ~= 1 then
|
|
|
|
self:setCropZoomMode(true)
|
|
|
|
end
|
2014-11-06 02:20:55 +00:00
|
|
|
return
|
2019-03-03 07:57:20 +00:00
|
|
|
elseif mode == "none" then
|
|
|
|
if self.document.configurable.text_wrap ~= 1 then
|
|
|
|
self.ui:handleEvent(Event:new("SetZoomMode", "pagewidth", "cropping"))
|
|
|
|
end
|
|
|
|
return
|
2014-11-06 02:20:55 +00:00
|
|
|
end
|
2014-03-13 13:52:43 +00:00
|
|
|
-- backup original view dimen
|
|
|
|
self.orig_view_dimen = Geom:new{w = self.view.dimen.w, h = self.view.dimen.h}
|
|
|
|
-- backup original view bgcolor
|
|
|
|
self.orig_view_bgcolor = self.view.outer_page_color
|
2019-03-14 19:58:45 +00:00
|
|
|
self.view.outer_page_color = Blitbuffer.COLOR_DARK_GRAY
|
2014-03-13 13:52:43 +00:00
|
|
|
-- backup original page scroll
|
|
|
|
self.orig_page_scroll = self.view.page_scroll
|
|
|
|
self.view.page_scroll = false
|
|
|
|
-- backup and disable original hinting state
|
|
|
|
self.ui:handleEvent(Event:new("DisableHinting"))
|
|
|
|
-- backup original reflow mode as cropping use non-reflow mode
|
|
|
|
self.orig_reflow_mode = self.document.configurable.text_wrap
|
|
|
|
if self.orig_reflow_mode == 1 then
|
|
|
|
self.document.configurable.text_wrap = 0
|
|
|
|
-- if we are in reflow mode, then we are already in page
|
|
|
|
-- mode, just force readerview to recalculate visible_area
|
|
|
|
self.view:recalculate()
|
|
|
|
else
|
|
|
|
self.ui:handleEvent(Event:new("SetZoomMode", "page", "cropping"))
|
|
|
|
end
|
|
|
|
self.ui:handleEvent(Event:new("SetDimensions",
|
|
|
|
Geom:new{w = Screen:getWidth(), h = Screen:getHeight()*11/12})
|
|
|
|
)
|
|
|
|
self.bbox_widget = BBoxWidget:new{
|
|
|
|
crop = self,
|
|
|
|
ui = self.ui,
|
|
|
|
view = self.view,
|
|
|
|
document = self.document,
|
|
|
|
}
|
|
|
|
self.crop_dialog = PageCropDialog:new{
|
|
|
|
self.bbox_widget,
|
|
|
|
ok_callback = function() self:onConfirmPageCrop() end,
|
|
|
|
cancel_callback = function() self:onCancelPageCrop() end,
|
|
|
|
}
|
|
|
|
UIManager:show(self.crop_dialog)
|
|
|
|
return true
|
2013-02-02 20:42:59 +00:00
|
|
|
end
|
|
|
|
|
2013-02-23 05:10:53 +00:00
|
|
|
function ReaderCropping:onConfirmPageCrop()
|
2014-03-13 13:52:43 +00:00
|
|
|
--DEBUG("new bbox", new_bbox)
|
|
|
|
UIManager:close(self.crop_dialog)
|
|
|
|
local new_bbox = self.bbox_widget:getModifiedPageBBox()
|
|
|
|
self.ui:handleEvent(Event:new("BBoxUpdate", new_bbox))
|
|
|
|
local pageno = self.view.state.page
|
|
|
|
self.document.bbox[pageno] = new_bbox
|
|
|
|
self.document.bbox[Math.oddEven(pageno)] = new_bbox
|
|
|
|
self:exitPageCrop(true)
|
|
|
|
return true
|
2013-02-20 11:39:09 +00:00
|
|
|
end
|
|
|
|
|
2013-02-23 05:10:53 +00:00
|
|
|
function ReaderCropping:onCancelPageCrop()
|
2014-03-13 13:52:43 +00:00
|
|
|
UIManager:close(self.crop_dialog)
|
|
|
|
self:exitPageCrop(false)
|
|
|
|
return true
|
2013-02-20 11:39:09 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderCropping:exitPageCrop(confirmed)
|
2014-03-13 13:52:43 +00:00
|
|
|
-- restore hinting state
|
|
|
|
self.ui:handleEvent(Event:new("RestoreHinting"))
|
|
|
|
-- restore page scroll
|
|
|
|
self.view.page_scroll = self.orig_page_scroll
|
|
|
|
-- restore view bgcolor
|
|
|
|
self.view.outer_page_color = self.orig_view_bgcolor
|
|
|
|
-- restore reflow mode
|
|
|
|
self.document.configurable.text_wrap = self.orig_reflow_mode
|
|
|
|
-- restore view dimens
|
|
|
|
self.ui:handleEvent(Event:new("RestoreDimensions", self.orig_view_dimen))
|
|
|
|
self.view:recalculate()
|
|
|
|
-- Exiting should have the same look and feel with entering.
|
|
|
|
if self.orig_reflow_mode == 1 then
|
|
|
|
self.ui:handleEvent(Event:new("RestoreZoomMode"))
|
|
|
|
else
|
2014-11-06 02:20:55 +00:00
|
|
|
self:setCropZoomMode(confirmed)
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
2013-02-02 20:42:59 +00:00
|
|
|
end
|
|
|
|
|
2014-11-06 02:20:55 +00:00
|
|
|
function ReaderCropping:setCropZoomMode(confirmed)
|
|
|
|
if confirmed then
|
|
|
|
-- if original zoom mode is not "content", set zoom mode to "contentwidth"
|
2016-04-26 02:45:55 +00:00
|
|
|
self:setZoomMode(
|
|
|
|
self.orig_zoom_mode:find("content")
|
|
|
|
and self.orig_zoom_mode
|
|
|
|
or "contentwidth")
|
2014-11-06 02:20:55 +00:00
|
|
|
self.ui:handleEvent(Event:new("InitScrollPageStates"))
|
|
|
|
else
|
2016-04-26 02:45:55 +00:00
|
|
|
self:setZoomMode(self.orig_zoom_mode)
|
2014-11-06 02:20:55 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-04-26 02:45:55 +00:00
|
|
|
function ReaderCropping:setZoomMode(mode)
|
|
|
|
self.ui:handleEvent(Event:new("SetZoomMode", mode))
|
|
|
|
end
|
|
|
|
|
2013-02-02 20:42:59 +00:00
|
|
|
function ReaderCropping:onReadSettings(config)
|
2014-03-13 13:52:43 +00:00
|
|
|
self.document.bbox = config:readSetting("bbox")
|
2013-02-02 20:42:59 +00:00
|
|
|
end
|
|
|
|
|
2013-12-27 15:18:16 +00:00
|
|
|
function ReaderCropping:onSaveSettings()
|
2014-03-13 13:52:43 +00:00
|
|
|
self.ui.doc_settings:saveSetting("bbox", self.document.bbox)
|
2013-02-02 20:42:59 +00:00
|
|
|
end
|
2013-10-18 20:38:07 +00:00
|
|
|
|
|
|
|
return ReaderCropping
|