From: Tony Cook Date: Sat, 5 Nov 2005 10:04:10 +0000 (+0000) Subject: - t1 library re-initialization modified to support T1Lib 5.1.0 X-Git-Tag: Imager-0.48^2~97 X-Git-Url: http://git.imager.perl.org/imager.git/commitdiff_plain/3a12a980da6cbf13295f9663d0acdd30d3c918cd - t1 library re-initialization modified to support T1Lib 5.1.0 --- diff --git a/Changes b/Changes index 39778a8e..e3d893c4 100644 --- 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 0c7a96a7..6046d7a7 100644 --- 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); } diff --git a/lib/Imager/Font/Type1.pm b/lib/Imager/Font/Type1.pm index 510d4dfe..8837aaa8 100644 --- a/lib/Imager/Font/Type1.pm +++ b/lib/Imager/Font/Type1.pm @@ -159,6 +159,8 @@ can re-enable that by calling Imager::init() with the C 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: diff --git a/t/t30t1font.t b/t/t30t1font.t index cd342d5a..9d8a0107 100644 --- a/t/t30t1font.t +++ b/t/t30t1font.t @@ -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';