From c24d75f18cccff90dae5682cd7895c353b9fd2eb Mon Sep 17 00:00:00 2001 From: poire-z Date: Fri, 1 Sep 2017 21:49:10 +0200 Subject: [PATCH] Fix use of default font with font-family: styles Base bumped. Previsouly, parts of document in

would be rendered with the first font set, and would not follow change of font (unline other texts without styles). That was observable with Embedded Styles set to On, but is even more noticiable with the new Embedded Fonts setting set to off. --- base | 2 +- frontend/document/credocument.lua | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/base b/base index b42a2b686..58112413f 160000 --- a/base +++ b/base @@ -1 +1 @@ -Subproject commit b42a2b686ac0af88b70e4a44da065d3b7bed6433 +Subproject commit 58112413f2a29fa227d47ae8e558ffdb74278aa9 diff --git a/frontend/document/credocument.lua b/frontend/document/credocument.lua index 0efe9598a..e8e4938b6 100644 --- a/frontend/document/credocument.lua +++ b/frontend/document/credocument.lua @@ -335,6 +335,26 @@ function CreDocument:setFontFace(new_font_face) if new_font_face then logger.dbg("CreDocument: set font face", new_font_face) self._document:setStringProperty("font.face.default", new_font_face) + + -- The following makes FontManager prefer this font in its match + -- algorithm, with the bias given (applies only to rendering of + -- elements with css font-family) + -- See: crengine/src/lvfntman.cpp LVFontDef::CalcMatch(): + -- it will compute a score for each font, where it adds: + -- + 25600 if standard font family matches (inherit serif sans-serif + -- cursive fantasy monospace) (note that crengine registers all fonts as + -- "sans-serif", except if their name is "Times" or "Times New Roman") + -- + 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) + -- +256000 if font names match + -- So, here, we can bump the score of our default font, and we could use: + -- +1: uses existing real font-family, but use our font for + -- font-family: serif, sans-serif..., and fonts not found (or + -- embedded fonts disabled) + -- +25601: uses existing real font-family, but use our font even + -- for font-family: monospace + -- +256001: prefer our font to any existing font-family font + self._document:setAsPreferredFontWithBias(new_font_face, 1) end end