Label系统字体怎么设置行高?
- 研究了一天也没有解决
- 暂时的想法是自己分行,每行使用一个Label
- 平台: win32
- 记录一下
1. Label::createWithSystemFont
2. Label::createSpriteForSystemFont
void Label::createSpriteForSystemFont(const FontDefinition& fontDef)
{
_currentLabelType = LabelType::STRING_TEXTURE;
//文本纹理
auto texture = new (std::nothrow) Texture2D;
texture->initWithString(_utf8Text.c_str(), fontDef);
3. Texture2D::initWithString
bool hasPremultipliedAlpha;
Data outData = Device::getTextureDataForText(text, textDef, align, imageWidth, imageHeight, hasPremultipliedAlpha);
4. Device::getTextureDataForText
SIZE size = { (LONG)textDefinition._dimensions.width,(LONG)textDefinition._dimensions.height };
CC_BREAK_IF(!dc.drawText(text, size, align, textDefinition._fontName.c_str(), (int)textDefinition._fontSize, textDefinition._enableWrap, textDefinition._overflow));
5. BitmapDC::drawText
int drawText(const char * pszText, SIZE& tSize, Device::TextAlign eAlign, const char * fontName, int textSize,
bool enableWrap, int overflow)
{
if (fixedText)
{
nRet = DrawTextW(_DC, fixedText, nLen, &rcText, dwFmt);
}
else
{
nRet = DrawTextW(_DC, pwszBuffer, nLen, &rcText, dwFmt);
}
6. win32.DrawTextW
DrawText(
hDC: HDC; {设备句柄}
lpString: PChar; {文本}
nCount: Integer; {要绘制的字符个数; -1 表示全部}
var lpRect: TRect; {矩形结构}
uFormat: UINT {选项}
): Integer; {返回文本高度}
Windows平台下设置Label行高的探索
博主在尝试为Label设置自定义行高,通过研究`Label::createWithSystemFont`、`Label::createSpriteForSystemFont`、`Texture2D::initWithString`等方法深入源码,发现行高设置的难点在于`Device::getTextureDataForText`和`win32.DrawTextW`函数。目前解决方案是考虑将文本拆分为多行,每行使用独立的Label。该问题主要涉及Cocos2d-x库在Win32平台的字体渲染。
3974

被折叠的 条评论
为什么被折叠?



