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: // Add new character:
use ab_glyph::Font as _; use ab_glyph::Font as _;
let glyph_id = self.ab_glyph_font.glyph_id(c); 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 glyph_id.0 == 0 {
if invisible_char(c) { if invisible_char(c) {
// hack // hack
@ -147,7 +159,7 @@ impl FontImpl {
None None
} }
} else { } else {
let mut glyph_info = allocate_glyph( let glyph_info = allocate_glyph(
&mut self.atlas.lock(), &mut self.atlas.lock(),
&self.ab_glyph_font, &self.ab_glyph_font,
glyph_id, glyph_id,
@ -156,12 +168,6 @@ impl FontImpl {
self.pixels_per_point, 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); self.glyph_info_cache.write().insert(c, glyph_info);
Some(glyph_info) Some(glyph_info)
} }