Re: Drawing glyph bounding box on rendered text?

Hi August,

Yes I saw that thanks, but the issue was it was hard to discern what the actual API calls were, given that I don't do Python and correlate those with the C APIs listed in the Pango manual, the Python wrappers seem to match up exactly with the C API functions.

Also I'm after bounding boxes around glyphs, which I think the code did not seem to do (I can do boxes around runs and lines in C, that seems to be easy).


On 09/05/2011 22:13, august wrote:
Behdad posted a python application that draws lines around clusters,
runs, and lines:

Maybe you haven't seen that yet and can help.

best -august.

Hi all,

I'm trying to accurately draw a rectangle around each glyph (not
character) in rendered text. I'm very close but things aren't quite
lining up correctly. I've attached an image showing this, but if the
mailing list filters it, you can also see it here:
Green box shows line extents, red boxes should show bounding box for
each glyph.

As you can see, widths and X starting positions of the boxes are off
slightly. (So is height, but I suppose I could lock that to the
bottom of the line extents?)

Relevant code that drew that is:

double pango_to_ink = (1.0 / ((double) PANGO_SCALE)); // utility

[ create surface, context, layout, then do pango_layout_set_text() ]

[ for each line in layout use pango_layout_iter_get_line() : ]

pango_layout_iter_get_line_extents(pIter,&line_r, NULL);
pangolineX = pango_to_ink * ((double) line_r.x);  // start position
of this line of the layout
pangolineY = pango_to_ink * ((double) line_r.y);

[ get each run in current line: ]

for (i = 0; i<  pRun->glyphs->num_glyphs; i++) // loop through
glyphs in current run

      pango_font_get_glyph_extents(font, glyphID, NULL,&glyphbox);
// Just to get glyph height as it's not in the geometry

      glyphX = pangolineX + pango_to_ink * ((double)
      glyphY = pangolineY + pango_to_ink * ((double)
      glyphW = pango_to_ink * ((double)
      glyphH = pango_to_ink * ((double) glyphbox.height);

       cairo_rectangle(context, glyphX, glyphY, glyphW, glyphH - glyphY);


Where am I going wrong in getting the glyph bounding boxes
accurately? (this needs to also work for Indic, Hebrew, Arabic,
Chinese and so on)
It doesn't matter if the box has empty space, i.e. incorporates the
distance between glyphs, though knowing the actual glyph bounding
box AND the space separating it from the next glyph
would be ideal.

Thanks and regards,

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

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