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

Method Draw

libs/drape_frontend/text_shape.cpp:235–282  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

233}
234
235void TextShape::Draw(ref_ptr<dp::GraphicsContext> context, ref_ptr<dp::Batcher> batcher,
236 ref_ptr<dp::TextureManager> textures) const
237{
238 auto const & titleDecl = m_params.m_titleDecl;
239
240 ASSERT(!titleDecl.m_primaryText.empty(), ());
241 StraightTextLayout primaryLayout(titleDecl.m_primaryText, titleDecl.m_primaryTextFont.m_size, textures,
242 titleDecl.m_anchor, titleDecl.m_forceNoWrap, titleDecl.m_primaryTextLanguageIndex);
243
244 if (m_params.m_limitedText)
245 {
246 if (auto const y = primaryLayout.GetPixelSize().y; y >= m_params.m_limits.y)
247 {
248 float const newFontSize = titleDecl.m_primaryTextFont.m_size * m_params.m_limits.y / y;
249 primaryLayout = StraightTextLayout(titleDecl.m_primaryText, newFontSize, textures, titleDecl.m_anchor,
250 titleDecl.m_forceNoWrap, titleDecl.m_primaryTextLanguageIndex);
251 }
252 }
253
254 glsl::vec2 primaryOffset;
255 glsl::vec2 secondaryOffset;
256 if (titleDecl.m_secondaryText.empty())
257 {
258 CalculateTextOffsets(titleDecl, primaryLayout.GetPixelSize(), m2::PointF{0.f, 0.f}, primaryOffset, secondaryOffset);
259 primaryOffset += glsl::vec2{m_symbolOffset.x, m_symbolOffset.y};
260 }
261 else
262 {
263 StraightTextLayout secondaryLayout{
264 titleDecl.m_secondaryText, titleDecl.m_secondaryTextFont.m_size, textures, titleDecl.m_anchor,
265 titleDecl.m_forceNoWrap, titleDecl.m_secondaryTextLanguageIndex};
266
267 if (secondaryLayout.GetGlyphCount() > 0)
268 {
269 CalculateTextOffsets(titleDecl, primaryLayout.GetPixelSize(), secondaryLayout.GetPixelSize(), primaryOffset,
270 secondaryOffset);
271 secondaryOffset += glsl::vec2(m_symbolOffset.x, m_symbolOffset.y);
272 DrawSubString(context, secondaryLayout, titleDecl.m_secondaryTextFont, secondaryOffset, batcher, textures,
273 false /* isPrimary */, titleDecl.m_secondaryOptional);
274 }
275 }
276
277 // The order of drawing secondary and primary texts has been changed after a minor refactoring for better performance.
278 // If there are any issues caused by a swapped order, it should be changed back.
279 if (primaryLayout.GetGlyphCount() > 0)
280 DrawSubString(context, primaryLayout, titleDecl.m_primaryTextFont, primaryOffset, batcher, textures,
281 true /* isPrimary */, titleDecl.m_primaryOptional);
282}
283
284void TextShape::DrawSubString(ref_ptr<dp::GraphicsContext> context, StraightTextLayout & layout,
285 dp::FontDecl const & font, glm::vec2 const & baseOffset, ref_ptr<dp::Batcher> batcher,

Callers

nothing calls this directly

Calls 7

ASSERTFunction · 0.85
CalculateTextOffsetsFunction · 0.85
vec2Class · 0.85
GetPixelSizeMethod · 0.80
GetGlyphCountMethod · 0.80
StraightTextLayoutClass · 0.70
emptyMethod · 0.45

Tested by

no test coverage detected