Skip to content

Commit d86e579

Browse files
authored
Label fixes for wrapping, overflow and alignment (#2567)
* Code improvements * Fix label shrink and missing character issue * Fix for character displaying outside label boundary * Remove redundant code Improve method names * Fix clamping for different horizontal alignment Use letter offsets for more accurate clamping * Show slider percentages and rendered font size where possible
1 parent eec1830 commit d86e579

File tree

5 files changed

+166
-122
lines changed

5 files changed

+166
-122
lines changed

core/2d/FontAtlas.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ void FontAtlas::initWithSettings(void* opaque /*simdjson::ondemand::document*/)
229229
auto letterInfo = field.value();
230230
tempDef.U = static_cast<float>(letterInfo["U"].get_double());
231231
tempDef.V = static_cast<float>(letterInfo["V"].get_double());
232-
tempDef.xAdvance = static_cast<float>(letterInfo["advance"].get_double());
232+
tempDef.xAdvance = static_cast<int>(letterInfo["advance"].get_double());
233233
tempDef.width = static_cast<float>(letterInfo["width"].get_double());
234234
tempDef.height = static_cast<float>(letterInfo["height"].get_double());
235235
tempDef.offsetX = static_cast<float>(letterInfo["offsetX"].get_double());
@@ -421,10 +421,7 @@ bool FontAtlas::prepareLetterDefinitions(const std::u32string& utf32Text)
421421
}
422422
}
423423
glyphHeight = static_cast<int>(bitmapHeight) + _letterPadding + _letterEdgeExtend;
424-
if (glyphHeight > _currLineHeight)
425-
{
426-
_currLineHeight = glyphHeight;
427-
}
424+
_currLineHeight = std::max(glyphHeight, _currLineHeight);
428425
charRenderer->renderCharAt(_currentPageData, (int)_currentPageOrigX + adjustForExtend,
429426
(int)_currentPageOrigY + adjustForExtend, bitmap, bitmapWidth, bitmapHeight,
430427
_width, _height);
@@ -442,8 +439,7 @@ bool FontAtlas::prepareLetterDefinitions(const std::u32string& utf32Text)
442439
}
443440
else
444441
{
445-
if (bitmap)
446-
delete[] bitmap;
442+
delete[] bitmap;
447443

448444
tempDef.validDefinition = !!tempDef.xAdvance;
449445
tempDef.width = 0;

0 commit comments

Comments
 (0)