Label系统字体怎么设置行高?

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;          {返回文本高度}

https://blog.csdn.net/qingmvc/article/details/121165384

RichText富文本控件解决你的问题
调用这个方法setVerticalSpace

ps:已经有好久没登论坛

把Line Heigth设置数值更大一些不是可以控制行高间距嘛?

微信截图_20211105180141

看此贴的分类好像是2dx,打扰了

系统字体不支持的了

void Label::setLineHeight(float height)
{
    CCASSERT(_currentLabelType != LabelType::STRING_TEXTURE, "Not supported system font!");

lineHeight 行高啊
这个overflow是调整整体的尺寸

TTF/BMFont才支持,系统字体不支持