Re: calculating text length

ext Owen Taylor wrote:
> On Thu, 2007-04-19 at 11:17 +0300, Tapani P�i wrote:
>> ext Owen Taylor wrote:
>>> On Wed, 2007-04-18 at 10:43 +0300, Tapani P�i wrote:
>>>> Hello,
>>>> I have a performance problem with Matchbox window manager calculating
>>>> window title width rather slowly with Pango when doing ellipsation for
>>>> the title. The current algorithm is rather poor but produces good result
>>>> and works nicely for short titles, however when our browser puts the
>>>> title of a webpage as window title and webpage titles seem to sometimes
>>>> be even 300 characters long ...
>>>> Current algorithm takes the title, goes from title's end to begin and
>>>> inserts '...\0' to end and check if it would fit now. Result is always
>>>> perfect. However it calls several Pango funcs when checking the width
>>>> and besides of the algorithm I'd like to optimize width check aswell. It
>>>> calls pango_itemize() and then pango_shape, pango_glyph_string_extents
>>>> for each resulted item (word?) just like when rendering text. I thought
>>>> one way would be to take 'average char width' and then calculate some
>>>> pessimistic result out of that (?) I'd like to know if there's a quick
>>>> way to have extents for all characters in a string or maybe some other
>>>> way to quickly check how many characters of $string would fit in $w pixels.
>>> Can't you just use the ellipsization feature of Pango? That's going to
>>> be considerably faster than the algorithm you describe.
>> I guess this is only with pango-layout? I think Matchbox is not using
>> layout because the rendering is slower than with just doing it in a loop
>> with pango-glyph-string, window title is single line always.
> Care to show benchmarks? 
> While there is obviously some overhead from the PangoLayout object, the
> cost of laying out text in Pango is mostly the cost of laying out the
> text ... that is, within pango_itemize() and pango_shape().
> If you use PangoLayout, you get to delete considerable amounts of code,
> and you get a carefully written, smart, ellipsization algorithm.

Hmm OK, I will test with layout aswell. Like I said 'i think' it has
overhead :) It would be definitely nice to get things done
automatically. Maybe the main reason todo things like it's currently
being done is to have a generic codebase which fits to multiple backends
such as Pango. pango_glyph_string_get_logical_widths() was something I
was actually originally looking for ...

> 						- Owen

// Tapani

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