mirror of
https://github.com/koreader/koreader.git
synced 2025-12-24 12:14:05 +01:00
pdfdocument: cache page text (#10450)
Updating the selection queries the same page tens of times per second. This prevents KOReader from keeping up with high-frequency input event streams. Fixes #10443. Relies on koreader/koreader-base#1612.
This commit is contained in:
@@ -103,10 +103,17 @@ function PdfDocument:comparePositions(pos1, pos2)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function PdfDocument:getPageTextBoxes(pageno)
|
function PdfDocument:getPageTextBoxes(pageno)
|
||||||
local page = self._document:openPage(pageno)
|
local hash = "textbox|"..self.file.."|"..pageno
|
||||||
local text = page:getPageText()
|
local cached = DocCache:check(hash)
|
||||||
page:close()
|
if not cached then
|
||||||
return text
|
local page = self._document:openPage(pageno)
|
||||||
|
local text = page:getPageText()
|
||||||
|
page:close()
|
||||||
|
DocCache:insert(hash, CacheItem:new{text=text, size=text.size})
|
||||||
|
return text
|
||||||
|
else
|
||||||
|
return cached.text
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function PdfDocument:getPanelFromPage(pageno, pos)
|
function PdfDocument:getPanelFromPage(pageno, pos)
|
||||||
|
|||||||
Reference in New Issue
Block a user