From 8fc84938bfaabd954f6dd0d05370c7c51fd26765 Mon Sep 17 00:00:00 2001 From: Jinhao Date: Mon, 14 Dec 2015 00:30:03 +0800 Subject: [PATCH] use UTF-8 for string representation --- .../nana/detail/linux_X11/platform_spec.hpp | 2 +- include/nana/detail/win32/platform_spec.hpp | 4 ++-- include/nana/gui/widgets/categorize.hpp | 22 ++++++++++++++----- .../widgets/skeletons/text_token_stream.hpp | 4 ++-- include/nana/paint/graphics.hpp | 8 +++---- include/nana/paint/image.hpp | 3 --- source/detail/platform_spec_posix.cpp | 6 ++--- source/detail/platform_spec_windows.cpp | 9 +++++--- source/gui/widgets/label.cpp | 8 +++---- source/paint/graphics.cpp | 15 +++++++------ 10 files changed, 47 insertions(+), 34 deletions(-) diff --git a/include/nana/detail/linux_X11/platform_spec.hpp b/include/nana/detail/linux_X11/platform_spec.hpp index 0a013ed6..44a73a12 100644 --- a/include/nana/detail/linux_X11/platform_spec.hpp +++ b/include/nana/detail/linux_X11/platform_spec.hpp @@ -203,7 +203,7 @@ namespace detail void default_native_font(const font_ptr_t&); unsigned font_size_to_height(unsigned) const; unsigned font_height_to_size(unsigned) const; - font_ptr_t make_native_font(const nana::char_t* name, unsigned height, unsigned weight, bool italic, bool underline, bool strick_out); + font_ptr_t make_native_font(const char* name, unsigned height, unsigned weight, bool italic, bool underline, bool strick_out); Display* open_display(); void close_display(); diff --git a/include/nana/detail/win32/platform_spec.hpp b/include/nana/detail/win32/platform_spec.hpp index b129406b..dc6329fe 100644 --- a/include/nana/detail/win32/platform_spec.hpp +++ b/include/nana/detail/win32/platform_spec.hpp @@ -80,7 +80,7 @@ namespace detail struct font_tag { - nana::string name; + native_string_type name; unsigned height; unsigned weight; bool italic; @@ -186,7 +186,7 @@ namespace detail void default_native_font(const font_ptr_t&); unsigned font_size_to_height(unsigned) const; unsigned font_height_to_size(unsigned) const; - font_ptr_t make_native_font(const nana::char_t* name, unsigned height, unsigned weight, bool italic, bool underline, bool strike_out); + font_ptr_t make_native_font(const char* name, unsigned height, unsigned weight, bool italic, bool underline, bool strike_out); static platform_spec& instance(); diff --git a/include/nana/gui/widgets/categorize.hpp b/include/nana/gui/widgets/categorize.hpp index 6b62b0ed..43c115f6 100644 --- a/include/nana/gui/widgets/categorize.hpp +++ b/include/nana/gui/widgets/categorize.hpp @@ -174,13 +174,25 @@ namespace nana { } - categorize(window wd, const nana::string& text, bool visible = true) + categorize(window wd, const std::string& text_utf8, bool visible = true) : categorize(wd, ::nana::rectangle(), visible) { this->caption(text); } - categorize(window wd, const nana::char_t* text, bool visible = true) + categorize(window wd, const char* text_utf8, bool visible = true) + : categorize(wd, ::nana::rectangle(), visible) + { + this->caption(text); + } + + categorize(window wd, const std::wstring& text, bool visible = true) + : categorize(wd, ::nana::rectangle(), visible) + { + this->caption(text); + } + + categorize(window wd, const wchar_t* text, bool visible = true) : categorize(wd, ::nana::rectangle(), visible) { this->caption(text); @@ -206,7 +218,7 @@ namespace nana } /// Erases a child category with a specified name from current category. - categorize& childset_erase(const nana::string& name) + categorize& childset_erase(const std::string& name) { if(this->get_drawer_trigger().childset_erase(name)) API::update_window(*this); @@ -220,13 +232,13 @@ namespace nana } /// Sets the splitter string - categorize& splitstr(const nana::string& sstr) + categorize& splitstr(const std::string& sstr) { this->get_drawer_trigger().splitstr(sstr); return *this; } - nana::string splitstr() const + std::string splitstr() const { return this->get_drawer_trigger().splitstr(); } diff --git a/include/nana/gui/widgets/skeletons/text_token_stream.hpp b/include/nana/gui/widgets/skeletons/text_token_stream.hpp index 87d934a4..4f936400 100644 --- a/include/nana/gui/widgets/skeletons/text_token_stream.hpp +++ b/include/nana/gui/widgets/skeletons/text_token_stream.hpp @@ -434,7 +434,7 @@ namespace nana{ namespace widgets{ namespace skeletons }; }; - ::std::wstring font; + ::std::string font; std::size_t font_size; bool bold; bool bold_empty; //bold should be ignored if bold_empty is true @@ -706,7 +706,7 @@ namespace nana{ namespace widgets{ namespace skeletons if(token::string != tknizer.read()) throw std::runtime_error(""); - fp->font = tknizer.idstr(); + fp->font = to_utf8(tknizer.idstr()); break; case token::size: if(token::equal != tknizer.read()) diff --git a/include/nana/paint/graphics.hpp b/include/nana/paint/graphics.hpp index ae8264a2..be093425 100644 --- a/include/nana/paint/graphics.hpp +++ b/include/nana/paint/graphics.hpp @@ -36,14 +36,14 @@ namespace nana font(); font(drawable_type); font(const font&); - font(const char_t* name, unsigned size, bool bold = false, bool italic = false, bool underline = false, bool strike_out = false); + font(const ::std::string& name, unsigned size, bool bold = false, bool italic = false, bool underline = false, bool strike_out = false); ~font(); bool empty() const; - void make(const char_t* name, unsigned size, bool bold = false, bool italic = false, bool underline = false, bool strike_out = false); - void make_raw(const char_t*, unsigned height, unsigned weight, bool italic, bool underline, bool strike_out); + void make(const ::std::string& name, unsigned size, bool bold = false, bool italic = false, bool underline = false, bool strike_out = false); + void make_raw(const ::std::string& name, unsigned height, unsigned weight, bool italic, bool underline, bool strike_out); void set_default() const; - ::nana::string name() const; + ::std::string name() const; unsigned size() const; bool bold() const; unsigned height() const; diff --git a/include/nana/paint/image.hpp b/include/nana/paint/image.hpp index db70ce0a..e3f0e37e 100644 --- a/include/nana/paint/image.hpp +++ b/include/nana/paint/image.hpp @@ -32,8 +32,6 @@ namespace paint image(); image(const image&); image(image&&); - //image(const nana::char_t* file); - //image(const nana::string& filename); //deprecated image(const ::nana::experimental::filesystem::path& file); template @@ -45,7 +43,6 @@ namespace paint ~image(); image& operator=(const image& rhs); image& operator=(image&&); - //bool open(const nana::string& filename); //deprecated bool open(const ::nana::experimental::filesystem::path& file); /// Opens an icon from a specified buffer diff --git a/source/detail/platform_spec_posix.cpp b/source/detail/platform_spec_posix.cpp index 33d81a75..43cdfccd 100644 --- a/source/detail/platform_spec_posix.cpp +++ b/source/detail/platform_spec_posix.cpp @@ -515,7 +515,7 @@ namespace detail atombase_.xdnd_finished = ::XInternAtom(display_, "XdndFinished", False); //Create default font object. - def_font_ptr_ = make_native_font(0, font_size_to_height(10), 400, false, false, false); + def_font_ptr_ = make_native_font(nullptr, font_size_to_height(10), 400, false, false, false); msg_dispatcher_ = new msg_dispatcher(display_); } @@ -550,10 +550,10 @@ namespace detail return height; } - platform_spec::font_ptr_t platform_spec::make_native_font(const nana::char_t* name, unsigned height, unsigned weight, bool italic, bool underline, bool strike_out) + platform_spec::font_ptr_t platform_spec::make_native_font(const char* name, unsigned height, unsigned weight, bool italic, bool underline, bool strike_out) { font_ptr_t ref; -#if defined(NANA_UNICODE) +#if 1 //Xft if(0 == name || *name == 0) name = STR("*"); diff --git a/source/detail/platform_spec_windows.cpp b/source/detail/platform_spec_windows.cpp index 96e0ae97..3ad1a352 100644 --- a/source/detail/platform_spec_windows.cpp +++ b/source/detail/platform_spec_windows.cpp @@ -207,7 +207,7 @@ namespace detail #endif #endif ::SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof metrics, &metrics, 0); - def_font_ptr_ = make_native_font(metrics.lfMessageFont.lfFaceName, font_size_to_height(9), 400, false, false, false); + def_font_ptr_ = make_native_font(utf8_cast(metrics.lfMessageFont.lfFaceName).c_str(), font_size_to_height(9), 400, false, false, false); } const platform_spec::font_ptr_t& platform_spec::default_native_font() const @@ -238,12 +238,15 @@ namespace detail return height; } - platform_spec::font_ptr_t platform_spec::make_native_font(const nana::char_t* name, unsigned height, unsigned weight, bool italic, bool underline, bool strike_out) + platform_spec::font_ptr_t platform_spec::make_native_font(const char* name, unsigned height, unsigned weight, bool italic, bool underline, bool strike_out) { ::LOGFONT logfont; memset(&logfont, 0, sizeof logfont); - strcpy(logfont.lfFaceName, (name && *name ? name : def_font_ptr_->name.c_str())); + if (name && *name) + strcpy(logfont.lfFaceName, utf8_cast(name).c_str()); + else + strcpy(logfont.lfFaceName, def_font_ptr_->name.c_str()); logfont.lfCharSet = DEFAULT_CHARSET; HDC hdc = ::GetDC(0); diff --git a/source/gui/widgets/label.cpp b/source/gui/widgets/label.cpp index f6968dd0..f595d39d 100644 --- a/source/gui/widgets/label.cpp +++ b/source/gui/widgets/label.cpp @@ -259,7 +259,7 @@ namespace nana return fp->bold; } - const nana::string& _m_fontname(nana::widgets::skeletons::fblock* fp) + const std::string& _m_fontname(nana::widgets::skeletons::fblock* fp) { while(fp->font.empty()) { @@ -274,13 +274,13 @@ namespace nana { if(fp != fblock_) { - const nana::string& name = _m_fontname(fp); + auto& name = _m_fontname(fp); auto fontsize = static_cast(_m_font_size(fp)); bool bold = _m_bold(fp); if((fontsize != font_.size()) || bold != font_.bold() || name != font_.name()) { - font_.make(name.data(), fontsize, bold); + font_.make(name, fontsize, bold); graph.typeface(font_); } fblock_ = fp; @@ -606,7 +606,7 @@ namespace nana ::nana::paint::font font_; struct def_font_tag { - ::nana::string font_name; + ::std::string font_name; std::size_t font_size; bool font_bold; ::nana::color fgcolor; diff --git a/source/paint/graphics.cpp b/source/paint/graphics.cpp index ab4b1121..53ed2e33 100644 --- a/source/paint/graphics.cpp +++ b/source/paint/graphics.cpp @@ -79,7 +79,7 @@ namespace paint impl_->font_ptr = rhs.impl_->font_ptr; } - font::font(const nana::char_t* name, unsigned size, bool bold, bool italic, bool underline, bool strike_out) + font::font(const std::string& name, unsigned size, bool bold, bool italic, bool underline, bool strike_out) : impl_(new impl_type) { make(name, size, bold, italic, underline, strike_out); @@ -95,17 +95,17 @@ namespace paint return ((nullptr == impl_) || (nullptr == impl_->font_ptr)); } - void font::make(const nana::char_t* name, unsigned size, bool bold, bool italic, bool underline, bool strike_out) + void font::make(const std::string& name, unsigned size, bool bold, bool italic, bool underline, bool strike_out) { size = nana::detail::platform_spec::instance().font_size_to_height(size); make_raw(name, size, bold ? 700 : 400, italic, underline, strike_out); } - void font::make_raw(const nana::char_t*name, unsigned height, unsigned weight, bool italic, bool underline, bool strike_out) + void font::make_raw(const std::string& name, unsigned height, unsigned weight, bool italic, bool underline, bool strike_out) { if(impl_) { - auto t = nana::detail::platform_spec::instance().make_native_font(name, height, weight, italic, underline, strike_out); + auto t = nana::detail::platform_spec::instance().make_native_font(name.c_str(), height, weight, italic, underline, strike_out); if(t) impl_->font_ptr = t; } @@ -119,10 +119,11 @@ namespace paint nana::detail::platform_spec::instance().default_native_font(impl_->font_ptr); } - nana::string font::name() const + std::string font::name() const { - if(empty()) return nana::string(); - return impl_->font_ptr->name; + if(empty()) return std::string(); + + return to_utf8(impl_->font_ptr->name); } unsigned font::size() const