From 9b8043cf31f2c88855d87eb0a26771048690aa69 Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Thu, 19 Jan 2012 15:56:27 -0200 Subject: [PATCH] fix paste oftexts with accents in x11 --- .../core_fonts/verdana-11px-rounded.otfont | 2 +- src/framework/CMakeLists.txt | 3 ++ src/framework/platform/x11window.cpp | 3 +- src/framework/util/exception.h | 22 ++++++++ src/framework/util/utf8.cpp | 52 +++++++++++++++++++ src/framework/util/utf8.h | 36 +++++++++++++ 6 files changed, 116 insertions(+), 2 deletions(-) create mode 100644 src/framework/util/utf8.cpp create mode 100644 src/framework/util/utf8.h diff --git a/modules/core_fonts/verdana-11px-rounded.otfont b/modules/core_fonts/verdana-11px-rounded.otfont index 6f3a49ae..711b2f33 100644 --- a/modules/core_fonts/verdana-11px-rounded.otfont +++ b/modules/core_fonts/verdana-11px-rounded.otfont @@ -192,7 +192,7 @@ Font 215: 11 216: 9 217: 8 - 218: 8 + 218: 9 219: 8 220: 8 221: 9 diff --git a/src/framework/CMakeLists.txt b/src/framework/CMakeLists.txt index 09a86f1a..54e7f30c 100644 --- a/src/framework/CMakeLists.txt +++ b/src/framework/CMakeLists.txt @@ -129,6 +129,9 @@ SET(framework_SOURCES ${framework_SOURCES} ${CMAKE_CURRENT_LIST_DIR}/application.cpp ${CMAKE_CURRENT_LIST_DIR}/luafunctions.cpp + # framework util + ${CMAKE_CURRENT_LIST_DIR}/util/utf8.cpp + # framework core ${CMAKE_CURRENT_LIST_DIR}/core/logger.cpp ${CMAKE_CURRENT_LIST_DIR}/core/configmanager.cpp diff --git a/src/framework/platform/x11window.cpp b/src/framework/platform/x11window.cpp index 20ba5c32..354cd825 100644 --- a/src/framework/platform/x11window.cpp +++ b/src/framework/platform/x11window.cpp @@ -23,6 +23,7 @@ #include "x11window.h" #include #include +#include #define LSB_BIT_SET(p, n) (p[(n)/8] |= (1 <<((n)%8))) @@ -977,7 +978,7 @@ std::string X11Window::getClipboardText() &dummy, &data); if(result == Success) - clipboardText = (const char*)data; + clipboardText = Fw::utf8StringToLatin1(data); XFree(data); } } diff --git a/src/framework/util/exception.h b/src/framework/util/exception.h index c0561670..f79d19f8 100644 --- a/src/framework/util/exception.h +++ b/src/framework/util/exception.h @@ -1,3 +1,25 @@ +/* + * Copyright (c) 2010-2012 OTClient + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * 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. + */ + #ifndef EXCEPTION_H #define EXCEPTION_H diff --git a/src/framework/util/utf8.cpp b/src/framework/util/utf8.cpp new file mode 100644 index 00000000..f92e120b --- /dev/null +++ b/src/framework/util/utf8.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2010-2012 OTClient + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * 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. + */ + +#include "utf8.h" + +#include +#include + +char Fw::utf8CharToLatin1(uchar *utf8, int *read) +{ + if(utf8[0] == 0xc3) { + *read = 2; + return (char)(64 + utf8[1]); + } else if(utf8[0] == 0xc2) { + *read = 2; + return utf8[1]; + } else { + *read = 1; + return utf8[0]; + } +} + +std::string Fw::utf8StringToLatin1(uchar *utf8) { + std::string out; + int len = strlen((char*)utf8); + for(int i=0; i + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * 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. + */ + +#ifndef UTF8_H +#define UTF8_H + +#include "types.h" +#include + +namespace Fw { + +char utf8CharToLatin1(uchar *utf8, int *read); +std::string utf8StringToLatin1(uchar *utf8); + +}; + +#endif