dotnetprojects / SVGImage

A SVGImage Control for WPF
http://dotnetprojects.github.io/SVGImage/
MIT License
199 stars 41 forks source link

SVGRender and RectangleShape #33

Closed paulushub closed 4 years ago

paulushub commented 4 years ago

Comparing the handling of the RectangleShape in SVGRender, there was a change in the original code, in particular, the construction of the RectangleGeometry. The results of the change is that some of the original sample files, like computer-aj_aj_ashton_01.svg, are now throwing exceptions. Simply reverting to the original construction code fixes this bug, but what issue was fixed with the current changes?

The original is

if (shape is ClipArtViewer.RectangleShape)
{
    ClipArtViewer.RectangleShape r = shape as ClipArtViewer.RectangleShape;
    RectangleGeometry rect = new RectangleGeometry(new Rect(r.X, r.Y, r.Width, r.Height));
    rect.RadiusX = r.RX;
    rect.RadiusY = r.RY;
    if (rect.RadiusX == 0 && rect.RadiusY > 0)
        rect.RadiusX = rect.RadiusY;
    grp.Children.Add(NewDrawingItem(shape, rect));
}

and the current version is

if (shape is RectangleShape)
{
    RectangleShape r = shape as RectangleShape;
    RectangleGeometry rect = new RectangleGeometry(new Rect(r.X < 0 ? 0 : r.X, r.Y < 0 ? 0 : r.Y, r.X < 0 ? r.Width + r.X : r.Width, r.Y < 0 ? r.Height + r.Y : r.Height));
    rect.RadiusX = r.RX;
    rect.RadiusY = r.RY;
    if (rect.RadiusX == 0 && rect.RadiusY > 0) rect.RadiusX = rect.RadiusY;
    var di = this.NewDrawingItem(shape, rect);
    AddDrawingToGroup(grp, shape, di);
    continue;
}
paulushub commented 4 years ago

If there is no reason for the change, then there is nothing to worry about.