From 06b6c3f794d5bc9e2c5c0292d6bd14212f263d27 Mon Sep 17 00:00:00 2001 From: mvglasow Date: Tue, 19 Aug 2025 00:26:26 +0300 Subject: [PATCH] [drape] Replace newline with space in StraightTextLayout and PathTextLayout Signed-off-by: mvglasow --- libs/drape_frontend/text_layout.cpp | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/libs/drape_frontend/text_layout.cpp b/libs/drape_frontend/text_layout.cpp index 9b50080eb..5d9c705fc 100644 --- a/libs/drape_frontend/text_layout.cpp +++ b/libs/drape_frontend/text_layout.cpp @@ -281,10 +281,18 @@ dp::TGlyphs TextLayout::GetGlyphs() const StraightTextLayout::StraightTextLayout(std::string const & text, float fontSize, ref_ptr textures, dp::Anchor anchor, bool forceNoWrap) { - ASSERT_EQUAL(std::string::npos, text.find('\n'), ("Multiline text is not expected", text)); + /* + * TODO Temporary workaround: If the string contains newlines, replace them with whitespaces. + * On the long run, this should be fixed in the map generator and this workaround removed after + * a few months, when maps with buggy data can be expected to have been phased out. + */ + std::string stext = text; + while (stext.find('\n') != std::string::npos) + stext[stext.find('\n')] = ' '; + ASSERT_EQUAL(std::string::npos, stext.find('\n'), ("Multiline text is not expected", stext)); m_textSizeRatio = fontSize * static_cast(VisualParams::Instance().GetFontScale()) / dp::kBaseFontSizePixels; - m_shapedGlyphs = textures->ShapeSingleTextLine(dp::kBaseFontSizePixels, text, &m_glyphRegions); + m_shapedGlyphs = textures->ShapeSingleTextLine(dp::kBaseFontSizePixels, stext, &m_glyphRegions); // TODO(AB): Use ICU's BreakIterator to split text properly in different languages without spaces. // TODO(AB): Implement SplitText for RTL languages. @@ -378,13 +386,21 @@ PathTextLayout::PathTextLayout(m2::PointD const & tileCenter, std::string const ref_ptr textureManager) : m_tileCenter(tileCenter) { - ASSERT_EQUAL(std::string::npos, text.find('\n'), ("Multiline text is not expected", text)); + /* + * TODO Temporary workaround: If the string contains newlines, replace them with whitespaces. + * On the long run, this should be fixed in the map generator and this workaround removed after + * a few months, when maps with buggy data can be expected to have been phased out. + */ + std::string stext = text; + while (stext.find('\n') != std::string::npos) + stext[stext.find('\n')] = ' '; + ASSERT_EQUAL(std::string::npos, stext.find('\n'), ("Multiline text is not expected", stext)); auto const fontScale = static_cast(VisualParams::Instance().GetFontScale()); m_textSizeRatio = fontSize * fontScale / dp::kBaseFontSizePixels; // TODO(AB): StraightTextLayout used a logic to split a longer string into two strings. - m_shapedGlyphs = textureManager->ShapeSingleTextLine(dp::kBaseFontSizePixels, text, &m_glyphRegions); + m_shapedGlyphs = textureManager->ShapeSingleTextLine(dp::kBaseFontSizePixels, stext, &m_glyphRegions); } void PathTextLayout::CacheStaticGeometry(dp::TextureManager::ColorRegion const & colorRegion,