Skip to content

Commit cf4de9b

Browse files
committed
Cache-friendler blending loops in FontFreeType::getGlyphBitmapByIndex.
1 parent 42d59d2 commit cf4de9b

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

core/2d/FontFreeType.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ namespace ax
4545
{
4646

4747
FT_Library FontFreeType::_FTlibrary;
48-
bool FontFreeType::_FTInitialized = false;
49-
bool FontFreeType::_streamParsingEnabled = true;
50-
bool FontFreeType::_doNativeBytecodeHinting = true;
51-
bool FontFreeType::_globalSDFEnabled = false;
52-
const int FontFreeType::DistanceMapSpread = 6;
48+
bool FontFreeType::_FTInitialized = false;
49+
bool FontFreeType::_streamParsingEnabled = true;
50+
bool FontFreeType::_doNativeBytecodeHinting = true;
51+
bool FontFreeType::_globalSDFEnabled = false;
52+
const int FontFreeType::DistanceMapSpread = 6;
5353

5454
// By default, will render square when character glyph missing in current font
5555
char32_t FontFreeType::_mssingGlyphCharacter = 0;
@@ -440,12 +440,11 @@ unsigned char* FontFreeType::getGlyphBitmap(char32_t charCode,
440440

441441
if (charUTF8 == "\n")
442442
charUTF8 = "\\n";
443-
AXLOGW("The font face: {} doesn't contains char: <{}>", _fontFace->charmap->face->family_name,
444-
charUTF8);
443+
AXLOGW("The font face: {} doesn't contains char: <{}>", _fontFace->charmap->face->family_name, charUTF8);
445444
#endif
446445

447446
if (ppFallbackInfo && s_FontEngine)
448-
{ // try fallback
447+
{ // try fallback
449448
auto faceInfo = s_FontEngine->lookupFontFaceForCodepoint(charCode);
450449
if (faceInfo)
451450
{
@@ -454,13 +453,14 @@ unsigned char* FontFreeType::getGlyphBitmap(char32_t charCode,
454453
}
455454
}
456455

457-
// Not found charCode in system fallback fonts
458-
if (_mssingGlyphCharacter != 0)
456+
// Not found charCode in system fallback fonts
457+
if (_mssingGlyphCharacter != 0)
459458
{
460-
if (_mssingGlyphCharacter == 0x1A) {
461-
xAdvance = 0;
459+
if (_mssingGlyphCharacter == 0x1A)
460+
{
461+
xAdvance = 0;
462462
return nullptr; // don't render anything for this character
463-
}
463+
}
464464
// Try get new glyph index with missing glyph character code
465465
glyphIndex = FT_Get_Char_Index(_fontFace, static_cast<FT_ULong>(_mssingGlyphCharacter));
466466
}
@@ -545,9 +545,9 @@ unsigned char* FontFreeType::getGlyphBitmapByIndex(unsigned int glyphIndex,
545545

546546
auto px = outlineMinX - blendImageMinX;
547547
auto py = blendImageMaxY - outlineMaxY;
548-
for (int x = 0; x < outlineWidth; ++x)
548+
for (int y = 0; y < outlineHeight; ++y)
549549
{
550-
for (int y = 0; y < outlineHeight; ++y)
550+
for (int x = 0; x < outlineWidth; ++x)
551551
{
552552
index = px + x + ((py + y) * blendWidth);
553553
index2 = x + (y * outlineWidth);
@@ -557,9 +557,9 @@ unsigned char* FontFreeType::getGlyphBitmapByIndex(unsigned int glyphIndex,
557557

558558
px = glyphMinX - blendImageMinX;
559559
py = blendImageMaxY - glyphMaxY;
560-
for (int x = 0; x < outWidth; ++x)
560+
for (int y = 0; y < outHeight; ++y)
561561
{
562-
for (int y = 0; y < outHeight; ++y)
562+
for (int x = 0; x < outWidth; ++x)
563563
{
564564
index = px + x + ((y + py) * blendWidth);
565565
index2 = x + (y * outWidth);
@@ -710,4 +710,4 @@ void FontFreeType::releaseFont(std::string_view fontName)
710710
}
711711
}
712712

713-
}
713+
} // namespace ax

0 commit comments

Comments
 (0)