Fix negative-origin viewBox image dimensions#499
Merged
Conversation
…to fix/issue-446-viewbox-dimensions # Conflicts: # src/Svg.Model/Services/SvgService.cs # tests/Svg.Skia.UnitTests/SKSvgTests.cs
This was referenced May 12, 2026
This was referenced May 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Summary: Fix Negative-Origin viewBox Image Dimensions
Overview
This PR fixes incorrect output image dimensions when exporting standalone SVG documents that use percentage root
width/heightvalues with aviewBoxwhosemin-xormin-yis non-zero.Issue: #446
Problem
SvgService.GetDimensions()resolved percentage-sized root SVG documents by multiplying the percentage against:bounds.Width + bounds.Leftbounds.Height + bounds.TopFor a
viewBoxlike:that effectively used the right and bottom coordinates as dimensions. With negative
viewBoxorigins, this produced output dimensions around3399x415instead of the expected4876x2771, leaving large blank areas and clipping or misframing the rendered content.Changes
Fix root percentage dimension resolution
Updated
SvgService.GetDimensions()so root SVG percentage width and height resolve against the viewport size only:bounds.Widthbounds.HeightThis keeps
viewBoxposition separate fromviewBoxsize, which matches the SVG model where the third and fourthviewBoxvalues define the viewport width and height independently of the first two origin values.Add regression coverage
Added
Save_StandaloneDocumentWithNegativeViewBoxOrigin_UsesViewBoxSizetoSKSvgTests.The test covers a compact negative-origin
viewBox:It verifies both:
SvgService.GetDimensions()returns120x80SKSvg.Save()produces a120x80PNGClean nullable xml:base fallback
While reviewing the change,
TryGetXmlBase()emitted a nullable assignment warning when falling through to custom attributes. The helper now assigns a non-null fallback and returnsfalsewhen noxml:basevalue is available.Validation
Ran:
Result:
Notes
The full solution build was not used as the primary validation target for this focused fix because the checkout contains many unrelated projects and target frameworks. The focused test project was restored and run after initializing submodules, which exercises the changed dimension logic and export path.