mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 01:20:25 +00:00
LibGfx: Use the paths to emoji images generated alongside emoji data
Rather than formatting the paths at runtime, as vformat is quite heavy in a profile.
This commit is contained in:
parent
1484d3d9f5
commit
392c8c99aa
Notes:
sideshowbarker
2024-07-17 08:59:18 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/392c8c99aa Pull-request: https://github.com/SerenityOS/serenity/pull/17579 Reviewed-by: https://github.com/linusg
1 changed files with 14 additions and 9 deletions
|
@ -5,6 +5,7 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <AK/Debug.h>
|
||||
#include <AK/DeprecatedString.h>
|
||||
#include <AK/HashMap.h>
|
||||
#include <AK/Span.h>
|
||||
|
@ -13,6 +14,7 @@
|
|||
#include <LibGfx/Bitmap.h>
|
||||
#include <LibGfx/Font/Emoji.h>
|
||||
#include <LibUnicode/CharacterTypes.h>
|
||||
#include <LibUnicode/Emoji.h>
|
||||
|
||||
namespace Gfx {
|
||||
|
||||
|
@ -20,7 +22,7 @@ namespace Gfx {
|
|||
// https://unicode.org/emoji/charts/emoji-list.html
|
||||
// https://unicode.org/emoji/charts/emoji-zwj-sequences.html
|
||||
|
||||
static HashMap<DeprecatedString, RefPtr<Gfx::Bitmap>> s_emojis;
|
||||
static HashMap<StringView, RefPtr<Gfx::Bitmap>> s_emojis;
|
||||
|
||||
Bitmap const* Emoji::emoji_for_code_point(u32 code_point)
|
||||
{
|
||||
|
@ -29,20 +31,23 @@ Bitmap const* Emoji::emoji_for_code_point(u32 code_point)
|
|||
|
||||
Bitmap const* Emoji::emoji_for_code_points(ReadonlySpan<u32> const& code_points)
|
||||
{
|
||||
// FIXME: This function is definitely not fast.
|
||||
auto basename = DeprecatedString::join('_', code_points, "U+{:X}"sv);
|
||||
auto emoji = Unicode::find_emoji_for_code_points(code_points);
|
||||
if (!emoji.has_value() || !emoji->image_path.has_value())
|
||||
return nullptr;
|
||||
|
||||
auto it = s_emojis.find(basename);
|
||||
if (it != s_emojis.end())
|
||||
return (*it).value.ptr();
|
||||
auto emoji_path = emoji->image_path.value();
|
||||
if (auto it = s_emojis.find(emoji_path); it != s_emojis.end())
|
||||
return it->value.ptr();
|
||||
|
||||
auto bitmap_or_error = Bitmap::load_from_file(DeprecatedString::formatted("/res/emoji/{}.png", basename));
|
||||
auto bitmap_or_error = Bitmap::load_from_file(emoji_path);
|
||||
if (bitmap_or_error.is_error()) {
|
||||
s_emojis.set(basename, nullptr);
|
||||
dbgln_if(EMOJI_DEBUG, "Generated emoji data has path {}, but could not load image: {}", emoji_path, bitmap_or_error.error());
|
||||
s_emojis.set(emoji_path, nullptr);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto bitmap = bitmap_or_error.release_value();
|
||||
s_emojis.set(basename, bitmap);
|
||||
s_emojis.set(emoji_path, bitmap);
|
||||
return bitmap.ptr();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue