[librsvg] Move rsvg_handle_get_pixbuf*() to rsvg-handle.c



commit 724e28216093b7ffec0b0b02bb10addbdab0cfcc
Author: Federico Mena Quintero <federico gnome org>
Date:   Thu Feb 1 18:41:59 2018 -0600

    Move rsvg_handle_get_pixbuf*() to rsvg-handle.c
    
    This lets us remove rsvg.c

 Makefile.am   |   1 -
 rsvg-handle.c |  74 +++++++++++++++++++++++++++++++++++++
 rsvg.c        | 117 ----------------------------------------------------------
 3 files changed, 74 insertions(+), 118 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index ccd4878..e2f3244 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -61,7 +61,6 @@ librsvg_@RSVG_API_MAJOR_VERSION@_la_SOURCES = \
        rsvg-text.h             \
        rsvg-xml.c              \
        rsvg-xml.h              \
-       rsvg.c                  \
        rsvg.h                  \
        $(NULL)
 
diff --git a/rsvg-handle.c b/rsvg-handle.c
index 1083f81..a728311 100644
--- a/rsvg-handle.c
+++ b/rsvg-handle.c
@@ -1018,6 +1018,80 @@ rsvg_handle_has_sub (RsvgHandle * handle,
     return rsvg_defs_lookup (handle->priv->defs, id) != NULL;
 }
 
+/**
+ * rsvg_handle_get_pixbuf_sub:
+ * @handle: An #RsvgHandle
+ * @id: (nullable): An element's id within the SVG, starting with "##", for
+ * example, "##layer1"; or %NULL to use the whole SVG.
+ *
+ * Returns the pixbuf loaded by @handle.  The pixbuf returned will be reffed, so
+ * the caller of this function must assume that ref.  If insufficient data has
+ * been read to create the pixbuf, or an error occurred in loading, then %NULL
+ * will be returned.  Note that the pixbuf may not be complete until
+ * @rsvg_handle_close has been called.
+ *
+ * Returns: (transfer full) (nullable): the pixbuf loaded by @handle, or %NULL.
+ *
+ * Since: 2.14
+ **/
+GdkPixbuf *
+rsvg_handle_get_pixbuf_sub (RsvgHandle * handle, const char *id)
+{
+    RsvgDimensionData dimensions;
+    GdkPixbuf *output = NULL;
+    cairo_surface_t *surface;
+    cairo_t *cr;
+
+    g_return_val_if_fail (handle != NULL, NULL);
+
+    if (handle->priv->state != RSVG_HANDLE_STATE_CLOSED_OK)
+        return NULL;
+
+    rsvg_handle_get_dimensions (handle, &dimensions);
+    if (!(dimensions.width && dimensions.height))
+        return NULL;
+
+    surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
+                                          dimensions.width, dimensions.height);
+    if (cairo_surface_status (surface) != CAIRO_STATUS_SUCCESS) {
+        cairo_surface_destroy (surface);
+        return NULL;
+    }
+
+    cr = cairo_create (surface);
+
+    if (!rsvg_handle_render_cairo_sub (handle, cr, id)) {
+        cairo_destroy (cr);
+        cairo_surface_destroy (surface);
+        return NULL;
+    }
+
+    cairo_destroy (cr);
+
+    output = rsvg_cairo_surface_to_pixbuf (surface);
+    cairo_surface_destroy (surface);
+
+    return output;
+}
+
+/**
+ * rsvg_handle_get_pixbuf:
+ * @handle: An #RsvgHandle
+ *
+ * Returns the pixbuf loaded by @handle.  The pixbuf returned will be reffed, so
+ * the caller of this function must assume that ref.  If insufficient data has
+ * been read to create the pixbuf, or an error occurred in loading, then %NULL
+ * will be returned.  Note that the pixbuf may not be complete until
+ * @rsvg_handle_close has been called.
+ *
+ * Returns: (transfer full) (nullable): the pixbuf loaded by @handle, or %NULL.
+ **/
+GdkPixbuf *
+rsvg_handle_get_pixbuf (RsvgHandle * handle)
+{
+    return rsvg_handle_get_pixbuf_sub (handle, NULL);
+}
+
 /**
  * rsvg_handle_set_dpi:
  * @handle: An #RsvgHandle


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]