added line spacing setting for crereader

this patch also introduces an interface for setFontSize and setStyleSheet.
Hopefully, we can use the latter to send customized CSS to CREngine
as Lua strings. This functionality is however untested for now.
pull/2/merge
HW 12 years ago
parent 96958c62ca
commit e4841e88c4

@ -325,6 +325,30 @@ static int zoomFont(lua_State *L) {
return 1;
}
static int setFontSize(lua_State *L) {
CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument");
int size = luaL_checkint(L, 2);
doc->text_view->setFontSize(size);
return 0;
}
static int setDefaultInterlineSpace(lua_State *L) {
CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument");
int space = luaL_checkint(L, 2);
doc->text_view->setDefaultInterlineSpace(space);
return 0;
}
static int setStyleSheet(lua_State *L) {
CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument");
const char* style_sheet_data = luaL_checkstring(L, 2);
doc->text_view->setStyleSheet(lString8(style_sheet_data));
return 0;
}
static int toggleFontBolder(lua_State *L) {
CreDocument *doc = (CreDocument*) luaL_checkudata(L, 1, "credocument");
@ -422,6 +446,9 @@ static const struct luaL_Reg credocument_meth[] = {
{"getToc", getTableOfContent},
/*--- set methods ---*/
{"setFontFace", setFontFace},
{"setFontSize", setFontSize},
{"setDefaultInterlineSpace", setDefaultInterlineSpace},
{"setStyleSheet", setStyleSheet},
/* --- control methods ---*/
{"gotoPage", gotoPage},
{"gotoPercent", gotoPercent},

@ -9,6 +9,8 @@ CREReader = UniReader:new{
gamma_index = 15,
font_face = nil,
line_space_percent = 100,
}
function CREReader:init()
@ -39,6 +41,8 @@ function CREReader:open(filename)
return false, self.doc -- will contain error message
end
self.doc:setDefaultInterlineSpace(self.line_space_percent)
return true
end
@ -53,6 +57,9 @@ function CREReader:loadSpecialSettings()
local gamma_index = self.settings:readSetting("gamma_index")
self.gamma_index = gamma_index or self.gamma_index
cre.setGammaIndex(self.gamma_index)
local line_space_percent = self.settings:readSetting("line_space_percent")
self.line_space_percent = line_space_percent or self.line_space_percent
end
function CREReader:getLastPageOrPos()
@ -67,6 +74,7 @@ end
function CREReader:saveSpecialSettings()
self.settings:savesetting("font_face", self.font_face)
self.settings:savesetting("gamma_index", self.gamma_index)
self.settings:savesetting("line_space_percent", self.line_space_percent)
end
function CREReader:saveLastPageOrPos()
@ -245,20 +253,44 @@ function CREReader:adjustCreReaderCommands()
self.commands:del(KEY_N, MOD_SHIFT, "N") -- show highlights
-- overwrite commands
self.commands:add(KEY_PGFWD, MOD_SHIFT_OR_ALT, ">",
self.commands:add(KEY_PGFWD, MOD_SHIFT, ">",
"increase font size",
function(cr)
cr.doc:zoomFont(1)
cr:redrawCurrentPage()
end
)
self.commands:add(KEY_PGBCK, MOD_SHIFT_OR_ALT, "<",
self.commands:add(KEY_PGBCK, MOD_SHIFT, "<",
"decrease font size",
function(cr)
cr.doc:zoomFont(-1)
cr:redrawCurrentPage()
end
)
self.commands:add(KEY_PGFWD, MOD_ALT, ">",
"increase line spacing",
function(cr)
self.line_space_percent = self.line_space_percent + 10
if self.line_space_percent > 200 then
self.line_space_percent = 200
end
print("line spacing set to", self.line_space_percent)
cr.doc:setDefaultInterlineSpace(self.line_space_percent)
cr:redrawCurrentPage()
end
)
self.commands:add(KEY_PGBCK, MOD_ALT, "<",
"decrease line spacing",
function(cr)
self.line_space_percent = self.line_space_percent - 10
if self.line_space_percent < 100 then
self.line_space_percent = 100
end
print("line spacing set to", self.line_space_percent)
cr.doc:setDefaultInterlineSpace(self.line_space_percent)
cr:redrawCurrentPage()
end
)
local numeric_keydefs = {}
for i=1,10 do
numeric_keydefs[i]=Keydef:new(KEY_1+i-1, nil, tostring(i%10))

Loading…
Cancel
Save