diff options
-rw-r--r-- | Libraries/LibDraw/Emoji.cpp | 27 | ||||
-rw-r--r-- | Libraries/LibDraw/Emoji.h | 19 | ||||
-rw-r--r-- | Libraries/LibDraw/Makefile | 3 |
3 files changed, 48 insertions, 1 deletions
diff --git a/Libraries/LibDraw/Emoji.cpp b/Libraries/LibDraw/Emoji.cpp new file mode 100644 index 0000000000..650c688ece --- /dev/null +++ b/Libraries/LibDraw/Emoji.cpp @@ -0,0 +1,27 @@ +#include "Emoji.h" +#include "GraphicsBitmap.h" +#include <AK/AKString.h> +#include <AK/HashMap.h> + +static HashMap<u32, Emoji> s_emojis; + +Emoji::Emoji(NonnullRefPtr<GraphicsBitmap> bitmap) + : m_bitmap(move(bitmap)) +{ +} + +const Emoji* Emoji::emoji_for_codepoint(u32 codepoint) +{ + auto it = s_emojis.find(codepoint); + if (it != s_emojis.end()) + return &(*it).value; + + String path = String::format("/res/emoji/U+%X.png", codepoint); + + auto bitmap = GraphicsBitmap::load_from_file(path); + if (!bitmap) + return nullptr; + + s_emojis.set(codepoint, Emoji { bitmap.release_nonnull() }); + return &(*s_emojis.find(codepoint)).value; +} diff --git a/Libraries/LibDraw/Emoji.h b/Libraries/LibDraw/Emoji.h new file mode 100644 index 0000000000..7a810e4650 --- /dev/null +++ b/Libraries/LibDraw/Emoji.h @@ -0,0 +1,19 @@ +#pragma once + +#include <AK/Types.h> +#include <AK/NonnullRefPtr.h> + +class GraphicsBitmap; + +class Emoji { + public: + ~Emoji() {} + + static const Emoji* emoji_for_codepoint(u32 codepoint); + const GraphicsBitmap& bitmap() const { return m_bitmap; } + +private: + explicit Emoji(NonnullRefPtr<GraphicsBitmap>); + + NonnullRefPtr<GraphicsBitmap> m_bitmap; +}; diff --git a/Libraries/LibDraw/Makefile b/Libraries/LibDraw/Makefile index c1330120f5..653c372a2a 100644 --- a/Libraries/LibDraw/Makefile +++ b/Libraries/LibDraw/Makefile @@ -9,7 +9,8 @@ OBJS = \ Painter.o \ PNGLoader.o \ Rect.o \ - StylePainter.o + StylePainter.o \ + Emoji.o LIBRARY = libdraw.a DEFINES += -DUSERLAND |