| 1480 | } |
| 1481 | |
| 1482 | void Text::updateWidthCache() { |
| 1483 | if ( NULL == mFontStyleConfig.Font || mString.empty() ) |
| 1484 | return; |
| 1485 | |
| 1486 | mLinesWidth.clear(); |
| 1487 | |
| 1488 | Float width = 0; |
| 1489 | Float maxWidth = 0; |
| 1490 | bool bold = ( mFontStyleConfig.Style & Bold ) != 0; |
| 1491 | bool italic = ( mFontStyleConfig.Style & Italic ) != 0; |
| 1492 | Float hspace = static_cast<Float>( mFontStyleConfig.Font |
| 1493 | ->getGlyph( L' ', mFontStyleConfig.CharacterSize, bold, |
| 1494 | italic, mFontStyleConfig.OutlineThickness ) |
| 1495 | .advance ); |
| 1496 | |
| 1497 | #ifdef EE_TEXT_SHAPER_ENABLED |
| 1498 | if ( TextShaperEnabled && mFontStyleConfig.Font->getType() == FontType::TTF && |
| 1499 | !canSkipShaping( mTextHints ) ) { |
| 1500 | auto layout = TextLayout::layout( |
| 1501 | mString, mFontStyleConfig.Font, mFontStyleConfig.CharacterSize, mFontStyleConfig.Style, |
| 1502 | mTabWidth, mFontStyleConfig.OutlineThickness, {}, mTextHints, mDirection ); |
| 1503 | mLinesWidth = layout->getLinesWidth(); |
| 1504 | mCachedWidth = layout->size.getWidth(); |
| 1505 | return; |
| 1506 | } |
| 1507 | #endif |
| 1508 | |
| 1509 | Uint32 codepoint; |
| 1510 | Uint32 prevChar = 0; |
| 1511 | size_t size = mString.size(); |
| 1512 | for ( std::size_t i = 0; i < size; ++i ) { |
| 1513 | codepoint = mString[i]; |
| 1514 | auto glyph = |
| 1515 | mFontStyleConfig.Font->getGlyph( codepoint, mFontStyleConfig.CharacterSize, bold, |
| 1516 | italic, mFontStyleConfig.OutlineThickness ); |
| 1517 | |
| 1518 | if ( codepoint != '\t' && codepoint != '\n' ) { |
| 1519 | if ( !( mTextHints & TextHints::NoKerning ) ) { |
| 1520 | auto kerning = mFontStyleConfig.Font->getKerning( |
| 1521 | prevChar, codepoint, mFontStyleConfig.CharacterSize, bold, italic, |
| 1522 | mFontStyleConfig.OutlineThickness ); |
| 1523 | width += kerning; |
| 1524 | } |
| 1525 | |
| 1526 | width += glyph.advance; |
| 1527 | } else if ( codepoint == '\t' ) { |
| 1528 | width += tabAdvance( hspace, mTabWidth, mTabStops ? width : std::optional<Float>{} ); |
| 1529 | codepoint = 0; |
| 1530 | } else if ( codepoint == '\r' ) { |
| 1531 | prevChar = 0; |
| 1532 | continue; |
| 1533 | } |
| 1534 | |
| 1535 | if ( codepoint == '\n' ) { |
| 1536 | mLinesWidth.push_back( width ); |
| 1537 | width = 0; |
| 1538 | prevChar = 0; |
| 1539 | } else { |
nothing calls this directly
no test coverage detected