[perl-Gnome2-Rsvg] Wrap new API
- From: Torsten Schönfeld <tsch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [perl-Gnome2-Rsvg] Wrap new API
- Date: Mon, 17 May 2010 21:59:17 +0000 (UTC)
commit e1d7e3837eb526d78488bdf9d82e46d28065da8c
Author: Torsten Schönfeld <kaffeetisch gmx de>
Date: Mon May 17 23:52:38 2010 +0200
Wrap new API
Specifically:
â?¢ rsvg_set_default_dpi_x_y
â?¢ rsvg_handle_new_from_data
â?¢ rsvg_handle_new_from_file
â?¢ rsvg_handle_get_pixbuf_sub
â?¢ rsvg_handle_get_dimensions
â?¢ rsvg_handle_get_dimensions_sub
â?¢ rsvg_handle_get_position_sub
â?¢ rsvg_handle_has_sub
â?¢ rsvg_handle_set_dpi_x_y
Also, rework the test slightly to be more robust.
t/Rsvg.t | 122 ++++++++++++++++++++++++++++++++++++++--------------
xs/Rsvg.xs | 140 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 229 insertions(+), 33 deletions(-)
---
diff --git a/t/Rsvg.t b/t/Rsvg.t
index 150067f..c011c84 100644
--- a/t/Rsvg.t
+++ b/t/Rsvg.t
@@ -1,8 +1,25 @@
#!/usr/bin/perl -w
use strict;
-use Test::More tests => 177;
+use Cwd qw(cwd);
+use Test::More;
use Gnome2::Rsvg;
+sub read_file {
+ open(SVG, '<', $_[0]) or return ();
+ my @data = <SVG>;
+ close(SVG);
+ return @data;
+}
+
+my $svg = "t/window.svg";
+my @svg_data = read_file($svg);
+
+plan @svg_data
+ ? (tests => @svg_data + 40)
+ : (skip_all => "Could not read test image $svg");
+
+###############################################################################
+
my $number = qr/^\d+$/;
my $been_here = 0;
@@ -18,46 +35,24 @@ my $size_callback = sub {
$height * 2);
};
-my $svg = "t/window.svg";
-my $svg_gz = "t/window.svg.gz";
-
-###############################################################################
-
my $handle = Gnome2::Rsvg::Handle -> new();
isa_ok($handle, "Gnome2::Rsvg::Handle");
$handle -> set_size_callback($size_callback);
-
-SKIP: {
- skip("couldn't open test image", 164)
- unless (open(SVG, $svg));
-
- while (<SVG>) {
- ok($handle -> write($_));
- }
-
- close(SVG);
-
- ok($handle -> close());
-
- my $pixbuf = $handle -> get_pixbuf();
- isa_ok($pixbuf, "Gtk2::Gdk::Pixbuf");
-
- like($pixbuf -> get_width(), $number);
- like($pixbuf -> get_height(), $number);
+foreach (@svg_data) {
+ ok($handle -> write($_));
}
-SKIP: {
- skip("get_title and get_desc are new in 2.4", 2)
- unless (Gnome2::Rsvg -> CHECK_VERSION(2, 4, 0));
+ok($handle -> close());
- is($handle -> get_title(), "Urgs");
- is($handle -> get_desc(), "Urgs");
-}
+my $pixbuf = $handle -> get_pixbuf();
+isa_ok($pixbuf, "Gtk2::Gdk::Pixbuf");
+
+like($pixbuf -> get_width(), $number);
+like($pixbuf -> get_height(), $number);
###############################################################################
-use Cwd qw(cwd);
my $uri = cwd() . "/" . $svg;
# Bug in librsvg: no relative paths?
@@ -73,11 +68,21 @@ foreach (Gnome2::Rsvg -> pixbuf_from_file($uri),
###############################################################################
SKIP: {
+ skip("get_title and get_desc are new in 2.4", 2)
+ unless (Gnome2::Rsvg -> CHECK_VERSION(2, 4, 0));
+
+ is($handle -> get_title(), "Urgs");
+ is($handle -> get_desc(), "Urgs");
+}
+
+SKIP: {
skip("set_default_dpi and set_dpi are new in 2.8", 0)
unless (Gnome2::Rsvg -> CHECK_VERSION(2, 8, 0));
Gnome2::Rsvg -> set_default_dpi(96);
+ Gnome2::Rsvg -> set_default_dpi_x_y(96, 96);
$handle -> set_dpi(96);
+ $handle -> set_dpi_x_y(96, 96);
}
SKIP: {
@@ -91,12 +96,63 @@ SKIP: {
}
SKIP: {
- skip("cairo integretaion is new in 2.14", 0)
+ skip('2.14 stuff', 11)
unless (Gnome2::Rsvg -> CHECK_VERSION(2, 14, 0));
+ is (eval { Gnome2::Rsvg::Handle -> new_from_data('<>'); }, undef);
+ isa_ok (Gnome2::Rsvg::Handle -> new_from_data('<svg></svg>'),
+ 'Gnome2::Rsvg::Handle');
+
+ is (eval { Gnome2::Rsvg::Handle -> new_from_file($0); }, undef);
+ my $handle = Gnome2::Rsvg::Handle -> new_from_file($uri);
+ isa_ok ($handle, 'Gnome2::Rsvg::Handle');
+
my $surface = Cairo::ImageSurface -> create("argb32", 10, 10);
my $cr = Cairo::Context -> create($surface);
$handle -> render_cairo($cr);
- $handle -> render_cairo_sub($cr, "linearGradient90");
+ $handle -> render_cairo_sub($cr, '#defs22');
+ $handle -> render_cairo_sub($cr, undef);
+
+ isa_ok ($handle -> get_pixbuf_sub('#path9'), 'Gtk2::Gdk::Pixbuf');
+ isa_ok ($handle -> get_pixbuf_sub(undef), 'Gtk2::Gdk::Pixbuf');
+
+ dimensions_ok($handle -> get_dimensions());
+}
+
+SKIP: {
+ skip('2.22 stuff', 13)
+ unless (Gnome2::Rsvg -> CHECK_VERSION(2, 22, 0));
+
+ my $handle = Gnome2::Rsvg::Handle -> new_from_file($svg);
+ isa_ok ($handle, 'Gnome2::Rsvg::Handle');
+
+ my $surface = Cairo::ImageSurface -> create('argb32', 10, 10);
+ my $cr = Cairo::Context -> create($surface);
+
+ ok($handle -> render_cairo($cr));
+ ok($handle -> render_cairo_sub($cr, "#defs22"));
+ ok($handle -> render_cairo_sub($cr, undef));
+
+ ok($handle -> has_sub('#path9'));
+ dimensions_ok($handle -> get_dimensions_sub('#path9'));
+ position_ok($handle -> get_position_sub('#path9'));
+}
+
+###############################################################################
+
+sub dimensions_ok {
+ my ($d) = @_;
+ isa_ok($d, 'HASH');
+ ok(exists $d->{width});
+ ok(exists $d->{height});
+ ok(exists $d->{em});
+ ok(exists $d->{ex});
+}
+
+sub position_ok {
+ my ($p) = @_;
+ isa_ok ($p, 'HASH');
+ ok(exists $p->{x});
+ ok(exists $p->{y});
}
diff --git a/xs/Rsvg.xs b/xs/Rsvg.xs
index a942043..4fa2ad1 100644
--- a/xs/Rsvg.xs
+++ b/xs/Rsvg.xs
@@ -64,6 +64,49 @@ rsvg2perl_size_func (gint *width,
/* ------------------------------------------------------------------------- */
+#if LIBRSVG_CHECK_VERSION (2, 14, 0)
+
+static SV *
+newSVRsvgDimensionData (RsvgDimensionData *data)
+{
+ HV *hv;
+
+ if (!data)
+ return &PL_sv_undef;
+
+ hv = newHV ();
+ hv_store (hv, "width", 5, newSViv (data->width), 0);
+ hv_store (hv, "height", 6, newSViv (data->height), 0);
+ hv_store (hv, "em", 2, newSVnv (data->em), 0);
+ hv_store (hv, "ex", 2, newSVnv (data->ex), 0);
+
+ return newRV_noinc ((SV *) hv);
+}
+
+#endif
+
+#if LIBRSVG_CHECK_VERSION (2, 22, 0)
+
+static SV *
+newSVRsvgPositionData (RsvgPositionData *data)
+{
+ HV *hv;
+
+ if (!data)
+ return &PL_sv_undef;
+
+ hv = newHV ();
+ hv_store (hv, "x", 1, newSViv (data->x), 0);
+ hv_store (hv, "y", 1, newSVnv (data->y), 0);
+
+ return newRV_noinc ((SV *) hv);
+}
+
+#endif
+
+/* ------------------------------------------------------------------------- */
+
+
MODULE = Gnome2::Rsvg PACKAGE = Gnome2::Rsvg PREFIX = rsvg_
=for object Gnome2::Rsvg::main
@@ -187,6 +230,12 @@ rsvg_set_default_dpi (class, dpi)
C_ARGS:
dpi
+## void rsvg_set_default_dpi_x_y (double dpi_x, double dpi_y)
+void
+rsvg_set_default_dpi_x_y (class, double dpi_x, double dpi_y)
+ C_ARGS:
+ dpi_x, dpi_y
+
MODULE = Gnome2::Rsvg PACKAGE = Gnome2::Rsvg::Handle PREFIX = rsvg_handle_
## RsvgHandle *rsvg_handle_new (void)
@@ -250,11 +299,53 @@ rsvg_handle_close (handle)
OUTPUT:
RETVAL
+#if LIBRSVG_CHECK_VERSION (2, 14, 0)
+
+=for apidoc __gerror__
+=cut
+## RsvgHandle * rsvg_handle_new_from_data (const guint8 *data, gsize data_len, GError **error);
+RsvgHandle *
+rsvg_handle_new_from_data (class, SV *data)
+ PREINIT:
+ const guint8 *real_data;
+ gsize data_len = 0;
+ GError *error = NULL;
+ CODE:
+ real_data = (const guint8 *) SvPV (data, data_len);
+ RETVAL = rsvg_handle_new_from_data (real_data, data_len, &error);
+ if (error)
+ gperl_croak_gerror (NULL, error);
+ OUTPUT:
+ RETVAL
+
+=for apidoc __gerror__
+=cut
+## Deliberately use 'char' instead of 'gchar' to avoid encorcing UTF-8.
+## RsvgHandle * rsvg_handle_new_from_file (const gchar *file_name, GError **error);
+RsvgHandle *
+rsvg_handle_new_from_file (class, const char *file_name)
+ PREINIT:
+ GError *error = NULL;
+ CODE:
+ RETVAL = rsvg_handle_new_from_file (file_name, &error);
+ if (error)
+ gperl_croak_gerror (NULL, error);
+ OUTPUT:
+ RETVAL
+
+#endif
+
## GdkPixbuf *rsvg_handle_get_pixbuf (RsvgHandle *handle)
GdkPixbuf_noinc *
rsvg_handle_get_pixbuf (handle)
RsvgHandle *handle
+#if LIBRSVG_CHECK_VERSION (2, 14, 0)
+
+GdkPixbuf_noinc * rsvg_handle_get_pixbuf_sub (RsvgHandle * handle, const char_ornull *id);
+
+#endif
+
#if LIBRSVG_CHECK_VERSION (2, 4, 0)
## G_CONST_RETURN char* rsvg_handle_get_title (RsvgHandle *handle)
@@ -269,12 +360,61 @@ rsvg_handle_get_desc (handle)
#endif /* 2.4.0 */
+#if LIBRSVG_CHECK_VERSION (2, 14, 0)
+
+## void rsvg_handle_get_dimensions (RsvgHandle *handle, RsvgDimensionData *dimension_data);
+SV *
+rsvg_handle_get_dimensions (RsvgHandle *handle)
+ PREINIT:
+ RsvgDimensionData dimension_data = {0,};
+ CODE:
+ rsvg_handle_get_dimensions (handle, &dimension_data);
+ RETVAL = newSVRsvgDimensionData (&dimension_data);
+ OUTPUT:
+ RETVAL
+
+#endif
+
+#if LIBRSVG_CHECK_VERSION (2, 22, 0)
+
+## gboolean rsvg_handle_get_dimensions_sub (RsvgHandle *handle, RsvgDimensionData *dimension_data, const char *id);
+SV *
+rsvg_handle_get_dimensions_sub (RsvgHandle *handle, const char_ornull *id)
+ PREINIT:
+ RsvgDimensionData dimension_data = {0,};
+ CODE:
+ if (!rsvg_handle_get_dimensions_sub (handle, &dimension_data, id))
+ RETVAL = &PL_sv_undef;
+ else
+ RETVAL = newSVRsvgDimensionData (&dimension_data);
+ OUTPUT:
+ RETVAL
+
+## gboolean rsvg_handle_get_position_sub (RsvgHandle *handle, RsvgPositionData *position_data, const char *id);
+SV *
+rsvg_handle_get_position_sub (RsvgHandle *handle, const char_ornull *id)
+ PREINIT:
+ RsvgPositionData position_data = {0,};
+ CODE:
+ if (!rsvg_handle_get_position_sub (handle, &position_data, id))
+ RETVAL = &PL_sv_undef;
+ else
+ RETVAL = newSVRsvgPositionData (&position_data);
+ OUTPUT:
+ RETVAL
+
+gboolean rsvg_handle_has_sub (RsvgHandle *handle, const char *id);
+
+#endif
+
## void rsvg_handle_set_dpi (RsvgHandle *handle, double dpi)
void
rsvg_handle_set_dpi (handle, dpi)
RsvgHandle *handle
double dpi
+void rsvg_handle_set_dpi_x_y (RsvgHandle *handle, double dpi_x, double dpi_y);
+
#if LIBRSVG_CHECK_VERSION (2, 10, 0)
## void rsvg_handle_set_base_uri (RsvgHandle *handle, const char *base_uri)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]