#include "xfont.h"

XFont::XFont()
    : XAsset()
    , mFontName()
    , mPixelHeight(0)
    , mGlyphCount(0)
    , mMaterial()
    , mGlowMaterial()
    , mGlyphs()
{
    SetType(ASSET_TYPE_FONT);
    SetName("Font");
}

XFont::~XFont()
{
    
}

void XFont::Clear()
{
    mFontName.Clear();
    mPixelHeight = 0;
    mGlyphCount = 0;
    mMaterial.Clear();
    mGlowMaterial.Clear();
    mGlyphs.clear();
}

void XFont::ParseData(XDataStream *aStream)
{
    if (GetPtr() == -1)
    {
        mFontName.ParsePtr(aStream, false);

        qint32 glyphsPtr;
        *aStream
            >> mPixelHeight
            >> mGlyphCount;

        mMaterial.ParsePtr(aStream, false);
        mGlowMaterial.ParsePtr(aStream, false);

        *aStream >> glyphsPtr;

        mFontName.ParseData(aStream);
        mMaterial.ParseData(aStream);
        mGlowMaterial.ParseData(aStream);

        if (glyphsPtr == -1)
        {
            for (int i = 0; i < mGlyphCount; i++)
            {
                XGlyph newGlyph;
                newGlyph.ParseData(aStream);
                mGlyphs.append(newGlyph);
            }
        }
    }
}
