add auto page crop

This commit is contained in:
chrox
2013-04-14 15:16:42 +08:00
parent e56bea89aa
commit fb05f9a428
6 changed files with 61 additions and 2 deletions

View File

@@ -88,6 +88,27 @@ function KoptInterface:logReflowDuration(pageno, dur)
end
end
function KoptInterface:getAutoBBox(doc, pageno)
local bbox = {
x0 = 0, y0 = 0,
x1 = 0, y1 = 0,
}
local context_hash = self:getContextHash(doc, pageno, bbox)
local hash = "autobbox|"..context_hash
local cached = Cache:check(hash)
if not cached then
local page = doc._document:openPage(pageno)
local kc = self:getKOPTContext(doc, pageno, bbox)
bbox.x0, bbox.y0, bbox.x1, bbox.y1 = page:getAutoBBox(kc)
DEBUG("Auto detected bbox", bbox)
page:close()
Cache:insert(hash, CacheItem:new{ bbox = bbox })
return bbox
else
return cached.bbox
end
end
function KoptInterface:getReflowedDim(kc)
self:waitForContext(kc)
return kc:getPageDim()