add semi-auto bbox option in page crop dialog

pull/155/head
chrox 11 years ago
parent 87296fe884
commit 2e5d2b9930

@ -87,7 +87,7 @@ function DjvuDocument:invertTextYAxel(pageno, text_table)
end
function DjvuDocument:getPageBBox(pageno)
if self.configurable.text_wrap ~= 1 and self.configurable.trim_page == 1 then
if self.configurable.text_wrap ~= 1 and self.configurable.trim_page > 0 then
return self.koptinterface:getAutoBBox(self, pageno)
else
return Document.getPageBBox(self, pageno)

@ -75,10 +75,31 @@ function KoptInterface:getContextHash(doc, pageno, bbox)
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:createContext(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{ autobbox = bbox })
return bbox
else
return cached.autobbox
end
end
function KoptInterface:getSemiAutoBBox(doc, pageno)
-- use manual bbox
local bbox = Document.getPageBBox(doc, pageno)
local context_hash = self:getContextHash(doc, pageno, bbox)
local hash = "autobbox|"..context_hash
local hash = "semiautobbox|"..context_hash
local cached = Cache:check(hash)
if not cached then
local page = doc._document:openPage(pageno)
@ -89,12 +110,12 @@ function KoptInterface:getAutoBBox(doc, pageno)
auto_bbox.y0 = auto_bbox.y0 + bbox.y0
auto_bbox.x1 = auto_bbox.x1 + bbox.x0
auto_bbox.y1 = auto_bbox.y1 + bbox.y0
DEBUG("Auto detected bbox", auto_bbox)
DEBUG("Semi-auto detected bbox", auto_bbox)
page:close()
Cache:insert(hash, CacheItem:new{ autobbox = auto_bbox })
Cache:insert(hash, CacheItem:new{ semiautobbox = auto_bbox })
return auto_bbox
else
return cached.autobbox
return cached.semiautobbox
end
end

@ -92,8 +92,13 @@ end
function PdfDocument:getPageBBox(pageno)
if self.configurable.text_wrap ~= 1 and self.configurable.trim_page == 1 then
-- auto bbox finding
return self.koptinterface:getAutoBBox(self, pageno)
elseif self.configurable.text_wrap ~= 1 and self.configurable.trim_page == 2 then
-- semi-auto bbox finding
return self.koptinterface:getSemiAutoBBox(self, pageno)
else
-- get saved manual bbox
return Document.getPageBBox(self, pageno)
end
end

@ -23,12 +23,12 @@ KoptOptions = {
{
name = "trim_page",
name_text = PAGE_CROP_STR,
toggle = {AUTO_STR, MANUAL_STR},
toggle = {MANUAL_STR, AUTO_STR, SEMIAUTO_STR},
alternate = false,
values = {1, 0},
values = {0, 1, 2},
default_value = DKOPTREADER_CONFIG_TRIM_PAGE,
event = "PageCrop",
args = {"auto", "manual"},
args = {"manual", "auto", "semi-auto"},
}
}
},

@ -25,6 +25,7 @@ ON_STR = _("on")
OFF_STR = _("off")
AUTO_STR = _("auto")
MANUAL_STR = _("manual")
SEMIAUTO_STR = _("semi-auto")
SMALL_STR = _("small")
MEDIUM_STR = _("medium")
LARGE_STR = _("large")

Loading…
Cancel
Save