Uniformisation of the UNICODE in the soft

This commit is contained in:
Edouard Dupin 2012-02-13 18:03:28 +01:00
parent d1677a10ba
commit 61f296a246
11 changed files with 121 additions and 167 deletions

View File

@ -211,7 +211,53 @@ int32_t unicode::convertUnicodeToUtf8(etk::VectorType<uniChar_t>& input_Unicode,
int32_t unicode::convertUtf8ToUnicode(etk::VectorType<char>& input_UTF8, etk::VectorType<uniChar_t>& output_Unicode)
{
TK_WARNING("TODO : not coded...");
bool baseValid;
char tmpData[20];
int32_t pos = 0;
while (pos < input_UTF8.Size()) {
int32_t lenMax = input_UTF8.Size() - pos;
//4 case
if( 1<=lenMax
&& 0x00 == (input_UTF8[pos+0] & 0x80) )
{
tmpData[0] = input_UTF8[pos+0];
tmpData[1] = '\0';
pos += 1;
} else if( 2<=lenMax
&& 0xC0 == (input_UTF8[pos+0] & 0xE0)
&& 0x80 == (input_UTF8[pos+1] & 0xC0) ) {
tmpData[0] = input_UTF8[pos+0];
tmpData[1] = input_UTF8[pos+1];
tmpData[2] = '\0';
pos += 1;
} else if( 3<=lenMax
&& 0xE0 == (input_UTF8[pos+0] & 0xF0)
&& 0x80 == (input_UTF8[pos+1] & 0xC0)
&& 0x80 == (input_UTF8[pos+2] & 0xC0)) {
tmpData[0] = input_UTF8[pos+0];
tmpData[1] = input_UTF8[pos+1];
tmpData[2] = input_UTF8[pos+2];
tmpData[3] = '\0';
pos += 1;
} else if( 4<=lenMax
&& 0xF0 == (input_UTF8[pos+0] & 0xF8)
&& 0x80 == (input_UTF8[pos+1] & 0xC0)
&& 0x80 == (input_UTF8[pos+2] & 0xC0)
&& 0x80 == (input_UTF8[pos+3] & 0xC0)) {
tmpData[0] = input_UTF8[pos+0];
tmpData[1] = input_UTF8[pos+1];
tmpData[2] = input_UTF8[pos+2];
tmpData[3] = input_UTF8[pos+3];
tmpData[4] = '\0';
pos += 1;
} else {
tmpData[0] = '\0';
pos += 1;
}
uniChar_t tmpUnicode;
convertUtf8ToUnicode(tmpData, tmpUnicode);
output_Unicode.PushBack(tmpUnicode);
}
return 0;
}

View File

@ -25,6 +25,7 @@
#include <ewol/Font.h>
#include <ewol/Texture.h>
#include <etk/unicode.h>
#include <etk/VectorType.h>
#include <ewol/importgl.h>
@ -207,7 +208,7 @@ class FTFontInternal
} else {
// all OK
EWOL_INFO("load font : \"" << m_fileName << "\" ");
Display();
//Display();
}
}
~FTFontInternal(void)
@ -234,11 +235,11 @@ class FTFontInternal
// a small shortcut
FT_GlyphSlot slot = m_fftFace->glyph;
/*
EWOL_DEBUG("Max size for ths glyph size=" << size <<
" is (" << m_fftFace->max_advance_width << "," << m_fftFace->max_advance_height << ")" <<
"?=(" << (m_fftFace->max_advance_width>>6) << "," << (m_fftFace->max_advance_height>>6) << ")");
*/
// retrieve glyph index from character code
int32_t glyph_index = FT_Get_Char_Index(m_fftFace, 'A' );
// load glyph image into the slot (erase previous one)
@ -265,12 +266,6 @@ class FTFontInternal
}
int32_t nbLine = (nbElement / nbRaws) + 1;
int32_t textureHeight = nextP2(nbLine*glyphMaxHeight);
/*if (textureWidth < textureHeight) {
textureWidth = textureHeight;
}
if (textureWidth > textureHeight) {
textureHeight = textureWidth;
}*/
EWOL_DEBUG("Generate a text texture for char(" << nbRaws << "," << nbLine << ") with size=(" << textureWidth << "," << textureHeight << ")");
// Allocate Memory For The Texture Data.
@ -303,6 +298,11 @@ class FTFontInternal
*/
// retrieve glyph index from character code
glyph_index = FT_Get_Char_Index(m_fftFace, listElement[iii].unicodeCharVal );
/*
if (glyph_index < 1) {
EWOL_WARNING("Can not load Glyph : " << listElement[iii].unicodeCharVal);
}
*/
// load glyph image into the slot (erase previous one)
error = FT_Load_Glyph(m_fftFace, // handle to face object
glyph_index, // glyph index
@ -326,12 +326,12 @@ class FTFontInternal
EWOL_ASSERT(tmpLineStartPos+tmpHeight < textureHeight, "Texture dimention estimatiuon error for the current Font");
}
/*
EWOL_VERBOSE("elem=" << listElement[iii].unicodeCharVal
<<" size=(" << tmpWidth << "," << tmpHeight << ")"
<< " for bitmap (left=" << slot->bitmap_left << ",top=" << slot->bitmap_top << ")");
EWOL_VERBOSE(" BEARING=(" << (slot->metrics.horiBearingX>>6) << "," << (slot->metrics.vertBearingY>>6) << ")" );
*/
for(int32_t j=0; j < tmpHeight;j++) {
for(int32_t i=0; i < tmpWidth; i++){
int32_t position = (tmpRowStartPos + i )
@ -404,10 +404,14 @@ class FTFont{
freeTypeFontElement_ts tmpchar1;
tmpchar1.unicodeCharVal = 0;
m_elements.PushBack(tmpchar1);
for (int32_t iii=0x20; iii<0x7F; iii++) {
// TODO : dynamic generation of this : expected minimum of 0x20 => 0x7F ....
for (int32_t iii=0x20; iii<0xFF; iii++) {
freeTypeFontElement_ts tmpchar;
tmpchar.unicodeCharVal = iii;
m_elements.PushBack(tmpchar);
if (0x7F == iii) {
iii = 0x9F;
}
}
m_size = size;
m_listLoadedTTFont[m_trueTypeFontId]->GenerateBitmapFont(m_size, m_lineHeight, m_textureId, m_elements);
@ -569,6 +573,7 @@ void ewol::UnloadFont(int32_t id)
}
// TODO : Change this code ....
int32_t ewol::DrawText(int32_t fontID,
coord2D_ts & drawPosition,
coord2D_ts & clipSize,
@ -577,115 +582,23 @@ int32_t ewol::DrawText(int32_t fontID,
etk::VectorType<coord2D_ts> & coord,
etk::VectorType<texCoord_ts> & coordTex)
{
if(fontID>=m_listLoadedFont.Size() || fontID < 0) {
EWOL_WARNING("try to display text with an fontID that does not existed " << fontID);
return 0;
// TODO : Remove this part of code ... ==> how???
int32_t nbElement = strlen(utf8String);
etk::VectorType<char> tmpStruct;
for (int32_t iii=0; iii<nbElement; iii++) {
tmpStruct.PushBack(utf8String[iii]);
}
etk::VectorType<freeTypeFontElement_ts> & listOfElement = m_listLoadedFont[fontID]->GetRefOnElement();
char * tmpVal = (char*)utf8String;
fontTextureId = m_listLoadedFont[fontID]->GetOglId();
int32_t fontSize = m_listLoadedFont[fontID]->GetSize();
clipping_ts tmpClip;
tmpClip.x = 0;
tmpClip.y = 0;
tmpClip.w = clipSize.x;
tmpClip.h = clipSize.y;
etkFloat_t posDrawX = drawPosition.x;
while(*tmpVal != 0) {
uint32_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;
}
etkFloat_t sizeWidth = listOfElement[charIndex].advance;
// check the clipping
if (clipSize.x>0 && posDrawX+sizeWidth > clipSize.x) {
// TODO : Create a better clipping methode ...
break;
}
// 0x01 == 0x20 == ' ';
if (tmpChar != 0x01) {
/* Bitmap position
* 0------1
* | |
* | |
* 3------2
*/
coord2D_ts bitmapDrawPos[4];
bitmapDrawPos[0].x = posDrawX + listOfElement[charIndex].bearing.x;
bitmapDrawPos[1].x = posDrawX + listOfElement[charIndex].bearing.x + listOfElement[charIndex].size.x;
bitmapDrawPos[2].x = posDrawX + listOfElement[charIndex].bearing.x + listOfElement[charIndex].size.x;
bitmapDrawPos[3].x = posDrawX + listOfElement[charIndex].bearing.x;
bitmapDrawPos[0].y = drawPosition.y + fontSize - listOfElement[charIndex].bearing.y;
bitmapDrawPos[1].y = drawPosition.y + fontSize - listOfElement[charIndex].bearing.y;
bitmapDrawPos[2].y = drawPosition.y + fontSize - listOfElement[charIndex].bearing.y + listOfElement[charIndex].size.y;
bitmapDrawPos[3].y = drawPosition.y + fontSize - listOfElement[charIndex].bearing.y + listOfElement[charIndex].size.y;
/* texture Position :
* 0------1
* | |
* | |
* 3------2
*/
texCoord_ts texturePos[4];
texturePos[0].u = listOfElement[charIndex].posStart.u;
texturePos[1].u = listOfElement[charIndex].posStop.u;
texturePos[2].u = listOfElement[charIndex].posStop.u;
texturePos[3].u = listOfElement[charIndex].posStart.u;
texturePos[0].v = listOfElement[charIndex].posStart.v;
texturePos[1].v = listOfElement[charIndex].posStart.v;
texturePos[2].v = listOfElement[charIndex].posStop.v;
texturePos[3].v = listOfElement[charIndex].posStop.v;
// NOTE : Android does not support the Quads elements ...
/* Step 1 :
* ********
* ******
* ****
* **
*
*/
// set texture coordonates :
coordTex.PushBack(texturePos[0]);
coordTex.PushBack(texturePos[1]);
coordTex.PushBack(texturePos[2]);
// set display positions :
coord.PushBack(bitmapDrawPos[0]);
coord.PushBack(bitmapDrawPos[1]);
coord.PushBack(bitmapDrawPos[2]);
/* Step 2 :
*
* **
* ****
* ******
* ********
*/
// set texture coordonates :
coordTex.PushBack(texturePos[0]);
coordTex.PushBack(texturePos[2]);
coordTex.PushBack(texturePos[3]);
// set display positions :
coord.PushBack(bitmapDrawPos[0]);
coord.PushBack(bitmapDrawPos[2]);
coord.PushBack(bitmapDrawPos[3]);
}
posDrawX += sizeWidth;
}
int32_t sizeOut = posDrawX - drawPosition.x;
drawPosition.x = posDrawX;
return sizeOut;
etk::VectorType<uniChar_t> outputData;
unicode::convertUtf8ToUnicode(tmpStruct, outputData);
outputData.PushBack(0);
return DrawText(fontID, drawPosition, tmpClip, &outputData[0], fontTextureId, coord, coordTex);
}
int32_t ewol::DrawText(int32_t fontID,
@ -711,21 +624,18 @@ int32_t ewol::DrawText(int32_t fontID,
while(*tmpVal != 0) {
uint32_t tmpChar = *tmpVal++;
int32_t charIndex;
if (tmpChar >= 0x80) {
charIndex = 0;
} else if (tmpChar < 0x20) {
if (tmpChar < 0x20) {
charIndex = 0;
} else if (tmpChar < 0x80) {
charIndex = tmpChar - 0x1F;
} else {
charIndex = 0;
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;
}
// 0x01 == 0x20 == ' ';
if (tmpChar != 0x01) {

View File

@ -279,7 +279,7 @@ namespace ewol {
// -- Keboard event (when one is present or when a graphical is present
// ----------------------------------------------------------------------------------------------------------------
public:
virtual bool OnEventKb(eventKbType_te typeEvent, char UTF8_data[UTF8_MAX_SIZE]) { return false; };
virtual bool OnEventKb(eventKbType_te typeEvent, uniChar_t unicodeData) { return false; };
virtual bool OnEventKbMove(eventKbType_te typeEvent, eventKbMoveType_te moveTypeEvent) { return false; };

View File

@ -144,9 +144,7 @@ static void* BaseAppEntry(void* param)
EWOL_DEBUG("Receive MSG : THREAD_KEYBORAD_KEY");
{
eventKeyboardKey_ts * tmpData = (eventKeyboardKey_ts*)data.data;
etk::String keyInput = "a";
keyInput.c_str()[0] = tmpData->myChar;
guiAbstraction::SendKeyboardEvent(tmpData->isDown, keyInput);
guiAbstraction::SendKeyboardEvent(tmpData->isDown, tmpData->myChar);
}
break;
case THREAD_KEYBORAD_MOVE:
@ -283,11 +281,11 @@ void EWOL_ThreadEventInputState(int pointerID, bool isUp, float x, float y )
ewol::threadMsg::SendMessage(androidJniMsg, THREAD_INPUT_STATE, ewol::threadMsg::MSG_PRIO_LOW, &tmpData, sizeof(eventInputState_ts) );
}
void EWOL_ThreadKeyboardEvent(bool isDown, etk::String &keyInput)
void EWOL_ThreadKeyboardEvent(bool isDown, uniChar_t keyInput)
{
eventKeyboardKey_ts tmpData;
tmpData.isDown = isDown;
tmpData.myChar = keyInput.c_str()[0];
tmpData.myChar = keyInput;
ewol::threadMsg::SendMessage(androidJniMsg, THREAD_KEYBORAD_KEY, ewol::threadMsg::MSG_PRIO_LOW, &tmpData, sizeof(eventKeyboardKey_ts) );
}

View File

@ -37,7 +37,7 @@ void EWOL_ThreadSetArchiveDir(int mode, const char* str);
void EWOL_ThreadResize(int w, int h );
void EWOL_ThreadEventInputMotion(int pointerID, float x, float y);
void EWOL_ThreadEventInputState(int pointerID, bool isUp, float x, float y);
void EWOL_ThreadKeyboardEvent(bool isDown, etk::String &keyInput);
void EWOL_ThreadKeyboardEvent(bool isDown, uniChar_t keyInput);
void EWOL_ThreadKeyboardEventMove(bool isDown, ewol::eventKbMoveType_te &keyInput);

View File

@ -71,17 +71,17 @@ void guiAbstraction::ForceRedrawAll(void)
}
void guiAbstraction::SendKeyboardEvent(bool isDown, etk::String &keyInput)
void guiAbstraction::SendKeyboardEvent(bool isDown, uniChar_t keyInput)
{
// Get the current Focused Widget :
ewol::Widget * tmpWidget = ewol::widgetManager::FocusGet();
if (NULL != tmpWidget) {
if(true == isDown) {
EWOL_VERBOSE("X11 PRESSED : \"" << keyInput << "\" size=" << keyInput.Size());
tmpWidget->OnEventKb(ewol::EVENT_KB_TYPE_DOWN, keyInput.c_str());
EWOL_VERBOSE("GUI PRESSED : \"" << keyInput << "\"");
tmpWidget->OnEventKb(ewol::EVENT_KB_TYPE_DOWN, keyInput);
} else {
EWOL_VERBOSE("X11 Release : \"" << keyInput << "\" size=" << keyInput.Size());
tmpWidget->OnEventKb(ewol::EVENT_KB_TYPE_UP, keyInput.c_str());
EWOL_VERBOSE("GUI Release : \"" << keyInput << "\"");
tmpWidget->OnEventKb(ewol::EVENT_KB_TYPE_UP, keyInput);
}
}
}

View File

@ -45,7 +45,7 @@ namespace guiAbstraction
void KeyboardShow(ewol::keyboardMode_te mode);
void KeyboardHide(void);
void ForceRedrawAll(void);
void SendKeyboardEvent(bool isDown, etk::String &keyInput);
void SendKeyboardEvent(bool isDown, uniChar_t keyInput);
void SendKeyboardEventMove(bool isDown, ewol::eventKbMoveType_te &keyInput);
};

View File

@ -25,6 +25,7 @@
#include <ewol/Debug.h>
#include <etk/String.h>
#include <etk/unicode.h>
#include <ewol/WidgetManager.h>
#include <ewol/base/gui.h>
@ -585,14 +586,10 @@ void X11_Run(void)
case 91: // Suppr on keypad
find = false;
{
char buf[2];
buf[0] = 0x7F;
buf[1] = 0x00;
etk::String tmpData = buf;
if(event.type == KeyPress) {
EWOL_ThreadKeyboardEvent(true, tmpData);
EWOL_ThreadKeyboardEvent(true, 0x0000007F);
} else {
EWOL_ThreadKeyboardEvent(false, tmpData);
EWOL_ThreadKeyboardEvent(false, 0x0000007F);
}
}
default:
@ -603,17 +600,21 @@ void X11_Run(void)
XComposeStatus status;
int count = XLookupString(&event.xkey, buf, 10, &keysym, &status);
buf[count] = '\0';
EWOL_WARNING("Unknow event Key : " << event.xkey.keycode << " char=" << (int32_t)buf[0]);
// Replace \r error ...
if (buf[0] == '\r') {
buf[0] = '\n';
buf[1] = '\0';
}
if (count>0) {
etk::String tmpData = buf;
// transform iun unicode
uniChar_t unicodeValue;
//unicode::convertUtf8ToUnicode(buf, unicodeValue);
unicode::convertIsoToUnicode(unicode::EDN_CHARSET_ISO_8859_15, buf[0], unicodeValue);
EWOL_INFO("event Key : " << event.xkey.keycode << " char=\"" << buf << "\"'len=" << strlen(buf) << " unicode=" << unicodeValue);
if(event.type == KeyPress) {
EWOL_ThreadKeyboardEvent(true, tmpData);
EWOL_ThreadKeyboardEvent(true, unicodeValue);
} else {
EWOL_ThreadKeyboardEvent(false, tmpData);
EWOL_ThreadKeyboardEvent(false, unicodeValue);
}
} else {
EWOL_WARNING("Unknow event Key : " << event.xkey.keycode);

View File

@ -23,6 +23,7 @@
*/
#include <etk/unicode.h>
#include <ewol/widget/Entry.h>
#include <ewol/OObject.h>
#include <ewol/WidgetManager.h>
@ -173,24 +174,19 @@ bool ewol::Entry::OnEventInput(int32_t IdInput, eventInputType_te typeEvent, etk
}
bool ewol::Entry::OnEventKb(eventKbType_te typeEvent, char UTF8_data[UTF8_MAX_SIZE])
bool ewol::Entry::OnEventKb(eventKbType_te typeEvent, uniChar_t unicodeData)
{
if( UTF8_data != NULL
&& typeEvent == ewol::EVENT_KB_TYPE_DOWN) {
//EWOL_DEBUG("Entry input data ... : \"" << UTF8_data << "\" size=" << strlen(UTF8_data) << " data=" << (int32_t)UTF8_data[0] );
return GenEventInputExternal(ewolEventEntryEnter, -1, -1);
if (0x7F == UTF8_data[0]) {
if (m_data.Size() > 0) {
// SUPPR
}
} else if (0x08 == UTF8_data[0]) {
EWOL_DEBUG("The entry is an UTF8 string ...");
EWOL_TODO("later...");
if (m_data.Size() > 0) {
// DEL :
m_data.Remove(m_data.Size()-1, 1);
}
} else if(UTF8_data[0] >= 20) {
if( typeEvent == ewol::EVENT_KB_TYPE_DOWN) {
//EWOL_DEBUG("Entry input data ... : \"" << unicodeData << "\" " );
//return GenEventInputExternal(ewolEventEntryEnter, -1, -1);
if (0x7F == unicodeData) {
// SUPPR
} else if (0x08 == unicodeData) {
// DEL :
m_data.Remove(m_data.Size()-1, 1);
} else if(unicodeData >= 20) {
char UTF8_data[50];
unicode::convertUnicodeToUtf8(unicodeData, UTF8_data);
m_data += UTF8_data;
}
UpdateTextPosition();

View File

@ -62,7 +62,7 @@ namespace ewol {
virtual void OnRegenerateDisplay(void);
public:
virtual bool OnEventInput(int32_t IdInput, eventInputType_te typeEvent, etkFloat_t x, etkFloat_t y);
virtual bool OnEventKb(eventKbType_te typeEvent, char UTF8_data[UTF8_MAX_SIZE]);
virtual bool OnEventKb(eventKbType_te typeEvent, uniChar_t unicodeData);
protected:
virtual void OnGetFocus(void);
virtual void OnLostFocus(void);

View File

@ -33,6 +33,7 @@
#include <ewol/WidgetManager.h>
//#include <etk/Vector.h>
#include <etk/VectorType.h>
#include <etk/unicode.h>
#include <ewol/ewol.h>
#include <ewol/base/gui.h>
@ -192,8 +193,10 @@ bool ewol::Keyboard::OnEventAreaExternal(int32_t widgetID, const char * generate
if (data == "TAB") {
data = "\t";
}
guiAbstraction::SendKeyboardEvent(true, data);
guiAbstraction::SendKeyboardEvent(false, data);
uniChar_t unicodeValue;
unicode::convertUtf8ToUnicode(data.c_str(), unicodeValue);
guiAbstraction::SendKeyboardEvent(true, unicodeValue);
guiAbstraction::SendKeyboardEvent(false, unicodeValue);
return true;
} else if (ewolEventKeyboardHide == generateEventId) {
Hide();