diff --git a/installer/PowerToysSetup/Product.wxs b/installer/PowerToysSetup/Product.wxs
index 59c1b28f89..8d57f38edd 100644
--- a/installer/PowerToysSetup/Product.wxs
+++ b/installer/PowerToysSetup/Product.wxs
@@ -438,18 +438,18 @@
-
+
-
+
-
+
diff --git a/src/modules/previewpane/SvgThumbnailProvider/SvgThumbnailProvider.cs b/src/modules/previewpane/SvgThumbnailProvider/SvgThumbnailProvider.cs
index 8930516a37..925091ae7b 100644
--- a/src/modules/previewpane/SvgThumbnailProvider/SvgThumbnailProvider.cs
+++ b/src/modules/previewpane/SvgThumbnailProvider/SvgThumbnailProvider.cs
@@ -1,24 +1,22 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+using System;
+using System.Drawing;
+using System.Drawing.Drawing2D;
+using System.Globalization;
+using System.IO;
+using System.Linq;
+using System.Runtime.InteropServices;
+using System.Runtime.InteropServices.ComTypes;
+using System.Windows.Forms;
+using Common.ComInterlop;
+using Common.Utilities;
+using Microsoft.PowerToys.Telemetry;
+using PreviewHandlerCommon;
-namespace SvgThumbnailProvider
+namespace Microsoft.PowerToys.ThumbnailHandler.Svg
{
- using System;
- using System.Drawing;
- using System.Drawing.Drawing2D;
- using System.Drawing.Imaging;
- using System.IO;
- using System.Linq;
- using System.Runtime.InteropServices;
- using System.Runtime.InteropServices.ComTypes;
- using System.Windows.Forms;
- using Common;
- using Common.ComInterlop;
- using Common.Utilities;
- using Microsoft.PowerToys.Telemetry;
- using PreviewHandlerCommon;
-
///
/// SVG Thumbnail Provider.
///
@@ -64,7 +62,7 @@ namespace SvgThumbnailProvider
{
deviceContextHandle = graphics.GetHdc();
- IViewObject viewObject = browser.ActiveXInstance as IViewObject;
+ IViewObject viewObject = browser?.ActiveXInstance as IViewObject;
viewObject.Draw(1, -1, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, deviceContextHandle, ref rect, IntPtr.Zero, IntPtr.Zero, 0);
}
finally
@@ -100,30 +98,16 @@ namespace SvgThumbnailProvider
// Wrap the SVG content in HTML in IE Edge mode so we can ensure
// we render properly.
string wrappedContent = WrapSVGInHTML(content);
- WebBrowserExt browser = new WebBrowserExt();
- browser.Dock = DockStyle.Fill;
- browser.IsWebBrowserContextMenuEnabled = false;
- browser.ScriptErrorsSuppressed = true;
- browser.ScrollBarsEnabled = false;
- browser.AllowNavigation = false;
- browser.Width = (int)cx;
- browser.Height = (int)cx;
- browser.DocumentText = wrappedContent;
-
- // Wait for the browser to render the content.
- while (browser.IsBusy || browser.ReadyState != WebBrowserReadyState.Complete)
+ using (WebBrowserExt browser = new WebBrowserExt())
{
- Application.DoEvents();
- }
-
- // Check size of the rendered SVG.
- var svg = browser.Document.GetElementsByTagName("svg").Cast().FirstOrDefault();
- if (svg != null)
- {
- // Update the size of the browser control to fit the SVG
- // in the visible viewport.
- browser.Width = svg.OffsetRectangle.Width;
- browser.Height = svg.OffsetRectangle.Height;
+ browser.Dock = DockStyle.Fill;
+ browser.IsWebBrowserContextMenuEnabled = false;
+ browser.ScriptErrorsSuppressed = true;
+ browser.ScrollBarsEnabled = false;
+ browser.AllowNavigation = false;
+ browser.Width = (int)cx;
+ browser.Height = (int)cx;
+ browser.DocumentText = wrappedContent;
// Wait for the browser to render the content.
while (browser.IsBusy || browser.ReadyState != WebBrowserReadyState.Complete)
@@ -131,16 +115,32 @@ namespace SvgThumbnailProvider
Application.DoEvents();
}
- // Capture the image of the SVG from the browser.
- thumbnail = GetBrowserContentImage(browser, svg.OffsetRectangle, Color.White);
- if (thumbnail.Width != cx && thumbnail.Height != cx)
+ // Check size of the rendered SVG.
+ var svg = browser.Document.GetElementsByTagName("svg").Cast().FirstOrDefault();
+ if (svg != null)
{
- // We are not the appropriate size for caller. Resize now while
- // respecting the aspect ratio.
- float scale = Math.Min((float)cx / thumbnail.Width, (float)cx / thumbnail.Height);
- int scaleWidth = (int)(thumbnail.Width * scale);
- int scaleHeight = (int)(thumbnail.Height * scale);
- thumbnail = ResizeImage(thumbnail, scaleWidth, scaleHeight);
+ // Update the size of the browser control to fit the SVG
+ // in the visible viewport.
+ browser.Width = svg.OffsetRectangle.Width;
+ browser.Height = svg.OffsetRectangle.Height;
+
+ // Wait for the browser to render the content.
+ while (browser.IsBusy || browser.ReadyState != WebBrowserReadyState.Complete)
+ {
+ Application.DoEvents();
+ }
+
+ // Capture the image of the SVG from the browser.
+ thumbnail = GetBrowserContentImage(browser, svg.OffsetRectangle, Color.White);
+ if (thumbnail.Width != cx && thumbnail.Height != cx)
+ {
+ // We are not the appropriate size for caller. Resize now while
+ // respecting the aspect ratio.
+ float scale = Math.Min((float)cx / thumbnail.Width, (float)cx / thumbnail.Height);
+ int scaleWidth = (int)(thumbnail.Width * scale);
+ int scaleHeight = (int)(thumbnail.Height * scale);
+ thumbnail = ResizeImage(thumbnail, scaleWidth, scaleHeight);
+ }
}
}
@@ -166,7 +166,7 @@ namespace SvgThumbnailProvider
{0}