mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
add usedbbox support
This commit is contained in:
@@ -124,6 +124,20 @@ function Document:getPageDimensions(pageno, zoom, rotation)
|
||||
return native_dimen
|
||||
end
|
||||
|
||||
function Document:getUsedBBoxDimensions(pageno, zoom, rotation)
|
||||
ubbox = self:getUsedBBox(pageno)
|
||||
ubbox_dimen = Geom:new{
|
||||
x = ubbox.x0,
|
||||
y = ubbox.y0,
|
||||
w = ubbox.x1 - ubbox.x0,
|
||||
h = ubbox.y1 - ubbox.y0,
|
||||
}
|
||||
if zoom ~= 1 then
|
||||
ubbox_dimen:transformByScale(zoom)
|
||||
end
|
||||
return ubbox_dimen
|
||||
end
|
||||
|
||||
function Document:getToc()
|
||||
return self._document:getToc()
|
||||
end
|
||||
@@ -185,6 +199,14 @@ function Document:hintPage(pageno, zoom, rotation)
|
||||
self:renderPage(pageno, nil, zoom, rotation)
|
||||
end
|
||||
|
||||
--[[
|
||||
Draw page content to blitbuffer.
|
||||
1. find tile in cache
|
||||
2. if not found, call renderPage
|
||||
|
||||
@target: target blitbuffer
|
||||
@rect: visible_area inside document page
|
||||
--]]
|
||||
function Document:drawPage(target, x, y, rect, pageno, zoom, rotation, render_mode)
|
||||
local hash_full_page = "renderpg|"..self.file.."|"..pageno.."|"..zoom.."|"..rotation
|
||||
local hash_excerpt = "renderpg|"..self.file.."|"..pageno.."|"..zoom.."|"..rotation.."|"..tostring(rect)
|
||||
@@ -196,8 +218,12 @@ function Document:drawPage(target, x, y, rect, pageno, zoom, rotation, render_mo
|
||||
tile = self:renderPage(pageno, rect, zoom, rotation, render_mode)
|
||||
end
|
||||
end
|
||||
DEBUG("now painting", tile)
|
||||
target:blitFrom(tile.bb, x, y, rect.x - tile.excerpt.x, rect.y - tile.excerpt.y, rect.w, rect.h)
|
||||
DEBUG("now painting", tile, rect)
|
||||
target:blitFrom(tile.bb,
|
||||
x, y,
|
||||
rect.x - tile.excerpt.x,
|
||||
rect.y - tile.excerpt.y,
|
||||
rect.w, rect.h)
|
||||
end
|
||||
|
||||
function Document:drawCurrentView(target, x, y, rect, pos)
|
||||
|
||||
@@ -41,7 +41,7 @@ function PdfDocument:getUsedBBox(pageno)
|
||||
end
|
||||
local page = self._document:openPage(pageno)
|
||||
local used = {}
|
||||
used.x, used.y, used.w, used.h = page:getUsedBBox()
|
||||
used.x0, used.y0, used.x1, used.y1 = page:getUsedBBox()
|
||||
--@TODO give size for cacheitem? 02.12 2012 (houqp)
|
||||
Cache:insert(hash, CacheItem:new{
|
||||
ubbox = used,
|
||||
|
||||
@@ -65,6 +65,15 @@ function Geom:scaleBy(zx, zy)
|
||||
return self
|
||||
end
|
||||
|
||||
--[[
|
||||
this method also takes care of x and y
|
||||
]]--
|
||||
function Geom:transformByScale(zx, zy)
|
||||
self.x = self.x * zx
|
||||
self.y = self.y * (zx or zy)
|
||||
self:scaleBy(zx, zy)
|
||||
end
|
||||
|
||||
--[[
|
||||
enlarges or shrinks dimensions or rectangles
|
||||
|
||||
|
||||
@@ -13,7 +13,9 @@ ReaderView = WidgetContainer:new{
|
||||
-- DjVu page rendering mode (used in djvu.c:drawPage())
|
||||
render_mode = 0, -- default to COLOR
|
||||
|
||||
-- visible area within current viewing page
|
||||
visible_area = Geom:new{x = 0, y = 0},
|
||||
-- dimen for current viewing page
|
||||
page_area = Geom:new{},
|
||||
}
|
||||
|
||||
@@ -56,12 +58,22 @@ function ReaderView:paintTo(bb, x, y)
|
||||
end
|
||||
|
||||
function ReaderView:recalculate()
|
||||
local page_size = nil
|
||||
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
|
||||
|
||||
if not self.bbox then
|
||||
self.page_area = self.ui.document:getPageDimensions(
|
||||
self.state.page,
|
||||
self.state.zoom,
|
||||
self.state.rotation)
|
||||
else
|
||||
self.page_area = self.ui.document:getUsedBBoxDimensions(
|
||||
self.state.page,
|
||||
self.state.zoom,
|
||||
self.state.rotation)
|
||||
end
|
||||
-- starts from left top of page_area
|
||||
self.visible_area.x = self.page_area.x
|
||||
self.visible_area.y = self.page_area.y
|
||||
-- reset our size
|
||||
self.visible_area:setSizeTo(self.dimen)
|
||||
-- and recalculate it according to page size
|
||||
@@ -80,8 +92,8 @@ function ReaderView:PanningUpdate(dx, dy)
|
||||
if self.visible_area ~= old then
|
||||
-- flag a repaint
|
||||
UIManager:setDirty(self.dialog)
|
||||
DEBUG(self.page_area)
|
||||
DEBUG(self.visible_area)
|
||||
DEBUG("on pan: page_area", self.page_area)
|
||||
DEBUG("on pan: visible_area", self.visible_area)
|
||||
end
|
||||
return true
|
||||
end
|
||||
@@ -111,6 +123,10 @@ function ReaderView:onZoomUpdate(zoom)
|
||||
self:recalculate()
|
||||
end
|
||||
|
||||
function ReaderView:onBBoxUpdate(bbox)
|
||||
self.bbox = bbox
|
||||
end
|
||||
|
||||
function ReaderView:onRotationUpdate(rotation)
|
||||
self.state.rotation = rotation
|
||||
self:recalculate()
|
||||
|
||||
@@ -59,11 +59,13 @@ function ReaderZooming:setZoom()
|
||||
if self.zoom_mode == "content"
|
||||
or self.zoom_mode == "contentwidth"
|
||||
or self.zoom_mode == "contentheight" then
|
||||
-- TODO: enable this, still incomplete
|
||||
page_size = self.ui.document:getUsedBBox(self.current_page)
|
||||
self.view:handleEvent(Event:new("BBoxUpdate", page_size))
|
||||
ubbox_dimen = self.ui.document:getUsedBBoxDimensions(self.current_page, 1)
|
||||
--self.view:handleEvent(Event:new("BBoxUpdate", page_size))
|
||||
self.view:onBBoxUpdate(ubbox_dimen)
|
||||
page_size = ubbox_dimen
|
||||
else
|
||||
-- otherwise, operate on full page
|
||||
self.view:onBBoxUpdate(nil)
|
||||
page_size = self.ui.document:getNativePageDimensions(self.current_page)
|
||||
end
|
||||
-- calculate zoom value:
|
||||
|
||||
Reference in New Issue
Block a user