Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Svg thumbnail failed rendering #32936

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Globalization;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Text.RegularExpressions;
using Common.Utilities;
using ManagedCommon;
using Microsoft.Web.WebView2.Core;
Expand Down Expand Up @@ -120,7 +120,26 @@ public Bitmap GetThumbnailImpl(uint cx)
var a = await _browser.ExecuteScriptAsync($"document.getElementsByTagName('svg')[0].viewBox;");
if (a != null)
{
await _browser.ExecuteScriptAsync($"document.getElementsByTagName('svg')[0].style = 'width:100%;height:100%';");
// Retrieve the entire HTML content
var htmlContent = await _browser.ExecuteScriptAsync("document.documentElement.outerHTML;");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have to run JavaScript to get these contents?
Aren't we supposed to have that already from other parts in the code? Thinking SvgContents.
Makes no sense to asynchronously run JavaScript to get something we should already have.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

This issue was not observed in svg preview.
But the same error was seen in Peek. Since a common structure is not used, it would be more accurate to examine it in a separate PR.


// Directly search for the fill-rule within the HTML content
string fillRule = string.Empty;
var match = Regex.Match(htmlContent, @"fill-rule\s*:\s*([^;]+)");
if (match.Success)
{
fillRule = match.Groups[1].Value;
}

// Apply fill-rule if present in SVG file - fixes #28814
if (!string.IsNullOrEmpty(fillRule))
{
await _browser.ExecuteScriptAsync($"document.getElementsByTagName('svg')[0].style = 'width:100%;height:100%;fill-rule:{fillRule};'");
}
else
{
await _browser.ExecuteScriptAsync($"document.getElementsByTagName('svg')[0].style = 'width:100%;height:100%';");
}
}

// Hide scrollbar - fixes #18286
Expand Down
Loading