Gems/AtomLyIntegration/AtomFont/Code/Source/AtomFont.cpp
bool ParseFontFamilyXml(const XmlNodeRef& node, FontFamilyTagXml& xmlData)
    {
        if (!node)
        {
            return false;
        }

        // <fontfamily>
        if (AZStd::string(node->getTag()) == "fontfamily")
        {
            const int numAttributes = node->getNumAttributes();

            if (numAttributes <= 0)
            {
                // Expecting at least one attribute
                return false;
            }

            AZStd::string name;

            for (int i = 0, count = node->getNumAttributes(); i < count; ++i)
            {
                const char* key = "";
                const char* value = "";
                if (node->getAttributeByIndex(i, &key, &value))
                {
                    if (AZStd::string(key) == "name")
                    {
                        name = value;
                    }
                    else
                    {
                        // Unexpected font tag attribute
                        return false;
                    }
                }
            }

            AZ::StringFunc::TrimWhiteSpace(name, true, true);
            if (!name.empty())
            {
                xmlData.m_fontFamilyName = name;
            }
            else
            {
                // Font family must have a name
                return false;
            }
        }

        // <font>
        if (AZStd::string(node->getTag()) == "font")
        {
            xmlData.m_fontTagsXml.push_back(FontTagXml());

            AZStd::string lang;
            for (int i = 0, count = node->getNumAttributes(); i < count; ++i)
            {
                const char* key = "";
                const char* value = "";
                if (node->getAttributeByIndex(i, &key, &value))
                {
                    if (AZStd::string(key) == "lang")
                    {
                        lang = value;
                    }
                    else
                    {
                        // Unexpected font tag attribute
                        return false;
                    }
                }
            }

            AZ::StringFunc::TrimWhiteSpace(lang, true, true);
            if (!lang.empty())
            {
                xmlData.m_fontTagsXml.back().m_lang = lang;
            }
        }

        // <file>
        else if (AZStd::string(node->getTag()) == "file")
        {
            const int numAttributes = node->getNumAttributes();

            if (numAttributes <= 0)
            {
                // Expecting at least one attribute
                return false;
            }

            AZStd::string path;
            AZStd::string tags;

            for (int i = 0, count = node->getNumAttributes(); i < count; ++i)
            {
                const char* key = "";
                const char* value = "";
                if (node->getAttributeByIndex(i, &key, &value))
                {
                    if (AZStd::string(key) == "path")
                    {
                        path = value;
                    }
                    else if (AZStd::string(key) == "tags")
                    {
                        tags = value;
                    }
                    else
                    {
                        // Unexpected font tag attribute
                        return false;
                    }
                }
            }

            AZ::StringFunc::TrimWhiteSpace(tags, true, true);
            if (tags.empty())
            {
                xmlData.m_fontTagsXml.back().m_fontFilename = path;
            }
            else if (tags == "b")
            {
                xmlData.m_fontTagsXml.back().m_boldFontFilename = path;
            }
            else if (tags == "i")
            {
                xmlData.m_fontTagsXml.back().m_italicFontFilename = path;
            }
            else
            {
                // We'll just assume any other tag indicates bold italic
                xmlData.m_fontTagsXml.back().m_boldItalicFontFilename = path;
            }
        }

        for (int i = 0, count = node->getChildCount(); i < count; ++i)
        {
            XmlNodeRef child = node->getChild(i);
            if (!ParseFontFamilyXml(child, xmlData))
            {
                return false;
            }
        }

        return true;
    }
//! Returns true if the XML tree was traversed successfully, false otherwise.
//!
//! Note that, if this function returns true, it simply means that there were
//! no unexpected structure issues with the given XML tree, it doesn't 
//! necessarily mean that all the required fields were parsed.
Returns true if the XML tree was traversed successfully, false otherwise.
Note that, if this function returns true, it simply means that there were
no unexpected structure issues with the given XML tree, it doesn't
necessarily mean that all the required fields were parsed.
Returns true if the XML tree was traversed successfully false otherwise . Note that if this function returns true it simply means that there were no unexpected structure issues with the given XML tree it doesn ' t necessarily mean that all the required fields were parsed .
bool ParseFontFamilyXml(const XmlNodeRef& node, FontFamilyTagXml& xmlData)
    {
        if (!node)
        {
            return false;
        }
        if (AZStd::string(node->getTag()) == "fontfamily")
        {
            const int numAttributes = node->getNumAttributes();
            if (numAttributes <= 0)
            {
                return false;
            }
            AZStd::string name;
            for (int i = 0, count = node->getNumAttributes(); i < count; ++i)
            {
                const char* key = "";
                const char* value = "";
                if (node->getAttributeByIndex(i, &key, &value))
                {
                    if (AZStd::string(key) == "name")
                    {
                        name = value;
                    }
                    else
                    {
                        return false;
                    }
                }
            }
            AZ::StringFunc::TrimWhiteSpace(name, true, true);
            if (!name.empty())
            {
                xmlData.m_fontFamilyName = name;
            }
            else
            {
                return false;
            }
        }
        if (AZStd::string(node->getTag()) == "font")
        {
            xmlData.m_fontTagsXml.push_back(FontTagXml());
            AZStd::string lang;
            for (int i = 0, count = node->getNumAttributes(); i < count; ++i)
            {
                const char* key = "";
                const char* value = "";
                if (node->getAttributeByIndex(i, &key, &value))
                {
                    if (AZStd::string(key) == "lang")
                    {
                        lang = value;
                    }
                    else
                    {
                        return false;
                    }
                }
            }
            AZ::StringFunc::TrimWhiteSpace(lang, true, true);
            if (!lang.empty())
            {
                xmlData.m_fontTagsXml.back().m_lang = lang;
            }
        }
        else if (AZStd::string(node->getTag()) == "file")
        {
            const int numAttributes = node->getNumAttributes();
            if (numAttributes <= 0)
            {
                return false;
            }
            AZStd::string path;
            AZStd::string tags;
            for (int i = 0, count = node->getNumAttributes(); i < count; ++i)
            {
                const char* key = "";
                const char* value = "";
                if (node->getAttributeByIndex(i, &key, &value))
                {
                    if (AZStd::string(key) == "path")
                    {
                        path = value;
                    }
                    else if (AZStd::string(key) == "tags")
                    {
                        tags = value;
                    }
                    else
                    {
                        return false;
                    }
                }
            }
            AZ::StringFunc::TrimWhiteSpace(tags, true, true);
            if (tags.empty())
            {
                xmlData.m_fontTagsXml.back().m_fontFilename = path;
            }
            else if (tags == "b")
            {
                xmlData.m_fontTagsXml.back().m_boldFontFilename = path;
            }
            else if (tags == "i")
            {
                xmlData.m_fontTagsXml.back().m_italicFontFilename = path;
            }
            else
            {
                xmlData.m_fontTagsXml.back().m_boldItalicFontFilename = path;
            }
        }
        for (int i = 0, count = node->getChildCount(); i < count; ++i)
        {
            XmlNodeRef child = node->getChild(i);
            if (!ParseFontFamilyXml(child, xmlData))
            {
                return false;
            }
        }
        return true;
    }
bool ParseFontFamilyXml ( const XmlNodeRef & node , FontFamilyTagXml & xmlData ) { if ( ! node ) { return false ; } if ( AZStd :: string ( node -> getTag ( ) ) == " " ) { const int numAttributes = node -> getNumAttributes ( ) ; if ( numAttributes <= 0 ) { return false ; } AZStd :: string name ; for ( int i = 0 , count = node -> getNumAttributes ( ) ; i < count ; ++ i ) { const char * key = " " ; const char * value = " " ; if ( node -> getAttributeByIndex ( i , & key , & value ) ) { if ( AZStd :: string ( key ) == " " ) { name = value ; } else { return false ; } } } AZ :: StringFunc :: TrimWhiteSpace ( name , true , true ) ; if ( ! name . empty ( ) ) { xmlData . m_fontFamilyName = name ; } else { return false ; } } if ( AZStd :: string ( node -> getTag ( ) ) == " " ) { xmlData . m_fontTagsXml . push_back ( FontTagXml ( ) ) ; AZStd :: string lang ; for ( int i = 0 , count = node -> getNumAttributes ( ) ; i < count ; ++ i ) { const char * key = " " ; const char * value = " " ; if ( node -> getAttributeByIndex ( i , & key , & value ) ) { if ( AZStd :: string ( key ) == " " ) { lang = value ; } else { return false ; } } } AZ :: StringFunc :: TrimWhiteSpace ( lang , true , true ) ; if ( ! lang . empty ( ) ) { xmlData . m_fontTagsXml . back ( ) . m_lang = lang ; } } else if ( AZStd :: string ( node -> getTag ( ) ) == " " ) { const int numAttributes = node -> getNumAttributes ( ) ; if ( numAttributes <= 0 ) { return false ; } AZStd :: string path ; AZStd :: string tags ; for ( int i = 0 , count = node -> getNumAttributes ( ) ; i < count ; ++ i ) { const char * key = " " ; const char * value = " " ; if ( node -> getAttributeByIndex ( i , & key , & value ) ) { if ( AZStd :: string ( key ) == " " ) { path = value ; } else if ( AZStd :: string ( key ) == " " ) { tags = value ; } else { return false ; } } } AZ :: StringFunc :: TrimWhiteSpace ( tags , true , true ) ; if ( tags . empty ( ) ) { xmlData . m_fontTagsXml . back ( ) . m_fontFilename = path ; } else if ( tags == " " ) { xmlData . m_fontTagsXml . back ( ) . m_boldFontFilename = path ; } else if ( tags == " " ) { xmlData . m_fontTagsXml . back ( ) . m_italicFontFilename = path ; } else { xmlData . m_fontTagsXml . back ( ) . m_boldItalicFontFilename = path ; } } for ( int i = 0 , count = node -> getChildCount ( ) ; i < count ; ++ i ) { XmlNodeRef child = node -> getChild ( i ) ; if ( ! ParseFontFamilyXml ( child , xmlData ) ) { return false ; } } return true ; }
Returns true if the XML tree was traversed successfully, false otherwise.
Returns true if the XML tree was traversed successfully false otherwise .
// <fontfamily> // Expecting at least one attribute // Unexpected font tag attribute // Font family must have a name // <font> // Unexpected font tag attribute // <file> // Expecting at least one attribute // Unexpected font tag attribute // We'll just assume any other tag indicates bold italic