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.)
pull/5906/head
poire-z 4 years ago
parent 182dc60e00
commit fa6fed8569

@ -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

Loading…
Cancel
Save