Re: canvas rich text widget?



Bibek Sahu <scorpio dodds net> writes: 
> 	Oooh... I like. :-)
> 
> 	However, as the documents state, it is somewhat resource-hungry. 
> This I do not like.  The new internal structure I came up with was designed
> to have a small footprint, but only if you didn't change the styles too
> much... since this tktext-port only bloats in its footprint if you change
> styles often, I imagine it's just as good as what I had in mind.  Besides --
> this is essentially the same as what's going into Gtk+ 2.0; I can now pray
> that the Gtk+ folks take care of the memory overhead issues. ;-)
> 

There is an unavoidable size-speed tradeoff with a text buffer like
this. There are quite a few places where you can draw the line, but
the tradeoff is unavoidable; either you are slow in lots of cases but
use minimal RAM, or you are fast in lots of cases and use more RAM.

The GTK widget tries to balance size vs. speed nicely, but of course
some people will disagree with the correct balance. In any case, don't
think you can just shrink the widget without speed/feature penalties.
Or that you can add features/speed without growing the widget
further. ;-) No free lunches.
 
> 	As I said, I like it.  What I'm going to /try/ to do is grab the
> gtk+ 2.0 text widget and convert it over to drawing on the canvas.  I am not
> yet sure how feasible an idea this is; the reason I thought of it is because
> the tktext-port docs say that it should be easy to swap-out the underlying
> backend, and because Havoc said that the gtk+ 2.0 version uses Pango to do
> rendering, and Pango has a freetype renderer.  If it can do that, then I can
> probably <cross fingers> get it to render freetype text to a GdkPixmap
> (technically a GdkWindow, which underlies the Pixmap [or did when I last
> checked]).  And as I recall, the important part of the Canvas buffer was
> basically a GdkPixmap.
> 
> 	Since it's probably already rendering to a GdkWindow, I may not even
> have to change that part of the code.  What I /will/ have to deal with is
> the pango stuff.  I know /of/ Pango, but that's really where it ends with
> me.
> 

You shouldn't need to touch Pango. You can use all the text widget
files except for gtktreeview.h, gtktreeview.c. The rendering and such
is abstracted into gtktextlayout.h, gtktextdisplay.h. You simply need
to write a canvas item which uses the backend in the same way as the
GtkTreeView widget.

The GtkTreeView frontend is 6,000 semicolon-terminated lines of code
you have to duplicate in the canvas item, but the total text widget is
25,000 "grep ';'" lines of code, so you are saving yourself 20K lines
or so by reusing the backend, which is a fair amount of work to
save. ;-)

Havoc





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