2

I'm using Pango to layout my text and NV Path to render glyphs.

Having difficulty in finding correct methods for getting per glyph positions. As you can see at the moment I'm calculating this values according to line and glyph indexes.

But Pango has better methods for this; like per glyph, per line, extent queries. My problem is that this methods got no documentation and I wasn't able to find any samples.

How can i get correct glyph positions from Pango for this type of application?

std::vector<uint32_t>   glyphs;
std::vector<GLfloat>    positions;

int lineCount                           = pango_layout_get_line_count( pangoLayout );

for ( int l = 0; l < lineCount; ++l )
{
    PangoLayoutLine*    line            = pango_layout_get_line_readonly( pangoLayout, l );
    GSList*             runs            = line->runs;

    float xOffset                       = 0.0f;

    while( runs )
    {
        PangoLayoutRun* run             = static_cast<PangoLayoutRun*>( runs->data );

        glyphs.resize( run->glyphs->num_glyphs, 0 );
        positions.resize( run->glyphs->num_glyphs * 2, 0 );

        for( int g = 0; g < run->glyphs->num_glyphs; ++g )
        {               
            glyphs[g]                   = run->glyphs->glyphs[g].glyph;
            // Need Correct Values Here
            positions[ g * 2 + 0 ]      = xOffset * NVPATH_DEFUALT_EMSCALE;
            positions[ g * 2 + 1 ]      = (float)l * NVPATH_DEFUALT_EMSCALE;

            xOffset                 += PANGO_PIXELS( run->glyphs->glyphs[g].geometry.width ) / getFontSize();
        }

        const Font::RefT font           = getFont( pango_font_description_get_family( pango_font_describe( run->item->analysis.font ) ) );

        glEnable( GL_STENCIL_TEST );

        glStencilFillPathInstancedNV(   run->glyphs->num_glyphs,
                                        GL_UNSIGNED_INT,
                                        &glyphs[0],
                                        font->nvPath,
                                        GL_PATH_FILL_MODE_NV,
                                        0xFF,
                                        GL_TRANSLATE_2D_NV,
                                        &positions[0]
                                        );


        glStencilFunc( GL_NOTEQUAL, 0, 0xFF );
        glStencilOp( GL_KEEP, GL_KEEP, GL_ZERO );
        glColor3f( 0.0, 0.0, 0.0 );

        glCoverFillPathInstancedNV(     run->glyphs->num_glyphs,
                                        GL_UNSIGNED_INT,
                                        &glyphs[0],
                                        font->nvPath,
                                        GL_BOUNDING_BOX_OF_BOUNDING_BOXES_NV,
                                        GL_TRANSLATE_2D_NV,
                                        &positions[0]
                                        );

        glDisable( GL_STENCIL_TEST );

        runs                            = runs->next;
    }
}

0 Answers0