From 708a02f090e06e3ebeb89b671567f746817323a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Kondratiuk?= Date: Sat, 10 Oct 2020 14:30:00 -0300 Subject: [PATCH] fix(page): fix pdf PaperFormat (#931) --- src/Common/PackageInfo.props | 2 +- src/PlaywrightSharp.Tests/PdfTests.cs | 2 +- src/PlaywrightSharp/IPage.cs | 2 +- src/PlaywrightSharp/Margin.cs | 2 +- src/PlaywrightSharp/Page.cs | 2 +- src/PlaywrightSharp/PaperFormat.cs | 85 +++---------------- .../Transport/Channels/PageChannel.cs | 2 +- 7 files changed, 19 insertions(+), 78 deletions(-) diff --git a/src/Common/PackageInfo.props b/src/Common/PackageInfo.props index d5943714a5..a5418bf64e 100644 --- a/src/Common/PackageInfo.props +++ b/src/Common/PackageInfo.props @@ -2,7 +2,7 @@ true - 0.142.1 + 0.142.2 $(PackageVersion) $(PackageVersion) $(PackageVersion) diff --git a/src/PlaywrightSharp.Tests/PdfTests.cs b/src/PlaywrightSharp.Tests/PdfTests.cs index f52a45a149..86b3f5e505 100644 --- a/src/PlaywrightSharp.Tests/PdfTests.cs +++ b/src/PlaywrightSharp.Tests/PdfTests.cs @@ -28,7 +28,7 @@ public async Task ShouldBeAbleToSaveFile() { fileInfo.Delete(); } - await Page.GetPdfAsync(outputFile); + await Page.GetPdfAsync(outputFile, format: PaperFormat.Letter); fileInfo = new FileInfo(outputFile); Assert.True(new FileInfo(outputFile).Length > 0); if (fileInfo.Exists) diff --git a/src/PlaywrightSharp/IPage.cs b/src/PlaywrightSharp/IPage.cs index a292e627f2..1b6312a8d5 100644 --- a/src/PlaywrightSharp/IPage.cs +++ b/src/PlaywrightSharp/IPage.cs @@ -1581,7 +1581,7 @@ Task GetPdfAsync( bool printBackground = false, bool landscape = false, string pageRanges = "", - PaperFormat format = null, + PaperFormat? format = null, string width = null, string height = null, Margin margin = null, diff --git a/src/PlaywrightSharp/Margin.cs b/src/PlaywrightSharp/Margin.cs index d4f554d221..c60bf18ee7 100644 --- a/src/PlaywrightSharp/Margin.cs +++ b/src/PlaywrightSharp/Margin.cs @@ -4,7 +4,7 @@ namespace PlaywrightSharp { /// - /// Margin options used in . + /// Margin options used in . /// public class Margin : IEquatable { diff --git a/src/PlaywrightSharp/Page.cs b/src/PlaywrightSharp/Page.cs index a49ccdcfe4..e2b67853e7 100644 --- a/src/PlaywrightSharp/Page.cs +++ b/src/PlaywrightSharp/Page.cs @@ -706,7 +706,7 @@ public async Task GetPdfAsync( bool printBackground = false, bool landscape = false, string pageRanges = "", - PaperFormat format = null, + PaperFormat? format = null, string width = null, string height = null, Margin margin = null, diff --git a/src/PlaywrightSharp/PaperFormat.cs b/src/PlaywrightSharp/PaperFormat.cs index 6d7f97d489..793452e022 100644 --- a/src/PlaywrightSharp/PaperFormat.cs +++ b/src/PlaywrightSharp/PaperFormat.cs @@ -6,121 +6,62 @@ namespace PlaywrightSharp /// /// Paper format. /// - /// - public class PaperFormat : IEquatable + /// + public enum PaperFormat { - /// - /// Initializes a new instance of the class. - /// - /// Page width in inches. - /// Page height in inches. - public PaperFormat(decimal width, decimal height) - { - Width = width; - Height = height; - } - /// /// Letter: 8.5 inches x 11 inches. /// - public static PaperFormat Letter => new PaperFormat(8.5m, 11); + Letter, /// /// Legal: 8.5 inches by 14 inches. /// - public static PaperFormat Legal => new PaperFormat(8.5m, 14); + Legal, /// /// Tabloid: 11 inches by 17 inches. /// - public static PaperFormat Tabloid => new PaperFormat(11, 17); + Tabloid, /// /// Ledger: 17 inches by 11 inches. /// - public static PaperFormat Ledger => new PaperFormat(17, 11); + Ledger, /// /// A0: 33.1 inches by 46.8 inches. /// - public static PaperFormat A0 => new PaperFormat(33.1m, 46.8m); + A0, /// /// A1: 23.4 inches by 33.1 inches. /// - public static PaperFormat A1 => new PaperFormat(23.4m, 33.1m); + A1, /// /// A2: 16.5 inches by 23.4 inches. /// - public static PaperFormat A2 => new PaperFormat(16.54m, 23.4m); + A2, /// /// A3: 11.7 inches by 16.5 inches. /// - public static PaperFormat A3 => new PaperFormat(11.7m, 16.54m); + A3, /// /// A4: 8.27 inches by 11.7 inches. /// - public static PaperFormat A4 => new PaperFormat(8.27m, 11.7m); + A4, /// /// A5: 5.83 inches by 8.27 inches. /// - public static PaperFormat A5 => new PaperFormat(5.83m, 8.27m); + A5, /// /// A6: 4.13 inches by 5.83 inches. /// - public static PaperFormat A6 => new PaperFormat(4.13m, 5.83m); - - /// - /// Page width in inches. - /// - public decimal Width { get; set; } - - /// - /// Page height in inches. - /// - public decimal Height { get; set; } - - /// - public static bool operator ==(PaperFormat left, PaperFormat right) - => EqualityComparer.Default.Equals(left, right); - - /// - public static bool operator !=(PaperFormat left, PaperFormat right) => !(left == right); - - /// - /// Checks for object equality. - /// - /// Format to check. - /// Whether the objects are equal or not. - public override bool Equals(object obj) - { - if (obj == null || GetType() != obj.GetType()) - { - return false; - } - - return Equals((PaperFormat)obj); - } - - /// - /// Checks for object equality. - /// - /// Format to check. - /// Whether the objects are equal or not. - public bool Equals(PaperFormat other) - => other != null && - Width == other.Width && - Height == other.Height; - - /// - public override int GetHashCode() - => 859600377 - ^ Width.GetHashCode() - ^ Height.GetHashCode(); + A6, } } diff --git a/src/PlaywrightSharp/Transport/Channels/PageChannel.cs b/src/PlaywrightSharp/Transport/Channels/PageChannel.cs index 1f7769366d..bccb1e85e4 100644 --- a/src/PlaywrightSharp/Transport/Channels/PageChannel.cs +++ b/src/PlaywrightSharp/Transport/Channels/PageChannel.cs @@ -462,7 +462,7 @@ internal async Task GetPdfAsync( bool printBackground, bool landscape, string pageRanges, - PaperFormat format, + PaperFormat? format, string width, string height, Margin margin,