2019-09-04 23:42:30 +03:00
|
|
|
#include <AK/HashMap.h>
|
2019-09-06 15:34:26 +02:00
|
|
|
#include <AK/String.h>
|
|
|
|
#include <LibDraw/Emoji.h>
|
|
|
|
#include <LibDraw/GraphicsBitmap.h>
|
2019-09-04 23:42:30 +03:00
|
|
|
|
2019-10-19 18:36:45 +02:00
|
|
|
static HashMap<u32, RefPtr<GraphicsBitmap>> s_emojis;
|
2019-09-04 23:42:30 +03:00
|
|
|
|
2019-10-19 18:36:45 +02:00
|
|
|
const GraphicsBitmap* Emoji::emoji_for_codepoint(u32 codepoint)
|
2019-09-04 23:42:30 +03:00
|
|
|
{
|
|
|
|
auto it = s_emojis.find(codepoint);
|
|
|
|
if (it != s_emojis.end())
|
2019-10-19 18:36:45 +02:00
|
|
|
return (*it).value.ptr();
|
2019-09-04 23:42:30 +03:00
|
|
|
|
|
|
|
String path = String::format("/res/emoji/U+%X.png", codepoint);
|
|
|
|
|
|
|
|
auto bitmap = GraphicsBitmap::load_from_file(path);
|
2019-10-19 18:36:45 +02:00
|
|
|
if (!bitmap) {
|
|
|
|
s_emojis.set(codepoint, nullptr);
|
2019-09-04 23:42:30 +03:00
|
|
|
return nullptr;
|
2019-10-19 18:36:45 +02:00
|
|
|
}
|
2019-09-04 23:42:30 +03:00
|
|
|
|
2019-10-19 18:36:45 +02:00
|
|
|
s_emojis.set(codepoint, bitmap);
|
|
|
|
return bitmap.ptr();
|
2019-09-04 23:42:30 +03:00
|
|
|
}
|