@ -2,11 +2,14 @@
This module contains miscellaneous helper functions for the creoptions and koptoptions .
] ]
local Device = require ( " device " )
local InfoMessage = require ( " ui/widget/infomessage " )
local UIManager = require ( " ui/uimanager " )
local _ = require ( " gettext " )
local C_ = _.pgettext
local T = require ( " ffi/util " ) . template
local logger = require ( " logger " )
local Screen = Device.screen
local optionsutil = { }
@ -14,7 +17,44 @@ function optionsutil.enableIfEquals(configurable, option, value)
return configurable [ option ] == value
end
function optionsutil . showValues ( configurable , option , prefix , document )
-- Converts px size to mm, inch or pt
-- if the `metric_length`-setting is not set or true -> mm
-- if the `metric_length`-setting is false -> inch
-- if format == "pt" -> pt
local function convertSizeTo ( px , format )
local format_factor = 1 -- we are defaulting on mm
if format == " pt " then
format_factor = format_factor * 2660 / 1000 -- see https://www.wikiwand.com/en/Metric_typographic_units
elseif format == " in " then
format_factor = 1 / 25.4
end
local display_dpi = Device : getDeviceScreenDPI ( ) or Screen : getDPI ( ) -- use device hardcoded dpi if available
return Screen : scaleBySize ( px ) / display_dpi * 25.4 * format_factor
end
local function real_size_string ( ko_size , unit )
if not ko_size or not unit then return " " end
ko_size = tonumber ( ko_size )
local shown_unit
if unit == " pt " then
shown_unit = C_ ( " Font size " , " pt " )
elseif unit == " mm " then
shown_unit = C_ ( " Length " , " mm " )
elseif unit == " in " then
shown_unit = C_ ( " Length " , " in " )
else
shown_unit = unit -- for future units
end
if ko_size then
return string.format ( " (%.2f %s) " , convertSizeTo ( ko_size , unit ) , shown_unit )
else
return " "
end
end
function optionsutil . showValues ( configurable , option , prefix , document , unit )
local default = G_reader_settings : readSetting ( prefix .. " _ " .. option.name )
local current = configurable [ option.name ]
local value_default , value_current
@ -123,7 +163,12 @@ function optionsutil.showValues(configurable, option, prefix, document)
current , value_current , default )
end
else
text = T ( _ ( " %1 \n %2 \n Current value: %3 \n Default value: %4 " ) , name_text , help_text , current , default )
if unit ~= " pt " then
unit = G_reader_settings : nilOrTrue ( " metric_length " ) and " mm " or " in "
end
text = T ( _ ( " %1 \n %2 \n Current value: %3%4 \n Default value: %5%6 " ) , name_text , help_text ,
current , real_size_string ( current , unit ) ,
default , real_size_string ( default , unit ) )
end
UIManager : show ( InfoMessage : new { text = text } )
end
@ -131,26 +176,30 @@ end
function optionsutil . showValuesHMargins ( configurable , option )
local default = G_reader_settings : readSetting ( " copt_ " .. option.name )
local current = configurable [ option.name ]
local unit = G_reader_settings : nilOrTrue ( " metric_length " ) and " mm " or " in "
if not default then
UIManager : show ( InfoMessage : new {
text = T ( _ ( [ [
Current margins :
left : % 1
right : % 2
left : % 1 % 2
right : % 3% 4
Default margins : not set ] ] ) ,
current [ 1 ] , current [ 2 ] )
current [ 1 ] , real_size_string ( current [ 1 ] , unit ) ,
current [ 2 ] , real_size_string ( current [ 2 ] , unit ) )
} )
else
UIManager : show ( InfoMessage : new {
text = T ( _ ( [ [
Current margins :
left : % 1
right : % 2
left : % 1 % 2
right : % 3% 4
Default margins :
left : % 3
right : % 4 ] ] ) ,
current [ 1 ] , current [ 2 ] ,
default [ 1 ] , default [ 2 ] )
left : % 5 % 6
right : % 7 % 8 ] ] ) ,
current [ 1 ] , real_size_string ( current [ 1 ] , unit ) ,
current [ 2 ] , real_size_string ( current [ 2 ] , unit ) ,
default [ 1 ] , real_size_string ( default [ 1 ] , unit ) ,
default [ 2 ] , real_size_string ( default [ 2 ] , unit ) )
} )
end
end