add: font zooming in CREReader

This commit is contained in:
Qingping Hou
2012-03-30 12:31:09 +08:00
parent c0edbfae27
commit ad750a89f8
2 changed files with 48 additions and 19 deletions

50
cre.cpp
View File

@@ -60,24 +60,6 @@ static int closeDocument(lua_State *L) {
return 0;
}
static int gotoPage(lua_State *L) {
CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument");
int pageno = luaL_checkint(L, 2);
doc->text_view->goToPage(pageno);
return 0;
}
static int gotoPos(lua_State *L) {
CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument");
int pos = luaL_checkint(L, 2);
doc->text_view->SetPos(pos);
return 0;
}
static int getNumberOfPages(lua_State *L) {
CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument");
@@ -170,6 +152,35 @@ static int getTableOfContent(lua_State *L) {
return 1;
}
static int gotoPage(lua_State *L) {
CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument");
int pageno = luaL_checkint(L, 2);
doc->text_view->goToPage(pageno);
return 0;
}
static int gotoPos(lua_State *L) {
CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument");
int pos = luaL_checkint(L, 2);
doc->text_view->SetPos(pos);
return 0;
}
/* zoom font by given delta and return zoomed font size */
static int zoomFont(lua_State *L) {
CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument");
int delta = luaL_checkint(L, 2);
doc->text_view->ZoomFont(delta);
lua_pushnumber(L, doc->text_view->getFontSize());
return 1;
}
static int drawCurrentPage(lua_State *L) {
CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument");
DrawContext *dc = (DrawContext*) luaL_checkudata(L, 2, "drawcontext");
@@ -214,8 +225,9 @@ static const struct luaL_Reg credocument_meth[] = {
{"getPos", getPos},
{"GetFullHeight", getFullHeight},
{"getToc", getTableOfContent},
{"gotoPos", gotoPos},
{"gotoPage", gotoPage},
{"gotoPos", gotoPos},
{"zoomFont", zoomFont},
{"drawCurrentPage", drawCurrentPage},
{"close", closeDocument},
{"__gc", closeDocument},

View File

@@ -89,6 +89,7 @@ function CREReader:prevView()
end
function CREReader:adjustCreReaderCommands()
-- delete commands
self.commands:del(KEY_G, nil, "G")
self.commands:del(KEY_J, nil, "J")
self.commands:del(KEY_K, nil, "K")
@@ -107,4 +108,20 @@ function CREReader:adjustCreReaderCommands()
self.commands:del(KEY_F, nil, "F")
self.commands:del(KEY_F, MOD_SHIFT, "F")
self.commands:del(KEY_F, MOD_ALT, "F")
-- overwrite commands
self.commands:add(KEY_PGFWD, MOD_SHIFT_OR_ALT, ">",
"increase font size",
function(cr)
cr.doc:zoomFont(1)
cr:redrawCurrentPage()
end
)
self.commands:add(KEY_PGBCK, MOD_SHIFT_OR_ALT, "<",
"decrease font size",
function(cr)
cr.doc:zoomFont(-1)
cr:redrawCurrentPage()
end
)
end