From b4e40843d5aa88c00a41747750e4153ff00f61b0 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Sat, 27 Jul 2019 20:39:34 -0700 Subject: [PATCH] working on radial gradients --- wx/svg/_nanosvg.pxd | 13 ++++++------- wx/svg/_nanosvg.pyx | 27 ++++++++++++++++++++------- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/wx/svg/_nanosvg.pxd b/wx/svg/_nanosvg.pxd index c72955b2..f15e0d9c 100644 --- a/wx/svg/_nanosvg.pxd +++ b/wx/svg/_nanosvg.pxd @@ -93,14 +93,13 @@ cdef extern from 'nanosvg.h': NSVGshape *shapes cdef NSVGimage *nsvgParseFromFile(const char *filename, const char *units, float dpi) - cdef NSVGimage *nsvgParse(char *input, const char *units, float dpi) - cdef void nsvgDelete(NSVGimage *image) cdef NSVGpath* nsvgDuplicatePath(NSVGpath* p); cdef void nsvg__xformInverse(float* inv, float* t); + cdef void nsvg__xformPoint(float* dx, float* dy, float x, float y, float* t) @@ -108,10 +107,10 @@ cdef extern from 'nanosvgrast.h': ctypedef struct NSVGrasterizer cdef NSVGrasterizer* nsvgCreateRasterizer() - - cdef void nsvgRasterize(NSVGrasterizer* r, - NSVGimage* image, float tx, float ty, float scale, - unsigned char* dst, int w, int h, int stride) - cdef void nsvgDeleteRasterizer(NSVGrasterizer*) + + cdef void nsvgRasterize( + NSVGrasterizer* r, + NSVGimage* image, float tx, float ty, float scale, + unsigned char* dst, int w, int h, int stride) \ No newline at end of file diff --git a/wx/svg/_nanosvg.pyx b/wx/svg/_nanosvg.pyx index 42f2fd40..46615693 100644 --- a/wx/svg/_nanosvg.pyx +++ b/wx/svg/_nanosvg.pyx @@ -499,21 +499,34 @@ cdef class SVGgradient: For linear gradients this returns the start and stop points as tuples of the form ((x1,y1), (x2,y2)). """ - # nanosvg transforms the start and stop points to (0,0) and (0,1) and + # nanosvg normalizes the start and stop points to (0,0) and (0,1) and # provides the transform used to do so. To get back the original x1,y1 # and x2,y2 we need to invert the transform. # See https://github.com/memononen/nanosvg/issues/26 - cdef float inv[6] + cdef float inverse[6] cdef float x1, y1, x2, y2 - nsvg__xformInverse(inv, self._ptr.xform) + nsvg__xformInverse(inverse, self._ptr.xform) - x1 = inv[4] - y1 = inv[5] - x2 = inv[2] + inv[4] - y2 = inv[3] + inv[5] + nsvg__xformPoint(&x1, &y1, 0, 0, inverse) + nsvg__xformPoint(&x2, &y2, 0, 1, inverse) return ((x1,y1), (x2,y2)) + + @property + def radialPoint(self): + cdef float inverse[6] + cdef float xo, yo, xc, yc, radius + + nsvg__xformInverse(inverse, self._ptr.xform) + + nsvg__xformPoint(&xc, &yc, 0, 0, inverse) + nsvg__xformPoint(&xo, &yo, 0, 1, inverse) + radius = yo - yc; + + return (xo, yo, xc, yc, radius) + + #---------------------------------------------------------------------------- cdef class SVGgradientStop: """