位图字体呈现和字距位图、字体

2023-09-11 04:58:01 作者:知南茶温暖

我试图创建位图字体的渲染器,但是,我有问题使实际个人信件的展示位置。

I am attempting to create a bitmap font renderer, however, I am having problems rendering the actual individual letter placements.

我会获得通过GetCharABCWidthsFloat和GetTextMetricsW字体的字符信息,但是,我不能确定如何使用ABC宽度的正常......或者我需要更多的信息来做到这一点?

I will obtain the font character information via GetCharABCWidthsFloat and GetTextMetricsW, however, I am unsure how to use the ABC width's properly ... or do I need more information to do this?

我不希望使用的FreeType或任何其他库的做到这一点,我想通过C ++ \ Windows中可用的标准功能做到这一点。

I do not want to use FreeType or any other libraries's to do this, I am trying to do this with standard functionality available through C++\Windows.

如果没有字距微调信息,这些字母将不会出现正确。例如,看看宋体,当一个F和T被并排放置在一起。如果没有正确的字母间距,他们将寻找太远。 算法的例子---

Without the kerning information, the letters will not appear correct. For example, take a look at "Times new roman" when an "f" and a "t" are placed next to each other. Without the correct letter spacing, they will look too far apart. algorithm example ---

float letterBottomLeftX = 0.0f;
float letterHeight = 1.0f;
float letterWidth = 1.0f;

float scale = 1.0f;
for(U32 c = 0; c < numberOfCharacters; ++c)
{
    fon->GetCharcterInfo(charValue, charInfo);
    //float advancedWith = (charInfo.A * scale) + (charInfo.B * scale) + (charInfo.C * scale);

    letterWidth = charInfo.B * scale;
    letterHeight = textMetrics.Height * scale;

    if(c == 0)
    {
        letterBottomLeftX = -(charInfo.A * scale);
    }


    // vertex placement, beginning at letterBottomLeftX

    // texture placement

    // index placement

    letterBottomLeftX += (charInfo.A + charInfo.B + charInfo.C) * scale;
}

下面是什么样子,你可以看到的字符之间的间距不好的例子。 (忽略贴图UV的,我要解决这个问题后,我得到的字母位置正确的)。

Here is an example of what it looks like, you can notice the bad spacing between characters. (Ignore the texture UV's, I am going to fix that after I get the letter placement correct).

推荐答案

的文档 KERNINGPAIR 似乎pretty的简单。如果当前字符和下面的字符出现在通过 WFIRST wSecond 成员表中,添加 iKernAmount 来像素的你提前为下一个字符数。

The documentation for KERNINGPAIR seems pretty straightforward. If both the current character and the following character occur in the table via the wFirst and wSecond members, add the iKernAmount to the number of pixels you advance for the next character.

我会建议创建一个的std ::地图&LT;的std ::对&LT;为wchar_t,wchar_t的&GT;,INT&GT; GetKerningPairs结果,以便快速查找。你已经注意到了, GetKerningPairs 不适合角色的每一个可能的组合返回结果。这个信息是从字体本身到来,并且它是由字体设计以指示哪个字符对有需要的调整。这是很可能这些信息会丢失全部或失踪的性格对,似乎是显而易见的给你。

I would suggest creating a std::map<std::pair<wchar_t,wchar_t>,int> with the results from GetKerningPairs for quick lookup. You have noticed that GetKerningPairs does not return a result for every possible combination of characters. This information is coming from the font itself, and it is up to the font designer to indicate which character pairs are in need of adjustment. It is quite possible for this information to be missing entirely, or to be missing character pairs that seem obvious to you.

请确保您 SetMapMode(HDC,MM_TEXT)调用任何这些函数,因为映射模式影响的结果之前。

Make sure you do SetMapMode(hdc,MM_TEXT) before calling any of these functions, since the mapping mode affects the results.

 
精彩推荐
图片推荐