diff options
author | Timothy Flynn <trflynn89@pm.me> | 2023-02-23 08:41:55 -0500 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2023-02-24 19:48:47 +0100 |
commit | 392c8c99aaf9e55d820b2f4de3678921729fea93 (patch) | |
tree | 4cc25644e0c492876f240907b61b832adf03dbfa /Userland/Libraries/LibGfx/Font | |
parent | 1484d3d9f51e3ccade772931131e7d998933382e (diff) | |
download | serenity-392c8c99aaf9e55d820b2f4de3678921729fea93.zip |
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.
Diffstat (limited to 'Userland/Libraries/LibGfx/Font')
-rw-r--r-- | Userland/Libraries/LibGfx/Font/Emoji.cpp | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/Userland/Libraries/LibGfx/Font/Emoji.cpp b/Userland/Libraries/LibGfx/Font/Emoji.cpp index a6c4e1ca8d..055e45df60 100644 --- a/Userland/Libraries/LibGfx/Font/Emoji.cpp +++ b/Userland/Libraries/LibGfx/Font/Emoji.cpp @@ -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(); } |