Skip to content

Commit 61aaf57

Browse files
authored
Make Clip.Scale public (#1676)
* Make Clip.Scale public * Default Scale to 1
1 parent 6272d40 commit 61aaf57

File tree

5 files changed

+29
-3
lines changed

5 files changed

+29
-3
lines changed

lib/PuppeteerSharp.Tests/PageTests/ScreenshotTests.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,32 @@ await page.SetViewportAsync(new ViewPortOptions
111111
}
112112
}
113113

114+
[Fact(Timeout = TestConstants.DefaultTestTimeout)]
115+
public async Task ShouldClipScale()
116+
{
117+
await using (var page = await Context.NewPageAsync())
118+
{
119+
await page.SetViewportAsync(new ViewPortOptions
120+
{
121+
Width = 500,
122+
Height = 500
123+
});
124+
await page.GoToAsync(TestConstants.ServerUrl + "/grid.html");
125+
var screenshot = await page.ScreenshotDataAsync(new ScreenshotOptions
126+
{
127+
Clip = new Clip
128+
{
129+
X = 50,
130+
Y = 100,
131+
Width = 150,
132+
Height = 100,
133+
Scale = 2
134+
}
135+
});
136+
Assert.True(ScreenshotHelper.PixelMatch("screenshot-clip-rect-scale.png", screenshot));
137+
}
138+
}
139+
114140
[SkipBrowserFact(skipFirefox: true)]
115141
public async Task ShouldClipElementsToTheViewport()
116142
{
8.27 KB
Loading
8.27 KB
Loading

lib/PuppeteerSharp/Media/Clip.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ public class Clip
3131
/// Scale of the webpage rendering. Defaults to 1.
3232
/// </summary>
3333
/// <value>The scale.</value>
34-
public int Scale { get; internal set; }
34+
public int Scale { get; set; } = 1;
3535
}
36-
}
36+
}

lib/PuppeteerSharp/Page.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2023,7 +2023,7 @@ private Clip ProcessClip(Clip clip)
20232023
Y = y,
20242024
Width = Math.Round(clip.Width + clip.X - x, MidpointRounding.AwayFromZero),
20252025
Height = Math.Round(clip.Height + clip.Y - y, MidpointRounding.AwayFromZero),
2026-
Scale = 1
2026+
Scale = clip.Scale
20272027
};
20282028
}
20292029

0 commit comments

Comments
 (0)