| 1 | package Text::FIGlet::Illuminated; | ||
| 2 | require 5; | ||
| 3 | use strict; | ||
| 4 | use vars qw/$VERSION @ISA/; | ||
| 5 | use Text::FIGlet; | ||
| 6 | use Text::Wrap; | ||
| 7 | $VERSION = 2.19; | ||
| 8 | @ISA = 'Text::FIGlet::Font'; | ||
| 9 | |||
| 10 | sub new{ | ||
| 11 | shift(); | ||
| 12 | bless(Text::FIGlet->new(@_)); | ||
| 13 | } | ||
| 14 | |||
| 15 | sub illuminate{ | ||
| 16 | my $font = shift; | ||
| 17 | my %opts = @_; | ||
| 18 | |||
| 19 | my @buffer; | ||
| 20 | if( $opts{-w} < 0 ){ | ||
| 21 | $opts{-w} = abs($opts{-w}); | ||
| 22 | @buffer = _illuminate($font, %opts); | ||
| 23 | } | ||
| 24 | else{ | ||
| 25 | foreach( split("$/$/", $opts{-A} ) ){ | ||
| 26 | push @buffer, _illuminate($font, %opts, -A=>$_); | ||
| 27 | } | ||
| 28 | } | ||
| 29 | |||
| 30 | return wantarray ? @buffer : join("\n", @buffer); | ||
| 31 | } | ||
| 32 | |||
| 33 | sub _illuminate{ | ||
| 34 | my $font = shift; | ||
| 35 | my %opts = @_; | ||
| 36 | |||
| 37 | my $text = $opts{'-A'}; | ||
| 38 | $opts{'-A'} = substr($text, 0, 1, ''); | ||
| 39 | |||
| 40 | my @illumination = $font->figify(%opts); | ||
| 41 | |||
| 42 | my $empty; | ||
| 43 | for(my $i=0; $i<=$#illumination; $i++ ){ | ||
| 44 | if( $illumination[$i] =~ /^\s+$/ ){ | ||
| 45 | $empty = $i; } | ||
| 46 | else{ | ||
| 47 | last; } | ||
| 48 | } | ||
| 49 | splice(@illumination,0,$empty+1); | ||
| 50 | for(my $i=$#illumination; $i>=0; $i-- ){ | ||
| 51 | if( $illumination[$i] =~ /^\s+$/ ){ | ||
| 52 | $empty = $i; } | ||
| 53 | else{ | ||
| 54 | last; } | ||
| 55 | } | ||
| 56 | splice(@illumination,$empty, $#illumination-$empty); | ||
| 57 | |||
| 58 | $opts{-w}||=80; | ||
| 59 | my $cols = length($illumination[0]); | ||
| 60 | my $freecols = $opts{-w} -$cols -2; | ||
| 61 | my $rows = scalar(@illumination); | ||
| 62 | |||
| 63 | $Text::Wrap::columns = $freecols; | ||
| 64 | |||
| 65 | my @body = split /\n/, wrap('', '', $text); | ||
| 66 | |||
| 67 | for(my $i=0; $i<=$#illumination; $i++ ){ | ||
| 68 | $illumination[$i] .= ' ' . shift(@body)||''; | ||
| 69 | } | ||
| 70 | |||
| 71 | if( scalar(@body) ){ | ||
| 72 | my $body = join(' ', @body); | ||
| 73 | $body =~ y/\n//d; | ||
| 74 | $Text::Wrap::columns = $opts{-w}; | ||
| 75 | push(@illumination, split(/\n/, wrap('', '', $body))); | ||
| 76 | } | ||
| 77 | |||
| 78 | return wantarray ? @illumination : join("\n", @illumination); | ||
| 79 | } | ||
| 80 | |||
| 81 | 1; | ||
| 82 | __END__ |