From 034977d53f0b340b240d35e058a56a4866533392 Mon Sep 17 00:00:00 2001 From: mrbesen Date: Thu, 22 Jul 2021 20:51:57 +0200 Subject: [PATCH] vector font, canApply --- src/bot.cpp | 11 ++++++++++- src/font.h | 1 + src/phonefont.cpp | 4 ++++ src/phonefont.h | 1 + src/replacefont.cpp | 4 ++++ src/replacefont.h | 1 + src/vectorfont.cpp | 18 ++++++++++++++++++ src/vectorfont.h | 14 ++++++++++++++ 8 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 src/vectorfont.cpp create mode 100644 src/vectorfont.h diff --git a/src/bot.cpp b/src/bot.cpp index 020e3e4..68fb7a4 100644 --- a/src/bot.cpp +++ b/src/bot.cpp @@ -5,6 +5,7 @@ using json = nlohmann::json; #include "replacefont.h" #include "phonefont.h" +#include "vectorfont.h" static const std::string fancyrepl[] {"𝓊","ð“Ŧ","𝓎","𝓭","ð“Ū","ð“Ŋ","𝓰","ð“ą","ð“ē","ð“ģ","ð“ī","ð“ĩ","ð“ķ","𝓷","ð“ļ","ð“đ","𝓚","ð“ŧ","𝓞","ð“―","ð“ū","ð“ŋ","𝔀","𝔁","𝔂","𝔃","𝓐","𝓑","𝓒","𝓓","𝓔","𝓕","𝓖","𝓗","𝓘","𝓙","𝓚","𝓛","𝓜","𝓝","𝓞","𝓟","𝓠","ð“Ą","ð“Ē","ð“Ģ","ð“Ī","ð“Ĩ","ð“Ķ","𝓧","ð“Ļ","ð“Đ"}; static const std::string frakturrepl[] {"𝖆","𝖇","𝖈","𝖉","𝖊","𝖋","𝖌","𝖍","𝖎","𝖏","𝖐","𝖑","𝖒","𝖓","𝖔","𝖕","𝖖","𝖗","𝖘","𝖙","𝖚","𝖛","𝖜","𝖝","𝖞","𝖟","𝕎","𝕭","ð•Ū","ð•Ŋ","𝕰","ð•ą","ð•ē","ð•ģ","ð•ī","ð•ĩ","ð•ķ","𝕷","ð•ļ","ð•đ","𝕚","ð•ŧ","𝕞","ð•―","ð•ū","ð•ŋ","𝖀","𝖁","𝖂","𝖃","𝖄","𝖅"}; @@ -13,13 +14,14 @@ static const std::string cursedrepl[] {"aĖĩĖŠĖĖšĖ‡Í™Í‡Ė˜Í•Í”ĖĨĖĢ", "bĖķĖĖˆĖ static const std::string monospacere[] {"𝚊", "𝚋", "𝚌", "𝚍", "𝚎", "𝚏", "𝚐", "𝚑", "𝚒", "𝚓", "𝚔", "𝚕", "𝚖", "𝚗", "𝚘", "𝚙", "𝚚", "𝚛", "𝚜", "𝚝", "𝚞", "𝚟", "𝚠", "ðšĄ", "ðšĒ", "ðšĢ", "𝙰", "ð™ą", "ð™ē", "ð™ģ", "ð™ī", "ð™ĩ", "ð™ķ", "𝙷", "ð™ļ", "ð™đ", "𝙚", "ð™ŧ", "𝙞", "ð™―", "ð™ū", "ð™ŋ", "𝚀", "𝚁", "𝚂", "𝚃", "𝚄", "𝚅", "𝚆", "𝚇", "𝚈", "𝚉"}; FontBot::FontBot() { - fonts.reserve(6); + fonts.reserve(7); fonts.push_back(new ReplaceFont("Fancy", fancyrepl)); fonts.push_back(new ReplaceFont("Fraktur", frakturrepl)); fonts.push_back(new ReplaceFont("Double", doublerepl)); fonts.push_back(new ReplaceFont("Cursed", cursedrepl)); fonts.push_back(new PhoneFont()); fonts.push_back(new ReplaceFont("monospace", monospacere)); + fonts.push_back(new VectorFont()); } FontBot::~FontBot() { @@ -29,10 +31,17 @@ FontBot::~FontBot() { } bool FontBot::handleInline(TelegramAPI::Manager* api, TelegramAPI::InlineQuery& q) { + if(q.query.empty()) return true; + + // awnser json arr = {}; uint8_t id = 1; for(const Font* f : fonts) { + // skip font if it can not be applied + if(!f->canApply(q.query)) continue; + + // apply font std::string fontized; json j; diff --git a/src/font.h b/src/font.h index 4ad5a5b..95dfdde 100644 --- a/src/font.h +++ b/src/font.h @@ -7,4 +7,5 @@ public: virtual ~Font() {} virtual void applyFont(const std::string& in, std::string& out) const = 0; virtual const std::string& getName() const = 0; + virtual bool canApply(const std::string& in) const = 0; }; \ No newline at end of file diff --git a/src/phonefont.cpp b/src/phonefont.cpp index 19d5682..1e806e8 100644 --- a/src/phonefont.cpp +++ b/src/phonefont.cpp @@ -29,4 +29,8 @@ void PhoneFont::applyFont(const std::string& in, std::string& out) const { const std::string& PhoneFont::getName() const { static const std::string name = "Old Phone"; return name; +} + +bool PhoneFont::canApply(const std::string& in) const { + return true; } \ No newline at end of file diff --git a/src/phonefont.h b/src/phonefont.h index cbfaccc..12a5bcf 100644 --- a/src/phonefont.h +++ b/src/phonefont.h @@ -8,6 +8,7 @@ public: virtual void applyFont(const std::string& in, std::string& out) const override; virtual const std::string& getName() const override; + virtual bool canApply(const std::string& in) const override; private: static const std::string phonePad[]; }; \ No newline at end of file diff --git a/src/replacefont.cpp b/src/replacefont.cpp index 897d12b..b318e5d 100644 --- a/src/replacefont.cpp +++ b/src/replacefont.cpp @@ -19,4 +19,8 @@ void ReplaceFont::applyFont(const std::string& in, std::string& out) const { const std::string& ReplaceFont::getName() const { return name; +} + +bool ReplaceFont::canApply(const std::string& in) const { + return true; } \ No newline at end of file diff --git a/src/replacefont.h b/src/replacefont.h index 8f363a3..d5f5da1 100644 --- a/src/replacefont.h +++ b/src/replacefont.h @@ -8,6 +8,7 @@ public: virtual void applyFont(const std::string& in, std::string& out) const override; virtual const std::string& getName() const override; + virtual bool canApply(const std::string& in) const override; private: const std::string name; const std::string* repl; //pointer (array) diff --git a/src/vectorfont.cpp b/src/vectorfont.cpp new file mode 100644 index 0000000..19dc5a9 --- /dev/null +++ b/src/vectorfont.cpp @@ -0,0 +1,18 @@ +#include "vectorfont.h" + +const std::string VectorFont::vectorSymbol = "⃗"; + +VectorFont::VectorFont() {} + +void VectorFont::applyFont(const std::string& in, std::string& out) const { + out = in[0] + vectorSymbol; +} + +const std::string& VectorFont::getName() const { + static const std::string name = "Vector"; + return name; +} + +bool VectorFont::canApply(const std::string& in) const { + return in.length() == 1; +} \ No newline at end of file diff --git a/src/vectorfont.h b/src/vectorfont.h new file mode 100644 index 0000000..3c39724 --- /dev/null +++ b/src/vectorfont.h @@ -0,0 +1,14 @@ +#pragma once + +#include "font.h" + +class VectorFont : public Font { +public: + VectorFont(); + + virtual void applyFont(const std::string& in, std::string& out) const override; + virtual const std::string& getName() const override; + virtual bool canApply(const std::string& in) const override; +private: + static const std::string vectorSymbol; +}; \ No newline at end of file