2013-02-03 08:15:54 +00:00
|
|
|
require "ui/bbox"
|
2013-02-03 04:29:30 +00:00
|
|
|
|
2013-02-02 20:42:59 +00:00
|
|
|
ReaderCropping = InputContainer:new{}
|
|
|
|
|
|
|
|
function ReaderCropping:onPageCrop(mode)
|
|
|
|
if mode == "auto" then return end
|
2013-02-18 04:19:57 +00:00
|
|
|
self.orig_reflow_mode = self.document.configurable.text_wrap
|
2013-02-02 20:42:59 +00:00
|
|
|
self.ui:handleEvent(Event:new("CloseConfig"))
|
2013-02-08 16:11:30 +00:00
|
|
|
self.cropping_zoommode = true
|
|
|
|
self.cropping_offset = true
|
2013-02-18 04:19:57 +00:00
|
|
|
if self.orig_reflow_mode == 1 then
|
2013-02-17 16:01:57 +00:00
|
|
|
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"))
|
|
|
|
end
|
2013-02-18 04:19:57 +00:00
|
|
|
self.cropping_zoommode = false
|
2013-02-02 20:42:59 +00:00
|
|
|
local ubbox = self.document:getPageBBox(self.current_page)
|
|
|
|
--DEBUG("used page bbox", ubbox)
|
|
|
|
self.crop_bbox = BBoxWidget:new{
|
|
|
|
page_bbox = ubbox,
|
|
|
|
ui = self.ui,
|
|
|
|
crop = self,
|
|
|
|
document = self.document,
|
|
|
|
pageno = self.current_page,
|
|
|
|
}
|
|
|
|
UIManager:show(self.crop_bbox)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2013-02-18 04:19:57 +00:00
|
|
|
function ReaderCropping:onExitPageCrop()
|
|
|
|
self.document.configurable.text_wrap = self.orig_reflow_mode
|
|
|
|
self.view:recalculate()
|
|
|
|
-- Exiting should have the same look and feel with entering.
|
|
|
|
if self.orig_reflow_mode == 1 then
|
|
|
|
self.document.configurable.text_wrap = 1
|
|
|
|
self.view:recalculate()
|
|
|
|
else
|
|
|
|
self.ui:handleEvent(Event:new("SetZoomMode", self.orig_zoom_mode))
|
|
|
|
end
|
|
|
|
UIManager.repaint_all = true
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2013-02-02 20:42:59 +00:00
|
|
|
function ReaderCropping:onPageUpdate(page_no)
|
|
|
|
--DEBUG("page updated to", page_no)
|
|
|
|
self.current_page = page_no
|
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderCropping:onZoomUpdate(zoom)
|
|
|
|
--DEBUG("zoom updated to", zoom)
|
|
|
|
self.zoom = zoom
|
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderCropping:onScreenOffsetUpdate(screen_offset)
|
2013-02-08 16:11:30 +00:00
|
|
|
if self.cropping_offset then
|
2013-02-18 04:19:57 +00:00
|
|
|
--DEBUG("offset updated to", screen_offset)
|
2013-02-08 16:11:30 +00:00
|
|
|
self.screen_offset = screen_offset
|
|
|
|
self.cropping_offset = false
|
|
|
|
end
|
2013-02-02 20:42:59 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderCropping:onSetZoomMode(mode)
|
2013-02-08 16:11:30 +00:00
|
|
|
if not self.cropping_zoommode then
|
2013-02-02 20:42:59 +00:00
|
|
|
--DEBUG("backup zoom mode", mode)
|
|
|
|
self.orig_zoom_mode = mode
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderCropping:onReadSettings(config)
|
|
|
|
local bbox = config:readSetting("bbox")
|
|
|
|
self.document.bbox = bbox
|
2013-02-08 16:11:30 +00:00
|
|
|
--DEBUG("read document bbox", self.document.bbox)
|
2013-02-02 20:42:59 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderCropping:onCloseDocument()
|
|
|
|
self.ui.doc_settings:saveSetting("bbox", self.document.bbox)
|
|
|
|
end
|