Skip to content
This repository was archived by the owner on Sep 9, 2019. It is now read-only.
Open
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"<!(node -e \"require('nan')\")"
],
"variables": {
"packages": "librsvg-2.0 cairo-png cairo-pdf cairo-svg",
"packages": "librsvg-2.0 cairo-png cairo-pdf cairo-ps cairo-svg",
"conditions": [
[ "OS!='win'", {
"libraries": "<!(<(pkg_env) pkg-config --libs-only-l <(packages))",
Expand All @@ -36,6 +36,7 @@
[ "OS!='mac' and OS!='win'", {
"cflags": [
"<@(cflags)",
"-fpermissive",
"-std=c++0x"
],
"ldflags": [
Expand Down
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

* PNG
* PDF
* PS
* SVG
* Raw memory buffer image

Expand Down
3 changes: 3 additions & 0 deletions src/Enums.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ render_format_t RenderFormatFromString(const char* formatString) {
return RENDER_FORMAT_JPEG;
} else if (std::strcmp(formatString, "pdf") == 0) {
return RENDER_FORMAT_PDF;
} else if (std::strcmp(formatString, "ps") == 0) {
return RENDER_FORMAT_PS;
} else if (std::strcmp(formatString, "svg") == 0) {
return RENDER_FORMAT_SVG;
} else if (std::strcmp(formatString, "vips") == 0) {
Expand All @@ -36,6 +38,7 @@ Handle<Value> RenderFormatToString(render_format_t format) {
format == RENDER_FORMAT_PNG ? "png" :
format == RENDER_FORMAT_JPEG ? "jpeg" :
format == RENDER_FORMAT_PDF ? "pdf" :
format == RENDER_FORMAT_PS ? "ps" :
format == RENDER_FORMAT_SVG ? "svg" :
format == RENDER_FORMAT_VIPS ? "vips" :
NULL;
Expand Down
5 changes: 3 additions & 2 deletions src/Enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ typedef enum {
RENDER_FORMAT_PNG = 1,
RENDER_FORMAT_JPEG = 2,
RENDER_FORMAT_PDF = 3,
RENDER_FORMAT_SVG = 4,
RENDER_FORMAT_VIPS = 5
RENDER_FORMAT_PS = 4,
RENDER_FORMAT_SVG = 5,
RENDER_FORMAT_VIPS = 6
} render_format_t;

render_format_t RenderFormatFromString(const char* formatString);
Expand Down
21 changes: 17 additions & 4 deletions src/Rsvg.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "Enums.h"
#include <node_buffer.h>
#include <cairo-pdf.h>
#include <cairo-ps.h>
#include <cairo-svg.h>
#include <string>
#include <iostream>
Expand Down Expand Up @@ -82,15 +83,24 @@ NAN_METHOD(Rsvg::New) {
gsize length = Buffer::Length(ARGVAR[0]);

GError* error = NULL;
handle = rsvg_handle_new_from_data(buffer, length, &error);

//handle = rsvg_handle_new_from_data(buffer, length, &error);
handle = rsvg_handle_new_with_flags((RsvgHandleFlags)RSVG_HANDLE_FLAG_UNLIMITED+RSVG_HANDLE_FLAG_KEEP_IMAGE_DATA);
rsvg_handle_write(handle, buffer, length, &error);
if (error) {
Nan::ThrowError(error->message);
g_error_free(error);
return ARGVAR.GetReturnValue().Set(Nan::Undefined());
}
error = NULL;
rsvg_handle_close(handle, &error);
if (error) {
Nan::ThrowError(error->message);
g_error_free(error);
return ARGVAR.GetReturnValue().Set(Nan::Undefined());
}

} else {
handle = rsvg_handle_new();
handle = rsvg_handle_new_with_flags((RsvgHandleFlags)RSVG_HANDLE_FLAG_UNLIMITED+RSVG_HANDLE_FLAG_KEEP_IMAGE_DATA);
}
// Error handling.
if (!handle) {
Expand Down Expand Up @@ -313,7 +323,8 @@ NAN_METHOD(Rsvg::Render) {
return ARGVAR.GetReturnValue().Set(Nan::Undefined());
} else if (
renderFormat == RENDER_FORMAT_SVG ||
renderFormat == RENDER_FORMAT_PDF) {
renderFormat == RENDER_FORMAT_PDF ||
renderFormat == RENDER_FORMAT_PS) {
pixelFormat = CAIRO_FORMAT_INVALID;
} else if (renderFormat == RENDER_FORMAT_VIPS) {
Nan::ThrowError("Format not supported: VIPS");
Expand Down Expand Up @@ -369,6 +380,8 @@ NAN_METHOD(Rsvg::Render) {
#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 10, 0)
cairo_pdf_surface_restrict_to_version(surface, CAIRO_PDF_VERSION_1_4);
#endif
} else if (renderFormat == RENDER_FORMAT_PS) {
surface = cairo_ps_surface_create_for_stream(GetDataChunks, &data, width, height);
} else {
surface = cairo_image_surface_create(pixelFormat, width, height);
}
Expand Down