fix: retain the selected code font with CJK fallback
Verify Tessera GUI / verify (push) Successful in 9m46s
Verify Tessera GUI / verify (push) Successful in 9m46s
This commit is contained in:
+12
-2
@@ -68,6 +68,7 @@ struct PreparedText {
|
||||
|
||||
struct TextEngine {
|
||||
fonts: FontSystem,
|
||||
code_family: Option<String>,
|
||||
swash: SwashCache,
|
||||
buffers: HashMap<TextKey, PreparedText>,
|
||||
source_bytes: usize,
|
||||
@@ -100,11 +101,12 @@ impl TextEngine {
|
||||
if let Some(name) = sans {
|
||||
fonts.db_mut().set_sans_serif_family(name);
|
||||
}
|
||||
if let Some(name) = mono {
|
||||
if let Some(name) = &mono {
|
||||
fonts.db_mut().set_monospace_family(name);
|
||||
}
|
||||
Self {
|
||||
fonts,
|
||||
code_family: mono,
|
||||
swash: SwashCache::new(),
|
||||
buffers: HashMap::new(),
|
||||
source_bytes: 0,
|
||||
@@ -128,7 +130,12 @@ impl TextEngine {
|
||||
}
|
||||
let family = match style.family {
|
||||
TextFamily::Interface => Family::SansSerif,
|
||||
TextFamily::Code => Family::Monospace,
|
||||
// Keep Latin source on the selected code face, and allow ordinary
|
||||
// script fallback for CJK instead of searching all monospace faces.
|
||||
TextFamily::Code => self
|
||||
.code_family
|
||||
.as_deref()
|
||||
.map_or(Family::Monospace, Family::Name),
|
||||
};
|
||||
let mut buffer = Buffer::new(
|
||||
&mut self.fonts,
|
||||
@@ -288,12 +295,15 @@ mod tests {
|
||||
.collect();
|
||||
assert_eq!(glyphs.len(), 4);
|
||||
assert!(glyphs.iter().all(|glyph| glyph.glyph_id != 0));
|
||||
assert!(engine.buffers[&key].size.width <= style.font_size * 8.0);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ellipsis_fits_actual_width_and_preserves_graphemes() {
|
||||
let style = TextStyle::code();
|
||||
let short_source = "let s = ui.text(\"中文字体\")";
|
||||
assert_eq!(fit(short_source, 365.0, style), short_source);
|
||||
let value = "e\u{301}e\u{301}中文字体e\u{301}e\u{301}";
|
||||
let width = measure("e\u{301}e\u{301}中…", style).width + 0.01;
|
||||
let fitted = fit(value, width, style);
|
||||
|
||||
Reference in New Issue
Block a user