From 6c5b544f4b9a3b1de9a8cc366d691f8531671833 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Sat, 28 Mar 2026 17:51:51 +0100 Subject: [PATCH] cleanup --- crates/epaint/src/text/font.rs | 18 +++++++----------- crates/epaint/src/text/text_layout.rs | 5 +++-- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/crates/epaint/src/text/font.rs b/crates/epaint/src/text/font.rs index 535b111b6..48659fbe9 100644 --- a/crates/epaint/src/text/font.rs +++ b/crates/epaint/src/text/font.rs @@ -551,10 +551,13 @@ impl FontFace { } = *shaped; if glyph_id == GlyphId::NOTDEF { + // invisible return (GlyphAllocation::default(), h_pos.round() as i32); } let (h_pos_round, bin) = if is_cjk { + // CJK scripts contain a lot of characters and could hog the glyph atlas + // if we stored 4 subpixel offsets per glyph. (h_pos.round() as i32, SubpixelBin::Zero) } else { SubpixelBin::new(h_pos) @@ -562,18 +565,11 @@ impl FontFace { let cache_key = GlyphCacheKey::new(glyph_id, metrics, bin); - let alloc = if let Some(cached) = self.glyph_alloc_cache.get(&cache_key) { - *cached - } else { - let alloc = self - .font + let alloc = *self.glyph_alloc_cache.entry(cache_key).or_insert_with(|| { + self.font .allocate_glyph_uncached(atlas, metrics, glyph_id, bin, (&metrics.location).into()) - .unwrap_or_default(); - - self.glyph_alloc_cache.insert(cache_key, alloc); - - alloc - }; + .unwrap_or_default() + }); (alloc, h_pos_round) } diff --git a/crates/epaint/src/text/text_layout.rs b/crates/epaint/src/text/text_layout.rs index d0cdeba2e..9483355fe 100644 --- a/crates/epaint/src/text/text_layout.rs +++ b/crates/epaint/src/text/text_layout.rs @@ -8,6 +8,7 @@ use crate::{ Color32, Mesh, Stroke, Vertex, stroke::PathStroke, text::{ + TAB_SIZE, font::{StyledMetrics, is_cjk, is_cjk_break_allowed}, fonts::FontFaceKey, }, @@ -227,8 +228,8 @@ fn layout_shaped_run( // Override the advance width to TAB_SIZE × space width. if chr == '\t' { let (_, space_info) = font.glyph_info(' '); - advance_width_px = - crate::text::TAB_SIZE as f32 * space_info.advance_width_unscaled.0 * px_scale; + let space_width_px = space_info.advance_width_unscaled.0 * px_scale; + advance_width_px = TAB_SIZE as f32 * space_width_px; } // Apply extra_letter_spacing only at cluster boundaries,