Re: Help with use of PangoLayout



On Mon, 2007-10-29 at 02:56 +0100, Bogdan Butnaru wrote:
> Hello!

Hi,

> I'm having a bit of trouble figuring out what's the best way of doing
> some rather complex text layout using Pango.

Unfortunately modifying the layout is one area that PangoLayout is not
very good at currently.

> What I'm trying to do is layout icon labels (Nautilus') in a smart
> way, which is tricky because of complex space constraints. To form an
> idea, I want to layout a label on one line if it's relatively short,
> but to constrain it on exactly as many lines as needed to fill the
> icon's height if it's longer, without making the lines shorter than a
> minimum, and to ellipsize the line if the result can't fit in a
> certain maximum width and height. And I need to try all this with both
> word line-breaks and character line-breaks and pick between one
> according to some criteria. Thankfully I don't need to worry about
> hyphenation...
> 
> I see two ways of doing this: The hard way would be to forgo using
> PangoLayout entirely, shape the string and then use some sort of
> dynamic programming to split the label in lines and display it in
> pieces. I'd really _not_ like to do that, because I'm pretty sure
> there are lots of smart things PangoLayout does in there that I won't
> know about (mainly bidi and characters changing shape when they're
> split). Also, the application I'm modifying (Nautilus) is already
> based on PangoLayout, so not using it would mean I'd have to change a
> lot more than just icon layout routines.

Nah, not using PangoLayout doesn't make much sense.


> The easy way would be to create a PangoLayout, measure its pieces, and
> then change its lines to make fit things better. The problem is that I
> don't know if that's even possible, other than changing its text,
> which would mean it'd have to do a complete re-parsing, which would
> make incremental-tweaking algorithms inefficient.

Relayouting is what you need to do.  GtkLabel already does something
like that.  I want to add features to PangoLayout to make this much
easier, see:

  http://bugzilla.gnome.org/show_bug.cgi?id=469313

> So, is there a way of doing small tweaks to a layout (other than the
> obvious layout_set_* methods), for example adding a line-break to an
> already-laid-out paragraph? I was thinking about playing around with
> char_attrs, but I can't figure out if that is actually possible.

Not really.  It's all or none right now.  Any change causes a relayout.
But I really doubt that would be too expensive for icon text anyway.


> (I could just make do with an ellipsizing function with both
> horizontal and vertical limits, but that's not available as far as I
> can tell.)

Yes, that's exactly the API I want to add.

> Thanks in advance for any help!
> 
> -- Bogdan Butnaru — bogdanb gmail com

Hope that helped,

-- 
behdad
http://behdad.org/

"Those who would give up Essential Liberty to purchase a little
 Temporary Safety, deserve neither Liberty nor Safety."
        -- Benjamin Franklin, 1759





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