diff --git a/cocos/ui/UIRichText.cpp b/cocos/ui/UIRichText.cpp index 72e604eb2ed0..dd54598db17a 100755 --- a/cocos/ui/UIRichText.cpp +++ b/cocos/ui/UIRichText.cpp @@ -842,6 +842,7 @@ ValueMap MyXMLVisitor::tagAttrMapWithXMLElement(const char ** attrs) const std::string RichText::KEY_VERTICAL_SPACE("KEY_VERTICAL_SPACE"); const std::string RichText::KEY_WRAP_MODE("KEY_WRAP_MODE"); +const std::string RichText::KEY_WORD_SEPARATOR_MODE("KEY_WORD_SEPARATOR_MODE"); const std::string RichText::KEY_HORIZONTAL_ALIGNMENT("KEY_HORIZONTAL_ALIGNMENT"); const std::string RichText::KEY_FONT_COLOR_STRING("KEY_FONT_COLOR_STRING"); const std::string RichText::KEY_FONT_SIZE("KEY_FONT_SIZE"); @@ -886,6 +887,7 @@ RichText::RichText() { _defaults[KEY_VERTICAL_SPACE] = 0.0f; _defaults[KEY_WRAP_MODE] = static_cast(WrapMode::WRAP_PER_WORD); + _defaults[KEY_WORD_SEPARATOR_MODE] = static_cast(WordSeparatorMode::WordSeparatorBasedOnDevice); _defaults[KEY_HORIZONTAL_ALIGNMENT] = static_cast(HorizontalAlignment::LEFT); _defaults[KEY_FONT_COLOR_STRING] = "#ffffff"; _defaults[KEY_FONT_SIZE] = 12.0f; @@ -1007,6 +1009,20 @@ void RichText::setWrapMode(RichText::WrapMode wrapMode) } } +RichText::WordSeparatorMode RichText::getWordSeparatorMode() +{ + return static_cast(_defaults.at(KEY_WORD_SEPARATOR_MODE).asInt()); +} + +void RichText::setWordSeparatorMode(RichText::WordSeparatorMode wordSeparatorMode) +{ + if (static_cast(_defaults.at(KEY_WORD_SEPARATOR_MODE).asInt()) != wordSeparatorMode) + { + _defaults[KEY_WORD_SEPARATOR_MODE] = static_cast(wordSeparatorMode); + _formatTextDirty = true; + } +} + RichText::HorizontalAlignment RichText::getHorizontalAlignment() const { return static_cast(_defaults.at(KEY_HORIZONTAL_ALIGNMENT).asInt()); @@ -1223,6 +1239,9 @@ void RichText::setDefaults(const ValueMap& defaults) } if (defaults.find(KEY_WRAP_MODE) != defaults.end()) { _defaults[KEY_WRAP_MODE] = defaults.at(KEY_WRAP_MODE).asInt(); + } + if (defaults.find(KEY_WORD_SEPARATOR_MODE) != defaults.end()) { + _defaults[KEY_WORD_SEPARATOR_MODE] = defaults.at(KEY_WORD_SEPARATOR_MODE).asInt(); } if (defaults.find(KEY_HORIZONTAL_ALIGNMENT) != defaults.end()) { _defaults[KEY_HORIZONTAL_ALIGNMENT] = defaults.at(KEY_HORIZONTAL_ALIGNMENT).asInt(); @@ -1496,48 +1515,76 @@ void RichText::formatText() } namespace { + + typedef bool (*FUNC_PTR_WRAPPABLE_WORD)(const StringUtils::StringUTF8::CharUTF8& ch); + inline bool isUTF8CharWrappable(const StringUtils::StringUTF8::CharUTF8& ch) { return (!ch.isASCII() || !std::isalnum(ch._char[0], std::locale())); } - int getPrevWordPos(const StringUtils::StringUTF8& text, int idx) + inline bool isUTF8CharSpaceSlashNotHighUnicodeWrappable(const StringUtils::StringUTF8::CharUTF8& ch) + { + return ch._char.c_str()[0] == 32 || ch._char.c_str()[0] == 45; // space or '-' + } + + inline bool isUTF8CharSpaceSlashAndKCJWrappable(const StringUtils::StringUTF8::CharUTF8& ch) + { + int len = strlen((char*) ch._char.c_str()); + return ch._char.c_str()[0] == 32 || ch._char.c_str()[0] == 45 || len >= 3; // space or '-' or CJK Unified Ideographs (Chinese, Japanese, and Korean) + } + + int getPrevWordPos(const StringUtils::StringUTF8& text, int idx, FUNC_PTR_WRAPPABLE_WORD func) { if (idx <= 0) return -1; // start from idx-1 const StringUtils::StringUTF8::CharUTF8Store& str = text.getString(); - auto it = std::find_if(str.rbegin() + (str.size() - idx + 1), str.rend(), isUTF8CharWrappable); + auto it = std::find_if(str.rbegin() + (str.size() - idx + 1), str.rend(), func); if (it == str.rend()) return -1; return static_cast(it.base() - str.begin()); } - int getNextWordPos(const StringUtils::StringUTF8& text, int idx) + int getNextWordPos(const StringUtils::StringUTF8& text, int idx, FUNC_PTR_WRAPPABLE_WORD func) { const StringUtils::StringUTF8::CharUTF8Store& str = text.getString(); if (idx + 1 >= static_cast(str.size())) return static_cast(str.size()); - auto it = std::find_if(str.begin() + idx + 1, str.end(), isUTF8CharWrappable); + auto it = std::find_if(str.begin() + idx + 1, str.end(), func); return static_cast(it - str.begin()); } - bool isWrappable(const StringUtils::StringUTF8& text) + bool isWrappable(const StringUtils::StringUTF8& text, FUNC_PTR_WRAPPABLE_WORD func) { const StringUtils::StringUTF8::CharUTF8Store& str = text.getString(); - return std::any_of(str.begin(), str.end(), isUTF8CharWrappable); + return std::any_of(str.begin(), str.end(), func); } - int findSplitPositionForWord(Label* label, const StringUtils::StringUTF8& text, int estimatedIdx, float originalLeftSpaceWidth, float newLineWidth) + int findSplitPositionForWord(Label* label, const StringUtils::StringUTF8& text, int estimatedIdx, + float originalLeftSpaceWidth, float newLineWidth, RichText::WordSeparatorMode wordSeparatorMode) { + FUNC_PTR_WRAPPABLE_WORD charWrappableFunctionPointer = &isUTF8CharWrappable; + switch (wordSeparatorMode) { + case RichText::WordSeparatorSpaceSlashAndKCJ: + charWrappableFunctionPointer = &isUTF8CharSpaceSlashAndKCJWrappable; + break; + case RichText::WordSeparatorSpaceSlashNotHighUnicode: + charWrappableFunctionPointer = &isUTF8CharSpaceSlashNotHighUnicodeWrappable; + break; + case RichText::WordSeparatorBasedOnDevice: + charWrappableFunctionPointer = &isUTF8CharWrappable; + break; + } + bool startingNewLine = (newLineWidth == originalLeftSpaceWidth); - if (!isWrappable(text)) + if (!isWrappable(text, charWrappableFunctionPointer)) return (startingNewLine ? static_cast(text.length()) : 0); // The adjustment of the new line position - int idx = getNextWordPos(text, estimatedIdx); + int idx = getNextWordPos(text, estimatedIdx, charWrappableFunctionPointer); std::string leftStr = text.getAsCharSequence(0, idx); label->setString(leftStr); float textRendererWidth = label->getContentSize().width; @@ -1546,7 +1593,7 @@ namespace { while (1) { // try to erase a word - int newidx = getPrevWordPos(text, idx); + int newidx = getPrevWordPos(text, idx, charWrappableFunctionPointer); if (newidx >= 0) { leftStr = text.getAsCharSequence(0, newidx); @@ -1566,7 +1613,7 @@ namespace { while (1) { // try to append a word - int newidx = getNextWordPos(text, idx); + int newidx = getNextWordPos(text, idx, charWrappableFunctionPointer); leftStr = text.getAsCharSequence(0, newidx); label->setString(leftStr); textRendererWidth = label->getContentSize().width; @@ -1646,6 +1693,7 @@ void RichText::handleTextRenderer(const std::string& text, const std::string& fo { bool fileExist = FileUtils::getInstance()->isFileExist(fontName); RichText::WrapMode wrapMode = static_cast(_defaults.at(KEY_WRAP_MODE).asInt()); + RichText::WordSeparatorMode wordSeparatorMode = static_cast(_defaults.at(KEY_WORD_SEPARATOR_MODE).asInt()); // split text by \n std::stringstream ss(text); @@ -1719,7 +1767,7 @@ void RichText::handleTextRenderer(const std::string& text, const std::string& fo int leftLength = 0; if (wrapMode == WRAP_PER_WORD) - leftLength = findSplitPositionForWord(textRenderer, utf8Text, estimatedIdx, _leftSpaceWidth, _customSize.width); + leftLength = findSplitPositionForWord(textRenderer, utf8Text, estimatedIdx, _leftSpaceWidth, _customSize.width, wordSeparatorMode); else leftLength = findSplitPositionForChar(textRenderer, utf8Text, estimatedIdx, _leftSpaceWidth, _customSize.width); diff --git a/cocos/ui/UIRichText.h b/cocos/ui/UIRichText.h index 723683c0057a..814919338c9e 100644 --- a/cocos/ui/UIRichText.h +++ b/cocos/ui/UIRichText.h @@ -350,6 +350,12 @@ class CC_GUI_DLL RichText : public Widget WRAP_PER_WORD, WRAP_PER_CHAR }; + + enum WordSeparatorMode: int { + WordSeparatorBasedOnDevice, /*!< The wrapping will be compute based on the device setting */ + WordSeparatorSpaceSlashNotHighUnicode, /*!< Spaces and '-' will be consider words separators. Recommended for Korean */ + WordSeparatorSpaceSlashAndKCJ /*!< Spaces, '-' and KCJ unicodes will be consider words separators. */ + }; enum class HorizontalAlignment { LEFT, @@ -372,6 +378,7 @@ class CC_GUI_DLL RichText : public Widget static const std::string KEY_VERTICAL_SPACE; /*!< key of vertical space */ static const std::string KEY_WRAP_MODE; /*!< key of per word, or per char */ + static const std::string KEY_WORD_SEPARATOR_MODE; /*!< key of word separator mode */ static const std::string KEY_HORIZONTAL_ALIGNMENT; /*!< key of left, right, or center */ static const std::string KEY_FONT_COLOR_STRING; /*!< key of font color */ static const std::string KEY_FONT_SIZE; /*!< key of font size */ @@ -486,6 +493,8 @@ class CC_GUI_DLL RichText : public Widget void setWrapMode(WrapMode wrapMode); /*!< sets the wrapping mode: WRAP_PER_CHAR or WRAP_PER_WORD */ WrapMode getWrapMode() const; /*!< returns the current wrapping mode */ + void setWordSeparatorMode(WordSeparatorMode wordSeparatorMode); /*!< sets the word separator mode */ + WordSeparatorMode getWordSeparatorMode(); /*!< returns the current word separator mode */ void setHorizontalAlignment(HorizontalAlignment a); /*!< sets the horizontal alignment mode: LEFT, CENTER, or RIGHT */ HorizontalAlignment getHorizontalAlignment() const; /*!< returns the current horizontal alignment mode */ void setFontColor(const std::string& color); /*!< Set the font color. @param color the #RRGGBB hexadecimal notation. */ diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIRichTextTest/UIRichTextTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIRichTextTest/UIRichTextTest.cpp index f562adbdb07d..d437a085210e 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIRichTextTest/UIRichTextTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIRichTextTest/UIRichTextTest.cpp @@ -55,28 +55,19 @@ UIRichTextTests::UIRichTextTests() // // UIRichTextTest // + +#define _RICH_TEXT_TAG (15) + bool UIRichTextTest::init() { if (UIScene::init()) { Size widgetSize = _widget->getContentSize(); + float x = widgetSize.width * 1 / 4; - auto config = Configuration::getInstance(); - config->loadConfigFile("configs/config-test-ok.plist"); - - - std::string str1 = config->getValue("Chinese").asString(); - std::string str2 = config->getValue("Japanese").asString(); - CCLOG("str1:%s ascii length = %ld, utf8 length = %ld, substr = %s", - str1.c_str(), - static_cast(str1.length()), - StringUtils::getCharacterCountInUTF8String(str1), - Helper::getSubStringOfUTF8String(str1, 0, 5).c_str()); - CCLOG("str2:%s ascii length = %ld, utf8 length = %ld, substr = %s", - str2.c_str(), - static_cast(str2.length()), - StringUtils::getCharacterCountInUTF8String(str2), - Helper::getSubStringOfUTF8String(str2, 0, 2).c_str()); + _currentWrappingMode = RichText::WRAP_PER_WORD; + _currentAlignment = RichText::HorizontalAlignment::LEFT; + _currentLanguage = RichTextWrapLanguage_Original; // Add the alert Text *alert = Text::create("RichText", "fonts/Marker Felt.ttf", 30); @@ -87,15 +78,17 @@ bool UIRichTextTest::init() Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); button->setTouchEnabled(true); button->setTitleText("switch"); - button->setPosition(Vec2(widgetSize.width * 1 / 3, widgetSize.height / 2.0f + button->getContentSize().height * 2.5)); + button->setPosition(Vec2(x, widgetSize.height / 2.0f + button->getContentSize().height * 2.5)); button->addTouchEventListener(CC_CALLBACK_2(UIRichTextTest::touchEvent, this)); button->setLocalZOrder(10); _widget->addChild(button); + float x_inc = button->getContentSize().width * 0.9; + Button* button2 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); button2->setTouchEnabled(true); button2->setTitleText("wrap mode"); - button2->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5)); + button2->setPosition(Vec2(x + x_inc, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5)); button2->addTouchEventListener(CC_CALLBACK_2(UIRichTextTest::switchWrapMode, this)); button2->setLocalZOrder(10); _widget->addChild(button2); @@ -103,52 +96,161 @@ bool UIRichTextTest::init() Button* button3 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); button3->setTouchEnabled(true); button3->setTitleText("alignment"); - button3->setPosition(Vec2(widgetSize.width * 2 / 3, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5)); + button3->setPosition(Vec2(x + x_inc * 2, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5)); button3->addTouchEventListener(CC_CALLBACK_2(UIRichTextTest::switchAlignment, this)); button3->setLocalZOrder(10); _widget->addChild(button3); - // RichText - _richText = RichText::create(); - _richText->ignoreContentAdaptWithSize(false); - _richText->setContentSize(Size(100, 100)); - - RichElementText* re1 = RichElementText::create(1, Color3B::WHITE, 255, str1, "SimSun", 10); - RichElementText* re2 = RichElementText::create(2, Color3B::YELLOW, 255, "And this is yellow. ", "Helvetica", 10); - RichElementText* re3 = RichElementText::create(3, Color3B::GRAY, 255, str2, "Yu Mincho", 10); - RichElementText* re4 = RichElementText::create(4, Color3B::GREEN, 255, "And green with TTF support. ", "fonts/Marker Felt.ttf", 10); - RichElementText* re5 = RichElementText::create(5, Color3B::RED, 255, "Last one is red ", "Helvetica", 10); + Button* button4 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); + button4->setTouchEnabled(true); + button4->setTitleText("language"); + button4->setPosition(Vec2(x+ x_inc * 3, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5)); + button4->addTouchEventListener(CC_CALLBACK_2(UIRichTextTest::switchLanguage, this)); + button4->setLocalZOrder(10); + _widget->addChild(button4); - RichElementImage* reimg = RichElementImage::create(6, Color3B::WHITE, 255, "cocosui/sliderballnormal.png"); + setLanguage(_currentLanguage); // TODO // cocostudio::ArmatureDataManager::getInstance()->addArmatureFileInfo("cocosui/100/100.ExportJson"); // cocostudio::Armature *pAr = cocostudio::Armature::create("100"); // // pAr->getAnimation()->play("Animation1"); -// RichElementCustomNode* recustom = RichElementCustomNode::create(1, Color3B::WHITE, 255, pAr); - RichElementText* re6 = RichElementText::create(7, Color3B::ORANGE, 255, "Have fun!! ", "Helvetica", 10); - _richText->pushBackElement(re1); - _richText->insertElement(re2, 1); - _richText->pushBackElement(re3); - _richText->pushBackElement(re4); - _richText->pushBackElement(re5); - _richText->insertElement(reimg, 2); + return true; + } + return false; +} + +void UIRichTextTest::setLanguage(RichTextWrapLanguage language) +{ + Size widgetSize = _widget->getContentSize(); + + _widget->removeChildByTag(_RICH_TEXT_TAG); + + switch(language) { + default: + case RichTextWrapLanguage_Original: { + auto config = Configuration::getInstance(); + config->loadConfigFile("configs/config-test-ok.plist"); + + std::string str1 = config->getValue("Chinese").asString(); + std::string str2 = config->getValue("Japanese").asString(); + + CCLOG("str1:%s ascii length = %ld, utf8 length = %ld, substr = %s", + str1.c_str(), + static_cast(str1.length()), + StringUtils::getCharacterCountInUTF8String(str1), + Helper::getSubStringOfUTF8String(str1, 0, 5).c_str()); + CCLOG("str2:%s ascii length = %ld, utf8 length = %ld, substr = %s", + str2.c_str(), + static_cast(str2.length()), + StringUtils::getCharacterCountInUTF8String(str2), + Helper::getSubStringOfUTF8String(str2, 0, 2).c_str()); + + // RichText + _richText = RichText::create(); + _richText->setTag(_RICH_TEXT_TAG); + _richText->setWrapMode(_currentWrappingMode); + _richText->setHorizontalAlignment(_currentAlignment); + _richText->ignoreContentAdaptWithSize(false); + _richText->setContentSize(Size(100, 100)); + + RichElementText *re1 = RichElementText::create(1, Color3B::WHITE, 255, str1, "SimSun", + 10); + RichElementText *re2 = RichElementText::create(2, Color3B::YELLOW, 255, + "And this is yellow. ", "Helvetica", 10); + RichElementText *re3 = RichElementText::create(3, Color3B::GRAY, 255, str2, "Yu Mincho", + 10); + RichElementText *re4 = RichElementText::create(4, Color3B::GREEN, 255, + "And green with TTF support. ", + "fonts/Marker Felt.ttf", 10); + RichElementText *re5 = RichElementText::create(5, Color3B::RED, 255, "Last one is red ", + "Helvetica", 10); + + RichElementImage *reimg = RichElementImage::create(6, Color3B::WHITE, 255, + "cocosui/sliderballnormal.png"); + + // RichElementCustomNode* recustom = RichElementCustomNode::create(1, Color3B::WHITE, 255, pAr); + RichElementText *re6 = RichElementText::create(7, Color3B::ORANGE, 255, "Have fun!! ", + "Helvetica", 10); + _richText->pushBackElement(re1); + _richText->insertElement(re2, 1); + _richText->pushBackElement(re3); + _richText->pushBackElement(re4); + _richText->pushBackElement(re5); + _richText->insertElement(reimg, 2); // _richText->pushBackElement(recustom); - _richText->pushBackElement(re6); + _richText->pushBackElement(re6); - _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2)); - _richText->setLocalZOrder(10); + _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2)); + _richText->setLocalZOrder(10); + _widget->addChild(_richText); - _widget->addChild(_richText); + // test remove all children, this call won't effect the test + _richText->removeAllChildren(); + } + break; - // test remove all children, this call won't effect the test - _richText->removeAllChildren(); + case RichTextWrapLanguage_Spanish: + addSingleRichTextWithText("Pingüino Pingüino Pingüino canción canción canción canción tamaño tamaño tamaño.", + RichText::WordSeparatorSpaceSlashAndKCJ); + break; - return true; + case RichTextWrapLanguage_Romanian: + addSingleRichTextWithText("Cântecul Cântecul Cântecul Cântecul Cântecul politică politică politică politică.", + RichText::WordSeparatorSpaceSlashAndKCJ); + break; + + case RichTextWrapLanguage_Russian: + addSingleRichTextWithText("Франция с завтрашнего дня закроет свои границы со странами, не входящими в Евросоюз: она пытается избежать нового ограничения", + RichText::WordSeparatorSpaceSlashAndKCJ); + break; + + case RichTextWrapLanguage_English: + addSingleRichTextWithText("Testing word-wrapping. Testing word-wrapping. Testing word-wrapping. Testing word-wrapping.", + RichText::WordSeparatorSpaceSlashAndKCJ); + break; + + case RichTextWrapLanguage_French: + addSingleRichTextWithText("espère espère espère l'appel l'appel l'opposant Alexeï Alexeï enquête Royaume-Uni Royaume-Uni", + RichText::WordSeparatorSpaceSlashAndKCJ); + break; + + case RichTextWrapLanguage_Korean: + addSingleRichTextWithText("차가운 대리석으로 대리석으로 대리석으로 둘러싸인 둘러싸인 담으로 둘러싸인 정원에서 승인 된 라임 나무 줄, 난 자랍니다", + RichText::WordSeparatorSpaceSlashNotHighUnicode); + break; + + case RichTextWrapLanguage_Chinese: + addSingleRichTextWithText("在圍牆花園裡四周是冷大理石和成行的樹我成長", + RichText::WordSeparatorSpaceSlashAndKCJ); + break; } - return false; +} + +void UIRichTextTest::addSingleRichTextWithText(const std::string& text, const RichText::WordSeparatorMode& wordSeparatorMode) +{ + Size widgetSize = _widget->getContentSize(); + + _richText = RichText::create(); + _richText->setTag(_RICH_TEXT_TAG); + _richText->setWrapMode(_currentWrappingMode); + _richText->setWordSeparatorMode(wordSeparatorMode); + _richText->setHorizontalAlignment(_currentAlignment); + _richText->ignoreContentAdaptWithSize(false); + _richText->setContentSize(Size(100, 100)); + + RichElementText *re = RichElementText::create(5, Color3B::YELLOW, 255, + text, + "Helvetica", 10); + _richText->pushBackElement(re); + + _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2)); + _richText->setLocalZOrder(10); + + _widget->addChild(_richText); + _richText->removeAllChildren(); } void UIRichTextTest::touchEvent(Ref *pSender, Widget::TouchEventType type) @@ -178,21 +280,28 @@ void UIRichTextTest::switchWrapMode(Ref *pSender, Widget::TouchEventType type) { if (type == Widget::TouchEventType::ENDED) { - auto wrapMode = _richText->getWrapMode(); - wrapMode = (wrapMode == RichText::WRAP_PER_WORD) ? RichText::WRAP_PER_CHAR : RichText::WRAP_PER_WORD; - _richText->setWrapMode(wrapMode); + _currentWrappingMode = (_currentWrappingMode == RichText::WRAP_PER_WORD) ? RichText::WRAP_PER_CHAR : RichText::WRAP_PER_WORD; + _richText->setWrapMode(_currentWrappingMode); } } void UIRichTextTest::switchAlignment(Ref *sender, Widget::TouchEventType type) { if (type == Widget::TouchEventType::ENDED) { - auto alignment = _richText->getHorizontalAlignment(); - alignment = static_cast((static_cast::type>(alignment) + 1) % 3); - _richText->setHorizontalAlignment(alignment); + _currentAlignment = static_cast((static_cast::type>(_currentAlignment) + 1) % 3); + _richText->setHorizontalAlignment(_currentAlignment); } } +void UIRichTextTest::switchLanguage(Ref *sender, Widget::TouchEventType type) { + if (type == Widget::TouchEventType::ENDED) + { + _currentLanguage = static_cast((_currentLanguage + 1) % RichTextWrapLanguage_Max); + setLanguage(_currentLanguage); + } +} + + // // UIRichTextXMLBasic // diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIRichTextTest/UIRichTextTest.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIRichTextTest/UIRichTextTest.h index fb4923e8842b..8b3c0cbb4091 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIRichTextTest/UIRichTextTest.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIRichTextTest/UIRichTextTest.h @@ -30,6 +30,20 @@ #include "../UIScene.h" DEFINE_TEST_SUITE(UIRichTextTests); +using namespace cocos2d::ui; + +enum RichTextWrapLanguage: int { + RichTextWrapLanguage_Original = 0, + RichTextWrapLanguage_Spanish, + RichTextWrapLanguage_Romanian, + RichTextWrapLanguage_Russian, + RichTextWrapLanguage_English, + RichTextWrapLanguage_French, + RichTextWrapLanguage_Korean, + RichTextWrapLanguage_Chinese, + + RichTextWrapLanguage_Max +}; class UIRichTextTest : public UIScene { @@ -37,12 +51,19 @@ class UIRichTextTest : public UIScene CREATE_FUNC(UIRichTextTest); bool init() override; + void setLanguage(RichTextWrapLanguage language); + void addSingleRichTextWithText(const std::string& text, const RichText::WordSeparatorMode& wordSeparatorMode); void touchEvent(cocos2d::Ref* sender, cocos2d::ui::Widget::TouchEventType type); void switchWrapMode(cocos2d::Ref* sender, cocos2d::ui::Widget::TouchEventType type); void switchAlignment(cocos2d::Ref* sender, cocos2d::ui::Widget::TouchEventType type); + void switchLanguage(cocos2d::Ref* sender, cocos2d::ui::Widget::TouchEventType type); protected: cocos2d::ui::RichText* _richText; + RichTextWrapLanguage _currentLanguage; + RichText::WrapMode _currentWrappingMode; + RichText::HorizontalAlignment _currentAlignment; + }; class UIRichTextXMLBasic : public UIScene