Fix: '\t' always take up the width of four spaces

This commit is contained in:
Emil Ernerfeldt 2021-10-23 14:38:26 +02:00
parent 96b642a7f5
commit 4ace85b780

View file

@ -137,6 +137,18 @@ impl FontImpl {
// Add new character:
use ab_glyph::Font as _;
let glyph_id = self.ab_glyph_font.glyph_id(c);
if c == '\t' {
if let Some(space) = self.glyph_info(' ') {
let glyph_info = GlyphInfo {
advance_width: crate::text::TAB_SIZE as f32 * space.advance_width,
..GlyphInfo::default()
};
self.glyph_info_cache.write().insert(c, glyph_info);
return Some(glyph_info);
}
}
if glyph_id.0 == 0 {
if invisible_char(c) {
// hack
@ -147,7 +159,7 @@ impl FontImpl {
None
}
} else {
let mut glyph_info = allocate_glyph(
let glyph_info = allocate_glyph(
&mut self.atlas.lock(),
&self.ab_glyph_font,
glyph_id,
@ -156,12 +168,6 @@ impl FontImpl {
self.pixels_per_point,
);
if c == '\t' {
if let Some(space) = self.glyph_info(' ') {
glyph_info.advance_width = crate::text::TAB_SIZE as f32 * space.advance_width;
}
}
self.glyph_info_cache.write().insert(c, glyph_info);
Some(glyph_info)
}