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