From 30898a3cd8476b6a3ecae59eb7b0841a542e36fb Mon Sep 17 00:00:00 2001 From: chrox Date: Sun, 17 Aug 2014 21:45:48 +0800 Subject: [PATCH] config line space/font gamma values directly --- defaults.lua | 10 ++++ frontend/apps/reader/modules/readerfont.lua | 54 ++++++++------------- frontend/ui/data/creoptions.lua | 38 ++++++++++----- frontend/ui/widget/configdialog.lua | 2 +- 4 files changed, 59 insertions(+), 45 deletions(-) diff --git a/defaults.lua b/defaults.lua index 9c7913baf..227269562 100644 --- a/defaults.lua +++ b/defaults.lua @@ -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_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 -- 0 for top "full" progress bar -- 1 for bottom "mini" progress bar diff --git a/frontend/apps/reader/modules/readerfont.lua b/frontend/apps/reader/modules/readerfont.lua index db30fd046..151ef8fe1 100644 --- a/frontend/apps/reader/modules/readerfont.lua +++ b/frontend/apps/reader/modules/readerfont.lua @@ -68,24 +68,30 @@ function ReaderFont:onSetDimensions(dimen) end 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.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) - --@TODO change this! 12.01 2013 (houqp) - self.font_size = config:readSetting("font_size") or DCREREADER_CONFIG_DEFAULT_FONT_SIZE or 22 + self.font_size = config:readSetting("font_size") + or DCREREADER_CONFIG_DEFAULT_FONT_SIZE or 22 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) - --@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") or (DKOPTREADER_CONFIG_LINE_SPACING or 1.2)*100 + self.line_space_percent = config:readSetting("line_space_percent") + or G_reader_settings:readSetting("copt_line_spacing") + or DCREREADER_CONFIG_LINE_SPACE_PERCENT_MEDIUM 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) -- Dirty hack: we have to add folloing call in order to set @@ -146,25 +152,14 @@ function ReaderFont:onSetFontSize(new_size) return true end -function ReaderFont:onChangeLineSpace(direction) - local msg = "" - 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 +function ReaderFont:onSetLineSpace(space) + self.line_space_percent = math.min(200, math.max(80, space)) UIManager:show(Notification:new{ - text = msg..self.line_space_percent.."%", + text = _("Set line space to ")..self.line_space_percent.."%", timeout = 1, }) self.ui.document:setInterlineSpacePercent(self.line_space_percent) self.ui:handleEvent(Event:new("UpdatePos")) - return true end @@ -175,20 +170,13 @@ function ReaderFont:onToggleFontBolder(toggle) return true end -function ReaderFont:onChangeFontGamma(direction) - local msg = "" - 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() +function ReaderFont:onSetFontGamma(gamma) + self.gamma_index = gamma UIManager:show(Notification:new{ - text = msg..self.gamma_index, + text = _("Set font gamma to ")..self.gamma_index, timeout = 1 }) + self.ui.document:setGammaIndex(self.gamma_index) self.ui:handleEvent(Event:new("RedrawCurrentView")) return true end diff --git a/frontend/ui/data/creoptions.lua b/frontend/ui/data/creoptions.lua index 82d2900d7..3c5e254a6 100644 --- a/frontend/ui/data/creoptions.lua +++ b/frontend/ui/data/creoptions.lua @@ -37,11 +37,19 @@ local CreOptions = { { name = "line_spacing", name_text = S.LINE_SPACING, - toggle = {S.DECREASE, S.INCREASE}, - alternate = false, - args = {"decrease", "increase"}, - default_arg = "decrease", - event = "ChangeLineSpace", + toggle = {S.SMALL, S.MEDIUM, S.LARGE}, + values = { + DCREREADER_CONFIG_LINE_SPACE_PERCENT_SMALL, + DCREREADER_CONFIG_LINE_SPACE_PERCENT_MEDIUM, + 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", @@ -53,12 +61,12 @@ local CreOptions = { DCREREADER_CONFIG_MARGIN_SIZES_LARGE, }, default_value = DCREREADER_CONFIG_MARGIN_SIZES_MEDIUM, + event = "SetPageMargins", args = { DCREREADER_CONFIG_MARGIN_SIZES_SMALL, DCREREADER_CONFIG_MARGIN_SIZES_MEDIUM, DCREREADER_CONFIG_MARGIN_SIZES_LARGE, }, - event = "SetPageMargins", }, } }, @@ -102,11 +110,19 @@ local CreOptions = { { name = "font_gamma", name_text = S.CONTRAST, - toggle = {S.DECREASE, S.INCREASE}, - alternate = false, - args = {"decrease", "increase"}, - default_arg = "increase", - event = "ChangeFontGamma", + item_text = {S.LIGHTER, S.DEFAULT, S.DARKER}, + default_value = DCREREADER_CONFIG_DEFAULT_FONT_GAMMA, + values = { + DCREREADER_CONFIG_LIGHTER_FONT_GAMMA, + 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, + }, } } }, diff --git a/frontend/ui/widget/configdialog.lua b/frontend/ui/widget/configdialog.lua index 35d0f8394..86e8e5cfe 100644 --- a/frontend/ui/widget/configdialog.lua +++ b/frontend/ui/widget/configdialog.lua @@ -234,7 +234,7 @@ function ConfigOption:init() local current_item = nil local function value_diff(val1, val2, name) if type(val1) ~= type(val2) then - error("different data types in option", name) + DEBUG("different data types in option") end if type(val1) == "number" then return math.abs(val1 - val2)