MCPcopy Create free account
hub / github.com/comaps/comaps / ShapeSingleTextLine

Method ShapeSingleTextLine

libs/drape/texture_manager.cpp:496–562  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

494}
495
496text::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

Callers 6

StraightTextLayoutMethod · 0.80
PathTextLayoutMethod · 0.80
PrecacheMethod · 0.80
SetTextMethod · 0.80

Calls 15

ASSERTFunction · 0.85
ShapeTextMethod · 0.80
SetResourceInfoMethod · 0.80
getMethod · 0.65
emptyMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45
insertMethod · 0.45
reserveMethod · 0.45
MapResourceMethod · 0.45
emplace_backMethod · 0.45

Tested by

no test coverage detected