From 3f3598da186e9dccadfe23259fffc149ee4ee643 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Thu, 20 Aug 2020 10:27:16 -0700 Subject: [PATCH 1/8] fix: honor pageRanges on macOS --- docs/api/web-contents.md | 14 ++--- docs/api/webview-tag.md | 12 ++-- patches/chromium/.patches | 1 + ..._properly_honor_print_range_on_macos.patch | 63 +++++++++++++++++++ .../browser/api/electron_api_web_contents.cc | 5 +- 5 files changed, 80 insertions(+), 15 deletions(-) create mode 100644 patches/chromium/fix_properly_honor_print_range_on_macos.patch diff --git a/docs/api/web-contents.md b/docs/api/web-contents.md index a989b7a4a4b76..a7d8e7230c940 100644 --- a/docs/api/web-contents.md +++ b/docs/api/web-contents.md @@ -1296,9 +1296,9 @@ Returns [`PrinterInfo[]`](structures/printer-info.md) * `pagesPerSheet` Number (optional) - The number of pages to print per page sheet. * `collate` Boolean (optional) - Whether the web page should be collated. * `copies` Number (optional) - The number of copies of the web page to print. - * `pageRanges` Record (optional) - The page range to print. - * `from` Number - the start page. - * `to` Number - the end page. + * `pageRanges` Object[] (optional) - The page range to print. On macOS, only one range is honored. + * `from` Number - Index of the first page to print (0-based). + * `to` Number - Index of the last page to print (inclusive) (0-based). * `duplexMode` String (optional) - Set the duplex mode of the printed web page. Can be `simplex`, `shortEdge`, or `longEdge`. * `dpi` Record (optional) * `horizontal` Number (optional) - The horizontal dpi. @@ -1324,10 +1324,10 @@ Example usage: const options = { silent: true, deviceName: 'My-Printer', - pageRanges: { + pageRanges: [{ from: 0, to: 1 - } + }] } win.webContents.print(options, (success, errorType) => { if (!success) console.log(errorType) @@ -1345,8 +1345,8 @@ win.webContents.print(options, (success, errorType) => { default margin, 1 for no margin, and 2 for minimum margin. * `scaleFactor` Number (optional) - The scale factor of the web page. Can range from 0 to 100. * `pageRanges` Record (optional) - The page range to print. - * `from` Number - zero-based index of the first page to print. - * `to` Number - zero-based index of the last page to print (inclusive). + * `from` Number - Index of the first page to print (0-based). + * `to` Number - Index of the last page to print (inclusive) (0-based). * `pageSize` String | Size (optional) - Specify page size of the generated PDF. Can be `A3`, `A4`, `A5`, `Legal`, `Letter`, `Tabloid` or an Object containing `height` and `width` in microns. * `printBackground` Boolean (optional) - Whether to print CSS backgrounds. diff --git a/docs/api/webview-tag.md b/docs/api/webview-tag.md index 65d3c2284d7f1..05325fe7cf543 100644 --- a/docs/api/webview-tag.md +++ b/docs/api/webview-tag.md @@ -560,9 +560,9 @@ Stops any `findInPage` request for the `webview` with the provided `action`. * `pagesPerSheet` Number (optional) - The number of pages to print per page sheet. * `collate` Boolean (optional) - Whether the web page should be collated. * `copies` Number (optional) - The number of copies of the web page to print. - * `pageRanges` Record (optional) - The page range to print. - * `from` Number - zero-based index of the first page to print. - * `to` Number - zero-based index of the last page to print (inclusive). + * `pageRanges` Object[] (optional) - The page range to print. + * `from` Number - Index of the first page to print (1-based). + * `to` Number - Index of the last page to print (inclusive) (1-based). * `duplexMode` String (optional) - Set the duplex mode of the printed web page. Can be `simplex`, `shortEdge`, or `longEdge`. * `dpi` Record (optional) * `horizontal` Number (optional) - The horizontal dpi. @@ -587,9 +587,9 @@ Prints `webview`'s web page. Same as `webContents.print([options])`. default margin, 1 for no margin, and 2 for minimum margin. and `width` in microns. * `scaleFactor` Number (optional) - The scale factor of the web page. Can range from 0 to 100. - * `pageRanges` Record (optional) - The page range to print. - * `from` Number - the first page to print. - * `to` Number - the last page to print (inclusive). + * `pageRanges` Record (optional) - The page range to print. On macOS, only the first range is honored. + * `from` Number - Index of the first page to print (0-based). + * `to` Number - Index of the last page to print (inclusive) (0-based). * `pageSize` String | Size (optional) - Specify page size of the generated PDF. Can be `A3`, `A4`, `A5`, `Legal`, `Letter`, `Tabloid` or an Object containing `height` * `printBackground` Boolean (optional) - Whether to print CSS backgrounds. diff --git a/patches/chromium/.patches b/patches/chromium/.patches index e43f9e4ab97ef..da29395218d2f 100644 --- a/patches/chromium/.patches +++ b/patches/chromium/.patches @@ -100,3 +100,4 @@ remove_some_deps_that_do_not_work_on_arm64.patch fix_check_issecureeventinputenabled_in_constructor_before_setting.patch skip_atk_toolchain_check.patch worker_feat_add_hook_to_notify_script_ready.patch +fix_properly_honor_print_range_on_macos.patch diff --git a/patches/chromium/fix_properly_honor_print_range_on_macos.patch b/patches/chromium/fix_properly_honor_print_range_on_macos.patch new file mode 100644 index 0000000000000..31a081c6a566d --- /dev/null +++ b/patches/chromium/fix_properly_honor_print_range_on_macos.patch @@ -0,0 +1,63 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Shelley Vohr +Date: Thu, 20 Aug 2020 10:55:48 -0700 +Subject: fix: properly honor print range on macOS + +The print ranges in Chromium's print job settings were not being properly +plumbed through to PMPrintSettings on mcOS. This fixes that by setting +them should they exist. + +This will be upstreamed. + +diff --git a/printing/printing_context_mac.h b/printing/printing_context_mac.h +index 06cdc0e1a4a50e29a148c97c964c30a939e800da..5db5cdb61be0beee4506313dcde46c499e011383 100644 +--- a/printing/printing_context_mac.h ++++ b/printing/printing_context_mac.h +@@ -81,6 +81,10 @@ class PRINTING_EXPORT PrintingContextMac : public PrintingContext { + // Returns true if the orientation was set. + bool SetOrientationIsLandscape(bool landscape); + ++ // Set the page range in native print info object. ++ // Returns true if the range was set. ++ bool SetPrintRangeInPrintSettings(const PageRanges& ranges); ++ + // Sets duplex mode in PMPrintSettings. + // Returns true if duplex mode is set. + bool SetDuplexModeInPrintSettings(mojom::DuplexMode mode); +diff --git a/printing/printing_context_mac.mm b/printing/printing_context_mac.mm +index 56bcfbe625537c7b1bc2a999c261836bb15896ba..3965b877718160ce55e7c97d75e8992f45ac3f2f 100644 +--- a/printing/printing_context_mac.mm ++++ b/printing/printing_context_mac.mm +@@ -188,7 +188,8 @@ PMPaper MatchPaper(CFArrayRef paper_list, + !SetCopiesInPrintSettings(settings_->copies()) || + !SetCollateInPrintSettings(settings_->collate()) || + !SetDuplexModeInPrintSettings(settings_->duplex_mode()) || +- !SetOutputColor(settings_->color())) { ++ !SetOutputColor(settings_->color()) || ++ !SetPrintRangeInPrintSettings(settings_->ranges()) ) { + return OnError(); + } + } +@@ -341,6 +342,22 @@ PMPaper MatchPaper(CFArrayRef paper_list, + return PMSetCopies(print_settings, copies, false) == noErr; + } + ++bool PrintingContextMac::SetPrintRangeInPrintSettings(const PageRanges& ranges) { ++ // Default is already NSPrintAllPages - we can safely bail. ++ if (ranges.empty()) ++ return true; ++ ++ auto print_settings = ++ static_cast([print_info_.get() PMPrintSettings]); ++ ++ // macOS does not allow multiple ranges, so pluck the first. ++ auto range = ranges.front(); ++ bool set_first_page = PMSetFirstPage(print_settings, range.from + 1, false) == noErr; ++ bool set_last_page = PMSetLastPage(print_settings, range.to + 1, false) == noErr; ++ ++ return set_first_page && set_last_page; ++} ++ + bool PrintingContextMac::SetCollateInPrintSettings(bool collate) { + PMPrintSettings print_settings = + static_cast([print_info_.get() PMPrintSettings]); diff --git a/shell/browser/api/electron_api_web_contents.cc b/shell/browser/api/electron_api_web_contents.cc index fee2dcf38cfd9..be9153e0956e0 100644 --- a/shell/browser/api/electron_api_web_contents.cc +++ b/shell/browser/api/electron_api_web_contents.cc @@ -2068,8 +2068,9 @@ void WebContents::Print(gin::Arguments* args) { int from, to; if (range.Get("from", &from) && range.Get("to", &to)) { base::Value range(base::Value::Type::DICTIONARY); - range.SetIntKey(printing::kSettingPageRangeFrom, from); - range.SetIntKey(printing::kSettingPageRangeTo, to); + // Chromium uses 1-based page ranges, so increment each by 1. + range.SetIntKey(printing::kSettingPageRangeFrom, from + 1); + range.SetIntKey(printing::kSettingPageRangeTo, to + 1); page_range_list.Append(std::move(range)); } else { continue; From a3973b07abb3bc663ece1e9fa322752796c0c868 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Thu, 20 Aug 2020 20:00:32 -0700 Subject: [PATCH 2/8] Honor ranges on Linux --- docs/api/webview-tag.md | 4 +-- patches/chromium/.patches | 2 +- ...properly_honor_printing_page_ranges.patch} | 31 +++++++++++++++++-- 3 files changed, 32 insertions(+), 5 deletions(-) rename patches/chromium/{fix_properly_honor_print_range_on_macos.patch => fix_properly_honor_printing_page_ranges.patch} (67%) diff --git a/docs/api/webview-tag.md b/docs/api/webview-tag.md index 05325fe7cf543..24ad92211dacb 100644 --- a/docs/api/webview-tag.md +++ b/docs/api/webview-tag.md @@ -561,8 +561,8 @@ Stops any `findInPage` request for the `webview` with the provided `action`. * `collate` Boolean (optional) - Whether the web page should be collated. * `copies` Number (optional) - The number of copies of the web page to print. * `pageRanges` Object[] (optional) - The page range to print. - * `from` Number - Index of the first page to print (1-based). - * `to` Number - Index of the last page to print (inclusive) (1-based). + * `from` Number - Index of the first page to print (0-based). + * `to` Number - Index of the last page to print (inclusive) (0-based). * `duplexMode` String (optional) - Set the duplex mode of the printed web page. Can be `simplex`, `shortEdge`, or `longEdge`. * `dpi` Record (optional) * `horizontal` Number (optional) - The horizontal dpi. diff --git a/patches/chromium/.patches b/patches/chromium/.patches index da29395218d2f..453f128b6b4d7 100644 --- a/patches/chromium/.patches +++ b/patches/chromium/.patches @@ -100,4 +100,4 @@ remove_some_deps_that_do_not_work_on_arm64.patch fix_check_issecureeventinputenabled_in_constructor_before_setting.patch skip_atk_toolchain_check.patch worker_feat_add_hook_to_notify_script_ready.patch -fix_properly_honor_print_range_on_macos.patch +fix_properly_honor_printing_page_ranges.patch diff --git a/patches/chromium/fix_properly_honor_print_range_on_macos.patch b/patches/chromium/fix_properly_honor_printing_page_ranges.patch similarity index 67% rename from patches/chromium/fix_properly_honor_print_range_on_macos.patch rename to patches/chromium/fix_properly_honor_printing_page_ranges.patch index 31a081c6a566d..235bd924e33b6 100644 --- a/patches/chromium/fix_properly_honor_print_range_on_macos.patch +++ b/patches/chromium/fix_properly_honor_printing_page_ranges.patch @@ -1,7 +1,7 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Thu, 20 Aug 2020 10:55:48 -0700 -Subject: fix: properly honor print range on macOS +Subject: fix: properly honor printing page ranges The print ranges in Chromium's print job settings were not being properly plumbed through to PMPrintSettings on mcOS. This fixes that by setting @@ -25,7 +25,7 @@ index 06cdc0e1a4a50e29a148c97c964c30a939e800da..5db5cdb61be0beee4506313dcde46c49 // Returns true if duplex mode is set. bool SetDuplexModeInPrintSettings(mojom::DuplexMode mode); diff --git a/printing/printing_context_mac.mm b/printing/printing_context_mac.mm -index 56bcfbe625537c7b1bc2a999c261836bb15896ba..3965b877718160ce55e7c97d75e8992f45ac3f2f 100644 +index 56bcfbe625537c7b1bc2a999c261836bb15896ba..849e35a5a862921fafc1580496063f4bd1aa0fb5 100644 --- a/printing/printing_context_mac.mm +++ b/printing/printing_context_mac.mm @@ -188,7 +188,8 @@ PMPaper MatchPaper(CFArrayRef paper_list, @@ -61,3 +61,30 @@ index 56bcfbe625537c7b1bc2a999c261836bb15896ba..3965b877718160ce55e7c97d75e8992f bool PrintingContextMac::SetCollateInPrintSettings(bool collate) { PMPrintSettings print_settings = static_cast([print_info_.get() PMPrintSettings]); +diff --git a/ui/gtk/printing/print_dialog_gtk.cc b/ui/gtk/printing/print_dialog_gtk.cc +index 8a78a609295a1d90208bdc7e73d7a850c319f361..8efbbfb31eac99323be5e81826d5738b2390a82d 100644 +--- a/ui/gtk/printing/print_dialog_gtk.cc ++++ b/ui/gtk/printing/print_dialog_gtk.cc +@@ -239,6 +239,22 @@ void PrintDialogGtk::UpdateSettings( + + gtk_print_settings_set_n_copies(gtk_settings_, settings->copies()); + gtk_print_settings_set_collate(gtk_settings_, settings->collate()); ++ ++ auto print_ranges = settings->ranges(); ++ if (!print_ranges.empty()) { ++ // Tell the system that we only intend to print a subset of pages. ++ gtk_print_settings_set_print_pages(gtk_settings_, GTK_PRINT_PAGES_RANGES); ++ ++ GtkPageRange* ranges; ++ ranges = g_new (GtkPageRange, print_ranges.size()); ++ for (size_t i = 0; i < print_ranges.size(); i++) { ++ auto range = print_ranges[i]; ++ ranges[i].start = range.from; ++ ranges[i].end = range.to; ++ } ++ ++ gtk_print_settings_set_page_ranges(gtk_settings_, ranges, 1); ++ } + + #if defined(USE_CUPS) + // Set advanced settings first so they can be overridden by user applied From 099382eb31afca34220a87cbf0ef77eaa0dc217b Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Thu, 20 Aug 2020 23:02:23 -0700 Subject: [PATCH 3/8] Honor page ranges on Windows --- ..._properly_honor_printing_page_ranges.patch | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/patches/chromium/fix_properly_honor_printing_page_ranges.patch b/patches/chromium/fix_properly_honor_printing_page_ranges.patch index 235bd924e33b6..555fed4136ace 100644 --- a/patches/chromium/fix_properly_honor_printing_page_ranges.patch +++ b/patches/chromium/fix_properly_honor_printing_page_ranges.patch @@ -47,7 +47,7 @@ index 56bcfbe625537c7b1bc2a999c261836bb15896ba..849e35a5a862921fafc1580496063f4b + if (ranges.empty()) + return true; + -+ auto print_settings = ++ auto* print_settings = + static_cast([print_info_.get() PMPrintSettings]); + + // macOS does not allow multiple ranges, so pluck the first. @@ -61,6 +61,41 @@ index 56bcfbe625537c7b1bc2a999c261836bb15896ba..849e35a5a862921fafc1580496063f4b bool PrintingContextMac::SetCollateInPrintSettings(bool collate) { PMPrintSettings print_settings = static_cast([print_info_.get() PMPrintSettings]); +diff --git a/printing/printing_context_system_dialog_win.cc b/printing/printing_context_system_dialog_win.cc +index d3c8677f30d72efc49b28f293260c74c7b8d8b4e..73744c03eae91687a9229ebc2249a55fdf30e4bb 100644 +--- a/printing/printing_context_system_dialog_win.cc ++++ b/printing/printing_context_system_dialog_win.cc +@@ -52,14 +52,25 @@ void PrintingContextSystemDialogWin::AskUserForSettings( + PRINTPAGERANGE ranges[32]; + dialog_options.nStartPage = START_PAGE_GENERAL; + if (max_pages) { +- // Default initialize to print all the pages. + memset(ranges, 0, sizeof(ranges)); +- ranges[0].nFromPage = 1; +- ranges[0].nToPage = max_pages; +- dialog_options.nPageRanges = 1; +- dialog_options.nMaxPageRanges = base::size(ranges); ++ ++ auto page_ranges = settings_->ranges(); ++ if (!page_ranges.empty()) { ++ for (size_t i = 0; i < page_ranges.size(); i++) { ++ auto range = page_ranges[i]; ++ ranges[i].nFromPage = range.from; ++ ranges[i].nToPage = range.to; ++ } ++ dialog_options.nPageRanges = page_ranges.size(); ++ } else { ++ ranges[0].nFromPage = 1; ++ ranges[0].nToPage = max_pages; ++ dialog_options.nPageRanges = 1; ++ } ++ + dialog_options.nMinPage = 1; + dialog_options.nMaxPage = max_pages; ++ dialog_options.nMaxPageRanges = base::size(ranges); + dialog_options.lpPageRanges = ranges; + } else { + // No need to bother, we don't know how many pages are available. diff --git a/ui/gtk/printing/print_dialog_gtk.cc b/ui/gtk/printing/print_dialog_gtk.cc index 8a78a609295a1d90208bdc7e73d7a850c319f361..8efbbfb31eac99323be5e81826d5738b2390a82d 100644 --- a/ui/gtk/printing/print_dialog_gtk.cc From f6818cc6a556c0df6a12436a3d7f9c06365b1990 Mon Sep 17 00:00:00 2001 From: Electron Bot Date: Fri, 21 Aug 2020 15:49:07 +0000 Subject: [PATCH 4/8] update patches --- .../chromium/fix_properly_honor_printing_page_ranges.patch | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/patches/chromium/fix_properly_honor_printing_page_ranges.patch b/patches/chromium/fix_properly_honor_printing_page_ranges.patch index 555fed4136ace..275d6bf0b7013 100644 --- a/patches/chromium/fix_properly_honor_printing_page_ranges.patch +++ b/patches/chromium/fix_properly_honor_printing_page_ranges.patch @@ -25,7 +25,7 @@ index 06cdc0e1a4a50e29a148c97c964c30a939e800da..5db5cdb61be0beee4506313dcde46c49 // Returns true if duplex mode is set. bool SetDuplexModeInPrintSettings(mojom::DuplexMode mode); diff --git a/printing/printing_context_mac.mm b/printing/printing_context_mac.mm -index 56bcfbe625537c7b1bc2a999c261836bb15896ba..849e35a5a862921fafc1580496063f4bd1aa0fb5 100644 +index 56bcfbe625537c7b1bc2a999c261836bb15896ba..f916e78de99b87e0dae4f5f87329886b658ccd93 100644 --- a/printing/printing_context_mac.mm +++ b/printing/printing_context_mac.mm @@ -188,7 +188,8 @@ PMPaper MatchPaper(CFArrayRef paper_list, @@ -62,7 +62,7 @@ index 56bcfbe625537c7b1bc2a999c261836bb15896ba..849e35a5a862921fafc1580496063f4b PMPrintSettings print_settings = static_cast([print_info_.get() PMPrintSettings]); diff --git a/printing/printing_context_system_dialog_win.cc b/printing/printing_context_system_dialog_win.cc -index d3c8677f30d72efc49b28f293260c74c7b8d8b4e..73744c03eae91687a9229ebc2249a55fdf30e4bb 100644 +index d3c8677f30d72efc49b28f293260c74c7b8d8b4e..bacc24388e0159a83c4ed5e03b104e1115dd9713 100644 --- a/printing/printing_context_system_dialog_win.cc +++ b/printing/printing_context_system_dialog_win.cc @@ -52,14 +52,25 @@ void PrintingContextSystemDialogWin::AskUserForSettings( From a3af1b9223ea5d960e88a9fb311017f3e349c279 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Tue, 25 Aug 2020 08:28:20 -0700 Subject: [PATCH 5/8] Address review feedback --- docs/api/webview-tag.md | 4 ++-- .../chromium/fix_properly_honor_printing_page_ranges.patch | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/docs/api/webview-tag.md b/docs/api/webview-tag.md index 24ad92211dacb..b202a9bc2b65a 100644 --- a/docs/api/webview-tag.md +++ b/docs/api/webview-tag.md @@ -560,7 +560,7 @@ Stops any `findInPage` request for the `webview` with the provided `action`. * `pagesPerSheet` Number (optional) - The number of pages to print per page sheet. * `collate` Boolean (optional) - Whether the web page should be collated. * `copies` Number (optional) - The number of copies of the web page to print. - * `pageRanges` Object[] (optional) - The page range to print. + * `pageRanges` Object[] (optional) - The page range to print. * `from` Number - Index of the first page to print (0-based). * `to` Number - Index of the last page to print (inclusive) (0-based). * `duplexMode` String (optional) - Set the duplex mode of the printed web page. Can be `simplex`, `shortEdge`, or `longEdge`. @@ -587,7 +587,7 @@ Prints `webview`'s web page. Same as `webContents.print([options])`. default margin, 1 for no margin, and 2 for minimum margin. and `width` in microns. * `scaleFactor` Number (optional) - The scale factor of the web page. Can range from 0 to 100. - * `pageRanges` Record (optional) - The page range to print. On macOS, only the first range is honored. + * `pageRanges` Object[] (optional) - The page range to print. On macOS, only the first range is honored. * `from` Number - Index of the first page to print (0-based). * `to` Number - Index of the last page to print (inclusive) (0-based). * `pageSize` String | Size (optional) - Specify page size of the generated PDF. Can be `A3`, diff --git a/patches/chromium/fix_properly_honor_printing_page_ranges.patch b/patches/chromium/fix_properly_honor_printing_page_ranges.patch index 275d6bf0b7013..453b49bc199d9 100644 --- a/patches/chromium/fix_properly_honor_printing_page_ranges.patch +++ b/patches/chromium/fix_properly_honor_printing_page_ranges.patch @@ -100,7 +100,7 @@ diff --git a/ui/gtk/printing/print_dialog_gtk.cc b/ui/gtk/printing/print_dialog_ index 8a78a609295a1d90208bdc7e73d7a850c319f361..8efbbfb31eac99323be5e81826d5738b2390a82d 100644 --- a/ui/gtk/printing/print_dialog_gtk.cc +++ b/ui/gtk/printing/print_dialog_gtk.cc -@@ -239,6 +239,22 @@ void PrintDialogGtk::UpdateSettings( +@@ -239,6 +239,23 @@ void PrintDialogGtk::UpdateSettings( gtk_print_settings_set_n_copies(gtk_settings_, settings->copies()); gtk_print_settings_set_collate(gtk_settings_, settings->collate()); @@ -111,7 +111,7 @@ index 8a78a609295a1d90208bdc7e73d7a850c319f361..8efbbfb31eac99323be5e81826d5738b + gtk_print_settings_set_print_pages(gtk_settings_, GTK_PRINT_PAGES_RANGES); + + GtkPageRange* ranges; -+ ranges = g_new (GtkPageRange, print_ranges.size()); ++ ranges = g_new(GtkPageRange, print_ranges.size()); + for (size_t i = 0; i < print_ranges.size(); i++) { + auto range = print_ranges[i]; + ranges[i].start = range.from; @@ -119,6 +119,7 @@ index 8a78a609295a1d90208bdc7e73d7a850c319f361..8efbbfb31eac99323be5e81826d5738b + } + + gtk_print_settings_set_page_ranges(gtk_settings_, ranges, 1); ++ g_free(ranges); + } #if defined(USE_CUPS) From a436c2c21d0e3ba16c43e7a09ad792a83fa0be17 Mon Sep 17 00:00:00 2001 From: Electron Bot Date: Tue, 25 Aug 2020 15:42:39 +0000 Subject: [PATCH 6/8] update patches --- docs/api/webview-tag.md | 2 +- patches/chromium/fix_properly_honor_printing_page_ranges.patch | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/api/webview-tag.md b/docs/api/webview-tag.md index b202a9bc2b65a..b116b033efe6b 100644 --- a/docs/api/webview-tag.md +++ b/docs/api/webview-tag.md @@ -587,7 +587,7 @@ Prints `webview`'s web page. Same as `webContents.print([options])`. default margin, 1 for no margin, and 2 for minimum margin. and `width` in microns. * `scaleFactor` Number (optional) - The scale factor of the web page. Can range from 0 to 100. - * `pageRanges` Object[] (optional) - The page range to print. On macOS, only the first range is honored. + * `pageRanges` Record (optional) - The page range to print. On macOS, only the first range is honored. * `from` Number - Index of the first page to print (0-based). * `to` Number - Index of the last page to print (inclusive) (0-based). * `pageSize` String | Size (optional) - Specify page size of the generated PDF. Can be `A3`, diff --git a/patches/chromium/fix_properly_honor_printing_page_ranges.patch b/patches/chromium/fix_properly_honor_printing_page_ranges.patch index 453b49bc199d9..ea568f00252f5 100644 --- a/patches/chromium/fix_properly_honor_printing_page_ranges.patch +++ b/patches/chromium/fix_properly_honor_printing_page_ranges.patch @@ -97,7 +97,7 @@ index d3c8677f30d72efc49b28f293260c74c7b8d8b4e..bacc24388e0159a83c4ed5e03b104e11 } else { // No need to bother, we don't know how many pages are available. diff --git a/ui/gtk/printing/print_dialog_gtk.cc b/ui/gtk/printing/print_dialog_gtk.cc -index 8a78a609295a1d90208bdc7e73d7a850c319f361..8efbbfb31eac99323be5e81826d5738b2390a82d 100644 +index 8a78a609295a1d90208bdc7e73d7a850c319f361..2f5bc01bedf84126d8fb1597a0b813a2b7230279 100644 --- a/ui/gtk/printing/print_dialog_gtk.cc +++ b/ui/gtk/printing/print_dialog_gtk.cc @@ -239,6 +239,23 @@ void PrintDialogGtk::UpdateSettings( From 81dea24255859802e4e6b371dbcbd88b8a691642 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Thu, 27 Aug 2020 14:00:26 -0700 Subject: [PATCH 7/8] fix: pageRange radio button on Windows --- .../fix_properly_honor_printing_page_ranges.patch | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/patches/chromium/fix_properly_honor_printing_page_ranges.patch b/patches/chromium/fix_properly_honor_printing_page_ranges.patch index ea568f00252f5..2123ab5e70275 100644 --- a/patches/chromium/fix_properly_honor_printing_page_ranges.patch +++ b/patches/chromium/fix_properly_honor_printing_page_ranges.patch @@ -62,10 +62,10 @@ index 56bcfbe625537c7b1bc2a999c261836bb15896ba..f916e78de99b87e0dae4f5f87329886b PMPrintSettings print_settings = static_cast([print_info_.get() PMPrintSettings]); diff --git a/printing/printing_context_system_dialog_win.cc b/printing/printing_context_system_dialog_win.cc -index d3c8677f30d72efc49b28f293260c74c7b8d8b4e..bacc24388e0159a83c4ed5e03b104e1115dd9713 100644 +index d3c8677f30d72efc49b28f293260c74c7b8d8b4e..de40066409c0fda5aac59ef3254c5e052dfa34f5 100644 --- a/printing/printing_context_system_dialog_win.cc +++ b/printing/printing_context_system_dialog_win.cc -@@ -52,14 +52,25 @@ void PrintingContextSystemDialogWin::AskUserForSettings( +@@ -52,15 +52,29 @@ void PrintingContextSystemDialogWin::AskUserForSettings( PRINTPAGERANGE ranges[32]; dialog_options.nStartPage = START_PAGE_GENERAL; if (max_pages) { @@ -80,8 +80,8 @@ index d3c8677f30d72efc49b28f293260c74c7b8d8b4e..bacc24388e0159a83c4ed5e03b104e11 + if (!page_ranges.empty()) { + for (size_t i = 0; i < page_ranges.size(); i++) { + auto range = page_ranges[i]; -+ ranges[i].nFromPage = range.from; -+ ranges[i].nToPage = range.to; ++ ranges[i].nFromPage = range.from + 1; ++ ranges[i].nToPage = range.to + 1; + } + dialog_options.nPageRanges = page_ranges.size(); + } else { @@ -94,8 +94,12 @@ index d3c8677f30d72efc49b28f293260c74c7b8d8b4e..bacc24388e0159a83c4ed5e03b104e11 dialog_options.nMaxPage = max_pages; + dialog_options.nMaxPageRanges = base::size(ranges); dialog_options.lpPageRanges = ranges; ++ ++ // Ensure the Pages radio button is selected. ++ dialog_options.Flags |= PD_PAGENUMS; } else { // No need to bother, we don't know how many pages are available. + dialog_options.Flags |= PD_NOPAGENUMS; diff --git a/ui/gtk/printing/print_dialog_gtk.cc b/ui/gtk/printing/print_dialog_gtk.cc index 8a78a609295a1d90208bdc7e73d7a850c319f361..2f5bc01bedf84126d8fb1597a0b813a2b7230279 100644 --- a/ui/gtk/printing/print_dialog_gtk.cc From bfde583fba5441ba6b35164d98cbb23fc0c9e6ef Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Thu, 27 Aug 2020 17:38:30 -0700 Subject: [PATCH 8/8] Only set PD_PAGENUMS when page_ranges.empty() false --- .../fix_properly_honor_printing_page_ranges.patch | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/patches/chromium/fix_properly_honor_printing_page_ranges.patch b/patches/chromium/fix_properly_honor_printing_page_ranges.patch index 2123ab5e70275..c8e74c4b14838 100644 --- a/patches/chromium/fix_properly_honor_printing_page_ranges.patch +++ b/patches/chromium/fix_properly_honor_printing_page_ranges.patch @@ -62,10 +62,10 @@ index 56bcfbe625537c7b1bc2a999c261836bb15896ba..f916e78de99b87e0dae4f5f87329886b PMPrintSettings print_settings = static_cast([print_info_.get() PMPrintSettings]); diff --git a/printing/printing_context_system_dialog_win.cc b/printing/printing_context_system_dialog_win.cc -index d3c8677f30d72efc49b28f293260c74c7b8d8b4e..de40066409c0fda5aac59ef3254c5e052dfa34f5 100644 +index d3c8677f30d72efc49b28f293260c74c7b8d8b4e..f6e66aaa58ab1881d64dcbb320ae8b5ac7631b28 100644 --- a/printing/printing_context_system_dialog_win.cc +++ b/printing/printing_context_system_dialog_win.cc -@@ -52,15 +52,29 @@ void PrintingContextSystemDialogWin::AskUserForSettings( +@@ -52,14 +52,28 @@ void PrintingContextSystemDialogWin::AskUserForSettings( PRINTPAGERANGE ranges[32]; dialog_options.nStartPage = START_PAGE_GENERAL; if (max_pages) { @@ -84,6 +84,9 @@ index d3c8677f30d72efc49b28f293260c74c7b8d8b4e..de40066409c0fda5aac59ef3254c5e05 + ranges[i].nToPage = range.to + 1; + } + dialog_options.nPageRanges = page_ranges.size(); ++ ++ // Ensure the Pages radio button is selected. ++ dialog_options.Flags |= PD_PAGENUMS; + } else { + ranges[0].nFromPage = 1; + ranges[0].nToPage = max_pages; @@ -94,12 +97,8 @@ index d3c8677f30d72efc49b28f293260c74c7b8d8b4e..de40066409c0fda5aac59ef3254c5e05 dialog_options.nMaxPage = max_pages; + dialog_options.nMaxPageRanges = base::size(ranges); dialog_options.lpPageRanges = ranges; -+ -+ // Ensure the Pages radio button is selected. -+ dialog_options.Flags |= PD_PAGENUMS; } else { // No need to bother, we don't know how many pages are available. - dialog_options.Flags |= PD_NOPAGENUMS; diff --git a/ui/gtk/printing/print_dialog_gtk.cc b/ui/gtk/printing/print_dialog_gtk.cc index 8a78a609295a1d90208bdc7e73d7a850c319f361..2f5bc01bedf84126d8fb1597a0b813a2b7230279 100644 --- a/ui/gtk/printing/print_dialog_gtk.cc