2020-01-18 09:38:21 +01:00
|
|
|
/*
|
2020-01-24 16:45:29 +03:00
|
|
|
* Copyright (c) 2019-2020, Sergey Bugaev <bugaevc@serenityos.org>
|
2020-01-18 09:38:21 +01:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 09:38:21 +01:00
|
|
|
*/
|
|
|
|
|
|
2019-09-04 23:42:30 +03:00
|
|
|
#include <AK/HashMap.h>
|
2019-09-06 15:34:26 +02:00
|
|
|
#include <AK/String.h>
|
2020-02-06 12:07:05 +01:00
|
|
|
#include <LibGfx/Bitmap.h>
|
2020-09-18 09:49:51 +02:00
|
|
|
#include <LibGfx/Emoji.h>
|
2019-09-04 23:42:30 +03:00
|
|
|
|
2020-02-06 11:56:38 +01:00
|
|
|
namespace Gfx {
|
2019-09-04 23:42:30 +03:00
|
|
|
|
2020-02-06 11:56:38 +01:00
|
|
|
static HashMap<u32, RefPtr<Gfx::Bitmap>> s_emojis;
|
|
|
|
|
|
2020-08-05 16:31:20 -04:00
|
|
|
const Bitmap* Emoji::emoji_for_code_point(u32 code_point)
|
2019-09-04 23:42:30 +03:00
|
|
|
{
|
2020-08-05 16:31:20 -04:00
|
|
|
auto it = s_emojis.find(code_point);
|
2019-09-04 23:42:30 +03:00
|
|
|
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
|
|
|
|
2021-11-06 16:25:29 +01:00
|
|
|
auto bitmap_or_error = Bitmap::try_load_from_file(String::formatted("/res/emoji/U+{:X}.png", code_point));
|
|
|
|
|
if (bitmap_or_error.is_error()) {
|
2020-08-05 16:31:20 -04:00
|
|
|
s_emojis.set(code_point, nullptr);
|
2019-09-04 23:42:30 +03:00
|
|
|
return nullptr;
|
2019-10-19 18:36:45 +02:00
|
|
|
}
|
2021-11-06 16:25:29 +01:00
|
|
|
auto bitmap = bitmap_or_error.release_value();
|
2020-08-05 16:31:20 -04:00
|
|
|
s_emojis.set(code_point, bitmap);
|
2019-10-19 18:36:45 +02:00
|
|
|
return bitmap.ptr();
|
2019-09-04 23:42:30 +03:00
|
|
|
}
|
2020-02-06 11:56:38 +01:00
|
|
|
|
|
|
|
|
}
|