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
This commit is contained in:
Sergey Bugaev 2019-09-04 23:42:30 +03:00 committed by Andreas Kling
parent 55197ed4ef
commit 9d64c60e01
Notes: sideshowbarker 2024-07-19 12:16:13 +09:00
3 changed files with 48 additions and 1 deletions

View file

@ -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;
}

19
Libraries/LibDraw/Emoji.h Normal file
View file

@ -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;
};

View file

@ -9,7 +9,8 @@ OBJS = \
Painter.o \
PNGLoader.o \
Rect.o \
StylePainter.o
StylePainter.o \
Emoji.o
LIBRARY = libdraw.a
DEFINES += -DUSERLAND