Text-Bidi
view release on metacpan or search on metacpan
bin/fribidi.pl view on Meta::CPAN
#!perl
# PODNAME: fribidi.pl
# ABSTRACT: Convert logical text to visual, via the unicode bidi algorithm
use 5.10.0;
use warnings;
use integer;
use strict;
use open ':encoding(utf8)';
use open ':std';
use Text::Bidi 2.07 qw(log2vis get_bidi_type_name fribidi_version);
use Text::Bidi::Constants;
#use Carp::Always;
use Getopt::Long qw(:config gnu_getopt auto_help auto_version);
our $VERSION = "2.07\nlibfribidi " . fribidi_version;
our $width = $ENV{'COLUMNS'} // 80;
our %Opts = ('width=i' => \$width);
GetOptions(\%Opts, qw(break:s rtl! ltr! levels! hex! dir! ltov! types! verbose! width=i));
$Opts{'break'} = ' ' if defined($Opts{'break'}) and ($Opts{'break'} eq '');
if ($Opts{'verbose'}) {
$Opts{$_} = 1 foreach (qw(levels dir ltov types hex));
}
# read paragraphs (and make perlcritic happy with 'local')
local $/ = '';
my $flags;
$flags = { break => $Opts{'break'} } if defined $Opts{'break'};
my $dir = $Opts{'rtl'} ? $Text::Bidi::Par::RTL
: $Opts{'ltr'} ? $Text::Bidi::Par::LTR : undef;
while (<>) {
chomp;
s/ *\n */ /g;
my ($p, $visual) = log2vis($_, $width, $dir, $flags);
say $visual;
say '';
say STDERR "Base dir: " . get_bidi_type_name($p->dir) if $Opts{'dir'};
say STDERR "Hex: " . join(' ', map { sprintf("%x", ord($_)) } split '');
say STDERR "Types: " . join(' ', $p->type_names) if $Opts{'types'};
say STDERR "Levels: " . join(' ', @{$p->levels}) if $Opts{'levels'};
}
# start of POD
__END__
=pod
=head1 NAME
fribidi.pl - Convert logical text to visual, via the unicode bidi algorithm
=head1 VERSION
version 2.18
=head1 SYNOPSIS
# display bidi text given in logical order in foo.txt
fribidi.pl foo.txt
# same, but force Right-To-Left paragraph direction
fribidi.pl --rtl foo.txt
# same, but break lines on spaces
fribidi.pl --rtl --break -- foo.txt
=head1 DESCRIPTION
This script is similar to the fribidi(1) program provided with libfribidi,
and performs a subset of its functions. The main point is to test
L<Text::Bidi> and provide a usage example.
=head1 OPTIONS
=over
=item --(no)ltr
Force all paragraph directions to be Left-To-Right. The default is to deduce
the paragraph direction via the bidi algorithm.
=item --(no)rtl
Force all paragraph directions to be Right-To-Left. The default is to deduce
the paragraph direction via the bidi algorithm.
=item --width=I<n>
( run in 3.133 seconds using v1.01-cache-2.11-cpan-364913b4093 )