]> git.imager.perl.org - imager.git/commitdiff
[rt #69879] various T1 improvments
authorTony Cook <tony@develop-help.com>
Fri, 14 Oct 2011 11:11:08 +0000 (22:11 +1100)
committerTony Cook <tony@develop-help.com>
Fri, 14 Oct 2011 11:11:08 +0000 (22:11 +1100)
Changes
T1/Changes
T1/T1.pm
T1/imt1.c
T1/t/t20oo.t

diff --git a/Changes b/Changes
index 541c8af05cdf5846542856f838c9bc800f032809..57576c2989bc57c3e416fee13e55490fbd534b6c 100644 (file)
--- a/Changes
+++ b/Changes
@@ -32,6 +32,15 @@ Bug fixes:
  - add overloaded eq to Imager::Matrix2d, since older perls don't seem
    to synthesize it from overloaded "".
 
  - add overloaded eq to Imager::Matrix2d, since older perls don't seem
    to synthesize it from overloaded "".
 
+  - use T1_StrError() for error messages on modern libt1
+    https://rt.cpan.org/Ticket/Display.html?id=69879
+
+ - actually load the font rather than just adding it to the catalog on
+   creation.
+
+ - Imager::Font->new now produces better error messages for the T1
+   engine.
+
 Imager 0.85_01 - 10 Oct 2011
 ==============
 
 Imager 0.85_01 - 10 Oct 2011
 ==============
 
index 4fd2a438a99b81278a64f22ad85e748a14f8d58a..918023929a2fd77dfb351d0d0d26c6e405582cfd 100644 (file)
@@ -1,3 +1,15 @@
+Imager::Font::T1 1.015
+======================
+
+ - use T1_StrError() for error messages on modern libt1
+   https://rt.cpan.org/Ticket/Display.html?id=69879
+
+ - actually load the font rather than just adding it to the catalog on
+   creation.
+
+ - Imager::Font->new now produces better error messages for the T1
+   engine.
+
 Imager::Font::T1 1.014
 ======================
 
 Imager::Font::T1 1.014
 ======================
 
index 80663ba9f3269cc0380de2b8b3cfb9ec071a8816..89dd12eba51df5211cb40798e9d67fc5e4b2a794 100644 (file)
--- a/T1/T1.pm
+++ b/T1/T1.pm
@@ -74,7 +74,7 @@ sub new {
 
   my $id = i_t1_new($hsh{file},$hsh{afm});
   unless ($id >= 0) { # the low-level code may miss some error handling
 
   my $id = i_t1_new($hsh{file},$hsh{afm});
   unless ($id >= 0) { # the low-level code may miss some error handling
-    $Imager::ERRSTR = "Could not load font ($id)";
+    Imager->_set_error(Imager->_error_as_msg);
     return;
   }
   return bless {
     return;
   }
   return bless {
index 9c19c53b1e126ec54bd67a5db419f8a732b6da6a..3027e424373c3aef7405d51c30ef58acad9b5095 100644 (file)
--- a/T1/imt1.c
+++ b/T1/imt1.c
@@ -93,6 +93,7 @@ i_t1_new(char *pfb,char *afm) {
   font_id = T1_AddFont(pfb);
   if (font_id<0) {
     mm_log((1,"i_t1_new: Failed to load pfb file '%s' - return code %d.\n",pfb,font_id));
   font_id = T1_AddFont(pfb);
   if (font_id<0) {
     mm_log((1,"i_t1_new: Failed to load pfb file '%s' - return code %d.\n",pfb,font_id));
+    t1_push_error();
     return font_id;
   }
   
     return font_id;
   }
   
@@ -101,8 +102,18 @@ i_t1_new(char *pfb,char *afm) {
     if (T1_SetAfmFileName(font_id,afm)<0) mm_log((1,"i_t1_new: afm loading of '%s' failed.\n",afm));
   }
 
     if (T1_SetAfmFileName(font_id,afm)<0) mm_log((1,"i_t1_new: afm loading of '%s' failed.\n",afm));
   }
 
+  if (T1_LoadFont(font_id)) {
+    mm_log((1, "i_t1_new() -> -1 - T1_LoadFont failed (%d)\n", T1_errno));
+    t1_push_error();
+    i_push_error(0, "loading font");
+    T1_DeleteFont(font_id);
+    return -1;
+  }
+
   ++t1_active_fonts;
 
   ++t1_active_fonts;
 
+  mm_log((1, "i_t1_new() -> %d\n", font_id));
+
   return font_id;
 }
 
   return font_id;
 }
 
@@ -572,6 +583,10 @@ i_t1_glyph_name(int font_num, unsigned long ch, char *name_buf,
 
 static void
 t1_push_error(void) {
 
 static void
 t1_push_error(void) {
+#if T1LIB_VERSION > 5 || T1LIB_VERSION == 5 && T1LIB_VERSION >= 1
+  /* I don't know when T1_StrError() was introduced, be conservative */
+  i_push_error(T1_errno, T1_StrError(T1_errno));
+#else
   switch (T1_errno) {
   case 0: 
     i_push_error(0, "No error"); 
   switch (T1_errno) {
   case 0: 
     i_push_error(0, "No error"); 
@@ -682,5 +697,6 @@ t1_push_error(void) {
   default:
     i_push_errorf(T1_errno, "unknown error %d", (int)T1_errno);
   }
   default:
     i_push_errorf(T1_errno, "unknown error %d", (int)T1_errno);
   }
+#endif
 }
 
 }
 
index 16935c4134c0027e25cd4b637cf8ddb43dd24c78..273743e5e144b57c773c857674c79252565bb622 100644 (file)
@@ -2,7 +2,7 @@
 use strict;
 use Imager;
 use Imager::Test qw(isnt_image);
 use strict;
 use Imager;
 use Imager::Test qw(isnt_image);
-use Test::More tests => 13;
+use Test::More tests => 14;
 
 # extracted from t/t36oofont.t
 
 
 # extracted from t/t36oofont.t
 
@@ -80,6 +80,14 @@ ok($img->write(file=>"testout/t36oofont1.ppm", type=>'pnm'),
   }
 }
 
   }
 }
 
+{ # open a non-font as a font (test open failure)
+  local $ENV{LANG} = "C";
+  local $ENV{LC_ALL} = "C";
+  my $font = Imager::Font->new(file => "t/t20oo.t", type => "t1");
+  ok(!$font, "should fail to open test script as a font");
+  print "# ", Imager->errstr, "\n";
+}
+
 unless ($ENV{IMAGER_KEEP_FILES}) {
   unlink "testout/t36oofont1.ppm";
 }
 unless ($ENV{IMAGER_KEEP_FILES}) {
   unlink "testout/t36oofont1.ppm";
 }