Re: pango_layout_set_alignment not working for printing



On 03/29/2009 12:51 PM, Ian Puleston wrote:
Hi,

I have code that is printing Pango-formatted text, and its working fine. But
now I have a case where I want to print some text centered, which I'm trying
to do using pango_layout_set_alignment and I can't get that to work.

At the start of the print I call gtk_print_context_create_pango_layout to
create a PangoLayout, and then pango_layout_set_text and
pango_layout_set_attributes to set the text and pango attributes in it. I
then print the text line-by-line using pango_layout_get_line_readonly to
extract the line and pango_cairo_show_layout_line to render it. This all
works fine - I can set attributes like font size and color and they print as
they should.

So, to try to print some text centered I added a call to
pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER) on the PangoLayout
right after setting the text and attributes in it, and that did nothing -
the text still prints left-aligned.

I also tried pango_layout_set_justify which also did nothing, and to make
sure the layout was wide enough, added this which also made no difference:
         gdouble pageWidth = gtk_print_context_get_width(context);
         pango_layout_set_width(layout, pageWidth * PANGO_SCALE);

Anyone got any ideas what I might be missing?

The line itself has no information about its placement. You need to get the line_extents from your iterator and render the line at its logical reported logical x,y to get the alignment to work.

behdad



Ian


_______________________________________________
gtk-list mailing list
gtk-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-list



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]