1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
#!/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 <span>.
$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".
"<span font='Amiri'>".q{برنامج أهلا بالعالم}."</span>".
"def" );
showlayout( $cr, $layout, $x, $y );
# Ship out.
$cr->show_page;
|