| 2055 | } // namespace |
| 2056 | |
| 2057 | void RichText::handleTextRenderer(std::string_view text, |
| 2058 | std::string_view fontName, |
| 2059 | float fontSize, |
| 2060 | const Color3B& color, |
| 2061 | uint8_t opacity, |
| 2062 | uint32_t flags, |
| 2063 | std::string_view url, |
| 2064 | const Color3B& outlineColor, |
| 2065 | int outlineSize, |
| 2066 | const Color3B& shadowColor, |
| 2067 | const Vec2& shadowOffset, |
| 2068 | int shadowBlurRadius, |
| 2069 | const Color3B& glowColor, |
| 2070 | std::string_view id) |
| 2071 | { |
| 2072 | bool fileExist = FileUtils::getInstance()->isFileExist(fontName); |
| 2073 | RichText::WrapMode wrapMode = static_cast<RichText::WrapMode>(_defaults.at(KEY_WRAP_MODE).asInt()); |
| 2074 | |
| 2075 | // split text by \n |
| 2076 | std::stringstream ss; |
| 2077 | ss << text; |
| 2078 | std::string currentText; |
| 2079 | size_t realLines = 0; |
| 2080 | auto isFirstLabel = true; |
| 2081 | while (std::getline(ss, currentText, '\n')) |
| 2082 | { |
| 2083 | if (realLines > 0) |
| 2084 | { |
| 2085 | addNewLine(); |
| 2086 | _lineHeights.back() = fontSize; |
| 2087 | } |
| 2088 | ++realLines; |
| 2089 | |
| 2090 | size_t splitParts = 0; |
| 2091 | StringUtils::StringUTF8 utf8Text(currentText); |
| 2092 | while (!currentText.empty()) |
| 2093 | { |
| 2094 | if (splitParts > 0) |
| 2095 | { |
| 2096 | addNewLine(); |
| 2097 | _lineHeights.back() = fontSize; |
| 2098 | } |
| 2099 | ++splitParts; |
| 2100 | |
| 2101 | Label* textRenderer = fileExist ? Label::createWithTTF(currentText, fontName, fontSize) |
| 2102 | : Label::createWithSystemFont(currentText, fontName, fontSize); |
| 2103 | |
| 2104 | if (flags & RichElementText::ITALICS_FLAG) |
| 2105 | textRenderer->enableItalics(); |
| 2106 | if (flags & RichElementText::BOLD_FLAG) |
| 2107 | textRenderer->enableBold(); |
| 2108 | if (flags & RichElementText::UNDERLINE_FLAG) |
| 2109 | textRenderer->enableUnderline(); |
| 2110 | if (flags & RichElementText::STRIKETHROUGH_FLAG) |
| 2111 | textRenderer->enableStrikethrough(); |
| 2112 | if (flags & RichElementText::URL_FLAG) |
| 2113 | textRenderer->addComponent(UrlTouchListenerComponent::create( |
| 2114 | textRenderer, url, [this](std::string_view url) { openUrl(url); })); |
nothing calls this directly
no test coverage detected