从 freetype 检索指定的字形(SHIFT JIS 编码)?

发布于 2024-10-06 22:46:34 字数 777 浏览 0 评论 0原文

到目前为止,我使用纹理(位图字体)进行字体渲染,但我正在尝试让 freetype2 工作。我的所有字符串都是 SHIFT_JIS 编码的,我现在唯一的问题是从 freetype 获得正确的字形到正确的 SHIFT_JIS 位序列。但这似乎比我想象的要难。例如,“亜”的字符代码为“0x889F”(字节 1 设置为 136,字节 2 设置为 159)——这是根据 SHIFT_JIS 编码的。所以我调用了该函数:

FT_Select_Charmap(face, FT_ENCODING_SJIS);

然后尝试使用该字符代码加载字形:

FT_Load_Char(face, 0x889F, FT_LOAD_RENDER ); 

但我收到了一些随机字形。这不可能是特定于字体的问题,因为我已经尝试了不同的字体,但得到了相同的结果(是的,它们提供了 shift-jis 字符映射)。例如“0”(零)应该位于位置 0x0030 - 但实际上它位于 0x002D。并非所有字符的常量偏移量为 3,否则不会有问题...我认为我的“FT_Load_Char”调用以错误的方式传递了 charcode 参数 - 但无法猜测它是如何正确的。已经尝试过:

FT_Load_Char(face, FT_Get_Char_Index(face, 0x889F), FT_LOAD_RENDER ); 

但后来我收到另一个随机字形。 那么,如果没有选择默认的字符映射,如何将字符代码传递给 FT_Load_Char?

任何建议都会非常有帮助。谢谢。

Until now I used a texture (bitmapfont) for font rendering, but I'm trying to get freetype2 working. All my strings are SHIFT_JIS encoded and my only Problem is now to get from freetype the right glyph to a proper SHIFT_JIS bitsequence. But it seems harder than I expected. To example "亜" has the charcode "0x889F" (byte 1 is set to 136 and byte 2 is 159) - that's according to the SHIFT_JIS encoding. So I called the function:

FT_Select_Charmap(face, FT_ENCODING_SJIS);

and try then to load a glyph with that charcode:

FT_Load_Char(face, 0x889F, FT_LOAD_RENDER ); 

But I receive some random glyph. It cant be a font-specific problem, because I tried already different fonts with the same result (and yeah, they provide a shift-jis charmap). To example "0" (zero) should be at position 0x0030 - but its in fact at 0x002D. Not all characters have an constant offset of 3, otherwise there would be no problem... I think my "FT_Load_Char" call, pass the charcode parameter in a wrong way - but cant guess how it would be right. Already tried:

FT_Load_Char(face, FT_Get_Char_Index(face, 0x889F), FT_LOAD_RENDER ); 

But then I receive another random glyph.
So, how can I pass the charcode to FT_Load_Char if not the default charmap is selected?

Any advice would be really helpful. Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

开始看清了 2024-10-13 22:46:34

如果有人稍后发现有类似问题:
我最终将字符代码即时转换为 unicode(使用 icu4c)。似乎很多日语 SJIS 字体标题都存在问题(无法通过 freetype 枚举选择它们 - 仅当您列出其中一种字体的所有可用字符集,然后手动选择正确的字符集 - 平台 ID 和编码 ID所有这些字体也不完全相同)。但这不是满足我的需求的正确解决方案(因为使用不同的字体),所以我最终决定使用 Icu4c。

希望这对某人有帮助。

If anyone will find this later with a similiar problem:
I ended up with converting the character codes on the fly to unicode (using icu4c). It seems like there`s a problem with a lot of japanese SJIS font headers (they can not selected via the freetype enums - only if you list all available charsets of one of these fonts and then choose the right manually - platform ID & encoding ID aren't identical for all of these fonts too). But that wasn't a proper solution for my needings (because using different fonts), so I finally decided to use Icu4c.

Hopefully this will be helpful to someone.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文