
#include "kjs/wk_config.h"
#include "BALConfiguration.h"
#include <font/BTFont.h>
#include "../../Graphics/DirectFB/BCNativeImageDirectFB.h"
#include "BCFontPlatformDataPrivateDirectFB.h"
#include "BTWidget.h"
#include <font/FontData.h>
#include <graphics/GraphicsContext.h>
#include "RGBA32Array.h"

#include <directfb.h>

#include "BTLogHelper.h"

namespace BAL {

class BCNativeImage;

void BTFont::drawGlyphs(GraphicsContext* graphicsContext, const FontData* font, const GlyphBuffer& glyphBuffer,
                      int from, int numGlyphs, const FloatPoint& point) const
{
    DBGML(MODULE_FONTS, LEVEL_INFO, "\nBTFont::drawGlyphs() numGlyphs=%d\n", numGlyphs);
    // Set the text color to use for drawing.
    float red, green, blue, alpha;
    Color penColor = graphicsContext->fillColor();
    penColor.getRGBA(red, green, blue, alpha);

    GlyphBufferGlyph* glyphs = const_cast<GlyphBufferGlyph*>(glyphBuffer.glyphs(from));
    float offset = 0.0;
    IDirectFBSurface* surface = ((BCNativeImage *)(graphicsContext->widget()->backingStore()))->getNativeDirectFB();

    surface->SetColor(surface, (int)(red*0xff), (int)(green*0xff), (int)(blue*0xff), (int)(alpha*0xff));
    surface->SetFont(surface, static_cast<BCFontPlatformDataPrivateDirectFB *> (font->platformData().impl())->getDFBFont ());
#if 1
    for (int i = 0; i < numGlyphs; i++) {
        surface->DrawGlyph(surface, glyphs[i], (int)(point.x() + offset), (int)(point.y()), DSTF_LEFT);
        offset += glyphBuffer.advanceAt(from + i);
    }
#else // não funcionou :
    surface->DrawString(surface, (const char *)glyphs, numGlyphs, (int)point.x(), (int)point.y(), DSTF_LEFT);
#endif
}

void BTFont::drawComplexText(GraphicsContext*, const TextRun&, const TextStyle&, const FloatPoint&, int from, int to) const
{
    BALNotImplemented();
}

float BTFont::floatWidthForComplexText(const TextRun&, const TextStyle&) const
{
    BALNotImplemented();
    return 0.0f;
}

int BTFont::offsetForPositionForComplexText(const TextRun&, const TextStyle&, int, bool) const
{
    BALNotImplemented();
    return 0;
}

FloatRect BTFont::selectionRectForComplexText(const TextRun&, const TextStyle&, const IntPoint&, int, int, int) const
{
    BALNotImplemented();
    return FloatRect();
}

}
