Code style
This commit is contained in:
parent
7d9d0a2772
commit
c756ac46bc
51
src/rtext.c
51
src/rtext.c
|
|
@ -381,22 +381,49 @@ Font LoadFontEx(const char *fileName, int fontSize, int *codepoints, int codepoi
|
||||||
// Reload the font after adding the new characters to the list of desired characters
|
// Reload the font after adding the new characters to the list of desired characters
|
||||||
void AddNewCharsToFontEx(Font *font, const char *fileName, int fontSize, char *newChars)
|
void AddNewCharsToFontEx(Font *font, const char *fileName, int fontSize, char *newChars)
|
||||||
{
|
{
|
||||||
int codepointCount = 0;
|
// Get the codepoints of the newChars
|
||||||
int *codepoints = LoadCodepoints(newChars, &codepointCount);
|
int codepointCount = 0;
|
||||||
|
int *codepoints = LoadCodepoints(newChars, &codepointCount);
|
||||||
|
|
||||||
int newCount = font->glyphCount + codepointCount;
|
// Maximum value of the number of codepoints in the updated Font
|
||||||
|
int newCount = font->glyphCount + codepointCount;
|
||||||
|
|
||||||
int *newCodepoints = MemAlloc(newCount * sizeof(int));
|
// Allocate space for the new codepoints and populate it
|
||||||
for (int i=0; i<font->glyphCount; i++) {
|
int *newCodepoints = MemAlloc(newCount * sizeof(int));
|
||||||
newCodepoints[i] = font->glyphs[i].value;
|
|
||||||
}
|
|
||||||
for (int i=font->glyphCount; i<newCount; i++) {
|
|
||||||
newCodepoints[i] = codepoints[i-font->glyphCount];
|
|
||||||
}
|
|
||||||
|
|
||||||
*font = LoadFontEx(fileName, fontSize, newCodepoints, newCount);
|
int codepointCountWithNoDupes = 0; // We don't need to assign chars that already exist in the Font
|
||||||
|
for (int i = 0; i < font->glyphCount; i++)
|
||||||
|
{
|
||||||
|
newCodepoints[i] = font->glyphs[i].value;
|
||||||
|
codepointCountWithNoDupes += 1;
|
||||||
|
}
|
||||||
|
|
||||||
MemFree(newCodepoints);
|
for (int i = font->glyphCount; i < newCount; i++)
|
||||||
|
{
|
||||||
|
bool codepointIsUnique = true;
|
||||||
|
int cp = codepoints[i-font->glyphCount];
|
||||||
|
|
||||||
|
// This loop checks for the existence for the existence of the newChars in the input Font
|
||||||
|
for (int j = 0; j < font->glyphCount; j++)
|
||||||
|
{
|
||||||
|
if (cp == font->glyphs[j].value)
|
||||||
|
{
|
||||||
|
codepointIsUnique = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (codepointIsUnique)
|
||||||
|
{
|
||||||
|
newCodepoints[codepointCountWithNoDupes] = cp;
|
||||||
|
codepointCountWithNoDupes += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unload the Font and then reassign the newly built Font
|
||||||
|
UnloadFont(*font);
|
||||||
|
*font = LoadFontEx(fileName, fontSize, newCodepoints, codepointCountWithNoDupes);
|
||||||
|
|
||||||
|
MemFree(newCodepoints);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load an Image font file (XNA style)
|
// Load an Image font file (XNA style)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user