diff --git a/cocos/2d/CCFontAtlas.cpp b/cocos/2d/CCFontAtlas.cpp index 2511e1d70e..7e926440da 100644 --- a/cocos/2d/CCFontAtlas.cpp +++ b/cocos/2d/CCFontAtlas.cpp @@ -341,17 +341,12 @@ bool FontAtlas::prepareLetterDefinitions(const std::u16string& utf16Text) tempDef.offsetX = tempRect.origin.x + adjustForDistanceMap + adjustForExtend; tempDef.offsetY = _fontAscender + tempRect.origin.y - adjustForDistanceMap - adjustForExtend; - glyphHeight = static_cast(bitmapHeight) + _letterPadding + _letterEdgeExtend; - if (glyphHeight > _currLineHeight) - { - _currLineHeight = glyphHeight; - } if (_currentPageOrigX + tempDef.width > CacheTextureWidth) { _currentPageOrigY += _currLineHeight; _currLineHeight = 0; _currentPageOrigX = 0; - if (_currentPageOrigY + _lineHeight >= CacheTextureHeight) + if (_currentPageOrigY + _lineHeight + _letterPadding + _letterEdgeExtend >= CacheTextureHeight) { unsigned char *data = nullptr; if (pixelFormat == Texture2D::PixelFormat::AI88) @@ -385,6 +380,11 @@ bool FontAtlas::prepareLetterDefinitions(const std::u16string& utf16Text) tex->release(); } } + glyphHeight = static_cast(bitmapHeight) + _letterPadding + _letterEdgeExtend; + if (glyphHeight > _currLineHeight) + { + _currLineHeight = glyphHeight; + } _fontFreeType->renderCharAt(_currentPageData, _currentPageOrigX + adjustForExtend, _currentPageOrigY + adjustForExtend, bitmap, bitmapWidth, bitmapHeight); tempDef.U = _currentPageOrigX; @@ -425,7 +425,7 @@ bool FontAtlas::prepareLetterDefinitions(const std::u16string& utf16Text) { data = _currentPageData + CacheTextureWidth * (int)startY; } - _atlasTextures[_currentPage]->updateWithData(data, 0, startY, CacheTextureWidth, _currentPageOrigY - startY + _lineHeight); + _atlasTextures[_currentPage]->updateWithData(data, 0, startY, CacheTextureWidth, _currentPageOrigY - startY + _currLineHeight); return true; }