Changeset 1119

Show
Ignore:
Timestamp:
07/21/06 16:37:11
Author:
miyagawa
Message:

By Jcode. let's use Text::WrapI18N

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/plagger/lib/Plagger/Plugin/Publish/SWF.pm

    r1118 r1119  
    55use File::Spec; 
    66use SWF::Builder; 
    7 use Jcode; 
    87 
    98sub register { 
     
    107106    my $body_size = $self->conf->{body_size} || 24; 
    108107 
    109     $body = $self->linefeed($body); 
     108    if ($self->conf->{linefeed}) { 
     109        $body = $self->fold_body($body, $self->conf->{linefeed}); 
     110    } 
    110111 
    111112    my $entry_name = 'entry_text'.$page; 
     
    130131} 
    131132 
    132 sub linefeed { 
    133     my($self, $str, $n) = @_; 
    134     my $linefeed = $self->conf->{linefeed} || 30; 
    135     my @line = split "\n",$str; 
    136     my $line; 
    137     for my $l (@line){ 
    138         my @l = Jcode->new($l)->jfold($linefeed); 
    139         $line .= join "\n",@l; 
    140         $line .= "\n"; 
     133sub fold_body { 
     134    my($self, $str, $length) = @_; 
     135 
     136    $length ||= 30; 
     137 
     138    if (eval { require Text::WrapI18N }) { 
     139        local $Text::WrapI18N::columns = $length; 
     140        return Text::WrapI18N::wrap('', '', Encode::encode_utf8($str)); 
     141    } else { 
     142        require Text::Wrap; 
     143        local $Text::Wrap::columns = $length + 1; 
     144        return Text::Wrap::wrap('', '', $str); 
    141145    } 
    142     $line; 
    143146} 
    144147