#define STB_TRUETYPE_IMPLEMENTATION
#define STBTT_STATIC

#define FONT_ARENA_MEMORY_SIZE_MB 16

#include "stb_truetype.h"

typedef struct F_InitReceipt F_InitReceipt;
struct F_InitReceipt
{
  U64 u64[1];
};

typedef struct F_Atlas F_Atlas;
struct F_Atlas
{
  R_Handle texture;
  U64 start_glyph;
  U64 last_glyph;
  Vec2_S64 size;
};


typedef struct F_State F_State;
struct F_State
{
  Arena* arena;
  U8 *baked_atlas;
  F_Atlas atlas;
  stbtt_bakedchar *cdata;
};

typedef struct F_Piece F_Piece;
struct F_Piece
{
  F_Piece *next;
  R_Handle texture;
  Rng2_F32 src_rect;
  Vec2_F32 dst_p0;
  Vec2_F32 dst_p1;
  Vec2_F32 offset;
  F32 advance;
  U32 decode_size;
};

// A sequence of glyphs to render, linked list implementation
typedef struct F_Run F_Run;
struct F_Run
{
  F_Piece *first_piece;
  F_Piece *last_piece;
  U64 piece_count;
  F32 advance;
};







////////////////////////////
//~ Font forward declarations
root_function Arena *F_get_font_arena();
root_function F_InitReceipt F_init();
root_function U8 *F_get_baked_atlas();
root_function R_Handle F_atlas_texture_handle();
root_function F_Run F_run_from_string(Arena *arena, String8 string, Vec2_F32 position);
root_function F_State *F_get_state(); // TODO remove this its only for d3d11 shutdown crap 