]> git.imager.perl.org - imager.git/commitdiff
- t1 library re-initialization modified to support T1Lib 5.1.0
authorTony Cook <tony@develop=help.com>
Sat, 5 Nov 2005 10:04:10 +0000 (10:04 +0000)
committerTony Cook <tony@develop=help.com>
Sat, 5 Nov 2005 10:04:10 +0000 (10:04 +0000)
Changes
font.c
lib/Imager/Font/Type1.pm
t/t30t1font.t

diff --git a/Changes b/Changes
index 39778a8e6cb86508e5b889f849dde68e8078bc5f..e3d893c486cf2bc4c87d31adc7d487e1c3e5fcd4 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1164,6 +1164,7 @@ Revision history for Perl extension Imager.
 - reading a multi-image GIF was leaking memory (a line buffer per file)
 - maxcolors now must be at least 1 when creating a paletted image.
 - converted t/t022double.t to use Test::More
+- t1 library re-initialization modified to support T1Lib 5.1.0
 
 =================================================================
 
diff --git a/font.c b/font.c
index 0c7a96a78e05e66a4ccd7719bf27d8269000334e..6046d7a7941111a8eb543cf4d272a49dfdf708f5 100644 (file)
--- a/font.c
+++ b/font.c
@@ -87,6 +87,9 @@ static char *t1_from_utf8(char const *in, int len, int *outlen);
 
 static void t1_push_error(void);
 
+static int t1_active_fonts = 0;
+static int t1_initialized = 0;
+
 /* 
 =item i_init_t1(t1log)
 
@@ -99,6 +102,15 @@ undef_int
 i_init_t1(int t1log) {
   int init_flags = IGNORE_CONFIGFILE|IGNORE_FONTDATABASE;
   mm_log((1,"init_t1()\n"));
+
+  if (t1_active_fonts) {
+    mm_log((1, "Cannot re-initialize T1 - active fonts\n"));
+    return 1;
+  }
+
+  if (t1_initialized) {
+    T1_CloseLib();
+  }
   
   if (t1log)
     init_flags |= LOGFILE;
@@ -108,6 +120,9 @@ i_init_t1(int t1log) {
   }
   T1_SetLogLevel(T1LOG_DEBUG);
   i_t1_set_aa(1); /* Default Antialias value */
+
+  ++t1_initialized;
+
   return(0);
 }
 
@@ -125,6 +140,7 @@ Shuts the t1lib font rendering engine down.
 void
 i_close_t1(void) {
   T1_CloseLib();
+  t1_initialized = 0;
 }
 
 
@@ -155,6 +171,8 @@ 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));
   }
 
+  ++t1_active_fonts;
+
   return font_id;
 }
 
@@ -171,6 +189,9 @@ Frees resources for a t1 font with given font id.
 int
 i_t1_destroy(int font_id) {
   mm_log((1,"i_t1_destroy(font_id %d)\n",font_id));
+
+  --t1_active_fonts;
+
   return T1_DeleteFont(font_id);
 }
 
index 510d4dfea0cbe73d92e9897f7702082639b158cd..8837aaa8fbc565e513c0640caaaedc998a8b298f 100644 (file)
@@ -159,6 +159,8 @@ can re-enable that by calling Imager::init() with the C<t1log> option:
 
   Imager::init(t1log=>1);
 
+This must be called before creating any fonts.
+
 Currently specific to Imager::Font::Type1, you can use the following
 flags when drawing text or calculating a bounding box:
 
index cd342d5aa639249ac2d918efe0dd179d40c9bc71..9d8a01072cb058a1347a0decb51de6400842daf0 100644 (file)
@@ -36,6 +36,14 @@ SKIP:
 
   i_t1_set_aa(1);
 
+  unlink "t1lib.log"; # lose it if it exists
+  init(t1log=>0);
+  ok(!-e("t1lib.log"), "disable t1log");
+  init(t1log=>1);
+  ok(-e("t1lib.log"), "enable t1log");
+  init(t1log=>0);
+  unlink "t1lib.log";
+
   my $fnum=Imager::i_t1_new($fontname_pfb,$fontname_afm); # this will load the pfb font
   unless (ok($fnum >= 0, "load font $fontname_pfb")) {
     skip("without the font I can't do a thing", 48);
@@ -124,14 +132,6 @@ SKIP:
   print "# debug: ",join(" x ",i_t1_bbox(0,50,"eses",4) ),"\n";
   print "# debug: ",join(" x ",i_t1_bbox(0,50,"llll",4) ),"\n";
 
-  unlink "t1lib.log"; # lose it if it exists
-  init(t1log=>0);
-  ok(!-e("t1lib.log"), "disable t1log");
-  init(t1log=>1);
-  ok(-e("t1lib.log"), "enable t1log");
-  init(t1log=>0);
-  unlink "t1lib.log";
-
   # character existance tests - uses the special ExistenceTest font
   my $exists_font = 'fontfiles/ExistenceTest.pfb';
   my $exists_afm = 'fontfiles/ExistenceText.afm';