Fixed Stroke Width Calculation

2019-09-14 08:02发布

问题:

I would like to have a fixed stroke width into my views using the SVG tag. I mean, having the strokes 1 pixel wide no matter the scale transformations.

It seems the vector-effect="non-scaling-stroke" property approach is still not supported in Edge/IE, so I am thinking about calculating this manually.

If I discover the scaling factor of the viewbox, then I will be able to calculate a fixed stroke width.

How can I get this "scaling factor"?

<svg version="1.1"
    baseProfile="full"
    width="100%" height="Auto"
    viewBox="0 0 @sheet.SheetShape.Bounds.Width @sheet.SheetShape.Bounds.Height"
    xmlns="http://www.w3.org/2000/svg">

<rect width="100%" height="100%" stroke="red" fill="white" />

@foreach (var cut in sheet.SheetCuts)
{
    <line stroke-width="2" stroke="black" stroke-dasharray="5, 5" x1=@cut.Start.X y1=@cut.Start.Y x2=@cut.End.X y2=@cut.End.Y />
}
</svg>

Thank you,