//! [font_translate]
void FontTranslator::translate(ScriptCompiler* compiler, const AbstractNodePtr& node)
{
    ObjectAbstractNode* obj = static_cast<ObjectAbstractNode*>(node.get());

    // Must have a name - unless we are in legacy mode. Then the class is the name.
    if (obj->name.empty() && obj->cls == "font")
    {
        compiler->addError(ScriptCompiler::CE_OBJECTNAMEEXPECTED, obj->file, obj->line,
                           "font must be given a name");
        return;
    }

    String& name = obj->cls == "font" ? obj->name : obj->cls;

    FontPtr font = FontManager::getSingleton().create(name, compiler->getResourceGroup());
    font->_notifyOrigin(obj->file);

    for (auto& c : obj->children)
    {
        if (c->type == ANT_PROPERTY)
        {
            parseAttribute(compiler, font, static_cast<PropertyAbstractNode*>(c.get()));
        }
    }
}
Exemple #2
0
    //---------------------------------------------------------------------
    void FontManager::parseScript(DataStreamPtr& stream, const String& groupName)
    {
        String line;
        FontPtr pFont;

        while( !stream->eof() )
        {
            line = stream->getLine();
            // Ignore blanks & comments
            if( !line.length() || line.substr( 0, 2 ) == "//" )
            {
                continue;
            }
            else
            {
                if (pFont.isNull())
                {
                    // No current font
                    // So first valid data should be font name
                    if (StringUtil::startsWith(line, "font "))
                    {
                        // chop off the 'particle_system ' needed by new compilers
                        line = line.substr(5);
                    }
                    pFont = create(line, groupName);
                    pFont->_notifyOrigin(stream->getName());
                    // Skip to and over next {
                    stream->skipLine("{");
                }
                else
                {
                    // Already in font
                    if (line == "}")
                    {
                        // Finished 
                        pFont.setNull();
                        // NB font isn't loaded until required
                    }
                    else
                    {
                        parseAttribute(line, pFont);
                    }
                }
            }
        }
    }