unified coordinates system in djvrereader

fix bug in showing manual corp area.
this also fixes #132.
Qingping Hou 12 years ago
parent d21ea032e5
commit a672cf4ee0

@ -255,6 +255,17 @@ static int getPageText(lua_State *L) {
DjvuDocument *doc = (DjvuDocument*) luaL_checkudata(L, 1, "djvudocument");
int pageno = luaL_checkint(L, 2);
/* get page height for coordinates transform */
ddjvu_pageinfo_t info;
ddjvu_status_t r;
while ((r=ddjvu_document_get_pageinfo(
doc->doc_ref, pageno-1, &info))<DDJVU_JOB_OK) {
handle(L, doc->context, TRUE);
}
if (r>=DDJVU_JOB_FAILED)
return luaL_error(L, "cannot get page #%d information", pageno);
/* start retrieving page text */
miniexp_t sexp, se_line, se_word;
int i = 1, j = 1, counter_l = 1, counter_w=1,
nr_line = 0, nr_word = 0;
@ -292,16 +303,18 @@ static int getPageText(lua_State *L) {
lua_pushnumber(L, miniexp_to_int(miniexp_nth(1, se_line)));
lua_settable(L, -3);
lua_pushstring(L, "y0");
lua_pushnumber(L, miniexp_to_int(miniexp_nth(2, se_line)));
lua_pushstring(L, "y1");
lua_pushnumber(L,
info.height - miniexp_to_int(miniexp_nth(2, se_line)));
lua_settable(L, -3);
lua_pushstring(L, "x1");
lua_pushnumber(L, miniexp_to_int(miniexp_nth(3, se_line)));
lua_settable(L, -3);
lua_pushstring(L, "y1");
lua_pushnumber(L, miniexp_to_int(miniexp_nth(4, se_line)));
lua_pushstring(L, "y0");
lua_pushnumber(L,
info.height - miniexp_to_int(miniexp_nth(4, se_line)));
lua_settable(L, -3);
/* now loop through each word in the line */
@ -325,16 +338,18 @@ static int getPageText(lua_State *L) {
lua_pushnumber(L, miniexp_to_int(miniexp_nth(1, se_word)));
lua_settable(L, -3);
lua_pushstring(L, "y0");
lua_pushnumber(L, miniexp_to_int(miniexp_nth(2, se_word)));
lua_pushstring(L, "y1");
lua_pushnumber(L,
info.height - miniexp_to_int(miniexp_nth(2, se_word)));
lua_settable(L, -3);
lua_pushstring(L, "x1");
lua_pushnumber(L, miniexp_to_int(miniexp_nth(3, se_word)));
lua_settable(L, -3);
lua_pushstring(L, "y1");
lua_pushnumber(L, miniexp_to_int(miniexp_nth(4, se_word)));
lua_pushstring(L, "y0");
lua_pushnumber(L,
info.height - miniexp_to_int(miniexp_nth(4, se_word)));
lua_settable(L, -3);
lua_pushstring(L, "word");

@ -31,68 +31,3 @@ function DJVUReader:getText(pageno)
return self.doc:getPageText(pageno)
end
----------------------------------------------------
-- In djvulibre library, some coordinates starts from
-- lower left conner, i.e. y is upside down in kpv's
-- coordinate. So y0 should be taken with special care.
----------------------------------------------------
function DJVUReader:zoomedRectCoordTransform(x0, y0, x1, y1)
local x,y = self:screenOffset()
return
x0 * self.globalzoom + x,
self.cur_full_height - (y1 * self.globalzoom) + y,
(x1 - x0) * self.globalzoom,
(y1 - y0) * self.globalzoom
end
-- make sure at least part of the box can be seen in next/previous view
-- @FIXME only works in FIT_TO_CONTENT_WIDTH mode 21.04 2012 (houqp)
-- @TODO use zoomedRectCoordTransform in unireader, no need to overwrite
-- it in here.
function DJVUReader:_isBoxInNextView(box)
return self.cur_full_height - (box.y0 * self.globalzoom) > -self.offset_y + G_height
end
function DJVUReader:_isBoxInPrevView(box)
return self.cur_full_height - (box.y1 * self.globalzoom) < -self.offset_y
end
-- y axel in djvulibre starts from bottom
function DJVUReader:_isEntireWordInScreenHeightRange(w)
return (w ~= nil) and
(self.cur_full_height - (w.y1 * self.globalzoom) >=
-self.offset_y) and
(self.cur_full_height - (w.y0 * self.globalzoom) <=
-self.offset_y + G_height)
end
-- y axel in djvulibre starts from bottom
function DJVUReader:_isEntireLineInScreenHeightRange(l)
return (l ~= nil) and
(self.cur_full_height - (l.y1 * self.globalzoom) >=
-self.offset_y) and
(self.cur_full_height - (l.y0 * self.globalzoom) <=
-self.offset_y + G_height)
end
-- y axel in djvulibre starts from bottom
function DJVUReader:_isWordInScreenRange(w)
if not w then
return false
end
is_entire_word_out_of_screen_height =
(self.cur_full_height - (w.y0 * self.globalzoom) <=
-self.offset_y)
or (self.cur_full_height - (w.y1 * self.globalzoom) >=
-self.offset_y + G_height)
is_entire_word_out_of_screen_width =
(w.x0 * self.globalzoom >= -self.offset_x + G_width
or w.x1 * self.globalzoom <= -self.offset_x)
return (not is_entire_word_out_of_screen_height) and
(not is_entire_word_out_of_screen_width)
end

Loading…
Cancel
Save