mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
add auto page crop
This commit is contained in:
@@ -65,6 +65,14 @@ function DjvuDocument:invertTextYAxel(pageno, text_table)
|
||||
return text_table
|
||||
end
|
||||
|
||||
function DjvuDocument:getPageBBox(pageno)
|
||||
if self.configurable.text_wrap ~= 1 and self.configurable.trim_page == 1 then
|
||||
return self.koptinterface:getAutoBBox(self, pageno)
|
||||
else
|
||||
return Document.getPageBBox(self, pageno)
|
||||
end
|
||||
end
|
||||
|
||||
function DjvuDocument:getPageDimensions(pageno, zoom, rotation)
|
||||
if self.configurable.text_wrap == 1 then
|
||||
return self.koptinterface:getPageDimensions(self, pageno, zoom, rotation)
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -67,6 +67,14 @@ function PdfDocument:getUsedBBox(pageno)
|
||||
return used
|
||||
end
|
||||
|
||||
function PdfDocument:getPageBBox(pageno)
|
||||
if self.configurable.text_wrap ~= 1 and self.configurable.trim_page == 1 then
|
||||
return self.koptinterface:getAutoBBox(self, pageno)
|
||||
else
|
||||
return Document.getPageBBox(self, pageno)
|
||||
end
|
||||
end
|
||||
|
||||
function PdfDocument:getPageDimensions(pageno, zoom, rotation)
|
||||
if self.configurable.text_wrap == 1 then
|
||||
return self.koptinterface:getPageDimensions(self, pageno, zoom, rotation)
|
||||
|
||||
@@ -57,8 +57,9 @@ KoptOptions = {
|
||||
name = "page_margin",
|
||||
name_text = PAGE_MARGIN_STR,
|
||||
toggle = {SMALL_STR, MEDIUM_STR, LARGE_STR},
|
||||
values = {0.06, 0.10, 0.14},
|
||||
values = {0.05, 0.10, 0.15},
|
||||
default_value = 0.10,
|
||||
event = "MarginUpdate",
|
||||
},
|
||||
{
|
||||
name = "line_spacing",
|
||||
@@ -175,8 +176,9 @@ KoptOptions = {
|
||||
name = "defect_size",
|
||||
name_text = DEFECT_SIZE_STR,
|
||||
toggle = {SMALL_STR, MEDIUM_STR, LARGE_STR},
|
||||
values = {0.5, 1.0, 2.0},
|
||||
values = {1.0, 8.0, 15.0},
|
||||
default_value = 1.0,
|
||||
event = "DefectSizeUpdate",
|
||||
},
|
||||
{
|
||||
name = "quality",
|
||||
|
||||
@@ -360,6 +360,21 @@ function ReaderView:onGammaUpdate(gamma)
|
||||
end
|
||||
end
|
||||
|
||||
function ReaderView:onDefectSizeUpdate()
|
||||
self.ui:handleEvent(Event:new("ReZoom"))
|
||||
self.ui:handleEvent(Event:new("InitScrollPageStates"))
|
||||
end
|
||||
|
||||
function ReaderView:onPageCrop()
|
||||
self.ui:handleEvent(Event:new("ReZoom"))
|
||||
self.ui:handleEvent(Event:new("InitScrollPageStates"))
|
||||
end
|
||||
|
||||
function ReaderView:onMarginUpdate()
|
||||
self.ui:handleEvent(Event:new("ReZoom"))
|
||||
self.ui:handleEvent(Event:new("InitScrollPageStates"))
|
||||
end
|
||||
|
||||
function ReaderView:onSetViewMode(new_mode)
|
||||
self.ui.view_mode = new_mode
|
||||
self.ui.document:setViewMode(new_mode)
|
||||
|
||||
@@ -155,6 +155,11 @@ function ReaderZooming:onPageUpdate(new_page_no)
|
||||
self:setZoom()
|
||||
end
|
||||
|
||||
function ReaderZooming:onReZoom()
|
||||
self:setZoom()
|
||||
return true
|
||||
end
|
||||
|
||||
function ReaderZooming:onHintPage()
|
||||
if not self.view.hinting then return true end
|
||||
if self.current_page < self.ui.document.info.number_of_pages then
|
||||
|
||||
Reference in New Issue
Block a user