使用 Perl Pango 进行文本对齐
我将 Pango 与 Perl 结合使用,它成功地赋予了完美地留下文本(这个任务是一场噩梦):
代码:
#!/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 文档,但没有找到太多信息。有谁知道该怎么做?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据我的阅读文档我会说< code>$layout->set_alignment('center'); 但我没有使用过Pango,也没有尝试过。
布局的默认大小似乎紧紧地包裹着内容,因此为了让居中做一些您可以看到的事情,您需要将布局的宽度设置为允许它发生的东西,例如 -
$layout->; set_width(400)
编辑添加
set_width()
段落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