Windows:从其他字体获取替换字符的字形轮廓

发布于 2024-08-13 21:23:36 字数 244 浏览 3 评论 0原文

我需要将字体渲染到 3D 游戏世界中,因此我使用 GetGlyphOutline 轮廓函数来获取要渲染到纹理中的字形形状。但是,我希望能够处理给定字体中不存在字符的情况(亚洲其他国际文本经常出现这种情况)。 Windows 文本渲染将自动替换具有所需字符的字体。但 GetGlyphOutline 不会。我如何检测这种情况,并获取替换字形的轮廓? Mac OS X Core Text 有一个函数可以获取给定字体和字符串的匹配替换字体 - Windows 上有类似的功能吗?

I need to render fonts into a 3d game world, so I use the GetGlyphOutline outline function to get the glyph shapes to render into a texture. However, I want to be able to handle the case where characters are not present in the given font (as is often the case for asian other other international text). Windows text rendering will automatically substitute fonts which have the needed characters. But GetGlyphOutline will not. How can I detect this case, and get the outlines for the substituted glyphs? Mac OS X Core Text has a function to get a matching substitution font for a given font and a string - is there anything similar on windows?

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

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

发布评论

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

评论(2

无边思念无边月 2024-08-20 21:23:36

Found out what I needed to know myself: The IMLangFontLink interface, especially the MapFont method contain the needed functionality to find out which substitution fonts should be used on windows.

做个ˇ局外人 2024-08-20 21:23:36

我也对 GetGlyphOutline 感到困惑。我不确定您是否能够执行相同的操作,但我能够通过将 TextOut()BeginPath() 结合使用来获得混合脚本文本轮廓、EndPath()GetPath()

例如,即使使用 Arial 字体,我也能够获取日语文本「テsuto」的路径(使用 C++,但也可以在 C 中轻松完成):

SelectObject(hdc, hArialFont);
BeginPath(hdc);
TextOut(hdc, 100, 100, L"\u30c6\u30b9\u30c8"); // auto font subbing
EndPath(hdc);

// get number of points in path
int pc = GetPath(hdc, NULL, NULL, 0);

if (pc > 0)
{
    std::vector<POINT> points(pc);
    std::vector<BYTE> types(pc); // PT_MOVETO, PT_LINETO, PT_BEZIERTO

    GetPath(hdc, &points[0], &types[0], pc);

    // it seems the first four points are the bounding rect
    // subsequent points match up to their types

    for (int i = 4; i < pc; i++)
    {
        if (types[i] == PT_LINETO)
            LineTo(hdc, points[i].x, points[i].y); // etc
    }
}

I too have puzzled with GetGlyphOutline. I'm not sure if you were able to do the same, but I was able to get mixed-script text outlines by using TextOut() in combination with BeginPath(), EndPath() and GetPath().

For example, even with the Arial font, I am able to get the path of the Japanese text 「テスト」 (using C++, but can easily be done in C as well):

SelectObject(hdc, hArialFont);
BeginPath(hdc);
TextOut(hdc, 100, 100, L"\u30c6\u30b9\u30c8"); // auto font subbing
EndPath(hdc);

// get number of points in path
int pc = GetPath(hdc, NULL, NULL, 0);

if (pc > 0)
{
    std::vector<POINT> points(pc);
    std::vector<BYTE> types(pc); // PT_MOVETO, PT_LINETO, PT_BEZIERTO

    GetPath(hdc, &points[0], &types[0], pc);

    // it seems the first four points are the bounding rect
    // subsequent points match up to their types

    for (int i = 4; i < pc; i++)
    {
        if (types[i] == PT_LINETO)
            LineTo(hdc, points[i].x, points[i].y); // etc
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文