#pragma once

#include <string>
#include <memory>
#include <vector>
#include "IFont.h"
#include "File.h"

class File;

class FontReader
{
public:
    ~FontReader();
    void setPath(const std::string& path);

    std::unique_ptr<IFont> read();

private:

    struct OffsetSubtable
    {
        uint32_t scaler_type{0};
        uint16_t num_tables{0};
        uint16_t search_range{0};
        uint16_t entry_selector{0};
        uint16_t range_shift{0};
    };

    struct Table
    {
        std::string name;
        unsigned checksum{0};
        unsigned offset{0};
        unsigned length{0};
    };

    bool readOffsetSubtable();
    void logOffsetSubtable();
    void logTable(const Table& table);

    void readTableDirectory();

    void readTable();
    void readHeadTable();

    unsigned mCurrentOffset{0};
    OffsetSubtable mOffsetSubtable;
    std::vector<Table> mTables;

    std::unique_ptr<IFont> mWorkingFont;
    std::unique_ptr<File> mFile;
    std::string mPath;
};
