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

Method StraightTextLayout

libs/drape_frontend/text_layout.cpp:287–325  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

285}
286
287StraightTextLayout::StraightTextLayout(std::string const & text, float fontSize, ref_ptr<dp::TextureManager> textures,
288 dp::Anchor anchor, bool forceNoWrap,
289 localisation::LanguageIndex const textLanguageIndex)
290{
291 /*
292 * TODO Temporary workaround: If the string contains newlines, replace them with whitespaces.
293 * On the long run, this should be fixed in the map generator and this workaround removed after
294 * a few months, when maps with buggy data can be expected to have been phased out.
295 */
296 std::string stext = text;
297 while (stext.find('\n') != std::string::npos)
298 stext[stext.find('\n')] = ' ';
299 ASSERT_EQUAL(std::string::npos, stext.find('\n'), ("Multiline text is not expected", stext));
300
301 m_textSizeRatio = fontSize * static_cast<float>(VisualParams::Instance().GetFontScale()) / dp::kBaseFontSizePixels;
302 m_shapedGlyphs = textures->ShapeSingleTextLine(dp::kBaseFontSizePixels, stext, &m_glyphRegions, textLanguageIndex);
303
304 // TODO(AB): Use ICU's BreakIterator to split text properly in different languages without spaces.
305 // TODO(AB): Implement SplitText for RTL languages.
306 auto const lines =
307 SplitText(forceNoWrap || m_shapedGlyphs.m_isRTL, m_textSizeRatio, textures->GetSpaceGlyph(), m_shapedGlyphs);
308 m_rowsCount = lines.size();
309
310 float summaryHeight = 0.;
311 float maxLength = 0;
312 for (auto const & line : lines)
313 {
314 summaryHeight += line.m_scaledHeight;
315 maxLength = std::max(maxLength, line.m_scaledLength);
316 }
317
318 XLayouter const xL(anchor);
319 YLayouter yL(anchor, summaryHeight);
320
321 for (auto const & l : lines)
322 m_offsets.emplace_back(l.m_nextLineStartIndex, glsl::vec2(xL(l.m_scaledLength, maxLength), yL(l.m_scaledHeight)));
323
324 m_pixelSize = m2::PointF(maxLength, summaryHeight);
325}
326
327m2::PointF StraightTextLayout::GetSymbolBasedTextOffset(m2::PointF const & symbolSize, dp::Anchor textAnchor,
328 dp::Anchor symbolAnchor)

Callers

nothing calls this directly

Calls 8

SplitTextFunction · 0.85
vec2Class · 0.85
GetFontScaleMethod · 0.80
ShapeSingleTextLineMethod · 0.80
GetSpaceGlyphMethod · 0.80
findMethod · 0.45
sizeMethod · 0.45
emplace_backMethod · 0.45

Tested by

no test coverage detected