Skip to content

Commit

Permalink
Make sure nanosvg functions are static so they aren't exported throug…
Browse files Browse the repository at this point in the history
…h the SDL_image static library
  • Loading branch information
slouken committed Oct 5, 2019
1 parent 3d58952 commit 31ce11c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
1 change: 1 addition & 0 deletions IMG_svg.c
Expand Up @@ -67,6 +67,7 @@
#endif
#undef HAVE_STDIO_H

#define NSVG_EXPORT static
#define NANOSVG_IMPLEMENTATION
#include "nanosvg.h"
#define NANOSVGRAST_IMPLEMENTATION
Expand Down
18 changes: 11 additions & 7 deletions nanosvg.h
Expand Up @@ -29,6 +29,10 @@
#ifndef NANOSVG_H
#define NANOSVG_H

#ifndef NSVG_EXPORT
#define NSVG_EXPORT
#endif

#ifdef __cplusplus
extern "C" {
#endif
Expand Down Expand Up @@ -161,14 +165,14 @@ typedef struct NSVGimage
} NSVGimage;

// Parses SVG file from a file, returns SVG image as paths.
NSVGimage* nsvgParseFromFile(const char* filename, const char* units, float dpi);
NSVG_EXPORT NSVGimage* nsvgParseFromFile(const char* filename, const char* units, float dpi);

// Parses SVG file from a null terminated string, returns SVG image as paths.
// Important note: changes the string.
NSVGimage* nsvgParse(char* input, const char* units, float dpi);
NSVG_EXPORT NSVGimage* nsvgParse(char* input, const char* units, float dpi);

// Deletes list of paths.
void nsvgDelete(NSVGimage* image);
NSVG_EXPORT void nsvgDelete(NSVGimage* image);

#ifdef __cplusplus
}
Expand Down Expand Up @@ -1257,7 +1261,7 @@ typedef struct NSVGNamedColor {
unsigned int color;
} NSVGNamedColor;

NSVGNamedColor nsvg__colors[] = {
static NSVGNamedColor nsvg__colors[] = {

{ "red", NSVG_RGB(255, 0, 0) },
{ "green", NSVG_RGB( 0, 128, 0) },
Expand Down Expand Up @@ -2961,7 +2965,7 @@ static void nsvg__scaleToViewbox(NSVGparser* p, const char* units)
}
}

NSVGimage* nsvgParse(char* input, const char* units, float dpi)
NSVG_EXPORT NSVGimage* nsvgParse(char* input, const char* units, float dpi)
{
NSVGparser* p;
NSVGimage* ret = 0;
Expand All @@ -2986,7 +2990,7 @@ NSVGimage* nsvgParse(char* input, const char* units, float dpi)
}

#ifdef HAVE_STDIO_H
NSVGimage* nsvgParseFromFile(const char* filename, const char* units, float dpi)
NSVG_EXPORT NSVGimage* nsvgParseFromFile(const char* filename, const char* units, float dpi)
{
FILE* fp = NULL;
size_t size;
Expand Down Expand Up @@ -3016,7 +3020,7 @@ NSVGimage* nsvgParseFromFile(const char* filename, const char* units, float dpi)
}
#endif /* HAVE_STDIO_H */

void nsvgDelete(NSVGimage* image)
NSVG_EXPORT void nsvgDelete(NSVGimage* image)
{
NSVGshape *snext, *shape;
if (image == NULL) return;
Expand Down
23 changes: 15 additions & 8 deletions nanosvgrast.h
Expand Up @@ -25,6 +25,10 @@
#ifndef NANOSVGRAST_H
#define NANOSVGRAST_H

#ifndef NSVG_EXPORT
#define NSVG_EXPORT
#endif

#ifdef __cplusplus
extern "C" {
#endif
Expand All @@ -44,7 +48,7 @@ typedef struct NSVGrasterizer NSVGrasterizer;
*/

// Allocated rasterizer context.
NSVGrasterizer* nsvgCreateRasterizer(void);
NSVG_EXPORT NSVGrasterizer* nsvgCreateRasterizer(void);

// Rasterizes SVG image, returns RGBA image (non-premultiplied alpha)
// r - pointer to rasterizer context
Expand All @@ -55,12 +59,12 @@ NSVGrasterizer* nsvgCreateRasterizer(void);
// w - width of the image to render
// h - height of the image to render
// stride - number of bytes per scaleline in the destination buffer
void nsvgRasterize(NSVGrasterizer* r,
NSVGimage* image, float tx, float ty, float scale,
unsigned char* dst, int w, int h, int stride);
NSVG_EXPORT void nsvgRasterize(NSVGrasterizer* r,
NSVGimage* image, float tx, float ty, float scale,
unsigned char* dst, int w, int h, int stride);

// Deletes rasterizer context.
void nsvgDeleteRasterizer(NSVGrasterizer*);
NSVG_EXPORT void nsvgDeleteRasterizer(NSVGrasterizer*);


#ifdef __cplusplus
Expand All @@ -70,6 +74,9 @@ void nsvgDeleteRasterizer(NSVGrasterizer*);
#endif // NANOSVGRAST_H

#ifdef NANOSVGRAST_IMPLEMENTATION
#ifndef NSVG_EXPORT
#define NSVG_EXPORT
#endif

/*
#include <math.h>
Expand Down Expand Up @@ -145,7 +152,7 @@ struct NSVGrasterizer
int width, height, stride;
};

NSVGrasterizer* nsvgCreateRasterizer()
NSVG_EXPORT NSVGrasterizer* nsvgCreateRasterizer()
{
NSVGrasterizer* r = (NSVGrasterizer*)malloc(sizeof(NSVGrasterizer));
if (r == NULL) goto error;
Expand All @@ -161,7 +168,7 @@ NSVGrasterizer* nsvgCreateRasterizer()
return NULL;
}

void nsvgDeleteRasterizer(NSVGrasterizer* r)
NSVG_EXPORT void nsvgDeleteRasterizer(NSVGrasterizer* r)
{
NSVGmemPage* p;

Expand Down Expand Up @@ -1360,7 +1367,7 @@ static void dumpEdges(NSVGrasterizer* r, const char* name)
}
*/

void nsvgRasterize(NSVGrasterizer* r,
NSVG_EXPORT void nsvgRasterize(NSVGrasterizer* r,
NSVGimage* image, float tx, float ty, float scale,
unsigned char* dst, int w, int h, int stride)
{
Expand Down

0 comments on commit 31ce11c

Please sign in to comment.