Skip to content
Permalink
Browse files

Add/update some docstrings

  • Loading branch information...
Robin Dunn authored and RobinD42 committed Aug 7, 2019
1 parent 7d7c669 commit 68d8224a8681e0b03be93973be1e1cf87a8f3675
Showing with 29 additions and 13 deletions.
  1. +29 −13 wx/svg/_nanosvg.pyx
@@ -11,14 +11,14 @@
#---------------------------------------------------------------------- #----------------------------------------------------------------------
""" """
NanoSVG is a "simple stupid single-header-file SVG parser" from NanoSVG is a "simple stupid single-header-file SVG parser" from
https://github.com/memononen/nanosvg. The output of the parser is a list of https://github.com/memononen/nanosvg. The output of the parser is a collection
cubic bezier shapes. of data structures representing cubic bezier shapes.
The library is well suited for anything from rendering scalable icons in your NanoSVG supports a wide range of SVG features. The library is well suited for
editor application to prototyping a game. anything from rendering scalable icons in your editor application to prototyping
a game. There is not a full coverage of the SVG specification, however the
NanoSVG supports a wide range of SVG features, but something may be missing, features needed for typical icons or even more advanced vector images are
feel free to create a pull request! present.
The shapes in the SVG images are transformed by the viewBox and converted to The shapes in the SVG images are transformed by the viewBox and converted to
specified units. That is, you should get the same looking data as you designed specified units. That is, you should get the same looking data as you designed
@@ -34,8 +34,10 @@ The units passed to NanoSVG should be one of: 'px', 'pt', 'pc' 'mm', 'cm', or
If you don't know or care about the units stuff, "px" and 96 should get you If you don't know or care about the units stuff, "px" and 96 should get you
going. going.
This module implements a Cython-based wrapper for the nanosvg code, providing This module implements a Cython-based wrapper for the NanoSVG code, providing
access to the parsed SVG data as a nested collection of objects and properties. access to the parsed SVG data as a nested collection of objects and properties.
Note that these classes are essentially read-only. There is no support (yet?)
for manipulating the SVG shape info in memory.
""" """


import sys import sys
@@ -75,7 +77,6 @@ cpdef enum SVGflags:
#---------------------------------------------------------------------------- #----------------------------------------------------------------------------
# Cython classes for wrapping the nanosvg structs # Cython classes for wrapping the nanosvg structs


# SVGimage
cdef class SVGimageBase: cdef class SVGimageBase:
""" """
A SVGimageBase can be created either from an SVG file or from an in-memory A SVGimageBase can be created either from an SVG file or from an in-memory
@@ -167,6 +168,16 @@ cdef class SVGimageBase:
def RasterizeToBytes(self, float tx=0.0, float ty=0.0, float scale=1.0, def RasterizeToBytes(self, float tx=0.0, float ty=0.0, float scale=1.0,
int width=-1, int height=-1, int stride=-1) -> bytes: int width=-1, int height=-1, int stride=-1) -> bytes:
""" """
Renders the SVG image to a ``bytes`` object as a series of RGBA values.

:param float `tx`: Image horizontal offset (applied after scaling)
:param float `ty`: Image vertical offset (applied after scaling)
:param float `scale`: Image scale
:param int `width`: width of the image to render, defaults to width from the SVG file
:param int `height`: height of the image to render, defaults to height from the SVG file
:param int `stride`: number of bytes per scan line in the destination buffer, typically ``width * 4``

:returns: A bytes object containing the raw RGBA pixel color values
""" """
self._check_ptr() self._check_ptr()
if self._rasterizer == NULL: if self._rasterizer == NULL:
@@ -179,11 +190,10 @@ cdef class SVGimageBase:
if stride == -1: if stride == -1:
stride = width * 4; stride = width * 4;


buffer = bytes(height * stride) buf = bytes(height * stride)
nsvgRasterize(self._rasterizer, self._ptr, tx, ty, scale, buffer, nsvgRasterize(self._rasterizer, self._ptr, tx, ty, scale, buf,
width, height, stride) width, height, stride)
return buffer return buf



@property @property
def width(self) -> float: def width(self) -> float:
@@ -442,6 +452,9 @@ cdef class SVGpath:
#---------------------------------------------------------------------------- #----------------------------------------------------------------------------
cdef class SVGpaint: cdef class SVGpaint:
""" """
This class defines how to fill or stroke a shape when rendering the SVG
image. In other words, how to create the pen or brush. It can be a solid
color, linear or radial gradients, etc.
""" """
cdef NSVGpaint *_ptr cdef NSVGpaint *_ptr


@@ -491,6 +504,8 @@ cdef class SVGpaint:
#---------------------------------------------------------------------------- #----------------------------------------------------------------------------
cdef class SVGgradient: cdef class SVGgradient:
""" """
A gradient is a method used to fade from one color to another, either
linearly or radially.
""" """
cdef NSVGgradient *_ptr cdef NSVGgradient *_ptr


@@ -540,6 +555,7 @@ cdef class SVGgradient:
#---------------------------------------------------------------------------- #----------------------------------------------------------------------------
cdef class SVGgradientStop: cdef class SVGgradientStop:
""" """
A Gradient stop is an offset and a color, which is used when drawing gradients.
""" """
cdef NSVGgradientStop *_ptr cdef NSVGgradientStop *_ptr


0 comments on commit 68d8224

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