From 0a7c2377084644140cc308a76303ed078688e169 Mon Sep 17 00:00:00 2001 From: Marc Lehmann Date: Mon, 10 May 1999 16:00:50 +0000 Subject: [PATCH] see plug-ins/perl/Changes --- plug-ins/perl/Changes | 3 + plug-ins/perl/Gimp.pm | 16 +++- plug-ins/perl/Gimp/Compat.pm | 126 +++++++++++++++++++++++++++ plug-ins/perl/Gimp/PDL.pm | 7 +- plug-ins/perl/MANIFEST | 1 + plug-ins/perl/examples/example-fu.pl | 1 - plug-ins/perl/examples/fit-text | 2 - plug-ins/perl/examples/innerbevel | 3 - plug-ins/perl/examples/terral_text | 4 +- 9 files changed, 147 insertions(+), 16 deletions(-) create mode 100644 plug-ins/perl/Gimp/Compat.pm diff --git a/plug-ins/perl/Changes b/plug-ins/perl/Changes index 3a5bd460ea..b5003b4412 100644 --- a/plug-ins/perl/Changes +++ b/plug-ins/perl/Changes @@ -4,6 +4,9 @@ Revision history for Gimp-Perl extension. - disabled paintbrush in testsuite since it has different calling parameters in 1.1. - added use File::Basename to Fu.pm. + - new module Gimp::Compat, which is loaded on demand. + - gimp_text_fontname etc.. are now available in gimp-1.0 as well, + re-enabled the scripts using it (and depending on 1.1 before). 1.081 Thu May 6 19:33:37 CEST 1999 - added "oneliners". diff --git a/plug-ins/perl/Gimp.pm b/plug-ins/perl/Gimp.pm index dce20fdb02..84eb64dcb9 100644 --- a/plug-ins/perl/Gimp.pm +++ b/plug-ins/perl/Gimp.pm @@ -13,7 +13,7 @@ use subs qw(init end lock unlock canonicalize_color); require DynaLoader; @ISA=qw(DynaLoader); -$VERSION = 1.081; +$VERSION = 1.082; @_param = qw( PARAM_BOUNDARY PARAM_CHANNEL PARAM_COLOR PARAM_DISPLAY PARAM_DRAWABLE @@ -306,6 +306,19 @@ sub format_msg { } sub _initialized_callback { + # load the compatibility module on older versions + if ($interface_pkg eq "Gimp::Lib") { + # this must match @max_gimp_version in Gimp::Compat + my @compat_gimp_version = (1,1); + if ((Gimp->major_version < $compat_gimp_version[0]) + || (Gimp->major_version == $compat_gimp_version[0] + && Gimp->minor_version < $compat_gimp_version[1])) { + require Gimp::Compat; + $compat_gimp_version[0] == $Gimp::Compat::max_gimp_version[0] + && $compat_gimp_version[1] == $Gimp::Compat::max_gimp_version[1] + or die "FATAL: Gimp::Compat version mismatch\n"; + } + } if (@log) { unless ($in_net || $in_query || $in_quit || $in_init) { for(@log) { @@ -458,6 +471,7 @@ sub AUTOLOAD { my ($class,$name) = $AUTOLOAD =~ /^(.*)::(.*?)$/; for(@{"$class\::PREFIXES"}) { my $sub = $_.$name; + print "checking for $sub(",join(",",@_),")\n"; if (exists $ignore_function{$sub}) { *{$AUTOLOAD} = sub { () }; goto &$AUTOLOAD; diff --git a/plug-ins/perl/Gimp/Compat.pm b/plug-ins/perl/Gimp/Compat.pm new file mode 100644 index 0000000000..f40a7bcd0a --- /dev/null +++ b/plug-ins/perl/Gimp/Compat.pm @@ -0,0 +1,126 @@ +=head1 NAME + + Gimp::Compat - compatibility functions for older verasions of Gimp. + +=head1 SYNOPSIS + + + +=head1 DESCRIPTION + +Older versions of Gimp (vesion 1.0 at the time of this writing) lack some +very important or useful functions. + +This module is providing the most needed replacement functions. If you +happen to miss a function then please create a replacement function and +send it to me ;) + +These functions are handled in exactly the same way as PDB-Functions, +i.e. the (hypothetical) function C can be called as +$image->xyzzy, if the module is available. + +=head1 FUNCTIONS + +=over 4 + +=item gimp_text_fontname + +=item gimp_get_extents_fontname + +=back + +=head1 AUTHOR + +Various, Dov Grobgeld . The author of the +Gimp-Perl extension (contact him to include new functions) is Marc Lehmann + + +=cut + +package Gimp::Compat; + +$VERSION=$Gimp::VERSION; + +use Gimp (); + +# as a failsafe check, lowest version NOT requiring this module +@max_gimp_version = (1,1); + +# The following function is used to convert a xlfd to the array structure +# used by the pre 1.2 functions gimp_text_ext() and gimp_text_get_extent_ext(). + +sub xlfd_unpack { + my $fontname = shift; + my $size_overload = shift; + my $size_unit_overload = shift; + # XLFDs fields can contain anything, including minus signs, but we + # gracefully ignore these weird things here ;) + my $p = "[^-]*"; + my($foundry, + $family, + $weight, + $slant, + $set_width, + $pixelsize, + $pointsize, + $spacing, + $registry, + $encoding, + ) = $fontname=~ + /^-($p) (?# foundry ) + -($p) (?# family ) + -($p) (?# weight ) + -($p) (?# slant ) + -($p) (?# set_Width ) + -$p + -($p) (?# pixelsize ) + -($p) (?# pointsize ) + -$p + -$p + -($p) (?# spacing ) + -$p + -($p) (?# rgstry ) + -($p) (?# encdng ) + /x or die "xlfd_unpack: unmatched XLFD '$fontname'\n"; + + my $size; + if ($pixelsize && $pixelsize ne "*") { + $size = $pixelsize; + } else { + $size = 0.1*$pointsize; + } + $size = $size_overload if $size_overload; + my $size_unit = ($pointsize > 0); + $size_unit = $size_unit if defined $size_unit_overload; + return ($size, $size_unit, $foundry, $family, $weight, $slant, + $set_width, $spacing, $registry, $encoding); +} + +sub fun { + my($major,$minor,$name,$sub)=@_; + if (Gimp->major_version < $major + || (Gimp->major_version == $major && Gimp->minor_version < $minor)) { + print "overwriting Gimp::Lib::$name ($major,$minor)\n"; + *{"Gimp::Lib::$name"}=$sub; + } +} + +fun 1,1,gimp_text_get_extents_fontname,sub { + my($string, $xlfd_size, $xlfd_unit, $xlfd) = @_; + + Gimp->text_get_extents_ext($string, @font_info, + xlfd_unpack($xlfd, $xlfd_size, $xlfd_unit)); +}; + +fun 1,1,gimp_text_fontname,sub { + shift if $_[0]->isa('Gimp::Image'); + my ($drw, $x,$y, $string,$border,$antialias, $xlfd_size, $xlfd_unit, $xlfd) = @_; + + Gimp->text_ext($drw, $x, $y, $string, $border, $antialias, + xlfd_unpack($xlfd, $xlfd_size, $xlfd_unit)); +}; + +1; + + + diff --git a/plug-ins/perl/Gimp/PDL.pm b/plug-ins/perl/Gimp/PDL.pm index 227b04d957..eb47146e0b 100644 --- a/plug-ins/perl/Gimp/PDL.pm +++ b/plug-ins/perl/Gimp/PDL.pm @@ -1,13 +1,8 @@ package Gimp::PDL; use Carp; -use Gimp; +use Gimp (); use PDL; -use base qw(Exporter); - -require Exporter; - -@EXPORT = (); sub Gimp::Tile::set_data($) { (my $p = byte $_[1])->make_physical; diff --git a/plug-ins/perl/MANIFEST b/plug-ins/perl/MANIFEST index dc80853f51..1722be2e34 100644 --- a/plug-ins/perl/MANIFEST +++ b/plug-ins/perl/MANIFEST @@ -40,6 +40,7 @@ Gimp/Util.pm Gimp/Feature.pm Gimp/Pod.pm Gimp/Module.pm +Gimp/Compat.pm embed/Makefile.PL embed/perlmod.c nolib/Makefile.PL diff --git a/plug-ins/perl/examples/example-fu.pl b/plug-ins/perl/examples/example-fu.pl index 380b096f62..2e0a6bb80a 100755 --- a/plug-ins/perl/examples/example-fu.pl +++ b/plug-ins/perl/examples/example-fu.pl @@ -56,7 +56,6 @@ register "gimp_fu_example_script", # fill in a function name fill $l BG_IMAGE_FILL; - # the next function only works in gimp-1.1 $text_layer=$img->text_fontname(-1,10,10,$text,5,1,xlfd_size($font),$font); gimp_palette_set_foreground("green"); diff --git a/plug-ins/perl/examples/fit-text b/plug-ins/perl/examples/fit-text index 906a1e22cd..9e15980a45 100755 --- a/plug-ins/perl/examples/fit-text +++ b/plug-ins/perl/examples/fit-text @@ -32,8 +32,6 @@ register "fit_text", [PF_FONT, "font", "What font type to use - size will be ignored", $defaultfont], [PF_STRING, "string", "Text String to fill with", "Fit Text"], ], - [], - ['gimp-1.1'], sub { my($img,$layer,$xlfd,$string) =@_; ($sel,$x1,$y1,$x2,$y2) = $img->gimp_selection_bounds; diff --git a/plug-ins/perl/examples/innerbevel b/plug-ins/perl/examples/innerbevel index 3be155226b..36271c8869 100755 --- a/plug-ins/perl/examples/innerbevel +++ b/plug-ins/perl/examples/innerbevel @@ -39,9 +39,6 @@ register $regname, $shortdesc, $longdesc, $authorname, $author, $date, $path, $i [PF_SLIDER, "shinyness", "How shiny the final image will be",30, [0,90,5]], [PF_SLIDER, "depth_shape", "Determines the final shape", 34 , [0,64,32]], [PF_RADIO, "map", "The type of Map to use", 2, [Linear => 0, Spherical => 1, Sinusoidal => 2] ], - ],[], - [ - 'gimp-1.1', ], sub { my ($font, $text, $color1, $color2, $azimuth, $elevation, $depth, $maptype) = @_; diff --git a/plug-ins/perl/examples/terral_text b/plug-ins/perl/examples/terral_text index 94591e11b5..a9ee621eb7 100644 --- a/plug-ins/perl/examples/terral_text +++ b/plug-ins/perl/examples/terral_text @@ -48,8 +48,6 @@ register [ PF_STRING, "text", "Enter your Text to be Terral-ified", "TerralText"], [ PF_SLIDER, "blur_amount", "Blur Amount", 10, [0,26,1]], ], - [], - ['gimp-1.1'], sub { ($img, $pattern, $solidnoise, $font, $text, $blur) = @_; $oldbg = gimp_palette_get_background(); @@ -65,7 +63,7 @@ sub { # about before blindly apply a type of layer. Oh well. Call it RGBA # for now. - # Hello, Seth.. look at this: + # FIXED: Hello, Seth.. look at this: $textlayer = $img->layer_new($img->width, $img->height, $img->layertype(1), "TextLayer", 100, 0);