Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/rendering
diff options
context:
space:
mode:
authorKae <80987908+Novaenia@users.noreply.github.com>2023-07-22 22:31:04 +1000
committerKae <80987908+Novaenia@users.noreply.github.com>2023-07-22 22:31:04 +1000
commitcb19eef701b5c9e27d0464795fffcf8a4d795a21 (patch)
tree5cfbdf49ebd7ac9539891eea850e244887d4c355 /source/rendering
parent4fbd67daccfa69df6988bdf17c67ee3d5f3049c5 (diff)
Add character swapping (no GUI yet)
Diffstat (limited to 'source/rendering')
-rw-r--r--source/rendering/StarTextPainter.cpp89
-rw-r--r--source/rendering/StarTextPainter.hpp11
2 files changed, 1 insertions, 99 deletions
diff --git a/source/rendering/StarTextPainter.cpp b/source/rendering/StarTextPainter.cpp
index 3e6c618..f0ef53d 100644
--- a/source/rendering/StarTextPainter.cpp
+++ b/source/rendering/StarTextPainter.cpp
@@ -1,98 +1,11 @@
#include "StarTextPainter.hpp"
#include "StarJsonExtra.hpp"
+#include "StarText.hpp"
#include <regex>
namespace Star {
-namespace Text {
- static auto stripEscapeRegex = std::regex(strf("\\{:c}[^;]*{:c}", CmdEsc, EndEsc));
- String stripEscapeCodes(String const& s) {
- return std::regex_replace(s.utf8(), stripEscapeRegex, "");
- }
-
- inline bool isEscapeCode(char c) {
- return c == CmdEsc || c == StartEsc;
- }
-
- static std::string escapeChars = strf("{:c}{:c}", CmdEsc, StartEsc);
-
- typedef function<bool(StringView text)> TextCallback;
- typedef function<bool(StringView commands)> CommandsCallback;
- bool processText(StringView text, TextCallback textFunc, CommandsCallback commandsFunc = CommandsCallback(), bool includeCommandSides = false) {
- std::string_view escChars(escapeChars);
-
- std::string_view str = text.utf8();
- while (true) {
- size_t escape = str.find_first_of(escChars);
- if (escape != NPos) {
- escape = str.find_first_not_of(escChars, escape) - 1; // jump to the last ^
-
- size_t end = str.find_first_of(EndEsc, escape);
- if (end != NPos) {
- if (escape && !textFunc(str.substr(0, escape)))
- return false;
- if (commandsFunc) {
- StringView commands = includeCommandSides
- ? str.substr(escape, end - escape + 1)
- : str.substr(escape + 1, end - escape - 1);
- if (!commands.empty() && !commandsFunc(commands))
- return false;
- }
- str = str.substr(end + 1);
- continue;
- }
- }
-
- if (!str.empty())
- return textFunc(str);
-
- return true;
- }
- }
-
- // The below two functions aren't used anymore, not bothering with StringView for them
- String preprocessEscapeCodes(String const& s) {
- bool escape = false;
- std::string result = s.utf8();
-
- size_t escapeStartIdx = 0;
- for (size_t i = 0; i < result.size(); i++) {
- auto& c = result[i];
- if (isEscapeCode(c)) {
- escape = true;
- escapeStartIdx = i;
- }
- if ((c <= SpecialCharLimit) && !(c == StartEsc))
- escape = false;
- if ((c == EndEsc) && escape)
- result[escapeStartIdx] = StartEsc;
- }
- return {result};
- }
-
- String extractCodes(String const& s) {
- bool escape = false;
- StringList result;
- String escapeCode;
- for (auto c : preprocessEscapeCodes(s)) {
- if (c == StartEsc)
- escape = true;
- if (c == EndEsc) {
- escape = false;
- for (auto command : escapeCode.split(','))
- result.append(command);
- escapeCode = "";
- }
- if (escape && (c != StartEsc))
- escapeCode.append(c);
- }
- if (!result.size())
- return "";
- return "^" + result.join(",") + ";";
- }
-}
-
TextPositioning::TextPositioning() {
pos = Vec2F();
hAnchor = HorizontalAnchor::LeftAnchor;
diff --git a/source/rendering/StarTextPainter.hpp b/source/rendering/StarTextPainter.hpp
index 7f132fd..381a358 100644
--- a/source/rendering/StarTextPainter.hpp
+++ b/source/rendering/StarTextPainter.hpp
@@ -10,17 +10,6 @@ namespace Star {
STAR_CLASS(TextPainter);
-namespace Text {
- unsigned char const StartEsc = '\x1b';
- unsigned char const EndEsc = ';';
- unsigned char const CmdEsc = '^';
- unsigned char const SpecialCharLimit = ' ';
-
- String stripEscapeCodes(String const& s);
- String preprocessEscapeCodes(String const& s);
- String extractCodes(String const& s);
-}
-
enum class FontMode {
Normal,
Shadow