jac*_*ack 6 c# c++ algorithm fonts rendering
我调用"GetCharABCWidthsFloatW"来获取角色的宽度信息.有了这个,我将获得左侧轴承,右侧轴承和先进的宽度.
为了定位每个字符,我将从一个从零开始的"xPlacement"变量开始.我将首先通过减去"左侧轴承"来调整xPlacement变量.绘制完角色后,我会按角色的宽度前进(我稍后会显示计算结果).然后,我将通过添加当前"xPlacement"中的"右侧方位"信息来移动xPlacement变量.
在我看来,这应该是字符放置的代码,对吗?
重要的是要纠正字符的宽度.宽度将通过采用advancedWidth,左侧轴承的POSITIVE版本和右侧轴承的POSITIVE版本来计算.我会将这些值转换为正值,如果它们是负数,那么我可以得到字符的总宽度.
这是一些关于如何生成的伪代码.
float xPlacement = 0.0f;
for(int i = 0; i < strlen(text); ++i)
{
char charValue = text[i];
GetCharWidthABC(.., .., charInfo);
float posLeft = charInfo.leftSideBearing;
if(charInfo.leftSideBearing < 0)
posLeft = -charInfo.leftSideBearing;
float posRight = charInfo.rightSideBearing;
if(posRight < 0)
posRight = -charInfo.rightSideBearing;
float posWidth = posRight + posRight + charInfo.advancedWidth;
float letterWidth = posWidth;
xPlacement -= charInfo.leftSideBearing;
/* generated some vertex coordinates, using the xPlacement variable and letterWidth */
xPlacement += letterWidth;
xPlacement += charInfo.rightSideBearing
}
Run Code Online (Sandbox Code Playgroud)
这似乎是正确的方法吗?
由于问题标签中提到了 C#,因此您可能会对查看 .NET Framework 附带的一些非常强大的类(从版本 3.0 开始,实际上随 WPF 核心程序集附带)感兴趣。他们是:
前两个类在某种程度上与技术/设备无关,除了 .NET Framework 本身之外。