FontAtlas * FontDefinitionTTF::createFontAtlas()
{
    FontAtlas *retAtlas = new FontAtlas( *_textImages->getFont() );
    
    if (!retAtlas)
        return 0;
    
    // add all the textures
    int numTextures = getNumTextures();
    if (!numTextures)
        return 0;
    
    for (int c = 0; c<numTextures; ++c)
        retAtlas->addTexture(*getTexture(c), c);
    
    // set the common line height
    retAtlas->setCommonLineHeight(getCommonLineHeight() * 0.8);
    
    
    for( auto &item: _fontLettersDefinitionUTF16 )
    {
        if ( item.second.validDefinition )
        {
            FontLetterDefinition tempDefinition = item.second;
            tempDefinition.offsetX = 0;
            tempDefinition.anchorX = 0.0f;
            tempDefinition.anchorY = 1.0f;
            retAtlas->addLetterDefinition(tempDefinition);
        }
    }
    
    // done here
    return retAtlas;
}
FontAtlas * FontDefinitionTTF::createFontAtlas()
{
    int numTextures          = 0;
    TextFontPagesDef *pages = m_pTextImages->getPages();
    
    if (pages)
        numTextures = pages->getNumPages();
    else
        return nullptr;
    
    if (!numTextures)
        return nullptr;
    
    FontAtlas *retAtlas = new FontAtlas(*m_pTextImages->getFont());
    
    if (!retAtlas)
        return 0;
    
    for (int c = 0; c < numTextures; ++c)
    {
        TextFontPagesDef *pPages = m_pTextImages->getPages();
        retAtlas->addTexture(*(pPages->getPageAt(c)->getPageTexture()), c);
    }
    
    // set the common line height
    retAtlas->setCommonLineHeight(m_fCommonLineHeight * 0.8);
    
    for( auto &item: m_aFontLettersDefinitionUTF16 )
    {
        if ( item.second.validDefinition )
        {
            FontLetterDefinition tempDefinition = item.second;
            tempDefinition.offsetX = 0;
            tempDefinition.anchorX = 0.0f;
            tempDefinition.anchorY = 1.0f;
            retAtlas->addLetterDefinition(tempDefinition);
        }
    }
    
    // done here
    return retAtlas;
}
FontAtlas * FontCharMap::createFontAtlas()
{
    FontAtlas *tempAtlas = new FontAtlas(*this);
    if (!tempAtlas)
        return nullptr;
    
    Size s = _texture->getContentSize();

    int itemsPerColumn = (int)(s.height / _itemHeight);
    int itemsPerRow = (int)(s.width / _itemWidth);

    tempAtlas->setCommonLineHeight(_itemHeight);
    
    FontLetterDefinition tempDefinition;
    tempDefinition.textureID = 0;
    tempDefinition.offsetX  = 0.0f;
    tempDefinition.offsetY  = 0.0f;
    tempDefinition.validDefinition = true;
    tempDefinition.width    = _itemWidth;
    tempDefinition.height   = _itemHeight;
    tempDefinition.xAdvance = _itemWidth * CC_CONTENT_SCALE_FACTOR();

    int charId = _mapStartChar;
    for (int row = 0; row < itemsPerColumn; ++row)
    {
        for (int col = 0; col < itemsPerRow; ++col)
        {
            tempDefinition.letteCharUTF16 = charId;

            tempDefinition.U        = _itemWidth * col;
            tempDefinition.V        = _itemHeight * row;           

            tempAtlas->addLetterDefinition(tempDefinition);
            charId++;
        }
    }
    
    tempAtlas->addTexture(_texture,0);

    return tempAtlas;
}