slow pango text drawing



Hello,

First thing to say is that I'm very new to Gtk+. ;)

I'd like to to create my own widget, which will draw the binary contents
(using cp437 codepage) of a file on the screen. For this I thought I'd use
Pango for text rendering and Cairo for drawing some primitives (background,
some boxes, etc). My current approach is to draw each character into each
block on the screen. Each block is 8x8 pixels, so when the window is resized
to f.e. 640x480, there will be ~80x60 characters on the screen (total 4800
chars). I'd like to use char-by-char drawing, because later I'd like to add
different colors (or other transformations) to different chars (I want to
build a small and simple binary file visualization app).

Problem is that my whole drawing method, doing only what I've written above,
takes about 1 *second* per call (on Intel Q9300), so it's very, very slow.
I'd like to speed it up by 1000%. ;)

I've changed my approach and I've checked the speed when drawing 4800 chars
at one pango call, turns out the speed is the same.

The pseudocode of my current algorithm looks like this:

// ------------------------------------------------------------------

// Layout is Pango::Layout
// Context is Cairo::Context

void Widget::on_expose(RefPtr& pango, RefPtr& cairo) {
    // timer start

    cairo->move_to(1.0f, 1.0f);
    pango->update_from_cairo_context(cairo);
    pango->set_font_description(monospaced_font);
    pango->set_text(my_buffer); // ~4800 chars, utf-8 encoded

    // when I comment this line below, nothing gets drawn, of course, but
    // the 1-second problem is gone.

    pango->add_to_cairo_context(cairo);
    cairo->fill();

    // timer stop - ~1 second
}
// ------------------------------------------------------------------

So I have these questions:

- is Pango suitable for my problem? (not sure if I provided enough 
 information. I can post code if necessary),

- or maybe should I use plain Gdk / SDL for this?

My Gtk/Gtkmm/Cairo/Pango versions are same as current stable ones.

Thanks for any info and sorry if I'm asking obvious stuff.

-- 
Regards, antek




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