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 67 68 69 70 71 72 73 74 75 76
|
#!/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 <i><span foreground="red">quick</span> <span size="15360"><b>brown</b></span></i> 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{ <span font="sans 20"> this should look like THIS</span>};
$layout->set_markup($phrase);
showlayout( $cr, $layout, $x, $y );
# Ship out.
$cr->show_page;
|