From adbbc0248bfb0acb960f93abd29e310fe1702da4 Mon Sep 17 00:00:00 2001 From: "Pedro M. de Echanove Pasquin" Date: Tue, 11 Aug 2026 22:04:22 +0200 Subject: [PATCH] =?UTF-8?q?render:=20pre-scale=20font=5Fline=5Fmetrics=20b?= =?UTF-8?q?y=20dpi=5Fscale=20The=20text=20pipeline=20works=20in=20physical?= =?UTF-8?q?=20pixels:=20measure=5Ftext=20and=20draw=5Ftext=20multiply=20th?= =?UTF-8?q?e=20font=20size=20by=20dpi=5Fscale=20internally,=20and=20the=20?= =?UTF-8?q?layout=20rects=20widgets=20receive=20are=20physical=20too.=20fo?= =?UTF-8?q?nt=5Fline=5Fmetrics=20was=20the=20one=20exception=20=E2=80=94?= =?UTF-8?q?=20it=20returned=20line=20metrics=20at=20the=20logical=20size?= =?UTF-8?q?=20=E2=80=94=20so=20the=20line=20height=20and=20ascent=20the=20?= =?UTF-8?q?text=20and=20rich=5Ftext=20widgets=20derive=20from=20it=20came?= =?UTF-8?q?=20out=20divided=20by=20the=20surface=20scale=20factor.=20On=20?= =?UTF-8?q?any=20output=20with=20a=20scale=20other=20than=201=20(e.g.=20a?= =?UTF-8?q?=20200%=20display,=20or=20any=20fractional=20setting=20the=20co?= =?UTF-8?q?mpositor=20rounds=20up=20to=20buffer=20scale=202),=20wrapped=20?= =?UTF-8?q?lines=20overlapped,=20baselines=20sat=20too=20high,=20and=20pre?= =?UTF-8?q?ferred=5Fsize=20reported=20half=20the=20real=20text=20height.?= =?UTF-8?q?=20Scale=20the=20size=20handed=20to=20horizontal=5Fline=5Fmetri?= =?UTF-8?q?cs=20by=20dpi=5Fscale=20in=20both=20the=20Canvas=20wrapper=20an?= =?UTF-8?q?d=20the=20GLES=20backend,=20matching=20the=20already=20pre-scal?= =?UTF-8?q?ed=20font=5Fmetrics.=20At=20scale=201=20the=20behaviour=20is=20?= =?UTF-8?q?unchanged.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/gles_render/setup.rs | 6 +++--- src/render/mod.rs | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/gles_render/setup.rs b/src/gles_render/setup.rs index 25e7cd4..5d08cb6 100644 --- a/src/gles_render/setup.rs +++ b/src/gles_render/setup.rs @@ -772,11 +772,11 @@ impl GlesCanvas self.font_for_char( ch ).metrics( ch, size * self.dpi_scale ) } - /// Horizontal line metrics of the default font at `size` px (`None` if the - /// font lacks them). Not pre-scaled by `dpi_scale`. + /// Horizontal line metrics of the default font at `size` logical px (`None` + /// if the font lacks them), pre-scaled by `dpi_scale`. pub fn font_line_metrics( &self, size: f32 ) -> Option { - self.font.horizontal_line_metrics( size ) + self.font.horizontal_line_metrics( size * self.dpi_scale ) } /// Resize the FBO and viewport. The previous color attachment is freed and diff --git a/src/render/mod.rs b/src/render/mod.rs index 41ab104..226bdfe 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -529,10 +529,11 @@ impl Canvas self.font().metrics( ch, size * self.dpi_scale() ) } - /// Convenience wrapper around `font().horizontal_line_metrics(...)`. + /// Convenience wrapper around `font().horizontal_line_metrics(...)`, + /// pre-scaled by `dpi_scale` like [`Self::font_metrics`]. pub fn font_line_metrics( &self, size: f32 ) -> Option { - self.font().horizontal_line_metrics( size ) + self.font().horizontal_line_metrics( size * self.dpi_scale() ) } pub fn resize( &mut self, width: u32, height: u32 )