Try harder to succeed at fall-backing to a Monospace font

A combination of some ideas:

 * Try all Monospace fonts before giving up.
 * Relax exact weight restriction on font matching when trying Monospace
   fall-back. Try smaller weights if needed.
 * Make the fall-back try order weight-offset aware, AND script-aware.
 * And finally, add the option to adjust the font size of glyphs using
   fall-back Monospace fonts, so the width of them matches the default
   font width.

   For my use-case, the current fall-back attempt always fails with
   Arabic script. And none of the Arabic-supporting Monospace fonts in
   my system also support medium weight. So, if my default font is set
   to medium weight, script-aware fall-back alone will still not work.

Signed-off-by: Mohammad AlSaleh <CE.Mohammad.AlSaleh@gmail.com>
This commit is contained in:
Mohammad AlSaleh 2024-01-17 12:32:33 +03:00 committed by Jeremy Soller
parent 054b7da828
commit 329941c4a6
8 changed files with 177 additions and 39 deletions

View file

@ -184,6 +184,7 @@ impl BufferLine {
font_size: f32,
width: f32,
wrap: Wrap,
match_mono_width: Option<f32>,
) -> &[LayoutLine] {
self.layout_in_buffer(
&mut ShapeBuffer::default(),
@ -191,6 +192,7 @@ impl BufferLine {
font_size,
width,
wrap,
match_mono_width,
)
}
@ -202,12 +204,13 @@ impl BufferLine {
font_size: f32,
width: f32,
wrap: Wrap,
match_mono_width: Option<f32>,
) -> &[LayoutLine] {
if self.layout_opt.is_none() {
let align = self.align;
let shape = self.shape_in_buffer(scratch, font_system);
let mut layout = Vec::with_capacity(1);
shape.layout_to_buffer(scratch, font_size, width, wrap, align, &mut layout);
shape.layout_to_buffer(scratch, font_size, width, wrap, align, &mut layout, match_mono_width);
self.layout_opt = Some(layout);
}
self.layout_opt.as_ref().expect("layout not found")