mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
fix: fall back to default DPI when GTK returns 0 on Linux (#50490)
GetDefaultPrinterDPI() creates a blank GtkPrintSettings and reads its resolution, which returns 0 for uninitialized settings. With DPI=0, SetPrintableAreaIfValid() computes a zero scale factor, producing empty page dimensions that fail PrintMsgPrintParamsIsValid(). Fall back to kDefaultPdfDpi (72) when GTK returns 0, matching the existing Windows fallback pattern when CreateDC fails. Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
This commit is contained in:
@@ -59,6 +59,8 @@ gfx::Size GetDefaultPrinterDPI(const std::u16string& device_name) {
|
||||
GtkPrintSettings* print_settings = gtk_print_settings_new();
|
||||
int dpi = gtk_print_settings_get_resolution(print_settings);
|
||||
g_object_unref(print_settings);
|
||||
if (dpi <= 0)
|
||||
dpi = printing::kDefaultPdfDpi;
|
||||
return {dpi, dpi};
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user