I am attempting to create a bitmap font renderer, however, I am having problems rendering the actual individual letter placements.
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?
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.
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;
}
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).
http://img88.imageshack.us/img88/4015/njpjp2.png
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.
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.
Make sure you do SetMapMode(hdc,MM_TEXT) before calling any of these functions, since the mapping mode affects the results.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With