Text-Layout-0.038/ 0000755 0004000 0004000 00000000000 14660205422 011522 5 ustar jv jv Text-Layout-0.038/tests/ 0000755 0004000 0004000 00000000000 14660205422 012664 5 ustar jv jv Text-Layout-0.038/tests/im1.pl 0000644 0004000 0004000 00000007366 14660205421 013722 0 ustar jv jv #!/usr/bin/perl
use strict;
use warnings;
use utf8;
binmode( STDOUT => ':utf8' );
binmode( STDERR => ':utf8' );
use PDF::API2;
use lib "../lib";
use Text::Layout;
use Text::Layout::FontConfig;
# 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);
# Setup the fonts.
setup_fonts();
# Select a font.
my $font = Text::Layout::FontConfig->from_string("Sans 45");
$layout->set_font_description($font);
$layout->register_element
( TextLayoutImageElement->new( pdf => $pdf ), "img" );
# Start...
my $x = 0;
my $y = 730;
#=for later
# Text to render.
$layout->set_markup("abc
def");
showlayout( $x, $y );
$layout->set_markup("abc
def");
showlayout( $x+300, $y );
$y -= 150;
$layout->set_markup("abc
def");
showlayout( $x, $y );
$layout->set_markup("abc
def");
showlayout( $x+300, $y );
$y -= 150;
$layout->set_markup("abc
def");
# Render it.
showlayout( $x, $y );
$y -= 150;
#=cut
# Make a non-zero origin object.
my $xo = $pdf->xo_form;
$xo->fill_color("lime");
$xo->stroke_color("green");
$xo->linewidth(2);
$xo->bbox( -10, -10, 30, 70);
$xo->transform( translate => [ -10, -10 ] );
$xo->rectangle(0,0,40,80);
$xo->fill;
$xo->move(10,0)->vline(80)->stroke;
$xo->move(0,10)->hline(40)->stroke;
my $dd = "";
$layout->set_markup("abc
def");
showlayout( $x, $y );
$layout->set_markup("abc
def");
showlayout( $x+300, $y );
$y -= 150;
$dd = "dx=10 dy=10";
$layout->set_markup("abc
def");
showlayout( $x, $y );
$layout->set_markup("abc
def");
showlayout( $x+300, $y );
$y -= 150;
$pdf->saveas("pdfapi2.pdf");
################ Subroutines ################
sub showlayout {
my ( $x, $y ) = @_;
$y -= $layout->get_baseline;
$layout->show( $x, $y, $text);
$layout->showbb($gfx);
}
sub setup_fonts {
# Register all corefonts. Useful for fallback.
# Not required, skip if you have your own fonts.
my $fd = Text::Layout::FontConfig->new;
# $fd->register_corefonts;
$fd->add_fontdirs( $ENV{HOME}."/.fonts", "/usr/share/fonts/" );
$fd->register_font( "ITCGaramond-Light.ttf", "Garamond" );
$fd->register_font( "ITCGaramond-Bold.ttf", "Garamond", "Bold" );
$fd->register_font( "ITCGaramond-LightItalic.ttf", "Garamond", "Italic" );
$fd->register_font( "ITCGaramond-BoldItalic.ttf", "Garamond", "BoldItalic" );
# Make Serif alias for Garamond.
$fd->register_aliases( "Garamond", "Serif" );
# Add a Sans family.
$fd->register_font( "DejaVuSans.ttf", "Sans", "",
{ shaping => 0 }
);
$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 a Sans family.
$fd->register_font( "calibri.ttf", "Cal", "", );
$fd->register_font( "calibrib.ttf", "Cal", "Bold" );
$fd->register_font( "calibri.ttf", "Cal", "Italic" );
$fd->register_font( "calibrii.ttf", "Cal", "BoldItalic" );
}
################ Classes ################
use Object::Pad;
class TextLayoutImageElement :isa(Text::Layout::PDFAPI2::ImageElement);
method getimage ($fragment) {
$fragment->{_img} //=
do {
if ( $fragment->{src} eq "xo" ) {
$xo;
}
else {
$pdf->image($fragment->{src});
}
};
}
1;
Text-Layout-0.038/tests/tl_p_02.pl 0000644 0004000 0004000 00000010633 14660205421 014462 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;
my $gfx = $page->gfx;
# Create a layout instance.
my $layout = Text::Layout->new($pdf);
my $PANGO_SCALE = $layout->set_pango_mode("on");
# Setup the fonts.
setup_fonts();
# Select a font.
my $font = Text::Layout::FontConfig->from_string("Sans 33");
$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;
# 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 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( $x, $y );
# Ship out.
$pdf->saveas("tl_p_02.pdf");
################ Subroutines ################
sub showlayout {
my ( $x, $y ) = @_;
$layout->show( $x, $y, $text);
$layout->showbb($gfx);
}
sub setup_fonts {
# 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/" );
$fd->register_font( "ITCGaramond-Light.ttf", "Garamond" );
$fd->register_font( "ITCGaramond-Bold.ttf", "Garamond", "Bold" );
$fd->register_font( "ITCGaramond-LightItalic.ttf", "Garamond", "Italic" );
$fd->register_font( "ITCGaramond-BoldItalic.ttf", "Garamond", "BoldItalic" );
# Make Serif alias for Garamond.
$fd->register_aliases( "Garamond", "Serif" );
# 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/Lohit-Devanagari.ttf",
"Deva", "", "",
{ shaping => 1,
language => 'nepali'
} );
my $o = { interline => 1 };
$fd->register_font( "Helvetica", "Sanss", "", "", $o );
$fd->register_font( "HelveticaOblique", "Sanss", "Italic", "", $o );
$fd->register_font( "HelveticaBold", "Sanss", "Bold", "", $o );
}
Text-Layout-0.038/tests/tl_c_03.pl 0000644 0004000 0004000 00000005447 14660205421 014455 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.038/tests/ab.jpg 0000644 0004000 0004000 00000005773 14507251316 013767 0 ustar jv jv JFIF Created with The GIMPICC_PROFILE lcms@ mntrRGB XYZ
4 -acspAPPL -lcms
desc @cprt ` 6wtpt chad ,rXYZ bXYZ gXYZ rTRC gTRC bTRC chrm 4 $dmnd X $dmdd | $mluc enUS $ G I M P b u i l t - i n s R G Bmluc enUS P u b l i c D o m a i n XYZ -sf32 B % nXYZ o 8 XYZ $ XYZ b para ff
Y
[chrm T| L &g