From fa6fed85694fc15e2a97d9ef711f7be03f5d8da4 Mon Sep 17 00:00:00 2001 From: poire-z Date: Thu, 27 Feb 2020 12:12:49 +0100 Subject: [PATCH] cre: setFontFace(): increase bias given to the main font Solve the issue when a font without bold and italic variants is used as the default font (e.g. FreeSerif), and the style tweak "Ignore publisher font-family" is used (which uses a trick to cancel any font-family by requesting a font named "NoSuchFont"): When text is italic or bold, any of the registered fonts which have a real italic or bold variant would win over our default font, as the best substitute to NoSuchFont-Italic. This gives our default font a bit more bias so it can win in its scoring against the other fonts, and be rendered as fake italic or fake bold - which will ensure consistent font and line height. (A bit hacky, but no alternative solution found.) --- frontend/document/credocument.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/frontend/document/credocument.lua b/frontend/document/credocument.lua index 9e000bca5..d12314df1 100644 --- a/frontend/document/credocument.lua +++ b/frontend/document/credocument.lua @@ -586,6 +586,18 @@ function CreDocument:setFontFace(new_font_face) -- for font-family: monospace -- +256001: prefer our font to any existing font-family font self._document:setAsPreferredFontWithBias(new_font_face, 1) + -- +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 + -- have an italic or bold variant: + -- italic_match = 5 * (256 for real italic, or 128 for fake italic + -- weight_match = 5 * (256 - weight_diff * 256 / 800) + -- 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 + -- score, have a factor of 100 or 1000 vs the 5 used for italic & weight, + -- so it shouldn't hurt much). + -- Note that this is mostly necessary when forcing a not found name, + -- as we do in the Ignore font-family style tweak. + self._document:setAsPreferredFontWithBias(new_font_face, 1 + 128*5 + 256*5) end end