mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
mod: rewrite highlight feature
waiting for integrate test with cursor support
This commit is contained in:
@@ -17,3 +17,61 @@ function DJVUReader:open(filename)
|
||||
self.doc = djvu.openDocument(filename)
|
||||
return self:loadSettings(filename)
|
||||
end
|
||||
|
||||
function DJVUReader:_isWordInScreenRange(w)
|
||||
return (self.cur_full_height-(w.y0*self.globalzoom) <=
|
||||
-self.offset_y + width) and
|
||||
(self.cur_full_height-(w.y1*self.globalzoom) >=
|
||||
-self.offset_y)
|
||||
end
|
||||
|
||||
function DJVUReader:_genTextIter(text, l0, w0, l1, w1)
|
||||
local word_items = {}
|
||||
local count = 0
|
||||
local l = l0
|
||||
local w = w0
|
||||
local tmp_w1 = 0
|
||||
|
||||
-- build item table
|
||||
while l <= l1 do
|
||||
local words = text[l].words
|
||||
|
||||
if l == l1 then
|
||||
tmp_w1 = w1
|
||||
else
|
||||
tmp_w1 = #words
|
||||
end
|
||||
|
||||
while w <= tmp_w1 do
|
||||
if self:_isWordInScreenRange(words[w]) then
|
||||
table.insert(word_items, words[w])
|
||||
end -- EOF if isInScreenRange
|
||||
w = w + 1
|
||||
end -- EOF while words
|
||||
-- goto next line, reset j
|
||||
w = 1
|
||||
l = l + 1
|
||||
end -- EOF for while
|
||||
|
||||
return function() count = count + 1 return word_items[count] end
|
||||
end
|
||||
|
||||
function DJVUReader:_drawTextHighLight(text_iter)
|
||||
for i in text_iter do
|
||||
fb.bb:paintRect(
|
||||
i.x0*self.globalzoom,
|
||||
self.offset_y+self.cur_full_height-(i.y1*self.globalzoom),
|
||||
(i.x1-i.x0)*self.globalzoom,
|
||||
(i.y1-i.y0)*self.globalzoom, 15)
|
||||
end -- EOF for
|
||||
end
|
||||
|
||||
function DJVUReader:startHighLightMode()
|
||||
local t = self.doc:getPageText(self.pageno)
|
||||
|
||||
--self:_drawTextHighLight(self:_genTextIter(t, 1, 1, #t, #(t[#t].words)))
|
||||
-- highlight the first line
|
||||
self:_drawTextHighLight(self:_genTextIter(t, 1, 1, 1, #(t[1].words)))
|
||||
fb:refresh(0)
|
||||
end
|
||||
|
||||
|
||||
@@ -725,28 +725,7 @@ function UniReader:showJumpStack()
|
||||
end
|
||||
|
||||
function UniReader:highLightText()
|
||||
local t = self.doc:getPageText(self.pageno)
|
||||
|
||||
local function isInScreenRange(v)
|
||||
return (self.cur_full_height-(v.y0*self.globalzoom) <=
|
||||
-self.offset_y + width) and
|
||||
(self.cur_full_height-(v.y1*self.globalzoom) >=
|
||||
-self.offset_y)
|
||||
end
|
||||
|
||||
for k1,v1 in ipairs(t) do
|
||||
local words = v1.words
|
||||
for k,v in ipairs(words) do
|
||||
if isInScreenRange(v) then
|
||||
fb.bb:paintRect(
|
||||
v.x0*self.globalzoom,
|
||||
self.offset_y+self.cur_full_height-(v.y1*self.globalzoom),
|
||||
(v.x1-v.x0)*self.globalzoom,
|
||||
(v.y1-v.y0)*self.globalzoom, 15)
|
||||
end -- EOF if isInScreenRange
|
||||
end -- EOF for words
|
||||
end -- EOF for lines
|
||||
fb:refresh(0)
|
||||
return
|
||||
end
|
||||
|
||||
function UniReader:showMenu()
|
||||
@@ -893,7 +872,7 @@ function UniReader:inputloop()
|
||||
self:setrotate( self.globalrotate - 10 )
|
||||
end
|
||||
elseif ev.code == KEY_N then
|
||||
self:highLightText()
|
||||
self:startHighLightMode()
|
||||
elseif ev.code == KEY_HOME then
|
||||
if Keys.shiftmode or Keys.altmode then
|
||||
-- signal quit
|
||||
|
||||
Reference in New Issue
Block a user