[perl-Gtk2] Gtk2::Gdk::Pixbuf->save(): ensure that option strings are utf8



commit 2e1f808320e7ac75c2a0172551654f5313b2534b
Author: Kevin Ryde <user42 zip com au>
Date:   Tue Dec 7 22:25:58 2010 +0100

    Gtk2::Gdk::Pixbuf->save(): ensure that option strings are utf8
    
    https://bugzilla.gnome.org/show_bug.cgi?id=620910

 NEWS            |    2 ++
 t/GdkPixbuf.t   |   27 +++++++++++++++++++++++++--
 xs/GdkPixbuf.xs |    9 ++++++---
 3 files changed, 33 insertions(+), 5 deletions(-)
---
diff --git a/NEWS b/NEWS
index 1c776e7..7876ea4 100644
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,8 @@ Overview of changes in the next unstable release
 * Fix length of Gtk2::Gdk::Pixbuf->get_pixels() return.
 * Allow Gtk2::Buildable implementations to return undef from
   GET_INTERNAL_CHILD.
+* Ensure that the option strings passed to Gtk2::Gdk::Pixbuf->save() are
+  upgraded to utf8 if necessary.
 
 Overview of changes in Gtk2 1.230
 =================================
diff --git a/t/GdkPixbuf.t b/t/GdkPixbuf.t
index f35efb5..a0a92b6 100644
--- a/t/GdkPixbuf.t
+++ b/t/GdkPixbuf.t
@@ -1,6 +1,7 @@
+#!/usr/bin/env perl
 use strict;
 use warnings;
-use Gtk2::TestHelper tests => 108, noinit => 1;
+use Gtk2::TestHelper tests => 110, noinit => 1;
 
 my $show = 0;
 
@@ -215,7 +216,18 @@ my $mtime = scalar localtime;
 my $desc = 'Something really cool';
 $pixbuf->save ($filename, 'png',
 	       'tEXt::Thumb::MTime' => $mtime,
-	       'tEXt::Description' => $desc);
+	       'tEXt::Description' => $desc,
+	       #
+	       # latin1 bytes upgraded to utf8 in the xsub
+	       #
+	       # Crib note: if there's no upgrade in the xsub then one of
+	       # two bad things happen: if libpng was built without iTXt
+	       # support then gdk-pixbuf gives a GError because the bytes
+	       # are not valid utf8; or if libpng does have iTXt then
+	       # gdk-pixbuf drops the bytes straight in an iTXt in the file,
+	       # leaving invalid utf8 there.
+	       #
+	       'tEXt::Title' => "z \x{B1} .5");
 ok (1);
 
 $pixbuf = Gtk2::Gdk::Pixbuf->new_from_file ($filename);
@@ -225,6 +237,17 @@ is ($pixbuf->get_option ('tEXt::Description'), $desc, 'get_option works');
 is ($pixbuf->get_option ('tEXt::Thumb::MTime'), $mtime, 'get_option works');
 ok (! $pixbuf->get_option ('tEXt::noneXIStenTTag'),
     'get_option returns undef if the key is not found');
+{
+	my $got = $pixbuf->get_option ('tEXt::Title');
+	my $want = "z \x{B1} .5";
+	utf8::upgrade ($want);
+	is ($got, $want, 'get_option tEXt::Title');
+	SKIP: {
+		utf8->can('is_utf8')
+			or skip 'utf8::is_utf8() not available (perl 5.8.0)', 1;
+		ok (utf8::is_utf8($got), 'get_option tEXt::Title is_utf8()');
+	}
+}
 
 SKIP: {
 	skip 'new 2.2 stuff', 3
diff --git a/xs/GdkPixbuf.xs b/xs/GdkPixbuf.xs
index e247bea..23be15b 100644
--- a/xs/GdkPixbuf.xs
+++ b/xs/GdkPixbuf.xs
@@ -650,9 +650,12 @@ gdk_pixbuf_save (pixbuf, filename, type, ...)
 	option_vals = g_new0 (char *, nkeys + 1);
 
 	for (i = 0 ; i < nkeys ; i++) {
-		/* NOT copies */
-		option_keys[i] = SvPV_nolen (ST (FIRST_KEY + i*2 + 0));
-		option_vals[i] = SvPV_nolen (ST (FIRST_KEY + i*2 + 1));
+		/* NOT copies of the strings.
+		   option_vals[] are utf8 for png format "tEXt::Foo" etc.
+		   option_keys[] are ascii-only circa gtk 2.18, but presume
+		   any non-ascii there would be utf8 too. */
+		option_keys[i] = SvGChar (ST (FIRST_KEY + i*2 + 0));
+		option_vals[i] = SvGChar (ST (FIRST_KEY + i*2 + 1));
 	}
 
 	worked = gdk_pixbuf_savev (pixbuf, filename, type, 



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