//
// Created by m on 12/5/21.
//

#include "sdlfontmanager.hpp"

std::string SdlFontManager::get_key(SdlFontArgs args) {
    return fmt::format("{}_{}", args.size, get_resource_path(args.font_path));
}

std::shared_ptr<TTF_Font> SdlFontManager::load_resource(SdlFontArgs args) {
    std::string path = get_resource_path(args.font_path);
    TTF_Font *font = TTF_OpenFont(path.c_str(), args.size);
    if(font == nullptr) {
        throw MissingFontException(path, TTF_GetError());
    }
    return std::shared_ptr<TTF_Font>(font, TTF_CloseFont);
}
