
#include "kjs/wk_config.h"
#include "BALConfiguration.h"
#include "BCGlyphBufferDirectFB.h"

#include "BTLogHelper.h"

IMPLEMENT_CREATE_DELETE(BIGlyphBuffer, BCGlyphBufferDirectFB);

namespace BAL {

bool BCGlyphBufferDirectFB::isEmpty() const
{
    DBGML(MODULE_FONTS, LEVEL_INFO, "\nBCGlyphBufferDirectFB::isEmpty()\n");
    return m_fontData.isEmpty();
}

int BCGlyphBufferDirectFB::size() const
{
    DBGML(MODULE_FONTS, LEVEL_INFO, "\nBCGlyphBufferDirectFB::size()\n");
    return m_fontData.size();
}

void BCGlyphBufferDirectFB::clear()
{
    DBGML(MODULE_FONTS, LEVEL_INFO, "\nBCGlyphBufferDirectFB::clear()\n"); 
    m_fontData.clear();
    m_glyphs.clear();
    m_advances.clear();
}

GlyphBufferGlyph* BCGlyphBufferDirectFB::glyphs(int from)
{
    DBGML(MODULE_FONTS, LEVEL_INFO, "\nBCGlyphBufferDirectFB::glyphs(%d)\n", from);
    return m_glyphs.data() + from;
}

const GlyphBufferGlyph* BCGlyphBufferDirectFB::glyphs(int from) const
{
    DBGML(MODULE_FONTS, LEVEL_INFO, "\nBCGlyphBufferDirectFB::glyphs(%d) const\n", from);
    return m_glyphs.data() + from;
}

GlyphBufferAdvance* BCGlyphBufferDirectFB::advances(int from)
{
    DBGML(MODULE_FONTS, LEVEL_INFO, "\nBCGlyphBufferDirectFB::advances(%d)\n", from);
    return m_advances.data() + from;
}

const GlyphBufferAdvance* BCGlyphBufferDirectFB::advances(int from) const
{
    DBGML(MODULE_FONTS, LEVEL_INFO, "\nBCGlyphBufferDirectFB::advances(%d) const\n", from);
    return m_advances.data() + from;
}

const BTFontData* BCGlyphBufferDirectFB::fontDataAt(int index) const
{
    DBGML(MODULE_FONTS, LEVEL_INFO, "\nBCGlyphBufferDirectFB::fontDataAt(%d) const\n", index);
    return m_fontData[index];
}

void BCGlyphBufferDirectFB::swap(int index1, int index2)
{
    DBGML(MODULE_FONTS, LEVEL_INFO, "\nBCGlyphBufferDirectFB::swap()\n");
    const BTFontData* f = m_fontData[index1];
    m_fontData[index1] = m_fontData[index2];
    m_fontData[index2] = f;

    GlyphBufferGlyph g = m_glyphs[index1];
    m_glyphs[index1] = m_glyphs[index2];
    m_glyphs[index2] = g;

    GlyphBufferAdvance s = m_advances[index1];
    m_advances[index1] = m_advances[index2];
    m_advances[index2] = s;
}

Glyph BCGlyphBufferDirectFB::glyphAt(int index) const
{
    DBGML(MODULE_FONTS, LEVEL_INFO, "\nBCGlyphBufferDirectFB::glyphAt(%d) const\n", index);
    return m_glyphs[index];
}

float BCGlyphBufferDirectFB::advanceAt(int index) const
{
    DBGML(MODULE_FONTS, LEVEL_INFO, "\nBCGlyphBufferDirectFB::advanceAt(%d) const = %f\n", index, m_advances[index].width());
    return m_advances[index].width();
}

FloatSize BCGlyphBufferDirectFB::offsetAt(int index) const
{
    DBGML(MODULE_FONTS, LEVEL_INFO, "\nBCGlyphBufferDirectFB::offsetAt(%d) const\n", index);
    return FloatSize();
}

void BCGlyphBufferDirectFB::add(Glyph glyph, const BTFontData* font, float width, const FloatSize* offset)
{
    DBGML(MODULE_FONTS, LEVEL_INFO, "\nBCGlyphBufferDirectFB::add('%c')\n", glyph);
    m_fontData.append(font);
    m_glyphs.append(glyph);
    m_advances.append(FloatSize(width, 0));
}

} //namespace BAL
