forked from organicmaps/organicmaps
Refactored wstring to UniString
This commit is contained in:
parent
6350ab1569
commit
a03961d097
13 changed files with 63 additions and 81 deletions
|
@ -160,26 +160,6 @@ inline bool to_uint64(string const & s, uint64_t & i) { return to_uint64(s.c_str
|
|||
inline bool to_int64(string const & s, int64_t & i) { return to_int64(s.c_str(), i); }
|
||||
inline bool to_double(string const & s, double & d) { return to_double(s.c_str(), d); }
|
||||
|
||||
/// @TODO Remove, it's temporary workaround until YG is not refactored
|
||||
/// @deprecated
|
||||
inline wstring FromUtf8(string const & str)
|
||||
{
|
||||
wstring result;
|
||||
utf8::unchecked::utf8to16(str.begin(), str.end(), back_inserter(result));
|
||||
return result;
|
||||
}
|
||||
|
||||
/// @TODO Remove, it's temporary workaround until YG is not refactored
|
||||
/// @deprecated
|
||||
inline wstring UniStringToUtf16(UniString const & str)
|
||||
{
|
||||
string utf8tmp;
|
||||
utf8::unchecked::utf32to8(str.begin(), str.end(), back_inserter(utf8tmp));
|
||||
wstring result;
|
||||
utf8::unchecked::utf8to16(utf8tmp.begin(), utf8tmp.end(), back_inserter(result));
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename ItT, typename DelimiterT>
|
||||
typename ItT::value_type JoinStrings(ItT begin, ItT end, DelimiterT const & delimiter)
|
||||
{
|
||||
|
|
|
@ -218,7 +218,7 @@ void InformationDisplay::drawCenter(DrawerYG * drawer)
|
|||
params.m_position = yg::EPosAboveLeft;
|
||||
params.m_rm = drawer->screen()->resourceManager().get();
|
||||
params.m_skin = drawer->screen()->skin().get();
|
||||
params.m_logText = strings::FromUtf8(out.str());
|
||||
params.m_logText = strings::MakeUniString(out.str());
|
||||
|
||||
yg::StraightTextElement ste(params);
|
||||
|
||||
|
@ -387,7 +387,7 @@ void InformationDisplay::drawLog(DrawerYG * drawer)
|
|||
params.m_position = yg::EPosAboveRight;
|
||||
params.m_rm = drawer->screen()->resourceManager().get();
|
||||
params.m_skin = drawer->screen()->skin().get();
|
||||
params.m_logText = strings::FromUtf8(*it);
|
||||
params.m_logText = strings::MakeUniString(*it);
|
||||
|
||||
yg::StraightTextElement ste(params);
|
||||
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
#include "../base/SRC_FIRST.hpp"
|
||||
|
||||
#include "glyph_cache.hpp"
|
||||
#include "glyph_cache_impl.hpp"
|
||||
#include "data_formats.hpp"
|
||||
|
@ -21,21 +19,21 @@ namespace gil = boost::gil;
|
|||
|
||||
namespace yg
|
||||
{
|
||||
GlyphKey::GlyphKey(int id, int fontSize, bool isMask, yg::Color const & color)
|
||||
: m_id(id), m_fontSize(fontSize), m_isMask(isMask), m_color(color)
|
||||
GlyphKey::GlyphKey(strings::UniChar symbolCode, int fontSize, bool isMask, yg::Color const & color)
|
||||
: m_symbolCode(symbolCode), m_fontSize(fontSize), m_isMask(isMask), m_color(color)
|
||||
{}
|
||||
|
||||
uint32_t GlyphKey::toUInt32() const
|
||||
{
|
||||
return static_cast<uint32_t>(m_id) << 16
|
||||
return static_cast<uint32_t>(m_symbolCode) << 16
|
||||
| static_cast<uint32_t>(m_fontSize) << 8
|
||||
| static_cast<uint32_t>(m_isMask);
|
||||
}
|
||||
|
||||
bool operator<(GlyphKey const & l, GlyphKey const & r)
|
||||
{
|
||||
if (l.m_id != r.m_id)
|
||||
return l.m_id < r.m_id;
|
||||
if (l.m_symbolCode != r.m_symbolCode)
|
||||
return l.m_symbolCode < r.m_symbolCode;
|
||||
if (l.m_fontSize != r.m_fontSize)
|
||||
return l.m_fontSize < r.m_fontSize;
|
||||
if (l.m_isMask != r.m_isMask)
|
||||
|
@ -63,7 +61,7 @@ namespace yg
|
|||
|
||||
pair<Font*, int> GlyphCache::getCharIDX(GlyphKey const & key)
|
||||
{
|
||||
vector<shared_ptr<Font> > & fonts = m_impl->getFonts(key.m_id);
|
||||
vector<shared_ptr<Font> > & fonts = m_impl->getFonts(key.m_symbolCode);
|
||||
|
||||
Font * font = 0;
|
||||
|
||||
|
@ -78,7 +76,7 @@ namespace yg
|
|||
m_impl->m_charMapCache,
|
||||
faceID,
|
||||
-1,
|
||||
key.m_id
|
||||
key.m_symbolCode
|
||||
);
|
||||
if (charIDX != 0)
|
||||
return make_pair(font, charIDX);
|
||||
|
@ -88,9 +86,9 @@ namespace yg
|
|||
|
||||
for (size_t i = 0; i < m_impl->m_unicodeBlocks.size(); ++i)
|
||||
{
|
||||
if (m_impl->m_unicodeBlocks[i].hasSymbol(key.m_id))
|
||||
if (m_impl->m_unicodeBlocks[i].hasSymbol(key.m_symbolCode))
|
||||
{
|
||||
LOG(LINFO, ("symbol not found, id=", key.m_id, ", unicodeBlock=", m_impl->m_unicodeBlocks[i].m_name));
|
||||
LOG(LINFO, ("Symbol", key.m_symbolCode, "not found, unicodeBlock=", m_impl->m_unicodeBlocks[i].m_name));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -240,7 +238,7 @@ namespace yg
|
|||
|
||||
double GlyphCache::getTextLength(double fontSize, string const & text)
|
||||
{
|
||||
wstring s = strings::FromUtf8(text);
|
||||
strings::UniString const s = strings::MakeUniString(text);
|
||||
double len = 0;
|
||||
for (unsigned i = 0; i < s.size(); ++i)
|
||||
{
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
#pragma once
|
||||
|
||||
#include "color.hpp"
|
||||
|
||||
#include "../base/string_utils.hpp"
|
||||
|
||||
#include "../std/shared_ptr.hpp"
|
||||
#include "../std/vector.hpp"
|
||||
#include "../std/string.hpp"
|
||||
#include "../std/utility.hpp"
|
||||
#include "color.hpp"
|
||||
|
||||
namespace yg
|
||||
{
|
||||
|
@ -29,13 +32,14 @@ namespace yg
|
|||
|
||||
struct GlyphKey
|
||||
{
|
||||
int m_id;
|
||||
strings::UniChar m_symbolCode;
|
||||
int m_fontSize;
|
||||
bool m_isMask;
|
||||
yg::Color m_color;
|
||||
/// as it's used for fixed fonts only, the color doesn't matter
|
||||
/// @TODO REMOVE IT!!! All chars are already 32bit
|
||||
uint32_t toUInt32() const;
|
||||
GlyphKey(int id, int fontSize, bool isMask, yg::Color const & color);
|
||||
GlyphKey(strings::UniChar symbolCode, int fontSize, bool isMask, yg::Color const & color);
|
||||
};
|
||||
|
||||
struct Font;
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#include "../base/SRC_FIRST.hpp"
|
||||
#include "glyph_cache_impl.hpp"
|
||||
|
||||
#include "../base/path_utils.hpp"
|
||||
|
@ -16,11 +15,11 @@
|
|||
|
||||
namespace yg
|
||||
{
|
||||
UnicodeBlock::UnicodeBlock(string const & name, uint32_t start, uint32_t end)
|
||||
UnicodeBlock::UnicodeBlock(string const & name, strings::UniChar start, strings::UniChar end)
|
||||
: m_name(name), m_start(start), m_end(end)
|
||||
{}
|
||||
|
||||
bool UnicodeBlock::hasSymbol(uint16_t sym) const
|
||||
bool UnicodeBlock::hasSymbol(strings::UniChar sym) const
|
||||
{
|
||||
return (m_start <= sym) && (m_end >= sym);
|
||||
}
|
||||
|
@ -40,8 +39,8 @@ namespace yg
|
|||
while (true)
|
||||
{
|
||||
string name;
|
||||
uint16_t start;
|
||||
uint16_t end;
|
||||
strings::UniChar start;
|
||||
strings::UniChar end;
|
||||
fin >> name >> std::hex >> start >> std::hex >> end;
|
||||
if (!fin)
|
||||
break;
|
||||
|
@ -263,11 +262,11 @@ namespace yg
|
|||
|
||||
struct sym_in_block
|
||||
{
|
||||
bool operator() (UnicodeBlock const & b, uint16_t sym) const
|
||||
bool operator() (UnicodeBlock const & b, strings::UniChar sym) const
|
||||
{
|
||||
return (b.m_start < sym);
|
||||
}
|
||||
bool operator() (uint16_t sym, UnicodeBlock const & b) const
|
||||
bool operator() (strings::UniChar sym, UnicodeBlock const & b) const
|
||||
{
|
||||
return (sym < b.m_start);
|
||||
}
|
||||
|
@ -277,7 +276,7 @@ namespace yg
|
|||
}
|
||||
};
|
||||
|
||||
vector<shared_ptr<Font> > & GlyphCacheImpl::getFonts(uint16_t sym)
|
||||
vector<shared_ptr<Font> > & GlyphCacheImpl::getFonts(strings::UniChar sym)
|
||||
{
|
||||
if ((m_lastUsedBlock != m_unicodeBlocks.end()) && m_lastUsedBlock->hasSymbol(sym))
|
||||
return m_lastUsedBlock->m_fonts;
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "ft2_debug.hpp"
|
||||
|
||||
#include "../base/memory_mapped_file.hpp"
|
||||
#include "../base/string_utils.hpp"
|
||||
|
||||
#include "../std/string.hpp"
|
||||
#include "../std/vector.hpp"
|
||||
|
@ -39,15 +40,15 @@ namespace yg
|
|||
vector<string> m_blacklist;
|
||||
/// @}
|
||||
|
||||
uint32_t m_start;
|
||||
uint32_t m_end;
|
||||
strings::UniChar m_start;
|
||||
strings::UniChar m_end;
|
||||
/// sorted indices in m_fonts, from the best to the worst
|
||||
vector<shared_ptr<Font> > m_fonts;
|
||||
/// coverage of each font, in symbols
|
||||
vector<int> m_coverage;
|
||||
|
||||
UnicodeBlock(string const & name, uint32_t start, uint32_t end);
|
||||
bool hasSymbol(uint16_t sym) const;
|
||||
UnicodeBlock(string const & name, strings::UniChar start, strings::UniChar end);
|
||||
bool hasSymbol(strings::UniChar sym) const;
|
||||
};
|
||||
|
||||
struct GlyphCacheImpl
|
||||
|
@ -75,7 +76,7 @@ namespace yg
|
|||
void initBlocks(string const & fileName);
|
||||
void initFonts(string const & whiteListFile, string const & blackListFile);
|
||||
|
||||
vector<shared_ptr<Font> > & getFonts(uint16_t sym);
|
||||
vector<shared_ptr<Font> > & getFonts(strings::UniChar sym);
|
||||
void addFont(char const * fileName);
|
||||
void addFonts(vector<string> const & fontNames);
|
||||
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
#include "../base/SRC_FIRST.hpp"
|
||||
|
||||
#include "glyph_layout.hpp"
|
||||
#include "resource_manager.hpp"
|
||||
#include "skin.hpp"
|
||||
|
@ -64,7 +62,7 @@ namespace yg
|
|||
Skin * skin,
|
||||
FontDesc const & fontDesc,
|
||||
m2::PointD const & pt,
|
||||
wstring const & visText,
|
||||
strings::UniString const & visText,
|
||||
yg::EPosition pos)
|
||||
: m_firstVisible(0),
|
||||
m_lastVisible(visText.size())
|
||||
|
@ -171,7 +169,7 @@ namespace yg
|
|||
FontDesc const & fontDesc,
|
||||
m2::PointD const * pts,
|
||||
size_t ptsCount,
|
||||
wstring const & visText,
|
||||
strings::UniString const & visText,
|
||||
double fullLength,
|
||||
double pathOffset,
|
||||
yg::EPosition pos)
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
#include "defines.hpp"
|
||||
|
||||
#include "../base/string_utils.hpp"
|
||||
|
||||
#include "../geometry/rect2d.hpp"
|
||||
#include "../geometry/point2d.hpp"
|
||||
#include "../geometry/aa_rect2d.hpp"
|
||||
|
@ -49,14 +51,14 @@ namespace yg
|
|||
Skin * skin,
|
||||
FontDesc const & font,
|
||||
m2::PointD const & pt,
|
||||
wstring const & visText,
|
||||
strings::UniString const & visText,
|
||||
yg::EPosition pos);
|
||||
|
||||
GlyphLayout(ResourceManager * resourceManager,
|
||||
FontDesc const & font,
|
||||
m2::PointD const * pts,
|
||||
size_t ptsCount,
|
||||
wstring const & visText,
|
||||
strings::UniString const & visText,
|
||||
double fullLength,
|
||||
double pathOffset,
|
||||
yg::EPosition pos);
|
||||
|
|
|
@ -223,7 +223,7 @@ namespace yg
|
|||
|
||||
if (fontIt != m_fonts.end())
|
||||
{
|
||||
FontInfo::TChars::const_iterator charIt = fontIt->m_chars.find(g.m_id);
|
||||
FontInfo::TChars::const_iterator charIt = fontIt->m_chars.find(g.m_symbolCode);
|
||||
if (charIt != fontIt->m_chars.end())
|
||||
{
|
||||
if (g.m_isMask)
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
#include "../base/SRC_FIRST.hpp"
|
||||
|
||||
#include "text_element.hpp"
|
||||
#include "screen.hpp"
|
||||
#include "skin.hpp"
|
||||
|
@ -9,8 +7,6 @@
|
|||
#include "../3party/fribidi/lib/fribidi-deprecated.h"
|
||||
|
||||
#include "../base/logging.hpp"
|
||||
#include "../base/string_utils.hpp"
|
||||
|
||||
|
||||
namespace yg
|
||||
{
|
||||
|
@ -53,13 +49,12 @@ namespace yg
|
|||
m_depth = depth;
|
||||
}
|
||||
|
||||
wstring const TextElement::log2vis(wstring const & str)
|
||||
strings::UniString TextElement::log2vis(strings::UniString const & str)
|
||||
{
|
||||
size_t const count = str.size();
|
||||
wstring res;
|
||||
res.resize(count);
|
||||
strings::UniString res(count);
|
||||
FriBidiParType dir = FRIBIDI_PAR_LTR; // requested base direction
|
||||
fribidi_log2vis(str.c_str(), count, &dir, &res[0], 0, 0, 0);
|
||||
fribidi_log2vis(&str[0], count, &dir, &res[0], 0, 0, 0);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -71,15 +66,18 @@ namespace yg
|
|||
m_rm(p.m_rm),
|
||||
m_skin(p.m_skin)
|
||||
{
|
||||
m_visText = m_log2vis ? log2vis(m_logText) : m_logText;
|
||||
if (m_log2vis)
|
||||
m_visText = log2vis(m_logText);
|
||||
else
|
||||
m_visText = m_logText;
|
||||
}
|
||||
|
||||
wstring const & TextElement::logText() const
|
||||
strings::UniString const & TextElement::logText() const
|
||||
{
|
||||
return m_logText;
|
||||
}
|
||||
|
||||
wstring const & TextElement::visText() const
|
||||
strings::UniString const & TextElement::visText() const
|
||||
{
|
||||
return m_visText;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "../base/string_utils.hpp"
|
||||
|
||||
#include "../geometry/point2d.hpp"
|
||||
#include "../geometry/rect2d.hpp"
|
||||
#include "../geometry/aa_rect2d.hpp"
|
||||
|
@ -60,20 +62,20 @@ namespace yg
|
|||
|
||||
/// text-element specific
|
||||
FontDesc m_fontDesc;
|
||||
wstring m_logText; //< logical string
|
||||
wstring m_visText; //< visual string, BIDI processed
|
||||
strings::UniString m_logText; //< logical string
|
||||
strings::UniString m_visText; //< visual string, BIDI processed
|
||||
bool m_log2vis;
|
||||
ResourceManager * m_rm;
|
||||
Skin * m_skin;
|
||||
|
||||
wstring const log2vis(wstring const & str);
|
||||
strings::UniString log2vis(strings::UniString const & str);
|
||||
|
||||
public:
|
||||
|
||||
struct Params : OverlayElement::Params
|
||||
{
|
||||
FontDesc m_fontDesc;
|
||||
wstring m_logText;
|
||||
strings::UniString m_logText;
|
||||
bool m_log2vis;
|
||||
ResourceManager * m_rm;
|
||||
Skin * m_skin;
|
||||
|
@ -82,8 +84,8 @@ namespace yg
|
|||
TextElement(Params const & p);
|
||||
|
||||
void drawTextImpl(GlyphLayout const & layout, gl::TextRenderer * screen, FontDesc const & desc, double depth) const;
|
||||
wstring const & logText() const;
|
||||
wstring const & visText() const;
|
||||
strings::UniString const & logText() const;
|
||||
strings::UniString const & visText() const;
|
||||
FontDesc const & fontDesc() const;
|
||||
};
|
||||
|
||||
|
|
|
@ -77,7 +77,7 @@ namespace yg
|
|||
{
|
||||
return m_utf8Text;
|
||||
}
|
||||
|
||||
*/
|
||||
void TextRenderer::TextObj::Offset(m2::PointD const & offs)
|
||||
{
|
||||
m_elem.offset(offs);
|
||||
|
@ -113,7 +113,7 @@ namespace yg
|
|||
params.m_position = pos;
|
||||
params.m_rm = resourceManager().get();
|
||||
params.m_skin = skin().get();
|
||||
params.m_logText = strings::FromUtf8(utf8Text);
|
||||
params.m_logText = strings::MakeUniString(utf8Text);
|
||||
|
||||
StraightTextElement ste(params);
|
||||
|
||||
|
@ -305,7 +305,7 @@ namespace yg
|
|||
params.m_fullLength = fullLength;
|
||||
params.m_pathOffset = pathOffset;
|
||||
params.m_fontDesc = fontDesc;
|
||||
params.m_logText = strings::FromUtf8(utf8Text);
|
||||
params.m_logText = strings::MakeUniString(utf8Text);
|
||||
params.m_depth = depth;
|
||||
params.m_log2vis = true;
|
||||
params.m_rm = resourceManager().get();
|
||||
|
|
|
@ -714,7 +714,7 @@ namespace
|
|||
params.m_position = yg::EPosAboveRight;
|
||||
params.m_rm = p->resourceManager().get();
|
||||
params.m_skin = p->skin().get();
|
||||
params.m_logText = strings::FromUtf8("Simplicity is the ultimate sophistication");
|
||||
params.m_logText = strings::MakeUniString("Simplicity is the ultimate sophistication");
|
||||
yg::StraightTextElement ste(params);
|
||||
|
||||
m2::AARectD r = ste.boundRect();
|
||||
|
@ -738,7 +738,7 @@ namespace
|
|||
params.m_position = yg::EPosAboveRight;
|
||||
params.m_rm = p->resourceManager().get();
|
||||
params.m_skin = p->skin().get();
|
||||
params.m_logText = strings::FromUtf8("Simplicity is the ultimate sophistication");
|
||||
params.m_logText = strings::MakeUniString("Simplicity is the ultimate sophistication");
|
||||
yg::StraightTextElement ste(params);
|
||||
|
||||
m2::AARectD r = ste.boundRect();
|
||||
|
@ -875,7 +875,7 @@ namespace
|
|||
{
|
||||
yg::StraightTextElement::Params params;
|
||||
params.m_fontDesc = yg::FontDesc(false, 20);
|
||||
params.m_logText = strings::FromUtf8("Simplicity is the ultimate sophistication. Leonardo Da Vinci.");
|
||||
params.m_logText = strings::MakeUniString("Simplicity is the ultimate sophistication. Leonardo Da Vinci.");
|
||||
params.m_depth = 10;
|
||||
params.m_log2vis = false;
|
||||
params.m_rm = p->resourceManager().get();
|
||||
|
@ -919,7 +919,7 @@ namespace
|
|||
params.m_fullLength = calc_length(m_path);
|
||||
params.m_pathOffset = 0;
|
||||
params.m_fontDesc = yg::FontDesc(false, 20);
|
||||
params.m_logText = strings::FromUtf8("Simplicity is the ultimate sophistication. Leonardo Da Vinci.");
|
||||
params.m_logText = strings::MakeUniString("Simplicity is the ultimate sophistication. Leonardo Da Vinci.");
|
||||
params.m_depth = 10;
|
||||
params.m_log2vis = false;
|
||||
params.m_rm = p->resourceManager().get();
|
||||
|
|
Loading…
Add table
Reference in a new issue