Skip to content
Permalink
Browse files

Add method to transform and fetch the start and stop points for linea…

…r gradients
  • Loading branch information...
RobinD42 committed Jul 28, 2019
1 parent 12e57b6 commit d7694127f54d05ce4d6dca666cac6547fec622b7
Showing with 24 additions and 2 deletions.
  1. +2 −0 wx/svg/_nanosvg.pxd
  2. +22 −2 wx/svg/_nanosvg.pyx
@@ -100,6 +100,8 @@ cdef extern from 'nanosvg.h':

cdef NSVGpath* nsvgDuplicatePath(NSVGpath* p);

cdef void nsvg__xformInverse(float* inv, float* t);



cdef extern from 'nanosvgrast.h':
@@ -80,7 +80,7 @@ cdef class SVGimage:


@staticmethod
def from_file(str filename, str units='px', float dpi=96) -> SVGimage:
def CreateFromFile(str filename, str units='px', float dpi=96) -> SVGimage:
"""
Loads an SVG image from a file.

@@ -98,7 +98,7 @@ cdef class SVGimage:


@staticmethod
def from_bytes(bytes buffer, str units='px', float dpi=96) -> SVGimage:
def CreateFromBytes(bytes buffer, str units='px', float dpi=96) -> SVGimage:
"""
Loads an SVG image from a bytes object.

@@ -493,7 +493,27 @@ cdef class SVGgradient:
for i in range(self._ptr.nstops):
yield SVGgradientStop.from_ptr(&self._ptr.stops[i])

@property
def linearPoints(self) -> tuple:
"""
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
# 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 x1, y1, x2, y2
nsvg__xformInverse(inv, self._ptr.xform)

x1 = inv[4]
y1 = inv[5]
x2 = inv[2] + inv[4]
y2 = inv[3] + inv[5]

return ((x1,y1), (x2,y2))
#----------------------------------------------------------------------------
cdef class SVGgradientStop:
"""

0 comments on commit d769412

Please sign in to comment.
You can’t perform that action at this time.