我使用了Perl中的Pango,并成功地完美呈现了从右到左的文本(这个任务真是噩梦):
代码:
#!/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');
然而,我遇到的唯一问题是文本对齐。我不知道如何使文本居中。我阅读了Pango文档,但没有找到太多信息。有人知道怎么做吗?
$layout->set_width(400)
吗? - AFresh1