summaryrefslogtreecommitdiff
path: root/Libraries
diff options
context:
space:
mode:
authorSergey Bugaev <bugaevc@gmail.com>2019-09-04 23:42:30 +0300
committerAndreas Kling <awesomekling@gmail.com>2019-09-05 16:37:39 +0200
commit9d64c60e011f33095a95f3620891e46fe19b63fc (patch)
tree0a24e1e501a5ea6b99496084941ae709290ac063 /Libraries
parent55197ed4ef1ab39ede3598bc20d074023f9ec8d7 (diff)
downloadserenity-9d64c60e011f33095a95f3620891e46fe19b63fc.zip
LibDraw: Introduce an Emoji class
This class can locate and load emojis, which are expected to be stored as regular PNG images at /res/emoji/U+XXXX.png, where XXXX is the character codepoint. https://github.com/SerenityOS/serenity/issues/490
Diffstat (limited to 'Libraries')
-rw-r--r--Libraries/LibDraw/Emoji.cpp27
-rw-r--r--Libraries/LibDraw/Emoji.h19
-rw-r--r--Libraries/LibDraw/Makefile3
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