MCPcopy Create free account
hub / github.com/axmolengine/axmol / startElement

Method startElement

core/ui/UIRichText.cpp:886–1108  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

884}
885
886void 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;

Callers 8

test_case_start_implMethod · 0.45
test_run_startMethod · 0.45
test_run_endMethod · 0.45
test_case_endMethod · 0.45
subcase_startMethod · 0.45
log_assertMethod · 0.45
log_messageMethod · 0.45
test_run_endMethod · 0.45

Calls 15

atofFunction · 0.85
getURLFunction · 0.85
asStringMethod · 0.80
asFloatMethod · 0.80
color3BWithStringMethod · 0.80
getAnchorFontColor3BMethod · 0.80

Tested by 8

test_case_start_implMethod · 0.36
test_run_startMethod · 0.36
test_run_endMethod · 0.36
test_case_endMethod · 0.36
subcase_startMethod · 0.36
log_assertMethod · 0.36
log_messageMethod · 0.36
test_run_endMethod · 0.36