<commit_before>/*
This file is part of Groho, a simulator for inter-planetary travel and warfare.
Copyright (c) 2018 by <NAME>. Some rights reserved, see LICENSE

Handles font cache
*/

#pragma once

#include <Corrade/PluginManager/Manager.h>
#include <Magnum/Text/AbstractFont.h>
#include <Magnum/Text/DistanceFieldGlyphCache.h>
#include <Magnum/Text/Renderer.h>

namespace sim {

using namespace Magnum;

class Font {

public:
    Font(std::string fname = "resources/UbuntuMono-R.ttf")
        : _cache(Vector2i(2048), Vector2i(512), 22)
    {
        _font = _manager.loadAndInstantiate("FreeTypeFont");
        if (!_font)
            std::exit(1);

        /* Open the font and fill glyph cache */
        Utility::Resource rs("fonts");
        if (!_font->openSingleData(rs.getRaw(fname), 200.0f)) {
            Error() << "Cannot open font file";
            std::exit(1);
        }

        _font->fillGlyphCache(
            _cache,
            "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789: "
            "-+.\n");
    }

    static void enable_blending()
    {
        GL::Renderer::enable(GL::Renderer::Feature::Blending);
        GL::Renderer::setBlendFunction(
            GL::Renderer::BlendFunction::SourceAlpha,
            GL::Renderer::BlendFunction::OneMinusSourceAlpha);
        GL::Renderer::setBlendEquation(
            GL::Renderer::BlendEquation::Add, GL::Renderer::BlendEquation::Add);
    }

private:
    PluginManager::Manager<Text::AbstractFont> _manager;

public:
    std::unique_ptr<Text::AbstractFont> _font;
    Text::DistanceFieldGlyphCache       _cache;
};
}<commit_msg>Tweaks to render font better<commit_after>/*
This file is part of Groho, a simulator for inter-planetary travel and warfare.
Copyright (c) 2018 by <NAME>. Some rights reserved, see LICENSE

Handles font cache
*/

#pragma once

#include <Corrade/PluginManager/Manager.h>
#include <Magnum/Text/AbstractFont.h>
#include <Magnum/Text/DistanceFieldGlyphCache.h>
#include <Magnum/Text/Renderer.h>

namespace sim {

using namespace Magnum;

class Font {

public:
    Font(std::string fname = "resources/UbuntuMono-R.ttf")
        : _cache(Vector2i(2048), Vector2i(512), 5)
    {
        _font = _manager.loadAndInstantiate("FreeTypeFont");
        if (!_font)
            std::exit(1);

        /* Open the font and fill glyph cache */
        Utility::Resource rs("fonts");
        if (!_font->openSingleData(rs.getRaw(fname), 110.0f)) {
            Error() << "Cannot open font file";
            std::exit(1);
        }

        _font->fillGlyphCache(
            _cache,
            "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789: "
            "-+.\n");
    }

    static void enable_blending()
    {
        GL::Renderer::enable(GL::Renderer::Feature::Blending);
        GL::Renderer::setBlendFunction(
            GL::Renderer::BlendFunction::SourceAlpha,
            GL::Renderer::BlendFunction::OneMinusSourceAlpha);
        GL::Renderer::setBlendEquation(
            GL::Renderer::BlendEquation::Add, GL::Renderer::BlendEquation::Add);
    }

private:
    PluginManager::Manager<Text::AbstractFont> _manager;

public:
    std::unique_ptr<Text::AbstractFont> _font;
    Text::DistanceFieldGlyphCache       _cache;
};
}
{'fraction_non_alphanumeric': 0.12998160637645617, 'fraction_numerical': 0.01870018393623544, 'mean_word_length': 3.125158027812895, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, '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': '4516845', 'n_tokens_mistral': 1090, 'n_tokens_neox': 1015, 'n_words': 198}