[UX] Add InfoMessage about OCR (#3718)

pull/3723/head
Frans de Jonge 6 years ago committed by GitHub
parent 4c1c8b8c2e
commit 076bf406fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -2,6 +2,7 @@ local ButtonDialog = require("ui/widget/buttondialog")
local ConfirmBox = require("ui/widget/confirmbox")
local Device = require("device")
local Event = require("ui/event")
local InfoMessage = require("ui/widget/infomessage")
local InputContainer = require("ui/widget/container/inputcontainer")
local TimeVal = require("ui/timeval")
local UIManager = require("ui/uimanager")
@ -342,6 +343,16 @@ function ReaderHighlight:onHoldPan(_, ges)
UIManager:setDirty(self.dialog, "ui")
end
local info_message_ocr_text = _([[
No OCR results or no language data.
KOReader has a build-in OCR engine for recognizing words in scanned PDF and DjVu documents. In order to use OCR in scanned pages, you need to install tesseract trained data for your document language.
You can download language data files for version 3.04 from https://github.com/tesseract-ocr/tesseract/wiki/Data-Files
Copy the language data files for Tesseract 3.04 (e.g., eng.traineddata for English and spa.traineddata for Spanish) into koreader/data/tessdata
]])
function ReaderHighlight:lookup(selected_word, selected_link)
-- if we extracted text directly
if selected_word.word then
@ -351,8 +362,14 @@ function ReaderHighlight:lookup(selected_word, selected_link)
elseif selected_word.sbox and self.hold_pos then
local word = self.ui.document:getOCRWord(self.hold_pos.page, selected_word)
logger.dbg("OCRed word:", word)
local word_box = self.view:pageToScreenTransform(self.hold_pos.page, selected_word.sbox)
self.ui:handleEvent(Event:new("LookupWord", word, word_box, self, selected_link))
if word and word ~= "" then
local word_box = self.view:pageToScreenTransform(self.hold_pos.page, selected_word.sbox)
self.ui:handleEvent(Event:new("LookupWord", word, word_box, self, selected_link))
else
UIManager:show(InfoMessage:new{
text = info_message_ocr_text,
})
end
end
end
@ -363,7 +380,13 @@ function ReaderHighlight:translate(selected_text)
else
local text = self.ui.document:getOCRText(self.hold_pos.page, selected_text)
logger.dbg("OCRed text:", text)
self.ui:handleEvent(Event:new("TranslateText", self, text))
if text and text ~= "" then
self.ui:handleEvent(Event:new("TranslateText", self, text))
else
UIManager:show(InfoMessage:new{
text = info_message_ocr_text,
})
end
end
end

@ -1,15 +1,15 @@
local TileCacheItem = require("document/tilecacheitem")
local KOPTContext = require("ffi/koptcontext")
local Document = require("document/document")
local DataStorage = require("datastorage")
local CacheItem = require("cacheitem")
local Screen = require("device").screen
local Geom = require("ui/geometry")
local serial = require("serialize")
local Cache = require("cache")
local CacheItem = require("cacheitem")
local DataStorage = require("datastorage")
local DEBUG = require("dbg")
local Document = require("document/document")
local Geom = require("ui/geometry")
local KOPTContext = require("ffi/koptcontext")
local TileCacheItem = require("document/tilecacheitem")
local logger = require("logger")
local serial = require("serialize")
local util = require("ffi/util")
local Screen = require("device").screen
local KoptInterface = {
ocrengine = "ocrengine",

Loading…
Cancel
Save