mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
POC of text highlight in current page!
This commit is contained in:
14
djvu.c
14
djvu.c
@@ -286,7 +286,7 @@ static int openPage(lua_State *L) {
|
||||
static int getPageSize(lua_State *L) {
|
||||
DjvuPage *page = (DjvuPage*) luaL_checkudata(L, 1, "djvupage");
|
||||
DrawContext *dc = (DrawContext*) luaL_checkudata(L, 2, "drawcontext");
|
||||
|
||||
|
||||
lua_pushnumber(L, dc->zoom * page->info.width);
|
||||
lua_pushnumber(L, dc->zoom * page->info.height);
|
||||
|
||||
@@ -333,7 +333,7 @@ static int getPageText(lua_State *L) {
|
||||
int pageno = luaL_checkint(L, 2);
|
||||
|
||||
miniexp_t sexp, se_line, se_word;
|
||||
int i = 1, j = 1, counter = 1,
|
||||
int i = 1, j = 1, counter_l = 1, counter_w=1,
|
||||
nr_line = 0, nr_word = 0;
|
||||
const char *word = NULL;
|
||||
|
||||
@@ -350,6 +350,7 @@ static int getPageText(lua_State *L) {
|
||||
/* table that contains all the lines */
|
||||
lua_newtable(L);
|
||||
|
||||
counter_l = 1;
|
||||
for(i = 1; i <= nr_line; i++) {
|
||||
/* retrive one line entry */
|
||||
se_line = miniexp_nth(i, sexp);
|
||||
@@ -359,8 +360,9 @@ static int getPageText(lua_State *L) {
|
||||
}
|
||||
|
||||
/* subtable that contains words in a line */
|
||||
lua_pushnumber(L, i);
|
||||
lua_pushnumber(L, counter_l);
|
||||
lua_newtable(L);
|
||||
counter_l++;
|
||||
|
||||
/* set line position */
|
||||
lua_pushstring(L, "x0");
|
||||
@@ -382,7 +384,7 @@ static int getPageText(lua_State *L) {
|
||||
lua_pushstring(L, "words");
|
||||
lua_newtable(L);
|
||||
/* now loop through each word in the line */
|
||||
counter = 1;
|
||||
counter_w = 1;
|
||||
for(j = 1; j <= nr_word; j++) {
|
||||
/* retrive one word entry */
|
||||
se_word = miniexp_nth(j, se_line);
|
||||
@@ -393,9 +395,9 @@ static int getPageText(lua_State *L) {
|
||||
}
|
||||
|
||||
/* create table that contains info for a word */
|
||||
lua_pushnumber(L, counter);
|
||||
lua_pushnumber(L, counter_w);
|
||||
lua_newtable(L);
|
||||
counter++;
|
||||
counter_w++;
|
||||
|
||||
/* set word info */
|
||||
lua_pushstring(L, "x0");
|
||||
|
||||
@@ -32,9 +32,12 @@ UniReader = {
|
||||
-- gamma setting:
|
||||
globalgamma = 1.0, -- GAMMA_NO_GAMMA
|
||||
|
||||
-- size of current page for current zoom level in pixels
|
||||
-- cached tile size
|
||||
fullwidth = 0,
|
||||
fullheight = 0,
|
||||
-- size of current page for current zoom level in pixels
|
||||
cur_full_width = 0,
|
||||
cur_full_height = 0,
|
||||
offset_x = 0,
|
||||
offset_y = 0,
|
||||
min_offset_x = 0,
|
||||
@@ -180,7 +183,7 @@ function UniReader:draworcache(no, preCache)
|
||||
|
||||
-- ideally, this should be factored out and only be called when needed (TODO)
|
||||
local page = self.doc:openPage(no)
|
||||
local dc = self:setzoom(page)
|
||||
local dc = self:setzoom(page, preCache)
|
||||
|
||||
-- offset_x_in_page & offset_y_in_page is the offset within zoomed page
|
||||
-- they are always positive.
|
||||
@@ -285,7 +288,7 @@ function UniReader:clearcache()
|
||||
end
|
||||
|
||||
-- set viewer state according to zoom state
|
||||
function UniReader:setzoom(page)
|
||||
function UniReader:setzoom(page, preCache)
|
||||
local dc = self.newDC()
|
||||
local pwidth, pheight = page:getSize(self.nulldc)
|
||||
print("# page::getSize "..pwidth.."*"..pheight);
|
||||
@@ -415,6 +418,10 @@ function UniReader:setzoom(page)
|
||||
|
||||
dc:setRotate(self.globalrotate);
|
||||
self.fullwidth, self.fullheight = page:getSize(dc)
|
||||
if not preCache then -- save current page fullsize
|
||||
self.cur_full_width = self.fullwidth
|
||||
self.cur_full_height = self.fullheight
|
||||
end
|
||||
self.min_offset_x = fb.bb:getWidth() - self.fullwidth
|
||||
self.min_offset_y = fb.bb:getHeight() - self.fullheight
|
||||
if(self.min_offset_x > 0) then
|
||||
@@ -717,6 +724,31 @@ function UniReader:showJumpStack()
|
||||
end
|
||||
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)
|
||||
end
|
||||
|
||||
function UniReader:showMenu()
|
||||
local ypos = height - 50
|
||||
local load_percent = (self.pageno / self.doc:getPages())
|
||||
@@ -860,6 +892,8 @@ function UniReader:inputloop()
|
||||
else
|
||||
self:setrotate( self.globalrotate - 10 )
|
||||
end
|
||||
elseif ev.code == KEY_N then
|
||||
self:highLightText()
|
||||
elseif ev.code == KEY_HOME then
|
||||
if Keys.shiftmode or Keys.altmode then
|
||||
-- signal quit
|
||||
|
||||
Reference in New Issue
Block a user