简体   繁体   English

渲染字形后,将FreeType位图清零

[英]FreeType bitmaps are zeroed after rendering a glyph

I've created a repository that has the most basic way to reproduce my issue. 我创建了一个存储库该存储库具有最基本的方法来重现我的问题。 I use Cmake to build and it's set up to statically link freetype into my executable. 我使用Cmake进行构建,并将其设置为将freetype静态链接到我的可执行文件中。

FreeType is a submodule, so you can clone it all at once with: FreeType是一个子模块,因此您可以使用以下命令一次将其全部克隆:

git clone --recurse-submodules https://github.com/jeffw387/freetype_minimum_test

or if you prefer just clone freetype from git into the externals directory. 或者,如果您只希望从git克隆freetype到externals目录中。

I'm currently testing on Ubuntu. 我目前正在Ubuntu上进行测试。

I can initialize FreeType, create a face from the font, and load a glyph from a character code with the FT_LOAD_RENDER flag all without errors. 我可以初始化FreeType,从字体创建面孔,以及从带有FT_LOAD_RENDER标志的字符代码加载字形,而不会出现错误。

Then when I inspect the bitmap buffer, it's zero-initialized on every row. 然后,当我检查位图缓冲区时,每一行都将其初始化为零。 I used gdb from within VS Code in order to inspect the buffer, but before that I also tried copying out the data line by line. 我从VS Code中使用gdb来检查缓冲区,但是在此之前,我还尝试逐行复制数据。

The font I'm testing with is a free font I found online, but I was able to test it in Libre Office and it seems to work just fine. 我正在测试的字体是我在网上找到的免费字体,但是我可以在Libre Office中对其进行测试,并且看起来工作正常。

Can anyone spot a problem with the code? 谁能发现代码问题? If anyone is willing I'd love to know if this repo creates the same issue on their machine. 如果有人愿意,我很想知道这个仓库是否在他们的机器上造成了同样的问题。

Here's my cpp file for easy viewing: 这是我的cpp文件,方便查看:

#include <ft2build.h>
#include FT_FREETYPE_H
#include <iostream>
#include <vector>

int main() {
  FT_Library library{};
  if (FT_Init_FreeType(&library)) {
    std::cout << "Error initializing FreeType.";
  }

  FT_Face face{};
  auto faceResult = FT_New_Face(library, "Anke.ttf", 0, &face);
  if (faceResult) {
    std::cout << "Error creating face.";
  }

  if ((face->face_flags & FT_FACE_FLAG_SCALABLE) != FT_FACE_FLAG_SCALABLE) {
    std::cout << "Error: font is not scalable.";
  }

  if (FT_Set_Pixel_Sizes(face, 0, 50)) {
    std::cout << "Error setting font pixel size.";
  }

  if (FT_Load_Char(face, 'P', FT_LOAD_RENDER)) {
    std::cout << "Error loading or rendering glyph.";
  }
  auto bmp = face->glyph->bitmap;

  return 0;
}

I've done some further testing and it seems like there was a problem with my freetype fork. 我做了一些进一步的测试,看来我的freetype fork出了问题。 I haven't gone to the trouble of figuring out what it was, but in any case now that I've tried it with a fresh clone from https://github.com/aseprite/freetype2 it works. 我还没有弄清楚它是什么的麻烦,但是无论如何,现在无论如何,我已经尝试使用https://github.com/aseprite/freetype2的新克隆进行了尝试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM