I’m trying to implement a custom renderer for Pango, but in the draw_glyphs function, I run into the problem that the PangoGlyph glyph codes in the glyph info I get passed by Pango through the PangoGlyphInfos in the PangoGlyphString are wrong:
draw_glyphs(PangoFont* font, PangoGlyphString* glyphs, int x, int y) {
for (int i = 0; i < glyphs->num_glyphs; i++) {
PangoGlyphInfo *gi = &glyphs->glyphs[i];
printf("glyph: %u", gi->glyph);
draw_glyph(font, gi->glyph, p->x, p->y);
x_position += gi->geometry.width;
}
}
If I look at the output of this function, if in the input text i have a c for example, the value of gi->glyph for that is 102 which according to the ASCII table is the letter f, not the letter c.
On top of that, this offset changes depending on the font I use - in the LiberationSans family, with the regular, bold and italic variants the offset is -29, so for an uppercase Z in the input text I get a greater-than sign; with the bold-italic variant, the offset is +3, so I get an f for a c in the input. With other fonts, the offset is again different.
Am I supposed to do any mapping from the glyph code, or could my .ttf files be corrupted in some way ? (I am using a custom font map as well, so it uses custom .ttf files instead of system provided ones via the provided PangoFT2FontMap, but in font viewers they both seem okay)
What I could do is keep track of how many glyphs I’ve drawn in total and get the actual charcode from the text string - but that feels hacky, and also it would probably break if I turn on ellipsization.