]> git.imager.perl.org - imager.git/commitdiff
- the internal i_tags_get_string() function now acts correctly for
authorTony Cook <tony@develop=help.com>
Fri, 29 Apr 2005 14:36:04 +0000 (14:36 +0000)
committerTony Cook <tony@develop=help.com>
Fri, 29 Apr 2005 14:36:04 +0000 (14:36 +0000)
  integer only tags.

Changes
Imager.xs
TODO
t/t01introvert.t
tags.c

diff --git a/Changes b/Changes
index 0844dea2dc99eaa34c47a72b0ce2e509a794cdfe..0baa90a3ee9a2d59ba9df4940d83eeb979060853 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1074,6 +1074,8 @@ Revision history for Perl extension Imager.
   and right bearing values.
 - Imager::Matrix2d->rotate() would only rotate around the supplied 
   centre point if both 'x' and 'y' were non-zero.
+- the internal i_tags_get_string() function now acts correctly for
+  integer only tags.
 
 =================================================================
 
index 63b981ed2c0f34e0c2b4126565e0a6a43b98ac35..711dcc75ce28a9c56f246285610647e8941cb97f 100644 (file)
--- a/Imager.xs
+++ b/Imager.xs
@@ -3960,6 +3960,29 @@ i_tags_get(im, index)
           }
         }
 
+void
+i_tags_get_string(im, what_sv)
+        Imager::ImgRaw  im
+        SV *what_sv
+      PREINIT:
+        char const *name = NULL;
+        int code;
+        char buffer[200];
+        int result;
+      PPCODE:
+        if (SvIOK(what_sv)) {
+          code = SvIV(what_sv);
+          name = NULL;
+        }
+        else {
+          name = SvPV_nolen(what_sv);
+          code = 0;
+        }
+        if (i_tags_get_string(&im->tags, name, code, buffer, sizeof(buffer))) {
+          EXTEND(SP, 1);
+          PUSHs(sv_2mortal(newSVpv(buffer, 0)));
+        }
+
 int
 i_tags_count(im)
         Imager::ImgRaw  im
diff --git a/TODO b/TODO
index 9cc26ef77515d51a22d99911904d0a75cef1f747..5f37dd7b5fc968d75e09d2cfe77c595c50e577f5 100644 (file)
--- a/TODO
+++ b/TODO
@@ -16,8 +16,10 @@ not commitments.
   caching.  If FT1 is faster, add caching as a TODO for FT2.
 - add XS for i_tags_get_string() and test it.  It has an apparent problem
   in C<< sprintf(value, "%d", entry->data); >> since data is a pointer
+  (done)
 - test and fix problem with fallback value for 
   Imager::Font::BBox->advance_width. (done)
+- check handling of string() method align parameter.
 - i_tt_bbox_inst in font.c uses variable i without ever setting it. (fixed)
 - add sample CGI that handles an uploaded image (done)
 - examples for fountain filter in Imager::Filters
index e41de5e35e84b549919bd9906ec6496fa3fd23de..a9b191fe64ae6dd769bfeb21d23144a90bfe4201 100644 (file)
@@ -4,7 +4,7 @@
 
 use strict;
 use lib 't';
-use Test::More tests=>98;
+use Test::More tests=>124;
 
 BEGIN { use_ok(Imager => qw(:handy :all)) }
 
@@ -255,6 +255,45 @@ cmp_ok(Imager->errstr, '=~', qr/channels must be between 1 and 4/,
   ok(color_cmp($row[1], $blue) == 0, "then blue");
 }
 
+{ # general tag tests
+  
+  # we don't care much about the image itself
+  my $im = Imager::ImgRaw::new(10, 10, 1);
+
+  ok(Imager::i_tags_addn($im, 'alpha', 0, 101), "i_tags_addn(...alpha, 0, 101)");
+  ok(Imager::i_tags_addn($im, undef, 99, 102), "i_tags_addn(...undef, 99, 102)");
+  is(Imager::i_tags_count($im), 2, "should have 2 tags");
+  ok(Imager::i_tags_addn($im, undef, 99, 103), "i_tags_addn(...undef, 99, 103)");
+  is(Imager::i_tags_count($im), 3, "should have 3 tags, despite the dupe");
+  is(Imager::i_tags_find($im, 'alpha', 0), '0 but true', "find alpha");
+  is(Imager::i_tags_findn($im, 99, 0), 1, "find 99");
+  is(Imager::i_tags_findn($im, 99, 2), 2, "find 99 again");
+  is(Imager::i_tags_get($im, 0), 101, "check first");
+  is(Imager::i_tags_get($im, 1), 102, "check second");
+  is(Imager::i_tags_get($im, 2), 103, "check third");
+
+  ok(Imager::i_tags_add($im, 'beta', 0, "hello", 0), 
+     "add string with string key");
+  ok(Imager::i_tags_add($im, 'gamma', 0, "goodbye", 0),
+     "add another one");
+  ok(Imager::i_tags_add($im, undef, 199, "aloha", 0),
+     "add one keyed by number");
+  is(Imager::i_tags_find($im, 'beta', 0), 3, "find beta");
+  is(Imager::i_tags_find($im, 'gamma', 0), 4, "find gamma");
+  is(Imager::i_tags_findn($im, 199, 0), 5, "find 199");
+  ok(Imager::i_tags_delete($im, 2), "delete");
+  is(Imager::i_tags_find($im, 'beta', 0), 2, 'find beta after deletion');
+  ok(Imager::i_tags_delbyname($im, 'beta'), 'delete beta by name');
+  is(Imager::i_tags_find($im, 'beta', 0), undef, 'beta not there now');
+  is(Imager::i_tags_get_string($im, "gamma"), "goodbye", 
+     'i_tags_get_string() on a string');
+  is(Imager::i_tags_get_string($im, 99), 102, 
+     'i_tags_get_string() on a number entry');
+  ok(Imager::i_tags_delbycode($im, 99), 'delete by code');
+  is(Imager::i_tags_findn($im, 99, 0), undef, '99 not there now');
+  is(Imager::i_tags_count($im), 3, 'final count of 3');
+}
+
 sub check_add {
   my ($im, $color, $expected) = @_;
   my $index = Imager::i_addcolors($im, $color);
diff --git a/tags.c b/tags.c
index de2815aef501a32ab743b9b88f4d42d5cc0be611..bf8d3a5b8dda3cb9d22d631f7d44bf2ea80fb32f 100644 (file)
--- a/tags.c
+++ b/tags.c
@@ -442,7 +442,7 @@ int i_tags_get_string(i_img_tags *tags, char const *name, int code,
     value[cpsize] = '\0';
   }
   else {
-    sprintf(value, "%d", entry->data);
+    sprintf(value, "%d", entry->idata);
   }
 
   return 1;