Re: Significance of "width != 1" in Pango layouts?



Tony Graham <Tony Graham ireland sun com> writes:

> The definition of pango_x_render_layout() in pangox.c (and similar
> code in pangoft2.c, etc.) contains:
> 
>   if (width == -1 && align != PANGO_ALIGN_LEFT)
>     {
>       pango_layout_get_extents (layout, NULL, &logical_rect);
>       width = logical_rect.width;
>     }
>   
>   tmp_list = pango_layout_get_lines (layout);
>   while (tmp_list)
>     {
>       PangoLayoutLine *line = tmp_list->data;
>       int x_offset;
>       
>       pango_layout_line_get_extents (line, NULL, &logical_rect);
> 
>       if (width != 1 && align == PANGO_ALIGN_RIGHT)
> 	x_offset = width - logical_rect.width;
>       else if (width != 1 && align == PANGO_ALIGN_CENTER)
> 	x_offset = (width - logical_rect.width) / 2;
>       else
> 	x_offset = 0;
> 
> I believe that I understand the significance of the "width == -1" test
> -- if true, the lines aren't wrapped -- but I don't understand the
> significance of "width == 1", especially since I can't find any code
> that explicitly sets a layouts width to 1.
> 
> Also, since the width is in Pango units, the width would have to be a
> lot larger than 1 before the changes in x_offset made any visible
> difference.
> 
> What is the significance of testing that width != 1?

I believe that it's probably just a typo for -1, though it's not clear
why that test would being made.

pango_x_render_layout() is basically unused code outside of the
pango-viewer test program, and as is the case with most unused code,
it has rotted. The tested, debugged and improved version of this code
is gtk+/gdk/gdk/gdkpango.c:gdk_draw_layout().

[ Being in GTK+, it can be shared across backends, and also makes things
like handling color allocation a lot easier. ]

The easiest way to fix pango_*_render_layout() would probably be to
backport the code from gdk_draw_layout() to each backend.

Regards,
                                        Owen




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