mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
PDF free zoom mode revisit
this should implement feature request of zoom mode for multi-columns page in #501 This PR depends on koreader/koreader-base#435 How to use? 1. Tap the top left corner of a PDF/Djvu page to get into the flipping mode 2. Double-tap on text block will zoom in to that column 3. Double-tap on any area will zoom out to an overview of the page 4. repeat step 2 to focus to another page block How does it work? 1. We first find the mask of text blocks in the page. (Pic 1) 2. Then we intersect page boxes with user tap to form a page block. (Pic 2) 3. Finally we zoom the page to the page block and center current view to that block. (Pic 3)
This commit is contained in:
@@ -540,10 +540,11 @@ end
|
||||
--[[
|
||||
get page regions in native page via optical method,
|
||||
--]]
|
||||
function KoptInterface:getPageRegions(doc, pageno)
|
||||
function KoptInterface:getPageBlock(doc, pageno, x, y)
|
||||
local kctx = nil
|
||||
local bbox = doc:getPageBBox(pageno)
|
||||
local context_hash = self:getContextHash(doc, pageno, bbox)
|
||||
local hash = "pageregions|"..context_hash
|
||||
local hash = "pageblocks|"..context_hash
|
||||
local cached = Cache:check(hash)
|
||||
if not cached then
|
||||
local page_size = Document.getNativePageDimensions(doc, pageno)
|
||||
@@ -553,17 +554,19 @@ function KoptInterface:getPageRegions(doc, pageno)
|
||||
y1 = page_size.h,
|
||||
}
|
||||
local kc = self:createContext(doc, pageno, bbox)
|
||||
kc:setZoom(1.0)
|
||||
local screen_size = Screen:getSize()
|
||||
-- leptonica needs a source image of at least 300dpi
|
||||
kc:setZoom(screen_size.w / page_size.w * 300 / self.screen_dpi)
|
||||
local page = doc._document:openPage(pageno)
|
||||
page:getPagePix(kc)
|
||||
local regions = kc:getPageRegions()
|
||||
Cache:insert(hash, CacheItem:new{ pageregions = regions })
|
||||
kc:findPageBlocks()
|
||||
Cache:insert(hash, CacheItem:new{ kctx = kc })
|
||||
page:close()
|
||||
kc:free()
|
||||
return regions
|
||||
kctx = kc
|
||||
else
|
||||
return cached.pageregions
|
||||
kctx = cached.kctx
|
||||
end
|
||||
return kctx:getPageBlock(x, y)
|
||||
end
|
||||
|
||||
--[[
|
||||
|
||||
Reference in New Issue
Block a user