1
- using OpenQA . Selenium . BiDi . Communication ;
1
+ using OpenQA . Selenium . BiDi . Communication ;
2
+ using System ;
2
3
using System . Collections . Generic ;
3
4
4
5
namespace OpenQA . Selenium . BiDi . Modules . BrowsingContext ;
@@ -9,14 +10,13 @@ internal record PrintCommandParameters(BrowsingContext Context) : CommandParamet
9
10
{
10
11
public bool ? Background { get ; set ; }
11
12
12
- public Margin ? Margin { get ; set ; }
13
+ public PrintMargin ? Margin { get ; set ; }
13
14
14
- public Orientation ? Orientation { get ; set ; }
15
+ public PrintOrientation ? Orientation { get ; set ; }
15
16
16
- public Page ? Page { get ; set ; }
17
+ public PrintPage ? Page { get ; set ; }
17
18
18
- // TODO: It also supports strings
19
- public IEnumerable < long > ? PageRanges { get ; set ; }
19
+ public IEnumerable < PrintPageRange > ? PageRanges { get ; set ; }
20
20
21
21
public double ? Scale { get ; set ; }
22
22
@@ -27,21 +27,20 @@ public record PrintOptions : CommandOptions
27
27
{
28
28
public bool ? Background { get ; set ; }
29
29
30
- public Margin ? Margin { get ; set ; }
30
+ public PrintMargin ? Margin { get ; set ; }
31
31
32
- public Orientation ? Orientation { get ; set ; }
32
+ public PrintOrientation ? Orientation { get ; set ; }
33
33
34
- public Page ? Page { get ; set ; }
34
+ public PrintPage ? Page { get ; set ; }
35
35
36
- // TODO: It also supports strings
37
- public IEnumerable < long > ? PageRanges { get ; set ; }
36
+ public IEnumerable < PrintPageRange > ? PageRanges { get ; set ; }
38
37
39
38
public double ? Scale { get ; set ; }
40
39
41
40
public bool ? ShrinkToFit { get ; set ; }
42
41
}
43
42
44
- public struct Margin
43
+ public struct PrintMargin
45
44
{
46
45
public double ? Bottom { get ; set ; }
47
46
@@ -52,17 +51,63 @@ public struct Margin
52
51
public double ? Top { get ; set ; }
53
52
}
54
53
55
- public enum Orientation
54
+ public enum PrintOrientation
56
55
{
57
56
Portrait ,
58
57
Landscape
59
58
}
60
59
61
- public struct Page
60
+ public struct PrintPage
62
61
{
63
62
public double ? Height { get ; set ; }
64
63
65
64
public double ? Width { get ; set ; }
66
65
}
67
66
68
- public record PrintResult ( string Data ) ;
67
+ public readonly record struct PrintPageRange ( int ? Start , int ? End )
68
+ {
69
+ public static implicit operator PrintPageRange ( int index ) { return new PrintPageRange ( index , index ) ; }
70
+
71
+ #if NET8_0_OR_GREATER
72
+ public static implicit operator PrintPageRange ( Range range )
73
+ {
74
+ int ? start ;
75
+ int ? end ;
76
+
77
+ if ( range . Start . IsFromEnd && range . Start . Value == 0 )
78
+ {
79
+ start = null ;
80
+ }
81
+ else
82
+ {
83
+ if ( range . Start . IsFromEnd )
84
+ {
85
+ throw new NotSupportedException ( $ "Page index from end ({ range . Start } ) is not supported in page range for printing.") ;
86
+ }
87
+
88
+ start = range . Start . Value ;
89
+ }
90
+
91
+ if ( range . End . IsFromEnd && range . End . Value == 0 )
92
+ {
93
+ end = null ;
94
+ }
95
+ else
96
+ {
97
+ if ( range . End . IsFromEnd )
98
+ {
99
+ throw new NotSupportedException ( $ "Page index from end ({ range . End } ) is not supported in page range for printing.") ;
100
+ }
101
+
102
+ end = range . End . Value ;
103
+ }
104
+
105
+ return new PrintPageRange ( start , end ) ;
106
+ }
107
+ #endif
108
+ }
109
+
110
+ public record PrintResult ( string Data )
111
+ {
112
+ public byte [ ] ToByteArray ( ) => Convert . FromBase64String ( Data ) ;
113
+ }
0 commit comments