c++freetype2

How do I use libraqm to render the correct glyphs (Arabic) with FreeType2?


I have been using FreeType2 to render by text with OpenGL, but now I need to render Arabic which is more complex, so I have installed libraqm to help, and I have built and run the example code which shows me how to get the glyph index, offset, advance and cluster of each character.

What I need to know is how to get the image of the glyph.

In FreeType2, I have been using FT_Render_Glyph(), which takes an FT_GlyphSlot and an FT_RenderMode, then I get the bitmap from that FT_GlyphSlot.

But since I have an unsigned int as a glyph index from libraqm, I'm not sure how to get the correct glyph bitmap...

I have also tried manually setting the FT_GlyphSlot, such as: ftGlyphSlot->glyph_index = glyphs[i].index; before calling FT_Render_Glyph(), but then no text is rendered at all.

By the way, I have managed to render Arabic text with an Arabic font, but at the moment it is written left-to-right, and most of the glyphs are wrong. I'm pretty sure I can sort out the right-to-leftness and glyph joining as long as I can get the correct glyph image.


Solution

  • There is a division of labour between the shaping engine and the glyph rendering engine. Shaping (libraqm) tells you what glyph you want and where to put it. Rendering tells you what it looks like.

    So, you've already got the glyph selection and positioning information from libraqm. That's step one. Step two depends on a bit on what kind of canvas you're rendering onto, but the basic idea is that you can now (using freetype) select the glyph from the font by ID:

    FT_Load_Glyph( face, glyph_index, FT_LOAD_DEFAULT );
    

    and then you can get its bitmap as you normally would and position it onto your canvas in the place that libraqm told you to put it.