<commit_before>//
// Created by desktop on 21.10.16.
//

#include "zCFont.h"
#include "zenParser.h"
#include <vdfs/fileIndex.h>
#include <utils/logger.h>
#include <algorithm>

using namespace ZenLoad;

zCFont::zCFont(const std::string& fileName, const VDFS::FileIndex& fileIndex)
{
    std::string fntFile = fileName;
    std::transform(fntFile.begin(), fntFile.end(), fntFile.begin(), ::tolower);

    if(fntFile.find(".tga") != std::string::npos)
        fntFile = fntFile.substr(0, fntFile.size() - 4) + ".FNT";
    else if(fntFile.find(".fnt") == std::string::npos)
        fntFile += ".FNT";

    std::vector<uint8_t> data;
    fileIndex.getFileData(fileName, data);

    if(data.empty())
        return; // TODO: Throw an exception or something

    parseFNTData(data);
}

zCFont::~zCFont()
{

}

bool zCFont::parseFNTData(const std::vector<uint8_t>& fntData)
{
    try
    {
        // Create parser from memory
        // FIXME: There is an internal copy of the data here. Optimize!
        ZenLoad::ZenParser parser(fntData.data(), fntData.size());

        /**
         * FNT-format is pretty simple:
         * [string]: version\n
         * [string]: name\n
         * [uint32_t]: height
         * [uint32_t]: magicNumber? (MUST be always 0xFF)
         * [uint8_t]: width[FONT_NUM_MAX_LETTERS]
         * [float2]:  fontUV1[FONT_NUM_MAX_LETTERS]
         * {float2]:  fontUV2[FONT_NUM_MAX_LETTERS]
         */

        std::string version = parser.readLine();

        // Only version 1 is used by gothic
        if(version != "1")
        {
            LogError() << "Unknown font-version: " << version;
            return false;
        }

        std::string name = parser.readLine();

        uint32_t height = parser.readBinaryDWord();
        uint32_t magic = parser.readBinaryDWord();

        if(magic != 256)
        {<commit_msg>Fixed a loading issue with FONT_OLD_20_WHITE.TGA from Textures_Addon.vdf<commit_after>//
// Created by desktop on 21.10.16.
//

#include "zCFont.h"
#include "zenParser.h"
#include <vdfs/fileIndex.h>
#include <utils/logger.h>
#include <algorithm>

using namespace ZenLoad;

zCFont::zCFont(const std::string& fileName, const VDFS::FileIndex& fileIndex)
{
    std::string fntFile = fileName;
    std::transform(fntFile.begin(), fntFile.end(), fntFile.begin(), ::tolower);

    if(fntFile.find(".tga") != std::string::npos)
        fntFile = fntFile.substr(0, fntFile.size() - 4) + ".FNT";
    else if(fntFile.find(".fnt") == std::string::npos)
        fntFile += ".FNT";

    std::vector<uint8_t> data;
    fileIndex.getFileData(fileName, data);

    if(data.empty())
        return; // TODO: Throw an exception or something

    parseFNTData(data);
}

zCFont::~zCFont()
{

}

bool zCFont::parseFNTData(const std::vector<uint8_t>& fntData)
{
    try
    {
        // Create parser from memory
        // FIXME: There is an internal copy of the data here. Optimize!
        ZenLoad::ZenParser parser(fntData.data(), fntData.size());

        /**
         * FNT-format is pretty simple:
         * [string]: version\n
         * [string]: name\n
         * [uint32_t]: height
         * [uint32_t]: magicNumber? (MUST be always 0xFF)
         * [uint8_t]: width[FONT_NUM_MAX_LETTERS]
         * [float2]:  fontUV1[FONT_NUM_MAX_LETTERS]
         * {float2]:  fontUV2[FONT_NUM_MAX_LETTERS]
         */

        std::string version = parser.readLine();

        // Only version 1 is used by gothic
        if(version != "1")
        {
            LogError() << "Unknown font-version: " << version;
            return false;
        }

        std::string name = parser.readLine(false);

        uint32_t height = parser.readBinaryDWord();
        uint32_t magic = parser.readBinaryDWord();

        if(magic != 256)
        {
{'fraction_non_alphanumeric': 0.1464190981432361, 'fraction_numerical': 0.015915119363395226, 'mean_word_length': 2.584600760456274, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6495474', 'n_tokens_mistral': 1333, 'n_tokens_neox': 1287, 'n_words': 271}