Prima
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
Prima/Drawable/Glyphs.pm view on Meta::CPAN
sub justify_tabs
{
my ($self, $canvas, $text, %opt) = @_;
return unless $text =~ /\t/s;
my $glyphs = $self->[GLYPHS] or return;
my $indexes = $self->[INDEXES] or return;
my $advances = $self->[ADVANCES] or return;
my $fonts = $self->[FONTS];
my $length = @$advances;
my $ntabs = $opt{tabs} // 8;
my ($space, $width);
if ( exists $opt{glyph}) {
$space = $opt{glyph};
$width = $opt{width};
} elsif ( my $s = $canvas->text_shape("\x{20}",
advances => 1,
reorder => 0,
rtl => 0,
level => ts::Glyphs,
)
) {
$space = $s->[GLYPHS]->[0];
$width = $s->[ADVANCES]->[0];
} else {
return;
}
$width *= $ntabs;
for ( my $i = 0; $i < $length; $i++) {
my $ix = $indexes->[$i] & ~to::RTL;
next unless substr($text, $ix, 1) eq "\t";
$glyphs->[$i] = $space;
$advances->[$i] = $width;
$fonts->[$i] = 0 if $fonts;
}
return wantarray ? ( 1, $space, $width ) : 1;
}
sub justify
{
my ($self, $canvas, $text, $width, %opt) = @_;
my $ok = 0;
$ok |= ($self->justify_arabic($canvas, $text, $width, %opt) || 0) if
$opt{kashida};
$ok |= ($self->justify_interspace($canvas, $text, $width, %opt) || 0) if
$opt{letter} || $opt{word};
$ok |= ($self->justify_tabs($canvas, $text, %opt) || 0) if
exists $opt{tabs};
return $ok;
}
1;
=pod
=head1 NAME
Prima::Drawable::Glyphs - helper routines for bi-directional text input and complex scripts output
=head1 SYNOPSIS
=encoding utf-8
=for latex-makedoc header
\usepackage{amsmath,amssymb}
\DeclareFontFamily{U}{rcjhbltx}{}
\DeclareFontShape{U}{rcjhbltx}{m}{n}{<->rcjhbltx}{}
\DeclareSymbolFont{hebrewletters}{U}{rcjhbltx}{m}{n}
\DeclareMathSymbol{\alef}{\mathord}{hebrewletters}{39}
\DeclareMathSymbol{\pe}{\mathord}{hebrewletters}{112}
\DeclareMathSymbol{\samekh}{\mathord}{hebrewletters}{115}
=begin latex-makedoc
=begin latex
\begin{tt}
~ ~\\
\hspace*{1.5em}use Prima;\\
\hspace*{1.5em}\$::application->begin\_paint;\\
\hspace*{1.5em}\$application->text\_out('$\alef\pe\samekh123$',100,100);\\
\\
\hspace*{1.5em}123$\samekh\pe\alef$\\
\end{tt}
=end latex
=end latex-makedoc
=for latex-makedoc cut
use Prima;
$::application-> begin_paint;
â$::application-> text_shape_out('×פס123', 0,0);
â123ספ×
=for latex-makedoc cut
=head1 DESCRIPTION
The class implements an abstraction over a set of glyphs that can be rendered
to represent text strings. Objects of the class are created and returned from
C<Prima::Drawable::text_shape> calls, see more in
L<Prima::Drawable/text_shape>. A C<Prima::Drawable::Glyphs> object is a blessed
array reference that can contain either two, four, or five packed arrays with
16-bit integers, representing, correspondingly, a set of glyph indexes, a set
of character indexes, a set of glyph advances, a set of glyph position offsets
per glyph, and a font index. Additionally, the class implements several sets of
helper routines that aim to address common tasks when displaying glyph-based
strings.
=head2 Structure
Each sub-array is an instance of C<Prima::array>, an effective plain memory
structure that provides standard perl interface over a string scalar filled
with fixed-width integers.
The following methods provide read-only access to these arrays:
=over
view all matches for this distributionview release on metacpan - search on metacpan
( run in 1.923 second using v1.00-cache-2.02-grep-82fe00e-cpan-9f2165ba459b )