summaryrefslogtreecommitdiff
path: root/emojis.cpp
diff options
context:
space:
mode:
authorouwou <26526779+ouwou@users.noreply.github.com>2020-11-10 01:38:44 -0500
committerouwou <26526779+ouwou@users.noreply.github.com>2020-11-10 01:38:44 -0500
commiteb0feef51166eeabd58993c484e85e0739285aa1 (patch)
tree200c93680df8ecbcf127cc59e2f940e9f8af4b90 /emojis.cpp
parent823e1786e016a0dce58ffda0506608f2a2fce932 (diff)
downloadabaddon-portaudio-eb0feef51166eeabd58993c484e85e0739285aa1.tar.gz
abaddon-portaudio-eb0feef51166eeabd58993c484e85e0739285aa1.zip
use textviews in channel list + parse emojis
Diffstat (limited to 'emojis.cpp')
-rw-r--r--emojis.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/emojis.cpp b/emojis.cpp
index 5392ee8..6e9a293 100644
--- a/emojis.cpp
+++ b/emojis.cpp
@@ -72,6 +72,43 @@ Glib::ustring EmojiResource::HexToPattern(Glib::ustring hex) {
}
return ret;
}
+void EmojiResource::ReplaceEmojis(Glib::RefPtr<Gtk::TextBuffer> buf, int size) {
+ auto get_text = [&]() -> auto {
+ Gtk::TextBuffer::iterator a, b;
+ buf->get_bounds(a, b);
+ return buf->get_slice(a, b, true);
+ };
+ auto text = get_text();
+
+ int searchpos;
+ for (const auto &pattern : m_patterns) {
+ searchpos = 0;
+ Glib::RefPtr<Gdk::Pixbuf> pixbuf;
+ while (true) {
+ size_t r = text.find(pattern, searchpos);
+ if (r == Glib::ustring::npos) break;
+ if (!pixbuf) {
+ pixbuf = GetPixBuf(pattern);
+ if (pixbuf)
+ pixbuf = pixbuf->scale_simple(size, size, Gdk::INTERP_BILINEAR);
+ else
+ break;
+ }
+ searchpos = r + pattern.size();
+
+ const auto start_it = buf->get_iter_at_offset(r);
+ const auto end_it = buf->get_iter_at_offset(r + pattern.size());
+
+ auto it = buf->erase(start_it, end_it);
+ buf->insert_pixbuf(it, pixbuf);
+
+ int alen = text.size();
+ text = get_text();
+ int blen = text.size();
+ searchpos -= (alen - blen);
+ }
+ }
+}
const std::vector<Glib::ustring> &EmojiResource::GetPatterns() const {
return m_patterns;