Skip to content

Viewport area isn't determined properly if svg has both viewBox and width/height specified. #303

Description

@asdf1280
        <Border BorderBrush="#FF00FF3E" BorderThickness="1" HorizontalAlignment="Center" VerticalAlignment="Center">
            <svg:SvgCanvas Source="/Icons/main_reset.svg" EnsureViewboxPosition="True" EnsureViewboxSize="True" />
        </Border>

When svg file only specifies viewBox, the viewport is determined properly. Svg file was downloaded from material icons and is available here.
Image

However, if svg also has width and height defined, the viewBox attribute is completely ignored. Since it is viewbox rather than width/height that primarily deals with coordinate spaces of svg, width/height should be ignored or viewBox should have priority over these. And then, width/height should be used to scale the image. Although I haven't taken a closer look into the source code of this library, I'm sure there's something wrong in this process.

Anyway, here's what happens with the original svg downloaded from google, with both viewBox and dimensions specified.

Image

Note that these two images even have different sizes when displayed in svg canvas.

Here are two SVG files. The first one is buggy one.

Image
The buggy SVG starts with (This is the one originally generated by Google)

<svg xmlns="http://www.w3.org/2000/svg" height="48px" viewBox="0 -960 960 960" width="48px" fill="#000000">

or
(I have confirmed the order doesn't matter)

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960" width="48px" height="48px" fill="#000000">

Image
The normally-working SVG starts with

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960" fill="#000000">

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions