@@ -86,11 +86,6 @@ Image::Image(const Napi::CallbackInfo& info) : ObjectWrap<Image>(info), env(info
8686 width = height = 0 ;
8787 naturalWidth = naturalHeight = 0 ;
8888 state = DEFAULT;
89- #ifdef HAVE_RSVG
90- _rsvg = NULL ;
91- _is_svg = false ;
92- _svg_last_width = _svg_last_height = 0 ;
93- #endif
9489}
9590
9691/*
@@ -210,13 +205,6 @@ Image::clearData() {
210205 free (filename);
211206 filename = NULL ;
212207
213- #ifdef HAVE_RSVG
214- if (_rsvg != NULL ) {
215- g_object_unref (_rsvg);
216- _rsvg = NULL ;
217- }
218- #endif
219-
220208 width = height = 0 ;
221209 naturalWidth = naturalHeight = 0 ;
222210 state = DEFAULT;
@@ -310,18 +298,6 @@ Image::loadFromBuffer(uint8_t *buf, unsigned len) {
310298#endif
311299 }
312300
313- // confirm svg using first 1000 chars
314- // if a very long comment precedes the root <svg> tag, isSVG returns false
315- unsigned head_len = (len < 1000 ? len : 1000 );
316- if (isSVG (buf, head_len)) {
317- #ifdef HAVE_RSVG
318- return loadSVGFromBuffer (buf, len);
319- #else
320- this ->errorInfo .set (" node-canvas was built without SVG support" );
321- return CAIRO_STATUS_READ_ERROR;
322- #endif
323- }
324-
325301 if (isBMP (buf, len))
326302 return loadBMPFromBuffer (buf, len);
327303
@@ -397,22 +373,6 @@ Image::loaded() {
397373 * Returns this image's surface.
398374 */
399375cairo_surface_t *Image::surface () {
400- #ifdef HAVE_RSVG
401- if (_is_svg && (_svg_last_width != width || _svg_last_height != height)) {
402- if (_surface != NULL ) {
403- cairo_surface_destroy (_surface);
404- _surface = NULL ;
405- }
406-
407- cairo_status_t status = renderSVGToSurface ();
408- if (status != CAIRO_STATUS_SUCCESS) {
409- g_object_unref (_rsvg);
410- Napi::Error::New (env, cairo_status_to_string (status)).ThrowAsJavaScriptException ();
411-
412- return NULL ;
413- }
414- }
415- #endif
416376 return _surface;
417377}
418378
@@ -462,31 +422,8 @@ Image::loadSurface() {
462422#endif
463423 }
464424
465- // confirm svg using first 1000 chars
466- // if a very long comment precedes the root <svg> tag, isSVG returns false
467- uint8_t head[1000 ] = {0 };
468- fseek (stream, 0 , SEEK_END);
469- long len = ftell (stream);
470- unsigned head_len = (len < 1000 ? len : 1000 );
471- unsigned head_size = head_len * sizeof (uint8_t );
472- rewind (stream);
473- if (head_size != fread (&head, 1 , head_size, stream)) {
474- fclose (stream);
475- return CAIRO_STATUS_READ_ERROR;
476- }
477- rewind (stream);
478- if (isSVG (head, head_len)) {
479- #ifdef HAVE_RSVG
480- return loadSVG (stream);
481- #else
482- this ->errorInfo .set (" node-canvas was built without SVG support" );
483- return CAIRO_STATUS_READ_ERROR;
484- #endif
485- }
486-
487425 if (isBMP (buf, 2 ))
488426 return loadBMP (stream);
489-
490427 fclose (stream);
491428
492429 this ->errorInfo .set (" Unsupported image type" );
@@ -1460,115 +1397,6 @@ Image::rotatePixels(uint8_t* pixels, int width, int height, int channels,
14601397
14611398#endif /* HAVE_JPEG */
14621399
1463- #ifdef HAVE_RSVG
1464-
1465- /*
1466- * Load SVG from buffer
1467- */
1468-
1469- cairo_status_t
1470- Image::loadSVGFromBuffer (uint8_t *buf, unsigned len) {
1471- _is_svg = true ;
1472-
1473- if (NULL == (_rsvg = rsvg_handle_new_from_data (buf, len, nullptr ))) {
1474- return CAIRO_STATUS_READ_ERROR;
1475- }
1476-
1477- double d_width;
1478- double d_height;
1479-
1480- rsvg_handle_get_intrinsic_size_in_pixels (_rsvg, &d_width, &d_height);
1481-
1482- width = naturalWidth = d_width;
1483- height = naturalHeight = d_height;
1484-
1485- if (width <= 0 || height <= 0 ) {
1486- this ->errorInfo .set (" Width and height must be set on the svg element" );
1487- return CAIRO_STATUS_READ_ERROR;
1488- }
1489-
1490- return renderSVGToSurface ();
1491- }
1492-
1493- /*
1494- * Renders the Rsvg handle to this image's surface
1495- */
1496- cairo_status_t
1497- Image::renderSVGToSurface () {
1498- cairo_status_t status;
1499-
1500- _surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
1501-
1502- status = cairo_surface_status (_surface);
1503- if (status != CAIRO_STATUS_SUCCESS) {
1504- g_object_unref (_rsvg);
1505- return status;
1506- }
1507-
1508- cairo_t *cr = cairo_create (_surface);
1509- status = cairo_status (cr);
1510- if (status != CAIRO_STATUS_SUCCESS) {
1511- g_object_unref (_rsvg);
1512- return status;
1513- }
1514-
1515- RsvgRectangle viewport = {
1516- 0 , // x
1517- 0 , // y
1518- static_cast <double >(width),
1519- static_cast <double >(height)
1520- };
1521- gboolean render_ok = rsvg_handle_render_document (_rsvg, cr, &viewport, nullptr );
1522- if (!render_ok) {
1523- g_object_unref (_rsvg);
1524- cairo_destroy (cr);
1525- return CAIRO_STATUS_READ_ERROR; // or WRITE?
1526- }
1527-
1528- cairo_destroy (cr);
1529-
1530- _svg_last_width = width;
1531- _svg_last_height = height;
1532-
1533- return status;
1534- }
1535-
1536- /*
1537- * Load SVG
1538- */
1539-
1540- cairo_status_t
1541- Image::loadSVG (FILE *stream) {
1542- _is_svg = true ;
1543-
1544- struct stat s;
1545- int fd = fileno (stream);
1546-
1547- // stat
1548- if (fstat (fd, &s) < 0 ) {
1549- fclose (stream);
1550- return CAIRO_STATUS_READ_ERROR;
1551- }
1552-
1553- uint8_t *buf = (uint8_t *) malloc (s.st_size );
1554-
1555- if (!buf) {
1556- fclose (stream);
1557- return CAIRO_STATUS_NO_MEMORY;
1558- }
1559-
1560- size_t read = fread (buf, s.st_size , 1 , stream);
1561- fclose (stream);
1562-
1563- cairo_status_t result = CAIRO_STATUS_READ_ERROR;
1564- if (1 == read) result = loadSVGFromBuffer (buf, s.st_size );
1565- free (buf);
1566-
1567- return result;
1568- }
1569-
1570- #endif /* HAVE_RSVG */
1571-
15721400/*
15731401 * Load BMP from buffer.
15741402 */
@@ -1641,7 +1469,7 @@ cairo_status_t Image::loadBMP(FILE *stream){
16411469}
16421470
16431471/*
1644- * Return UNKNOWN, SVG, GIF, JPEG, or PNG based on the filename.
1472+ * Return UNKNOWN, GIF, JPEG, or PNG based on the filename.
16451473 */
16461474
16471475Image::type
@@ -1652,7 +1480,6 @@ Image::extension(const char *filename) {
16521480 if (len >= 4 && 0 == strcmp (" .gif" , filename - 4 )) return Image::GIF;
16531481 if (len >= 4 && 0 == strcmp (" .jpg" , filename - 4 )) return Image::JPEG;
16541482 if (len >= 4 && 0 == strcmp (" .png" , filename - 4 )) return Image::PNG;
1655- if (len >= 4 && 0 == strcmp (" .svg" , filename - 4 )) return Image::SVG;
16561483 return Image::UNKNOWN;
16571484}
16581485
@@ -1683,27 +1510,6 @@ Image::isPNG(uint8_t *data) {
16831510 return ' P' == data[1 ] && ' N' == data[2 ] && ' G' == data[3 ];
16841511}
16851512
1686- /*
1687- * Skip "<?" and "<!" tags to test if root tag starts "<svg"
1688- */
1689- int
1690- Image::isSVG (uint8_t *data, unsigned len) {
1691- for (unsigned i = 3 ; i < len; i++) {
1692- if (' <' == data[i-3 ]) {
1693- switch (data[i-2 ]) {
1694- case ' ?' :
1695- case ' !' :
1696- break ;
1697- case ' s' :
1698- return (' v' == data[i-1 ] && ' g' == data[i]);
1699- default :
1700- return false ;
1701- }
1702- }
1703- }
1704- return false ;
1705- }
1706-
17071513/*
17081514 * Check for valid BMP signatures
17091515 */
0 commit comments