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

Add nsvgParseFromRam function. #208

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
22 changes: 22 additions & 0 deletions src/nanosvg.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down