diff --git a/Sources/libetk/etk/unicode.cpp b/Sources/libetk/etk/unicode.cpp index d33c26d0..3a6bfc65 100644 --- a/Sources/libetk/etk/unicode.cpp +++ b/Sources/libetk/etk/unicode.cpp @@ -24,16 +24,15 @@ // cf : http://unicode.org/fr/charts/symbols.html#CombiningDiacriticalMarks -#include -#include -#include -#include +#include +#include +#include +#include -// /usr/include/gtk-3.0/gdk/gdkkeysyms.h // transform ISO <==> Unicode -void etk::unicode::convertIsoToUnicode(charset_te inputCharset, char input_ISO, uniChar_t & output_Unicode) +void unicode::convertIsoToUnicode(charset_te inputCharset, char input_ISO, uniChar_t & output_Unicode) { switch(inputCharset) { @@ -59,16 +58,16 @@ void etk::unicode::convertIsoToUnicode(charset_te inputCharset, char input_ISO, #endif break; default : - EDN_WARNING("Unknow charset ... " << inputCharset); + TK_WARNING("Unknow charset ... " << inputCharset); output_Unicode = '?'; break; } } -void etk::unicode::convertUnicodeToIso(charset_te inputCharset, uniChar_t input_Unicode, char & output_ISO) +void unicode::convertUnicodeToIso(charset_te inputCharset, uniChar_t input_Unicode, char & output_ISO) { - const int32_t *tmpTable = NULL; + const uniChar_t *tmpTable = NULL; switch(inputCharset) { case EDN_CHARSET_ISO_8859_1: tmpTable = TableIso8859_1; break; @@ -86,7 +85,7 @@ void etk::unicode::convertUnicodeToIso(charset_te inputCharset, uniChar_t input_ case EDN_CHARSET_ISO_8859_14: tmpTable = TableIso8859_14; break; case EDN_CHARSET_ISO_8859_15: tmpTable = TableIso8859_15; break; default : - EDN_WARNING("Unknow charset ... " << inputCharset); + TK_WARNING("Unknow charset ... " << inputCharset); output_ISO = '?'; return; } @@ -100,16 +99,16 @@ void etk::unicode::convertUnicodeToIso(charset_te inputCharset, uniChar_t input_ } -int32_t etk::unicode::convertIsoToUnicode(charset_te inputCharset, etk::VectorType& input_ISO, etk::VectorType& output_Unicode) +int32_t unicode::convertIsoToUnicode(charset_te inputCharset, etk::VectorType& input_ISO, etk::VectorType& output_Unicode) { - EDN_WARNING("TODO : not coded..."); + TK_WARNING("TODO : not coded..."); return 0; } -int32_t etk::unicode::convertUnicodeToIso(charset_te inputCharset, etk::VectorType& input_Unicode, etk::VectorType& output_ISO) +int32_t unicode::convertUnicodeToIso(charset_te inputCharset, etk::VectorType& input_Unicode, etk::VectorType& output_ISO) { - EDN_WARNING("TODO : not coded..."); + TK_WARNING("TODO : not coded..."); return 0; } @@ -141,7 +140,7 @@ static uint32_t unicodeToUtf8(uniChar_t value) output+= (value & 0x00000FC0)<<2; output+= value & 0x0000003F; } else { - EDN_ERROR("NON UTF8 caracter input..."); + TK_ERROR("NON UTF8 caracter input..."); return 0; } //printf("utf8convertion : %d=%08x ==> %08x\n",value, value, output); @@ -150,7 +149,7 @@ static uint32_t unicodeToUtf8(uniChar_t value) // Transform UTF-8 <==> Unicode -void etk::unicode::convertUnicodeToUtf8(uniChar_t input_Unicode, char * output_UTF8) +void unicode::convertUnicodeToUtf8(uniChar_t input_Unicode, char * output_UTF8) { uint32_t value = unicodeToUtf8(input_Unicode); if (0xFF >= value) { @@ -176,7 +175,7 @@ void etk::unicode::convertUnicodeToUtf8(uniChar_t input_Unicode, char * output_U -void etk::unicode::convertUtf8ToUnicode(char * input_UTF8, uniChar_t &output_Unicode) +void unicode::convertUtf8ToUnicode(char * input_UTF8, uniChar_t &output_Unicode) { int32_t len = strlen(input_UTF8); output_Unicode = 0; @@ -203,24 +202,24 @@ void etk::unicode::convertUtf8ToUnicode(char * input_UTF8, uniChar_t &output_Uni } -int32_t etk::unicode::convertUnicodeToUtf8(etk::VectorType& input_Unicode, etk::VectorType& output_UTF8) +int32_t unicode::convertUnicodeToUtf8(etk::VectorType& input_Unicode, etk::VectorType& output_UTF8) { - EDN_WARNING("TODO : not coded..."); + TK_WARNING("TODO : not coded..."); return 0; } -int32_t etk::unicode::convertUtf8ToUnicode(etk::VectorType& input_UTF8, etk::VectorType& output_Unicode) +int32_t unicode::convertUtf8ToUnicode(etk::VectorType& input_UTF8, etk::VectorType& output_Unicode) { - EDN_WARNING("TODO : not coded..."); + TK_WARNING("TODO : not coded..."); return 0; } // Transform ISO <==> UTF-8 -void etk::unicode::convertIsoToUtf8(charset_te inputCharset, char input_ISO, char * output_UTF8) +void unicode::convertIsoToUtf8(charset_te inputCharset, char input_ISO, char * output_UTF8) { - int32_t tmpUnicode; + uniChar_t tmpUnicode; // concert Iso in UniCode convertIsoToUnicode(inputCharset, input_ISO, tmpUnicode ); // convert UniCode in Utf-8 @@ -228,9 +227,9 @@ void etk::unicode::convertIsoToUtf8(charset_te inputCharset, char input_ISO, ch } -void etk::unicode::convertUtf8ToIso(charset_te inputCharset, char * input_UTF8, char & output_ISO) +void unicode::convertUtf8ToIso(charset_te inputCharset, char * input_UTF8, char & output_ISO) { - int32_t tmpUnicode; + uniChar_t tmpUnicode; // convert Utf-8 in UniCode convertUtf8ToUnicode(input_UTF8, tmpUnicode); // concert UniCode in Iso @@ -238,16 +237,16 @@ void etk::unicode::convertUtf8ToIso(charset_te inputCharset, char * input_UTF8, } -int32_t etk::unicode::convertIsoToUtf8(charset_te inputCharset, etk::VectorType& input_ISO, etk::VectorType& output_UTF8) +int32_t unicode::convertIsoToUtf8(charset_te inputCharset, etk::VectorType& input_ISO, etk::VectorType& output_UTF8) { - EDN_WARNING("TODO : not coded..."); + TK_WARNING("TODO : not coded..."); return 0; } -int32_t etk::unicode::convertUtf8ToIso(charset_te inputCharset, etk::VectorType& input_UTF8, etk::VectorType& output_ISO) +int32_t unicode::convertUtf8ToIso(charset_te inputCharset, etk::VectorType& input_UTF8, etk::VectorType& output_ISO) { - EDN_WARNING("TODO : not coded..."); + TK_WARNING("TODO : not coded..."); return 0; } @@ -261,9 +260,9 @@ int32_t etk::unicode::convertUtf8ToIso(charset_te inputCharset, etk::VectorType< * @return --- * */ -void Utf8_SizeElement(const char * data, int32_t lenMax , uint8_t &size, bool &baseValid) +void unicode::Utf8_SizeElement(const char * data, int32_t lenMax , uint8_t &size, bool &baseValid) { - EDN_ASSERT(0 <= lenMax, "size can not be < 0 ..."); + TK_ASSERT(0 <= lenMax, "size can not be < 0 ..."); if (0 > lenMax) { size = 0; baseValid = false; @@ -418,7 +417,7 @@ static uint32_t Utf8_GetValue(UTF8Element_ts &Element) */ -int32_t strUtf8Len(const char *input_UTF8) +int32_t unicode::strUtf8Len(const char *input_UTF8) { int32_t count = 0; int32_t size = strlen(input_UTF8); diff --git a/Sources/libetk/etk/unicodeTable.cpp b/Sources/libetk/etk/unicodeTable.cpp index cee93ce3..b315e1f9 100644 --- a/Sources/libetk/etk/unicodeTable.cpp +++ b/Sources/libetk/etk/unicodeTable.cpp @@ -23,9 +23,9 @@ */ -#include -#include -#include +#include +#include +#include extern "C" { diff --git a/Sources/libetk/file.mk b/Sources/libetk/file.mk index 1417725d..6f24347c 100644 --- a/Sources/libetk/file.mk +++ b/Sources/libetk/file.mk @@ -4,6 +4,8 @@ FILE_LIST = \ etk/Debug.cpp \ etk/DebugInternal.cpp \ etk/Memory.cpp \ + etk/unicode.cpp \ + etk/unicodeTable.cpp \ etk/String.cpp \ etk/Stream.cpp \ etk/File.cpp \ diff --git a/Sources/libewol/ewol/FontFreeType.cpp b/Sources/libewol/ewol/FontFreeType.cpp index fc755172..1d0334b0 100644 --- a/Sources/libewol/ewol/FontFreeType.cpp +++ b/Sources/libewol/ewol/FontFreeType.cpp @@ -27,15 +27,6 @@ #include #include -/* -#include -#include -#if defined(EWOL_X11_MODE__XF86V) -# include -#elif defined(EWOL_X11_MODE__XRENDER) -# include -#endif -*/ #include #if defined(__PLATFORM__Linux) # include @@ -765,7 +756,7 @@ int32_t ewol::DrawText(int32_t fontID, // update texture start X Pos tuA += addElement; } - if (dxB < drawStop.x) { + if (dxB > drawStop.x) { // clip display etkFloat_t drawSize = dxB - drawStop.x; // Update element start display @@ -848,6 +839,40 @@ int32_t ewol::DrawText(int32_t fontID, return sizeOut; } +int32_t ewol::GetWidth(int32_t fontID, const uniChar_t * unicodeString) +{ + if(fontID>=m_listLoadedFont.Size() || fontID < 0) { + EWOL_WARNING("try to display text with an fontID that does not existed " << fontID); + return 0; + } + etk::VectorType & listOfElement = m_listLoadedFont[fontID]->GetRefOnElement(); + uniChar_t * tmpVal = (uniChar_t*)unicodeString; + + etkFloat_t posDrawX = 0.0; + while(*tmpVal != 0) { + int32_t tmpChar = *tmpVal++; + int32_t charIndex; + if (tmpChar >= 0x80) { + charIndex = 0; + } else if (tmpChar < 0x20) { + charIndex = 0; + } else if (tmpChar < 0x80) { + charIndex = tmpChar - 0x1F; + } else { + for (int32_t iii=0x80-0x20; iii < listOfElement.Size(); iii++) { + if (listOfElement[iii].unicodeCharVal == tmpChar) { + charIndex = iii; + break; + } + } + // TODO : Update if possible the mapping + charIndex = 0; + } + posDrawX += listOfElement[charIndex].advance; + } + return posDrawX; +} + int32_t ewol::GetWidth(int32_t fontID, const char * utf8String) {