use UTF-8 for string representation

This commit is contained in:
Jinhao
2015-12-29 01:26:19 +08:00
parent 443b3dcd87
commit 48254b6555
22 changed files with 116 additions and 124 deletions

View File

@@ -1,7 +1,7 @@
/*
* Platform Implementation
* Nana C++ Library(http://www.nanapro.org)
* Copyright(C) 2003-2014 Jinhao(cnjinhao@hotmail.com)
* Copyright(C) 2003-2015 Jinhao(cnjinhao@hotmail.com)
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
@@ -129,7 +129,7 @@ namespace detail
pixbuf.paste(nana::rectangle(r.x, 0, r.width, r.height), dw, point{r.x, r.y});
}
nana::size raw_text_extent_size(drawable_type dw, const nana::char_t* text, std::size_t len)
nana::size raw_text_extent_size(drawable_type dw, const wchar_t* text, std::size_t len)
{
if(nullptr == dw || nullptr == text || 0 == len) return nana::size();
#if defined(NANA_WINDOWS)
@@ -138,7 +138,7 @@ namespace detail
return nana::size(size.cx, size.cy);
#elif defined(NANA_X11)
#if defined(NANA_UNICODE)
std::string utf8str = nana::charset(nana::string(text, len));
std::string utf8str = to_utf8(text);
XGlyphInfo ext;
XftFont * fs = reinterpret_cast<XftFont*>(dw->font->handle);
::XftTextExtentsUtf8(nana::detail::platform_spec::instance().open_display(), fs,
@@ -180,12 +180,6 @@ namespace detail
#elif defined(NANA_X11)
auto disp = ::nana::detail::platform_spec::instance().open_display();
#if defined(NANA_UNICODE)
/*
std::string utf8str = nana::charset(nana::string(str, len));
XftFont * fs = reinterpret_cast<XftFont*>(dw->font->handle);
::XftDrawStringUtf8(dw->xftdraw, &(dw->xft_fgcolor), fs, pos.x, pos.y + fs->ascent,
reinterpret_cast<XftChar8*>(const_cast<char*>(utf8str.c_str())), utf8str.size());
*/
auto fs = reinterpret_cast<XftFont*>(dw->font->handle);
//Fixed missing array declaration by dareg

View File

@@ -365,30 +365,35 @@ namespace paint
::nana::size graphics::text_extent_size(const ::std::string& text) const
{
throw_not_utf8(text);
return text_extent_size(static_cast<std::wstring>(::nana::charset(text, ::nana::unicode::utf8)));
return text_extent_size(to_wstring(text));
}
nana::size graphics::text_extent_size(const nana::char_t* text) const
::nana::size graphics::text_extent_size(const char* text, std::size_t len) const
{
return text_extent_size(text, nana::strlen(text));
return text_extent_size(std::string(text, text + len));
}
nana::size graphics::text_extent_size(const nana::string& text) const
nana::size graphics::text_extent_size(const wchar_t* text) const
{
return text_extent_size(text, std::wcslen(text));
}
nana::size graphics::text_extent_size(const std::wstring& text) const
{
return text_extent_size(text.c_str(), static_cast<unsigned>(text.length()));
}
nana::size graphics::text_extent_size(const nana::char_t* str, std::size_t len) const
nana::size graphics::text_extent_size(const wchar_t* str, std::size_t len) const
{
return detail::text_extent_size(handle_, str, len);
}
nana::size graphics::text_extent_size(const nana::string& str, std::size_t len) const
nana::size graphics::text_extent_size(const std::wstring& str, std::size_t len) const
{
return detail::text_extent_size(handle_, str.c_str(), len);
}
nana::size graphics::glyph_extent_size(const nana::char_t * str, std::size_t len, std::size_t begin, std::size_t end) const
nana::size graphics::glyph_extent_size(const wchar_t * str, std::size_t len, std::size_t begin, std::size_t end) const
{
if(len < end) end = len;
if (nullptr == handle_ || nullptr == str || 0 == len || begin >= end) return{};
@@ -414,12 +419,12 @@ namespace paint
return sz;
}
nana::size graphics::glyph_extent_size(const nana::string& str, std::size_t len, std::size_t begin, std::size_t end) const
nana::size graphics::glyph_extent_size(const std::wstring& str, std::size_t len, std::size_t begin, std::size_t end) const
{
return glyph_extent_size(str.c_str(), len, begin, end);
}
bool graphics::glyph_pixels(const nana::char_t * str, std::size_t len, unsigned* pxbuf) const
bool graphics::glyph_pixels(const wchar_t * str, std::size_t len, unsigned* pxbuf) const
{
if(nullptr == handle_ || nullptr == handle_->context || nullptr == str || nullptr == pxbuf) return false;
if(len == 0) return true;
@@ -966,12 +971,12 @@ namespace paint
string(pos, text_utf8);
}
void graphics::string(nana::point pos, const char_t* str, std::size_t len)
void graphics::string(nana::point pos, const wchar_t* str, std::size_t len)
{
if (handle_ && str && len)
{
const nana::char_t * end = str + len;
const nana::char_t * i = std::find(str, end, '\t');
auto const end = str + len;
auto i = std::find(str, end, '\t');
#if defined(NANA_LINUX) || defined(NANA_MACOS)
handle_->update_text_color();
#endif
@@ -1008,17 +1013,17 @@ namespace paint
}
}
void graphics::string(const nana::point& pos, const char_t* str)
void graphics::string(const nana::point& pos, const wchar_t* str)
{
string(pos, str, nana::strlen(str));
string(pos, str, std::wcslen(str));
}
void graphics::string(const nana::point& pos, const nana::string& str)
void graphics::string(const nana::point& pos, const std::wstring& str)
{
string(pos, str.data(), str.size());
}
void graphics::string(const point& pos, const ::nana::string& text, const color& clr)
void graphics::string(const point& pos, const ::std::wstring& text, const color& clr)
{
set_text_color(clr);
string(pos, text.data(), text.size());