1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-02 14:50:03 -04:00
This commit is contained in:
Emil Ernerfeldt
2026-03-28 17:51:51 +01:00
parent 83c03655d4
commit 6c5b544f4b
2 changed files with 10 additions and 13 deletions

View File

@@ -551,10 +551,13 @@ impl FontFace {
} = *shaped; } = *shaped;
if glyph_id == GlyphId::NOTDEF { if glyph_id == GlyphId::NOTDEF {
// invisible
return (GlyphAllocation::default(), h_pos.round() as i32); return (GlyphAllocation::default(), h_pos.round() as i32);
} }
let (h_pos_round, bin) = if is_cjk { 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) (h_pos.round() as i32, SubpixelBin::Zero)
} else { } else {
SubpixelBin::new(h_pos) SubpixelBin::new(h_pos)
@@ -562,18 +565,11 @@ impl FontFace {
let cache_key = GlyphCacheKey::new(glyph_id, metrics, bin); let cache_key = GlyphCacheKey::new(glyph_id, metrics, bin);
let alloc = if let Some(cached) = self.glyph_alloc_cache.get(&cache_key) { let alloc = *self.glyph_alloc_cache.entry(cache_key).or_insert_with(|| {
*cached self.font
} else {
let alloc = self
.font
.allocate_glyph_uncached(atlas, metrics, glyph_id, bin, (&metrics.location).into()) .allocate_glyph_uncached(atlas, metrics, glyph_id, bin, (&metrics.location).into())
.unwrap_or_default(); .unwrap_or_default()
});
self.glyph_alloc_cache.insert(cache_key, alloc);
alloc
};
(alloc, h_pos_round) (alloc, h_pos_round)
} }

View File

@@ -8,6 +8,7 @@ use crate::{
Color32, Mesh, Stroke, Vertex, Color32, Mesh, Stroke, Vertex,
stroke::PathStroke, stroke::PathStroke,
text::{ text::{
TAB_SIZE,
font::{StyledMetrics, is_cjk, is_cjk_break_allowed}, font::{StyledMetrics, is_cjk, is_cjk_break_allowed},
fonts::FontFaceKey, fonts::FontFaceKey,
}, },
@@ -227,8 +228,8 @@ fn layout_shaped_run(
// Override the advance width to TAB_SIZE × space width. // Override the advance width to TAB_SIZE × space width.
if chr == '\t' { if chr == '\t' {
let (_, space_info) = font.glyph_info(' '); let (_, space_info) = font.glyph_info(' ');
advance_width_px = let space_width_px = space_info.advance_width_unscaled.0 * px_scale;
crate::text::TAB_SIZE as f32 * 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, // Apply extra_letter_spacing only at cluster boundaries,