From 6fd7b180b2a786941134bb1b2eb41a89e5417262 Mon Sep 17 00:00:00 2001 From: Viktor Govako Date: Fri, 17 Jun 2022 10:02:17 +0300 Subject: [PATCH 01/15] [drape] Minor fixes to avoid static double constants. Signed-off-by: Viktor Govako --- drape_frontend/apply_feature_functors.cpp | 5 ++--- drape_frontend/apply_feature_functors.hpp | 2 +- drape_frontend/rule_drawer.cpp | 2 +- drape_frontend/stylist.cpp | 3 +++ drape_frontend/user_event_stream.cpp | 17 ++++++++++------- drape_frontend/user_event_stream.hpp | 5 ++++- drape_frontend/user_mark_shapes.cpp | 21 ++++++++------------- 7 files changed, 29 insertions(+), 26 deletions(-) diff --git a/drape_frontend/apply_feature_functors.cpp b/drape_frontend/apply_feature_functors.cpp index 6d7d0a4f44..02107bcfdb 100644 --- a/drape_frontend/apply_feature_functors.cpp +++ b/drape_frontend/apply_feature_functors.cpp @@ -778,7 +778,7 @@ ApplyLineFeatureGeometry::ApplyLineFeatureGeometry(TileKey const & tileKey, size_t pointsCount, bool smooth) : TBase(tileKey, insertShape, id, minVisibleScale, rank, CaptionDescription()) , m_currentScaleGtoP(static_cast(currentScaleGtoP)) - , m_sqrScale(currentScaleGtoP * currentScaleGtoP) + , m_minSegmentSqrLength(base::Pow2(4.0 * df::VisualParams::Instance().GetVisualScale() / currentScaleGtoP)) , m_simplify(tileKey.m_zoomLevel >= kLineSimplifyLevelStart && tileKey.m_zoomLevel <= kLineSimplifyLevelEnd) , m_smooth(smooth) @@ -804,9 +804,8 @@ void ApplyLineFeatureGeometry::operator() (m2::PointD const & point) } else { - static double minSegmentLength = base::Pow2(4.0 * df::VisualParams::Instance().GetVisualScale()); if (m_simplify && - ((m_spline->GetSize() > 1 && point.SquaredLength(m_lastAddedPoint) * m_sqrScale < minSegmentLength) || + ((m_spline->GetSize() > 1 && point.SquaredLength(m_lastAddedPoint) < m_minSegmentSqrLength) || m_spline->IsPrelonging(point))) { m_spline->ReplacePoint(point); diff --git a/drape_frontend/apply_feature_functors.hpp b/drape_frontend/apply_feature_functors.hpp index f7ee3b740a..8403dbed67 100644 --- a/drape_frontend/apply_feature_functors.hpp +++ b/drape_frontend/apply_feature_functors.hpp @@ -173,7 +173,7 @@ private: m2::SharedSpline m_spline; std::vector m_clippedSplines; float m_currentScaleGtoP; - double m_sqrScale; + double m_minSegmentSqrLength; m2::PointD m_lastAddedPoint; bool m_simplify; bool m_smooth; diff --git a/drape_frontend/rule_drawer.cpp b/drape_frontend/rule_drawer.cpp index bf9fb0d73e..670fa8244e 100644 --- a/drape_frontend/rule_drawer.cpp +++ b/drape_frontend/rule_drawer.cpp @@ -324,7 +324,7 @@ void RuleDrawer::ProcessLineStyle(FeatureType & f, Stylist const & s, TInsertShapeFn const & insertShape, int & minVisibleScale) { int const zoomLevel = m_context->GetTileKey().m_zoomLevel; - auto const smooth = ftypes::IsIsolineChecker::Instance()(f); + bool const smooth = ftypes::IsIsolineChecker::Instance()(f); ApplyLineFeatureGeometry applyGeom(m_context->GetTileKey(), insertShape, f.GetID(), m_currentScaleGtoP, minVisibleScale, f.GetRank(), diff --git a/drape_frontend/stylist.cpp b/drape_frontend/stylist.cpp index fbf395ecaf..ae2850b0d8 100644 --- a/drape_frontend/stylist.cpp +++ b/drape_frontend/stylist.cpp @@ -294,7 +294,10 @@ bool InitStylist(FeatureType & f, int8_t deviceLang, int const zoomLevel, bool b } } else + { + // GetSuitable function appends 'keys' vector, so move start index accordingly. idx = keys.size(); + } } feature::FilterRulesByRuntimeSelector(f, zoomLevel, keys); diff --git a/drape_frontend/user_event_stream.cpp b/drape_frontend/user_event_stream.cpp index d077a635d9..7ee24c64a9 100644 --- a/drape_frontend/user_event_stream.cpp +++ b/drape_frontend/user_event_stream.cpp @@ -141,7 +141,9 @@ UserEventStream::UserEventStream() , m_animationSystem(AnimationSystem::Instance()) , m_startDragOrg(m2::PointD::Zero()) , m_startDoubleTapAndHold(m2::PointD::Zero()) -{} + , m_dragThreshold(base::Pow2(VisualParams::Instance().GetDragThreshold())) +{ +} void UserEventStream::AddEvent(drape_ptr && event) { @@ -812,8 +814,7 @@ bool UserEventStream::CheckDrag(array const & touches, double threshol bool UserEventStream::TouchMove(array const & touches) { - double const kDragThreshold = base::Pow2(VisualParams::Instance().GetDragThreshold()); - size_t touchCount = GetValidTouchesCount(touches); + size_t const touchCount = GetValidTouchesCount(touches); bool isMapTouch = true; switch (m_state) @@ -821,7 +822,7 @@ bool UserEventStream::TouchMove(array const & touches) case STATE_EMPTY: if (touchCount == 1) { - if (CheckDrag(touches, kDragThreshold)) + if (CheckDrag(touches, m_dragThreshold)) BeginDrag(touches[0]); else isMapTouch = false; @@ -834,10 +835,12 @@ bool UserEventStream::TouchMove(array const & touches) case STATE_TAP_TWO_FINGERS: if (touchCount == 2) { - auto const threshold = static_cast(kDragThreshold); + float const threshold = static_cast(m_dragThreshold); if (m_twoFingersTouches[0].SquaredLength(touches[0].m_location) > threshold || m_twoFingersTouches[1].SquaredLength(touches[1].m_location) > threshold) + { BeginScale(touches[0], touches[1]); + } else isMapTouch = false; } @@ -848,13 +851,13 @@ bool UserEventStream::TouchMove(array const & touches) break; case STATE_TAP_DETECTION: case STATE_WAIT_DOUBLE_TAP: - if (CheckDrag(touches, kDragThreshold)) + if (CheckDrag(touches, m_dragThreshold)) CancelTapDetector(); else isMapTouch = false; break; case STATE_WAIT_DOUBLE_TAP_HOLD: - if (CheckDrag(touches, kDragThreshold)) + if (CheckDrag(touches, m_dragThreshold)) StartDoubleTapAndHold(touches[0]); break; case STATE_DOUBLE_TAP_HOLD: diff --git a/drape_frontend/user_event_stream.hpp b/drape_frontend/user_event_stream.hpp index d7698621a1..86def97619 100644 --- a/drape_frontend/user_event_stream.hpp +++ b/drape_frontend/user_event_stream.hpp @@ -408,6 +408,7 @@ public: }; UserEventStream(); + void AddEvent(drape_ptr && event); ScreenBase const & ProcessEvents(bool & modelViewChanged, bool & viewportChanged); ScreenBase const & GetCurrentScreen() const; @@ -497,7 +498,7 @@ private: bool DetectForceTap(Touch const & touch); void EndTapDetector(Touch const & touch); void CancelTapDetector(); - + void StartDoubleTapAndHold(Touch const & touch); void UpdateDoubleTapAndHold(Touch const & touch); void EndDoubleTapAndHold(Touch const & touch); @@ -556,6 +557,8 @@ private: std::array m_twoFingersTouches; m2::PointD m_startDoubleTapAndHold; + double const m_dragThreshold; + KineticScroller m_scroller; base::Timer m_kineticTimer; bool m_kineticScrollEnabled = true; diff --git a/drape_frontend/user_mark_shapes.cpp b/drape_frontend/user_mark_shapes.cpp index 9d1e530fe0..ffeccfc4a5 100644 --- a/drape_frontend/user_mark_shapes.cpp +++ b/drape_frontend/user_mark_shapes.cpp @@ -327,17 +327,15 @@ void GenerateTextShapes(ref_ptr context, ref_ptr(df::VisualParams::Instance().GetVisualScale()); m2::SharedSpline spline; spline.Reset(new m2::Spline(renderInfo.m_spline->GetSize())); - static double const kMinSegmentLength = base::Pow2(4.0 * vs); m2::PointD lastAddedPoint; for (auto const & point : renderInfo.m_spline->GetPath()) { - if (spline->GetSize() > 1 && point.SquaredLength(lastAddedPoint) * sqrScale < kMinSegmentLength) + if (spline->GetSize() > 1 && point.SquaredLength(lastAddedPoint) < minSqrLength) { spline->ReplacePoint(point); } @@ -568,15 +566,13 @@ void CacheUserLines(ref_ptr context, TileKey const & tileKe CHECK_GREATER(tileKey.m_zoomLevel, 0, ()); CHECK_LESS(tileKey.m_zoomLevel - 1, static_cast(kLineWidthZoomFactor.size()), ()); - auto const vs = static_cast(df::VisualParams::Instance().GetVisualScale()); + double const vs = df::VisualParams::Instance().GetVisualScale(); bool const simplify = tileKey.m_zoomLevel <= kLineSimplifyLevelEnd; - double sqrScale = 1.0; + // This var is used only if simplify == true. + double minSegmentSqrLength = 1.0; if (simplify) - { - double const currentScaleGtoP = 1.0 / GetScreenScale(tileKey.m_zoomLevel); - sqrScale = currentScaleGtoP * currentScaleGtoP; - } + minSegmentSqrLength = base::Pow2(4.0 * vs * GetScreenScale(tileKey.m_zoomLevel)); for (auto id : linesId) { @@ -604,7 +600,7 @@ void CacheUserLines(ref_ptr context, TileKey const & tileKe m2::SharedSpline spline = renderInfo.m_spline; if (simplify) - spline = SimplifySpline(renderInfo, sqrScale); + spline = SimplifySpline(renderInfo, minSegmentSqrLength); if (spline->GetSize() < 2) continue; @@ -623,8 +619,7 @@ void CacheUserLines(ref_ptr context, TileKey const & tileKe params.m_depthTestEnabled = true; params.m_depth = layer.m_depth; params.m_depthLayer = renderInfo.m_depthLayer; - params.m_width = static_cast(layer.m_width * vs * - kLineWidthZoomFactor[tileKey.m_zoomLevel - 1]); + params.m_width = static_cast(layer.m_width * vs * kLineWidthZoomFactor[tileKey.m_zoomLevel - 1]); params.m_minVisibleScale = 1; params.m_rank = 0; -- 2.45.3 From 4090cecb690a8a414469e825d60ca8a6b0b79efa Mon Sep 17 00:00:00 2001 From: Viktor Govako Date: Sat, 18 Jun 2022 15:03:39 +0300 Subject: [PATCH 02/15] [bookmarks] Took out helper code from BookmarkManager. Signed-off-by: Viktor Govako --- defines.hpp | 1 - map/bookmark_helpers.cpp | 153 +++++++++++++++----- map/bookmark_helpers.hpp | 18 ++- map/bookmark_manager.cpp | 207 +++------------------------ map/bookmark_manager.hpp | 11 +- map/framework.cpp | 1 + map/map_tests/bookmarks_test.cpp | 25 +--- map/map_tests/kmz_unarchive_test.cpp | 18 ++- platform/platform_android.cpp | 7 +- 9 files changed, 177 insertions(+), 264 deletions(-) diff --git a/defines.hpp b/defines.hpp index a9ad9376bd..6d7db959d9 100644 --- a/defines.hpp +++ b/defines.hpp @@ -60,7 +60,6 @@ #define READY_FILE_EXTENSION ".ready" #define RESUME_FILE_EXTENSION ".resume" #define DOWNLOADING_FILE_EXTENSION ".downloading" -#define BOOKMARKS_FILE_EXTENSION ".kml" #define TRANSIT_FILE_EXTENSION ".transit.json" #define GEOM_INDEX_TMP_EXT ".geomidx.tmp" diff --git a/map/bookmark_helpers.cpp b/map/bookmark_helpers.cpp index 4b53d09ad3..5b9a76325a 100644 --- a/map/bookmark_helpers.cpp +++ b/map/bookmark_helpers.cpp @@ -6,7 +6,6 @@ #include "kml/serdes_binary.hpp" #include "indexer/classificator.hpp" -#include "indexer/feature_utils.hpp" #include "platform/localization.hpp" #include "platform/platform.hpp" @@ -15,11 +14,9 @@ #include "coding/file_reader.hpp" #include "coding/file_writer.hpp" #include "coding/internal/file_data.hpp" -#include "coding/sha1.hpp" #include "coding/zip_reader.hpp" #include "base/file_name_utils.hpp" -#include "base/scope_guard.hpp" #include "base/string_utils.hpp" #include @@ -206,11 +203,76 @@ void ValidateKmlData(std::unique_ptr & data) t.m_layers.emplace_back(kml::KmlParser::GetDefaultTrackLayer()); } } + +// Returns extension with a dot in a lower case. +std::string GetFileExt(std::string const & filePath) +{ + return strings::MakeLowerCase(base::GetFileExtension(filePath)); +} + +std::string GetFileName(std::string const & filePath) +{ + std::string ret = filePath; + base::GetNameFromFullPath(ret); + return ret; +} + +bool IsBadCharForPath(char c) +{ + for (char illegalChar : {':', '/', '\\', '<', '>', '\"', '|', '?', '*'}) + { + if (c < ' ' || illegalChar == c) + return true; + } + + return false; +} } // namespace +std::string GetBookmarksDirectory() +{ + return base::JoinPath(GetPlatform().SettingsDir(), "bookmarks"); +} + +std::string RemoveInvalidSymbols(std::string const & name) +{ + // Remove not allowed symbols. + std::string res; + res.reserve(name.size()); + for (auto c : name) + { + if (!IsBadCharForPath(c)) + res.push_back(c); + } + return res; +} + +std::string GenerateUniqueFileName(const std::string & path, std::string name, std::string const & ext) +{ + // Remove extension, if file name already contains it. + if (strings::EndsWith(name, ext)) + name.resize(name.size() - ext.size()); + + size_t counter = 1; + std::string suffix; + while (Platform::IsFileExistsByFullPath(base::JoinPath(path, name + suffix + ext))) + suffix = strings::to_string(counter++); + return base::JoinPath(path, name + suffix + ext); +} + +std::string GenerateValidAndUniqueFilePathForKML(std::string const & fileName) +{ + std::string filePath = RemoveInvalidSymbols(fileName); + if (filePath.empty()) + filePath = kDefaultBookmarksFileName; + + return GenerateUniqueFileName(GetBookmarksDirectory(), std::move(filePath)); +} + std::string const kKmzExtension = ".kmz"; std::string const kKmlExtension = ".kml"; std::string const kKmbExtension = ".kmb"; +std::string const kDefaultBookmarksFileName = "Bookmarks"; std::unique_ptr LoadKmlFile(std::string const & file, KmlFileType fileType) { @@ -229,46 +291,61 @@ std::unique_ptr LoadKmlFile(std::string const & file, KmlFileType return kmlData; } -std::unique_ptr LoadKmzFile(std::string const & file, std::string & kmlHash) +std::string GetKMLPath(std::string const & filePath) { - std::string unarchievedPath; - try + std::string const fileExt = GetFileExt(filePath); + std::string fileSavePath; + if (fileExt == kKmlExtension) { - ZipFileReader::FileList files; - ZipFileReader::FilesList(file, files); - if (files.empty()) - return nullptr; + fileSavePath = GenerateValidAndUniqueFilePathForKML(GetFileName(filePath)); + if (!base::CopyFileX(filePath, fileSavePath)) + return {}; + } + else if (fileExt == kKmbExtension) + { + auto kmlData = LoadKmlFile(filePath, KmlFileType::Binary); + if (kmlData == nullptr) + return {}; - auto fileName = files.front().first; - for (auto const & f : files) + fileSavePath = GenerateValidAndUniqueFilePathForKML(GetFileName(filePath)); + if (!SaveKmlFileByExt(*kmlData, fileSavePath)) + return {}; + } + else if (fileExt == kKmzExtension) + { + try { - if (strings::MakeLowerCase(base::GetFileExtension(f.first)) == kKmlExtension) + ZipFileReader::FileList files; + ZipFileReader::FilesList(filePath, files); + std::string kmlFileName; + std::string ext; + for (size_t i = 0; i < files.size(); ++i) { - fileName = f.first; - break; + ext = GetFileExt(files[i].first); + if (ext == kKmlExtension) + { + kmlFileName = files[i].first; + break; + } } + if (kmlFileName.empty()) + return {}; + + fileSavePath = GenerateValidAndUniqueFilePathForKML(kmlFileName); + ZipFileReader::UnzipFile(filePath, kmlFileName, fileSavePath); + } + catch (RootException const & e) + { + LOG(LWARNING, ("Error unzipping file", filePath, e.Msg())); + return {}; } - unarchievedPath = file + ".raw"; - ZipFileReader::UnzipFile(file, fileName, unarchievedPath); } - catch (ZipFileReader::OpenException const & ex) + else { - LOG(LWARNING, ("Could not open zip file", ex.what())); - return nullptr; + LOG(LWARNING, ("Unknown file type", filePath)); + return {}; } - catch (std::exception const & ex) - { - LOG(LWARNING, ("Unexpected exception on openning zip file", ex.what())); - return nullptr; - } - - if (!GetPlatform().IsFileExistsByFullPath(unarchievedPath)) - return nullptr; - - SCOPE_GUARD(fileGuard, std::bind(&FileWriter::DeleteFileX, unarchievedPath)); - - kmlHash = coding::SHA1::CalculateBase64(unarchievedPath); - return LoadKmlFile(unarchievedPath, KmlFileType::Text); + return fileSavePath; } std::unique_ptr LoadKmlData(Reader const & reader, KmlFileType fileType) @@ -341,6 +418,13 @@ bool SaveKmlFileSafe(kml::FileData & kmlData, std::string const & file, KmlFileT }); } +bool SaveKmlFileByExt(kml::FileData & kmlData, std::string const & file) +{ + auto const ext = base::GetFileExtension(file); + return SaveKmlFileSafe(kmlData, file, ext == kKmbExtension ? KmlFileType::Binary + : KmlFileType::Text); +} + bool SaveKmlData(kml::FileData & kmlData, Writer & writer, KmlFileType fileType) { try @@ -386,8 +470,7 @@ void ResetIds(kml::FileData & kmlData) bool TruncType(std::string & type) { - static std::string const kDelim = "-"; - auto const pos = type.rfind(kDelim); + auto const pos = type.rfind('-'); if (pos == std::string::npos) return false; type.resize(pos); diff --git a/map/bookmark_helpers.hpp b/map/bookmark_helpers.hpp index 3ae6ed9c0b..f79a4818b9 100644 --- a/map/bookmark_helpers.hpp +++ b/map/bookmark_helpers.hpp @@ -2,8 +2,6 @@ #include "map/bookmark.hpp" -#include "indexer/feature.hpp" - #include "coding/reader.hpp" #include "geometry/rect2d.hpp" @@ -70,6 +68,7 @@ enum class BookmarkBaseType : uint16_t extern std::string const kKmzExtension; extern std::string const kKmlExtension; extern std::string const kKmbExtension; +extern std::string const kDefaultBookmarksFileName; enum class KmlFileType { @@ -87,12 +86,25 @@ inline std::string DebugPrint(KmlFileType fileType) UNREACHABLE(); } +/// @name File name/path helpers. +/// @{ +std::string GetBookmarksDirectory(); +std::string RemoveInvalidSymbols(std::string const & name); +std::string GenerateUniqueFileName(const std::string & path, std::string name, std::string const & ext = kKmlExtension); +std::string GenerateValidAndUniqueFilePathForKML(std::string const & fileName); +/// @} + +/// @name SerDes helpers. +/// @{ std::unique_ptr LoadKmlFile(std::string const & file, KmlFileType fileType); -std::unique_ptr LoadKmzFile(std::string const & file, std::string & kmlHash); std::unique_ptr LoadKmlData(Reader const & reader, KmlFileType fileType); +std::string GetKMLPath(std::string const & filePath); + bool SaveKmlFileSafe(kml::FileData & kmlData, std::string const & file, KmlFileType fileType); bool SaveKmlData(kml::FileData & kmlData, Writer & writer, KmlFileType fileType); +bool SaveKmlFileByExt(kml::FileData & kmlData, std::string const & file); +/// @} void ResetIds(kml::FileData & kmlData); diff --git a/map/bookmark_manager.cpp b/map/bookmark_manager.cpp index 4c5cfed03e..17312a7b9e 100644 --- a/map/bookmark_manager.cpp +++ b/map/bookmark_manager.cpp @@ -1,10 +1,8 @@ #include "map/bookmark_manager.hpp" -#include "map/api_mark_point.hpp" -#include "map/routing_mark.hpp" #include "map/search_api.hpp" -#include "map/search_mark.hpp" #include "map/user_mark.hpp" #include "map/user_mark_id_storage.hpp" +#include "map/track_mark.hpp" #include "drape_frontend/drape_engine.hpp" #include "drape_frontend/selection_shape.hpp" @@ -15,47 +13,31 @@ #include "platform/settings.hpp" #include "indexer/classificator.hpp" -#include "indexer/scales.hpp" #include "coding/file_writer.hpp" -#include "coding/hex.hpp" #include "coding/internal/file_data.hpp" #include "coding/serdes_json.hpp" -#include "coding/sha1.hpp" -#include "coding/string_utf8_multilang.hpp" #include "coding/zip_creator.hpp" -#include "coding/zip_reader.hpp" #include "geometry/rect_intersect.hpp" -#include "geometry/transformations.hpp" #include "base/file_name_utils.hpp" #include "base/macros.hpp" #include "base/stl_helpers.hpp" #include "base/string_utils.hpp" -#include "std/target_os.hpp" - #include -#include -#include +#include #include #include #include #include -#include -#include "private.h" - namespace { std::string const kLastEditedBookmarkCategory = "LastBookmarkCategory"; -// TODO(darina): Delete old setting. -std::string const kLastBookmarkType = "LastBookmarkType"; std::string const kLastEditedBookmarkColor = "LastBookmarkColor"; -std::string const kDefaultBookmarksFileName = "Bookmarks"; -std::string const kHotelsBookmarks = "Hotels"; std::string const kMetadataFileName = "bm.json"; std::string const kSortingTypeProperty = "sortingType"; std::string const kLargestBookmarkSymbolName = "bookmark-default-m"; @@ -63,37 +45,6 @@ size_t const kMinCommonTypesCount = 3; double const kNearDistanceInMeters = 20 * 1000.0; double const kMyPositionTrackSnapInMeters = 20.0; -// Returns extension with a dot in a lower case. -std::string GetFileExt(std::string const & filePath) -{ - return strings::MakeLowerCase(base::GetFileExtension(filePath)); -} - -std::string GetFileName(std::string const & filePath) -{ - std::string ret = filePath; - base::GetNameFromFullPath(ret); - return ret; -} - -std::string GetBookmarksDirectory() -{ - return base::JoinPath(GetPlatform().SettingsDir(), "bookmarks"); -} - -bool IsBadCharForPath(strings::UniChar const & c) -{ - static strings::UniChar const illegalChars[] = {':', '/', '\\', '<', '>', '\"', '|', '?', '*'}; - - for (size_t i = 0; i < ARRAY_SIZE(illegalChars); ++i) - { - if (c < ' ' || illegalChars[i] == c) - return true; - } - - return false; -} - class FindMarkFunctor { public: @@ -129,11 +80,12 @@ BookmarkManager::SharingResult GetFileForSharing(BookmarkManager::KMLDataCollect { auto const & kmlToShare = collection->front(); auto const categoryName = kml::GetDefaultStr(kmlToShare.second->m_categoryData.m_name); - std::string fileName = BookmarkManager::RemoveInvalidSymbols(categoryName, ""); + std::string fileName = RemoveInvalidSymbols(categoryName); if (fileName.empty()) fileName = base::GetNameFromFullPathWithoutExt(kmlToShare.first); + auto const filePath = base::JoinPath(GetPlatform().TmpDir(), fileName + kKmlExtension); - SCOPE_GUARD(fileGuard, std::bind(&FileWriter::DeleteFileX, filePath)); + SCOPE_GUARD(fileGuard, std::bind(&base::DeleteFileX, filePath)); auto const categoryId = kmlToShare.second->m_categoryData.m_id; @@ -610,10 +562,10 @@ template BookmarkManager::SortedByTimeBlockType GetSortedByTimeBlockType( std::chrono::duration const & timePeriod) { - static auto const kDay = std::chrono::hours(24); - static auto const kWeek = 7 * kDay; - static auto const kMonth = 31 * kDay; - static auto const kYear = 365 * kDay; + auto constexpr kDay = std::chrono::hours(24); + auto constexpr kWeek = 7 * kDay; + auto constexpr kMonth = 31 * kDay; + auto constexpr kYear = 365 * kDay; if (timePeriod < kWeek) return BookmarkManager::SortedByTimeBlockType::WeekAgo; @@ -1922,15 +1874,13 @@ void BookmarkManager::LoadBookmarks() CHECK_THREAD_CHECKER(m_threadChecker, ()); ClearCategories(); LoadMetadata(); + m_loadBookmarksFinished = false; NotifyAboutStartAsyncLoading(); GetPlatform().RunTask(Platform::Thread::File, [this]() { - std::string const dir = GetBookmarksDirectory(); - std::string const filesExt = kKmlExtension; - - auto collection = LoadBookmarks(dir, filesExt, KmlFileType::Text, - [](kml::FileData const &) + auto collection = LoadBookmarks(GetBookmarksDirectory(), kKmlExtension, KmlFileType::Text, + [](kml::FileData const &) { return true; // Allow to load any files from the bookmarks directory. }); @@ -1966,27 +1916,23 @@ void BookmarkManager::LoadBookmarkRoutine(std::string const & filePath, bool isT auto collection = std::make_shared(); - auto const savePath = GetKMLPath(filePath); - if (savePath) + std::string fileSavePath = GetKMLPath(filePath); + if (!fileSavePath.empty()) { - auto fileSavePath = *savePath; auto kmlData = LoadKmlFile(fileSavePath, KmlFileType::Text); if (m_needTeardown) return; if (kmlData) { - std::string fileName = base::GetNameFromFullPathWithoutExt(fileSavePath); + std::string const fileName = base::GetNameFromFullPathWithoutExt(fileSavePath); base::DeleteFileX(fileSavePath); fileSavePath = GenerateValidAndUniqueFilePathForKML(fileName); if (!SaveKmlFileSafe(*kmlData, fileSavePath, KmlFileType::Text)) - { base::DeleteFileX(fileSavePath); - fileSavePath.clear(); - } - if (!fileSavePath.empty()) + else collection->emplace_back(fileSavePath, std::move(kmlData)); } } @@ -2070,63 +2016,6 @@ void BookmarkManager::NotifyAboutFile(bool success, std::string const & filePath }); } -std::optional BookmarkManager::GetKMLPath(std::string const & filePath) -{ - std::string const fileExt = GetFileExt(filePath); - std::string fileSavePath; - if (fileExt == kKmlExtension) - { - fileSavePath = GenerateValidAndUniqueFilePathForKML(GetFileName(filePath)); - if (!base::CopyFileX(filePath, fileSavePath)) - return {}; - } - else if (fileExt == kKmbExtension) - { - auto kmlData = LoadKmlFile(filePath, KmlFileType::Binary); - if (kmlData == nullptr) - return {}; - - fileSavePath = GenerateValidAndUniqueFilePathForKML(GetFileName(filePath)); - if (!SaveKmlFileByExt(*kmlData, fileSavePath)) - return {}; - } - else if (fileExt == kKmzExtension) - { - try - { - ZipFileReader::FileList files; - ZipFileReader::FilesList(filePath, files); - std::string kmlFileName; - std::string ext; - for (size_t i = 0; i < files.size(); ++i) - { - ext = GetFileExt(files[i].first); - if (ext == kKmlExtension) - { - kmlFileName = files[i].first; - break; - } - } - if (kmlFileName.empty()) - return {}; - - fileSavePath = GenerateValidAndUniqueFilePathForKML(kmlFileName); - ZipFileReader::UnzipFile(filePath, kmlFileName, fileSavePath); - } - catch (RootException const & e) - { - LOG(LWARNING, ("Error unzipping file", filePath, e.Msg())); - return {}; - } - } - else - { - LOG(LWARNING, ("Unknown file type", filePath)); - return {}; - } - return fileSavePath; -} - void BookmarkManager::MoveBookmark(kml::MarkId bmID, kml::MarkGroupId curGroupID, kml::MarkGroupId newGroupID) { CHECK_THREAD_CHECKER(m_threadChecker, ()); @@ -2730,7 +2619,6 @@ BookmarkManager::KMLDataCollectionPtr BookmarkManager::PrepareToSaveBookmarks( CHECK_THREAD_CHECKER(m_threadChecker, ()); std::string const fileDir = GetBookmarksDirectory(); - std::string const fileExt = kKmlExtension; if (!GetPlatform().IsFileExistsByFullPath(fileDir) && !GetPlatform().MkDirChecked(fileDir)) return nullptr; @@ -2741,27 +2629,22 @@ BookmarkManager::KMLDataCollectionPtr BookmarkManager::PrepareToSaveBookmarks( auto * group = GetBmCategory(groupId); // Get valid file name from category name - std::string const name = RemoveInvalidSymbols(group->GetName(), kDefaultBookmarksFileName); std::string file = group->GetFileName(); - if (file.empty()) { - file = GenerateUniqueFileName(fileDir, name, fileExt); + std::string name = RemoveInvalidSymbols(group->GetName()); + if (name.empty()) + name = kDefaultBookmarksFileName; + + file = GenerateUniqueFileName(fileDir, std::move(name)); group->SetFileName(file); } - collection->emplace_back(file, CollectBmGroupKMLData(group)); + collection->emplace_back(std::move(file), CollectBmGroupKMLData(group)); } return collection; } -bool BookmarkManager::SaveKmlFileByExt(kml::FileData & kmlData, std::string const & file) -{ - auto const ext = base::GetFileExtension(file); - return SaveKmlFileSafe(kmlData, file, ext == kKmbExtension ? KmlFileType::Binary - : KmlFileType::Text); -} - void BookmarkManager::SaveBookmarks(kml::GroupIdCollection const & groupIdCollection) { CHECK_THREAD_CHECKER(m_threadChecker, ()); @@ -2781,8 +2664,7 @@ void BookmarkManager::SaveBookmarks(kml::GroupIdCollection const & groupIdCollec return; } - GetPlatform().RunTask(Platform::Thread::File, - [this, kmlDataCollection = std::move(kmlDataCollection)]() + GetPlatform().RunTask(Platform::Thread::File, [kmlDataCollection = std::move(kmlDataCollection)]() { for (auto const & kmlItem : *kmlDataCollection) SaveKmlFileByExt(*kmlItem.second, kmlItem.first); @@ -3310,49 +3192,6 @@ bool BookmarkManager::Metadata::GetEntryProperty(std::string const & entryName, return it->second.GetProperty(propertyName, value); } -// static -std::string BookmarkManager::RemoveInvalidSymbols(std::string const & name, std::string const & defaultName) -{ - // Remove not allowed symbols - strings::UniString uniName = strings::MakeUniString(name); - uniName.erase_if(&IsBadCharForPath); - return (uniName.empty() ? defaultName : strings::ToUtf8(uniName)); -} - -// static -std::string BookmarkManager::GenerateUniqueFileName(const std::string & path, std::string name, std::string const & kmlExt) -{ - // check if file name already contains .kml extension - size_t const extPos = name.rfind(kmlExt); - if (extPos != std::string::npos) - { - // remove extension - ASSERT_GREATER_OR_EQUAL(name.size(), kmlExt.size(), ()); - size_t const expectedPos = name.size() - kmlExt.size(); - if (extPos == expectedPos) - name.resize(expectedPos); - } - - size_t counter = 1; - std::string suffix; - while (Platform::IsFileExistsByFullPath(base::JoinPath(path, name + suffix + kmlExt))) - suffix = strings::to_string(counter++); - return base::JoinPath(path, name + suffix + kmlExt); -} - -// static -std::string BookmarkManager::GenerateValidAndUniqueFilePathForKML(std::string const & fileName) -{ - std::string filePath = RemoveInvalidSymbols(fileName, kDefaultBookmarksFileName); - return GenerateUniqueFileName(GetBookmarksDirectory(), filePath, kKmlExtension); -} - -// static -std::string BookmarkManager::GetActualBookmarksDirectory() -{ - return GetBookmarksDirectory(); -} - BookmarkManager::EditSession::EditSession(BookmarkManager & manager) : m_bmManager(manager) { diff --git a/map/bookmark_manager.hpp b/map/bookmark_manager.hpp index 75f25dbf79..3eb9760611 100644 --- a/map/bookmark_manager.hpp +++ b/map/bookmark_manager.hpp @@ -4,7 +4,6 @@ #include "map/bookmark_helpers.hpp" #include "map/elevation_info.hpp" #include "map/track.hpp" -#include "map/track_mark.hpp" #include "map/user_mark_layer.hpp" #include "drape_frontend/drape_engine_safe_ptr.hpp" @@ -25,7 +24,6 @@ #include #include #include -#include #include #include @@ -152,7 +150,7 @@ public: void AttachBookmark(kml::MarkId bmId, kml::MarkGroupId groupId); void DetachBookmark(kml::MarkId bmId, kml::MarkGroupId groupId); - + Track * GetTrackForEdit(kml::TrackId trackId); void MoveTrack(kml::TrackId trackID, kml::MarkGroupId curGroupID, kml::MarkGroupId newGroupID); @@ -364,15 +362,10 @@ public: void FilterInvalidBookmarks(kml::MarkIdCollection & bookmarks) const; void FilterInvalidTracks(kml::TrackIdCollection & tracks) const; - /// These functions are public for unit tests only. You shouldn't call them from client code. void EnableTestMode(bool enable); bool SaveBookmarkCategory(kml::MarkGroupId groupId); bool SaveBookmarkCategory(kml::MarkGroupId groupId, Writer & writer, KmlFileType fileType) const; void CreateCategories(KMLDataCollection && dataCollection, bool autoSave = true); - static std::string RemoveInvalidSymbols(std::string const & name, std::string const & defaultName); - static std::string GenerateUniqueFileName(std::string const & path, std::string name, std::string const & fileExt); - static std::string GenerateValidAndUniqueFilePathForKML(std::string const & fileName); - static std::string GetActualBookmarksDirectory(); static std::string GetTracksSortedBlockName(); static std::string GetOthersSortedBlockName(); static std::string GetNearMeSortedBlockName(); @@ -614,7 +607,6 @@ private: void NotifyAboutStartAsyncLoading(); void NotifyAboutFinishAsyncLoading(KMLDataCollectionPtr && collection); - std::optional GetKMLPath(std::string const & filePath); void NotifyAboutFile(bool success, std::string const & filePath, bool isTemporaryFile); void LoadBookmarkRoutine(std::string const & filePath, bool isTemporaryFile); @@ -638,7 +630,6 @@ private: std::unique_ptr CollectBmGroupKMLData(BookmarkCategory const * group) const; KMLDataCollectionPtr PrepareToSaveBookmarks(kml::GroupIdCollection const & groupIdCollection); - bool SaveKmlFileByExt(kml::FileData & kmlData, std::string const & file); bool HasDuplicatedIds(kml::FileData const & fileData) const; template diff --git a/map/framework.cpp b/map/framework.cpp index 696a662a1c..9e48da3812 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -2,6 +2,7 @@ #include "map/benchmark_tools.hpp" #include "map/gps_tracker.hpp" #include "map/user_mark.hpp" +#include "map/track_mark.hpp" #include "ge0/geo_url_parser.hpp" #include "ge0/parser.hpp" diff --git a/map/map_tests/bookmarks_test.cpp b/map/map_tests/bookmarks_test.cpp index 40ec385786..e23c4a11c0 100644 --- a/map/map_tests/bookmarks_test.cpp +++ b/map/map_tests/bookmarks_test.cpp @@ -216,7 +216,7 @@ UNIT_CLASS_TEST(Runner, Bookmarks_ImportKML) UNIT_CLASS_TEST(Runner, Bookmarks_ExportKML) { - string const dir = BookmarkManager::GetActualBookmarksDirectory(); + string const dir = GetBookmarksDirectory(); bool const delDirOnExit = Platform::MkDir(dir) == Platform::ERR_OK; SCOPE_GUARD(dirDeleter, [&](){ if (delDirOnExit) (void)Platform::RmDir(dir); }); string const ext = ".kmb"; @@ -287,7 +287,7 @@ namespace { void DeleteCategoryFiles(vector const & arrFiles) { - string const path = BookmarkManager::GetActualBookmarksDirectory(); + string const path = GetBookmarksDirectory(); string const extension = ".kmb"; for (auto const & fileName : arrFiles) FileWriter::DeleteFileX(base::JoinPath(path, fileName + extension)); @@ -490,32 +490,21 @@ UNIT_TEST(Bookmarks_IllegalFileName) vector const arrLegal = {"", "", "x", "x", "xy", "xy"}; for (size_t i = 0; i < arrIllegal.size(); ++i) - { - string const name = BookmarkManager::RemoveInvalidSymbols(arrIllegal[i], "Bookmarks"); - - if (arrLegal[i].empty()) - { - TEST_EQUAL("Bookmarks", name, ()); - } - else - { - TEST_EQUAL(arrLegal[i], name, ()); - } - } + TEST_EQUAL(arrLegal[i], RemoveInvalidSymbols(arrIllegal[i]), ()); } UNIT_TEST(Bookmarks_UniqueFileName) { string const BASE = "SomeUniqueFileName"; string const FILEBASE = "./" + BASE; - string const FILENAME = FILEBASE + BOOKMARKS_FILE_EXTENSION; + string const FILENAME = FILEBASE + kKmlExtension; { FileWriter file(FILENAME); file.Write(FILENAME.data(), FILENAME.size()); } - string gen = BookmarkManager::GenerateUniqueFileName(".", BASE, BOOKMARKS_FILE_EXTENSION); + string gen = GenerateUniqueFileName(".", BASE); TEST_NOT_EQUAL(gen, FILENAME, ()); TEST_EQUAL(gen, FILEBASE + "1.kml", ()); @@ -524,7 +513,7 @@ UNIT_TEST(Bookmarks_UniqueFileName) FileWriter file(FILENAME1); file.Write(FILENAME1.data(), FILENAME1.size()); } - gen = BookmarkManager::GenerateUniqueFileName(".", BASE, BOOKMARKS_FILE_EXTENSION); + gen = GenerateUniqueFileName(".", BASE); TEST_NOT_EQUAL(gen, FILENAME, ()); TEST_NOT_EQUAL(gen, FILENAME1, ()); TEST_EQUAL(gen, FILEBASE + "2.kml", ()); @@ -532,7 +521,7 @@ UNIT_TEST(Bookmarks_UniqueFileName) FileWriter::DeleteFileX(FILENAME); FileWriter::DeleteFileX(FILENAME1); - gen = BookmarkManager::GenerateUniqueFileName(".", BASE, BOOKMARKS_FILE_EXTENSION); + gen = GenerateUniqueFileName(".", BASE); TEST_EQUAL(gen, FILENAME, ()); } diff --git a/map/map_tests/kmz_unarchive_test.cpp b/map/map_tests/kmz_unarchive_test.cpp index caff022941..af56077bac 100644 --- a/map/map_tests/kmz_unarchive_test.cpp +++ b/map/map_tests/kmz_unarchive_test.cpp @@ -1,25 +1,23 @@ #include "testing/testing.hpp" #include "map/bookmark_helpers.hpp" -#include "map/framework.hpp" -#include "map/user_mark_id_storage.hpp" #include "platform/platform.hpp" -#include "coding/zip_reader.hpp" - #include "base/scope_guard.hpp" -#include -#include UNIT_TEST(KMZ_UnzipTest) { - UserMarkIdStorage::Instance().EnableSaving(false); - std::string const kmzFile = GetPlatform().TestsDataPathForFile("test.kmz"); - std::string kmlHash; - auto kmlData = LoadKmzFile(kmzFile, kmlHash); + std::string const filePath = GetKMLPath(kmzFile); + + TEST(!filePath.empty(), ()); + SCOPE_GUARD(fileGuard, std::bind(&base::DeleteFileX, filePath)); + + TEST(strings::EndsWith(filePath, "doc.kml"), (filePath)); + + auto const kmlData = LoadKmlFile(filePath, KmlFileType::Text); TEST(kmlData != nullptr, ()); TEST_EQUAL(kmlData->m_bookmarksData.size(), 6, ("Category wrong number of bookmarks")); diff --git a/platform/platform_android.cpp b/platform/platform_android.cpp index 167c85659c..2555b4c99a 100644 --- a/platform/platform_android.cpp +++ b/platform/platform_android.cpp @@ -49,7 +49,8 @@ private: unique_ptr Platform::GetReader(string const & file, string searchScope) const { - string const ext = base::GetFileExtension(file); + string ext = base::GetFileExtension(file); + strings::AsciiToLower(ext); ASSERT(!ext.empty(), ()); uint32_t const logPageSize = (ext == DATA_FILE_EXTENSION) ? READER_CHUNK_LOG_SIZE : 10; @@ -61,6 +62,8 @@ unique_ptr Platform::GetReader(string const & file, string searchSc searchScope = "f"; else { + ASSERT(ext != ".kml" && ext != ".kmb" && ext != ".kmz", ("BookmarkManager is responsible for that")); + if (ext == DATA_FILE_EXTENSION) { if (strings::StartsWith(file, WORLD_COASTS_FILE_NAME) || strings::StartsWith(file, WORLD_FILE_NAME)) @@ -68,8 +71,6 @@ unique_ptr Platform::GetReader(string const & file, string searchSc else searchScope = "w"; } - else if (ext == BOOKMARKS_FILE_EXTENSION) - searchScope = "w"; else if (file == SETTINGS_FILE_NAME) searchScope = "s"; else -- 2.45.3 From 914362725b499e7189e985f24f0a96c625ae6364 Mon Sep 17 00:00:00 2001 From: Viktor Govako Date: Sat, 18 Jun 2022 23:23:41 +0300 Subject: [PATCH 03/15] [drape] Minor code optimizations. Signed-off-by: Viktor Govako --- drape/font_texture.cpp | 6 ++-- drape/font_texture.hpp | 10 +++---- drape/glyph_generator.cpp | 2 -- drape/texture_manager.cpp | 26 +++++++--------- drape/texture_manager.hpp | 10 +++---- drape_frontend/user_mark_shapes.cpp | 46 +++++++++++++---------------- 6 files changed, 43 insertions(+), 57 deletions(-) diff --git a/drape/font_texture.cpp b/drape/font_texture.cpp index 03f7444358..25e0b30660 100644 --- a/drape/font_texture.cpp +++ b/drape/font_texture.cpp @@ -13,8 +13,6 @@ #include #include -using namespace std::placeholders; - namespace dp { GlyphPacker::GlyphPacker(const m2::PointU & size) @@ -258,11 +256,12 @@ void GlyphIndex::UploadResources(ref_ptr context, ref_ptrUploadData(context, zeroPoint.x, zeroPoint.y, rect.SizeX(), rect.SizeY(), make_ref(srcMemory)); - + glyph.m_image.Destroy(); } } +/* uint32_t GlyphIndex::GetAbsentGlyphsCount(strings::UniString const & text, int fixedHeight) const { uint32_t count = 0; @@ -273,4 +272,5 @@ uint32_t GlyphIndex::GetAbsentGlyphsCount(strings::UniString const & text, int f } return count; } +*/ } // namespace dp diff --git a/drape/font_texture.hpp b/drape/font_texture.hpp index adda3040da..e6a9c9ea9c 100644 --- a/drape/font_texture.hpp +++ b/drape/font_texture.hpp @@ -88,7 +88,7 @@ public: bool CanBeGlyphPacked(uint32_t glyphsCount) const; - uint32_t GetAbsentGlyphsCount(strings::UniString const & text, int fixedHeight) const; + //uint32_t GetAbsentGlyphsCount(strings::UniString const & text, int fixedHeight) const; // ONLY for unit-tests. DO NOT use this function anywhere else. size_t GetPendingNodesCount(); @@ -138,10 +138,10 @@ public: return m_index.CanBeGlyphPacked(newKeysCount); } - uint32_t GetAbsentGlyphsCount(strings::UniString const & text, int fixedHeight) const - { - return m_index.GetAbsentGlyphsCount(text, fixedHeight); - } +// uint32_t GetAbsentGlyphsCount(strings::UniString const & text, int fixedHeight) const +// { +// return m_index.GetAbsentGlyphsCount(text, fixedHeight); +// } private: GlyphIndex m_index; diff --git a/drape/glyph_generator.cpp b/drape/glyph_generator.cpp index c693dd695b..0c2c623df9 100644 --- a/drape/glyph_generator.cpp +++ b/drape/glyph_generator.cpp @@ -2,8 +2,6 @@ #include -using namespace std::placeholders; - namespace dp { GlyphGenerator::GlyphGenerator(uint32_t sdfScale) diff --git a/drape/texture_manager.cpp b/drape/texture_manager.cpp index 097376f0c2..88071dcc60 100644 --- a/drape/texture_manager.cpp +++ b/drape/texture_manager.cpp @@ -478,9 +478,8 @@ void TextureManager::OnSwitchMapStyle(ref_ptr context) // For Vulkan we use m_texturesToCleanup to defer textures destroying. for (size_t i = 0; i < m_symbolTextures.size(); ++i) { - ASSERT(m_symbolTextures[i] != nullptr, ()); - ASSERT(dynamic_cast(m_symbolTextures[i].get()) != nullptr, ()); ref_ptr symbolsTexture = make_ref(m_symbolTextures[i]); + ASSERT(symbolsTexture != nullptr, ()); if (context->GetApiVersion() != dp::ApiVersion::Vulkan) symbolsTexture->Invalidate(context, m_resPostfix, make_ref(m_textureAllocator)); @@ -495,34 +494,27 @@ void TextureManager::GetTexturesToCleanup(std::vector> & te std::swap(textures, m_texturesToCleanup); } -void TextureManager::GetSymbolRegion(std::string const & symbolName, SymbolRegion & region) +bool TextureManager::GetSymbolRegionSafe(std::string const & symbolName, SymbolRegion & region) { CHECK(m_isInitialized, ()); for (size_t i = 0; i < m_symbolTextures.size(); ++i) { - ASSERT(m_symbolTextures[i] != nullptr, ()); ref_ptr symbolsTexture = make_ref(m_symbolTextures[i]); + ASSERT(symbolsTexture != nullptr, ()); if (symbolsTexture->IsSymbolContained(symbolName)) { GetRegionBase(symbolsTexture, region, SymbolsTexture::SymbolKey(symbolName)); region.SetTextureIndex(static_cast(i)); - return; + return true; } } - LOG(LWARNING, ("Detected using of unknown symbol ", symbolName)); + return false; } -bool TextureManager::HasSymbolRegion(std::string const & symbolName) const +void TextureManager::GetSymbolRegion(std::string const & symbolName, SymbolRegion & region) { - CHECK(m_isInitialized, ()); - for (size_t i = 0; i < m_symbolTextures.size(); ++i) - { - ASSERT(m_symbolTextures[i] != nullptr, ()); - ref_ptr symbolsTexture = make_ref(m_symbolTextures[i]); - if (symbolsTexture->IsSymbolContained(symbolName)) - return true; - } - return false; + if (!GetSymbolRegionSafe(symbolName, region)) + LOG(LWARNING, ("Detected using of unknown symbol ", symbolName)); } void TextureManager::GetStippleRegion(PenPatternT const & pen, StippleRegion & region) @@ -551,6 +543,7 @@ void TextureManager::GetGlyphRegions(strings::UniString const & text, int fixedH CalcGlyphRegions(text, fixedHeight, regions); } +/* uint32_t TextureManager::GetAbsentGlyphsCount(ref_ptr texture, strings::UniString const & text, int fixedHeight) const @@ -573,6 +566,7 @@ uint32_t TextureManager::GetAbsentGlyphsCount(ref_ptr texture, TMultili count += GetAbsentGlyphsCount(texture, text[i], fixedHeight); return count; } +*/ bool TextureManager::AreGlyphsReady(strings::UniString const & str, int fixedHeight) const { diff --git a/drape/texture_manager.hpp b/drape/texture_manager.hpp index d1479f4bb8..49efef4c8c 100644 --- a/drape/texture_manager.hpp +++ b/drape/texture_manager.hpp @@ -88,8 +88,8 @@ public: void OnSwitchMapStyle(ref_ptr context); void GetTexturesToCleanup(std::vector> & textures); + bool GetSymbolRegionSafe(std::string const & symbolName, SymbolRegion & region); void GetSymbolRegion(std::string const & symbolName, SymbolRegion & region); - bool HasSymbolRegion(std::string const & symbolName) const; void GetStippleRegion(PenPatternT const & pen, StippleRegion & region); void GetColorRegion(Color const & color, ColorRegion & region); @@ -202,10 +202,10 @@ private: FillResults(text, fixedHeight, buffers, group); } - uint32_t GetAbsentGlyphsCount(ref_ptr texture, strings::UniString const & text, - int fixedHeight) const; - uint32_t GetAbsentGlyphsCount(ref_ptr texture, TMultilineText const & text, - int fixedHeight) const; +// uint32_t GetAbsentGlyphsCount(ref_ptr texture, strings::UniString const & text, +// int fixedHeight) const; +// uint32_t GetAbsentGlyphsCount(ref_ptr texture, TMultilineText const & text, +// int fixedHeight) const; void UpdateGlyphTextures(ref_ptr context); bool HasAsyncRoutines() const; diff --git a/drape_frontend/user_mark_shapes.cpp b/drape_frontend/user_mark_shapes.cpp index ffeccfc4a5..27d0f5812b 100644 --- a/drape_frontend/user_mark_shapes.cpp +++ b/drape_frontend/user_mark_shapes.cpp @@ -348,21 +348,18 @@ m2::SharedSpline SimplifySpline(UserLineRenderParams const & renderInfo, double return spline; } -std::string GetBackgroundForSymbol(std::string const & symbolName, - ref_ptr textures) +std::string GetBackgroundSymbolName(std::string const & symbolName) { - static std::string const kDelimiter = "-"; - static std::string const kBackgroundName = "bg"; - auto const tokens = strings::Tokenize(symbolName, kDelimiter.c_str()); + char const * kDelimiter = "-"; + auto const tokens = strings::Tokenize(symbolName, kDelimiter); if (tokens.size() < 2 || tokens.size() > 3) return {}; - std::string backgroundSymbol; - backgroundSymbol.append(tokens[0]).append(kDelimiter).append(kBackgroundName); + std::string res; + res.append(tokens[0]).append(kDelimiter).append("bg"); if (tokens.size() == 3) - backgroundSymbol.append(kDelimiter).append(tokens[2]); - - return textures->HasSymbolRegion(backgroundSymbol) ? backgroundSymbol : ""; + res.append(kDelimiter).append(tokens[2]); + return res; } drape_ptr CreateSymbolOverlayHandle(UserMarkRenderParams const & renderInfo, @@ -403,12 +400,12 @@ void CacheUserMarks(ref_ptr context, TileKey const & tileKe m2::PointD const tileCenter = tileKey.GetGlobalRect().Center(); m2::PointF symbolSize(0.0f, 0.0f); + dp::TextureManager::SymbolRegion symbolRegion; auto const symbolName = GetSymbolNameForZoomLevel(make_ref(renderInfo.m_symbolNames), tileKey); if (!symbolName.empty()) { - dp::TextureManager::SymbolRegion region; - textures->GetSymbolRegion(symbolName, region); - symbolSize = region.GetPixelSize(); + textures->GetSymbolRegion(symbolName, symbolRegion); + symbolSize = symbolRegion.GetPixelSize(); } m2::PointF symbolOffset = m2::PointF::Zero(); @@ -421,7 +418,7 @@ void CacheUserMarks(ref_ptr context, TileKey const & tileKe batcher); } - if (renderInfo.m_symbolNames != nullptr) + if (!symbolName.empty()) { if (renderInfo.m_symbolIsPOI) { @@ -429,21 +426,18 @@ void CacheUserMarks(ref_ptr context, TileKey const & tileKe } else { - dp::TextureManager::SymbolRegion region; - dp::TextureManager::SymbolRegion backgroundRegion; - buffer.clear(); - textures->GetSymbolRegion(symbolName, region); - auto const backgroundSymbol = GetBackgroundForSymbol(symbolName, textures); - if (!backgroundSymbol.empty()) + + dp::TextureManager::SymbolRegion backgroundRegion; + if (auto const background = GetBackgroundSymbolName(symbolName); !background.empty()) { - textures->GetSymbolRegion(backgroundSymbol, backgroundRegion); - CHECK_EQUAL(region.GetTextureIndex(), backgroundRegion.GetTextureIndex(), ()); + if (textures->GetSymbolRegionSafe(background, backgroundRegion)) + CHECK_EQUAL(symbolRegion.GetTextureIndex(), backgroundRegion.GetTextureIndex(), ()); } - m2::RectF const & texRect = region.GetTexRect(); + m2::RectF const & texRect = symbolRegion.GetTexRect(); m2::RectF const & bgTexRect = backgroundRegion.GetTexRect(); - m2::PointF const pxSize = region.GetPixelSize(); + m2::PointF const pxSize = symbolRegion.GetPixelSize(); dp::Anchor const anchor = renderInfo.m_anchor; m2::PointD const pt = MapShape::ConvertToLocal(renderInfo.m_pivot, tileCenter, kShapeCoordScalar); @@ -509,10 +503,10 @@ void CacheUserMarks(ref_ptr context, TileKey const & tileKe } auto state = CreateRenderState(program, renderInfo.m_depthLayer); state.SetProgram3d(program3d); - state.SetColorTexture(region.GetTexture()); + state.SetColorTexture(symbolRegion.GetTexture()); state.SetTextureFilter(dp::TextureFilter::Nearest); state.SetDepthTestEnabled(renderInfo.m_depthTestEnabled); - state.SetTextureIndex(region.GetTextureIndex()); + state.SetTextureIndex(symbolRegion.GetTextureIndex()); dp::AttributeProvider attribProvider(1, static_cast(buffer.size())); attribProvider.InitStream(0, UPV::GetBinding(), make_ref(buffer.data())); -- 2.45.3 From 9ad0c1c21da51cb535c5121b4c5fbc3846c0f1e3 Mon Sep 17 00:00:00 2001 From: Viktor Govako Date: Sun, 19 Jun 2022 00:09:45 +0300 Subject: [PATCH 04/15] [drape] Added ASSERT in ref_ptr. Signed-off-by: Viktor Govako --- drape/hw_texture_ios.mm | 2 +- drape/pointers.hpp | 29 +++++++++++++---------------- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/drape/hw_texture_ios.mm b/drape/hw_texture_ios.mm index 6aa0f45b1e..128e0acfba 100644 --- a/drape/hw_texture_ios.mm +++ b/drape/hw_texture_ios.mm @@ -139,7 +139,7 @@ void HWTextureApple::Create(ref_ptr context, Params const & { TBase::Create(context, params, data); - m_allocator = m_params.m_allocator.downcast(); + m_allocator = m_params.m_allocator; m_directBuffer = m_allocator->CVCreatePixelBuffer(m_params.m_width, m_params.m_height, params.m_format); glConst layout, pixelType; diff --git a/drape/pointers.hpp b/drape/pointers.hpp index 0202d4cf05..044179c283 100644 --- a/drape/pointers.hpp +++ b/drape/pointers.hpp @@ -129,25 +129,22 @@ public: template operator ref_ptr() const { - static_assert(std::is_base_of::value || std::is_base_of::value || - std::is_void::value || std::is_void::value, ""); + TResult * res; + + if constexpr(std::is_base_of::value || std::is_void::value) + res = m_ptr; + else + { + /// @todo I'd prefer separate down_cast> function, but the codebase already relies on it. + static_assert(std::is_base_of::value); + res = static_cast(m_ptr); + ASSERT_EQUAL(dynamic_cast(m_ptr), res, ("Avoid multiple inheritance")); + } #if defined(TRACK_POINTERS) - return ref_ptr(static_cast(m_ptr), m_isOwnerUnique); + return ref_ptr(res, m_isOwnerUnique); #else - return ref_ptr(static_cast(m_ptr)); -#endif - } - - template - ref_ptr downcast() const - { - ASSERT(dynamic_cast(m_ptr) != nullptr, ()); - -#if defined(TRACK_POINTERS) - return ref_ptr(static_cast(m_ptr), m_isOwnerUnique); -#else - return ref_ptr(static_cast(m_ptr)); + return ref_ptr(res); #endif } -- 2.45.3 From 43e86ea799d04fc4eefa4a830657d9e3ed8a443c Mon Sep 17 00:00:00 2001 From: Viktor Govako Date: Tue, 21 Jun 2022 15:17:59 +0300 Subject: [PATCH 05/15] [android] Fixed JNI functions declarations. Signed-off-by: Viktor Govako --- android/jni/com/mapswithme/maps/Framework.cpp | 19 +++++++++---------- .../src/com/mapswithme/maps/Framework.java | 2 +- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/android/jni/com/mapswithme/maps/Framework.cpp b/android/jni/com/mapswithme/maps/Framework.cpp index 68b1be6883..fa612abe0c 100644 --- a/android/jni/com/mapswithme/maps/Framework.cpp +++ b/android/jni/com/mapswithme/maps/Framework.cpp @@ -920,7 +920,7 @@ Java_com_mapswithme_maps_Framework_nativeGetDistanceAndAzimuthFromLatLon( return Java_com_mapswithme_maps_Framework_nativeGetDistanceAndAzimuth(env, clazz, merX, merY, cLat, cLon, north); } -JNIEXPORT jobject JNICALL +JNIEXPORT jstring JNICALL Java_com_mapswithme_maps_Framework_nativeFormatLatLon(JNIEnv * env, jclass, jdouble lat, jdouble lon, int coordsFormat) { switch (static_cast(coordsFormat)) @@ -937,15 +937,14 @@ Java_com_mapswithme_maps_Framework_nativeFormatLatLon(JNIEnv * env, jclass, jdou } } -JNIEXPORT jobject JNICALL +JNIEXPORT jstring JNICALL Java_com_mapswithme_maps_Framework_nativeFormatAltitude(JNIEnv * env, jclass, jdouble alt) { auto const localizedUnits = platform::GetLocalizedAltitudeUnits(); - return jni::ToJavaString(env, measurement_utils::FormatAltitudeWithLocalization(alt, - localizedUnits.m_low)); + return jni::ToJavaString(env, measurement_utils::FormatAltitudeWithLocalization(alt, localizedUnits.m_low)); } -JNIEXPORT jobject JNICALL +JNIEXPORT jstring JNICALL Java_com_mapswithme_maps_Framework_nativeFormatSpeed(JNIEnv * env, jclass, jdouble speed) { return jni::ToJavaString(env, measurement_utils::FormatSpeed(speed)); @@ -1347,7 +1346,7 @@ Java_com_mapswithme_maps_Framework_nativeSetMapStyle(JNIEnv * env, jclass, jint } JNIEXPORT jint JNICALL -Java_com_mapswithme_maps_Framework_nativeGetMapStyle(JNIEnv * env, jclass, jint mapStyle) +Java_com_mapswithme_maps_Framework_nativeGetMapStyle(JNIEnv * env, jclass) { return g_framework->GetMapStyle(); } @@ -1706,25 +1705,25 @@ Java_com_mapswithme_maps_Framework_nativeInvalidRoutePointsTransactionId(JNIEnv } JNIEXPORT jboolean JNICALL -Java_com_mapswithme_maps_Framework_nativeHasSavedRoutePoints() +Java_com_mapswithme_maps_Framework_nativeHasSavedRoutePoints(JNIEnv *, jclass) { return frm()->GetRoutingManager().HasSavedRoutePoints(); } JNIEXPORT void JNICALL -Java_com_mapswithme_maps_Framework_nativeLoadRoutePoints() +Java_com_mapswithme_maps_Framework_nativeLoadRoutePoints(JNIEnv *, jclass) { frm()->GetRoutingManager().LoadRoutePoints(g_loadRouteHandler); } JNIEXPORT void JNICALL -Java_com_mapswithme_maps_Framework_nativeSaveRoutePoints() +Java_com_mapswithme_maps_Framework_nativeSaveRoutePoints(JNIEnv *, jclass) { frm()->GetRoutingManager().SaveRoutePoints(); } JNIEXPORT void JNICALL -Java_com_mapswithme_maps_Framework_nativeDeleteSavedRoutePoints() +Java_com_mapswithme_maps_Framework_nativeDeleteSavedRoutePoints(JNIEnv *, jclass) { frm()->GetRoutingManager().DeleteSavedRoutePoints(); } diff --git a/android/src/com/mapswithme/maps/Framework.java b/android/src/com/mapswithme/maps/Framework.java index 2a21d5dd4a..f00981970b 100644 --- a/android/src/com/mapswithme/maps/Framework.java +++ b/android/src/com/mapswithme/maps/Framework.java @@ -156,7 +156,7 @@ public class Framework public static native int nativeGetDrawScale(); - public static native int nativePokeSearchInViewport(); + public static native void nativePokeSearchInViewport(); @Size(2) public static native double[] nativeGetScreenRectCenter(); -- 2.45.3 From 529aa39f05b8d415f57d25c256cd32a88e2cc58f Mon Sep 17 00:00:00 2001 From: Viktor Govako Date: Sun, 28 Aug 2022 10:19:03 +0300 Subject: [PATCH 06/15] Accept strings by value instead of explicit copy. Signed-off-by: Viktor Govako --- base/base_tests/string_utils_test.cpp | 36 +++++++------------ base/file_name_utils.cpp | 21 +++++------ base/file_name_utils.hpp | 4 +-- base/string_utils.cpp | 21 +++++------ base/string_utils.hpp | 6 ++-- coding/zip_creator.cpp | 3 +- .../world_roads_builder_tool.cpp | 5 +-- map/benchmark_tool/api.hpp | 2 +- map/benchmark_tool/features_loading.cpp | 8 ++--- map/bookmark_helpers.cpp | 28 +++++---------- map/bookmark_helpers.hpp | 4 +-- map/bookmark_manager.cpp | 7 ++-- .../routing_quality_tool/utils.cpp | 7 +--- .../gtfs_converter/gtfs_converter.cpp | 6 ++-- 14 files changed, 60 insertions(+), 98 deletions(-) diff --git a/base/base_tests/string_utils_test.cpp b/base/base_tests/string_utils_test.cpp index 2cd881b0e5..ddc05fbcc1 100644 --- a/base/base_tests/string_utils_test.cpp +++ b/base/base_tests/string_utils_test.cpp @@ -118,33 +118,23 @@ UNIT_TEST(LowerUniChar) UNIT_TEST(MakeLowerCase) { - std::string s; + using namespace strings; - s = "THIS_IS_UPPER"; - strings::MakeLowerCaseInplace(s); - TEST_EQUAL(s, "this_is_upper", ()); + TEST_EQUAL(MakeLowerCase("THIS_IS_UPPER"), "this_is_upper", ()); + TEST_EQUAL(MakeLowerCase("THIS_iS_MiXed"), "this_is_mixed", ()); + TEST_EQUAL(MakeLowerCase("this_is_lower"), "this_is_lower", ()); - s = "THIS_iS_MiXed"; - strings::MakeLowerCaseInplace(s); - TEST_EQUAL(s, "this_is_mixed", ()); + TEST_EQUAL(MakeLowerCase("Hola! 99-\xD0\xA3\xD0\x9F\xD0\xAF\xD0\xA7\xD0\x9A\xD0\x90"), + "hola! 99-\xD1\x83\xD0\xBF\xD1\x8F\xD1\x87\xD0\xBA\xD0\xB0", ()); - s = "this_is_lower"; - strings::MakeLowerCaseInplace(s); - TEST_EQUAL(s, "this_is_lower", ()); + // es-cet + TEST_EQUAL(MakeLowerCase("\xc3\x9f"), "ss", ()); - std::string const utf8("Hola! 99-\xD0\xA3\xD0\x9F\xD0\xAF\xD0\xA7\xD0\x9A\xD0\x90"); - TEST_EQUAL(strings::MakeLowerCase(utf8), - "hola! 99-\xD1\x83\xD0\xBF\xD1\x8F\xD1\x87\xD0\xBA\xD0\xB0", ()); - - s = "\xc3\x9f"; // es-cet - strings::MakeLowerCaseInplace(s); - TEST_EQUAL(s, "ss", ()); - - strings::UniChar const arr[] = {0x397, 0x10B4, 'Z'}; - strings::UniChar const carr[] = {0x3b7, 0x2d14, 'z'}; - strings::UniString const us(&arr[0], &arr[0] + ARRAY_SIZE(arr)); - strings::UniString const cus(&carr[0], &carr[0] + ARRAY_SIZE(carr)); - TEST_EQUAL(cus, strings::MakeLowerCase(us), ()); + UniChar const arr[] = {0x397, 0x10B4, 'Z'}; + UniChar const carr[] = {0x3b7, 0x2d14, 'z'}; + UniString const us(&arr[0], &arr[0] + ARRAY_SIZE(arr)); + UniString const cus(&carr[0], &carr[0] + ARRAY_SIZE(carr)); + TEST_EQUAL(cus, MakeLowerCase(us), ()); } UNIT_TEST(EqualNoCase) diff --git a/base/file_name_utils.cpp b/base/file_name_utils.cpp index ba1cba5e20..fe5fd85c2a 100644 --- a/base/file_name_utils.cpp +++ b/base/file_name_utils.cpp @@ -1,11 +1,10 @@ #include "base/file_name_utils.hpp" -#include "std/target_os.hpp" - -using namespace std; namespace base { +using namespace std; + void GetNameWithoutExt(string & name) { string::size_type const i = name.rfind('.'); @@ -32,19 +31,17 @@ void GetNameFromFullPath(string & name) name = name.substr(i+1); } -std::string GetNameFromFullPath(std::string const & path) +std::string FileNameFromFullPath(std::string path) { - std::string name = path; - GetNameFromFullPath(name); - return name; + GetNameFromFullPath(path); + return path; } -string GetNameFromFullPathWithoutExt(string const & path) +string GetNameFromFullPathWithoutExt(string path) { - string name = path; - GetNameFromFullPath(name); - GetNameWithoutExt(name); - return name; + GetNameFromFullPath(path); + GetNameWithoutExt(path); + return path; } string GetDirectory(string const & name) diff --git a/base/file_name_utils.hpp b/base/file_name_utils.hpp index 6fdc576eca..26a6e9a8df 100644 --- a/base/file_name_utils.hpp +++ b/base/file_name_utils.hpp @@ -17,10 +17,10 @@ std::string GetFileExtension(std::string const & name); /// Get file name from full path. void GetNameFromFullPath(std::string & name); -std::string GetNameFromFullPath(std::string const & path); +std::string FileNameFromFullPath(std::string path); /// Get file name from full path without extension. -std::string GetNameFromFullPathWithoutExt(std::string const & path); +std::string GetNameFromFullPathWithoutExt(std::string path); /// Returns all but last components of the path. After dropping the last /// component, all trailing slashes are removed, unless the result is a diff --git a/base/string_utils.cpp b/base/string_utils.cpp index 325574c3a2..049f0d164a 100644 --- a/base/string_utils.cpp +++ b/base/string_utils.cpp @@ -118,11 +118,10 @@ bool is_finite(double d) return IsFinite(d); } -UniString MakeLowerCase(UniString const & s) +UniString MakeLowerCase(UniString s) { - UniString result(s); - MakeLowerCaseInplace(result); - return result; + MakeLowerCaseInplace(s); + return s; } void MakeLowerCaseInplace(std::string & s) @@ -134,18 +133,16 @@ void MakeLowerCaseInplace(std::string & s) utf8::unchecked::utf32to8(uniStr.begin(), uniStr.end(), back_inserter(s)); } -std::string MakeLowerCase(std::string const & s) +std::string MakeLowerCase(std::string s) { - std::string result(s); - MakeLowerCaseInplace(result); - return result; + MakeLowerCaseInplace(s); + return s; } -UniString Normalize(UniString const & s) +UniString Normalize(UniString s) { - UniString result(s); - NormalizeInplace(result); - return result; + NormalizeInplace(s); + return s; } std::string Normalize(std::string const & s) diff --git a/base/string_utils.hpp b/base/string_utils.hpp index 866c06ea03..de785cdd3d 100644 --- a/base/string_utils.hpp +++ b/base/string_utils.hpp @@ -81,14 +81,14 @@ public: /// to rules in ftp://ftp.unicode.org/Public/UNIDATA/CaseFolding.txt /// For implementation @see base/lower_case.cpp void MakeLowerCaseInplace(UniString & s); -UniString MakeLowerCase(UniString const & s); +UniString MakeLowerCase(UniString s); /// Performs NFKD - Compatibility decomposition for Unicode according /// to rules in ftp://ftp.unicode.org/Public/UNIDATA/UnicodeData.txt /// For implementation @see base/normalize_unicode.cpp void NormalizeInplace(UniString & s); -UniString Normalize(UniString const & s); +UniString Normalize(UniString s); std::string Normalize(std::string const & s); /// Replaces "full width" unicode digits with ascii ones. @@ -120,7 +120,7 @@ bool ReplaceFirst(std::string & str, std::string const & from, std::string const bool ReplaceLast(std::string & str, std::string const & from, std::string const & to); void MakeLowerCaseInplace(std::string & s); -std::string MakeLowerCase(std::string const & s); +std::string MakeLowerCase(std::string s); bool EqualNoCase(std::string const & s1, std::string const & s2); UniString MakeUniString(std::string_view utf8s); diff --git a/coding/zip_creator.cpp b/coding/zip_creator.cpp index 5c19b67823..077082ac6e 100644 --- a/coding/zip_creator.cpp +++ b/coding/zip_creator.cpp @@ -80,8 +80,7 @@ bool CreateZipFromPathDeflatedAndDefaultCompression(std::string const & filePath zip::FileInfo zipInfo = {}; CreateTMZip(zipInfo.tmz_date); - std::string fileName = filePath; - base::GetNameFromFullPath(fileName); + std::string fileName = base::FileNameFromFullPath(filePath); if (!strings::IsASCIIString(fileName)) fileName = "OrganicMaps.kml"; diff --git a/generator/world_roads_builder/world_roads_builder_tool/world_roads_builder_tool.cpp b/generator/world_roads_builder/world_roads_builder_tool/world_roads_builder_tool.cpp index 73c9184678..21e772bb1b 100644 --- a/generator/world_roads_builder/world_roads_builder_tool/world_roads_builder_tool.cpp +++ b/generator/world_roads_builder/world_roads_builder_tool/world_roads_builder_tool.cpp @@ -22,7 +22,6 @@ #include "gflags/gflags.h" -using namespace routing; DEFINE_string(path_resources, "", "OMaps resources directory"); DEFINE_string(path_roads_file, "", "OSM file in o5m format."); @@ -30,10 +29,12 @@ DEFINE_string(path_res_file, "", "Path to the resulting file with roads for gene int main(int argc, char ** argv) { + using namespace routing; + gflags::SetUsageMessage( "Reads OSM file, generates text file with main cross-mwm roads for generator_tool."); gflags::ParseCommandLineFlags(&argc, &argv, true); - auto const toolName = base::GetNameFromFullPath(argv[0]); + auto const toolName = base::FileNameFromFullPath(argv[0]); if (FLAGS_path_resources.empty() || !Platform::IsDirectory(FLAGS_path_resources) || FLAGS_path_roads_file.empty() || FLAGS_path_res_file.empty()) diff --git a/map/benchmark_tool/api.hpp b/map/benchmark_tool/api.hpp index a35763bd48..1c231cd66f 100644 --- a/map/benchmark_tool/api.hpp +++ b/map/benchmark_tool/api.hpp @@ -44,5 +44,5 @@ namespace bench }; /// @param[in] count number of times to run benchmark - void RunFeaturesLoadingBenchmark(std::string const & file, std::pair scaleR, AllResult & res); + void RunFeaturesLoadingBenchmark(std::string filePath, std::pair scaleR, AllResult & res); } // namespace bench diff --git a/map/benchmark_tool/features_loading.cpp b/map/benchmark_tool/features_loading.cpp index 795675af9d..11f4ebfe53 100644 --- a/map/benchmark_tool/features_loading.cpp +++ b/map/benchmark_tool/features_loading.cpp @@ -99,17 +99,13 @@ namespace } } -void RunFeaturesLoadingBenchmark(string const & file, pair scaleRange, AllResult & res) +void RunFeaturesLoadingBenchmark(string fileName, pair scaleRange, AllResult & res) { - string fileName = file; base::GetNameFromFullPath(fileName); base::GetNameWithoutExt(fileName); - platform::LocalCountryFile localFile = - platform::LocalCountryFile::MakeForTesting(fileName); - FeaturesFetcher src; - auto const r = src.RegisterMap(localFile); + auto const r = src.RegisterMap(platform::LocalCountryFile::MakeForTesting(std::move(fileName))); if (r.second != MwmSet::RegResult::Success) return; diff --git a/map/bookmark_helpers.cpp b/map/bookmark_helpers.cpp index 5b9a76325a..eea90c4808 100644 --- a/map/bookmark_helpers.cpp +++ b/map/bookmark_helpers.cpp @@ -210,13 +210,6 @@ std::string GetFileExt(std::string const & filePath) return strings::MakeLowerCase(base::GetFileExtension(filePath)); } -std::string GetFileName(std::string const & filePath) -{ - std::string ret = filePath; - base::GetNameFromFullPath(ret); - return ret; -} - bool IsBadCharForPath(char c) { for (char illegalChar : {':', '/', '\\', '<', '>', '\"', '|', '?', '*'}) @@ -234,17 +227,14 @@ std::string GetBookmarksDirectory() return base::JoinPath(GetPlatform().SettingsDir(), "bookmarks"); } -std::string RemoveInvalidSymbols(std::string const & name) +std::string RemoveInvalidSymbols(std::string name) { // Remove not allowed symbols. - std::string res; - res.reserve(name.size()); - for (auto c : name) + name.erase(std::remove_if(name.begin(), name.end(), [](char c) { - if (!IsBadCharForPath(c)) - res.push_back(c); - } - return res; + return IsBadCharForPath(c); + }), name.end()); + return name; } std::string GenerateUniqueFileName(const std::string & path, std::string name, std::string const & ext) @@ -260,9 +250,9 @@ std::string GenerateUniqueFileName(const std::string & path, std::string name, s return base::JoinPath(path, name + suffix + ext); } -std::string GenerateValidAndUniqueFilePathForKML(std::string const & fileName) +std::string GenerateValidAndUniqueFilePathForKML(std::string fileName) { - std::string filePath = RemoveInvalidSymbols(fileName); + std::string filePath = RemoveInvalidSymbols(std::move(fileName)); if (filePath.empty()) filePath = kDefaultBookmarksFileName; @@ -297,7 +287,7 @@ std::string GetKMLPath(std::string const & filePath) std::string fileSavePath; if (fileExt == kKmlExtension) { - fileSavePath = GenerateValidAndUniqueFilePathForKML(GetFileName(filePath)); + fileSavePath = GenerateValidAndUniqueFilePathForKML(base::FileNameFromFullPath(filePath)); if (!base::CopyFileX(filePath, fileSavePath)) return {}; } @@ -307,7 +297,7 @@ std::string GetKMLPath(std::string const & filePath) if (kmlData == nullptr) return {}; - fileSavePath = GenerateValidAndUniqueFilePathForKML(GetFileName(filePath)); + fileSavePath = GenerateValidAndUniqueFilePathForKML(base::FileNameFromFullPath(filePath)); if (!SaveKmlFileByExt(*kmlData, fileSavePath)) return {}; } diff --git a/map/bookmark_helpers.hpp b/map/bookmark_helpers.hpp index f79a4818b9..c0b3c014e2 100644 --- a/map/bookmark_helpers.hpp +++ b/map/bookmark_helpers.hpp @@ -89,9 +89,9 @@ inline std::string DebugPrint(KmlFileType fileType) /// @name File name/path helpers. /// @{ std::string GetBookmarksDirectory(); -std::string RemoveInvalidSymbols(std::string const & name); +std::string RemoveInvalidSymbols(std::string name); std::string GenerateUniqueFileName(const std::string & path, std::string name, std::string const & ext = kKmlExtension); -std::string GenerateValidAndUniqueFilePathForKML(std::string const & fileName); +std::string GenerateValidAndUniqueFilePathForKML(std::string fileName); /// @} /// @name SerDes helpers. diff --git a/map/bookmark_manager.cpp b/map/bookmark_manager.cpp index 17312a7b9e..fd479e8dd6 100644 --- a/map/bookmark_manager.cpp +++ b/map/bookmark_manager.cpp @@ -79,8 +79,7 @@ public: BookmarkManager::SharingResult GetFileForSharing(BookmarkManager::KMLDataCollectionPtr collection) { auto const & kmlToShare = collection->front(); - auto const categoryName = kml::GetDefaultStr(kmlToShare.second->m_categoryData.m_name); - std::string fileName = RemoveInvalidSymbols(categoryName); + std::string fileName = RemoveInvalidSymbols(kml::GetDefaultStr(kmlToShare.second->m_categoryData.m_name)); if (fileName.empty()) fileName = base::GetNameFromFullPathWithoutExt(kmlToShare.first); @@ -1925,10 +1924,8 @@ void BookmarkManager::LoadBookmarkRoutine(std::string const & filePath, bool isT if (kmlData) { - std::string const fileName = base::GetNameFromFullPathWithoutExt(fileSavePath); - base::DeleteFileX(fileSavePath); - fileSavePath = GenerateValidAndUniqueFilePathForKML(fileName); + fileSavePath = GenerateValidAndUniqueFilePathForKML(base::GetNameFromFullPathWithoutExt(std::move(fileSavePath))); if (!SaveKmlFileSafe(*kmlData, fileSavePath, KmlFileType::Text)) base::DeleteFileX(fileSavePath); diff --git a/routing/routing_quality/routing_quality_tool/utils.cpp b/routing/routing_quality/routing_quality_tool/utils.cpp index 43014d3740..d676535062 100644 --- a/routing/routing_quality/routing_quality_tool/utils.cpp +++ b/routing/routing_quality/routing_quality_tool/utils.cpp @@ -1,12 +1,8 @@ #include "routing/routing_quality/routing_quality_tool/utils.hpp" -#include "routing/vehicle_mask.hpp" - #include "kml/serdes.hpp" #include "kml/types.hpp" -#include "coding/string_utf8_multilang.hpp" - #include "geometry/point_with_altitude.hpp" #include "base/assert.hpp" @@ -515,16 +511,15 @@ void SimilarityCounter::CreateKmlFiles(double percent, std::vector const CHECK_LESS(realResultIndex, results.size(), ()); auto const mapsmeResult = RoutesBuilder::Result::Load(results[realResultIndex].m_mapsmeDumpPath); + std::string const kmlFile = base::JoinPath(savePath, std::to_string(i) + ".kml"); if (m_routesSaver.GetComparsionType() == ComparisonType::MapsmeVsApi) { auto const apiResult = api::Response::Load(results[realResultIndex].m_anotherDumpPath); - std::string const kmlFile = base::JoinPath(savePath, std::to_string(i) + ".kml"); SaveKmlFileDataTo(mapsmeResult, apiResult, kmlFile); } else { auto const mapsmeAnotherResult = RoutesBuilder::Result::Load(results[realResultIndex].m_anotherDumpPath); - std::string const kmlFile = base::JoinPath(savePath, std::to_string(i) + ".kml"); SaveKmlFileDataTo(mapsmeResult, mapsmeAnotherResult, kmlFile); } diff --git a/transit/world_feed/gtfs_converter/gtfs_converter.cpp b/transit/world_feed/gtfs_converter/gtfs_converter.cpp index 55efcf55d7..49da98a930 100644 --- a/transit/world_feed/gtfs_converter/gtfs_converter.cpp +++ b/transit/world_feed/gtfs_converter/gtfs_converter.cpp @@ -75,7 +75,7 @@ bool SkipFeed(std::string const & feedPath, bool & pass) { if (!FLAGS_start_feed.empty() && pass) { - if (base::GetNameFromFullPath(feedPath) != FLAGS_start_feed) + if (base::FileNameFromFullPath(feedPath) != FLAGS_start_feed) return true; pass = false; } @@ -84,7 +84,7 @@ bool SkipFeed(std::string const & feedPath, bool & pass) bool StopOnFeed(std::string const & feedPath) { - if (!FLAGS_stop_feed.empty() && base::GetNameFromFullPath(feedPath) == FLAGS_stop_feed) + if (!FLAGS_stop_feed.empty() && base::FileNameFromFullPath(feedPath) == FLAGS_stop_feed) { LOG(LINFO, ("Stop on", feedPath)); return true; @@ -271,7 +271,7 @@ int main(int argc, char ** argv) { gflags::SetUsageMessage("Reads GTFS feeds or subway transit.json, produces json with global ids for generator."); gflags::ParseCommandLineFlags(&argc, &argv, true); - auto const toolName = base::GetNameFromFullPath(argv[0]); + auto const toolName = base::FileNameFromFullPath(argv[0]); if (FLAGS_path_gtfs_feeds.empty() && FLAGS_path_subway_json.empty()) { -- 2.45.3 From 2b5f122033bab92b9b0dada218fb3bd5088d24c8 Mon Sep 17 00:00:00 2001 From: Evgeny Fayvuzhinsky Date: Tue, 23 Aug 2022 16:18:38 +0300 Subject: [PATCH 07/15] [ios] Change UI font from Helvetica to system All storyboards and xibs with Helvetica were edited. Font styles (medium, italic) and sizes are preserved. Closes #3216 Signed-off-by: Evgeny Fayvuzhinsky --- data/faq.html | 2 +- .../MWMBCCreateCategoryAlert.xib | 6 +++--- .../CustomAlert/DefaultAlert/MWMDefaultAlert.xib | 8 ++++---- .../MWMDownloadTransitMapAlert.xib | 8 ++++---- .../MWMDownloaderDialogCell.xib | 2 +- .../MWMDownloaderDialogHeader.xib | 4 ++-- .../CustomAlert/LocationAlert/MWMLocationAlert.xib | 14 +++++++------- .../Classes/CustomAlert/MWMEditorViralAlert.xib | 8 ++++---- .../Maps/Classes/CustomAlert/MWMOsmAuthAlert.xib | 4 ++-- .../CustomAlert/MWMPlaceDoesntExistAlert.xib | 8 ++++---- .../MobileInternetAlert/MWMMobileInternetAlert.xib | 10 +++++----- .../MWMRoutingDisclaimerAlert.xib | 6 +++--- .../CustomAlert/SpinnerAlert/MWMSpinnerAlert.xib | 4 ++-- .../Views/RoutePreview/MWMiPadRoutePreview.xib | 6 +++--- .../Views/RoutePreview/MWMiPhoneRoutePreview.xib | 4 ++-- .../Maps/Classes/Widgets/MWMMapDownloadDialog.xib | 6 +++--- .../Maps/UI/Autoupdate/MWMAutoupdateController.xib | 8 ++++---- .../BottomMenu/Menu/Cells/BottomMenuItemCell.xib | 4 ++-- .../MWMMapDownloaderLargeCountryTableViewCell.xib | 6 +++--- .../Cells/MWMMapDownloaderPlaceTableViewCell.xib | 6 +++--- .../MWMMapDownloaderSubplaceTableViewCell.xib | 8 ++++---- .../Cells/MWMMapDownloaderTableViewCell.xib | 4 ++-- .../Downloader/DownloadAllView/DownloadAllView.xib | 4 ++-- .../Cells/MWMEditorAdditionalNameTableViewCell.xib | 2 +- .../UI/Editor/Cells/MWMEditorTextTableViewCell.xib | 2 +- .../MWMOpeningHoursAddScheduleTableViewCell.xib | 2 +- .../Cells/MWMOpeningHoursAllDayTableViewCell.xib | 2 +- .../MWMOpeningHoursClosedSpanTableViewCell.xib | 4 ++-- .../MWMOpeningHoursDaysSelectorTableViewCell.xib | 14 +++++++------- .../MWMOpeningHoursDeleteScheduleTableViewCell.xib | 2 +- .../Cells/MWMOpeningHoursTimeSpanTableViewCell.xib | 4 ++-- .../Street/MWMStreetEditorEditTableViewCell.xib | 2 +- .../PlacePageDescriptionViewController.swift | 2 +- .../MWMPlacePageOpeningHoursCell.xib | 10 +++++----- .../MWMPlacePageOpeningHoursWeekDayView.xib | 6 +++--- iphone/Maps/UI/Search/MWMSearchView.xib | 4 ++-- .../UI/Search/TableView/MWMSearchCommonCell.xib | 10 +++++----- .../Search/TableView/MWMSearchSuggestionCell.xib | 2 +- .../Tabs/CategoriesTab/SearchCategoryCell.xib | 2 +- .../Tabs/HistoryTab/SearchHistoryClearCell.xib | 2 +- .../Tabs/HistoryTab/SearchHistoryQueryCell.xib | 2 +- iphone/Maps/UI/Storyboard/Authorization.storyboard | 12 ++++++------ iphone/Maps/UI/Storyboard/Main.storyboard | 10 +++++----- iphone/Maps/UI/Storyboard/Welcome.storyboard | 4 ++-- 44 files changed, 120 insertions(+), 120 deletions(-) diff --git a/data/faq.html b/data/faq.html index c422c55468..ed1385a5bb 100644 --- a/data/faq.html +++ b/data/faq.html @@ -63,7 +63,7 @@ margin-left: 16px; margin-bottom: 16px; font-size: 16px; - font-family: "Helvetica Neue", "Roboto", "Arial", "sans-serif"; + font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", Helvetica, Arial, sans-serif, "Apple Color Emoji"; } html { diff --git a/iphone/Maps/Classes/CustomAlert/CreateBookmarkCategory/MWMBCCreateCategoryAlert.xib b/iphone/Maps/Classes/CustomAlert/CreateBookmarkCategory/MWMBCCreateCategoryAlert.xib index 77d382e3aa..046bc04863 100644 --- a/iphone/Maps/Classes/CustomAlert/CreateBookmarkCategory/MWMBCCreateCategoryAlert.xib +++ b/iphone/Maps/Classes/CustomAlert/CreateBookmarkCategory/MWMBCCreateCategoryAlert.xib @@ -23,7 +23,7 @@ - + @@ -81,7 +81,7 @@ - + @@ -101,7 +101,7 @@ - + diff --git a/iphone/Maps/Classes/CustomAlert/DefaultAlert/MWMDefaultAlert.xib b/iphone/Maps/Classes/CustomAlert/DefaultAlert/MWMDefaultAlert.xib index aa5606a90a..f0a36b4aeb 100644 --- a/iphone/Maps/Classes/CustomAlert/DefaultAlert/MWMDefaultAlert.xib +++ b/iphone/Maps/Classes/CustomAlert/DefaultAlert/MWMDefaultAlert.xib @@ -23,7 +23,7 @@ - + @@ -36,7 +36,7 @@ - + @@ -60,7 +60,7 @@ - + @@ -92,7 +92,7 @@ - + diff --git a/iphone/Maps/Classes/CustomAlert/DownloadTransitMapsAlert/MWMDownloadTransitMapAlert.xib b/iphone/Maps/Classes/CustomAlert/DownloadTransitMapsAlert/MWMDownloadTransitMapAlert.xib index 82adef76eb..c17f5a11ef 100644 --- a/iphone/Maps/Classes/CustomAlert/DownloadTransitMapsAlert/MWMDownloadTransitMapAlert.xib +++ b/iphone/Maps/Classes/CustomAlert/DownloadTransitMapsAlert/MWMDownloadTransitMapAlert.xib @@ -23,7 +23,7 @@ - + @@ -46,7 +46,7 @@ - + @@ -86,7 +86,7 @@ - + @@ -107,7 +107,7 @@ - + diff --git a/iphone/Maps/Classes/CustomAlert/DownloadTransitMapsAlert/MWMDownloaderDialogCell.xib b/iphone/Maps/Classes/CustomAlert/DownloadTransitMapsAlert/MWMDownloaderDialogCell.xib index 68f535c19c..44e62bf962 100644 --- a/iphone/Maps/Classes/CustomAlert/DownloadTransitMapsAlert/MWMDownloaderDialogCell.xib +++ b/iphone/Maps/Classes/CustomAlert/DownloadTransitMapsAlert/MWMDownloaderDialogCell.xib @@ -22,7 +22,7 @@ - + diff --git a/iphone/Maps/Classes/CustomAlert/DownloadTransitMapsAlert/MWMDownloaderDialogHeader.xib b/iphone/Maps/Classes/CustomAlert/DownloadTransitMapsAlert/MWMDownloaderDialogHeader.xib index 53f8c167b4..fbd5b34851 100644 --- a/iphone/Maps/Classes/CustomAlert/DownloadTransitMapsAlert/MWMDownloaderDialogHeader.xib +++ b/iphone/Maps/Classes/CustomAlert/DownloadTransitMapsAlert/MWMDownloaderDialogHeader.xib @@ -20,7 +20,7 @@ - + @@ -53,7 +53,7 @@ - + diff --git a/iphone/Maps/Classes/CustomAlert/LocationAlert/MWMLocationAlert.xib b/iphone/Maps/Classes/CustomAlert/LocationAlert/MWMLocationAlert.xib index 3db6731c4d..3ec06d7de6 100644 --- a/iphone/Maps/Classes/CustomAlert/LocationAlert/MWMLocationAlert.xib +++ b/iphone/Maps/Classes/CustomAlert/LocationAlert/MWMLocationAlert.xib @@ -23,7 +23,7 @@ - + @@ -37,7 +37,7 @@ - + @@ -61,7 +61,7 @@ - + @@ -81,7 +81,7 @@ - + @@ -133,7 +133,7 @@ - + @@ -147,7 +147,7 @@ - + @@ -161,7 +161,7 @@ - + diff --git a/iphone/Maps/Classes/CustomAlert/MWMEditorViralAlert.xib b/iphone/Maps/Classes/CustomAlert/MWMEditorViralAlert.xib index ce89f83c19..2380e83abe 100644 --- a/iphone/Maps/Classes/CustomAlert/MWMEditorViralAlert.xib +++ b/iphone/Maps/Classes/CustomAlert/MWMEditorViralAlert.xib @@ -23,7 +23,7 @@ - + @@ -44,7 +44,7 @@ - + @@ -67,7 +67,7 @@ - + @@ -98,7 +98,7 @@ - + diff --git a/iphone/Maps/Classes/CustomAlert/MWMOsmAuthAlert.xib b/iphone/Maps/Classes/CustomAlert/MWMOsmAuthAlert.xib index cc5d74756f..124ff8b88f 100644 --- a/iphone/Maps/Classes/CustomAlert/MWMOsmAuthAlert.xib +++ b/iphone/Maps/Classes/CustomAlert/MWMOsmAuthAlert.xib @@ -22,7 +22,7 @@ - + @@ -42,7 +42,7 @@ Войдите, чтобы ваши изменения увидели другие пользователи - + diff --git a/iphone/Maps/Classes/CustomAlert/MWMPlaceDoesntExistAlert.xib b/iphone/Maps/Classes/CustomAlert/MWMPlaceDoesntExistAlert.xib index 936ed04744..386329dee0 100644 --- a/iphone/Maps/Classes/CustomAlert/MWMPlaceDoesntExistAlert.xib +++ b/iphone/Maps/Classes/CustomAlert/MWMPlaceDoesntExistAlert.xib @@ -23,7 +23,7 @@ - + @@ -37,7 +37,7 @@ - + @@ -92,7 +92,7 @@ - + @@ -112,7 +112,7 @@ - + diff --git a/iphone/Maps/Classes/CustomAlert/MobileInternetAlert/MWMMobileInternetAlert.xib b/iphone/Maps/Classes/CustomAlert/MobileInternetAlert/MWMMobileInternetAlert.xib index 02e34b8cfe..b2f74f9e50 100644 --- a/iphone/Maps/Classes/CustomAlert/MobileInternetAlert/MWMMobileInternetAlert.xib +++ b/iphone/Maps/Classes/CustomAlert/MobileInternetAlert/MWMMobileInternetAlert.xib @@ -23,7 +23,7 @@ - + @@ -37,7 +37,7 @@ - + @@ -50,7 +50,7 @@ - + @@ -66,7 +66,7 @@