Skip to content

Svg thumbnail failed rendering #32936

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

Merged
merged 8 commits into from
Mar 18, 2025

Conversation

gokcekantarci
Copy link
Contributor

@gokcekantarci gokcekantarci commented May 21, 2024

Summary of the Pull Request

Default value of fill-rule in style is "nonzero". There is a possibility that rendering bugs may occur due to this reason. Therefore, to eliminate these errors, it is checked whether there is a fill-rule in style and if so, it is re-applied.

https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/fill-rule

PR Checklist

Detailed Description of the Pull Request / Additional comments

I created some SVG files for testing. The first one is the "fill-rule" attribute is under style. In others it's under "polygon" and "path". When I tested it with version 0.84.1, only the one under style was broken. Therefore, I was able to solve the problem by parsing the svg style of the file and re-applying the "fill-rule" and other attributes there. The reason why I re-applied all the attributes in the style was that if there was such an error in the "fill-rule", I suspected that there might be other attributes as well. When I changed the "stroke color", "clip-rule", "stroke-width", "opacity" attributes, I did not encounter this error. However, I preserved the code this way as similar errors may occur in other attributes in the future.

0.84.1
test files with release

PR
test files with PR

Validation Steps Performed

Check with these svg files

Test files.zip

Copy link
Contributor

@jaimecbernardo jaimecbernardo left a comment

Choose a reason for hiding this comment

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

I think the implementation should be changed, since I don't understand why JavaScript is needed to get the fill-rule. We're supposed to have that already from elsewhere.
Also this fixes for the svg thumbnail but not for svg preview. What about Peek? Does it have the same issue?

Copy link
Contributor

@jaimecbernardo jaimecbernardo left a comment

Choose a reason for hiding this comment

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

Looking at the solution, it doesn't seem like a safe solution. According to the sample in the documentation linked in this PR ( https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/fill-rule ) , fill-rule might be present in internal polygons and not even the svg tag. So this change might actually apply an internal fill rule to the whole SVG, since it's applying it to the svg tag.
This is likely to create errors in trying to show others files.

If what we're trying to do is restore the "fill-rule" we seem to be removing from the style of the svg, perhaps the correct solution is edit or add just the width and height instead of completely overwriting the style of the svg tag like we were doing before.
Thoughts?

gokcekantarci and others added 2 commits June 24, 2024 15:32
…iciently

- Add retry logic and error handling for WebView2 initialization
@crutkas
Copy link
Member

crutkas commented Sep 18, 2024

Is this ready for review again?

@cinnamon-msft cinnamon-msft added the Priority-1 Bug that is high priority label Mar 14, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request addresses an SVG thumbnail rendering bug by reapplying the fill-rule (and other style attributes) extracted from the SVG’s style attribute. The changes include removing an unused using directive, parsing the SVG content to capture style information, and adding a retry mechanism during WebView2 initialization.

Comments suppressed due to low confidence (1)

src/modules/previewpane/SvgThumbnailProvider/SvgThumbnailProvider.cs:123

  • [nitpick] The variable name 'a' is ambiguous; consider renaming it to something more descriptive like 'svgViewBoxResult' for clarity.
var a = await _browser.ExecuteScriptAsync($"document.getElementsByTagName('svg')[0].viewBox;");

Copy link
Contributor

@lei9444 lei9444 left a comment

Choose a reason for hiding this comment

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

Made some code changes, and the local test passed successfully.

@lei9444 lei9444 dismissed stale reviews from Parvezkhan0 and jaimecbernardo March 18, 2025 09:49

updated

@lei9444
Copy link
Contributor

lei9444 commented Mar 18, 2025

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Contributor

@vanzue vanzue left a comment

Choose a reason for hiding this comment

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

Tested, and works fine in my environment

@lei9444 lei9444 merged commit 1d358af into microsoft:main Mar 18, 2025
9 checks passed
lei9444 added a commit that referenced this pull request Mar 20, 2025
jaimecbernardo pushed a commit that referenced this pull request Mar 20, 2025
…ssion (#38058)

Revert "Svg thumbnail failed rendering (#32936)"

This reverts commit 1d358af.
colin-tso pushed a commit to colin-tso/PowerToys that referenced this pull request Apr 8, 2025
* [SVGThumbnail] Check fill-rule in SVG file and apply it.

* [SVGThumbnail] Comment added

* [SVGThumbnail] SvgContents is used instead of all html content.

* [SVGThumbnail] - Use SvgContents to extract and modify SVG styles efficiently
- Add retry logic and error handling for WebView2 initialization

* use Linq

---------

Co-authored-by: Jaime Bernardo <jaime@janeasystems.com>
Co-authored-by: Leilei Zhang <leilzh@microsoft.com>
colin-tso pushed a commit to colin-tso/PowerToys that referenced this pull request Apr 8, 2025
…d a regression (microsoft#38058)

Revert "Svg thumbnail failed rendering (microsoft#32936)"

This reverts commit 1d358af.
sadirano pushed a commit to sadirano/PowerToys that referenced this pull request Jun 10, 2025
* [SVGThumbnail] Check fill-rule in SVG file and apply it.

* [SVGThumbnail] Comment added

* [SVGThumbnail] SvgContents is used instead of all html content.

* [SVGThumbnail] - Use SvgContents to extract and modify SVG styles efficiently
- Add retry logic and error handling for WebView2 initialization

* use Linq

---------

Co-authored-by: Jaime Bernardo <jaime@janeasystems.com>
Co-authored-by: Leilei Zhang <leilzh@microsoft.com>
sadirano pushed a commit to sadirano/PowerToys that referenced this pull request Jun 10, 2025
…d a regression (microsoft#38058)

Revert "Svg thumbnail failed rendering (microsoft#32936)"

This reverts commit 1d358af.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority-1 Bug that is high priority
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants