pango layout in irregular (non-rectangular) bounding shape

View: New views
6 Messages — Rating Filter:   Alert me  

pango layout in irregular (non-rectangular) bounding shape

by august black :: Rate this Message:

| View Threaded | Show Only this Message


hey y'all,

         I'm just getting started with cairo and pango and trying to figure
         out how to render text within a non-rectangular bounding shape?   I
         can already render stuff to screen and bound a text segment by width
         and height....but still haven't figgered out how to translate it by
         x,y.   In addition, I'd like to render text inside a polygon shape.

         Can someone point me in the right direction?  I've been reading the
         mailinglist archives and looking at the online api reference trying
         to figure this out.  I've also started to inspect the Inkscape code
         to see how they do it....but can't yet see where.

         Do I need to iterate through the text segment, character by
         character, and draw each glyph to screen, measuring it's x and y?
         Is that slow?  

         Any help or pointers would be much appreciated.

         many thanks -august.
_______________________________________________
gtk-i18n-list mailing list
gtk-i18n-list@...
http://mail.gnome.org/mailman/listinfo/gtk-i18n-list

Parent Message unknown Re: pango layout in irregular (non-rectangular) bounding shape

by Alissa Sabre :: Rate this Message:

| View Threaded | Show Only this Message

august,

> I
> can already render stuff to screen and bound a text segment by width
> and height

I guess you tried PangoLayout and friends.

> how to render text within a non-rectangular bounding shape?

> Can someone point me in the right direction?

If I were you, I'd be using PangoItem, PangoGlyphString, and friends.
They are lower layer interface to pango, and you need to write more
codes than using PangoLayout, but it gives you better control over
layout.  (There may be some easier ways if you only needs fill texts
ina non rectangular area, but I don't know.)

The following outlines what you need to do:

(1) Call pango_itemize() once for your text,
(2) Call pango_break() for your entire text,
(3) Call pango_shape() for each PangoItem you got,
(4) Fold the text into lines, scanning the list of PangoItems, calling
    pango_glyph_string_get_width() for each PangoGlyphString you got,
    also breaking several PangoItem in a middle, referring to
    PangoLogAttr array you got (This will be the most complicated step),
(5) Either call pango_reorder_items() for each folded line and somehow
    refrect the results to your list of PangoGlyphString (or does an
    equivalent processing manually as suggested by pango document...), and
(6) Call pango_cairo_show_glyph_string() for each PangoGlyphString,
    moving the cairo current point appropriately.

Hope this helps,

    Alissa

--------------------------------------
Power up the Internet with Yahoo! Toolbar.
http://pr.mail.yahoo.co.jp/toolbar/
_______________________________________________
gtk-i18n-list mailing list
gtk-i18n-list@...
http://mail.gnome.org/mailman/listinfo/gtk-i18n-list

Re: pango layout in irregular (non-rectangular) bounding shape

by Behdad Esfahbod-3 :: Rate this Message:

| View Threaded | Show Only this Message

august wrote:
> hey y'all,
>
> I'm just getting started with cairo and pango and trying to figure
> out how to render text within a non-rectangular bounding shape?   I
> can already render stuff to screen and bound a text segment by width
> and height....but still haven't figgered out how to translate it by
> x,y.

If you are using pango_cairo_show_layout(), you need a cairo_move_to() before
that.

>   In addition, I'd like to render text inside a polygon shape.

This is not possible yet.  Here is the bug tracking this issue:

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

> Can someone point me in the right direction?  I've been reading the
> mailinglist archives and looking at the online api reference trying
> to figure this out.  I've also started to inspect the Inkscape code
> to see how they do it....but can't yet see where.
>
> Do I need to iterate through the text segment, character by
> character, and draw each glyph to screen, measuring it's x and y?
> Is that slow?  

No.  Just do that one line at a time.

behdad

> Any help or pointers would be much appreciated.
>
> many thanks -august.
> _______________________________________________
> gtk-i18n-list mailing list
> gtk-i18n-list@...
> http://mail.gnome.org/mailman/listinfo/gtk-i18n-list
>
_______________________________________________
gtk-i18n-list mailing list
gtk-i18n-list@...
http://mail.gnome.org/mailman/listinfo/gtk-i18n-list

Re: pango layout in irregular (non-rectangular) bounding shape

by august black :: Rate this Message:

| View Threaded | Show Only this Message

> august,
>
> > I
> > can already render stuff to screen and bound a text segment by width
> > and height
>
> I guess you tried PangoLayout and friends.
>
> > how to render text within a non-rectangular bounding shape?
>
> > Can someone point me in the right direction?
>
> If I were you, I'd be using PangoItem, PangoGlyphString, and friends.
> They are lower layer interface to pango, and you need to write more
> codes than using PangoLayout, but it gives you better control over
> layout.  (There may be some easier ways if you only needs fill texts
> ina non rectangular area, but I don't know.)
>
> The following outlines what you need to do:
>
> (1) Call pango_itemize() once for your text,
> (2) Call pango_break() for your entire text,
> (3) Call pango_shape() for each PangoItem you got,
> (4) Fold the text into lines, scanning the list of PangoItems, calling
>     pango_glyph_string_get_width() for each PangoGlyphString you got,
>     also breaking several PangoItem in a middle, referring to
>     PangoLogAttr array you got (This will be the most complicated step),
> (5) Either call pango_reorder_items() for each folded line and somehow
>     refrect the results to your list of PangoGlyphString (or does an
>     equivalent processing manually as suggested by pango document...), and
> (6) Call pango_cairo_show_glyph_string() for each PangoGlyphString,
>     moving the cairo current point appropriately.
>
> Hope this helps,
>     Alissa

Alissa,

        thanks so much for taking the time to outline all of this.  I am
        still learning the pango api and this helps.

        -august.
_______________________________________________
gtk-i18n-list mailing list
gtk-i18n-list@...
http://mail.gnome.org/mailman/listinfo/gtk-i18n-list

Re: pango layout in irregular (non-rectangular) bounding shape

by august black :: Rate this Message:

| View Threaded | Show Only this Message

>
> >   In addition, I'd like to render text inside a polygon shape.
>
> This is not possible yet.  Here is the bug tracking this issue:
>
>   http://bugzilla.gnome.org/show_bug.cgi?id=435706


Behdad,

                How far did you get with that?  I also see you were looking at
                Nathan Hurst's code for inkscape.  I'd love to study some of that
                code...but it seems like most of the links on that page are gone
                now.  Is this something I could help implement?

                                                -august.

_______________________________________________
gtk-i18n-list mailing list
gtk-i18n-list@...
http://mail.gnome.org/mailman/listinfo/gtk-i18n-list

Re: pango layout in irregular (non-rectangular) bounding shape

by Behdad Esfahbod-3 :: Rate this Message:

| View Threaded | Show Only this Message

august wrote:

>>>   In addition, I'd like to render text inside a polygon shape.
>> This is not possible yet.  Here is the bug tracking this issue:
>>
>>   http://bugzilla.gnome.org/show_bug.cgi?id=435706
>
>
> Behdad,
>
> How far did you get with that?  I also see you were looking at
> Nathan Hurst's code for inkscape.  I'd love to study some of that
> code...but it seems like most of the links on that page are gone
> now.  Is this something I could help implement?


I've not worked on it other than what's on the bug.  Feel free to look into
it.  Everything I had to add is already on the bug.

behdad

> -august.

_______________________________________________
gtk-i18n-list mailing list
gtk-i18n-list@...
http://mail.gnome.org/mailman/listinfo/gtk-i18n-list