/*
 *  TnFreeTypeGlyphProxy.h
 *
 *  Created by Thant on 3/11/2011
 *  Copyright 2011 TeleNav Inc. All rights reserved.
 *
 */


#ifndef TN_FREETYPE_GLYPH_PROXY_H
#define TN_FREETYPE_GLYPH_PROXY_H

#include <string>
#include <map>
#include <list>

#include <foundation/Mutex.h>
#include <foundation/SharedPtr.h>

#include <RenderEngine/TnDeprecate.h>
#include <RenderEngine/ITnMapGlyphProxy.h>


struct TnFreeTypeGlyphProxyImpl;
class TnFreeTypeFaceData;

class TnFreeTypeGlyphProxy : public ITnMapGlyphProxy
{
public:

    typedef Tn::Foundation::shared_ptr<TnFreeTypeGlyphProxy> ptr;
    typedef Tn::Foundation::weak_ptr<TnFreeTypeGlyphProxy> wptr;

    TnFreeTypeGlyphProxy();
    ~TnFreeTypeGlyphProxy();

    // This no longer does anything.
    TNMAP_DEPRECATED(void LoadFont(std::string const &, std::string const &);)

    /*  A given font file is loaded only once. The font name is
     *  expected to include whether the font is bold or italic or both
     *  in the case where that matters.
     */

    /*! FontPath takes a printf-style format string. It is used to
     *  generate a file path using the font name specified in the
     *  glyph request. For example, the format string:
     *
     *  "/system/fonts/%s.ttf"
     *
     *  along with the font name "DroidSans" specified in the
     *  configuration file, will find a font at:
     *
     *  /system/fonts/DroidSans.ttf
     *
     *  The client can specify more than one font path. Each path is
     *  tried from latest to earliest. The first path specified should be the
     *  complete path to a known font. This lets it serve as the
     *  fallthrough if an invalid or unknown font name is specified.
     */

    void FontPath(char const *);

    virtual void RequestGlyph(TnMapGlyphData::ptr const & data);
    virtual void CancelRequest(TnMapGlyphData::ptr const & data);

protected:

    Tn::Foundation::shared_ptr<TnFreeTypeGlyphProxyImpl> m_impl;

    typedef std::list<std::string> PathList;
    PathList m_pathList;

    typedef Tn::Foundation::shared_ptr<TnFreeTypeFaceData> FaceDataPtr;
    typedef std::map<std::string, FaceDataPtr > FaceMap;
    typedef std::pair<std::string, FaceDataPtr > FaceMapEntry;
    FaceMap m_faceMap;

    FaceDataPtr FindFace(std::string faceName);

	mutable Tn::Foundation::mutex         m_mutex;
};

#endif
