Skip to content

PdfCraft: An open-source PDF reader and editor written by scratch in pure Rust

M14: interface size preference; Auto follows GNOME text scaling (#902)

mitul728196d6f45ad4
diff --git a/ATTRIBUTION.toml b/ATTRIBUTION.toml
index fb17edeb0..3d7b86294 100644
--- a/ATTRIBUTION.toml
+++ b/ATTRIBUTION.toml
@@ -19,7 +19,7 @@ licence = "MIT OR Apache-2.0"
licence_file = "LICENSE-MIT"
kind = "translation"
usage = "Simplified Chinese UI strings, compiled in by crates/ui-egui/src/i18n/mod.rs"
-sha256 = "e59d7b71199d61a0e5de541de11509e94a78a5c8f085f12201a6fc096217564a"
+sha256 = "bd3a2ecc4e5706827859c7e55107ffe7430422a31cfae756a7410f739a18d309"
[[asset]]
path = "crates/ui-egui/src/i18n/zh-hant.tsv"
@@ -30,7 +30,7 @@ licence = "MIT OR Apache-2.0"
licence_file = "LICENSE-MIT"
kind = "translation"
usage = "Traditional Chinese UI strings, compiled in by crates/ui-egui/src/i18n/mod.rs"
-sha256 = "9c581ca790fc25aa484202c50f9cf6bbe0799572abe90b23fe37f2cba6508825"
+sha256 = "0266a1d134096809222b7dfe40a760f308336fe11f5b51d53f6eb0bf251d130b"
[[asset]]
path = "crates/ui-egui/src/i18n/cs.tsv"
@@ -41,7 +41,7 @@ licence = "MIT OR Apache-2.0"
licence_file = "LICENSE-MIT"
kind = "translation"
usage = "Czech UI strings, compiled in by crates/ui-egui/src/i18n/mod.rs"
-sha256 = "f973d0a66f4dae804bd308ac828ef5688c2336fd787724104253f72c1fab7446"
+sha256 = "933a864a7b0f6380dc1f9f636340f586638da636e660af6553d12c44981b7f94"
[[asset]]
path = "crates/ui-egui/src/i18n/pt-br.tsv"
@@ -52,7 +52,7 @@ licence = "MIT OR Apache-2.0"
licence_file = "LICENSE-MIT"
kind = "translation"
usage = "Brazilian Portuguese UI strings, compiled in by crates/ui-egui/src/i18n/mod.rs"
-sha256 = "598ead6edbaf5794c300bff2ba767239ad6e8f5c201afe7988952bb5adf1d0e4"
+sha256 = "cb37df8d0df51cd045816149fd07680a7014b3fba42d0ae1c6e80fab69ecbeda"
[[asset]]
path = "crates/ui-egui/src/i18n/es.tsv"
@@ -63,7 +63,7 @@ licence = "MIT OR Apache-2.0"
licence_file = "LICENSE-MIT"
kind = "translation"
usage = "Spanish UI strings, compiled in by crates/ui-egui/src/i18n/mod.rs"
-sha256 = "24ea1744a8bc0f34acb65bbc64daba47cf3dbb4bb954c14a8b7c752841d6ca46"
+sha256 = "90b49f520061c8174936b9e049d87b10318a1d5e1ebcc63a29f7c26a9dc56831"
[[asset]]
path = "crates/ui-egui/src/i18n/fr.tsv"
@@ -74,7 +74,7 @@ licence = "MIT OR Apache-2.0"
licence_file = "LICENSE-MIT"
kind = "translation"
usage = "French UI strings, compiled in by crates/ui-egui/src/i18n/mod.rs"
-sha256 = "7b1b5ae014234cc4e8da1496fdade2499ef302d1d882d05c8639eed570ec8619"
+sha256 = "13d83f91945362a618d9ca2bfdcc7d9a11d0e2b549899aac30ff210f1f566919"
[[asset]]
path = "crates/ui-egui/src/i18n/de.tsv"
@@ -85,7 +85,7 @@ licence = "MIT OR Apache-2.0"
licence_file = "LICENSE-MIT"
kind = "translation"
usage = "German UI strings, compiled in by crates/ui-egui/src/i18n/mod.rs"
-sha256 = "757eee5dbc83bde240a744d283241085ea12dadbb59ba9335ed09d077727fe12"
+sha256 = "f6bbf852d04a0f281a1e4735b619372e77963e9b30f5bc1ca040e815bd072100"
[[asset]]
path = "crates/ui-egui/src/i18n/te.tsv"
@@ -96,7 +96,7 @@ licence = "MIT OR Apache-2.0"
licence_file = "LICENSE-MIT"
kind = "translation"
usage = "Telugu UI strings, compiled in by crates/ui-egui/src/i18n/mod.rs"
-sha256 = "27e20bee9b536af7b883a13e3aecb58a3069c1aa9691503000587a61044fa70f"
+sha256 = "3d5b1e627bedbca0b34b6a7c76943ca063fe3bc4d0916e3026535716f205affa"
[[asset]]
path = "crates/ui-egui/src/i18n/it.tsv"
@@ -107,7 +107,7 @@ licence = "MIT OR Apache-2.0"
licence_file = "LICENSE-MIT"
kind = "translation"
usage = "Italian UI strings, compiled in by crates/ui-egui/src/i18n/mod.rs"
-sha256 = "5c68ea0936961fe24a9ac905c6c9d7e5fe5a8f7203b952865365d421fd1bed79"
+sha256 = "d55ea186857822a76254b2bb97ba144733f1f26764038fe4df6872c80cfc9df2"
[[asset]]
path = "crates/ui-egui/src/i18n/pl.tsv"
@@ -129,7 +129,7 @@ licence = "MIT OR Apache-2.0"
licence_file = "LICENSE-MIT"
kind = "translation"
usage = "Russian UI strings, compiled in by crates/ui-egui/src/i18n/mod.rs"
-sha256 = "3037387258191e8c7840817675ef871454cf6bd11143842a0c7aeeeef7772c6a"
+sha256 = "6164520d217da8b3ed6b15883133e6897f49de844b40f1988a80d66ddb12aa69"
[[asset]]
path = "crates/ui-egui/src/i18n/hu.tsv"
@@ -140,7 +140,7 @@ licence = "MIT OR Apache-2.0"
licence_file = "LICENSE-MIT"
kind = "translation"
usage = "Hungarian UI strings, compiled in by crates/ui-egui/src/i18n/mod.rs"
-sha256 = "cb06f042ebbac9bd75dcde134799151be8345e9554a9a930c586a14b8d0650ef"
+sha256 = "c8ef58ee02ce7a46452595a4a41cca91cea7dcf6aa85f7eb85947c5b67c3c0ad"
[[asset]]
path = "crates/ui-egui/src/i18n/bg.tsv"
@@ -151,7 +151,7 @@ licence = "MIT OR Apache-2.0"
licence_file = "LICENSE-MIT"
kind = "translation"
usage = "Bulgarian UI strings, compiled in by crates/ui-egui/src/i18n/mod.rs"
-sha256 = "c6761eda84aaec2dcd95fd5b4feb549c778567838d894492621b1a43e55251fa"
+sha256 = "914b15d71f3168d2875d1583fc66c4ae1bf8aaf6a71edd0e418be188cd4c1fcf"
[[asset]]
path = "crates/ui-egui/src/i18n/ja.tsv"
@@ -162,7 +162,7 @@ licence = "MIT OR Apache-2.0"
licence_file = "LICENSE-MIT"
kind = "translation"
usage = "Japanese UI strings, compiled in by crates/ui-egui/src/i18n/mod.rs"
-sha256 = "b37f1cae5cd20a2fa30bf237faa3f05700e6d5d1618f03c1ad7328a6deb7086f"
+sha256 = "c8a5b5038929f5eb3d91f479ab3b65a77e38056626fa9ef9e3e02932615d53a2"
[[asset]]
path = "crates/ui-egui/src/i18n/uk.tsv"
@@ -173,7 +173,7 @@ licence = "MIT OR Apache-2.0"
licence_file = "LICENSE-MIT"
kind = "translation"
usage = "Ukrainian UI strings, compiled in by crates/ui-egui/src/i18n/mod.rs"
-sha256 = "774def02e9d3803631f6da90b774133851ff5d73c2cb78f86809afbbea650e7e"
+sha256 = "5d4a82edfa1721bdaf3e0f7bbd59473a6a497c7ea47104a73e2062bf03facac6"
[[asset]]
path = "crates/ui-egui/src/i18n/ar.tsv"
@@ -184,7 +184,7 @@ licence = "MIT OR Apache-2.0"
licence_file = "LICENSE-MIT"
kind = "translation"
usage = "Arabic UI strings, compiled in by crates/ui-egui/src/i18n/mod.rs"
-sha256 = "cc448df6f85f1db3c9672e12e97718b98898d1662c87301ee0185b4c11563be0"
+sha256 = "2ce6abd311d689654a7932e3ac212088e2685efd8bd4f4fa8da0a29c6c5ab3c5"
[[asset]]
path = "assets/icons/accessibility.svg"
diff --git a/ROADMAP.md b/ROADMAP.md
index 5949645f1..6672c8f8b 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -135,6 +135,7 @@ Ranked; detail and the full milestone table in [docs/roadmap.md](docs/roadmap.md
Newest first: the date, what moved, and the new overall estimate.
+- **2026-10-10 (M14, interface size):** Preferences ▸ Interface size scales the whole interface (50–250 %, setting `ui_scale`, control option `ui-scale`); 50 % brings an interface the system draws at 200 % back to 100 % (#456). Auto, the default, follows the desktop's text scaling: on Linux and the BSDs the desktop app reads GNOME's `text-scaling-factor` once at launch, so with Large Text (1.25) on a 1× display the interface no longer draws 13 px labels that show their pixels next to the system's text. The size is egui's zoom factor, so `pixels_per_point` grows with it and page rasters stay one texel per screen pixel; egui's own ⌘+/⌘− interface zoom is turned off so those keys stay page zoom. Still missing: KDE's font DPI and Windows' "Make text bigger" aren't read (both scale only text there), and egui's text is still greyscale-antialiased without the system's gamma, so small text looks rougher than GTK's at 100 %.
- **2026-10-10 (M14, #496):** Shortcut displays share a UI formatter across toolbar search, registry menus, command palette, Help and tooltips. Modifier and key names use a dedicated catalog context in every bundled translation; missing entries keep the English key name rather than a command translation. German shows Strg/Umschalt/Entf, macOS retains its symbols, and runtime language changes refresh the display. Regression coverage checks localized layout widths, English/German switching, platform conventions and unchanged command execution. Milestone and effort estimates unchanged.
- **2026-10-10 (M5, shape fill colour, #686):** Rectangles, ovals, polygons and clouds can be filled. The comment quick bar has a Fill colour control for those tools ("No fill" or a swatch; it persists with the other per-tool styles), Comment Properties ▸ Appearance has a Fill colour row (one undo step with the other changes, carried over by Make Current Properties Default), and `comment_edit` takes `fill` (`"none"` removes it). `pdfcraft-annot::set_fill` writes or removes `/IC` and redraws the appearance; lines, ink and locked comments refuse it. Still missing: a custom colour picker (only the comment palette), and a separate fill for line endings.
diff --git a/apps/pdfcraft/src/main.rs b/apps/pdfcraft/src/main.rs
index 87f02ca76..9d6f5fcb7 100644
--- a/apps/pdfcraft/src/main.rs
+++ b/apps/pdfcraft/src/main.rs
@@ -33,6 +33,7 @@ use pdfcraft_ui_egui::PdfCraftApp;
mod apple_events;
mod logging;
mod single_instance;
+mod text_scale;
mod updates;
#[cfg(test)]
#[path = "windows_manifest.rs"]
@@ -302,6 +303,7 @@ fn app_creator<'a>(
app.restore(&json);
}
app.integrated_titlebar = integrated;
+ app.system_text_scale = text_scale::system();
app.update_source = Some(std::sync::Arc::new(updates::latest_release));
app.os_key_store_ids = cfg!(any(target_os = "macos", target_os = "windows"));
#[cfg(target_os = "macos")]
diff --git a/apps/pdfcraft/src/text_scale.rs b/apps/pdfcraft/src/text_scale.rs
new file mode 100644
index 000000000..8bb8ea51a
--- /dev/null
+++ b/apps/pdfcraft/src/text_scale.rs
@@ -0,0 +1,68 @@
+//! The desktop's text scaling, for Preferences ▸ Interface size ▸ Auto.
+//!
+//! On Linux and the BSDs, GNOME (and desktops sharing its settings schema) keep it in
+//! `org.gnome.desktop.interface text-scaling-factor` (Settings ▸ Accessibility ▸ Large Text sets
+//! 1.25). It is read once at launch through `gsettings`, which is absent or fails elsewhere, and
+//! anything but a sensible number counts as no scaling. Other systems scale the whole display
+//! instead, which already reaches egui as `pixels_per_point`.
+
+/// How long `gsettings` may take before launch goes on without it.
+#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd", target_os = "netbsd"))]
+const TIMEOUT: std::time::Duration = std::time::Duration::from_millis(500);
+
+/// The text scaling factor, or 1.0.
+pub fn system() -> f32 {
+ #[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd", target_os = "netbsd"))]
+ if let Some(output) = gsettings(&["get", "org.gnome.desktop.interface", "text-scaling-factor"]) {
+ return parse(&output);
+ }
+ 1.0
+}
+
+/// `gsettings` output (`1.25`) as a factor; 1.0 when it isn't a usable one.
+#[cfg_attr(not(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd", target_os = "netbsd")), allow(dead_code))]
+fn parse(output: &str) -> f32 {
+ output.trim().parse::<f64>().ok().and_then(pdfcraft_ui_egui::ui_scale::valid).unwrap_or(1.0)
+}
+
+/// Run `gsettings` and return what it printed, or `None` if it is missing, fails or hangs.
+#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd", target_os = "netbsd"))]
+fn gsettings(args: &[&str]) -> Option<String> {
+ use std::io::Read;
+ use std::process::{Command, Stdio};
+ let mut child = Command::new("gsettings").args(args).stdin(Stdio::null()).stdout(Stdio::piped()).stderr(Stdio::null()).spawn().ok()?;
+ let start = std::time::Instant::now();
+ loop {
+ match child.try_wait() {
+ Ok(Some(status)) if status.success() => break,
+ Ok(None) if start.elapsed() < TIMEOUT => std::thread::sleep(std::time::Duration::from_millis(5)),
+ _ => {
+ let _ = child.kill();
+ let _ = child.wait();
+ return None;
+ }
+ }
+ }
+ let mut out = String::new();
+ // A number fits in far less; a misbehaving `gsettings` can't make launch read without end.
+ child.stdout.take()?.take(256).read_to_string(&mut out).ok()?;
+ Some(out)
+}
+
+#[cfg(test)]
+mod tests {
+ #[test]
+ fn gsettings_output_parses_or_means_no_scaling() {
+ assert_eq!(super::parse("1.25\n"), 1.25);
+ assert_eq!(super::parse("1.0"), 1.0);
+ for bad in ["", "nan", "inf", "-2", "0", "uint32 0", "100"] {
+ assert_eq!(super::parse(bad), 1.0, "{bad}");
+ }
+ }
+
+ #[test]
+ fn reading_the_system_scale_never_fails() {
+ let f = super::system();
+ assert!(f.is_finite() && (pdfcraft_ui_egui::ui_scale::MIN..=pdfcraft_ui_egui::ui_scale::MAX).contains(&f), "{f}");
+ }
+}
diff --git a/crates/ui-egui/src/i18n/ar.tsv b/crates/ui-egui/src/i18n/ar.tsv
index e2d397bbe..eaa4d24b2 100644
--- a/crates/ui-egui/src/i18n/ar.tsv
+++ b/crates/ui-egui/src/i18n/ar.tsv
@@ -29,6 +29,9 @@
Preferences التفضيلات
Preferences… التفضيلات…
Interface language لغة الواجهة
+ Interface size حجم الواجهة
+ Auto ({percent}%) تلقائي ({percent}%)
+ Auto follows the system's text size. Pages always render at the display's full resolution. يتبع الوضع التلقائي حجم النص في النظام. تُعرض الصفحات دائمًا بالدقة الكاملة للشاشة.
Identity الهوية
Name on new comments الاسم على التعليقات الجديدة
Open… فتح…
diff --git a/crates/ui-egui/src/i18n/bg.tsv b/crates/ui-egui/src/i18n/bg.tsv
index 64796bf41..a91eb8f81 100644
--- a/crates/ui-egui/src/i18n/bg.tsv
+++ b/crates/ui-egui/src/i18n/bg.tsv
@@ -55,6 +55,9 @@
Preferences Настройки
Preferences… Настройки…
Interface language Език на интерфейса
+ Interface size Размер на интерфейса
+ Auto ({percent}%) Автоматично ({percent}%)
+ Auto follows the system's text size. Pages always render at the display's full resolution. Автоматично следва размера на текста в системата. Страниците винаги се изобразяват с пълната разделителна способност на екрана.
Identity Самоличност
Name on new comments Име в новите коментари
Open… Отвори…
diff --git a/crates/ui-egui/src/i18n/cs.tsv b/crates/ui-egui/src/i18n/cs.tsv
index 20623a74e..60e08d1b0 100644
--- a/crates/ui-egui/src/i18n/cs.tsv
+++ b/crates/ui-egui/src/i18n/cs.tsv
@@ -24,6 +24,9 @@
Preferences Předvolby
Preferences… Předvolby…
Interface language Jazyk rozhraní
+ Interface size Velikost rozhraní
+ Auto ({percent}%) Automaticky ({percent} %)
+ Auto follows the system's text size. Pages always render at the display's full resolution. Automaticky se řídí velikostí textu v systému. Stránky se vždy vykreslují v plném rozlišení displeje.
Identity Identita
Name on new comments Jméno autora nových komentářů
Enable Acrobat JavaScript Povolit Acrobat JavaScript
diff --git a/crates/ui-egui/src/i18n/de.tsv b/crates/ui-egui/src/i18n/de.tsv
index 981d6c476..0f539b14b 100644
--- a/crates/ui-egui/src/i18n/de.tsv
+++ b/crates/ui-egui/src/i18n/de.tsv
@@ -18,6 +18,9 @@
Preferences Einstellungen
Preferences… Einstellungen…
Interface language Sprache der Oberfläche
+ Interface size Größe der Oberfläche
+ Auto ({percent}%) Automatisch ({percent} %)
+ Auto follows the system's text size. Pages always render at the display's full resolution. Automatisch folgt der Textgröße des Systems. Seiten werden immer in der vollen Auflösung des Bildschirms dargestellt.
Identity Identität
Name on new comments Name für neue Kommentare
Open… Öffnen…
diff --git a/crates/ui-egui/src/i18n/es.tsv b/crates/ui-egui/src/i18n/es.tsv
index aef78de0d..94e58c9cd 100644
--- a/crates/ui-egui/src/i18n/es.tsv
+++ b/crates/ui-egui/src/i18n/es.tsv
@@ -18,6 +18,9 @@
Preferences Preferencias
Preferences… Preferencias…
Interface language Idioma de la interfaz
+ Interface size Tamaño de la interfaz
+ Auto ({percent}%) Automático ({percent} %)
+ Auto follows the system's text size. Pages always render at the display's full resolution. Automático sigue el tamaño del texto del sistema. Las páginas siempre se muestran con la resolución completa de la pantalla.
Identity Identidad
Name on new comments Nombre en los comentarios nuevos
Open… Abrir…
diff --git a/crates/ui-egui/src/i18n/fr.tsv b/crates/ui-egui/src/i18n/fr.tsv
index af009a511..6fe6ed05a 100644
--- a/crates/ui-egui/src/i18n/fr.tsv
+++ b/crates/ui-egui/src/i18n/fr.tsv
@@ -18,6 +18,9 @@
Preferences Préférences
Preferences… Préférences…
Interface language Langue de l'interface
+ Interface size Taille de l'interface
+ Auto ({percent}%) Automatique ({percent} %)
+ Auto follows the system's text size. Pages always render at the display's full resolution. Automatique suit la taille du texte du système. Les pages sont toujours rendues à la pleine résolution de l'écran.
Identity Identité
Name on new comments Nom sur les nouveaux commentaires
Open… Ouvrir…
diff --git a/crates/ui-egui/src/i18n/hu.tsv b/crates/ui-egui/src/i18n/hu.tsv
index 48666e9d6..084c352b1 100644
--- a/crates/ui-egui/src/i18n/hu.tsv
+++ b/crates/ui-egui/src/i18n/hu.tsv
@@ -18,6 +18,9 @@
Preferences Beállítások
Preferences… Beállítások…
Interface language Felület nyelve
+ Interface size Felület mérete
+ Auto ({percent}%) Automatikus ({percent}%)
+ Auto follows the system's text size. Pages always render at the display's full resolution. Az Automatikus beállítás a rendszer szövegméretét követi. Az oldalak mindig a kijelző teljes felbontásában jelennek meg.
Identity Személyazonosság
Name on new comments Név az új megjegyzéseken
Open… Megnyitás…
diff --git a/crates/ui-egui/src/i18n/it.tsv b/crates/ui-egui/src/i18n/it.tsv
index 21b6da2aa..76c6db343 100644
--- a/crates/ui-egui/src/i18n/it.tsv
+++ b/crates/ui-egui/src/i18n/it.tsv
@@ -24,6 +24,9 @@
Preferences Preferenze
Preferences… Preferenze…
Interface language Lingua dell'interfaccia
+ Interface size Dimensione dell'interfaccia
+ Auto ({percent}%) Auto ({percent}%)
+ Auto follows the system's text size. Pages always render at the display's full resolution. Auto segue la dimensione del testo del sistema. Le pagine vengono sempre visualizzate alla piena risoluzione dello schermo.
Identity Identità
Name on new comments Nome sui nuovi commenti
Open… Apri…
diff --git a/crates/ui-egui/src/i18n/ja.tsv b/crates/ui-egui/src/i18n/ja.tsv
index aec238538..6f57bfe43 100644
--- a/crates/ui-egui/src/i18n/ja.tsv
+++ b/crates/ui-egui/src/i18n/ja.tsv
@@ -24,6 +24,9 @@
Preferences 環境設定
Preferences… 環境設定…
Interface language 表示言語
+ Interface size 表示サイズ
+ Auto ({percent}%) 自動 ({percent}%)
+ Auto follows the system's text size. Pages always render at the display's full resolution. 自動にすると、システムの文字サイズに合わせます。ページは常にディスプレイの最大解像度で描画されます。
Identity 個人情報
Name on new comments 新しい注釈の作成者名
Open… 開く…
diff --git a/crates/ui-egui/src/i18n/pt-br.tsv b/crates/ui-egui/src/i18n/pt-br.tsv
index e40997548..73994df20 100644
--- a/crates/ui-egui/src/i18n/pt-br.tsv
+++ b/crates/ui-egui/src/i18n/pt-br.tsv
@@ -18,6 +18,9 @@
Preferences Preferências
Preferences… Preferências…
Interface language Idioma da interface
+ Interface size Tamanho da interface
+ Auto ({percent}%) Automático ({percent}%)
+ Auto follows the system's text size. Pages always render at the display's full resolution. Automático segue o tamanho do texto do sistema. As páginas sempre são exibidas na resolução total da tela.
Identity Identidade
Name on new comments Nome nos novos comentários
Open… Abrir…
diff --git a/crates/ui-egui/src/i18n/ru.tsv b/crates/ui-egui/src/i18n/ru.tsv
index 2b457fba0..39352d83b 100644
--- a/crates/ui-egui/src/i18n/ru.tsv
+++ b/crates/ui-egui/src/i18n/ru.tsv
@@ -17,6 +17,9 @@
Preferences Настройки
Preferences… Настройки…
Interface language Язык интерфейса
+ Interface size Размер интерфейса
+ Auto ({percent}%) Авто ({percent}%)
+ Auto follows the system's text size. Pages always render at the display's full resolution. В режиме «Авто» используется размер текста из настроек системы. Страницы всегда отображаются в полном разрешении экрана.
Identity Идентификация
Name on new comments Имя в новых комментариях
Open… Открыть…
diff --git a/crates/ui-egui/src/i18n/te.tsv b/crates/ui-egui/src/i18n/te.tsv
index 81e441f12..214c86828 100644
--- a/crates/ui-egui/src/i18n/te.tsv
+++ b/crates/ui-egui/src/i18n/te.tsv
@@ -22,6 +22,9 @@ comment menu Edit సవరించు
Preferences ప్రాధాన్యతలు
Preferences… ప్రాధాన్యతలు…
Interface language ఇంటర్‌ఫేస్ భాష
+ Interface size ఇంటర్‌ఫేస్ పరిమాణం
+ Auto ({percent}%) ఆటో ({percent}%)
+ Auto follows the system's text size. Pages always render at the display's full resolution. ఆటో సిస్టమ్ టెక్స్ట్ పరిమాణాన్ని అనుసరిస్తుంది. పేజీలు ఎల్లప్పుడూ డిస్‌ప్లే పూర్తి రిజల్యూషన్‌లో చూపబడతాయి.
Identity గుర్తింపు
Name on new comments కొత్త వ్యాఖ్యలపై చూపే పేరు
Open… తెరువు…
diff --git a/crates/ui-egui/src/i18n/uk.tsv b/crates/ui-egui/src/i18n/uk.tsv
index f28e3eebd..d2e04adf2 100644
--- a/crates/ui-egui/src/i18n/uk.tsv
+++ b/crates/ui-egui/src/i18n/uk.tsv
@@ -27,6 +27,9 @@
Preferences Налаштування
Preferences… Налаштування…
Interface language Мова інтерфейсу
+ Interface size Розмір інтерфейсу
+ Auto ({percent}%) Автоматично ({percent}%)
+ Auto follows the system's text size. Pages always render at the display's full resolution. Автоматичний режим використовує розмір тексту із системних налаштувань. Сторінки завжди відображаються в повній роздільній здатності екрана.
Identity Особисті дані
Name on new comments Ім’я в нових коментарях
Open… Відкрити…
diff --git a/crates/ui-egui/src/i18n/zh-hans.tsv b/crates/ui-egui/src/i18n/zh-hans.tsv
index cdd766d52..1e6aa98f1 100644
--- a/crates/ui-egui/src/i18n/zh-hans.tsv
+++ b/crates/ui-egui/src/i18n/zh-hans.tsv
@@ -58,6 +58,9 @@
Preferences 首选项
Preferences… 首选项…
Interface language 界面语言
+ Interface size 界面大小
+ Auto ({percent}%) 自动 ({percent}%)
+ Auto follows the system's text size. Pages always render at the display's full resolution. “自动”会跟随系统的文字大小。页面始终以显示器的完整分辨率渲染。
Identity 身份
Name on new comments 新注释的作者姓名
Open… 打开…
diff --git a/crates/ui-egui/src/i18n/zh-hant.tsv b/crates/ui-egui/src/i18n/zh-hant.tsv
index 481f7b960..c31592bd1 100644
--- a/crates/ui-egui/src/i18n/zh-hant.tsv
+++ b/crates/ui-egui/src/i18n/zh-hant.tsv
@@ -17,6 +17,9 @@
Preferences 偏好設定
Preferences… 偏好設定…
Interface language 介面語言
+ Interface size 介面大小
+ Auto ({percent}%) 自動 ({percent}%)
+ Auto follows the system's text size. Pages always render at the display's full resolution. 「自動」會跟隨系統的文字大小。頁面一律以螢幕的完整解析度呈現。
Identity 個人資訊
Name on new comments 新註解的作者名稱
Open… 開啟…
diff --git a/crates/ui-egui/src/js_ui.rs b/crates/ui-egui/src/js_ui.rs
index d285372b6..9f5ffdfa1 100644
--- a/crates/ui-egui/src/js_ui.rs
+++ b/crates/ui-egui/src/js_ui.rs
@@ -252,6 +252,30 @@ pub(crate) fn preferences_body(ui: &mut egui::Ui, app: &mut PdfCraftApp, t: &Tok
crate::i18n::set_current(crate::i18n::Lang::from_pref(&app.language));
}
});
+ ui.horizontal(|ui| {
+ use crate::ui_scale;
+ ui.label(tl!("Interface size"));
+ let auto =
+ crate::i18n::fmt(tl!("Auto ({percent}%)"), &[("percent", &ui_scale::percent(ui_scale::factor(None, app.system_text_scale)).to_string())]);
+ let selected = app.ui_scale.map_or_else(|| auto.clone(), |f| format!("{}%", ui_scale::percent(f)));
+ egui::ComboBox::from_id_salt("interface-size").selected_text(selected).show_ui(ui, |ui| {
+ if ui.selectable_value(&mut app.ui_scale, None, auto).clicked() {
+ ui.close();
+ }
+ for p in ui_scale::PRESETS {
+ let factor = f32::from(p) / 100.0;
+ if ui.selectable_label(app.ui_scale.is_some_and(|f| ui_scale::percent(f) == u32::from(p)), format!("{p}%")).clicked() {
+ app.ui_scale = Some(factor);
+ ui.close();
+ }
+ }
+ });
+ });
+ ui.label(
+ egui::RichText::new(tl!("Auto follows the system's text size. Pages always render at the display's full resolution."))
+ .small()
+ .color(t.text_muted),
+ );
ui.add_space(8.0);
ui.label(egui::RichText::new(tl!("Documents and view")).font(theme::semibold(13.0)));
ui.horizontal(|ui| {
diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs
index 70e14a8d8..62b4c1be8 100644
--- a/crates/ui-egui/src/lib.rs
+++ b/crates/ui-egui/src/lib.rs
@@ -111,6 +111,7 @@ mod recovery;
#[cfg(not(target_arch = "wasm32"))]
mod system_fonts;
pub mod theme;
+pub mod ui_scale;
pub mod updates;
mod wheel_pager;
mod widgets;
@@ -412,6 +413,13 @@ pub struct PdfCraftApp {
desktop_dark: Option<bool>,
/// Interface language preference: `auto` (follow the system) or a code from [`i18n::LANGUAGES`].
pub language: String,
+ /// Preferences ▸ Interface size as a factor, or `None` to follow [`Self::system_text_scale`].
+ pub ui_scale: Option<f32>,
+ /// The desktop's text scaling (GNOME's text scaling factor), which the desktop app reads at
+ /// launch. 1.0 elsewhere, so tests and screenshots don't depend on the machine.
+ pub system_text_scale: f32,
+ /// The interface size last given to egui ([`ui_scale::sync`]).
+ ui_scale_applied: Option<f32>,
/// Preferences: bake Fill & Sign marks into the page when saving. Off, so a normal save stays editable.
pub flatten_fill_sign_on_save: bool,
pub dialog: Option<Dialog>,
@@ -709,6 +717,9 @@ impl PdfCraftApp {
desktop_theme: pdfcraft_platform::desktop_theme::DesktopTheme::start(),
desktop_dark: None,
language: i18n::AUTO.to_string(),
+ ui_scale: None,
+ system_text_scale: 1.0,
+ ui_scale_applied: None,
flatten_fill_sign_on_save: false,
dialog: None,
update_source: None,
@@ -1361,6 +1372,8 @@ impl PdfCraftApp {
"default_zoom": self.view_defaults.zoom_name(),
"highlight_fields": self.view_defaults.highlight_fields,
"language": self.language,
+ // Null follows the system's text scaling.
+ "ui_scale": self.ui_scale,
"flatten_fill_sign": self.flatten_fill_sign_on_save,
"date_format": self.session.date_format(),
// Null follows the interface language.
@@ -1443,6 +1456,8 @@ impl PdfCraftApp {
if let Some(on) = v["flatten_fill_sign"].as_bool() {
self.flatten_fill_sign_on_save = on;
}
+ // Settings are untrusted: a size out of range follows the system instead.
+ self.ui_scale = v["ui_scale"].as_f64().and_then(ui_scale::valid);
// Settings are untrusted: an unusable pattern keeps the default.
if let Some(f) = v["date_format"].as_str() {
let _ = self.session.set_date_format(f);
@@ -1726,6 +1741,7 @@ impl PdfCraftApp {
};
}
("author", _) => self.comment_prefs.author = value.to_string(),
+ ("ui-scale", _) => self.ui_scale = ui_scale::parse(value)?,
("flatten-fill-sign", _) => {
self.flatten_fill_sign_on_save = match value {
"true" => true,
@@ -1887,6 +1903,7 @@ impl eframe::App for PdfCraftApp {
}
}
self.sync_theme(ctx);
+ ui_scale::sync(ctx, ui_scale::factor(self.ui_scale, self.system_text_scale), &mut self.ui_scale_applied);
// Remember user work even if its tab is subsequently closed or Home is selected.
self.startup_superseded |= !self.views.is_empty() || self.combine_showing() || self.dialog.is_some() || self.password_prompt.is_some();
// Before taking this frame's drop: the grid must be drawn once with the pointer where
diff --git a/crates/ui-egui/src/ui_scale.rs b/crates/ui-egui/src/ui_scale.rs
new file mode 100644
index 000000000..2637a0e05
--- /dev/null
+++ b/crates/ui-egui/src/ui_scale.rs
@@ -0,0 +1,121 @@
+//! Preferences ▸ Interface size: how large the interface is drawn, on top of the display's own
+//! scale. `Auto` follows the desktop's text scaling (GNOME's "Large Text" or text scaling factor,
+//! which the desktop app reads at launch), so PdfCraft's labels match the other apps' instead of
+//! staying small and showing their pixels on a 1× display.
+//!
+//! The scale is egui's zoom factor: `pixels_per_point` grows with it, so page rasters, which are
+//! rendered at `pixels_per_point` (`canvas::render_scale`), stay one texel per screen pixel.
+
+/// The smallest and largest interface sizes, as factors.
+pub const MIN: f32 = 0.5;
+pub const MAX: f32 = 3.0;
+
+/// The sizes the Preferences menu offers, in percent.
+pub const PRESETS: [u16; 10] = [50, 75, 90, 100, 110, 125, 150, 175, 200, 250];
+
+/// A factor from settings, the control channel or the system: finite and within [`MIN`]..=[`MAX`],
+/// or `None`.
+pub fn valid(factor: f64) -> Option<f32> {
+ let factor = factor as f32;
+ (factor.is_finite() && (MIN..=MAX).contains(&factor)).then_some(factor)
+}
+
+/// The factor to draw at: the preference, or the system's text scale when it is `Auto` (`None`).
+pub fn factor(preference: Option<f32>, system: f32) -> f32 {
+ preference.or_else(|| valid(f64::from(system))).unwrap_or(1.0)
+}
+
+/// Parse a control-channel value: `auto`, or a percentage such as `125` or `125%`.
+pub fn parse(value: &str) -> Result<Option<f32>, String> {
+ let value = value.trim();
+ if value.eq_ignore_ascii_case("auto") {
+ return Ok(None);
+ }
+ let percent: f64 = value.trim_end_matches('%').trim().parse().map_err(|_| format!("ui-scale must be auto or a percentage, not {value}"))?;
+ valid(percent / 100.0).map(Some).ok_or_else(|| format!("ui-scale must be between {}% and {}%", (MIN * 100.0).round(), (MAX * 100.0).round()))
+}
+
+/// The percentage a factor shows as.
+pub fn percent(factor: f32) -> u32 {
+ // In MIN..=MAX (every factor here went through `valid`, or is 1.0), so the cast can't overflow.
+ (factor * 100.0).round().clamp(0.0, 1000.0) as u32
+}
+
+/// Draw at `factor` from the next frame on, when it differs from the factor last applied
+/// (`applied`), so a zoom set elsewhere (a test harness's `pixels_per_point`) isn't undone every
+/// frame. egui's own ⌘+/⌘−/⌘0 interface zoom stays off: those keys zoom the page, and the
+/// preference alone decides the interface size.
+pub fn sync(ctx: &egui::Context, factor: f32, applied: &mut Option<f32>) {
+ if applied.is_none() {
+ ctx.options_mut(|o| o.zoom_with_keyboard = false);
+ }
+ if *applied != Some(factor) {
+ ctx.set_zoom_factor(factor);
+ *applied = Some(factor);
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn auto_follows_a_usable_system_scale_only() {
+ assert_eq!(factor(None, 1.25), 1.25);
+ assert_eq!(factor(Some(1.5), 1.25), 1.5);
+ for system in [f32::NAN, f32::INFINITY, -1.0, 0.0, 0.1, 40.0] {
+ assert_eq!(factor(None, system), 1.0, "{system}");
+ }
+ }
+
+ #[test]
+ fn control_values_parse_or_say_what_is_allowed() {
+ assert_eq!(parse("auto"), Ok(None));
+ assert_eq!(parse(" AUTO "), Ok(None));
+ assert_eq!(parse("125"), Ok(Some(1.25)));
+ assert_eq!(parse("150%"), Ok(Some(1.5)));
+ for bad in ["", "big", "10", "1000", "NaN", "inf", "-125"] {
+ assert!(parse(bad).is_err(), "{bad}");
+ }
+ for p in PRESETS {
+ assert_eq!(parse(&p.to_string()).map(|f| f.map(percent)), Ok(Some(u32::from(p))));
+ }
+ }
+
+ #[test]
+ fn sync_sets_the_zoom_and_turns_off_keyboard_zoom() {
+ let ctx = egui::Context::default();
+ let mut applied = None;
+ sync(&ctx, 1.25, &mut applied);
+ assert_eq!(applied, Some(1.25));
+ // A bare context's first frame uploads the font atlas; nothing paints it here.
+ ctx.run_ui(egui::RawInput::default(), |_| {}).textures_delta.clear();
+ assert_eq!(ctx.zoom_factor(), 1.25);
+ assert!(!ctx.options(|o| o.zoom_with_keyboard));
+ }
+
+ #[test]
+ fn the_app_draws_at_the_system_scale_until_a_size_is_chosen() {
+ let mut h = egui_kittest::Harness::builder().with_size(egui::vec2(1000.0, 700.0)).with_pixels_per_point(1.0).build_eframe(|_cc| {
+ let mut app = crate::PdfCraftApp::new();
+ app.system_text_scale = 1.25;
+ app
+ });
+ h.run_steps(3);
+ assert_eq!(h.ctx.pixels_per_point(), 1.25, "Auto follows the system's text scale");
+ h.state_mut().set_option("ui-scale", "150%").expect("a valid size");
+ h.run_steps(3);
+ assert_eq!(h.ctx.pixels_per_point(), 1.5);
+ assert!(h.state_mut().set_option("ui-scale", "5000").is_err());
+ // The chosen size survives a restart; a hostile one in the settings follows the system.
+ let saved = h.state().persist();
+ let mut restored = crate::PdfCraftApp::new();
+ restored.restore(&saved);
+ assert_eq!(restored.ui_scale, Some(1.5));
+ restored.restore(&saved.replace("\"ui_scale\":1.5", "\"ui_scale\":1e30"));
+ assert_eq!(restored.ui_scale, None);
+ h.state_mut().set_option("ui-scale", "auto").expect("auto");
+ h.run_steps(3);
+ assert_eq!(h.ctx.pixels_per_point(), 1.25);
+ }
+}