这里发生什么事情?
pango_font_description_set_family(font.get(),"Serif");
pango_font_description_set_absolute_size(font.get(), 16 * PANGO_SCALE);
int w;
int h;
pango_layout_set_font_description (layout.get(),font.get());
pango_layout_set_width(layout.get(),960*PANGO_SCALE/4);
pango_layout_set_text(layout.get(),"Lorem ipsum dolor sit amet, consctetur adipiscing elit. Nulla vel enim est. Phasellus quis lacinia urna.", -1);
//I want right alignment for this layout
pango_layout_set_alignment(layout.get(),PANGO_ALIGN_RIGHT);
pango_layout_get_pixel_size(layout.get(),&w,&h);
cairo_set_source_rgb (cr.get(), 0.0, 0.0, 0.0);
//Move draw point to the right edge, taking the size of the layout into account
cairo_move_to (cr.get(), 960 - 16 - w,16);
pango_cairo_show_layout(cr.get(), layout.get());
//Draw test rectangle around the text.
cairo_rectangle(cr.get(),960-16-w,16,w,h);
cairo_stroke(cr.get());
cairo_surface_write_to_png(surf.get(),"test.png");如图所示,文本位于所需位置的右侧。我如何才能正确定位文本?cairo_move_to显然不是正确的选择,或者是否有任何已知的bug影响PANGO_ALIGN_CENTER和PANGO_ALIGN_RIGHT的行为。PANGO_ALIGN_LEFT的工作方式与预期一致。

发布于 2017-02-14 21:49:08
问题是pango可能无法在其正确的偏移量处呈现文本。要解决此问题,请使用pango_layout_get_pixel_extents并查询"ink“矩形。请注意,它可能具有非零的x和y分量。从所需位置减去这些偏移量会得到正确的结果。
https://stackoverflow.com/questions/42226415
复制相似问题