| 1739 | } |
| 1740 | |
| 1741 | void RichText::formatText(bool force) |
| 1742 | { |
| 1743 | _formatTextDirty |= force; |
| 1744 | if (_formatTextDirty) |
| 1745 | { |
| 1746 | this->removeAllProtectedChildren(); |
| 1747 | _elementRenders.clear(); |
| 1748 | _lineHeights.clear(); |
| 1749 | if (_ignoreSize) |
| 1750 | { |
| 1751 | addNewLine(); |
| 1752 | for (ssize_t i = 0, size = _richElements.size(); i < size; ++i) |
| 1753 | { |
| 1754 | RichElement* element = _richElements.at(i); |
| 1755 | Node* elementRenderer = nullptr; |
| 1756 | switch (element->_type) |
| 1757 | { |
| 1758 | case RichElement::Type::TEXT: |
| 1759 | { |
| 1760 | RichElementText* elmtText = static_cast<RichElementText*>(element); |
| 1761 | Label* label; |
| 1762 | if (FileUtils::getInstance()->isFileExist(elmtText->_fontName)) |
| 1763 | { |
| 1764 | label = Label::createWithTTF(elmtText->_text, elmtText->_fontName, elmtText->_fontSize); |
| 1765 | } |
| 1766 | else |
| 1767 | { |
| 1768 | label = Label::createWithSystemFont(elmtText->_text, elmtText->_fontName, elmtText->_fontSize); |
| 1769 | } |
| 1770 | if (elmtText->_flags & RichElementText::ITALICS_FLAG) |
| 1771 | label->enableItalics(); |
| 1772 | if (elmtText->_flags & RichElementText::BOLD_FLAG) |
| 1773 | label->enableBold(); |
| 1774 | if (elmtText->_flags & RichElementText::UNDERLINE_FLAG) |
| 1775 | label->enableUnderline(); |
| 1776 | if (elmtText->_flags & RichElementText::STRIKETHROUGH_FLAG) |
| 1777 | label->enableStrikethrough(); |
| 1778 | if (elmtText->_flags & RichElementText::URL_FLAG) |
| 1779 | label->addComponent(UrlTouchListenerComponent::create( |
| 1780 | label, elmtText->_url, [this](std::string_view url) { openUrl(url); })); |
| 1781 | if (elmtText->_flags & RichElementText::OUTLINE_FLAG) |
| 1782 | { |
| 1783 | label->enableOutline(Color4B(elmtText->_outlineColor), elmtText->_outlineSize); |
| 1784 | } |
| 1785 | if (elmtText->_flags & RichElementText::SHADOW_FLAG) |
| 1786 | { |
| 1787 | label->enableShadow(Color4B(elmtText->_shadowColor), elmtText->_shadowOffset, |
| 1788 | elmtText->_shadowBlurRadius); |
| 1789 | } |
| 1790 | if (elmtText->_flags & RichElementText::GLOW_FLAG) |
| 1791 | { |
| 1792 | label->enableGlow(Color4B(elmtText->_glowColor)); |
| 1793 | } |
| 1794 | label->setTextColor(Color4B(elmtText->_color)); |
| 1795 | |
| 1796 | label->setName(elmtText->_id); |
| 1797 | |
| 1798 | elementRenderer = label; |