From eb0feef51166eeabd58993c484e85e0739285aa1 Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Tue, 10 Nov 2020 01:38:44 -0500 Subject: use textviews in channel list + parse emojis --- emojis.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'emojis.cpp') 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 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 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 &EmojiResource::GetPatterns() const { return m_patterns; -- cgit v1.2.3