<commit_before>/////////////////////////////////////////
//
//   OpenLieroX
//
//   Auxiliary Software class library
//
//   based on the work of JasonB
//   enhanced by <NAME> and <NAME>
//
//   code under LGPL
//
/////////////////////////////////////////


// Font class
// Created 15/7/01
// <NAME>


#include "defs.h"
#include "LieroX.h"
#include "GfxPrimitives.h"
#include "Unicode.h"

//
// IMPORTANT: all surfaces in CFont are alpha blended which means they can (and mostly do) have another format than screen.
// Because of this we cannot use almost any of the color handling functions from GfxPrimitives
// Format of the surfaces is guaranted to be 32bit ARGB
//


// For font drawing use FontGenerator tool in /tools/fontgenerator

///////////////////
// Load a font
int CFont::Load(const std::string& fontname, bool _colour)
{

	LOAD_IMAGE_WITHALPHA(bmpFont,fontname);

	Colorize = _colour;

	bmpWhite = gfxCreateSurfaceAlpha(bmpFont->w,bmpFont->h);
	bmpGreen = gfxCreateSurfaceAlpha(bmpFont->w,bmpFont->h);

	// Calculate the width of each character and number of characters
	Parse();

	// Precache some common font colors (but only if this font should be colorized)
	if (Colorize)  {
		PreCalculate(bmpWhite,tLX->clNormalLabel);
		PreCalculate(bmpGreen,tLX->clChatText);
	}


	// Pre-calculate some colours
	f_white = tLX->clNormalLabel;
	f_green = tLX->clChatText;

	// Set the color key for this alpha surface (SDL_SetColorKey does not work for alpha blended surfaces)
	SetColorKeyAlpha(bmpFont, 255,0,255);

	return true;
}


///////////////////
// Shutdown the font
void CFont::Shutdown(void)
{
	if(bmpWhite)  {
		SDL_FreeSurface(bmpWhite);
		bmpWhite = NULL;
	}
	if(bmpGreen)  {
		SDL_FreeSurface(bmpGreen);
		bmpGreen = NULL;
	}
}


//////////////////
// Helper function for CalculateWidth
// Checks, whether a vertical line is free (all pixels pink)<commit_msg>CFont fix<commit_after>/////////////////////////////////////////
//
//   OpenLieroX
//
//   Auxiliary Software class library
//
//   based on the work of JasonB
//   enhanced by <NAME> and <NAME>
//
//   code under LGPL
//
/////////////////////////////////////////


// Font class
// Created 15/7/01
// <NAME>


#include "defs.h"
#include "LieroX.h"
#include "GfxPrimitives.h"
#include "Unicode.h"

//
// IMPORTANT: all surfaces in CFont are alpha blended which means they can (and mostly do) have another format than screen.
// Because of this we cannot use almost any of the color handling functions from GfxPrimitives
// Format of the surfaces is guaranted to be 32bit ARGB
//


// For font drawing use FontGenerator tool in /tools/fontgenerator

///////////////////
// Load a font
int CFont::Load(const std::string& fontname, bool _colour)
{

	// Load the font
	LOAD_IMAGE_WITHALPHA(bmpFont,fontname);

	// Set the color key for this alpha surface (SDL_SetColorKey does not work for alpha blended surfaces)
	SetColorKeyAlpha(bmpFont, 255,0,255);

	Colorize = _colour;

	bmpWhite = gfxCreateSurfaceAlpha(bmpFont->w,bmpFont->h);
	bmpGreen = gfxCreateSurfaceAlpha(bmpFont->w,bmpFont->h);

	// Calculate the width of each character and number of characters
	Parse();

	// Precache some common font colors (but only if this font should be colorized)
	if (Colorize)  {
		PreCalculate(bmpWhite,tLX->clNormalLabel);
		PreCalculate(bmpGreen,tLX->clChatText);
	}


	// Pre-calculate some colours
	f_white = tLX->clNormalLabel;
	f_green = tLX->clChatText;

	return true;
}


///////////////////
// Shutdown the font
void CFont::Shutdown(void)
{
	if(bmpWhite)  {
		SDL_FreeSurface(bmpWhite);
		bmpWhite = NULL;
	}
	if(bmpGreen)  {
		SDL_FreeSurface(bmpGreen);
		bmpGreen = NULL;
	}
}


//////////////////
// Helper function for CalculateWidth
// Checks, whether a vertical line is free (all pixels pink)
{'fraction_non_alphanumeric': 0.17266949152542374, 'fraction_numerical': 0.007415254237288136, 'mean_word_length': 2.6993143976493634, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 25, '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': '618491', 'n_tokens_mistral': 1283, 'n_tokens_neox': 1193, 'n_words': 373}