[DEV] Enable real utf-8 label display

This commit is contained in:
Edouard DUPIN 2013-12-31 22:05:01 +01:00
parent 7bf47a6c12
commit 428111b1d9
8 changed files with 122 additions and 20 deletions

2
build

@ -1 +1 @@
Subproject commit 5079829d049c9233370ffef084cb73c26459ced7 Subproject commit 0e08561a5db3080036ffd546c98dcd0a95d6f4a9

2
external/ejson vendored

@ -1 +1 @@
Subproject commit fbf39d9ac20b7666f907154b58c8f7872bb1e271 Subproject commit 8cca9d9ce2bed7715d3f6febb5f756728e515220

2
external/etk vendored

@ -1 +1 @@
Subproject commit 64d54ca8da34f71c5b1b98f50f6ae3902a136db9 Subproject commit fc6e425cebc2bafc2d4169b8235878ae493e1545

2
monk

@ -1 +1 @@
Subproject commit 3ce578dac170394152c12478d24f8fbc7e8b01f1 Subproject commit 7654eea321b123e9af6b76f0d9e708e92d9448e4

View File

@ -184,7 +184,7 @@ void ewol::compositing::Text::reset(void) {
m_startTextpos = 0; m_startTextpos = 0;
m_stopTextPos = 0; m_stopTextPos = 0;
m_alignement = alignDisable; m_alignement = alignDisable;
m_htmlCurrrentLine = ""; m_htmlCurrrentLine = U"";
m_selectionStartPos = -100; m_selectionStartPos = -100;
m_cursorPos = -100; m_cursorPos = -100;
m_htmlDecoration.clear(); m_htmlDecoration.clear();
@ -385,7 +385,7 @@ void ewol::compositing::Text::parseHtmlNode(exml::Element* _element) {
// nothing to do ... // nothing to do ...
} else if (_element->getType(iii) == exml::typeText) { } else if (_element->getType(iii) == exml::typeText) {
exml::Node* child = _element->getNode(iii); exml::Node* child = _element->getNode(iii);
htmlAddData(child->getValue() ); htmlAddData(std::to_u32string(child->getValue()));
EWOL_VERBOSE("XML add : " << child->getValue()); EWOL_VERBOSE("XML add : " << child->getValue());
continue; continue;
} else if (_element->getType(iii)!=exml::typeElement) { } else if (_element->getType(iii)!=exml::typeElement) {
@ -472,8 +472,16 @@ void ewol::compositing::Text::parseHtmlNode(exml::Element* _element) {
void ewol::compositing::Text::printDecorated(const std::string& _text) { void ewol::compositing::Text::printDecorated(const std::string& _text) {
std::string tmpData("<html>\n<body>\n"); std::string tmpData("<html>\n<body>\n");
tmpData+=_text; tmpData += _text;
tmpData+="\n</body>\n</html>\n"; tmpData += "\n</body>\n</html>\n";
//EWOL_DEBUG("plop : " << tmpData);
printHTML(tmpData);
}
void ewol::compositing::Text::printDecorated(const std::u32string& _text) {
std::u32string tmpData(U"<html>\n<body>\n");
tmpData += _text;
tmpData += U"\n</body>\n</html>\n";
//EWOL_DEBUG("plop : " << tmpData); //EWOL_DEBUG("plop : " << tmpData);
printHTML(tmpData); printHTML(tmpData);
} }
@ -506,6 +514,34 @@ void ewol::compositing::Text::printHTML(const std::string& _text) {
htmlFlush(); htmlFlush();
} }
void ewol::compositing::Text::printHTML(const std::u32string& _text) {
exml::Document doc;
// reset parameter :
m_htmlDecoTmp.m_colorBg = etk::color::none;
m_htmlDecoTmp.m_colorFg = etk::color::black;
m_htmlDecoTmp.m_mode = ewol::font::Regular;
// TODO : Create an instance of xml parser to manage std::u32string...
if (doc.parse(std::to_string(_text)) == false) {
EWOL_ERROR( "can not load XML: PARSING error: Decorated text ");
return;
}
exml::Element* root = (exml::Element*)doc.getNamed( "html" );
if (root == NULL) {
EWOL_ERROR( "can not load XML: main node not find: \"html\"");
doc.display();
return;
}
exml::Element* bodyNode = (exml::Element*)root->getNamed( "body" );
if (root == NULL) {
EWOL_ERROR( "can not load XML: main node not find: \"body\"");
return;
}
(void)parseHtmlNode(bodyNode);
htmlFlush();
}
void ewol::compositing::Text::print(const std::string& _text, const std::vector<TextDecoration>& _decoration) { void ewol::compositing::Text::print(const std::string& _text, const std::vector<TextDecoration>& _decoration) {
if (m_font == NULL) { if (m_font == NULL) {
EWOL_ERROR("Font Id is not corectly defined"); EWOL_ERROR("Font Id is not corectly defined");
@ -1109,6 +1145,37 @@ vec3 ewol::compositing::Text::calculateSizeHTML(const std::string& _text) {
m_sizeDisplayStop.z()-m_sizeDisplayStart.z()); m_sizeDisplayStop.z()-m_sizeDisplayStart.z());
} }
vec3 ewol::compositing::Text::calculateSizeHTML(const std::u32string& _text) {
// remove intermediate result
reset();
//EWOL_DEBUG(" 0 size for=\n" << text);
// disable display system
m_needDisplay = false;
setPos(vec3(0,0,0) );
// same as print without the end display ...
printHTML(_text);
//EWOL_DEBUG(" 1 Start pos=" << m_sizeDisplayStart);
//EWOL_DEBUG(" 1 Stop pos=" << m_sizeDisplayStop);
// get the last elements
m_sizeDisplayStop.setValue(etk_max(m_position.x(), m_sizeDisplayStop.x()) ,
etk_max(m_position.y(), m_sizeDisplayStop.y()) ,
0);
m_sizeDisplayStart.setValue(etk_min(m_position.x(), m_sizeDisplayStart.x()) ,
etk_min(m_position.y(), m_sizeDisplayStart.y()) ,
0);
//EWOL_DEBUG(" 2 Start pos=" << m_sizeDisplayStart);
//EWOL_DEBUG(" 2 Stop pos=" << m_sizeDisplayStop);
// set back the display system
m_needDisplay = true;
return vec3( m_sizeDisplayStop.x()-m_sizeDisplayStart.x(),
m_sizeDisplayStop.y()-m_sizeDisplayStart.y(),
m_sizeDisplayStop.z()-m_sizeDisplayStart.z());
}
vec3 ewol::compositing::Text::calculateSizeDecorated(const std::string& _text) { vec3 ewol::compositing::Text::calculateSizeDecorated(const std::string& _text) {
if (_text.size() == 0) { if (_text.size() == 0) {
return vec3(0,0,0); return vec3(0,0,0);
@ -1120,6 +1187,17 @@ vec3 ewol::compositing::Text::calculateSizeDecorated(const std::string& _text) {
return tmpVal; return tmpVal;
} }
vec3 ewol::compositing::Text::calculateSizeDecorated(const std::u32string& _text) {
if (_text.size() == 0) {
return vec3(0,0,0);
}
std::u32string tmpData(U"<html><body>\n");
tmpData += _text;
tmpData += U"\n</body></html>\n";
vec3 tmpVal = calculateSizeHTML(tmpData);
return tmpVal;
}
vec3 ewol::compositing::Text::calculateSize(const std::string& _text) { vec3 ewol::compositing::Text::calculateSize(const std::string& _text) {
if (m_font == NULL) { if (m_font == NULL) {
EWOL_ERROR("Font Id is not corectly defined"); EWOL_ERROR("Font Id is not corectly defined");
@ -1136,6 +1214,22 @@ vec3 ewol::compositing::Text::calculateSize(const std::string& _text) {
return outputSize; return outputSize;
} }
vec3 ewol::compositing::Text::calculateSize(const std::u32string& _text) {
if (m_font == NULL) {
EWOL_ERROR("Font Id is not corectly defined");
return vec3(0,0,0);
}
vec3 outputSize(0, 0, 0);
for(auto element : _text) {
vec3 tmpp = calculateSize(element);
if (outputSize.y() == 0) {
outputSize.setY(tmpp.y());
}
outputSize.setX( outputSize.x() + tmpp.x());
}
return outputSize;
}
vec3 ewol::compositing::Text::calculateSize(const char32_t& _charcode) { vec3 ewol::compositing::Text::calculateSize(const char32_t& _charcode) {
if (m_font == NULL) { if (m_font == NULL) {
EWOL_ERROR("Font Id is not corectly defined"); EWOL_ERROR("Font Id is not corectly defined");
@ -1296,10 +1390,10 @@ bool ewol::compositing::Text::extrapolateLastId(const std::u32string& _text,
} }
} }
void ewol::compositing::Text::htmlAddData(const std::string& _data) { void ewol::compositing::Text::htmlAddData(const std::u32string& _data) {
if( m_htmlCurrrentLine.size()>0 if( m_htmlCurrrentLine.size()>0
&& m_htmlCurrrentLine[m_htmlCurrrentLine.size()-1] != ' ') { && m_htmlCurrrentLine[m_htmlCurrrentLine.size()-1] != ' ') {
m_htmlCurrrentLine+=" "; m_htmlCurrrentLine += U" ";
if(m_htmlDecoration.size()>0) { if(m_htmlDecoration.size()>0) {
TextDecoration tmp = m_htmlDecoration[m_htmlDecoration.size()-1]; TextDecoration tmp = m_htmlDecoration[m_htmlDecoration.size()-1];
m_htmlDecoration.push_back(tmp); m_htmlDecoration.push_back(tmp);
@ -1317,7 +1411,7 @@ void ewol::compositing::Text::htmlFlush(void) {
if (m_htmlCurrrentLine.size()>0) { if (m_htmlCurrrentLine.size()>0) {
print(m_htmlCurrrentLine, m_htmlDecoration); print(m_htmlCurrrentLine, m_htmlDecoration);
} }
m_htmlCurrrentLine = ""; m_htmlCurrrentLine = U"";
m_htmlDecoration.clear(); m_htmlDecoration.clear();
} }

View File

@ -284,6 +284,8 @@ namespace ewol {
* @TODO : implementation not done .... * @TODO : implementation not done ....
*/ */
void printDecorated(const std::string& _text); void printDecorated(const std::string& _text);
//! @previous
void printDecorated(const std::u32string& _text);
/** /**
* @brief display a compleat string in the current element with the generic decoration specification. (basic html data) * @brief display a compleat string in the current element with the generic decoration specification. (basic html data)
* *
@ -318,15 +320,15 @@ namespace ewol {
* @TODO : implementation not done .... * @TODO : implementation not done ....
*/ */
void printHTML(const std::string& _text); void printHTML(const std::string& _text);
//! @previous
void printHTML(const std::u32string& _text);
/** /**
* @brief display a compleat string in the current element whith specific decorations (advence mode). * @brief display a compleat string in the current element whith specific decorations (advence mode).
* @param[in] _text The string to display. * @param[in] _text The string to display.
* @param[in] _decoration The text decoration for the text that might be display (if the vector is smaller, the last parameter is get) * @param[in] _decoration The text decoration for the text that might be display (if the vector is smaller, the last parameter is get)
*/ */
void print(const std::string& _text, const std::vector<TextDecoration>& _decoration); void print(const std::string& _text, const std::vector<TextDecoration>& _decoration);
/** //! @previous
* @previous
*/
void print(const std::u32string& _text, const std::vector<TextDecoration>& _decoration); void print(const std::u32string& _text, const std::vector<TextDecoration>& _decoration);
/** /**
* @brief display the current char in the current element (note that the kerning is availlable if the position is not changed) * @brief display the current char in the current element (note that the kerning is availlable if the position is not changed)
@ -367,18 +369,24 @@ namespace ewol {
* @return The theoric size used. * @return The theoric size used.
*/ */
vec3 calculateSizeHTML(const std::string& _text); vec3 calculateSizeHTML(const std::string& _text);
//!@previous
vec3 calculateSizeHTML(const std::u32string& _text);
/** /**
* @brief calculate a theoric text size * @brief calculate a theoric text size
* @param[in] _text The string to calculate dimention. * @param[in] _text The string to calculate dimention.
* @return The theoric size used. * @return The theoric size used.
*/ */
vec3 calculateSizeDecorated(const std::string& _text); vec3 calculateSizeDecorated(const std::string& _text);
//!@previous
vec3 calculateSizeDecorated(const std::u32string& _text);
/** /**
* @brief calculate a theoric text size * @brief calculate a theoric text size
* @param[in] _text The string to calculate dimention. * @param[in] _text The string to calculate dimention.
* @return The theoric size used. * @return The theoric size used.
*/ */
vec3 calculateSize(const std::string& _text); vec3 calculateSize(const std::string& _text);
//!@previous
vec3 calculateSize(const std::u32string& _text);
/** /**
* @brief calculate a theoric charcode size * @brief calculate a theoric charcode size
* @param[in] _charcode The µUnicode value to calculate dimention. * @param[in] _charcode The µUnicode value to calculate dimention.
@ -410,14 +418,14 @@ namespace ewol {
bool extrapolateLastId(const std::u32string& _text, const int32_t _start, int32_t& _stop, int32_t& _space, int32_t& _freeSpace); bool extrapolateLastId(const std::u32string& _text, const int32_t _start, int32_t& _stop, int32_t& _space, int32_t& _freeSpace);
private: private:
// this section is reserved for HTML parsing and display: // this section is reserved for HTML parsing and display:
std::string m_htmlCurrrentLine; //!< current line for HTML display std::u32string m_htmlCurrrentLine; //!< current line for HTML display
std::vector<TextDecoration> m_htmlDecoration; //!< current decoration for the HTML display std::vector<TextDecoration> m_htmlDecoration; //!< current decoration for the HTML display
TextDecoration m_htmlDecoTmp; //!< current decoration TextDecoration m_htmlDecoTmp; //!< current decoration
/** /**
* @brief add a line with the current m_htmlDecoTmp decoration * @brief add a line with the current m_htmlDecoTmp decoration
* @param[in] _data The cuurent data to add. * @param[in] _data The cuurent data to add.
*/ */
void htmlAddData(const std::string& _data); void htmlAddData(const std::u32string& _data);
/** /**
* @brief draw the current line * @brief draw the current line
*/ */

View File

@ -28,7 +28,7 @@ void ewol::widget::Label::init(ewol::widget::Manager& _widgetManager) {
ewol::widget::Label::Label(std::string _newLabel) { ewol::widget::Label::Label(std::string _newLabel) {
addObjectType("ewol::widget::Label"); addObjectType("ewol::widget::Label");
m_label = _newLabel; m_label = std::to_u32string(_newLabel);
addEventId(eventPressed); addEventId(eventPressed);
setCanHaveFocus(false); setCanHaveFocus(false);
registerConfig(configValue, "string", NULL, "displayed value string"); // TODO : do not store in attibute... registerConfig(configValue, "string", NULL, "displayed value string"); // TODO : do not store in attibute...
@ -51,13 +51,13 @@ void ewol::widget::Label::calculateMinMaxSize(void) {
} }
void ewol::widget::Label::setLabel(const std::string& _newLabel) { void ewol::widget::Label::setLabel(const std::string& _newLabel) {
m_label = _newLabel; m_label = std::to_u32string(_newLabel);
markToRedraw(); markToRedraw();
requestUpdateSize(); requestUpdateSize();
} }
std::string ewol::widget::Label::getLabel(void) const { std::string ewol::widget::Label::getLabel(void) const {
return m_label; return std::to_string(m_label);
} }
void ewol::widget::Label::onDraw(void) { void ewol::widget::Label::onDraw(void) {

View File

@ -32,7 +32,7 @@ namespace ewol {
static void init(ewol::widget::Manager& _widgetManager); static void init(ewol::widget::Manager& _widgetManager);
private: private:
ewol::compositing::Text m_text; //!< Compositing text element. ewol::compositing::Text m_text; //!< Compositing text element.
std::string m_label; //!< decorated text to display. std::u32string m_label; //!< decorated text to display.
public: public:
/** /**
* @brief Constructor * @brief Constructor