Re: calculating text length



On Thu, 2007-04-19 at 11:17 +0300, Tapani Pälli wrote:
> ext Owen Taylor wrote:
> > On Wed, 2007-04-18 at 10:43 +0300, Tapani Pälli 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.

						- Owen

Attachment: signature.asc
Description: This is a digitally signed message part



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