add support of multi-language under Linux(#439)

also fix the font style issue under Linux
This commit is contained in:
Jinhao
2019-06-01 03:15:59 +08:00
parent 742cde9779
commit f57e824431
6 changed files with 514 additions and 26 deletions

View File

@@ -1,7 +1,7 @@
/*
* Platform Implementation
* Nana C++ Library(http://www.nanapro.org)
* Copyright(C) 2003-2018 Jinhao(cnjinhao@hotmail.com)
* Copyright(C) 2003-2019 Jinhao(cnjinhao@hotmail.com)
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
@@ -24,6 +24,12 @@
namespace nana
{
//Forward-declarations
//These names are defined platform_abstraction.cpp
class font_interface;
void nana_xft_draw_string(::XftDraw* xftdraw, ::XftColor* xftcolor, font_interface* ft, const nana::point& pos, const wchar_t * str, std::size_t len);
nana::size nana_xft_extents(font_interface* ft, const wchar_t* str, std::size_t len);
namespace paint
{
namespace detail
@@ -144,14 +150,19 @@ namespace detail
if (::GetTextExtentPoint32(dw->context, text, static_cast<int>(len), &size))
return nana::size(size.cx, size.cy);
#elif defined(NANA_X11)
std::string utf8text = to_utf8(std::wstring(text, len));
#if defined(NANA_USE_XFT)
#if 0
std::string utf8text = to_utf8(std::wstring(text, len));
XGlyphInfo ext;
XftFont * fs = reinterpret_cast<XftFont*>(dw->font->native_handle());
::XftTextExtentsUtf8(nana::detail::platform_spec::instance().open_display(), fs,
reinterpret_cast<XftChar8*>(const_cast<char*>(utf8text.data())), utf8text.size(), &ext);
return nana::size(ext.xOff, fs->ascent + fs->descent);
#else
return nana_xft_extents(dw->font.get(), text, len);
#endif
#else
std::string utf8text = to_utf8(std::wstring(text, len));
XRectangle ink;
XRectangle logic;
::XmbTextExtents(reinterpret_cast<XFontSet>(dw->font->native_handle()), utf8text.c_str(), utf8text.size(), &ink, &logic);
@@ -178,11 +189,20 @@ namespace detail
return nana::size(size.cx, size.cy);
#elif defined(NANA_X11)
#if defined(NANA_USE_XFT)
#if 0
XGlyphInfo ext;
XftFont * fs = reinterpret_cast<XftFont*>(dw->font->native_handle());
::XftTextExtentsUtf8(nana::detail::platform_spec::instance().open_display(), fs,
reinterpret_cast<XftChar8*>(const_cast<char*>(text)), len, &ext);
return nana::size(ext.xOff, fs->ascent + fs->descent);
#else
#ifdef _nana_std_has_string_view
auto wstr = to_wstring(std::string_view(text, len));
#else
auto wstr = to_wstring(std::string(text,len));
#endif
return nana_xft_extents(dw->font.get(), wstr.data(), wstr.size());
#endif
#else
XRectangle ink;
XRectangle logic;
@@ -240,6 +260,8 @@ namespace detail
#elif defined(NANA_X11)
auto disp = ::nana::detail::platform_spec::instance().open_display();
#if defined(NANA_USE_XFT)
#if 0
auto fs = reinterpret_cast<XftFont*>(dw->font->native_handle());
//Fixed missing array declaration by dareg
@@ -251,6 +273,9 @@ namespace detail
(*glyphs++) = XftCharIndex(disp, fs, *chr);
}
XftDrawGlyphs(dw->xftdraw, &(dw->xft_fgcolor), fs, pos.x, pos.y + fs->ascent, glyphs_ptr.get(), len);
#else
nana_xft_draw_string(dw->xftdraw, &(dw->xft_fgcolor), dw->font.get(), pos, str, len);
#endif
#else
XFontSet fs = reinterpret_cast<XFontSet>(dw->font->native_handle());
XFontSetExtents * ext = ::XExtentsOfFontSet(fs);