UI font rendering: use available bold fonts for bold (#5675)

A few fixes and enhancement related to bold text:
- When using bold=true with a regular font, use its bold
  variant if one exists (can be prevented by manually
  adding a setting: "use_bold_font_for_bold" = false).
- When using a bold font without bold=true, promote bold
  to true, so fallback fonts are drawn bold too.
- Whether using a bold font, or using bold=true, ensure
  fallback fonts are drawn bold, with their available bold
  variant if one exists, or with synthetized bold.
- When using a bold variant of a fallback font, keep using
  the regular variant as another fallback (as bold fonts
  may contain less glyphs than their regular counterpart).
- Allow providing bold=Font.FORCE_SYNTHETIZED_BOLD to
  get synth bold even when a bold font exists (might be
  interesting to get text in bold the same width as the
  same text non-bold).
- Use the font realname in the key when caching glyphs,
  instead of our aliases (cfont, infont...) to avoid
  duplication and wasting memory.
This commit is contained in:
poire-z
2019-12-08 20:31:27 +01:00
committed by GitHub
parent b578d8aa8b
commit 55f3575a10
4 changed files with 217 additions and 17 deletions

View File

@@ -38,7 +38,9 @@ local TextBoxWidget = InputContainer:new{
alignment = "left", -- or "center", "right"
dialog = nil, -- parent dialog that will be set dirty
face = nil,
bold = nil,
bold = nil, -- use bold=true to use a real bold font (or synthetized if not available),
-- or bold=Font.FORCE_SYNTHETIZED_BOLD to force using synthetized bold,
-- which, with XText, makes a bold string the same width as it non-bolded.
line_height = 0.3, -- in em
fgcolor = Blitbuffer.COLOR_BLACK,
width = Screen:scaleBySize(400), -- in pixels
@@ -59,6 +61,7 @@ local TextBoxWidget = InputContainer:new{
text_height = nil, -- adjusted height to visible text (lines_per_page*line_height_px)
cursor_line = nil, -- LineWidget to draw the vertical cursor.
_bb = nil,
_face_adjusted = nil,
-- We can provide a list of images: each image will be displayed on each
-- scrolled page, in its top right corner (if more images than pages, remaining
@@ -99,6 +102,15 @@ local TextBoxWidget = InputContainer:new{
}
function TextBoxWidget:init()
if not self._face_adjusted then
self._face_adjusted = true -- only do that once
-- If self.bold, or if self.face is a real bold face, we may need to use
-- an alternative instance of self.face, with possibly the associated
-- real bold font, and/or with tweaks so fallback fonts are rendered bold
-- too, without affecting the regular self.face
self.face, self.bold = Font:getAdjustedFace(self.face, self.bold)
end
self.line_height_px = Math.round( (1 + self.line_height) * self.face.size )
self.cursor_line = LineWidget:new{
dimen = Geom:new{