Added transliteration enabling setting.

This commit is contained in:
Daria Volvenkova 2017-05-25 16:54:36 +03:00
parent fb242784ab
commit 72232bbe53
4 changed files with 44 additions and 2 deletions

View file

@ -12,7 +12,6 @@
#include "std/unique_ptr.hpp"
#include <atomic>
#include <cstring>
#include <mutex>
@ -27,6 +26,10 @@ struct Transliteration::TransliteratorInfo
std::unique_ptr<Transliterator> m_transliterator;
};
Transliteration::Transliteration()
: m_enabled(true)
{}
Transliteration::~Transliteration()
{
// The use of u_cleanup() just before an application terminates is optional,
@ -59,8 +62,16 @@ void Transliteration::Init(std::string const & icuDataDir)
}
}
void Transliteration::SetEnabled(bool enable)
{
m_enabled = enable;
}
bool Transliteration::Transliterate(std::string const & str, int8_t langCode, std::string & out) const
{
if (!m_enabled)
return false;
if (str.empty() || strings::IsASCIIString(str))
return false;

View file

@ -1,5 +1,6 @@
#pragma once
#include <atomic>
#include <map>
#include <memory>
#include <string>
@ -13,10 +14,13 @@ public:
void Init(std::string const & icuDataDir);
void SetEnabled(bool enable);
bool Transliterate(std::string const & str, int8_t langCode, std::string & out) const;
private:
Transliteration() = default;
Transliteration();
std::atomic<bool> m_enabled;
struct TransliteratorInfo;
std::map<std::string, std::unique_ptr<TransliteratorInfo>> m_transliterators;

View file

@ -134,6 +134,7 @@ char const kAllowAutoZoom[] = "AutoZoom";
char const kTrafficEnabledKey[] = "TrafficEnabled";
char const kTrafficSimplifiedColorsKey[] = "TrafficSimplifiedColors";
char const kLargeFontsSize[] = "LargeFontsSize";
char const kAllowTranslit[] = "Transliteration";
#if defined(OMIM_OS_ANDROID)
char const kICUDataFile[] = "icudt57l.dat";
@ -1485,6 +1486,9 @@ void Framework::InitTransliteration()
#else
Transliteration::Instance().Init(GetPlatform().ResourcesDir());
#endif
if (!LoadTransliteration())
Transliteration::Instance().SetEnabled(false /* enable */);
}
storage::TCountryId Framework::GetCountryIndex(m2::PointD const & pt) const
@ -2911,6 +2915,25 @@ void Framework::SetRouteFinishPoint(m2::PointD const & pt, bool isValid)
m_drapeEngine->SetRoutePoint(pt, false /* isStart */, isValid);
}
void Framework::AllowTransliteration(bool allowTranslit)
{
Transliteration::Instance().SetEnabled(allowTranslit);
InvalidateRect(GetCurrentViewport());
}
bool Framework::LoadTransliteration()
{
bool isTranslitAllowed;
if (!settings::Get(kLargeFontsSize, isTranslitAllowed))
isTranslitAllowed = true;
return isTranslitAllowed;
}
void Framework::SaveTransliteration(bool allowTranslit)
{
settings::Set(kAllowTranslit, allowTranslit);
}
void Framework::Allow3dMode(bool allow3d, bool allow3dBuildings)
{
CallDrapeFunction(bind(&df::DrapeEngine::Allow3dMode, _1, allow3d, allow3dBuildings));

View file

@ -814,6 +814,10 @@ public:
void SetRouteStartPoint(m2::PointD const & pt, bool isValid);
void SetRouteFinishPoint(m2::PointD const & pt, bool isValid);
void AllowTransliteration(bool allowTranslit);
bool LoadTransliteration();
void SaveTransliteration(bool allowTranslit);
void Allow3dMode(bool allow3d, bool allow3dBuildings);
void Save3dMode(bool allow3d, bool allow3dBuildings);
void Load3dMode(bool & allow3d, bool & allow3dBuildings);