Re: How do I get X, Y pos and PangoLogAttr of each glyph in a rendered string?



Thanks very much for the help.

> You definitely can do it with glyphs...

OK, cool, so how - i.e. which APIs and how do I tie them together please? That's what's got me stuck!

> ...but is that really what you want? There's simpler API in pango to do that per cluster.

I'm not sure :) What's the definition of a cluster (and for that matter a glyph) ? I can't find this in the docs.

And what's the simpler API you're referring to?

Thanks for the Python code. I can't actually use Python (don't program in it, don't have it installed) but will read it as pseudocode and attempt similar in C!

Cheers
Alex

 On 20/04/2011 06:11, Behdad Esfahbod wrote:
On 04/19/11 16:27, Alex Kerr wrote:
Hello,
Hi Alex,

I'm using a really basic Cairo Pango prog as a test bed. It just displays a
short string on a Cairo surface using a Pango layout, which works fine.

For each glyph in the string, I now want to get it's X,Y pos (and width and
height) on the rendered Cairo surface, and the PangoLogAttr data, e.g. so I
could draw a box around each glyph, or whatever.

After a lot of reading the API stuff, and googling for examples, I'm not quite
sure how to tie the API functions together to achieve this. Anyone got any
suggestions, ideas, or code please?
You definitely can do it with glyphs, but is that really what you want?
There's simpler API in pango to do that per cluster.  Note that you cannot map
a glyph to the original string (and hence PangoLogAttr).  You can only do that
per cluster.

Check PangoLayoutIter.

I'm also attaching Python code that draws boxes around clusters.

Hope that helps,
behdad

Pseudocode for what I'm trying to do would be:

1. Render Pango text to Cairo surface (note: could be right-to-left, e.g.
Arabic, as well as left-to-right) - Done this.

2. For each glyph (or ligature) in the line of text:
     {
     3. Get X, Y, Width and Height of rendered glyph (or ligature)
     4. Get the PangoLogAttr structure for the same character
     5. Move onto the next glyph (/ligature/character) in the line
     }

P.S. As a separate side note, I understand glyphs to be the separate
components of a final rendered character, i.e. the main body and diacritic (if
present) would be separate glyphs. Each glyph in turn could possibly be made
up of more than one UTF-8 character. The rendering engine can potentially
combine certain combinations of glyphs to form a single ligature. Glyphs or
ligatures can also be referred to as characters (so PangoLogAttr applies to
ligatures and glyphs?). Have I got this right!?

Any help much appreciated :)

Many thanks indeed!
Alex



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



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