writing a text widget with pango



Hi All,

I just have some questions about pango. I'm trying to write a text
widget for xchat 2.0, but a few problems remain.

1) There are two ways I can render a PangoLayout:

   gdk_draw_layout (window, gc, layout, x, y);

   -or-

   ln = 0;
   while (1)
        {
                line = pango_layout_get_line (layout, ln);
                if (!line)
                        break;
                gdk_draw_layout_line (window, gc, x, y, line);
                y += this_lines_height;
                ln++;
        }

I thought these two ways would produce the same result, but they
don't. Rendering it line-by-line ignores the alignment setting
(PANGO_ALIGN_CENTER/PANGO_ALIGN_RIGHT). Is this intentional?

2) When your window is resized you have to do alot of work. How
   does GtkTextView handle this? I basically have to walk my entire
   buffer (list of PangoLayouts) and call pango_layout_set_width and
   pango_layout_get_line_count on them all (to set my Adjustment). This
   is pretty CPU intensive when using opaque resize or a large buffer
   (anything beyond a few 100 lines).

3) Mapping the adjustment->value to a position in the text buffer.
   Again, how does GtkTextView do this? It's not as easy as it seems,
   since each entry in the buffer (a PangoLayout) could take up any
   number of lines on the screen (1 or more). Currently I'm doing
   something like:

   l = 0;
   while (buffer)
        {
                l += pango_layout_get_line_count (buffer->layout);
                if (l >= adjustment->value)
                        break;
                buffer = buffer->next;
        }

   This is CPU intensitve aswell. Any suggestions on how to improve
   this algorithm would be appriciated.


4) Is pango_layout_line_get_pixel_extents cheap or should I cache it?

5) In this new GTK2.0/double-buffer world, is it quicker to set your
   GdkWindow background color, or use a 'None' backing pixmap?

Anyway, this is what I came up with in one afternoon, it's looking
pretty good:

http://213.197.30.23/ctext/


-- 
Peter Zelezny.



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