Merge pull request #1314 from mitchellh/xft-dpi-round

apprt/gtk: xft-dpi can be fractional, do not expect exact division
pull/1316/head
Mitchell Hashimoto 2024-01-15 23:05:50 -08:00 committed by GitHub
commit 771cbea0b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 2 deletions

View File

@ -676,8 +676,10 @@ pub fn getContentScale(self: *const Surface) !apprt.ContentScale {
const gtk_xft_dpi = c.g_value_get_int(&value);
// As noted above Xft.dpi is multiplied by 1024, so we divide by 1024,
// then divide by the default value of Xft.dpi (96) to derive a scale
const xft_dpi: f32 = @floatFromInt(@divExact(gtk_xft_dpi, 1024));
// then divide by the default value of Xft.dpi (96) to derive a scale.
// Note that gtk-xft-dpi can be fractional, so we use floating point
// math here.
const xft_dpi: f32 = @as(f32, @floatFromInt(gtk_xft_dpi)) / 1024;
break :xft_scale xft_dpi / 96;
};