开发者

Text Alignment With Perl Pango

I used Pango with Perl and It succeed rendering a right to left text perfectly (This mission is a nightmare ):

The code :

#!/usr/bin/perl -wT

use strict;
use warnings;
use Pango;
use Encode;

my $surface = Cairo::ImageSurface->create('argb32', 400, 100);
my $cr      = Cairo::Context->create($surface);
my $layout  = Pango::Cairo::create_layout($cr);

my $text    = decode('utf8','测试');
$layout->set_text("$text");

my $font    = Pango::FontDescription->开发者_高级运维from_string ('Serif Bold 50');
$layout->set_font_description($font);

Pango::Cairo::show_layout($cr, $layout);

$surface->write_to_png('pango.png');

However, the only problem I had was within the text alignment. I have no idea how I centralize the text. I read Pango documents, but I didn't find much information. Does anyone know how to do it?


Based on my reading of the docs I would say $layout->set_alignment('center'); but I haven't used Pango and haven't tried it.

And it seems the layout's default size wraps the content tightly so to get the centering to do something you can see you need to set the width of the layout to something that allows it to happen, for example - $layout->set_width(400)

EDIT Add set_width() paragraph

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜