@ -30,6 +30,7 @@ local CreDocument = Document:new{
line_space_percent = 100 ,
line_space_percent = 100 ,
default_font = " Noto Serif " ,
default_font = " Noto Serif " ,
monospace_font = " Droid Sans Mono " ,
header_font = " Noto Sans " ,
header_font = " Noto Sans " ,
-- Reasons for the fallback font ordering:
-- Reasons for the fallback font ordering:
@ -132,6 +133,9 @@ function CreDocument:engineInit()
-- and bold text with the font_base_weight setting set to its default value of 0 (=400).
-- and bold text with the font_base_weight setting set to its default value of 0 (=400).
cre.regularizeRegisteredFontsWeights ( true ) -- true to print what modifications were made
cre.regularizeRegisteredFontsWeights ( true ) -- true to print what modifications were made
-- Set up bias for some specific fonts
self : setOtherFontBiases ( )
engine_initialized = true
engine_initialized = true
end
end
end
end
@ -237,6 +241,12 @@ function CreDocument:setupDefaultView()
-- or cover image, eg. from History hold menu).
-- or cover image, eg. from History hold menu).
self : setupFallbackFontFaces ( )
self : setupFallbackFontFaces ( )
-- Adjust or not fallback font sizes
self : setAdjustedFallbackFontSizes ( G_reader_settings : nilOrTrue ( " cre_adjusted_fallback_font_sizes " ) )
-- set monospace fonts size scaling
self : setMonospaceFontScaling ( G_reader_settings : readSetting ( " cre_monospace_scaling " ) or 100 )
-- adjust font sizes according to dpi set in canvas context
-- adjust font sizes according to dpi set in canvas context
self._document : adjustFontSizes ( CanvasContext : getDPI ( ) )
self._document : adjustFontSizes ( CanvasContext : getDPI ( ) )
@ -902,8 +912,8 @@ function CreDocument:setFontFace(new_font_face)
-- See: crengine/src/lvfntman.cpp LVFontDef::CalcMatch():
-- See: crengine/src/lvfntman.cpp LVFontDef::CalcMatch():
-- it will compute a score for each font, where it adds:
-- it will compute a score for each font, where it adds:
-- + 25600 if standard font family matches (inherit serif sans-serif
-- + 25600 if standard font family matches (inherit serif sans-serif
-- cursive fantasy monospace) (note that crengine registers all fonts as
-- cursive fantasy monospace) (note that crengine registers all fonts
-- "sans-serif", except if their name is "Times" or "Times New Roman" )
-- as "sans-serif", except monospace fonts )
-- + 6400 if they don't and none are monospace (ie:serif vs sans-serif,
-- + 6400 if they don't and none are monospace (ie:serif vs sans-serif,
-- prefer a sans-serif to a monospace if looking for a serif)
-- prefer a sans-serif to a monospace if looking for a serif)
-- +256000 if font names match
-- +256000 if font names match
@ -914,20 +924,42 @@ function CreDocument:setFontFace(new_font_face)
-- +25601: uses existing real font-family, but use our font even
-- +25601: uses existing real font-family, but use our font even
-- for font-family: monospace
-- for font-family: monospace
-- +256001: prefer our font to any existing font-family font
-- +256001: prefer our font to any existing font-family font
self._document : setAsPreferredFontWithBias ( new_font_face , 1 )
-- cre.setAsPreferredFontWithBias(new_font_face, 1 )
-- +1 +128x5 +256x5: we want our main font, even if it has no italic
-- Rather +1 +128x5 +256x5: we want our main font, even if it has no italic
-- nor bold variant (eg FreeSerif), to win over all other fonts that
-- nor bold variant (eg FreeSerif), to win over all other fonts that have
-- have an italic or bold variant:
-- an italic or bold variant:
-- italic_match = 5 * (256 for real italic, or 128 for fake italic
-- italic_match = 5 * (256 for real italic, or 128 for fake italic
-- weight_match = 5 * (256 - weight_diff * 256 / 800)
-- weight_match = 5 * (256 - weight_diff * 256 / 800)
-- so give our font a bias enough to win over real italic or bold fonts
-- so give our font a bias enough to win over real italic or bold fonts
-- (all others params (size, family, name), used for computing the match
-- (all others params (size, family, name), used for computing the match
-- score, have a factor of 100 or 1000 vs the 5 used for italic & weight,
-- score, have a factor of 100 or 1000 vs the 5 used for italic & weight,
-- so it shouldn't hurt much).
-- so it shouldn't hurt much).
-- Note that this is mostly necessary when forcing a not found name,
-- Note that this is mostly necessary when a font name is given and we
-- as we do in the Ignore font-family style tweak.
-- don't have the font.
self._document : setAsPreferredFontWithBias ( new_font_face , 1 + 128 * 5 + 256 * 5 )
cre.setAsPreferredFontWithBias ( new_font_face , 1 + 128 * 5 + 256 * 5 )
-- The above call has resetted all other biases, so re-set our other ones
self : setOtherFontBiases ( )
end
end
end
function CreDocument : setOtherFontBiases ( )
-- Make sure the user selected (or the default) monospace font is used even
-- if other monospace fonts were registered (same factor as above so its
-- synthetic bold or italic are used, in case some other monospace font
-- has real bold or italic variants)
local monospace_font = G_reader_settings : readSetting ( " monospace_font " ) or self.monospace_font
cre.setAsPreferredFontWithBias ( monospace_font , 1 + 128 * 5 + 256 * 5 , false )
end
function CreDocument : setMonospaceFontScaling ( value )
logger.dbg ( " CreDocument: set monospace font scaling " , value )
self._document : setIntProperty ( " font.monospace.size.scale.percent " , value or 100 )
end
function CreDocument : setAdjustedFallbackFontSizes ( toggle )
logger.dbg ( " CreDocument: set adjusted fallback font sizes " , toggle )
self._document : setIntProperty ( " crengine.font.fallback.sizes.adjusted " , toggle and 1 or 0 )
end
end
function CreDocument : setupFallbackFontFaces ( )
function CreDocument : setupFallbackFontFaces ( )