feat: shape and antialias Tessera text with system fonts
Verify Tessera GUI / verify (push) Successful in 13m28s

This commit is contained in:
2026-10-20 14:25:28 +08:00
parent 1f64de48b9
commit f0fae1792f
19 changed files with 661 additions and 95 deletions
+14 -25
View File
@@ -2,6 +2,7 @@ use crate::{
display_list::{Color, DisplayList, DrawCommand},
document::{CodeNode, RenderDocument},
geometry::{Point, Rect},
text::{self as typography, TextStyle},
};
const PANEL: Color = Color::rgb(247, 247, 245);
@@ -154,14 +155,13 @@ pub fn build(
if state.selected_node_id.as_deref() == Some(node.id.as_str()) {
fill(&mut list, row, 5.0 * scale, SELECTED);
}
text(
&mut list,
row.x + (9.0 + depth as f32 * 14.0) * scale,
row.y + 8.0 * scale,
&fit(&format!("{} {}", node.kind, node.name), 44),
scale,
TEXT,
let text_x = row.x + (9.0 + depth as f32 * 14.0) * scale;
let label = typography::fit(
&format!("{} {}", node.kind, node.name),
(width - 14.0 * scale - text_x).max(0.0),
TextStyle::code().scaled(scale),
);
text(&mut list, text_x, row.y + 3.0 * scale, &label, scale, TEXT);
layout.rows.push(TreeRowHit {
rect: row,
node_id: node.id.clone(),
@@ -235,7 +235,7 @@ fn draw_source(
let first_y = area.y + 42.0 * scale;
let maximum_lines =
((area.y + area.height - first_y - 10.0 * scale) / line_height).max(0.0) as usize;
let max_chars = ((area.width / (8.0 * scale)) - 9.0).max(8.0) as usize;
let source_width = (area.width - 65.0 * scale).max(0.0);
for (offset, source_line) in all_lines[start..end].iter().take(maximum_lines).enumerate() {
let line_number = start + offset + 1;
@@ -252,7 +252,11 @@ fn draw_source(
list,
area.x + 55.0 * scale,
y,
&fit(&source_line.replace('\t', " "), max_chars),
&typography::fit(
&source_line.replace('\t', " "),
source_width,
TextStyle::code().scaled(scale),
),
scale,
TEXT,
);
@@ -266,21 +270,6 @@ fn flatten<'a>(node: &'a CodeNode, depth: usize, output: &mut Vec<(usize, &'a Co
}
}
fn fit(value: &str, maximum: usize) -> String {
let characters: Vec<_> = value.chars().collect();
if characters.len() <= maximum {
return value.to_owned();
}
if maximum < 3 {
return characters.into_iter().take(maximum).collect();
}
characters
.into_iter()
.take(maximum - 3)
.chain(['.', '.', '.'])
.collect()
}
fn fill(list: &mut DisplayList, rect: Rect, radius: f32, color: Color) {
list.push(DrawCommand::FillRoundedRect {
rect,
@@ -293,7 +282,7 @@ fn text(list: &mut DisplayList, x: f32, y: f32, value: &str, scale: f32, color:
list.push(DrawCommand::Text {
origin: Point::new(x, y),
value: value.to_owned(),
scale: scale.round().max(1.0) as u32,
style: TextStyle::code().scaled(scale),
color,
});
}