From a03961d09786de95007c1ab346480312e0909345 Mon Sep 17 00:00:00 2001 From: Alex Zolotarev Date: Sun, 12 Jun 2011 20:45:59 +0300 Subject: [PATCH] Refactored wstring to UniString --- base/string_utils.hpp | 20 -------------------- map/information_display.cpp | 4 ++-- yg/glyph_cache.cpp | 22 ++++++++++------------ yg/glyph_cache.hpp | 10 +++++++--- yg/glyph_cache_impl.cpp | 15 +++++++-------- yg/glyph_cache_impl.hpp | 11 ++++++----- yg/glyph_layout.cpp | 6 ++---- yg/glyph_layout.hpp | 6 ++++-- yg/skin_page.cpp | 2 +- yg/text_element.cpp | 20 +++++++++----------- yg/text_element.hpp | 14 ++++++++------ yg/text_renderer.cpp | 6 +++--- yg/yg_tests/screengl_test.cpp | 8 ++++---- 13 files changed, 63 insertions(+), 81 deletions(-) diff --git a/base/string_utils.hpp b/base/string_utils.hpp index 804767a72c..60a53f6aa6 100644 --- a/base/string_utils.hpp +++ b/base/string_utils.hpp @@ -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::value_type JoinStrings(ItT begin, ItT end, DelimiterT const & delimiter) { diff --git a/map/information_display.cpp b/map/information_display.cpp index b1e19ab741..fdfee16ffb 100644 --- a/map/information_display.cpp +++ b/map/information_display.cpp @@ -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); diff --git a/yg/glyph_cache.cpp b/yg/glyph_cache.cpp index 0559f7c9dd..43536ea736 100644 --- a/yg/glyph_cache.cpp +++ b/yg/glyph_cache.cpp @@ -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(m_id) << 16 + return static_cast(m_symbolCode) << 16 | static_cast(m_fontSize) << 8 | static_cast(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 GlyphCache::getCharIDX(GlyphKey const & key) { - vector > & fonts = m_impl->getFonts(key.m_id); + vector > & 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) { diff --git a/yg/glyph_cache.hpp b/yg/glyph_cache.hpp index 8c8c5f0aea..4f025c3c1a 100644 --- a/yg/glyph_cache.hpp +++ b/yg/glyph_cache.hpp @@ -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; diff --git a/yg/glyph_cache_impl.cpp b/yg/glyph_cache_impl.cpp index 1c0f8d9d29..ee84f89ef5 100644 --- a/yg/glyph_cache_impl.cpp +++ b/yg/glyph_cache_impl.cpp @@ -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 > & GlyphCacheImpl::getFonts(uint16_t sym) + vector > & GlyphCacheImpl::getFonts(strings::UniChar sym) { if ((m_lastUsedBlock != m_unicodeBlocks.end()) && m_lastUsedBlock->hasSymbol(sym)) return m_lastUsedBlock->m_fonts; diff --git a/yg/glyph_cache_impl.hpp b/yg/glyph_cache_impl.hpp index 78b21e6d06..2ddbacd4bd 100644 --- a/yg/glyph_cache_impl.hpp +++ b/yg/glyph_cache_impl.hpp @@ -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 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 > m_fonts; /// coverage of each font, in symbols vector 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 > & getFonts(uint16_t sym); + vector > & getFonts(strings::UniChar sym); void addFont(char const * fileName); void addFonts(vector const & fontNames); diff --git a/yg/glyph_layout.cpp b/yg/glyph_layout.cpp index d8ec0dcb74..5448cbefec 100644 --- a/yg/glyph_layout.cpp +++ b/yg/glyph_layout.cpp @@ -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) diff --git a/yg/glyph_layout.hpp b/yg/glyph_layout.hpp index 21151598f8..6758bd5eb6 100644 --- a/yg/glyph_layout.hpp +++ b/yg/glyph_layout.hpp @@ -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); diff --git a/yg/skin_page.cpp b/yg/skin_page.cpp index 6aea7c8b31..902effb596 100644 --- a/yg/skin_page.cpp +++ b/yg/skin_page.cpp @@ -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) diff --git a/yg/text_element.cpp b/yg/text_element.cpp index 8a7c890fb5..85697bc9e3 100644 --- a/yg/text_element.cpp +++ b/yg/text_element.cpp @@ -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; } diff --git a/yg/text_element.hpp b/yg/text_element.hpp index e9e808365d..c1e9d9e950 100644 --- a/yg/text_element.hpp +++ b/yg/text_element.hpp @@ -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; }; diff --git a/yg/text_renderer.cpp b/yg/text_renderer.cpp index 2d1110c277..6eefa427e3 100644 --- a/yg/text_renderer.cpp +++ b/yg/text_renderer.cpp @@ -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(); diff --git a/yg/yg_tests/screengl_test.cpp b/yg/yg_tests/screengl_test.cpp index 19861f6509..58d21163b4 100644 --- a/yg/yg_tests/screengl_test.cpp +++ b/yg/yg_tests/screengl_test.cpp @@ -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();