mirror of
https://github.com/electron/electron.git
synced 2026-05-02 03:00:22 -04:00
feat: allow defaulting to printer default page size (#49523)
Co-authored-by: Edvan de Matos <edvan.santos@querodelivery.com>
This commit is contained in:
@@ -191,4 +191,33 @@ scoped_refptr<base::TaskRunner> CreatePrinterHandlerTaskRunner() {
|
||||
#endif
|
||||
}
|
||||
|
||||
std::optional<gfx::Size> GetPrinterDefaultPaperSize(
|
||||
const std::string& printer_name) {
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
// Blocking is needed here because Windows printer drivers are oftentimes
|
||||
// not thread-safe and have to be accessed on the UI thread.
|
||||
ScopedAllowBlockingForElectron allow_blocking;
|
||||
#endif
|
||||
|
||||
if (printer_name.empty())
|
||||
return std::nullopt;
|
||||
|
||||
scoped_refptr<printing::PrintBackend> print_backend =
|
||||
printing::PrintBackend::CreateInstance(
|
||||
g_browser_process->GetApplicationLocale());
|
||||
|
||||
if (!print_backend)
|
||||
return std::nullopt;
|
||||
|
||||
printing::PrinterSemanticCapsAndDefaults caps;
|
||||
printing::mojom::ResultCode result =
|
||||
print_backend->GetPrinterSemanticCapsAndDefaults(printer_name, &caps);
|
||||
if (result != printing::mojom::ResultCode::kSuccess)
|
||||
return std::nullopt;
|
||||
|
||||
if (!caps.default_paper.size_um().IsEmpty())
|
||||
return caps.default_paper.size_um();
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
} // namespace electron
|
||||
|
||||
@@ -44,6 +44,11 @@ std::pair<std::string, std::u16string> GetDeviceNameToUse(
|
||||
// This function creates a task runner for use with printing tasks.
|
||||
scoped_refptr<base::TaskRunner> CreatePrinterHandlerTaskRunner();
|
||||
|
||||
// This function returns the default paper size of the specified printer, if
|
||||
// available.
|
||||
std::optional<gfx::Size> GetPrinterDefaultPaperSize(
|
||||
const std::string& printer_name);
|
||||
|
||||
} // namespace electron
|
||||
|
||||
#endif // ELECTRON_SHELL_BROWSER_PRINTING_PRINTING_UTILS_H_
|
||||
|
||||
Reference in New Issue
Block a user