summaryrefslogtreecommitdiff
path: root/Libraries/LibDraw/Emoji.cpp
blob: 7e8dd56f1aa4c5dfc6d913d43c9bc473e32659c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <AK/HashMap.h>
#include <AK/String.h>
#include <LibDraw/Emoji.h>
#include <LibDraw/GraphicsBitmap.h>

static HashMap<u32, RefPtr<GraphicsBitmap>> s_emojis;

const GraphicsBitmap* Emoji::emoji_for_codepoint(u32 codepoint)
{
    auto it = s_emojis.find(codepoint);
    if (it != s_emojis.end())
        return (*it).value.ptr();

    String path = String::format("/res/emoji/U+%X.png", codepoint);

    auto bitmap = GraphicsBitmap::load_from_file(path);
    if (!bitmap) {
        s_emojis.set(codepoint, nullptr);
        return nullptr;
    }

    s_emojis.set(codepoint, bitmap);
    return bitmap.ptr();
}