all repos — fluxbox @ 3dc71037822283699cccc42b67fe44fe487468ec

custom fork of the fluxbox windowmanager

fix handling of font+text encodings
rathnor rathnor
commit

3dc71037822283699cccc42b67fe44fe487468ec

parent

9d7c7e109e9327497d2ad554ac08ca147b560587

4 files changed, 35 insertions(+), 35 deletions(-)

jump to
M ChangeLogChangeLog

@@ -1,5 +1,8 @@

(Format: Year/Month/Day) Changes for 0.9.10: +*04/08/18: + * Fix handling of font encodings, and related bugs (Simon) + FbTk/Font.hh/cc fluxbox.cc *04/08/17: * New manpage for startfluxbox (Han) startfluxbox.1
M src/FbTk/Font.ccsrc/FbTk/Font.cc

@@ -19,7 +19,7 @@ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING

// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -//$Id: Font.cc,v 1.10 2004/08/14 09:33:09 fluxgen Exp $ +//$Id: Font.cc,v 1.11 2004/08/18 16:30:33 rathnor Exp $ #include "StringUtil.hh"

@@ -59,7 +59,7 @@ #include <cstring>

#include <cstdlib> #include <list> #include <typeinfo> - +#include <langinfo.h> #ifdef HAVE_SSTREAM #include <sstream>

@@ -97,12 +97,12 @@ // If empty message, yes this can happen, return

if(strlen(msg) == 0) return 0; - size_t inbytesleft = strlen(msg); size_t outbytesleft = 4*inbytesleft; char *new_msg = new char[outbytesleft]; char *new_msg_ptr = new_msg; char *msg_ptr = strdup(msg); + char *orig_msg_ptr = msg_ptr; // msg_ptr modified in iconv call if (iconv(cd, &msg_ptr, &inbytesleft, &new_msg, &outbytesleft) == -1) { // iconv can fail for three reasons

@@ -110,20 +110,20 @@ // 1) Invalid multibyte sequence is encountered in the input

// 2) An incomplete multibyte sequence // 3) The output buffer has no more room for the next converted character. // So we the delete new message and return original message - delete new_msg; - free(msg_ptr); + delete new_msg_ptr; + free(orig_msg_ptr); return 0; } - free(msg_ptr); + free(orig_msg_ptr); - *new_msg_ptr = '\0'; + *new_msg = '\0'; if(inbytesleft != 0) { - delete new_msg; + delete new_msg_ptr; return 0; } - - return new_msg; + + return new_msg_ptr; }

@@ -200,6 +200,11 @@

bool Font::m_multibyte = false; bool Font::m_utf8mode = false; +// some initialisation for using fonts +void fontInit() { + setlocale(LC_CTYPE, ""); +} + Font::Font(const char *name, bool antialias): m_fontimp(0), m_antialias(false), m_rotated(false),

@@ -212,34 +217,22 @@ // MB_CUR_MAX returns the size of a char in the current locale

if (MB_CUR_MAX > 1) // more than one byte, then we're multibyte m_multibyte = true; - char *envstr; // temporary string for enviroment variable // check for utf-8 mode - if (((envstr = getenv("LC_ALL")) && *envstr) || - ((envstr = getenv("LC_CTYPE")) && *envstr) || - ((envstr = getenv("LANG")) && *envstr)) { - if (strstr(envstr, "UTF-8")) - m_utf8mode = true; - m_locale = envstr; - int index = m_locale.find("."); - if (index != 0) - m_locale = m_locale.substr(index + 1); - else - m_locale = "UTF-8"; - } + char *locale_codeset = nl_langinfo(CODESET); - if (m_locale.empty()) - m_locale = "C"; + if (strcmp("UTF-8", locale_codeset) == 0) { + m_utf8mode = true; + } else { + // if locale isn't UTF-8 we try to + // create a iconv pointer so we can + // convert non utf-8 strings to utf-8 - // if locale isn't UTF-8 we try to - // create a iconv pointer so we can - // convert non utf-8 strings to utf-8 - if (m_locale != "UTF-8") { #ifdef DEBUG - cerr<<"FbTk::Font: m_locale = "<<m_locale<<endl; + cerr<<"FbTk::Font: check UTF-8 convert for codeset = "<<locale_codeset<<endl; #endif // DEBUG - m_iconv = iconv_open(m_locale.c_str(), "UTF-8"); + m_iconv = iconv_open("UTF-8", locale_codeset); if(m_iconv == (iconv_t)(-1)) { - cerr<<"FbTk::Font: code error: from "<<m_locale<<" to: UTF-8"<<endl; + cerr<<"FbTk::Font: code error: from "<<locale_codeset<<" to: UTF-8"<<endl; // if we failed with iconv then we can't convert // the strings to utf-8, so we disable utf8 mode m_utf8mode = false;
M src/FbTk/Font.hhsrc/FbTk/Font.hh

@@ -19,7 +19,7 @@ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING

// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -//$Id: Font.hh,v 1.9 2004/08/10 18:08:37 fluxgen Exp $ +//$Id: Font.hh,v 1.10 2004/08/18 16:30:33 rathnor Exp $ #ifndef FBTK_FONT_HH #define FBTK_FONT_HH

@@ -33,6 +33,8 @@

#include <iconv.h> namespace FbTk { + +void fontInit(); class FontImp;

@@ -109,7 +111,6 @@ int m_shadow_offx; ///< offset y for shadow

int m_shadow_offy; ///< offset x for shadow bool m_halo; ///< halo text std::string m_halo_color; ///< halo color - std::string m_locale; ///< system encoding iconv_t m_iconv; };
M src/fluxbox.ccsrc/fluxbox.cc

@@ -22,7 +22,7 @@ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING

// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: fluxbox.cc,v 1.248 2004/07/15 18:23:03 fluxgen Exp $ +// $Id: fluxbox.cc,v 1.249 2004/08/18 16:30:33 rathnor Exp $ #include "fluxbox.hh"

@@ -452,6 +452,9 @@ throw string(_FBTEXT(Fluxbox, NoDisplay,

"Can not connect to X server.\nMake sure you started X before you start Fluxbox.", "Error message when no X display appears to exist")); } + + FbTk::fontInit(); + // For KDE dock applets // KDE v1.x m_kwm1_dockwindow = XInternAtom(FbTk::App::instance()->display(),