Text-Layout-0.035/ 0000755 0004000 0004000 00000000000 14564576062 011535 5 ustar jv jv Text-Layout-0.035/tests/ 0000755 0004000 0004000 00000000000 14564576062 012677 5 ustar jv jv Text-Layout-0.035/tests/pango00.pl 0000644 0004000 0004000 00000003453 14564576061 014504 0 ustar jv jv #! perl
use strict;
################ Subroutines ################
my $cr;
my $layout;
my $PANGO_SCALE = 1024;
sub showlayout {
my ( $_cr, $_layout, $x, $y ) = @_;
$cr = $_cr;
$layout = $_layout;
$cr->move_to( $x, $y );
$cr->set_source_rgba( 0, 0, 0, 1 );
Pango::Cairo::show_layout( $cr, $layout );
my $dx = ($layout->get_size)[0]/$PANGO_SCALE;
showbb( $x, $y );
return $dx;
}
# Shows the bounding box of the last piece of text that was rendered.
sub showbb {
my ( $x, $y ) = @_;
# Show origin.
_showloc( $x, $y );
# Bounding box, top-left coordinates.
my @e = $layout->get_pixel_extents;
for ( 1, 0 ) {
printf( "%-7s %6.2f %6.2f %6.2f %6.2f\n",
(qw(Ink: Layout:))[$_],
@{%{e[$_]}}{qw( x y width height )} );
}
# NOTE: Some fonts include natural spacing in the bounding box.
# NOTE: Some fonts exclude accents on capitals from the bounding box.
# Show baseline.
$cr->save;
$cr->set_source_rgb(1,0,1);
$cr->set_line_width( 0.25 );
$cr->translate( $x, $y );
my %e = %{$e[1]};
_line( $e{x}, $layout->get_baseline/$PANGO_SCALE, $e{width}, 0 );
# Show BBox.
$cr->rectangle( $e{x}, $e{y}, $e{width}, $e{height} );;
$cr->stroke;
%e = %{$e[0]};
$cr->set_source_rgb(0,1,1);
$cr->rectangle( $e{x}, $e{y}, $e{width}, $e{height} );;
$cr->stroke;
$cr->restore;
}
sub _showloc {
my ( $x, $y, $d ) = @_;
$x ||= 0; $y ||= 0; $d ||= 50;
$cr->save;
$cr->set_source_rgb(0,0,1);
_line( $x-$d, $y, 2*$d, 0 );
_line( $x, $y-$d, 0, 2*$d );
$cr->restore;
}
sub _line {
my ( $x, $y, $w, $h, $lw ) = @_;
$lw ||= 0.5;
$y = $y;
$cr->save;
$cr->move_to( $x, $y );
$cr->rel_line_to( $w, $h );
$cr->set_line_width($lw);
$cr->stroke;
$cr->restore;
}
1;
Text-Layout-0.035/tests/tl_c_01.pl 0000644 0004000 0004000 00000010456 14564576061 014462 0 ustar jv jv #!/usr/bin/perl
# This is an example of using Text::Layout to create the same document
# as native Pango.
#
# This example uses Text::Layout in Pango conformance mode. The
# relevant parts of this program and its Pango counterpart are very
# much the same.
use strict;
use warnings;
use utf8;
use lib "../lib";
use PDF::API2;
use Text::Layout;
# Create document and graphics environment.
my $pdf = PDF::API2->new( file => 'tl_c_01.pdf' );
$pdf->mediabox( 595, 842 ); # A4
# Set up page and get the text context.
my $page = $pdf->page;
my $text = $page->text;
my $gfx = $page->gfx;
# Create a layout instance.
my $layout = Text::Layout->new($pdf);
# Tell Text::Layout that we are running in convenience mode.
# my $PANGO_SCALE = $layout->set_pango_mode(0); # default
my $PANGO_SCALE = $layout->get_pango_scale;
# Scale from Cairo (PDF) font size to Pango.
my $PANGO_FONT_SCALE = 1 * $PANGO_SCALE;
# Font sizes used, scaled.
my $realfontsize = 60;
my $fontsize = $realfontsize * $PANGO_FONT_SCALE;
my $tinysize = 20 * $PANGO_FONT_SCALE;
sub main {
# Select a font.
my $font = Text::Layout::FontConfig->from_string("freeserif 12");
$font->set_size($fontsize);
$layout->set_font_description($font);
# Start...
my $x = 0;
my $y = 500; # PDF goes up
# Text to render.
# Text to render.
my $txt = qq{ Áhe quick }.
# $tinysize = 20 for a 20pt font.
qq{brown }.
# rise is in points
qq{fox}.
# 170.667/1024 units of a 60pt font = 10pt.
qq{x}.
# size=60pt for a 60pt font.
qq{x };
my $txt_nomarkup = "Áhe quick brown fox ";
$layout->set_markup($txt);
# Left align text.
$layout->set_width( 595 * $PANGO_SCALE );
$layout->set_alignment("left");
# Render it.
showlayout( $x, $y );
$y -= 100;
# Right align text.
$layout->set_width( 595 * $PANGO_SCALE );
$layout->set_alignment("right");
# Render it.
showlayout( $x, $y );
$y -= 100;
# Plain PDF::API2, no Text::Layout.
$text->font( $font->{font}, $realfontsize );
# PDF::API2 text is baseline oriented.
$text->translate( $x, $y-50 );
my $dx = $text->text($txt_nomarkup);
if ( $font->{font}->can("extents") ) {
my $e = $font->{font}->extents( $txt_nomarkup, $realfontsize );
printf( "EXT: %.2f %.2f %.2f %.2f\n", @$e{qw( x y width height )} );
$gfx->save;
$gfx->translate( $x, $y-50 );
# PDF::API2 text is baseline oriented, so are the extents.
# So we can draw the BB at the same origin as the text.
$gfx->rect( $e->{x}, $e->{y}, $e->{width}, $e->{height} );
$gfx->linewidth(0.5);
$gfx->strokecolor("cyan");
$gfx->stroke;
$gfx->restore;
}
# Draw baseline.
$gfx->save;
$gfx->translate( $x, $y-50 );
$gfx->move( 0, 0 );
$gfx->line( $dx, 0 );
$gfx->linewidth(0.5);
$gfx->strokecolor("magenta");
$gfx->stroke;
$gfx->restore;
$y -= 100;
# Right align text.
$layout->set_width( 595 * $PANGO_SCALE );
$layout->set_alignment("center");
# Render it.
showlayout( $x, $y );
# Ship out.
$pdf->save;
}
################ Subroutines ################
sub showlayout {
my ( $x, $y ) = @_;
$layout->show( $x, $y, $text);
$layout->showbb($gfx);
}
sub setup_fonts {
$^O =~ /mswin/i ? setup_fonts_windows() : setup_fonts_linux();
}
sub setup_fonts_linux {
my $fd = Text::Layout::FontConfig->new;
# Add font dir and register fonts.
$fd->add_fontdirs( $ENV{HOME}."/.fonts", "/usr/share/fonts/" );
for ( "", qw( Bold Italic BoldItalic ) ) {
$fd->register_font( "FreeSerif$_.ttf", "freeserif", $_,
{ shaping => 0 } );
}
}
sub setup_fonts_windows {
my $fd = Text::Layout::FontConfig->new;
# Add font dir and register fonts.
$fd->add_fontdirs( "C:\\Windows\\Fonts" );
$fd->register_font( "georgia.ttf", "freeserif", "" );
$fd->register_font( "georgiab.ttf", "freeserif", "bold" );
$fd->register_font( "georgiai.ttf", "freeserif", "italic" );
$fd->register_font( "georgiaz.ttf", "freeserif", "bolditalic" );
}
################ Main entry point ################
# Setup the fonts.
setup_fonts();
# Run...
main();
Text-Layout-0.035/tests/pango04.pl 0000644 0004000 0004000 00000001670 14564576061 014507 0 ustar jv jv #!/usr/bin/perl
use strict;
use warnings;
use utf8;
use Pango;
use Cairo;
require "./pango00.pl"; # subs
# Create document and graphics environment.
my $surface = Cairo::PdfSurface->create( 'pango04.pdf', 595, 842 ); # A4
my $cr = Cairo::Context->create($surface);
my $layout = Pango::Cairo::create_layout($cr);
# Scale from Cairo (PDF) units to Pango.
my $PANGO_SCALE = Pango->scale;
# Select a font.
my $font = Pango::FontDescription->from_string('AR PL New Sung 60');
$layout->set_font_description($font);
$layout->get_context->set_base_gravity('west');
# Start...
my $x = 0;
my $y = 842-700;
# Left align text.
$layout->set_width( 595 * $PANGO_SCALE );
$layout->set_alignment("left");
# FireFly is TTB.
# WARNING: If the font cannot be found, a substitute font may come out LTR!.
$layout->set_markup("懶惰的姜貓");
$cr->translate(300,100);
$cr->rotate(2*atan2(1,1));
showlayout( $cr, $layout, $x, $y );
# Ship out.
$cr->show_page;
Text-Layout-0.035/tests/underline.pl 0000644 0004000 0004000 00000002053 14564576061 015220 0 ustar jv jv #!/usr/bin/perl
use strict;
use warnings;
use utf8;
my $verbose = 1;
use PDF::API2;
my $pdf = PDF::API2->new;
my $page = $pdf->page;
my $text = $page->text;
my $font = $pdf->corefont('Times-Roman');
$text->font( $font, 80 );
$text->translate(50,700);
$text->text("the quick brown fox _ ", -underline => ["auto","auto"] );
$text->text("jumps", -underline => "auto" );
use lib 'lib';
use Text::Layout;
my $layout = Text::Layout->new($pdf);
#my $fc = Text::Layout::FontConfig->new( corefonts => 1 );
# Select a font.
$font = Text::Layout::FontConfig->from_string("Times 80");
#my $font = $fc->from_string("Times 60");
$layout->set_font_description($font);
#$font->set_shaping;
$font->{underline_thickness} = 45;
$font->{underline_position} = -100;
$layout->set_markup( qq{the quick brown fox _ jumps} );
$layout->render( 50, 650, $text );
$layout->set_markup( qq{the quick brown fox _ jumps} );
$layout->render( 50, 550, $text );
$pdf->saveas("underline.pdf");
Text-Layout-0.035/tests/tl_p_01.pl 0000644 0004000 0004000 00000007615 14564576061 014502 0 ustar jv jv #!/usr/bin/perl
# This is an example of using Text::Layout to create the same document
# as native Pango.
#
# This example uses Text::Layout in Pango conformance mode. The
# relevant parts of this program and its Pango counterpart are very
# much the same.
use strict;
use warnings;
use utf8;
use lib "../lib";
use PDF::API2;
use Text::Layout;
# Create document and graphics environment.
my $pdf = PDF::API2->new( file => 'tl_p_01.pdf' );
$pdf->mediabox( 595, 842 ); # A4
# Set up page and get the text context.
my $page = $pdf->page;
my $text = $page->text;
my $gfx = $page->gfx;
# Create a layout instance.
my $layout = Text::Layout->new($pdf);
# Tell Text::Layout that we are running in Pango compatibility.
my $PANGO_SCALE = $layout->set_pango_mode("on");
# Scale from Cairo (PDF) font size to Pango.
my $PANGO_FONT_SCALE = 0.75 * $PANGO_SCALE;
# Font sizes used, scaled.
my $realfontsize = 60;
my $fontsize = $realfontsize * $PANGO_FONT_SCALE;
my $tinysize = 20 * $PANGO_FONT_SCALE;
sub main {
# Select a font.
my $font = Text::Layout::FontConfig->from_string("freeserif 12");
$font->set_size($fontsize);
$layout->set_font_description($font);
# Start...
my $x = 0;
my $y = 500; # PDF goes up
# Text to render.
my $txt = qq{ Áhe quick }.
# $tinysize = 15360 for a 20pt font.
qq{brown }.
# rise is in 1/1024 units.
qq{fox}.
# 10240/1024 units = 10pt.
qq{x}.
# size=45pt for a 60pt font.
qq{x };
my $txt_nomarkup = "Áhe quick brown fox ";
$layout->set_markup($txt);
# Left align text.
$layout->set_width( 595 * $PANGO_SCALE );
$layout->set_alignment("left");
# Render it.
showlayout( $x, $y );
$y -= 100;
# Right align text.
$layout->set_width( 595 * $PANGO_SCALE );
$layout->set_alignment("right");
# Render it.
showlayout( $x, $y );
$y -= 100;
# Plain PDF::API2, no Text::Layout.
$text->font( $font->{font}, $realfontsize );
# PDF::API2 text is baseline oriented.
$text->translate( $x, $y-50 );
my $dx = $text->text($txt_nomarkup);
if ( $font->{font}->can("extents") ) {
my $e = $font->{font}->extents( $txt_nomarkup, $realfontsize );
printf( "EXT: %.2f %.2f %.2f %.2f\n", @$e{qw( x y width height )} );
$gfx->save;
$gfx->translate( $x, $y-50 );
# PDF::API2 text is baseline oriented, so are the extents.
# So we can draw the BB at the same origin as the text.
$gfx->rect( $e->{x}, $e->{y}, $e->{width}, $e->{height} );
$gfx->linewidth(0.5);
$gfx->strokecolor("cyan");
$gfx->stroke;
$gfx->restore;
}
# Draw baseline.
$gfx->save;
$gfx->translate( $x, $y-50 );
$gfx->move( 0, 0 );
$gfx->line( $dx, 0 );
$gfx->linewidth(0.5);
$gfx->strokecolor("magenta");
$gfx->stroke;
$gfx->restore;
$y -= 100;
# Right align text.
$layout->set_width( 595 * $PANGO_SCALE );
$layout->set_alignment("center");
# Render it.
showlayout( $x, $y );
# Ship out.
$pdf->save;
}
################ Subroutines ################
sub showlayout {
my ( $x, $y ) = @_;
$layout->show( $x, $y, $text);
$layout->showbb($gfx);
}
sub setup_fonts {
my $fd = Text::Layout::FontConfig->new;
# Add font dir and register fonts.
$fd->add_fontdirs( $ENV{HOME}."/.fonts", "/usr/share/fonts/" );
for ( "", qw( Bold Italic BoldItalic ) ) {
$fd->register_font( "FreeSerif$_.ttf", "freeserif", $_,
{ shaping => 0 } );
}
for ( "Roman", qw( Bold Italic BoldItalic ) ) {
$fd->register_font( "Times-$_", "freeserixf",
$_ eq "Roman" ? "" : $_,
{ shaping => 0 } );
}
}
################ Main entry point ################
# Setup the fonts.
setup_fonts();
# Run...
main();
Text-Layout-0.035/tests/pango03.pl 0000644 0004000 0004000 00000003255 14564576061 014507 0 ustar jv jv #!/usr/bin/perl
use strict;
use warnings;
use utf8;
use Pango;
use Cairo;
require "./pango00.pl"; # subs
# Create document and graphics environment.
my $surface = Cairo::PdfSurface->create( 'pango03.pdf', 595, 842 ); # A4
my $cr = Cairo::Context->create($surface);
my $layout = Pango::Cairo::create_layout($cr);
# Scale from Cairo (PDF) units to Pango.
my $PANGO_SCALE = Pango->scale;
# Select a font.
my $font = Pango::FontDescription->from_string('Amiri 45');
$layout->set_font_description($font);
# Start...
my $x = 0;
my $y = 842-700;
# Left align text.
$layout->set_width( 595 * $PANGO_SCALE );
$layout->set_alignment("left");
# Arabic is RTL, so it comes out as right aligned.
$layout->set_markup( q{برنامج أهلا بالعالم} );
showlayout( $cr, $layout, $x, $y );
$y += 100;
# Typeset in three parts. Note that parts 1 and 3 will be ltr,
# and part 2 will be rtl.
$layout->set_markup("abc");
$x += showlayout( $cr, $layout, $x, $y );
$layout->set_markup( q{برنامج أهلا بالعالم} );
# Arabic is RTL, restrict to actual width to prevent unwanted alignment.
my $dx = ($layout->get_size)[0];
$layout->set_width($dx);
$x += showlayout( $cr, $layout, $x, $y );
$layout->set_markup("xyz");
$dx = ($layout->get_size)[0];
$layout->set_width($dx);
showlayout( $cr, $layout, $x, $y );
# Typeset as one string, using .
$x = 0;
$y += 100;
$font = Pango::FontDescription->from_string("Sans 45");
$layout->set_font_description($font);
$layout->set_width( 595 * $PANGO_SCALE );
$layout->set_markup( "abc".
"".q{برنامج أهلا بالعالم}."".
"def" );
showlayout( $cr, $layout, $x, $y );
# Ship out.
$cr->show_page;
Text-Layout-0.035/tests/pango02.pl 0000644 0004000 0004000 00000003557 14564576061 014513 0 ustar jv jv #!/usr/bin/perl
use strict;
use warnings;
use utf8;
use Pango;
use Cairo;
require "./pango00.pl"; # subs
# Create document and graphics environment.
my $surface = Cairo::PdfSurface->create( 'pango02.pdf', 595, 842 ); # A4
my $cr = Cairo::Context->create($surface);
my $layout = Pango::Cairo::create_layout($cr);
# Scale from Cairo (PDF) units to Pango.
my $PANGO_SCALE = Pango->scale;
# Scale from Cairo (PDF) font size to Pango.
my $PANGO_FONT_SCALE = 0.75 * $PANGO_SCALE;
# Font sizes used, scaled.
my $realfontsize = 60;
my $fontsize = $realfontsize * $PANGO_FONT_SCALE;
my $tinysize = 20 * $PANGO_FONT_SCALE;
# Select a font.
my $font = Pango::FontDescription->from_string('freeserif 12');
$font->set_size($fontsize);
$layout->set_font_description($font);
# Start...
my $x = 0;
my $y = 842-500; # Cairo goes down
# Text to render.
$layout->set_markup( q{ Áhe quick brown fox } );
# Left align text.
$layout->set_width( 595 * $PANGO_SCALE );
$layout->set_alignment("left");
# Render it.
showlayout( $cr, $layout, $x, $y );
$y += 100;
# Right align text.
$layout->set_width( 595 * $PANGO_SCALE );
$layout->set_alignment("right");
# Render it.
showlayout( $cr, $layout, $x, $y );
$y += 100;
$font = Pango::FontDescription->from_string('Lohit Devanagari 45');
$layout->set_font_description($font);
$layout->set_width( 595 * $PANGO_SCALE );
# Nepali is LTR.
$layout->set_alignment("left");
# This text consists of 6 characters but will render 4 glyphs.
my $phrase =
"\N{DEVANAGARI LETTER TA}".
"\N{DEVANAGARI LETTER MA}".
"\N{DEVANAGARI VOWEL SIGN AA}".
"\N{DEVANAGARI LETTER NGA}".
"\N{DEVANAGARI SIGN VIRAMA}".
"\N{DEVANAGARI LETTER GA}".
qq{ this should look like THIS};
$layout->set_markup($phrase);
showlayout( $cr, $layout, $x, $y );
# Ship out.
$cr->show_page;
Text-Layout-0.035/tests/md1.pl 0000644 0004000 0004000 00000001124 14564576061 013712 0 ustar jv jv #!/usr/bin/perl
use strict;
use warnings;
use utf8;
use lib "../lib";
use Text::Layout::Markdown;
# Create a layout instance.
my $layout = Text::Layout::Markdown->new;
binmode( STDOUT, ':utf8' );
# Text to render.
$layout->set_markup( q{Áhe quick brown fox} );
# Render it.
print $layout->show(), "\n";
# Text to render.
$layout->set_markup( q{Áhe quick brown fox} );
# Right align text (will be ignored w/ Markdown).
$layout->set_width(50);
$layout->set_alignment("center");
# Render it.
print $layout->show(), "\n";
Text-Layout-0.035/tests/tl_c_02.pl 0000644 0004000 0004000 00000011712 14564576061 014457 0 ustar jv jv #!/usr/bin/perl
use strict;
use warnings;
use utf8;
use lib "../lib";
use PDF::API2;
use Text::Layout;
use Text::Layout::FontConfig;
use HarfBuzz::Shaper 0.026;
# Create document and graphics environment.
my $pdf = PDF::API2->new();
$pdf->mediabox( 595, 842 ); # A4
# Set up page and get the text context.
my $page = $pdf->page;
my $text = $page->text;
my $gfx = $page->gfx;
# Create a layout instance.
my $layout = Text::Layout->new($pdf);
my $PANGO_SCALE;
sub main {
# Select a font.
my $font = Text::Layout::FontConfig->from_string("Sans 44");
$layout->set_font_description($font);
# Start...
my $x = 0;
my $y = 700;
# Text to render.
$layout->set_markup( q{ Áhe quick brown fox } );
# Left align text.
$layout->set_width( 595 * $PANGO_SCALE );
$layout->set_alignment("left");
# Render it.
showlayout( $x, $y );
$y -= 100;
# Right align text.
$layout->set_width( 595 * $PANGO_SCALE );
$layout->set_alignment("right");
# Render it.
showlayout( $x, $y );
$y -= 100;
$text->font( $font->{font}, 44);
$text->translate( $x, $y-50 );
my $txt_nomarkup = q{Áhe quick brown fox};
my $dx = $text->text($txt_nomarkup);
if ( $font->{font}->can("extents") ) {
my $e = $font->{font}->extents( $txt_nomarkup, 44 );
printf( "EXT: %.2f %.2f %.2f %.2f\n", @$e{qw( x y width height )} );
$gfx->save;
$gfx->translate( $x, $y-50 );
# PDF::API2 text is baseline oriented, so are the extents.
# So we can draw the BB at the same origin as the text.
$gfx->rect( $e->{x}, $e->{y}, $e->{width}, $e->{height} );
$gfx->linewidth(0.5);
$gfx->strokecolor("cyan");
$gfx->stroke;
$gfx->restore;
}
# Draw baseline.
$gfx->save;
$gfx->translate( $x, $y-50 );
$gfx->move( 0, 0 );
$gfx->line( $dx, 0 );
$gfx->linewidth(0.5);
$gfx->strokecolor("magenta");
$gfx->stroke;
$gfx->restore;
$y -= 100;
# Text to render.
# $layout->set_markup( q{Áhe quick brown fox} );
# Right align text.
$layout->set_width( 595 * $PANGO_SCALE );
$layout->set_alignment("center");
# Render it.
showlayout( $x, $y );
$y -= 100;
# This will only work properly with the HarfBuzz driver.
$font = Text::Layout::FontConfig->from_string("Deva 60");
$layout->set_font_description($font);
$layout->set_width( 595 * $PANGO_SCALE );
# Nepali is LTR.
$layout->set_alignment("left");
# This text consists of 6 characters but will render 4 glyphs.
my $phrase =
"\N{DEVANAGARI LETTER TA}".
"\N{DEVANAGARI LETTER MA}".
"\N{DEVANAGARI VOWEL SIGN AA}".
"\N{DEVANAGARI LETTER NGA}".
"\N{DEVANAGARI SIGN VIRAMA}".
"\N{DEVANAGARI LETTER GA}".
qq{ this should look like THIS};
$layout->set_markup($phrase);
showlayout( $x, $y );
# Ship out.
$pdf->saveas("tl_c_02.pdf");
}
################ Subroutines ################
sub showlayout {
my ( $x, $y ) = @_;
$layout->show( $x, $y, $text);
$layout->showbb($gfx);
}
sub setup_fonts {
$^O =~ /mswin/i ? setup_fonts_windows() : setup_fonts_linux();
}
sub setup_fonts_linux {
# Register all corefonts. Useful for fallback.
# Not required, skip if you have your own fonts.
my $fd = Text::Layout::FontConfig->new;
# $fd->register_corefonts;
# Add font dir and register fonts.
$fd->add_fontdirs( ".", $ENV{HOME}."/.fonts", "/usr/share/fonts/" );
# Add a Sans family.
$fd->register_font( "DejaVuSans.ttf", "Sans" );
$fd->register_font( "DejaVuSans-Bold.ttf", "Sans", "Bold" );
$fd->register_font( "DejaVuSans-Oblique.ttf", "Sans", "Italic" );
$fd->register_font( "DejaVuSans-BoldOblique.ttf", "Sans", "BoldItalic" );
# Add Devanagari. Requires shaping.
# Note that Nepali is a LTR language.
$fd->register_font( "Lohit-Devanagari.ttf",
"Deva", "", "",
{ shaping => 1,
language => 'nepali'
} );
}
sub setup_fonts_windows {
# Register all corefonts. Useful for fallback.
# Not required, skip if you have your own fonts.
my $fd = Text::Layout::FontConfig->new;
# $fd->register_corefonts;
# Add font dir and register fonts.
$fd->add_fontdirs( ".", "C:\\Windows\\Fonts" );
$fd->register_font( "arial.ttf", "sans", "" );
$fd->register_font( "arialbd.ttf", "sans", "bold" );
$fd->register_font( "ariali.ttf", "sans", "italic" );
$fd->register_font( "arialbi.ttf", "sans", "bolditalic" );
# Add Devanagari. Requires shaping.
# Note that Nepali is a LTR language.
$fd->register_font( "Lohit-Devanagari.ttf",
"Deva", "", "",
{ shaping => 1,
language => 'nepali'
} );
}
################ Main entry point ################
# Setup the fonts.
setup_fonts();
if ( @ARGV ) {
# For compliancy, use Pango units;
$PANGO_SCALE = $layout->set_pango_mode("on");
}
else {
$PANGO_SCALE = 1;
}
main();
Text-Layout-0.035/tests/tl_c_03.pl 0000644 0004000 0004000 00000005447 14564576061 014470 0 ustar jv jv #!/usr/bin/perl
use strict;
use warnings;
use utf8;
use PDF::API2;
use lib "../lib";
use Text::Layout;
use Text::Layout::FontConfig;
eval { require HarfBuzz::Shaper }
or warn("HarfBuzz::Shaper not found. Expect incorrect results!\n");
# Create document and graphics environment.
my $pdf = PDF::API2->new();
$pdf->mediabox( 595, 842 ); # A4
# Set up page and get the text context.
my $page = $pdf->page;
my $text = $page->text;
# Create a layout instance.
my $layout = Text::Layout->new($pdf);
# Select a font.
setup_fonts();
my $font = Text::Layout::FontConfig->from_string("Amiri 60");
$layout->set_font_description($font);
# Start...
my $x = 0;
my $y = 700;
# Left align text.
$layout->set_width(595);
$layout->set_alignment("left");
# Arabic is RTL, so it comes out as right aligned.
$layout->set_markup( q{برنامج أهلا بالعالم} );
showlayout( $x, $y );
# Typeset in three parts. Note that parts 1 and 3 will be ltr,
# and part 2 will be rtl.
# Note, however, that this currently relies on the native
# harfbuzz library to correctly determine ('guess') the
# characteristics of the text.
$y -= 100;
$layout->set_markup("abc");
$x += showlayout( $x, $y );
$layout->set_markup( q{برنامج أهلا بالعالم} );
# Arabic is RTL, restrict to actual width to prevent unwanted alignment.
$layout->set_width( ($layout->get_size)[0] );
$x += showlayout( $x, $y );
$layout->set_markup("xyz");
showlayout( $x, $y );
# Typeset as one string, using .
$x = 0;
$y -= 100;
$font = Text::Layout::FontConfig->from_string("Sans 60");
$layout->set_font_description($font);
$layout->set_markup( "abc".
"".q{برنامج أهلا بالعالم}."".
"def" );
showlayout( $x, $y );
# Ship out.
$pdf->saveas("tl_c_03.pdf");
################ Subroutines ################
my $gfx;
sub showlayout {
my ( $x, $y ) = @_;
$layout->show( $x, $y, $text);
my $dx = ($layout->get_size)[0];
$gfx //= $page->gfx;
$layout->showbb($gfx);
return $dx;
}
sub setup_fonts {
my $fd = Text::Layout::FontConfig->new;
# Add font dir and register fonts.
$fd->add_fontdirs( $ENV{HOME}."/.fonts", "/usr/share/fonts/" );
# Add a Sans family.
$fd->register_font( "FreeSans.ttf", "Sans" );
$fd->register_font( "FreeSansBold.ttf", "Sans", "Bold" );
$fd->register_font( "FreeSansOblique.ttf", "Sans", "Italic" );
$fd->register_font( "FreeSansBoldOblique.ttf", "Sans", "BoldItalic" );
# Add Devanagari (Indian). Requires shaping.
$fd->register_font( "lohit-devanagari/Lohit-Devanagari.ttf",
"Deva", "", "", { shaping => 1 } );
# Add Amiri (Arabic). Requires shaping.
$fd->register_font( "amiri/amiri-regular.ttf",
"Amiri", "", "",
{ shaping => 1,
nosubset => 1,
} );
}
Text-Layout-0.035/tests/Lohit-Devanagari.ttf 0000644 0004000 0004000 00000456604 14434450771 016545 0 ustar jv jv FFTM|c , GDEFTW H GPOS@ d
,GSUBA2M OS/2њ `cmapEjg ! Pcvt ] N fpgmb2 N gasp M glyfh %\ nhead 6hhea% $hmtxg ( locag D maxpPY # namegb # post?` * #prepO \ . A9 ܿ+ * 0 13 4a bb cj kk ll mm no p~ $ %&