Skip to content
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
27 changes: 21 additions & 6 deletions src/Image.cc
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,6 @@ cairo_surface_t *Image::surface() {

cairo_status_t status = renderSVGToSurface();
if (status != CAIRO_STATUS_SUCCESS) {
g_object_unref(_rsvg);
Napi::Error::New(env, cairo_status_to_string(status)).ThrowAsJavaScriptException();

return NULL;
Expand Down Expand Up @@ -1473,16 +1472,19 @@ Image::loadSVGFromBuffer(uint8_t *buf, unsigned len) {
return CAIRO_STATUS_READ_ERROR;
}

double d_width;
double d_height;
double d_width = 0;
double d_height = 0;

rsvg_handle_get_intrinsic_size_in_pixels(_rsvg, &d_width, &d_height);
gboolean has_size = rsvg_handle_get_intrinsic_size_in_pixels(_rsvg, &d_width, &d_height);

width = naturalWidth = d_width;
height = naturalHeight = d_height;
width = naturalWidth = has_size ? d_width : 0;
height = naturalHeight = has_size ? d_height : 0;

if (width <= 0 || height <= 0) {
this->errorInfo.set("Width and height must be set on the svg element");
g_object_unref(_rsvg);
_rsvg = NULL;
_is_svg = false;
return CAIRO_STATUS_READ_ERROR;
}

Expand All @@ -1501,13 +1503,22 @@ Image::renderSVGToSurface() {
status = cairo_surface_status(_surface);
if (status != CAIRO_STATUS_SUCCESS) {
g_object_unref(_rsvg);
_rsvg = NULL;
cairo_surface_destroy(_surface);
_surface = NULL;
_is_svg = false;
return status;
}

cairo_t *cr = cairo_create(_surface);
status = cairo_status(cr);
if (status != CAIRO_STATUS_SUCCESS) {
g_object_unref(_rsvg);
_rsvg = NULL;
cairo_destroy(cr);
cairo_surface_destroy(_surface);
_surface = NULL;
_is_svg = false;
return status;
}

Expand All @@ -1520,7 +1531,11 @@ Image::renderSVGToSurface() {
gboolean render_ok = rsvg_handle_render_document(_rsvg, cr, &viewport, nullptr);
if (!render_ok) {
g_object_unref(_rsvg);
_rsvg = NULL;
cairo_destroy(cr);
cairo_surface_destroy(_surface);
_surface = NULL;
_is_svg = false;
return CAIRO_STATUS_READ_ERROR; // or WRITE?
}

Expand Down