| 884 | } |
| 885 | |
| 886 | void MyXMLVisitor::startElement(void* /*ctx*/, const char* elementName, const char** atts) |
| 887 | { |
| 888 | auto it = _tagTables.find(elementName); |
| 889 | if (it != _tagTables.end()) |
| 890 | { |
| 891 | auto tagBehavior = it->second; |
| 892 | if (tagBehavior.handleVisitEnter != nullptr) |
| 893 | { |
| 894 | ValueMap&& tagAttrValueMap = tagAttrMapWithXMLElement(atts); |
| 895 | auto result = tagBehavior.handleVisitEnter(tagAttrValueMap); |
| 896 | ValueMap& attrValueMap = result.first; |
| 897 | RichElement* richElement = result.second; |
| 898 | if (tagBehavior.isFontElement) |
| 899 | { |
| 900 | Attributes attributes; |
| 901 | |
| 902 | if (auto&& itr = attrValueMap.find(RichText::KEY_FONT_SIZE); itr != attrValueMap.end()) |
| 903 | { |
| 904 | std::regex fontSizePattern(R"(([0-9]*(?:\.[0-9]+)?)(%|em)$)"); |
| 905 | std::smatch match; |
| 906 | auto sizeString = itr->second.asString(); |
| 907 | if (std::regex_match(sizeString, match, fontSizePattern) && match.size() == 3 && |
| 908 | !match[1].str().empty()) |
| 909 | { |
| 910 | auto scale = static_cast<float>(utils::atof(match[1].str().c_str())); |
| 911 | if (match[2].str() == "%") |
| 912 | { |
| 913 | attributes.fontSize = getFontSize() * scale / 100.f; |
| 914 | } |
| 915 | else // em |
| 916 | { |
| 917 | attributes.fontSize = getFontSize() * scale; |
| 918 | } |
| 919 | } |
| 920 | else |
| 921 | { |
| 922 | attributes.fontSize = itr->second.asFloat(); |
| 923 | } |
| 924 | } |
| 925 | if (attrValueMap.contains(RichText::KEY_FONT_SMALL)) |
| 926 | { |
| 927 | attributes.fontSize = getFontSize() * 0.8f; |
| 928 | } |
| 929 | if (attrValueMap.contains(RichText::KEY_FONT_BIG)) |
| 930 | { |
| 931 | attributes.fontSize = getFontSize() * 1.25f; |
| 932 | } |
| 933 | if (auto&& itr = attrValueMap.find(RichText::KEY_FONT_COLOR_STRING); itr != attrValueMap.end()) |
| 934 | { |
| 935 | attributes.setColor(_richText->color3BWithString(itr->second.asString())); |
| 936 | } |
| 937 | if (auto&& itr = attrValueMap.find(RichText::KEY_FONT_FACE); itr != attrValueMap.end()) |
| 938 | { |
| 939 | attributes.face = itr->second.asString(); |
| 940 | } |
| 941 | if (attrValueMap.contains(RichText::KEY_TEXT_BOLD)) |
| 942 | { |
| 943 | attributes.bold = true; |