diff --git a/src/nanosvg.h b/src/nanosvg.h index 5077f275..eaa6ae8e 100644 --- a/src/nanosvg.h +++ b/src/nanosvg.h @@ -165,6 +165,9 @@ typedef struct NSVGimage // 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 ram, returns SVG image. +NSVGimage* nsvgParseFromRam(const uint8_t* file_data, int file_data_size, 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); @@ -2960,6 +2963,25 @@ NSVGimage* nsvgParseFromFile(const char* filename, const char* units, float dpi) return NULL; } +NSVGimage* nsvgParseFromRam(const uint8_t* file_data, int file_data_size, const char* units, float dpi) +{ + char* data = NULL; + NSVGimage* image = NULL; + + data = (char*)malloc(file_data_size + 1); + if (data == NULL) goto error; + memcpy(data, file_data, file_data_size); + data[file_data_size] = '\0'; // Must be null terminated. + image = nsvgParse(data, units, dpi); + free(data); + return image; + +error: + if (data) free(data); + if (image) nsvgDelete(image); + return NULL; +} + NSVGpath* nsvgDuplicatePath(NSVGpath* p) { NSVGpath* res = NULL;