我应该如何将字形与 libraqm 垂直对齐?
How should I vertically align glyphs with libraqm?
我已经设法使用 libraqm 获得了正确的字形(字形整形),现在我需要进行字形连接以使字形正确连接。
我已经设法获得正确的水平前进,使用:
advance = (glyphs[i].x_advance / glyphs[i].ftface->units_per_EM) * fontsize;
但是,偏移量似乎不正确,因为所有字形 x 和 y 偏移量都被 libraqm 设置为 0。
最初,我使用以下方法设置字形的位置:
const float left = (float)(origin_x + glyphs[i].x_offset);
const float top = (float)(origin_y + font->leading + (font->ascent - glyphs[i].y_offset));
但这导致所有字形都与文本行的顶部对齐,如下所示:
(随机文本示例)
所以我修改了代码,使字形与文本行的底部对齐,如下所示:
const float left = (float)(origin_x + glyphs[i].x_offset);
const float top = (float)(origin_y + font->leading + (font->ascent - glyphs[i].y_offset)) - glyphs[i].ftface->glyph->bitmap.rows;
虽然看起来好多了,但还是不太对...
有谁知道我应该如何使用 libraqm 为每个字形获得正确的偏移量?
与其使用 glyphs[i].ftface->glyph->bitmap.rows
获取字形高度,不如使用 glyphs[i].ftface->glyph->bitmap_top
,因此您的垂直对齐方式如下所示:
const float top = (float)(origin_y + font->leading + (font->ascent - glyphs[i].y_offset)) - glyphs[i].ftface->glyph->bitmap_top;
我已经设法使用 libraqm 获得了正确的字形(字形整形),现在我需要进行字形连接以使字形正确连接。
我已经设法获得正确的水平前进,使用:
advance = (glyphs[i].x_advance / glyphs[i].ftface->units_per_EM) * fontsize;
但是,偏移量似乎不正确,因为所有字形 x 和 y 偏移量都被 libraqm 设置为 0。
最初,我使用以下方法设置字形的位置:
const float left = (float)(origin_x + glyphs[i].x_offset);
const float top = (float)(origin_y + font->leading + (font->ascent - glyphs[i].y_offset));
但这导致所有字形都与文本行的顶部对齐,如下所示:
所以我修改了代码,使字形与文本行的底部对齐,如下所示:
const float left = (float)(origin_x + glyphs[i].x_offset);
const float top = (float)(origin_y + font->leading + (font->ascent - glyphs[i].y_offset)) - glyphs[i].ftface->glyph->bitmap.rows;
虽然看起来好多了,但还是不太对...
有谁知道我应该如何使用 libraqm 为每个字形获得正确的偏移量?
与其使用 glyphs[i].ftface->glyph->bitmap.rows
获取字形高度,不如使用 glyphs[i].ftface->glyph->bitmap_top
,因此您的垂直对齐方式如下所示:
const float top = (float)(origin_y + font->leading + (font->ascent - glyphs[i].y_offset)) - glyphs[i].ftface->glyph->bitmap_top;