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

Method Init

libs/drape_frontend/stylist.cpp:52–108  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

50}
51
52void CaptionDescription::Init(FeatureType & f, int8_t deviceLang, int zoomLevel, feature::GeomType geomType,
53 bool auxCaptionExists)
54{
55 // TODO(pastk) : remove forced secondary text for all lines and set it via styles for major roads and rivers only.
56 // ATM even minor paths/streams/etc use secondary which makes their pathtexts take much more space.
57 localisation::NameTranslation translatedName = f.GetTranslatedName();
58 if (translatedName.m_primary.has_value())
59 {
60 m_mainText = translatedName.m_primary.value();
61 m_mainTextLanguageIndex = translatedName.m_primaryLikelyLanguageIndex;
62 }
63 if (zoomLevel > scales::GetUpperWorldScale() && (auxCaptionExists || geomType == feature::GeomType::Line))
64 {
65 if (translatedName.m_secondary.has_value())
66 {
67 m_auxText = translatedName.m_secondary.value();
68 m_auxTextLanguageIndex = translatedName.m_secondaryLikelyLanguageIndex;
69 }
70 }
71 if (ftypes::IsPublicTransportStopChecker::Instance()(feature::TypesHolder(f)))
72 {
73 auto const lRef = f.GetMetadata(feature::Metadata::FMD_LOCAL_REF);
74 if (!m_mainText.empty() && !lRef.empty())
75 {
76 //m_mainText.append(" (").append(lRef).append(")");
77 m_auxText = lRef;
78 }
79 }
80 ASSERT(m_auxText.empty() || !m_mainText.empty(), ("auxText without mainText"));
81
82 uint8_t constexpr kLongCaptionsMaxZoom = 4;
83 size_t constexpr kLowWorldMaxTextSize = 50;
84 if (zoomLevel <= kLongCaptionsMaxZoom && m_mainText.size() > kLowWorldMaxTextSize)
85 {
86 m_mainText.clear();
87 m_auxText.clear();
88 return;
89 }
90
91 // Set max text length to avoid VB/IB overflow in rendering.
92 size_t constexpr kMaxTextLength = 65;
93 if (strings::Truncate(m_mainText, kMaxTextLength))
94 m_mainText += "…";
95
96 // TODO(pastk) : its better to determine housenumbers minZoom once upon drules load and cache it,
97 // but it'd mean a lot of housenumbers-specific logic in otherwise generic RulesHolder..
98 uint8_t constexpr kHousenumbersMinZoom = 17;
99 if (geomType != feature::GeomType::Line && zoomLevel >= kHousenumbersMinZoom &&
100 (auxCaptionExists || m_mainText.empty()))
101 {
102 // TODO(pastk) : its not obvious that a housenumber display is dependent on a secondary caption drule existance in
103 // styles.
104 m_houseNumberText = f.GetHouseNumber();
105 if (!m_houseNumberText.empty() && !m_mainText.empty() && m_houseNumberText.find(m_mainText) != std::string::npos)
106 m_mainText.clear();
107 }
108}
109

Callers 7

OnContextCreateMethod · 0.45
StylistMethod · 0.45
OnContextCreateMethod · 0.45
BeginDragMethod · 0.45
StartNextAnimationsMethod · 0.45

Calls 13

GetUpperWorldScaleFunction · 0.85
ASSERTFunction · 0.85
TruncateFunction · 0.85
GetTranslatedNameMethod · 0.80
has_valueMethod · 0.80
GetHouseNumberMethod · 0.80
TypesHolderClass · 0.50
valueMethod · 0.45
GetMetadataMethod · 0.45
emptyMethod · 0.45
sizeMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected