From 28706d71b7705617e77f18e876c8bc344f9ebf72 Mon Sep 17 00:00:00 2001 From: yvsvarma Date: Thu, 23 Jan 2025 07:59:16 -0600 Subject: [PATCH 1/9] [dotnet] Enhance PrintOptions class to support for predefined and custom Paper Sizes --- dotnet/src/webdriver/PrintOptions.cs | 29 +++++++++++++++- dotnet/test/common/PrintTest.cs | 51 ++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 1 deletion(-) diff --git a/dotnet/src/webdriver/PrintOptions.cs b/dotnet/src/webdriver/PrintOptions.cs index b1f3efd30692e..424f88283bf9e 100644 --- a/dotnet/src/webdriver/PrintOptions.cs +++ b/dotnet/src/webdriver/PrintOptions.cs @@ -50,12 +50,24 @@ public class PrintOptions private const double DefaultPageHeight = 21.59; private const double DefaultPageWidth = 27.94; private const double CentimetersPerInch = 2.54; - + public static PageSize A4 { get; } = new PageSize { Width = 21.0, Height = 29.7 }; // cm + public static PageSize Legal { get; } = new PageSize { Width = 21.59, Height = 35.56 }; // cm + public static PageSize Letter { get; } = new PageSize { Width = 21.59, Height = 27.94 }; // cm + public static PageSize Tabloid { get; } = new PageSize { Width = 27.94, Height = 43.18 }; // cm private double scale = 1.0; private PageSize pageSize = new PageSize(); private Margins margins = new Margins(); private readonly HashSet pageRanges = new HashSet(); + /// + /// Initializes a new instance of the class with default values. + /// Default page size is set to A4. + /// + public PrintOptions() + { + this.PageDimensions = A4; // Default to A4 page size + } + /// /// Gets or sets the orientation of the pages in the printed document. /// @@ -99,6 +111,21 @@ public PageSize PageDimensions set => this.pageSize = value ?? throw new ArgumentNullException(nameof(value)); } + + /// + /// Sets the page size to a predefined or custom size. + /// + /// The page size to set. + /// Thrown if pageSize is null. + public void SetPageSize(PageSize pageSize) + { + if (pageSize == null) + { + throw new ArgumentNullException(nameof(pageSize), "Page size cannot be null."); + } + this.PageDimensions = pageSize; + } + /// /// Gets or sets the margins for each page in the doucment. /// diff --git a/dotnet/test/common/PrintTest.cs b/dotnet/test/common/PrintTest.cs index 324fc6e399c48..d6261ba6bcb39 100644 --- a/dotnet/test/common/PrintTest.cs +++ b/dotnet/test/common/PrintTest.cs @@ -122,5 +122,56 @@ public void MarginsCannotHaveNegativeValues() Assert.That(() => new PrintOptions.Margins { Left = -1 }, Throws.TypeOf()); Assert.That(() => new PrintOptions.Margins { Right = -1 }, Throws.TypeOf()); } + + [Test] + public void DefaultPageSizeIsA4() + { + var options = new PrintOptions(); + + Assert.That(options.PageDimensions.Width, Is.EqualTo(PrintOptions.A4.Width)); + Assert.That(options.PageDimensions.Height, Is.EqualTo(PrintOptions.A4.Height)); + } + + [Test] + public void CanSetPredefinedPageSizes() + { + var options = new PrintOptions(); + + options.SetPageSize(PrintOptions.A4); + Assert.That(options.PageDimensions.Width, Is.EqualTo(PrintOptions.A4.Width)); + Assert.That(options.PageDimensions.Height, Is.EqualTo(PrintOptions.A4.Height)); + + options.SetPageSize(PrintOptions.Legal); + Assert.That(options.PageDimensions.Width, Is.EqualTo(PrintOptions.Legal.Width)); + Assert.That(options.PageDimensions.Height, Is.EqualTo(PrintOptions.Legal.Height)); + + options.SetPageSize(PrintOptions.Letter); + Assert.That(options.PageDimensions.Width, Is.EqualTo(PrintOptions.Letter.Width)); + Assert.That(options.PageDimensions.Height, Is.EqualTo(PrintOptions.Letter.Height)); + + options.SetPageSize(PrintOptions.Tabloid); + Assert.That(options.PageDimensions.Width, Is.EqualTo(PrintOptions.Tabloid.Width)); + Assert.That(options.PageDimensions.Height, Is.EqualTo(PrintOptions.Tabloid.Height)); + } + + [Test] + public void CanSetCustomPageSize() + { + var options = new PrintOptions(); + var customPageSize = new PrintOptions.PageSize { Width = 25.0, Height = 30.0 }; + + options.SetPageSize(customPageSize); + + Assert.That(options.PageDimensions.Width, Is.EqualTo(25.0)); + Assert.That(options.PageDimensions.Height, Is.EqualTo(30.0)); + } + + [Test] + public void SettingPageSizeToNullThrowsException() + { + var options = new PrintOptions(); + Assert.That(() => options.SetPageSize(null), Throws.InstanceOf()); + } + } } From d655394d65607ab53cd874d1ac28225f4845a718 Mon Sep 17 00:00:00 2001 From: yvsvarma Date: Fri, 24 Jan 2025 23:06:31 -0600 Subject: [PATCH 2/9] addressing review comments --- dotnet/src/webdriver/PrintOptions.cs | 36 ++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/dotnet/src/webdriver/PrintOptions.cs b/dotnet/src/webdriver/PrintOptions.cs index 424f88283bf9e..931a54d523b4e 100644 --- a/dotnet/src/webdriver/PrintOptions.cs +++ b/dotnet/src/webdriver/PrintOptions.cs @@ -50,23 +50,36 @@ public class PrintOptions private const double DefaultPageHeight = 21.59; private const double DefaultPageWidth = 27.94; private const double CentimetersPerInch = 2.54; - public static PageSize A4 { get; } = new PageSize { Width = 21.0, Height = 29.7 }; // cm - public static PageSize Legal { get; } = new PageSize { Width = 21.59, Height = 35.56 }; // cm - public static PageSize Letter { get; } = new PageSize { Width = 21.59, Height = 27.94 }; // cm - public static PageSize Tabloid { get; } = new PageSize { Width = 27.94, Height = 43.18 }; // cm private double scale = 1.0; private PageSize pageSize = new PageSize(); private Margins margins = new Margins(); private readonly HashSet pageRanges = new HashSet(); + /// - /// Initializes a new instance of the class with default values. - /// Default page size is set to A4. + /// Represents the A4 paper size. + /// Width: 21.0 cm, Height: 29.7 cm /// - public PrintOptions() - { - this.PageDimensions = A4; // Default to A4 page size - } + public static PageSize A4 => new PageSize { Width = 21.0, Height = 29.7 }; // cm + + /// + /// Represents the Legal paper size. + /// Width: 21.59 cm, Height: 35.56 cm + /// + public static PageSize Legal => new PageSize { Width = 21.59, Height = 35.56 }; // cm + + /// + /// Represents the Letter paper size. + /// Width: 21.59 cm, Height: 27.94 cm + /// + public static PageSize Letter => new PageSize { Width = 21.59, Height = 27.94 }; // cm + + /// + /// Represents the Tabloid paper size. + /// Width: 27.94 cm, Height: 43.18 cm + /// + public static PageSize Tabloid => new PageSize { Width = 27.94, Height = 43.18 }; // cm + /// /// Gets or sets the orientation of the pages in the printed document. @@ -77,6 +90,9 @@ public PrintOptions() /// Gets or sets the amount which the printed content is zoomed. Valid values are 0.1 to 2.0. /// /// If the value is not set between 0.1 and 2.0. + + + public double ScaleFactor { get => this.scale; From f064dceb7a15664c1cdefd5db81d017528cbf3cf Mon Sep 17 00:00:00 2001 From: yvsvarma Date: Fri, 24 Jan 2025 23:15:54 -0600 Subject: [PATCH 3/9] update formatting --- dotnet/src/webdriver/PrintOptions.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/dotnet/src/webdriver/PrintOptions.cs b/dotnet/src/webdriver/PrintOptions.cs index 931a54d523b4e..2e3151a906740 100644 --- a/dotnet/src/webdriver/PrintOptions.cs +++ b/dotnet/src/webdriver/PrintOptions.cs @@ -80,7 +80,6 @@ public class PrintOptions /// public static PageSize Tabloid => new PageSize { Width = 27.94, Height = 43.18 }; // cm - /// /// Gets or sets the orientation of the pages in the printed document. /// @@ -91,8 +90,6 @@ public class PrintOptions /// /// If the value is not set between 0.1 and 2.0. - - public double ScaleFactor { get => this.scale; From 2e3eb579b5fb5a2e26949059a48e7de9d1be9474 Mon Sep 17 00:00:00 2001 From: yvsvarma Date: Sat, 25 Jan 2025 07:31:05 -0600 Subject: [PATCH 4/9] addressing review comments - removed setPagesize method and updated tests accordingly --- dotnet/src/webdriver/PrintOptions.cs | 63 +++++++++++----------------- dotnet/test/common/PrintTest.cs | 42 ++++++------------- 2 files changed, 37 insertions(+), 68 deletions(-) diff --git a/dotnet/src/webdriver/PrintOptions.cs b/dotnet/src/webdriver/PrintOptions.cs index 2e3151a906740..47a6a02e60ac8 100644 --- a/dotnet/src/webdriver/PrintOptions.cs +++ b/dotnet/src/webdriver/PrintOptions.cs @@ -55,31 +55,6 @@ public class PrintOptions private Margins margins = new Margins(); private readonly HashSet pageRanges = new HashSet(); - - /// - /// Represents the A4 paper size. - /// Width: 21.0 cm, Height: 29.7 cm - /// - public static PageSize A4 => new PageSize { Width = 21.0, Height = 29.7 }; // cm - - /// - /// Represents the Legal paper size. - /// Width: 21.59 cm, Height: 35.56 cm - /// - public static PageSize Legal => new PageSize { Width = 21.59, Height = 35.56 }; // cm - - /// - /// Represents the Letter paper size. - /// Width: 21.59 cm, Height: 27.94 cm - /// - public static PageSize Letter => new PageSize { Width = 21.59, Height = 27.94 }; // cm - - /// - /// Represents the Tabloid paper size. - /// Width: 27.94 cm, Height: 43.18 cm - /// - public static PageSize Tabloid => new PageSize { Width = 27.94, Height = 43.18 }; // cm - /// /// Gets or sets the orientation of the pages in the printed document. /// @@ -125,20 +100,6 @@ public PageSize PageDimensions } - /// - /// Sets the page size to a predefined or custom size. - /// - /// The page size to set. - /// Thrown if pageSize is null. - public void SetPageSize(PageSize pageSize) - { - if (pageSize == null) - { - throw new ArgumentNullException(nameof(pageSize), "Page size cannot be null."); - } - this.PageDimensions = pageSize; - } - /// /// Gets or sets the margins for each page in the doucment. /// @@ -299,6 +260,30 @@ public class PageSize private double height = DefaultPageHeight; private double width = DefaultPageWidth; + /// + /// Represents the A4 paper size. + /// Width: 21.0 cm, Height: 29.7 cm + /// + public static PageSize A4 => new PageSize { Width = 21.0, Height = 29.7 }; // cm + + /// + /// Represents the Legal paper size. + /// Width: 21.59 cm, Height: 35.56 cm + /// + public static PageSize Legal => new PageSize { Width = 21.59, Height = 35.56 }; // cm + + /// + /// Represents the Letter paper size. + /// Width: 21.59 cm, Height: 27.94 cm + /// + public static PageSize Letter => new PageSize { Width = 21.59, Height = 27.94 }; // cm + + /// + /// Represents the Tabloid paper size. + /// Width: 27.94 cm, Height: 43.18 cm + /// + public static PageSize Tabloid => new PageSize { Width = 27.94, Height = 43.18 }; // cm + /// /// Gets or sets the height of each page in centimeters. /// diff --git a/dotnet/test/common/PrintTest.cs b/dotnet/test/common/PrintTest.cs index d6261ba6bcb39..7d67e9f83bbc7 100644 --- a/dotnet/test/common/PrintTest.cs +++ b/dotnet/test/common/PrintTest.cs @@ -123,35 +123,26 @@ public void MarginsCannotHaveNegativeValues() Assert.That(() => new PrintOptions.Margins { Right = -1 }, Throws.TypeOf()); } - [Test] - public void DefaultPageSizeIsA4() - { - var options = new PrintOptions(); - - Assert.That(options.PageDimensions.Width, Is.EqualTo(PrintOptions.A4.Width)); - Assert.That(options.PageDimensions.Height, Is.EqualTo(PrintOptions.A4.Height)); - } - [Test] public void CanSetPredefinedPageSizes() { var options = new PrintOptions(); - options.SetPageSize(PrintOptions.A4); - Assert.That(options.PageDimensions.Width, Is.EqualTo(PrintOptions.A4.Width)); - Assert.That(options.PageDimensions.Height, Is.EqualTo(PrintOptions.A4.Height)); + options.PageDimensions = PrintOptions.PageSize.A4; + Assert.That(options.PageDimensions.Width, Is.EqualTo(PrintOptions.PageSize.A4.Width)); + Assert.That(options.PageDimensions.Height, Is.EqualTo(PrintOptions.PageSize.A4.Height)); - options.SetPageSize(PrintOptions.Legal); - Assert.That(options.PageDimensions.Width, Is.EqualTo(PrintOptions.Legal.Width)); - Assert.That(options.PageDimensions.Height, Is.EqualTo(PrintOptions.Legal.Height)); + options.PageDimensions = PrintOptions.PageSize.Legal; + Assert.That(options.PageDimensions.Width, Is.EqualTo(PrintOptions.PageSize.Legal.Width)); + Assert.That(options.PageDimensions.Height, Is.EqualTo(PrintOptions.PageSize.Legal.Height)); - options.SetPageSize(PrintOptions.Letter); - Assert.That(options.PageDimensions.Width, Is.EqualTo(PrintOptions.Letter.Width)); - Assert.That(options.PageDimensions.Height, Is.EqualTo(PrintOptions.Letter.Height)); + options.PageDimensions = PrintOptions.PageSize.Letter; + Assert.That(options.PageDimensions.Width, Is.EqualTo(PrintOptions.PageSize.Letter.Width)); + Assert.That(options.PageDimensions.Height, Is.EqualTo(PrintOptions.PageSize.Letter.Height)); - options.SetPageSize(PrintOptions.Tabloid); - Assert.That(options.PageDimensions.Width, Is.EqualTo(PrintOptions.Tabloid.Width)); - Assert.That(options.PageDimensions.Height, Is.EqualTo(PrintOptions.Tabloid.Height)); + options.PageDimensions = PrintOptions.PageSize.Tabloid; + Assert.That(options.PageDimensions.Width, Is.EqualTo(PrintOptions.PageSize.Tabloid.Width)); + Assert.That(options.PageDimensions.Height, Is.EqualTo(PrintOptions.PageSize.Tabloid.Height)); } [Test] @@ -160,18 +151,11 @@ public void CanSetCustomPageSize() var options = new PrintOptions(); var customPageSize = new PrintOptions.PageSize { Width = 25.0, Height = 30.0 }; - options.SetPageSize(customPageSize); + options.PageDimensions = customPageSize; Assert.That(options.PageDimensions.Width, Is.EqualTo(25.0)); Assert.That(options.PageDimensions.Height, Is.EqualTo(30.0)); } - [Test] - public void SettingPageSizeToNullThrowsException() - { - var options = new PrintOptions(); - Assert.That(() => options.SetPageSize(null), Throws.InstanceOf()); - } - } } From 80845e7fe8cf5e81e0263ae29b76a06829754ab5 Mon Sep 17 00:00:00 2001 From: yvsvarma Date: Sat, 25 Jan 2025 10:40:08 -0600 Subject: [PATCH 5/9] minor format updates --- dotnet/src/webdriver/PrintOptions.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/dotnet/src/webdriver/PrintOptions.cs b/dotnet/src/webdriver/PrintOptions.cs index 47a6a02e60ac8..fd8a2e3591628 100644 --- a/dotnet/src/webdriver/PrintOptions.cs +++ b/dotnet/src/webdriver/PrintOptions.cs @@ -64,7 +64,6 @@ public class PrintOptions /// Gets or sets the amount which the printed content is zoomed. Valid values are 0.1 to 2.0. /// /// If the value is not set between 0.1 and 2.0. - public double ScaleFactor { get => this.scale; @@ -99,7 +98,6 @@ public PageSize PageDimensions set => this.pageSize = value ?? throw new ArgumentNullException(nameof(value)); } - /// /// Gets or sets the margins for each page in the doucment. /// From ce2bcf275dccf594ce30aae655f64a5b0fbf0712 Mon Sep 17 00:00:00 2001 From: yvsvarma Date: Sat, 25 Jan 2025 10:46:55 -0600 Subject: [PATCH 6/9] fixing format --- dotnet/src/webdriver/PrintOptions.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/dotnet/src/webdriver/PrintOptions.cs b/dotnet/src/webdriver/PrintOptions.cs index fd8a2e3591628..6b049bc01dfa3 100644 --- a/dotnet/src/webdriver/PrintOptions.cs +++ b/dotnet/src/webdriver/PrintOptions.cs @@ -50,6 +50,7 @@ public class PrintOptions private const double DefaultPageHeight = 21.59; private const double DefaultPageWidth = 27.94; private const double CentimetersPerInch = 2.54; + private double scale = 1.0; private PageSize pageSize = new PageSize(); private Margins margins = new Margins(); From cac42e18f098c10f67b40e27d1692b0e33509664 Mon Sep 17 00:00:00 2001 From: yvsvarma Date: Sat, 25 Jan 2025 17:28:43 -0600 Subject: [PATCH 7/9] removed extra lines at the end --- dotnet/src/webdriver/PrintOptions.cs | 2 +- dotnet/test/common/PrintTest.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dotnet/src/webdriver/PrintOptions.cs b/dotnet/src/webdriver/PrintOptions.cs index 6b049bc01dfa3..70d351eb3fced 100644 --- a/dotnet/src/webdriver/PrintOptions.cs +++ b/dotnet/src/webdriver/PrintOptions.cs @@ -423,4 +423,4 @@ public double Right } } } -} +} \ No newline at end of file diff --git a/dotnet/test/common/PrintTest.cs b/dotnet/test/common/PrintTest.cs index 7d67e9f83bbc7..d7de2e90529a5 100644 --- a/dotnet/test/common/PrintTest.cs +++ b/dotnet/test/common/PrintTest.cs @@ -158,4 +158,4 @@ public void CanSetCustomPageSize() } } -} +} \ No newline at end of file From dd22d0b11e9ca169f5016df57d441b5995905878 Mon Sep 17 00:00:00 2001 From: yvsvarma Date: Sat, 25 Jan 2025 23:00:56 -0600 Subject: [PATCH 8/9] fixing formatting issues --- dotnet/src/webdriver/PrintOptions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dotnet/src/webdriver/PrintOptions.cs b/dotnet/src/webdriver/PrintOptions.cs index 70d351eb3fced..c5b8533a20249 100644 --- a/dotnet/src/webdriver/PrintOptions.cs +++ b/dotnet/src/webdriver/PrintOptions.cs @@ -50,7 +50,7 @@ public class PrintOptions private const double DefaultPageHeight = 21.59; private const double DefaultPageWidth = 27.94; private const double CentimetersPerInch = 2.54; - + private double scale = 1.0; private PageSize pageSize = new PageSize(); private Margins margins = new Margins(); From 0834338ca7b596527025e4da126af8cc6215e55d Mon Sep 17 00:00:00 2001 From: yvsvarma Date: Sun, 26 Jan 2025 07:56:42 -0600 Subject: [PATCH 9/9] adding extra line at the end of file to address the format checks --- dotnet/src/webdriver/PrintOptions.cs | 2 +- dotnet/test/common/PrintTest.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dotnet/src/webdriver/PrintOptions.cs b/dotnet/src/webdriver/PrintOptions.cs index c5b8533a20249..27375a0a72d1e 100644 --- a/dotnet/src/webdriver/PrintOptions.cs +++ b/dotnet/src/webdriver/PrintOptions.cs @@ -423,4 +423,4 @@ public double Right } } } -} \ No newline at end of file +} diff --git a/dotnet/test/common/PrintTest.cs b/dotnet/test/common/PrintTest.cs index d7de2e90529a5..7d67e9f83bbc7 100644 --- a/dotnet/test/common/PrintTest.cs +++ b/dotnet/test/common/PrintTest.cs @@ -158,4 +158,4 @@ public void CanSetCustomPageSize() } } -} \ No newline at end of file +}