<commit_before>#include <allegro.h>
#include "font.h"
#include "init.h"
#include "factory/font_factory.h"

Font::Font(){
}

Font::~Font(){
}

AllegroFont::AllegroFont( const FONT * const font ):
font( font ){
}
	
AllegroFont::AllegroFont( const AllegroFont & copy ):
font( copy.getInternalFont() ){
}

AllegroFont::~AllegroFont(){
}
	
const int AllegroFont::textLength( const char * text ) const{
	return text_length( getInternalFont(), text );
}

const int AllegroFont::getHeight( const string & str ) const {
	return getHeight();
}

const int AllegroFont::getHeight() const {
	return text_height( getInternalFont() );
}

void AllegroFont::setSize( const int x, const int y ){
}

const int AllegroFont::getSizeX() const {
	return 0;
}

const int AllegroFont::getSizeY() const {
	return 0;
}
	
void AllegroFont::printf( int x, int y, int color, const Bitmap & work, const string & str, int marker, ... ) const {
	char buf[512];
	va_list ap;

	va_start(ap, marker);
	uvszprintf(buf, sizeof(buf), str.c_str(), ap);
	va_end(ap);

	textout_ex( work.getBitmap(), getInternalFont(), buf, x, y, color, -1 );
}

const Font & Font::getDefaultFont(){
	// return getFont( "tmp/comic.ttf" );
	return getFont( "bios", 16, 16 );
}
	
const Font & Font::getFont( const string & name, const int x, const int y ){
	return *FontFactory::getFont( name, x, y );
}

FreeTypeFont::FreeTypeFont( const string & str ):
sizeX( 16 ),
sizeY( 16 ){
	this->font = new ftalleg::freetype( str, getSizeX(), getSizeY() );
}

const int FreeTypeFont::getHeight( const string & str ) const {
	return this->font->getHeight( str );
}

const int FreeTypeFont::getHeight() const {
	return getHeight( "A" );
}

const int FreeTypeFont::textLength( const char * text ) const {
	return this->font->getLength( string( text ) );
}
	
void FreeTypeFont::printf( int x, int y, int color, const Bitmap & work, const string & str, int marker, ... ) const {
	char buf[512];
	va_list ap;

	va_start(ap, marker);
	uvszprintf(buf, sizeof(buf), str.c_str(), ap);
	va_end(ap);

	this->font->render( x, y, color, work.getBitmap(), ftalleg::freetype::ftLeft, string( buf ), 0 );
}

void FreeTypeFont::setSize( const int x, const int y ){
	this->sizeX = x;
	this->sizeY = y;
	this->font->setSize( this->sizeX, this->sizeY );
}

const int FreeTypeFont::getSizeX() const {
	return this->sizeX;
}

const int FreeTypeFont::getSizeY() const {
	return this->sizeY;
}

FreeTypeFont::~FreeTypeFont(){
	// cout << "Delete font " << this->font << endl;
	delete this->font;
}
<commit_msg>use regular ansi function instead of allegros vsprintf<commit_after>#include <allegro.h>
#include "font.h"
#include "init.h"
#include "factory/font_factory.h"

Font::Font(){
}

Font::~Font(){
}

AllegroFont::AllegroFont( const FONT * const font ):
font( font ){
}
	
AllegroFont::AllegroFont( const AllegroFont & copy ):
font( copy.getInternalFont() ){
}

AllegroFont::~AllegroFont(){
}
	
const int AllegroFont::textLength( const char * text ) const{
	return text_length( getInternalFont(), text );
}

const int AllegroFont::getHeight( const string & str ) const {
	return getHeight();
}

const int AllegroFont::getHeight() const {
	return text_height( getInternalFont() );
}

void AllegroFont::setSize( const int x, const int y ){
}

const int AllegroFont::getSizeX() const {
	return 0;
}

const int AllegroFont::getSizeY() const {
	return 0;
}
	
void AllegroFont::printf( int x, int y, int color, const Bitmap & work, const string & str, int marker, ... ) const {
	char buf[512];
	va_list ap;

	va_start(ap, marker);
	uvszprintf(buf, sizeof(buf), str.c_str(), ap);
	va_end(ap);

	textout_ex( work.getBitmap(), getInternalFont(), buf, x, y, color, -1 );
}

const Font & Font::getDefaultFont(){
	// return getFont( "tmp/comic.ttf" );
	return getFont( "bios", 16, 16 );
}
	
const Font & Font::getFont( const string & name, const int x, const int y ){
	return *FontFactory::getFont( name, x, y );
}

FreeTypeFont::FreeTypeFont( const string & str ):
sizeX( 16 ),
sizeY( 16 ){
	this->font = new ftalleg::freetype( str, getSizeX(), getSizeY() );
}

const int FreeTypeFont::getHeight( const string & str ) const {
	return this->font->getHeight( str );
}

const int FreeTypeFont::getHeight() const {
	return getHeight( "A" );
}

const int FreeTypeFont::textLength( const char * text ) const {
	return this->font->getLength( string( text ) );
}
	
void FreeTypeFont::printf( int x, int y, int color, const Bitmap & work, const string & str, int marker, ... ) const {
	char buf[512];
	va_list ap;

	va_start(ap, marker);
	vsnprintf(buf, sizeof(buf), str.c_str(), ap);
	va_end(ap);

	this->font->render( x, y, color, work.getBitmap(), ftalleg::freetype::ftLeft, string( buf ), 0 );
}

void FreeTypeFont::setSize( const int x, const int y ){
	this->sizeX = x;
	this->sizeY = y;
	this->font->setSize( this->sizeX, this->sizeY );
}

const int FreeTypeFont::getSizeX() const {
	return this->sizeX;
}

const int FreeTypeFont::getSizeY() const {
	return this->sizeY;
}

FreeTypeFont::~FreeTypeFont(){
	// cout << "Delete font " << this->font << endl;
	delete this->font;
}

{'fraction_non_alphanumeric': 0.16167192429022081, 'fraction_numerical': 0.007097791798107256, 'mean_word_length': 4.7, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 39, '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': '6228394', 'n_tokens_mistral': 1865, 'n_tokens_neox': 1803, 'n_words': 505}