【发布时间】:2017-01-08 14:10:58
【问题描述】:
我正在尝试创建单色字形图集,但遇到了问题。 Freetype 在字形的位图中呈现“废话”。我责怪 freetype,因为某些字形仍然正确呈现。
生成的纹理图集:
为什么会这样,我该如何解决?
但是我仍然可能是错的,这里是位图处理代码:
static std::vector<unsigned char> generateBitmap(FT_Face &face, unsigned int glyph, size_t *width, size_t *height) {
FT_Load_Glyph(face, FT_Get_Char_Index(face, glyph), FT_LOAD_RENDER | FT_LOAD_MONOCHROME );
FT_Bitmap bitmap;
FT_Bitmap_New(&bitmap);
FT_Bitmap_Convert(ftLib, &face->glyph->bitmap, &bitmap, 1);
*width = bitmap.width;
*height = bitmap.rows;
std::vector<unsigned char> result(bitmap.width * bitmap.rows);//
for (size_t y = 0; y < bitmap.rows; ++y)
{
for (size_t x = 0; x < bitmap.width; ++x)
{
result[(bitmap.width * y) + x] = bitmap.buffer[(bitmap.width * y) + x];
}
}
FT_Bitmap_Done(ftLib, &bitmap);
return result;
}
以及将其放入主缓冲区的代码:
static void putOnBuffer(std::vector<unsigned char> &buffer, std::vector<unsigned char> &bitmap, size_t height, size_t width) {
int r = 0;
while (r < height) {
int w = 0;
while (w < width) {
//assume buffer is enough large
size_t mainBufPos = ((currentBufferPositionY + r) * imageWidth) + (currentBufferPositionX + w);
size_t bitmapBufPos = (r * width) + w;
buffer[mainBufPos] = clamp(int(bitmap[bitmapBufPos] * 0x100), 0xff);
w++;
}
r++;
}
}
【问题讨论】:
-
嗯,我很确定在这种特殊情况下,有比“废话”更好的词......
-
我敢打赌这不是 freetype,而是你的代码(但我看不到在哪里)。
-
看起来假设有一个固定的步幅(因此字形的宽度总是独立于渲染宽度的 8 或 4 的倍数),因为观察到的失真显然是由于缺少填充造成的。完整的字形可能恰好满足这个条件。
-
“我责怪 freetype,因为某些字形仍然正确呈现。” 这是不合理的。
-
在标题由四个字母组成的帖子中使用拉丁文应该会触发徽章。