KiCad PCB EDA Suite
nanosvg.h File Reference
#include <stdio.h>

Go to the source code of this file.

Classes

struct  NSVGgradientStop
 
struct  NSVGgradient
 
struct  NSVGpaint
 
struct  NSVGpath
 
struct  NSVGshape
 
struct  NSVGimage
 

Typedefs

typedef struct NSVGgradientStop NSVGgradientStop
 
typedef struct NSVGgradient NSVGgradient
 
typedef struct NSVGpaint NSVGpaint
 
typedef struct NSVGpath NSVGpath
 
typedef struct NSVGshape NSVGshape
 
typedef struct NSVGimage NSVGimage
 

Enumerations

enum  NSVGpaintType { NSVG_PAINT_NONE = 0, NSVG_PAINT_COLOR = 1, NSVG_PAINT_LINEAR_GRADIENT = 2, NSVG_PAINT_RADIAL_GRADIENT = 3 }
 
enum  NSVGspreadType { NSVG_SPREAD_PAD = 0, NSVG_SPREAD_REFLECT = 1, NSVG_SPREAD_REPEAT = 2 }
 
enum  NSVGlineJoin { NSVG_JOIN_MITER = 0, NSVG_JOIN_ROUND = 1, NSVG_JOIN_BEVEL = 2 }
 
enum  NSVGlineCap { NSVG_CAP_BUTT = 0, NSVG_CAP_ROUND = 1, NSVG_CAP_SQUARE = 2 }
 
enum  NSVGfillRule { NSVG_FILLRULE_NONZERO = 0, NSVG_FILLRULE_EVENODD = 1 }
 
enum  NSVGflags { NSVG_FLAGS_VISIBLE = 0x01 }
 

Functions

NSVGimagensvgParseFromFile (FILE *fp, const char *units, float dpi)
 
NSVGimagensvgParse (char *input, const char *units, float dpi)
 
NSVGpathnsvgDuplicatePath (NSVGpath *p)
 
void nsvgDelete (NSVGimage *image)
 

Typedef Documentation

typedef struct NSVGgradient NSVGgradient
typedef struct NSVGimage NSVGimage
typedef struct NSVGpaint NSVGpaint
typedef struct NSVGpath NSVGpath
typedef struct NSVGshape NSVGshape

Enumeration Type Documentation

Enumerator
NSVG_FILLRULE_NONZERO 
NSVG_FILLRULE_EVENODD 

Definition at line 96 of file nanosvg.h.

enum NSVGflags
Enumerator
NSVG_FLAGS_VISIBLE 

Definition at line 101 of file nanosvg.h.

101  {
102  NSVG_FLAGS_VISIBLE = 0x01
103 };
Enumerator
NSVG_CAP_BUTT 
NSVG_CAP_ROUND 
NSVG_CAP_SQUARE 

Definition at line 90 of file nanosvg.h.

90  {
91  NSVG_CAP_BUTT = 0,
92  NSVG_CAP_ROUND = 1,
93  NSVG_CAP_SQUARE = 2
94 };
Enumerator
NSVG_JOIN_MITER 
NSVG_JOIN_ROUND 
NSVG_JOIN_BEVEL 

Definition at line 84 of file nanosvg.h.

84  {
85  NSVG_JOIN_MITER = 0,
86  NSVG_JOIN_ROUND = 1,
87  NSVG_JOIN_BEVEL = 2
88 };
Enumerator
NSVG_PAINT_NONE 
NSVG_PAINT_COLOR 
NSVG_PAINT_LINEAR_GRADIENT 
NSVG_PAINT_RADIAL_GRADIENT 

Definition at line 71 of file nanosvg.h.

Enumerator
NSVG_SPREAD_PAD 
NSVG_SPREAD_REFLECT 
NSVG_SPREAD_REPEAT 

Definition at line 78 of file nanosvg.h.

Function Documentation

void nsvgDelete ( NSVGimage image)

Definition at line 3752 of file nanosvg.cpp.

References NSVGshape::fill, NSVGshape::next, nsvg__deletePaint(), nsvg__deletePaths(), NSVGshape::paths, NSVGimage::shapes, and NSVGshape::stroke.

Referenced by nsvg__deleteParser(), and nsvgParseFromFile().

3753 {
3754  NSVGshape* snext, * shape;
3755 
3756  if( image == NULL )
3757  return;
3758 
3759  shape = image->shapes;
3760 
3761  while( shape != NULL )
3762  {
3763  snext = shape->next;
3764  nsvg__deletePaths( shape->paths );
3765  nsvg__deletePaint( &shape->fill );
3766  nsvg__deletePaint( &shape->stroke );
3767  free( shape );
3768  shape = snext;
3769  }
3770 
3771  free( image );
3772 }
NSVGpath * paths
Definition: nanosvg.h:151
NSVGpaint fill
Definition: nanosvg.h:138
struct NSVGshape * next
Definition: nanosvg.h:152
static void nsvg__deletePaint(NSVGpaint *paint)
Definition: nanosvg.cpp:630
NSVGpaint stroke
Definition: nanosvg.h:139
NSVGshape * shapes
Definition: nanosvg.h:159
static void nsvg__deletePaths(NSVGpath *path)
Definition: nanosvg.cpp:615
NSVGpath* nsvgDuplicatePath ( NSVGpath p)

Definition at line 3712 of file nanosvg.cpp.

References NSVGpath::bounds, NSVGpath::closed, NSVGpath::npts, and NSVGpath::pts.

3713 {
3714  NSVGpath* res = NULL;
3715 
3716  if( p == NULL )
3717  return NULL;
3718 
3719  res = (NSVGpath*) malloc( sizeof(NSVGpath) );
3720 
3721  if( res == NULL )
3722  goto error;
3723 
3724  memset( res, 0, sizeof(NSVGpath) );
3725 
3726  res->pts = (float*) malloc( p->npts * 2 * sizeof(float) );
3727 
3728  if( res->pts == NULL )
3729  goto error;
3730 
3731  memcpy( res->pts, p->pts, p->npts * sizeof(float) * 2 );
3732  res->npts = p->npts;
3733 
3734  memcpy( res->bounds, p->bounds, sizeof(p->bounds) );
3735 
3736  res->closed = p->closed;
3737 
3738  return res;
3739 
3740 error:
3741 
3742  if( res != NULL )
3743  {
3744  free( res->pts );
3745  free( res );
3746  }
3747 
3748  return NULL;
3749 }
float * pts
Definition: nanosvg.h:128
int npts
Definition: nanosvg.h:129
float bounds[4]
Definition: nanosvg.h:131
char closed
Definition: nanosvg.h:130
NSVGimage* nsvgParse ( char *  input,
const char *  units,
float  dpi 
)

Definition at line 3642 of file nanosvg.cpp.

References NSVGparser::dpi, NSVGparser::image, nsvg__content(), nsvg__createParser(), nsvg__deleteParser(), nsvg__endElement(), nsvg__parseXML(), nsvg__scaleToViewbox(), and nsvg__startElement().

Referenced by nsvgParseFromFile().

3643 {
3644  NSVGparser* p;
3645  NSVGimage* ret = 0;
3646 
3647  p = nsvg__createParser();
3648 
3649  if( p == NULL )
3650  {
3651  return NULL;
3652  }
3653 
3654  p->dpi = dpi;
3655 
3657 
3658  // Scale to viewBox
3659  nsvg__scaleToViewbox( p, units );
3660 
3661  ret = p->image;
3662  p->image = NULL;
3663 
3664  nsvg__deleteParser( p );
3665 
3666  return ret;
3667 }
int nsvg__parseXML(char *input, void(*startelCb)(void *ud, const char *el, const char **attr), void(*endelCb)(void *ud, const char *el), void(*contentCb)(void *ud, const char *s), void *ud)
Definition: nanosvg.cpp:229
static void nsvg__content(void *ud, const char *s)
Definition: nanosvg.cpp:3464
static void nsvg__startElement(void *ud, const char *el, const char **attr)
Definition: nanosvg.cpp:3349
static void nsvg__scaleToViewbox(NSVGparser *p, const char *units)
Definition: nanosvg.cpp:3523
NSVGimage * image
Definition: nanosvg.cpp:363
static void nsvg__deleteParser(NSVGparser *p)
Definition: nanosvg.cpp:651
static void nsvg__endElement(void *ud, const char *el)
Definition: nanosvg.cpp:3445
static NSVGparser * nsvg__createParser()
Definition: nanosvg.cpp:564
float dpi
Definition: nanosvg.cpp:368
NSVGimage* nsvgParseFromFile ( FILE *  fp,
const char *  units,
float  dpi 
)

Definition at line 3670 of file nanosvg.cpp.

References nsvgDelete(), and nsvgParse().

Referenced by SVG_IMPORT_PLUGIN::Load().

3671 {
3672  size_t size;
3673  char* data = NULL;
3674  NSVGimage* image = NULL;
3675 
3676  if( !fp )
3677  return NULL;
3678 
3679  fseek( fp, 0, SEEK_END );
3680  size = ftell( fp );
3681  fseek( fp, 0, SEEK_SET );
3682  data = (char*) malloc( size + 1 );
3683 
3684  if( data == NULL )
3685  goto error;
3686 
3687  if( fread( data, 1, size, fp ) != size )
3688  goto error;
3689 
3690  data[size] = '\0'; // Must be null terminated.
3691  fclose( fp );
3692  image = nsvgParse( data, units, dpi );
3693  free( data );
3694 
3695  return image;
3696 
3697 error:
3698 
3699  if( fp )
3700  fclose( fp );
3701 
3702  if( data )
3703  free( data );
3704 
3705  if( image )
3706  nsvgDelete( image );
3707 
3708  return NULL;
3709 }
NSVGimage * nsvgParse(char *input, const char *units, float dpi)
Definition: nanosvg.cpp:3642
void nsvgDelete(NSVGimage *image)
Definition: nanosvg.cpp:3752