| 494 | } |
| 495 | |
| 496 | text::TextMetrics TextureManager::ShapeSingleTextLine( |
| 497 | float fontPixelHeight, std::string_view utf8, TGlyphsBuffer * glyphRegions, |
| 498 | localisation::LanguageIndex const textLanguageIndex) // TODO(AB): Better name? |
| 499 | { |
| 500 | ASSERT(!utf8.empty(), ()); |
| 501 | std::vector<ref_ptr<Texture::ResourceInfo>> resourcesInfo; |
| 502 | bool hasNewResources = false; |
| 503 | hb_language_t lang; |
| 504 | |
| 505 | if (textLanguageIndex == localisation::kUnsupportedLanguageIndex) |
| 506 | lang = m_mapLang; |
| 507 | else |
| 508 | { |
| 509 | localisation::LanguageCode const languageCode = localisation::ConvertLanguageIndexToLanguageCode(textLanguageIndex); |
| 510 | lang = hb_language_from_string(languageCode.data(), static_cast<int>(languageCode.size())); |
| 511 | } |
| 512 | |
| 513 | // TODO(AB): Is this mutex too slow? |
| 514 | std::lock_guard lock(m_calcGlyphsMutex); |
| 515 | |
| 516 | auto textMetrics = m_glyphManager->ShapeText(utf8, fontPixelHeight, lang); |
| 517 | |
| 518 | auto const & glyphs = textMetrics.m_glyphs; |
| 519 | |
| 520 | size_t const hybridGroupIndex = FindHybridGlyphsGroup(glyphs); |
| 521 | ASSERT(hybridGroupIndex != GetInvalidGlyphGroup(), ()); |
| 522 | GlyphGroup & group = m_glyphGroups[hybridGroupIndex]; |
| 523 | |
| 524 | // Mark used glyphs. |
| 525 | for (auto const & glyph : glyphs) |
| 526 | group.m_glyphKeys.insert(glyph.m_key); |
| 527 | |
| 528 | if (!group.m_texture) |
| 529 | group.m_texture = AllocateGlyphTexture(); |
| 530 | |
| 531 | if (glyphRegions) |
| 532 | resourcesInfo.reserve(glyphs.size()); |
| 533 | |
| 534 | for (auto const & glyph : glyphs) |
| 535 | { |
| 536 | bool newResource = false; |
| 537 | auto fontTexture = static_cast<FontTexture *>(group.m_texture.get())->MapResource(glyph.m_key, newResource); |
| 538 | hasNewResources |= newResource; |
| 539 | |
| 540 | if (glyphRegions) |
| 541 | resourcesInfo.emplace_back(fontTexture); |
| 542 | } |
| 543 | |
| 544 | if (glyphRegions) |
| 545 | { |
| 546 | glyphRegions->reserve(resourcesInfo.size()); |
| 547 | for (auto const & info : resourcesInfo) |
| 548 | { |
| 549 | GlyphRegion reg; |
| 550 | reg.SetResourceInfo(info); |
| 551 | reg.SetTexture(group.m_texture); |
| 552 | ASSERT(reg.IsValid(), ()); |
| 553 |
no test coverage detected