Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow custom XML parsers #157

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions src/nanosvg.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,22 @@ typedef struct NSVGimage
NSVGshape* shapes; // Linked list of shapes in the image.
} NSVGimage;

typedef int (*NSVGparseXML)(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);

// Parses SVG file from a file, returns SVG image as paths.
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);

// Like nsvgParse, but using the given custom XML parser.
NSVGimage* nsvgParseEx(char* input, const char* units, float dpi, NSVGparseXML parser);

// Duplicates a path.
NSVGpath* nsvgDuplicatePath(NSVGpath* p);

Expand Down Expand Up @@ -2873,7 +2882,7 @@ static void nsvg__scaleToViewbox(NSVGparser* p, const char* units)
}
}

NSVGimage* nsvgParse(char* input, const char* units, float dpi)
NSVGimage* nsvgParseEx(char* input, const char* units, float dpi, NSVGparseXML parse)
{
NSVGparser* p;
NSVGimage* ret = 0;
Expand All @@ -2884,7 +2893,7 @@ NSVGimage* nsvgParse(char* input, const char* units, float dpi)
}
p->dpi = dpi;

nsvg__parseXML(input, nsvg__startElement, nsvg__endElement, nsvg__content, p);
parse(input, nsvg__startElement, nsvg__endElement, nsvg__content, p);

// Scale to viewBox
nsvg__scaleToViewbox(p, units);
Expand All @@ -2897,6 +2906,11 @@ NSVGimage* nsvgParse(char* input, const char* units, float dpi)
return ret;
}

NSVGimage* nsvgParse(char* input, const char* units, float dpi)
{
return nsvgParseEx(input, units, dpi, nsvg__parseXML);
}

NSVGimage* nsvgParseFromFile(const char* filename, const char* units, float dpi)
{
FILE* fp = NULL;
Expand Down