home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / tsw / TSW_3.4.0.exe / Apache2 / perl / Wrap.pm < prev    next >
Encoding:
Perl POD Document  |  2004-01-30  |  4.8 KB  |  184 lines

  1. #============================================================= -*-Perl-*-
  2. #
  3. # Template::Plugin::GD::Text::Wrap
  4. #
  5. # DESCRIPTION
  6. #
  7. #   Simple Template Toolkit plugin interfacing to the GD::Text::Wrap
  8. #   module.
  9. #
  10. # AUTHOR
  11. #   Craig Barratt   <craig@arraycomm.com>
  12. #
  13. # COPYRIGHT
  14. #   Copyright (C) 2001 Craig Barratt.  All Rights Reserved.
  15. #
  16. #   This module is free software; you can redistribute it and/or
  17. #   modify it under the same terms as Perl itself.
  18. #
  19. #----------------------------------------------------------------------------
  20. #
  21. # $Id: Wrap.pm,v 1.55 2004/01/13 16:21:46 abw Exp $
  22. #
  23. #============================================================================
  24.  
  25. package Template::Plugin::GD::Text::Wrap;
  26.  
  27. require 5.004;
  28.  
  29. use strict;
  30. use GD::Text::Wrap;
  31. use Template::Plugin;
  32. use base qw( GD::Text::Wrap Template::Plugin );
  33. use vars qw( $VERSION );
  34.  
  35. $VERSION = sprintf("%d.%02d", q$Revision: 1.55 $ =~ /(\d+)\.(\d+)/);
  36.  
  37. sub new
  38. {
  39.     my $class   = shift;
  40.     my $context = shift;
  41.     my $gd      = shift;
  42.  
  43.     push(@_, %{pop(@_)}) if ( @_ & 1 && ref($_[@_-1]) eq "HASH" );
  44.     return $class->SUPER::new($gd, @_);
  45. }
  46.  
  47. sub set
  48. {
  49.     my $self = shift;
  50.  
  51.     push(@_, %{pop(@_)}) if ( @_ & 1 && ref($_[@_-1]) eq "HASH" );
  52.     $self->SUPER::set(@_);
  53. }
  54.  
  55. 1;
  56.  
  57. __END__
  58.  
  59.  
  60. #------------------------------------------------------------------------
  61. # IMPORTANT NOTE
  62. #   This documentation is generated automatically from source
  63. #   templates.  Any changes you make here may be lost.
  64. #   The 'docsrc' documentation source bundle is available for download
  65. #   from http://www.template-toolkit.org/docs.html and contains all
  66. #   the source templates, XML files, scripts, etc., from which the
  67. #   documentation for the Template Toolkit is built.
  68. #------------------------------------------------------------------------
  69.  
  70. =head1 NAME
  71.  
  72. Template::Plugin::GD::Text::Wrap - Break and wrap strings in GD images
  73.  
  74. =head1 SYNOPSIS
  75.  
  76.     [% USE align = GD.Text.Wrap(gd_image); %]
  77.  
  78. =head1 EXAMPLES
  79.  
  80.     [% FILTER null;
  81.         USE gd  = GD.Image(200,400);
  82.         USE gdc = GD.Constants;
  83.         black = gd.colorAllocate(0,   0, 0);
  84.         green = gd.colorAllocate(0, 255, 0);
  85.         txt = "This is some long text. " | repeat(10);
  86.         USE wrapbox = GD.Text.Wrap(gd,
  87.          line_space  => 4,
  88.          color       => green,
  89.          text        => txt,
  90.         );
  91.         wrapbox.set_font(gdc.gdMediumBoldFont);
  92.         wrapbox.set(align => 'center', width => 160);
  93.         wrapbox.draw(20, 20);
  94.         gd.png | stdout(1);
  95.       END;
  96.     -%]
  97.  
  98.     [% txt = BLOCK -%]
  99.     Lorem ipsum dolor sit amet, consectetuer adipiscing elit,
  100.     sed diam nonummy nibh euismod tincidunt ut laoreet dolore
  101.     magna aliquam erat volutpat.
  102.     [% END -%]
  103.     [% FILTER null;
  104.         #
  105.         # This example follows the example in GD::Text::Wrap, except
  106.         # we create a second image that is a copy just enough of the
  107.         # first image to hold the final text, plus a border.
  108.         #
  109.         USE gd  = GD.Image(400,400);
  110.         USE gdc = GD.Constants;
  111.         green = gd.colorAllocate(0, 255, 0);
  112.         blue  = gd.colorAllocate(0, 0, 255);
  113.         USE wrapbox = GD.Text.Wrap(gd,
  114.          line_space  => 4,
  115.          color       => green,
  116.          text        => txt,
  117.         );
  118.         wrapbox.set_font(gdc.gdMediumBoldFont);
  119.         wrapbox.set(align => 'center', width => 140);
  120.         rect = wrapbox.get_bounds(5, 5);
  121.         x0 = rect.0;
  122.         y0 = rect.1;
  123.         x1 = rect.2 + 9;
  124.         y1 = rect.3 + 9;
  125.         gd.filledRectangle(0, 0, x1, y1, blue);
  126.         gd.rectangle(0, 0, x1, y1, green);
  127.         wrapbox.draw(x0, y0);
  128.         nx = x1 + 1;
  129.         ny = y1 + 1;
  130.         USE gd2 = GD.Image(nx, ny);
  131.         gd2.copy(gd, 0, 0, 0, 0, x1, y1);
  132.         gd2.png | stdout(1);
  133.        END;
  134.     -%]
  135.  
  136. =head1 DESCRIPTION
  137.  
  138. The GD.Text.Wrap plugin provides an interface to the GD::Text::Wrap
  139. module. It allows multiples line of text to be drawn in GD images with
  140. various wrapping and alignment.
  141.  
  142. See L<GD::Text::Wrap> for more details. See
  143. L<Template::Plugin::GD::Text::Align> for a plugin
  144. that allow you to draw text with various alignment
  145. and orientation.
  146.  
  147. =head1 AUTHOR
  148.  
  149. Craig Barratt E<lt>craig@arraycomm.comE<gt>
  150.  
  151.  
  152. The GD::Text module was written by Martien Verbruggen.
  153.  
  154.  
  155. =head1 VERSION
  156.  
  157. 1.55, distributed as part of the
  158. Template Toolkit version 2.13, released on 30 January 2004.
  159.  
  160. =head1 COPYRIGHT
  161.  
  162.  
  163. Copyright (C) 2001 Craig Barratt E<lt>craig@arraycomm.comE<gt>
  164.  
  165. GD::Text is copyright 1999 Martien Verbruggen.
  166.  
  167. This module is free software; you can redistribute it and/or
  168. modify it under the same terms as Perl itself.
  169.  
  170. =head1 SEE ALSO
  171.  
  172. L<Template::Plugin|Template::Plugin>, L<Template::Plugin::GD|Template::Plugin::GD>, L<Template::Plugin::GD::Text::Align|Template::Plugin::GD::Text::Align>, L<GD|GD>, L<GD::Text::Wrap|GD::Text::Wrap>
  173.  
  174. =cut
  175.  
  176. # Local Variables:
  177. # mode: perl
  178. # perl-indent-level: 4
  179. # indent-tabs-mode: nil
  180. # End:
  181. #
  182. # vim: expandtab shiftwidth=4:
  183.