Snap text to pixel grid after applying viewport offset

Text inside viewports was blurry with fractional scale factors because it was aligned to the pixel grid before the viewport offset was applied.
This commit is contained in:
Dodomew authored and meehl committed 2026-11-10 22:33:55 +01:00
1 parent 1aa0aa128f
commit 3e065a8838
3 files changed
+16 -2

No files matched your search

+4
View File
@@ -2,6 +2,10 @@
## [Unreleased] - ReleaseDate
### Fixed
- Fix blurry text inside viewports with fractional scale factors
## [0.3.3] - 2026-10-23
### Fixed
+4
View File
@@ -57,6 +57,10 @@ impl DrawCommandRecorder {
self.current_viewport = viewport;
}
pub fn get_viewport(&self) -> LogicalRect<f32> {
self.current_viewport
}
pub fn set_viewport_from_size(&mut self, size: LogicalSize<f32>) {
self.set_viewport(LogicalRect::from_size(size));
}
+8 -2
View File
@@ -1,6 +1,6 @@
use crate::{
color::Srgba,
dpi::LogicalPoint,
dpi::{LogicalPoint, LogicalVector},
fonts::{Alignment, FontStyle, LayoutJob, LayoutToLogical},
math::Point,
pob::Context,
@@ -103,7 +103,13 @@ pub unsafe extern "C-unwind" fn draw_string(state: *mut ffi::lua_State) -> c_int
// apply offset to account for anchor position
let position = position + layout.anchor_offset(halign);
// align layout anchor with the physical pixel grid to reduce blurriness
let position = (position * scale_factor).round() / scale_factor;
let viewport_offset = if is_absolute_position {
LogicalVector::zero()
} else {
ctx.recorder.get_viewport().min.to_vector()
};
let position =
((position + viewport_offset) * scale_factor).round() / scale_factor - viewport_offset;
for glyph in &layout.glyphs {
ctx.recorder.draw_glyph(