1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-12-22 17:49:43 +01:00

Replace utfcpp by UTF8.h in Font.cpp

I'm also planning to change the argument types of font::len,
font::print and font::print_wrap from const std::string&s to
const char*s, but I'll do that separately.
This commit is contained in:
Dav999-v 2023-02-23 04:15:27 +01:00 committed by Misa Elizabeth Kai
parent 8a011c3061
commit f34aa65faa

View file

@ -1,7 +1,6 @@
#include "Font.h" #include "Font.h"
#include <tinyxml2.h> #include <tinyxml2.h>
#include <utf8/unchecked.h>
#include "Alloc.h" #include "Alloc.h"
#include "Constants.h" #include "Constants.h"
@ -10,6 +9,7 @@
#include "Graphics.h" #include "Graphics.h"
#include "GraphicsUtil.h" #include "GraphicsUtil.h"
#include "Localization.h" #include "Localization.h"
#include "UTF8.h"
#include "UtilityClass.h" #include "UtilityClass.h"
#include "Vlogging.h" #include "Vlogging.h"
#include "XMLUtils.h" #include "XMLUtils.h"
@ -350,20 +350,18 @@ static uint8_t load_font(FontContainer* container, const char* name)
bool charset_loaded = false; bool charset_loaded = false;
bool special_loaded = false; bool special_loaded = false;
unsigned char* charmap = NULL; unsigned char* charmap = NULL;
size_t length;
if (FILESYSTEM_areAssetsInSameRealDir(name_png, name_txt)) if (FILESYSTEM_areAssetsInSameRealDir(name_png, name_txt))
{ {
FILESYSTEM_loadAssetToMemory(name_txt, &charmap, &length, false); FILESYSTEM_loadAssetToMemory(name_txt, &charmap, NULL, false);
} }
if (charmap != NULL) if (charmap != NULL)
{ {
// We have a .txt! It's an obsolete system, but it takes priority if the file exists. // We have a .txt! It's an obsolete system, but it takes priority if the file exists.
unsigned char* current = charmap; const char* current = (char*) charmap;
unsigned char* end = charmap + length;
int pos = 0; int pos = 0;
while (current != end) uint32_t codepoint;
while ((codepoint = UTF8_next(&current)))
{ {
uint32_t codepoint = utf8::unchecked::next(current);
add_glyphinfo(f, codepoint, pos); add_glyphinfo(f, codepoint, pos);
++pos; ++pos;
} }
@ -966,14 +964,14 @@ std::string string_unwordwrap(const std::string& s)
* Only applied to English, so langmeta.autowordwrap isn't used here (it'd break looking up strings) */ * Only applied to English, so langmeta.autowordwrap isn't used here (it'd break looking up strings) */
std::string result; std::string result;
std::back_insert_iterator<std::string> inserter = std::back_inserter(result); result.reserve(s.length());
std::string::const_iterator iter = s.begin();
bool latest_was_space = true; // last character was a space (or the beginning, don't want leading whitespace) bool latest_was_space = true; // last character was a space (or the beginning, don't want leading whitespace)
int consecutive_newlines = 0; // number of newlines currently encountered in a row (multiple newlines should stay!) int consecutive_newlines = 0; // number of newlines currently encountered in a row (multiple newlines should stay!)
while (iter != s.end())
{
uint32_t ch = utf8::unchecked::next(iter);
const char* str = s.c_str();
uint32_t ch;
while ((ch = UTF8_next(&str)))
{
if (ch == '\n') if (ch == '\n')
{ {
if (consecutive_newlines == 0) if (consecutive_newlines == 0)
@ -994,7 +992,7 @@ std::string string_unwordwrap(const std::string& s)
if (ch != ' ' || !latest_was_space) if (ch != ' ' || !latest_was_space)
{ {
utf8::unchecked::append(ch, inserter); result.append(UTF8_encode(ch).bytes);
} }
latest_was_space = (ch == ' ' || ch == '\n'); latest_was_space = (ch == ' ' || ch == '\n');
@ -1150,11 +1148,11 @@ int len(const uint32_t flags, const std::string& t)
PrintFlags pf = decode_print_flags(flags); PrintFlags pf = decode_print_flags(flags);
int text_len = 0; int text_len = 0;
std::string::const_iterator iter = t.begin(); uint32_t codepoint;
while (iter != t.end()) const char* text = t.c_str(); // TODO no std::string
while ((codepoint = UTF8_next(&text)))
{ {
int cur = utf8::unchecked::next(iter); text_len += get_advance(pf.font_sel, codepoint);
text_len += get_advance(pf.font_sel, cur);
} }
return text_len * pf.scale; return text_len * pf.scale;
} }
@ -1237,13 +1235,13 @@ void print(
} }
int position = 0; int position = 0;
std::string::const_iterator iter = text.begin(); const char* str = text.c_str(); // TODO no std::string
while (iter != text.end()) uint32_t codepoint;
while ((codepoint = UTF8_next(&str)))
{ {
const uint32_t character = utf8::unchecked::next(iter);
position += font::print_char( position += font::print_char(
pf.font_sel, pf.font_sel,
character, codepoint,
x + position, x + position,
y, y,
pf.scale, pf.scale,