Re: a question about drawing wchar_t with SDL_TTF
jeroen clarysse <[email protected]>
| Newsgroups | gmane.comp.lib.sdl |
|---|---|
| Message-ID | <[email protected]> |
replying to myself… as usual, you can search for a solution a whole day and when you finally give up and ask for help, you bump into the solution while closing tabs on stackoverflow :-) the solution is dead simple : typedef std::basic_string<Uint16, std::char_traits<Uint16>, std::allocator<Uint16> > u16string; u16string utext( m_text.begin(), m_text.end() ); SDL_Surface *msg1Sur = TTF_RenderUNICODE_Blended_Wrapped(m_font->get_ttf_font(), utext.c_str(), m_fontcolor, (Uint32)m_force_width); i hope this helps others > On 07 Nov 2016, at 12:34, jeroen clarysse <[email protected]> wrote: > > given a std::wstring variable named m_text, I do the following : > > > size_t s = 2 * sizeof(wchar_t)*(m_text.size() + 1); > char * convertedChar = (char*) malloc(s); > > size_t res=0; > ppw_wcstombs(&res, convertedChar, s, m_text.c_str(), m_text.size()); > > convertedChar[m_text.size()] = 0; > > SDL_Surface *msg1Sur = TTF_RenderUTF8_Blended_Wrapped(m_font->get_ttf_font(), convertedChar, m_fontcolor, (Uint32)m_force_width); > > > this works nicely as long as the input string doesn’t contain unicode characters. As soon as I use something like a curly quote (“) the drawing stops right before that character > > > can anyone point me what I’m doing wrong ? > _______________________________________________ > SDL mailing list > [email protected] > http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org _______________________________________________ SDL mailing list [email protected] http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org