Text-Bidi
view release on metacpan or search on metacpan
lib/Text/Bidi/Paragraph.pm view on Meta::CPAN
# Created: Tue 27 Aug 2013 04:10:03 PM IDT
# Last Changed: Sat 07 Nov 2015 10:27:08 PM IST
use 5.10.0;
use warnings;
#no warnings 'experimental';
use integer;
use strict;
package Text::Bidi::Paragraph;
# ABSTRACT: Run the bidi algorithm on one paragraph
$Text::Bidi::Paragraph::VERSION = '2.18';
use Text::Bidi;
sub new {
my $class = shift;
my $par = shift;
my $self = { @_ };
my @bd = ($self->{'bd'});
$self->{'bd'} = Text::Bidi::S(@bd);
$self->{'par'} = $par;
$self->{'shape'} = 0
if $par =~ /[\p{bc=AL}\p{bc=AN}]/ and not exists $self->{'shape'};
bless $self => $class;
$self->_init
}
for my $f ( qw(par bd dir _par _mirpar _unicode _mirrored )) {
no strict 'refs';
*$f = sub { $_[0]->{$f} };
}
for my $f ( qw(len types levels map) ) {
no strict 'refs';
*$f = sub { $_[0]->{"_$f"} };
}
sub type_names {
my $self = shift;
my $bd = $self->bd;
map { $bd->get_bidi_type_name($_) } @{$self->types}
}
sub is_rtl { $_[0]->dir == $Text::Bidi::private::FRIBIDI_PAR_RTL }
sub _init {
my ($self) = (@_);
my $par = $self->par;
$self->{'_len'} = length($par);
my $bd = $self->bd;
$self->{'_unicode'} = $bd->utf8_to_internal($par);
#$self->{'_par'} = [split '', $par];
$self->{'_types'} = $bd->get_bidi_types($self->_unicode);
($self->{'dir'}, $self->{'_levels'}) =
$bd->get_par_embedding_levels($self->types, $self->dir);
$self->{'_map'} = [0..$#{$self->_unicode}];
$self->{'_unicode'} = $self->shaped($self->{'shape'})
if defined $self->{'shape'};
$self->{'_mirrored'} = $bd->mirrored($self->levels, $self->_unicode);
$self->{'_mirpar'} = $bd->internal_to_utf8($self->_mirrored);
$self->{'_par'} = [split '', $self->_mirpar ];
$self
}
sub ar_props {
my ($self) = (@_);
$self->{'_ar_props'} //= $self->bd->join_arabic($self->types, $self->levels, $self->bd->get_joining_types($self->_unicode))
}
sub shaped {
my ($self, $flags) = (@_);
($self->{'_ar_props'}, $self->{'_shaped'}) = $self->bd->shaped(
$flags, $self->levels, $self->ar_props, $self->_unicode)
unless defined $self->{'_shaped'};
$self->{'_shaped'}
}
sub visual {
( run in 1.081 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )