Align layout origins with physical pixel grid for sharper text rendering

This commit is contained in:
meehl committed 2025-10-20 12:24:31 +02:00
1 parent a096547b7f
commit 8d0f9502e3
4 files changed
+29 -14

No files matched your search

+1
View File
@@ -5,6 +5,7 @@
### Fixed
- Fix problem that causes non-identical frames to be elided.
- Correctly align layout origins with physical pixel grid for sharper text rendering.
## [0.1.1] - 2025-10-19
+5 -3
View File
@@ -99,9 +99,11 @@ impl Context {
self.previous_layers_hash = layers_hash;
let primitives = self.layers.consume_layers();
let meshes = self
.tessellator
.convert_clipped_primitives(primitives, font_atlas_size);
let meshes = self.tessellator.convert_clipped_primitives(
primitives,
font_atlas_size,
self.pixels_per_point,
);
RenderJob::Render {
meshes,
+4 -8
View File
@@ -155,7 +155,7 @@ impl Fonts {
};
let mut builder =
self.layout_context
.tree_builder(&mut self.font_context, 1.0, true, &style);
.tree_builder(&mut self.font_context, 1.0, false, &style);
builder.push_text(text);
let (mut layout, _) = builder.build();
@@ -204,13 +204,9 @@ impl Fonts {
..default_style
};
let mut builder = self.layout_context.tree_builder(
&mut self.font_context,
1.0,
// TODO: quantize true or false?
true,
&style,
);
let mut builder =
self.layout_context
.tree_builder(&mut self.font_context, 1.0, false, &style);
for segment in job.segments {
let brush_style = StyleProperty::Brush(segment.color);
+19 -3
View File
@@ -1,5 +1,5 @@
use crate::{
dpi::{Normalize, NormalizedQuad, NormalizedRect, Uv},
dpi::{ConvertToLogical, ConvertToPhysical, Normalize, NormalizedQuad, NormalizedRect, Uv},
fonts::FontAtlasSize,
renderer::{
mesh::{ClippedMesh, Mesh},
@@ -22,13 +22,19 @@ impl Tessellator {
&mut self,
clipped_primitives: impl Iterator<Item = ClippedPrimitive>,
font_atlas_size: FontAtlasSize,
pixels_per_point: f32,
) -> Vec<ClippedMesh> {
profiling::scope!("convert_primitives");
let mut clipped_meshes = Vec::with_capacity(self.last_clipped_meshes_size);
for clipped_primitive in clipped_primitives {
self.convert_clipped_primitive(clipped_primitive, font_atlas_size, &mut clipped_meshes);
self.convert_clipped_primitive(
clipped_primitive,
font_atlas_size,
pixels_per_point,
&mut clipped_meshes,
);
}
self.last_clipped_meshes_size = clipped_meshes.len();
@@ -39,6 +45,7 @@ impl Tessellator {
&mut self,
clipped_primitive: ClippedPrimitive,
font_atlas_size: FontAtlasSize,
pixels_per_point: f32,
out_clipped_meshes: &mut Vec<ClippedMesh>,
) {
let ClippedPrimitive {
@@ -79,6 +86,7 @@ impl Tessellator {
DrawPrimitive::Text(text_primitive) => self.convert_text_primitive(
text_primitive,
font_atlas_size,
pixels_per_point,
&mut last_clipped_mesh.mesh,
),
}
@@ -134,6 +142,7 @@ impl Tessellator {
&self,
text_primitive: TextPrimitive,
font_atlas_size: FontAtlasSize,
pixels_per_point: f32,
out: &mut Mesh,
) {
let TextPrimitive {
@@ -148,7 +157,14 @@ impl Tessellator {
out.vertices.reserve(layout.num_of_vertices);
out.indices.reserve(layout.num_of_indices);
// TODO: align to pixel grid?
// Make sure the layout origin aligns with the physical pixel grid so
// that each glyph aligns correctly. Glyphs are positioned relative
// to the layout origin and assume that it ends up on the start of
// a physical pixel.
let layout_pos = layout_pos
.to_physical::<f32, _>(pixels_per_point)
.round()
.to_logical(pixels_per_point);
for row in &layout.rows {
for glyph in &row.glyphs {