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

Just wondered if anyone can clarify these 4 points please or point me to the right doc?

Thanks very much,

On 21/04/2011 15:55, Alex Kerr wrote:
Thank you again. Can I clarify four more small things please?

1. In the API ref for PangoLayoutLine, is GSList *runs a list of pointers to PangoLayoutRuns?

2. How do I get from the glyph positional info given in PangoGlyphGeometry to get a coordinate for the glyph on the Cairo drawing surface?

3. Is PangoGlyph a unique identifier for a specific glyph in a font - i.e. it's not shared with different glyphs, but if the same glyph is repeated it will have the same ID number?

4. If I'm iterating through the glyphs in a cluster using e.g. PangoGlpyhItemIter and the method show here: how do I get to the data structures holding the glyph data and also cluster data from that - i.e. which function or pointer?

Thank you again for any clarification!


On 20/04/2011 16:05, Behdad Esfahbod wrote:
On 04/20/11 09:14, Alex Kerr wrote:
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.
A glyph is a single shape from the font. A cluster is a mapping between one
or more consecutive Unicode characters in the input text and one or more
consecutive glyphs in the glyph array that collectively correspond to eachother.

And what's the simpler API you're referring to?
The PangoLayoutIter API, which has next_cluster().

If you want more direct access, check pango_layout_get_line(), and note that PangoLayoutRun is the same as PangoGlyphItem. Then check PangoGlyphItemIter,
or just do whatever you want to the glyph-item.

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!
The code illustrates which API calls you can use.



  On 20/04/2011 06:11, Behdad Esfahbod wrote:
On 04/19/11 16:27, Alex Kerr wrote:
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,

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!

gtk-i18n-list mailing list
gtk-i18n-list gnome org

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