From 5ab8e853e3fb3469dde28d568078d1f2374c30c5 Mon Sep 17 00:00:00 2001 From: Daria Volvenkova Date: Wed, 31 May 2017 19:57:20 +0300 Subject: [PATCH] Get POI symbol size for calculating text offset. --- drape_frontend/apply_feature_functors.cpp | 88 +++++++++++++---------- drape_frontend/apply_feature_functors.hpp | 10 ++- drape_frontend/rule_drawer.cpp | 6 +- drape_frontend/text_shape.cpp | 11 +-- drape_frontend/text_shape.hpp | 3 +- 5 files changed, 70 insertions(+), 48 deletions(-) diff --git a/drape_frontend/apply_feature_functors.cpp b/drape_frontend/apply_feature_functors.cpp index 6de6d5d37c..e5f0a95534 100644 --- a/drape_frontend/apply_feature_functors.cpp +++ b/drape_frontend/apply_feature_functors.cpp @@ -20,6 +20,7 @@ #include "drape/color.hpp" #include "drape/stipple_pen_resource.hpp" +#include "drape/texture_manager.hpp" #include "drape/utils/projection.hpp" #include "base/logging.hpp" @@ -465,45 +466,13 @@ void ApplyPointFeature::ProcessRule(Stylist::TRuleWrapper const & rule) } if (!params.m_primaryText.empty() || !params.m_secondaryText.empty()) - { - m_insertShape(make_unique_dp(m_centerPoint, params, m_tileKey, - hasPOI, 0 /* textIndex */, - true /* affectedByZoomPriority */, - specialDisplacementMode, specialModePriority)); - } + m_textParams.push_back(params); } } -void ApplyPointFeature::Finish(CustomSymbolsContextPtr const & customSymbolsContext) +void ApplyPointFeature::Finish(ref_ptr texMng, CustomSymbolsContextPtr const & customSymbolsContext) { - if (m_symbolRule == nullptr) - return; - - PoiSymbolViewParams params(m_id); - params.m_tileCenter = m_tileRect.Center(); - params.m_depth = static_cast(m_symbolDepth); - params.m_minVisibleScale = m_minVisibleScale; - params.m_rank = m_rank; - - params.m_symbolName = m_symbolRule->name(); - bool prioritized = false; - if (customSymbolsContext) - { - auto customSymbolIt = customSymbolsContext->m_symbols.find(m_id); - if (customSymbolIt != customSymbolsContext->m_symbols.end()) - { - params.m_symbolName = customSymbolIt->second.m_symbolName; - prioritized = customSymbolIt->second.m_prioritized; - } - } - - double const mainScale = df::VisualParams::Instance().GetVisualScale(); - params.m_extendingSize = static_cast(m_symbolRule->has_min_distance() ? - mainScale * m_symbolRule->min_distance() : 0.0); - params.m_posZ = m_posZ; - params.m_hasArea = m_hasArea; - params.m_prioritized = prioritized || m_createdByEditor; - params.m_obsoleteInEditor = m_obsoleteInEditor; + m2::PointF symbolSize(0.0f, 0.0f); bool specialDisplacementMode = false; uint16_t specialModePriority = 0; @@ -513,8 +482,51 @@ void ApplyPointFeature::Finish(CustomSymbolsContextPtr const & customSymbolsCont specialModePriority = CalculateHotelOverlayPriority(m_hotelData); } - m_insertShape(make_unique_dp(m_centerPoint, params, m_tileKey, 0 /* text index */, + bool const hasPOI = m_symbolRule != nullptr; + + if (hasPOI) + { + PoiSymbolViewParams params(m_id); + params.m_tileCenter = m_tileRect.Center(); + params.m_depth = static_cast(m_symbolDepth); + params.m_minVisibleScale = m_minVisibleScale; + params.m_rank = m_rank; + + params.m_symbolName = m_symbolRule->name(); + bool prioritized = false; + if (customSymbolsContext) + { + auto customSymbolIt = customSymbolsContext->m_symbols.find(m_id); + if (customSymbolIt != customSymbolsContext->m_symbols.end()) + { + params.m_symbolName = customSymbolIt->second.m_symbolName; + prioritized = customSymbolIt->second.m_prioritized; + } + } + + double const mainScale = df::VisualParams::Instance().GetVisualScale(); + params.m_extendingSize = static_cast(m_symbolRule->has_min_distance() ? + mainScale * m_symbolRule->min_distance() : 0.0); + params.m_posZ = m_posZ; + params.m_hasArea = m_hasArea; + params.m_prioritized = prioritized || m_createdByEditor; + params.m_obsoleteInEditor = m_obsoleteInEditor; + + m_insertShape(make_unique_dp(m_centerPoint, params, m_tileKey, 0 /* text index */, specialDisplacementMode, specialModePriority)); + + dp::TextureManager::SymbolRegion region; + texMng->GetSymbolRegion(params.m_symbolName, region); + symbolSize = region.GetPixelSize(); + } + + for (auto const & textParams : m_textParams) + { + m_insertShape(make_unique_dp(m_centerPoint, textParams, m_tileKey, + hasPOI, symbolSize, 0 /* textIndex */, + true /* affectedByZoomPriority */, + specialDisplacementMode, specialModePriority)); + } } ApplyAreaFeature::ApplyAreaFeature(TileKey const & tileKey, TInsertShapeFn const & insertShape, @@ -934,7 +946,7 @@ void ApplyLineFeature::GetRoadShieldsViewParams(ftypes::RoadShield const & shiel } } -void ApplyLineFeature::Finish(std::set && roadShields) +void ApplyLineFeature::Finish(ref_ptr texMng, std::set && roadShields) { #ifdef CALC_FILTERED_POINTS LinesStat::Get().InsertLine(m_id, m_currentScaleGtoP, m_readedCount, m_spline->GetSize()); @@ -974,7 +986,7 @@ void ApplyLineFeature::Finish(std::set && roadShields) for (uint32_t i = 0; i < shieldsCount && !it.BeginAgain(); i++) { m_insertShape(make_unique_dp(shieldOffset + it.m_pos, textParams, m_tileKey, - true /* hasPOI */, textIndex, + true /* hasPOI */, m2::PointF(0.0f, 0.0f) /* symbolSize */, textIndex, false /* affectedByZoomPriority */)); if (IsColoredRoadShield(shield)) { diff --git a/drape_frontend/apply_feature_functors.hpp b/drape_frontend/apply_feature_functors.hpp index 7d6de97ac7..58121cd73b 100644 --- a/drape_frontend/apply_feature_functors.hpp +++ b/drape_frontend/apply_feature_functors.hpp @@ -28,6 +28,11 @@ namespace ftypes struct RoadShield; } +namespace dp +{ +class TextureManager; +} // namespace dp + namespace df { @@ -84,7 +89,7 @@ public: void operator()(m2::PointD const & point, bool hasArea); void ProcessRule(Stylist::TRuleWrapper const & rule); - void Finish(CustomSymbolsContextPtr const & customSymbolsContext); + void Finish(ref_ptr texMng, CustomSymbolsContextPtr const & customSymbolsContext); protected: float const m_posZ; @@ -98,6 +103,7 @@ private: SymbolRuleProto const * m_symbolRule; m2::PointF m_centerPoint; int m_displacementMode; + std::vector m_textParams; }; class ApplyAreaFeature : public ApplyPointFeature @@ -150,7 +156,7 @@ public: void operator() (m2::PointD const & point); bool HasGeometry() const; void ProcessRule(Stylist::TRuleWrapper const & rule); - void Finish(std::set && roadShields); + void Finish(ref_ptr texMng, std::set && roadShields); m2::PolylineD GetPolyline() const; diff --git a/drape_frontend/rule_drawer.cpp b/drape_frontend/rule_drawer.cpp index 94a08ca6d3..00d75b79a4 100644 --- a/drape_frontend/rule_drawer.cpp +++ b/drape_frontend/rule_drawer.cpp @@ -314,7 +314,7 @@ void RuleDrawer::ProcessAreaStyle(FeatureType const & f, Stylist const & s, TIns return; s.ForEachRule(bind(&ApplyAreaFeature::ProcessRule, &apply, _1)); - apply.Finish(m_customSymbolsContext); + apply.Finish(m_context->GetTextureManager(), m_customSymbolsContext); } void RuleDrawer::ProcessLineStyle(FeatureType const & f, Stylist const & s, TInsertShapeFn const & insertShape, @@ -333,7 +333,7 @@ void RuleDrawer::ProcessLineStyle(FeatureType const & f, Stylist const & s, TIns if (apply.HasGeometry()) s.ForEachRule(bind(&ApplyLineFeature::ProcessRule, &apply, _1)); - apply.Finish(ftypes::GetRoadShields(f)); + apply.Finish(m_context->GetTextureManager(), ftypes::GetRoadShields(f)); if (m_context->IsTrafficEnabled() && zoomLevel >= kRoadClass0ZoomLevel) { @@ -388,7 +388,7 @@ void RuleDrawer::ProcessPointStyle(FeatureType const & f, Stylist const & s, TIn return; s.ForEachRule(bind(&ApplyPointFeature::ProcessRule, &apply, _1)); - apply.Finish(m_customSymbolsContext); + apply.Finish(m_context->GetTextureManager(), m_customSymbolsContext); } void RuleDrawer::operator()(FeatureType const & f) diff --git a/drape_frontend/text_shape.cpp b/drape_frontend/text_shape.cpp index 12d3c1516f..8deda12b7c 100644 --- a/drape_frontend/text_shape.cpp +++ b/drape_frontend/text_shape.cpp @@ -122,13 +122,14 @@ private: } // namespace TextShape::TextShape(m2::PointD const & basePoint, TextViewParams const & params, - TileKey const & tileKey, bool hasPOI, + TileKey const & tileKey, bool hasPOI, m2::PointF const & symbolSize, uint32_t textIndex, bool affectedByZoomPriority, bool specialDisplacementMode, uint16_t specialModePriority) : m_basePoint(basePoint) , m_params(params) , m_tileCoords(tileKey.GetTileCoords()) , m_hasPOI(hasPOI) + , m_symbolSize(symbolSize) , m_affectedByZoomPriority(affectedByZoomPriority) , m_textIndex(textIndex) , m_specialDisplacementMode(specialDisplacementMode) @@ -149,7 +150,7 @@ void TextShape::Draw(ref_ptr batcher, ref_ptr t m_params.m_primaryTextFont.m_isSdf, textures, m_params.m_anchor); } - glsl::vec2 primaryOffset = glsl::ToVec2(m_params.m_primaryOffset); + glsl::vec2 primaryOffset = glsl::ToVec2(m_params.m_primaryOffset + m2::PointF(0.0f, m_symbolSize.y / 2.0f)); if (!m_params.m_secondaryText.empty()) { @@ -242,7 +243,8 @@ void TextShape::DrawSubStringPlain(StraightTextLayout const & layout, dp::FontDe move(dynamicBuffer), true); handle->SetPivotZ(m_params.m_posZ); - handle->SetOverlayRank(m_hasPOI ? (isPrimary ? dp::OverlayRank1 : dp::OverlayRank2) : dp::OverlayRank0); + handle->SetOverlayRank(m_hasPOI ? (isPrimary ? dp::OverlayRank1 : dp::OverlayRank2) + : dp::OverlayRank0); handle->SetExtendingSize(m_params.m_extendingSize); dp::AttributeProvider provider(2, static_cast(staticBuffer.size())); @@ -291,7 +293,8 @@ void TextShape::DrawSubStringOutlined(StraightTextLayout const & layout, dp::Fon move(dynamicBuffer), true); handle->SetPivotZ(m_params.m_posZ); - handle->SetOverlayRank(m_hasPOI ? (isPrimary ? dp::OverlayRank1 : dp::OverlayRank2) : dp::OverlayRank0); + handle->SetOverlayRank(m_hasPOI ? (isPrimary ? dp::OverlayRank1 : dp::OverlayRank2) + : dp::OverlayRank0); handle->SetExtendingSize(m_params.m_extendingSize); dp::AttributeProvider provider(2, static_cast(staticBuffer.size())); diff --git a/drape_frontend/text_shape.hpp b/drape_frontend/text_shape.hpp index e135cbd127..2ea100fd07 100644 --- a/drape_frontend/text_shape.hpp +++ b/drape_frontend/text_shape.hpp @@ -16,7 +16,7 @@ class TextShape : public MapShape { public: TextShape(m2::PointD const & basePoint, TextViewParams const & params, - TileKey const & tileKey, bool hasPOI, + TileKey const & tileKey, bool hasPOI, m2::PointF const & symbolSize, uint32_t textIndex, bool affectedByZoomPriority, bool specialDisplacementMode = false, uint16_t specialModePriority = 0xFFFF); @@ -44,6 +44,7 @@ private: TextViewParams m_params; m2::PointI m_tileCoords; bool m_hasPOI; + m2::PointF m_symbolSize; bool m_affectedByZoomPriority; uint32_t m_textIndex;