/*
 * Copyright (C) Research In Motion Limited 2009. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this library; see the file COPYING.LIB.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

#ifndef FontPlatformDataPrivate_h
#define FontPlatformDataPrivate_h

#include "FloatSize.h"
#include "GlyphBuffer.h"

#if USE(FREETYPE)
#include <ft2build.h>
#include FT_FREETYPE_H
#endif
#include <fontconfig/fontconfig.h>

#include <openvg.h>

#include <wtf/HashMap.h>
#include <wtf/HashTraits.h>
#include <wtf/Platform.h>
#include <wtf/RefCounted.h>
#include <wtf/text/CString.h>

namespace WebCore {

class SharedBuffer;

class FontPlatformDataPrivate : public RefCounted<FontPlatformDataPrivate> {
public:
    FontPlatformDataPrivate(float size, bool bold, bool italic)
        : m_size(size)
        , m_bold(bold)
        , m_italic(italic)
		, m_pattern(0)
#if USE(FREETYPE)
        , m_ftFace(0)
        , m_buffer(0)
#endif
#ifdef OPENVG_VERSION_1_1
        , m_vgFont(0)
#endif
    {
    }

    FontPlatformDataPrivate(const FontPlatformDataPrivate&);
    FontPlatformDataPrivate& operator=(const FontPlatformDataPrivate&);

    ~FontPlatformDataPrivate();

    void clear();

    void setFont(FcPattern* pattern);
#if USE(FREETYPE)
    void setBuffer(SharedBuffer* buffer);
#endif
    //void attachFontFile(const char* filename);

    float m_size;
    bool m_bold;
    bool m_italic;
	FcPattern* m_pattern;

#if USE(FREETYPE)
    static FT_Library s_ftLibrary; // handle to FreeType library
    FT_Face m_ftFace;
    SharedBuffer* m_buffer; // font data if memory face
#endif
#ifdef OPENVG_VERSION_1_1
    VGFont m_vgFont;
#endif

    struct GlyphDataVG {
    	WTF_MAKE_FAST_ALLOCATED;
    public:
        Vector<VGubyte> commands;
        Vector<VGbyte> bytePoints;
        Vector<VGfloat> floatPoints;
        VGfloat escapement[2];
        bool loaded;
    };

    WTF::HashMap<unsigned int, GlyphDataVG, WTF::DefaultHash<unsigned int>::Hash> m_glyphData;
};

} // namespace WebCore

#endif
