/*
 *  TnGlyphPlace.h
 *  Util
 *
 *  Created by Thant on 1/21/2014
 *  Copyright 2014 TeleNav Inc. All rights reserved.
 *
 */

#ifndef Util_TnGlyphPlace_INCLUDED
#define Util_TnGlyphPlace_INCLUDED

#include <map>
#include <deque>

#include <foundation/SharedPtr.h>
#include <foundation/TnTypes.h>
#include <foundation/Math/Vec.hpp>
#include <foundation/Math/Point.hpp>

namespace Tn {

namespace util {


typedef std::deque<Tn::math::Vec2f> Vec2fDeq;
typedef Tn::Foundation::shared_ptr<Vec2fDeq> Vec2fDeqPtr;


typedef std::map<uint32_t, Tn::math::Vec2f> KerningMap;
typedef boost::shared_ptr<KerningMap> KerningMapPtr;


struct GlyphGeom {

    /* All this is relative to the glyph bitmap. So origin is the
     * origin of the glyph within the bitmap. */

    typedef Tn::Foundation::shared_ptr<GlyphGeom> ptr;

    GlyphGeom(float width, 
              float height,
              Tn::math::Point<2,float> origin,
              Tn::math::Vec<2,float> advance,
              Tn::math::Point<2,float> center,
              KerningMapPtr const & kerning) :
        width(width),
        height(height),
        origin(origin),
        advance(advance),
        center(center),
        kerning(kerning) {}

    float width;
    float height;
    Tn::math::Point2f origin;
    Tn::math::Vec2f advance;
    Tn::math::Point2f center;

    KerningMapPtr kerning;
};


struct GlyphPlacement {

    /* All of this describes the bitmap placement. So origin is the
     * lower-left position of the bitmap, not the lower-left position
     * of the glyph within the bitmap. */

    typedef Tn::Foundation::shared_ptr<GlyphPlacement> ptr;

    GlyphPlacement(Tn::math::Point<2,float> const & origin,
                   Tn::math::Vec<2,float> const & x,
                   Tn::math::Vec<2,float> const & y) :
        origin(origin),
        horizontal(x),
        vertical(y) {}

    Tn::math::Point<2,float> origin;
    Tn::math::Vec<2,float> horizontal;
    Tn::math::Vec<2,float> vertical;
};

typedef std::deque<GlyphGeom> GlyphGeomDeq;
typedef Tn::Foundation::shared_ptr<GlyphGeomDeq> GlyphGeomDeqPtr;

typedef std::deque<GlyphPlacement> GlyphPlacementDeq;
typedef Tn::Foundation::shared_ptr<GlyphPlacementDeq> GlyphPlacementDeqPtr;


} // namespace util

} // namespace Tn

#endif
