diff --git a/CHANGELOG.md b/CHANGELOG.md index 97888a8..f15cde6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## [Unreleased] - ReleaseDate +### Fixed + +- Fix blurry text inside viewports with fractional scale factors + ## [0.3.3] - 2026-10-23 ### Fixed diff --git a/src/draw_commands.rs b/src/draw_commands.rs index 1e5e670..b8bb25f 100644 --- a/src/draw_commands.rs +++ b/src/draw_commands.rs @@ -57,6 +57,10 @@ impl DrawCommandRecorder { self.current_viewport = viewport; } + pub fn get_viewport(&self) -> LogicalRect { + self.current_viewport + } + pub fn set_viewport_from_size(&mut self, size: LogicalSize) { self.set_viewport(LogicalRect::from_size(size)); } diff --git a/src/pob/api/text.rs b/src/pob/api/text.rs index 26dbfc7..1b933c9 100644 --- a/src/pob/api/text.rs +++ b/src/pob/api/text.rs @@ -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(