Re: writing a text widget with pango



On 23 May 2002 01:37:15 -0400
Havoc Pennington <hp redhat com> wrote:

The only reason I went to line-by-line, was so that I could chop the top
few lines off, if the scrollbar was in that position. I guess I could
render the whole Layout a few pixels off the top of the window? Either
that, or do my own CENTER/RIGHT calculations (which are simple enough).

Yes, what I'd do is just draw the layout at negative coordinates, it
will be clipped to the window, works great.

But you don't know how many pixels to offset it by, unless you look at
the individual lines' extents anyway.


I thought keeping PangoLayouts around was the fastest way to go.

It probably is, but the memory footprint is most likely unacceptable.
As long as you have only tens of layouts onscreen at once, it should
be fine to create them on-demand. Or at least just keep a limited-size
cache.

True, it keeps alot of GSList around etc. So I converted it to create a
Layout on-the-fly, but the results are a little sluggish. Is there any
room for improvement in pango's internal: pango_layout_check_lines()? It
seems to be spending most of its time here.

I did a test, measuring the width and lines-taken of each paragraph on a 
large buffer (250,000 lines). My old XLib widget did it in about 2 seconds,
pango version takes about 1 minute.

Here's a small improvement for a special case:

--- pango-layout.c      Fri May 24 21:09:27 2002
+++ pango-layout.c.new  Thu May 30 15:12:12 2002
@@ -939,6 +939,10 @@
 {
   g_return_val_if_fail (layout != NULL, 0);
 
+  /* layouts with a width of -1 have no wraps; always 1 line */
+  if (layout->width == -1)
+    return 1;
+
   pango_layout_check_lines (layout);
   return g_slist_length (layout->lines);
 }


I'll probably delve into pango_layout_check_lines() next, and see what
can be done. Perhaps there should be a special version of
pango_layout_get_line_count that doesn't create the layout->lines list (for
when you're just measuring, but not going to render).


-- 
Peter Zelezny.



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