<commit_before>#include "dioptre/font/freetype/font.h"
#include "dioptre/font/freetype/face.h"
#include "dioptre/locator.h"

#include <exception>
#include <stdexcept>

namespace dioptre {
namespace font {
namespace freetype {

Face::Face(std::string fontFile) :
  dioptre::font::Face(fontFile)
{
  auto font = dioptre::Locator::getInstance<dioptre::font::freetype::Font>(dioptre::Module::M_FONT);
  auto filesystem = dioptre::Locator::getInstance<dioptre::filesystem::FilesystemInterface>(dioptre::Module::M_FILESYSTEM);

  auto size = filesystem->getSize(fontFile);

  unsigned char* buffer = new unsigned char[size];
  auto read = filesystem->read(fontFile, buffer, size);

  if (FT_New_Memory_Face(font->getLibrary(), buffer, size, 0, &face_)) {
    std::string error("Unable to load font: ");
    error.append(fontFile);

    throw std::runtime_error(error);
  }

  glyphSlot_ = new GlyphSlot(face_->glyph);

  delete buffer;
}

int Face::loadChar(int i) {
  return FT_Load_Char(face_, i, FT_LOAD_RENDER);
}

void Face::setSize(int width, int height) {
  FT_Set_Pixel_Sizes(face_, width, height);
}

GlyphSlot* Face::getGlyphSlot() {
  return glyphSlot_;
}

Face::~Face() {
  FT_Done_Face(face_);
}

} // freetype
} // font
} // dioptre
<commit_msg>keep font buffer for time of usage<commit_after>#include "dioptre/font/freetype/font.h"
#include "dioptre/font/freetype/face.h"
#include "dioptre/locator.h"

#include <exception>
#include <stdexcept>

namespace dioptre {
namespace font {
namespace freetype {

Face::Face(std::string fontFile) :
  dioptre::font::Face(fontFile)
{
  auto font = dioptre::Locator::getInstance<dioptre::font::freetype::Font>(dioptre::Module::M_FONT);
  auto filesystem = dioptre::Locator::getInstance<dioptre::filesystem::FilesystemInterface>(dioptre::Module::M_FILESYSTEM);

  auto size = filesystem->getSize(fontFile);

  unsigned char* buffer = new unsigned char[size];
  auto read = filesystem->read(fontFile, buffer, size);

  if (FT_New_Memory_Face(font->getLibrary(), buffer, size, 0, &face_)) {
    std::string error("Unable to load font: ");
    error.append(fontFile);

    throw std::runtime_error(error);
  }

  glyphSlot_ = new GlyphSlot(face_->glyph);
}

int Face::loadChar(int i) {
  return FT_Load_Char(face_, i, FT_LOAD_RENDER);
}

void Face::setSize(int width, int height) {
  FT_Set_Pixel_Sizes(face_, width, height);
}

GlyphSlot* Face::getGlyphSlot() {
  return glyphSlot_;
}

Face::~Face() {
  FT_Done_Face(face_);
}

} // freetype
} // font
} // dioptre

{'fraction_non_alphanumeric': 0.1526504583499402, 'fraction_numerical': 0.0007971303308090873, 'mean_word_length': 5.711229946524064, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 19, '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': '6594094', 'n_tokens_mistral': 915, 'n_tokens_neox': 893, 'n_words': 168}