aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrathnor <rathnor>2004-08-18 16:30:33 (GMT)
committerrathnor <rathnor>2004-08-18 16:30:33 (GMT)
commit3dc71037822283699cccc42b67fe44fe487468ec (patch)
tree3d87e739362fca1770f88f0bf93c8aad244f0b3d /src
parent9d7c7e109e9327497d2ad554ac08ca147b560587 (diff)
downloadfluxbox_paul-3dc71037822283699cccc42b67fe44fe487468ec.zip
fluxbox_paul-3dc71037822283699cccc42b67fe44fe487468ec.tar.bz2
fix handling of font+text encodings
Diffstat (limited to 'src')
-rw-r--r--src/FbTk/Font.cc57
-rw-r--r--src/FbTk/Font.hh5
-rw-r--r--src/fluxbox.cc5
3 files changed, 32 insertions, 35 deletions
diff --git a/src/FbTk/Font.cc b/src/FbTk/Font.cc
index 815cf0d..b79cdcc 100644
--- a/src/FbTk/Font.cc
+++ b/src/FbTk/Font.cc
@@ -19,7 +19,7 @@
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE. 20// DEALINGS IN THE SOFTWARE.
21 21
22//$Id: Font.cc,v 1.10 2004/08/14 09:33:09 fluxgen Exp $ 22//$Id: Font.cc,v 1.11 2004/08/18 16:30:33 rathnor Exp $
23 23
24 24
25#include "StringUtil.hh" 25#include "StringUtil.hh"
@@ -59,7 +59,7 @@
59#include <cstdlib> 59#include <cstdlib>
60#include <list> 60#include <list>
61#include <typeinfo> 61#include <typeinfo>
62 62#include <langinfo.h>
63 63
64#ifdef HAVE_SSTREAM 64#ifdef HAVE_SSTREAM
65#include <sstream> 65#include <sstream>
@@ -97,12 +97,12 @@ char* recode(iconv_t cd,
97 if(strlen(msg) == 0) 97 if(strlen(msg) == 0)
98 return 0; 98 return 0;
99 99
100
101 size_t inbytesleft = strlen(msg); 100 size_t inbytesleft = strlen(msg);
102 size_t outbytesleft = 4*inbytesleft; 101 size_t outbytesleft = 4*inbytesleft;
103 char *new_msg = new char[outbytesleft]; 102 char *new_msg = new char[outbytesleft];
104 char *new_msg_ptr = new_msg; 103 char *new_msg_ptr = new_msg;
105 char *msg_ptr = strdup(msg); 104 char *msg_ptr = strdup(msg);
105 char *orig_msg_ptr = msg_ptr; // msg_ptr modified in iconv call
106 106
107 if (iconv(cd, &msg_ptr, &inbytesleft, &new_msg, &outbytesleft) == -1) { 107 if (iconv(cd, &msg_ptr, &inbytesleft, &new_msg, &outbytesleft) == -1) {
108 // iconv can fail for three reasons 108 // iconv can fail for three reasons
@@ -110,20 +110,20 @@ char* recode(iconv_t cd,
110 // 2) An incomplete multibyte sequence 110 // 2) An incomplete multibyte sequence
111 // 3) The output buffer has no more room for the next converted character. 111 // 3) The output buffer has no more room for the next converted character.
112 // So we the delete new message and return original message 112 // So we the delete new message and return original message
113 delete new_msg; 113 delete new_msg_ptr;
114 free(msg_ptr); 114 free(orig_msg_ptr);
115 return 0; 115 return 0;
116 } 116 }
117 free(msg_ptr); 117 free(orig_msg_ptr);
118 118
119 *new_msg_ptr = '\0'; 119 *new_msg = '\0';
120 120
121 if(inbytesleft != 0) { 121 if(inbytesleft != 0) {
122 delete new_msg; 122 delete new_msg_ptr;
123 return 0; 123 return 0;
124 } 124 }
125 125
126 return new_msg; 126 return new_msg_ptr;
127} 127}
128 128
129 129
@@ -200,6 +200,11 @@ namespace FbTk {
200bool Font::m_multibyte = false; 200bool Font::m_multibyte = false;
201bool Font::m_utf8mode = false; 201bool Font::m_utf8mode = false;
202 202
203// some initialisation for using fonts
204void fontInit() {
205 setlocale(LC_CTYPE, "");
206}
207
203Font::Font(const char *name, bool antialias): 208Font::Font(const char *name, bool antialias):
204 m_fontimp(0), 209 m_fontimp(0),
205 m_antialias(false), m_rotated(false), 210 m_antialias(false), m_rotated(false),
@@ -212,34 +217,22 @@ Font::Font(const char *name, bool antialias):
212 if (MB_CUR_MAX > 1) // more than one byte, then we're multibyte 217 if (MB_CUR_MAX > 1) // more than one byte, then we're multibyte
213 m_multibyte = true; 218 m_multibyte = true;
214 219
215 char *envstr; // temporary string for enviroment variable
216 // check for utf-8 mode 220 // check for utf-8 mode
217 if (((envstr = getenv("LC_ALL")) && *envstr) || 221 char *locale_codeset = nl_langinfo(CODESET);
218 ((envstr = getenv("LC_CTYPE")) && *envstr) ||
219 ((envstr = getenv("LANG")) && *envstr)) {
220 if (strstr(envstr, "UTF-8"))
221 m_utf8mode = true;
222 m_locale = envstr;
223 int index = m_locale.find(".");
224 if (index != 0)
225 m_locale = m_locale.substr(index + 1);
226 else
227 m_locale = "UTF-8";
228 }
229 222
230 if (m_locale.empty()) 223 if (strcmp("UTF-8", locale_codeset) == 0) {
231 m_locale = "C"; 224 m_utf8mode = true;
225 } else {
226 // if locale isn't UTF-8 we try to
227 // create a iconv pointer so we can
228 // convert non utf-8 strings to utf-8
232 229
233 // if locale isn't UTF-8 we try to
234 // create a iconv pointer so we can
235 // convert non utf-8 strings to utf-8
236 if (m_locale != "UTF-8") {
237#ifdef DEBUG 230#ifdef DEBUG
238 cerr<<"FbTk::Font: m_locale = "<<m_locale<<endl; 231 cerr<<"FbTk::Font: check UTF-8 convert for codeset = "<<locale_codeset<<endl;
239#endif // DEBUG 232#endif // DEBUG
240 m_iconv = iconv_open(m_locale.c_str(), "UTF-8"); 233 m_iconv = iconv_open("UTF-8", locale_codeset);
241 if(m_iconv == (iconv_t)(-1)) { 234 if(m_iconv == (iconv_t)(-1)) {
242 cerr<<"FbTk::Font: code error: from "<<m_locale<<" to: UTF-8"<<endl; 235 cerr<<"FbTk::Font: code error: from "<<locale_codeset<<" to: UTF-8"<<endl;
243 // if we failed with iconv then we can't convert 236 // if we failed with iconv then we can't convert
244 // the strings to utf-8, so we disable utf8 mode 237 // the strings to utf-8, so we disable utf8 mode
245 m_utf8mode = false; 238 m_utf8mode = false;
diff --git a/src/FbTk/Font.hh b/src/FbTk/Font.hh
index 1ac2fe0..d994acf 100644
--- a/src/FbTk/Font.hh
+++ b/src/FbTk/Font.hh
@@ -19,7 +19,7 @@
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE. 20// DEALINGS IN THE SOFTWARE.
21 21
22//$Id: Font.hh,v 1.9 2004/08/10 18:08:37 fluxgen Exp $ 22//$Id: Font.hh,v 1.10 2004/08/18 16:30:33 rathnor Exp $
23 23
24#ifndef FBTK_FONT_HH 24#ifndef FBTK_FONT_HH
25#define FBTK_FONT_HH 25#define FBTK_FONT_HH
@@ -34,6 +34,8 @@
34 34
35namespace FbTk { 35namespace FbTk {
36 36
37void fontInit();
38
37class FontImp; 39class FontImp;
38 40
39/** 41/**
@@ -109,7 +111,6 @@ private:
109 int m_shadow_offy; ///< offset x for shadow 111 int m_shadow_offy; ///< offset x for shadow
110 bool m_halo; ///< halo text 112 bool m_halo; ///< halo text
111 std::string m_halo_color; ///< halo color 113 std::string m_halo_color; ///< halo color
112 std::string m_locale; ///< system encoding
113 iconv_t m_iconv; 114 iconv_t m_iconv;
114}; 115};
115 116
diff --git a/src/fluxbox.cc b/src/fluxbox.cc
index 291e62e..001b146 100644
--- a/src/fluxbox.cc
+++ b/src/fluxbox.cc
@@ -22,7 +22,7 @@
22// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23// DEALINGS IN THE SOFTWARE. 23// DEALINGS IN THE SOFTWARE.
24 24
25// $Id: fluxbox.cc,v 1.248 2004/07/15 18:23:03 fluxgen Exp $ 25// $Id: fluxbox.cc,v 1.249 2004/08/18 16:30:33 rathnor Exp $
26 26
27#include "fluxbox.hh" 27#include "fluxbox.hh"
28 28
@@ -452,6 +452,9 @@ Fluxbox::Fluxbox(int argc, char **argv, const char *dpy_name, const char *rcfile
452 "Can not connect to X server.\nMake sure you started X before you start Fluxbox.", 452 "Can not connect to X server.\nMake sure you started X before you start Fluxbox.",
453 "Error message when no X display appears to exist")); 453 "Error message when no X display appears to exist"));
454 } 454 }
455
456 FbTk::fontInit();
457
455 // For KDE dock applets 458 // For KDE dock applets
456 // KDE v1.x 459 // KDE v1.x
457 m_kwm1_dockwindow = XInternAtom(FbTk::App::instance()->display(), 460 m_kwm1_dockwindow = XInternAtom(FbTk::App::instance()->display(),