我调用“GetCharABCWidthsFloatW”来获取字符的宽度信息。这样我就能得到左侧轴承、右侧轴承和高级宽度。
为了定位每个字符,我将从零开始使用一个“xPlacement”变量。首先,我会通过减去“左侧轴承”来调整xPlacement变量。绘制字符后,我会按字符的宽度将其向前推进(稍后我会展示计算方法)。然后,我将通过将当前“xPlacement”的“右侧轴承”信息相加来移动xPlacement变量。
在我看来,这就是字符定位所需的全部代码,对吗?
重要的一点是要纠正字符的宽度。宽度将通过取advancedWidth、左侧轴承的正值和右侧轴承的正值来计算。如果它们是负数,我会将这些值转换为正数,以便获得字符的总宽度。
以下是关于如何生成伪代码的一些内容。
为了定位每个字符,我将从零开始使用一个“xPlacement”变量。首先,我会通过减去“左侧轴承”来调整xPlacement变量。绘制字符后,我会按字符的宽度将其向前推进(稍后我会展示计算方法)。然后,我将通过将当前“xPlacement”的“右侧轴承”信息相加来移动xPlacement变量。
在我看来,这就是字符定位所需的全部代码,对吗?
重要的一点是要纠正字符的宽度。宽度将通过取advancedWidth、左侧轴承的正值和右侧轴承的正值来计算。如果它们是负数,我会将这些值转换为正数,以便获得字符的总宽度。
以下是关于如何生成伪代码的一些内容。
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
}
这样做是否正确?