2

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?

4

1 回答 1

2

根据我对文档的阅读,我会说$layout->set_alignment('center');,但我没有使用过 Pango,也没有尝试过。

似乎布局的默认大小紧紧地包裹着内容,所以为了让居中做一些你可以看到的事情,你需要将布局的宽度设置为允许它发生的东西,例如 - $layout->set_width(400)

编辑添加set_width()段落

于 2011-10-06T16:32:25.353 回答