2012-05-18 22:50:26 +00:00
|
|
|
ReaderView = WidgetContainer:new{
|
|
|
|
document = nil,
|
|
|
|
|
|
|
|
state = {
|
|
|
|
page = 0,
|
2012-06-05 07:23:36 +00:00
|
|
|
pos = 0,
|
2012-05-18 22:50:26 +00:00
|
|
|
zoom = 1.0,
|
|
|
|
rotation = 0,
|
|
|
|
offset = {},
|
|
|
|
bbox = nil,
|
|
|
|
},
|
|
|
|
outer_page_color = 7,
|
2012-10-09 22:26:01 +00:00
|
|
|
-- DjVu page rendering mode (used in djvu.c:drawPage())
|
|
|
|
render_mode = 0, -- default to COLOR
|
2012-05-18 22:50:26 +00:00
|
|
|
|
|
|
|
visible_area = Geom:new{x = 0, y = 0},
|
|
|
|
page_area = Geom:new{},
|
|
|
|
}
|
|
|
|
|
|
|
|
function ReaderView:paintTo(bb, x, y)
|
2012-05-28 16:59:16 +00:00
|
|
|
DEBUG("painting", self.visible_area, "to", x, y)
|
2012-05-18 22:50:26 +00:00
|
|
|
local inner_offset = Geom:new{x = 0, y = 0}
|
|
|
|
|
|
|
|
-- draw surrounding space, if any
|
|
|
|
if self.ui.dimen.h > self.visible_area.h then
|
|
|
|
inner_offset.y = (self.ui.dimen.h - self.visible_area.h) / 2
|
|
|
|
bb:paintRect(x, y, self.ui.dimen.w, inner_offset.y, self.outer_page_color)
|
|
|
|
bb:paintRect(x, y + self.ui.dimen.h - inner_offset.y - 1, self.ui.dimen.w, inner_offset.y + 1, self.outer_page_color)
|
|
|
|
end
|
|
|
|
if self.ui.dimen.w > self.visible_area.w then
|
|
|
|
inner_offset.x = (self.ui.dimen.w - self.visible_area.w) / 2
|
|
|
|
bb:paintRect(x, y, inner_offset.x, self.ui.dimen.h, self.outer_page_color)
|
|
|
|
bb:paintRect(x + self.ui.dimen.w - inner_offset.x - 1, y, inner_offset.x + 1, self.ui.dimen.h, self.outer_page_color)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- draw content
|
2012-06-05 07:23:36 +00:00
|
|
|
if self.ui.document.info.has_pages then
|
|
|
|
self.ui.document:drawPage(
|
|
|
|
bb,
|
|
|
|
x + inner_offset.x,
|
|
|
|
y + inner_offset.y,
|
|
|
|
self.visible_area,
|
|
|
|
self.state.page,
|
|
|
|
self.state.zoom,
|
2012-10-09 22:26:01 +00:00
|
|
|
self.state.rotation,
|
|
|
|
self.render_mode)
|
2012-06-05 07:23:36 +00:00
|
|
|
else
|
|
|
|
self.ui.document:drawCurrentView(
|
|
|
|
bb,
|
|
|
|
x + inner_offset.x,
|
|
|
|
y + inner_offset.y,
|
|
|
|
self.visible_area,
|
|
|
|
self.state.pos)
|
|
|
|
end
|
2012-05-18 22:50:26 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderView:recalculate()
|
2012-06-05 07:23:36 +00:00
|
|
|
if self.ui.document.info.has_pages then
|
|
|
|
local page_size = self.ui.document:getPageDimensions(self.state.page, self.state.zoom, self.state.rotation)
|
|
|
|
-- TODO: bbox
|
|
|
|
self.page_area = page_size
|
2012-05-18 22:50:26 +00:00
|
|
|
|
2012-06-05 07:23:36 +00:00
|
|
|
-- reset our size
|
2012-06-12 16:14:23 +00:00
|
|
|
self.visible_area:setSizeTo(self.dimen)
|
2012-06-05 07:23:36 +00:00
|
|
|
-- and recalculate it according to page size
|
|
|
|
self.visible_area:offsetWithin(self.page_area, 0, 0)
|
|
|
|
else
|
2012-06-12 16:14:23 +00:00
|
|
|
self.visible_area:setSizeTo(self.dimen)
|
2012-06-05 07:23:36 +00:00
|
|
|
end
|
2012-05-18 22:50:26 +00:00
|
|
|
-- flag a repaint
|
|
|
|
UIManager:setDirty(self.dialog)
|
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderView:PanningUpdate(dx, dy)
|
2012-05-28 16:59:16 +00:00
|
|
|
DEBUG("pan by", dx, dy)
|
2012-06-10 15:36:19 +00:00
|
|
|
local old = self.visible_area:copy()
|
2012-05-18 22:50:26 +00:00
|
|
|
self.visible_area:offsetWithin(self.page_area, dx, dy)
|
|
|
|
if self.visible_area ~= old then
|
|
|
|
-- flag a repaint
|
|
|
|
UIManager:setDirty(self.dialog)
|
2012-05-28 16:59:16 +00:00
|
|
|
DEBUG(self.page_area)
|
|
|
|
DEBUG(self.visible_area)
|
2012-05-18 22:50:26 +00:00
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2012-06-12 16:14:23 +00:00
|
|
|
function ReaderView:onSetDimensions(dimensions)
|
|
|
|
self.dimen = dimensions
|
|
|
|
-- recalculate view
|
|
|
|
self:recalculate()
|
|
|
|
end
|
|
|
|
|
2012-10-09 22:26:01 +00:00
|
|
|
function ReaderView:onReadSettings(config)
|
|
|
|
self.render_mode = config:readSetting("render_mode") or 0
|
|
|
|
end
|
|
|
|
|
2012-05-18 22:50:26 +00:00
|
|
|
function ReaderView:onPageUpdate(new_page_no)
|
|
|
|
self.state.page = new_page_no
|
|
|
|
self:recalculate()
|
|
|
|
end
|
|
|
|
|
2012-06-05 07:23:36 +00:00
|
|
|
function ReaderView:onPosUpdate(new_pos)
|
|
|
|
self.state.pos = new_pos
|
|
|
|
self:recalculate()
|
|
|
|
end
|
|
|
|
|
2012-05-18 22:50:26 +00:00
|
|
|
function ReaderView:ZoomUpdate(zoom)
|
|
|
|
self.state.zoom = zoom
|
|
|
|
self:recalculate()
|
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderView:onRotationUpdate(rotation)
|
|
|
|
self.state.rotation = rotation
|
|
|
|
self:recalculate()
|
|
|
|
end
|
|
|
|
|
2012-10-09 22:26:01 +00:00
|
|
|
function ReaderView:onCloseDocument()
|
|
|
|
self.ui.doc_settings:saveSetting("render_mode", self.render_mode)
|
|
|
|
end
|