Skip to content

Commit

Permalink
getLinkFromPosition(), getPageLinks(): better xpointer for link origin (
Browse files Browse the repository at this point in the history
#598)

Bumps crengine for the new `getHRef(a_xpointer)` methods, see koreader/crengine#96
Follow up to #597.
  • Loading branch information
poire-z authored and Frenzie committed Feb 7, 2018
1 parent 81cd9b5 commit 953103e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
27 changes: 16 additions & 11 deletions cre.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,11 @@ static int getPosFromXPointer(lua_State *L) {
}
lua_pushinteger(L, pos);

return 1;
// Also returns the x value (as the 2nd returned value, as its
// less interesting to current code than the y value)
lua_pushinteger(L, pt.x);

return 2;
}

static int getCurrentPos(lua_State *L) {
Expand Down Expand Up @@ -947,10 +951,11 @@ static int getLinkFromPosition(lua_State *L) {

lvPoint pt(x, y);
ldomXPointer p = doc->text_view->getNodeByPoint(pt, true);
lString16 href = p.getHRef();
ldomXPointer a_p;
lString16 href = p.getHRef(a_p);
lua_pushstring(L, UnicodeToLocal(href).c_str());
if (!p.isNull()) {// return position's xpointer too
lua_pushstring(L, UnicodeToLocal(p.toString()).c_str());
if (!a_p.isNull()) { // return xpointer to <a> itself
lua_pushstring(L, UnicodeToLocal(a_p.toString()).c_str());
return 2;
}
return 1;
Expand Down Expand Up @@ -1205,7 +1210,8 @@ static int getPageLinks(lua_State *L) {
lString16 txt = links[i]->getRangeText();
lString8 txt8 = UnicodeToLocal( txt );

lString16 link = links[i]->getHRef();
ldomXPointer a_xpointer;
lString16 link = links[i]->getHRef(a_xpointer);
lString8 link8 = UnicodeToLocal( link );

ldomXRange currSel;
Expand Down Expand Up @@ -1234,12 +1240,11 @@ static int getPageLinks(lua_State *L) {
lua_pushinteger(L, end_pt.y - y_offset);
lua_settable(L, -3);

lua_pushstring(L, "start_xpointer");
lua_pushstring(L, UnicodeToLocal(currSel.getStart().toString()).c_str());
lua_settable(L, -3);
lua_pushstring(L, "end_xpointer");
lua_pushstring(L, UnicodeToLocal(currSel.getEnd().toString()).c_str());
lua_settable(L, -3);
if (!a_xpointer.isNull()) { // xpointer to <a> itself
lua_pushstring(L, "a_xpointer");
lua_pushstring(L, UnicodeToLocal(a_xpointer.toString()).c_str());
lua_settable(L, -3);
}

const char * link_to = link8.c_str();

Expand Down
2 changes: 1 addition & 1 deletion thirdparty/kpvcrlib/crengine

0 comments on commit 953103e

Please sign in to comment.