config line space/font gamma values directly

pull/810/head
chrox 10 years ago
parent c5def15558
commit 30898a3cd8

@ -114,6 +114,16 @@ DCREREADER_CONFIG_MARGIN_SIZES_SMALL = {5, 10, 5, 10}
DCREREADER_CONFIG_MARGIN_SIZES_MEDIUM = {10, 15, 10, 15} DCREREADER_CONFIG_MARGIN_SIZES_MEDIUM = {10, 15, 10, 15}
DCREREADER_CONFIG_MARGIN_SIZES_LARGE = {20, 20, 20, 20} DCREREADER_CONFIG_MARGIN_SIZES_LARGE = {20, 20, 20, 20}
-- crereader font gamma
DCREREADER_CONFIG_LIGHTER_FONT_GAMMA = 10
DCREREADER_CONFIG_DEFAULT_FONT_GAMMA = 15
DCREREADER_CONFIG_DARKER_FONT_GAMMA = 25
-- crereader line space percentage
DCREREADER_CONFIG_LINE_SPACE_PERCENT_SMALL = 90
DCREREADER_CONFIG_LINE_SPACE_PERCENT_MEDIUM = 100
DCREREADER_CONFIG_LINE_SPACE_PERCENT_LARGE = 120
-- crereader progress bar -- crereader progress bar
-- 0 for top "full" progress bar -- 0 for top "full" progress bar
-- 1 for bottom "mini" progress bar -- 1 for bottom "mini" progress bar

@ -68,24 +68,30 @@ function ReaderFont:onSetDimensions(dimen)
end end
function ReaderFont:onReadSettings(config) function ReaderFont:onReadSettings(config)
self.font_face = config:readSetting("font_face") or self.ui.document.default_font self.font_face = config:readSetting("font_face")
or self.ui.document.default_font
self.ui.document:setFontFace(self.font_face) self.ui.document:setFontFace(self.font_face)
self.header_font_face = config:readSetting("header_font_face") or self.ui.document.header_font self.header_font_face = config:readSetting("header_font_face")
or self.ui.document.header_font
self.ui.document:setHeaderFont(self.header_font_face) self.ui.document:setHeaderFont(self.header_font_face)
--@TODO change this! 12.01 2013 (houqp) self.font_size = config:readSetting("font_size")
self.font_size = config:readSetting("font_size") or DCREREADER_CONFIG_DEFAULT_FONT_SIZE or 22 or DCREREADER_CONFIG_DEFAULT_FONT_SIZE or 22
self.ui.document:setFontSize(Screen:scaleByDPI(self.font_size)) self.ui.document:setFontSize(Screen:scaleByDPI(self.font_size))
self.font_embolden = config:readSetting("font_embolden") or G_reader_settings:readSetting("copt_font_weight") or 0 self.font_embolden = config:readSetting("font_embolden")
or G_reader_settings:readSetting("copt_font_weight") or 0
self.ui.document:toggleFontBolder(self.font_embolden) self.ui.document:toggleFontBolder(self.font_embolden)
--@TODO still missing: line_spacing from settings.reader.lua (so far just decrease/increase in there) 18.07.2014 (WS64) self.line_space_percent = config:readSetting("line_space_percent")
self.line_space_percent = config:readSetting("line_space_percent") or (DKOPTREADER_CONFIG_LINE_SPACING or 1.2)*100 or G_reader_settings:readSetting("copt_line_spacing")
or DCREREADER_CONFIG_LINE_SPACE_PERCENT_MEDIUM
self.ui.document:setInterlineSpacePercent(self.line_space_percent) self.ui.document:setInterlineSpacePercent(self.line_space_percent)
self.gamma_index = config:readSetting("gamma_index") or 15 self.gamma_index = config:readSetting("gamma_index")
or G_reader_settings:readSetting("copt_font_gamma")
or DCREREADER_CONFIG_DEFAULT_FONT_GAMMA
self.ui.document:setGammaIndex(self.gamma_index) self.ui.document:setGammaIndex(self.gamma_index)
-- Dirty hack: we have to add folloing call in order to set -- Dirty hack: we have to add folloing call in order to set
@ -146,25 +152,14 @@ function ReaderFont:onSetFontSize(new_size)
return true return true
end end
function ReaderFont:onChangeLineSpace(direction) function ReaderFont:onSetLineSpace(space)
local msg = "" self.line_space_percent = math.min(200, math.max(80, space))
if direction == "decrease" then
self.line_space_percent = self.line_space_percent - 10
-- NuPogodi, 15.05.12: reduce lowest space_percent to 80
self.line_space_percent = math.max(self.line_space_percent, 80)
msg = _("Decrease line space to ")
else
self.line_space_percent = self.line_space_percent + 10
self.line_space_percent = math.min(self.line_space_percent, 200)
msg = _("Increase line space to ")
end
UIManager:show(Notification:new{ UIManager:show(Notification:new{
text = msg..self.line_space_percent.."%", text = _("Set line space to ")..self.line_space_percent.."%",
timeout = 1, timeout = 1,
}) })
self.ui.document:setInterlineSpacePercent(self.line_space_percent) self.ui.document:setInterlineSpacePercent(self.line_space_percent)
self.ui:handleEvent(Event:new("UpdatePos")) self.ui:handleEvent(Event:new("UpdatePos"))
return true return true
end end
@ -175,20 +170,13 @@ function ReaderFont:onToggleFontBolder(toggle)
return true return true
end end
function ReaderFont:onChangeFontGamma(direction) function ReaderFont:onSetFontGamma(gamma)
local msg = "" self.gamma_index = gamma
if direction == "increase" then
cre.setGammaIndex(self.gamma_index+2)
msg = _("Increase gamma to ")
elseif direction == "decrease" then
cre.setGammaIndex(self.gamma_index-2)
msg = _("Decrease gamma to ")
end
self.gamma_index = cre.getGammaIndex()
UIManager:show(Notification:new{ UIManager:show(Notification:new{
text = msg..self.gamma_index, text = _("Set font gamma to ")..self.gamma_index,
timeout = 1 timeout = 1
}) })
self.ui.document:setGammaIndex(self.gamma_index)
self.ui:handleEvent(Event:new("RedrawCurrentView")) self.ui:handleEvent(Event:new("RedrawCurrentView"))
return true return true
end end

@ -37,11 +37,19 @@ local CreOptions = {
{ {
name = "line_spacing", name = "line_spacing",
name_text = S.LINE_SPACING, name_text = S.LINE_SPACING,
toggle = {S.DECREASE, S.INCREASE}, toggle = {S.SMALL, S.MEDIUM, S.LARGE},
alternate = false, values = {
args = {"decrease", "increase"}, DCREREADER_CONFIG_LINE_SPACE_PERCENT_SMALL,
default_arg = "decrease", DCREREADER_CONFIG_LINE_SPACE_PERCENT_MEDIUM,
event = "ChangeLineSpace", DCREREADER_CONFIG_LINE_SPACE_PERCENT_LARGE,
},
default_value = DCREREADER_CONFIG_LINE_SPACE_PERCENT_MEDIUM,
event = "SetLineSpace",
args = {
DCREREADER_CONFIG_LINE_SPACE_PERCENT_SMALL,
DCREREADER_CONFIG_LINE_SPACE_PERCENT_MEDIUM,
DCREREADER_CONFIG_LINE_SPACE_PERCENT_LARGE,
},
}, },
{ {
name = "page_margins", name = "page_margins",
@ -53,12 +61,12 @@ local CreOptions = {
DCREREADER_CONFIG_MARGIN_SIZES_LARGE, DCREREADER_CONFIG_MARGIN_SIZES_LARGE,
}, },
default_value = DCREREADER_CONFIG_MARGIN_SIZES_MEDIUM, default_value = DCREREADER_CONFIG_MARGIN_SIZES_MEDIUM,
event = "SetPageMargins",
args = { args = {
DCREREADER_CONFIG_MARGIN_SIZES_SMALL, DCREREADER_CONFIG_MARGIN_SIZES_SMALL,
DCREREADER_CONFIG_MARGIN_SIZES_MEDIUM, DCREREADER_CONFIG_MARGIN_SIZES_MEDIUM,
DCREREADER_CONFIG_MARGIN_SIZES_LARGE, DCREREADER_CONFIG_MARGIN_SIZES_LARGE,
}, },
event = "SetPageMargins",
}, },
} }
}, },
@ -102,11 +110,19 @@ local CreOptions = {
{ {
name = "font_gamma", name = "font_gamma",
name_text = S.CONTRAST, name_text = S.CONTRAST,
toggle = {S.DECREASE, S.INCREASE}, item_text = {S.LIGHTER, S.DEFAULT, S.DARKER},
alternate = false, default_value = DCREREADER_CONFIG_DEFAULT_FONT_GAMMA,
args = {"decrease", "increase"}, values = {
default_arg = "increase", DCREREADER_CONFIG_LIGHTER_FONT_GAMMA,
event = "ChangeFontGamma", DCREREADER_CONFIG_DEFAULT_FONT_GAMMA,
DCREREADER_CONFIG_DARKER_FONT_GAMMA,
},
event = "SetFontGamma",
args = {
DCREREADER_CONFIG_LIGHTER_FONT_GAMMA,
DCREREADER_CONFIG_DEFAULT_FONT_GAMMA,
DCREREADER_CONFIG_DARKER_FONT_GAMMA,
},
} }
} }
}, },

@ -234,7 +234,7 @@ function ConfigOption:init()
local current_item = nil local current_item = nil
local function value_diff(val1, val2, name) local function value_diff(val1, val2, name)
if type(val1) ~= type(val2) then if type(val1) ~= type(val2) then
error("different data types in option", name) DEBUG("different data types in option")
end end
if type(val1) == "number" then if type(val1) == "number" then
return math.abs(val1 - val2) return math.abs(val1 - val2)

Loading…
Cancel
Save