Skip to content
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

Bug in nsvg__scaleToViewbox() #29

Closed
maxlem opened this issue Jan 30, 2015 · 1 comment
Closed

Bug in nsvg__scaleToViewbox() #29

maxlem opened this issue Jan 30, 2015 · 1 comment

Comments

@maxlem
Copy link

maxlem commented Jan 30, 2015

When no viewWidth/viewHeight is specified, it is determined from content's bounds max element instead of bound's max - min.

the following patch works for me on this test file (DO NOT expect it to render, meant to be used with a debugguer). I'm not sure the patch does the right thing when multiple paths are involved (one would use the extrema of path`s bounds)

<?xml version="1.0" encoding="utf-8"?><svg version="1.1" id="Layer_1"><path d="M-24.5, 0L0, -24.5L8.80764, -26.0009L41.0517, -12.645"/></svg>
Index: trunk/src/nanosvg.h
===================================================================
--- trunk/src/nanosvg.h (revision 50)
+++ trunk/src/nanosvg.h (working copy)
@@ -2497,13 +2497,13 @@
        if (p->image->width > 0)
            p->viewWidth = p->image->width;
        else
-           p->viewWidth = bounds[2];
+           p->viewWidth = bounds[2] - bounds[0];
    }
    if (p->viewHeight == 0) {
        if (p->image->height > 0)
            p->viewHeight = p->image->height;
        else
-           p->viewHeight = bounds[3];
+           p->viewHeight = bounds[3] - bounds[1];
    }
    if (p->image->width == 0)
        p->image->width = p->viewWidth;

[Edited: removed non pertinent part of the patch]

chrismile added a commit to chrismile/nanosvg that referenced this issue May 27, 2015
Fixed/added the following things:
- The right initial values for linear (x2=1.0f) and radial gradients
(cx=cy=r=0.5f). See:
http://www.w3.org/TR/SVG/pservers.html#LinearGradients
- Fixed matrix multiplication order in "nsvg__createGradient" to
properly support gradientUnits="userSpaceOnUse"
- Added support for gradientUnits="objectBoundingBox" with percentage
and floating point values (tested with
http://www.w3.org/TR/SVG/images/pservers/lingrad01.svg)
- Added patch from memononen#29
- Fixed removing the hash in front of "link:href" references. Currently
this only means that the first char is skipped. Not quite optimal (can
there be leading whitespace chars?), but it at least works.
This was referenced May 27, 2015
@memononen
Copy link
Owner

Closing this as the fix got merged in another PR. Thanks for taking the time to fix it!

Marirossibn added a commit to Marirossibn/Orca-deps-nanosvg that referenced this issue Jul 1, 2024
Fixed/added the following things:
- The right initial values for linear (x2=1.0f) and radial gradients
(cx=cy=r=0.5f). See:
http://www.w3.org/TR/SVG/pservers.html#LinearGradients
- Fixed matrix multiplication order in "nsvg__createGradient" to
properly support gradientUnits="userSpaceOnUse"
- Added support for gradientUnits="objectBoundingBox" with percentage
and floating point values (tested with
http://www.w3.org/TR/SVG/images/pservers/lingrad01.svg)
- Added patch from memononen/nanosvg#29
- Fixed removing the hash in front of "link:href" references. Currently
this only means that the first char is skipped. Not quite optimal (can
there be leading whitespace chars?), but it at least works.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants