Emoji.cpp 796 B

1234567891011121314151617181920212223242526272829303132
  1. /*
  2. * Copyright (c) 2019-2020, Sergey Bugaev <bugaevc@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <AK/HashMap.h>
  7. #include <AK/String.h>
  8. #include <LibGfx/Bitmap.h>
  9. #include <LibGfx/Emoji.h>
  10. namespace Gfx {
  11. static HashMap<u32, RefPtr<Gfx::Bitmap>> s_emojis;
  12. const Bitmap* Emoji::emoji_for_code_point(u32 code_point)
  13. {
  14. auto it = s_emojis.find(code_point);
  15. if (it != s_emojis.end())
  16. return (*it).value.ptr();
  17. auto bitmap_or_error = Bitmap::try_load_from_file(String::formatted("/res/emoji/U+{:X}.png", code_point));
  18. if (bitmap_or_error.is_error()) {
  19. s_emojis.set(code_point, nullptr);
  20. return nullptr;
  21. }
  22. auto bitmap = bitmap_or_error.release_value();
  23. s_emojis.set(code_point, bitmap);
  24. return bitmap.ptr();
  25. }
  26. }