mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 07:47:35 +00:00
LibGfx: Use LibUnicode to filter code points that cannot start an emoji
This commit is contained in:
parent
392c8c99aa
commit
8be43cd3bf
2 changed files with 7 additions and 37 deletions
|
@ -51,35 +51,10 @@ Bitmap const* Emoji::emoji_for_code_points(ReadonlySpan<u32> const& code_points)
|
|||
return bitmap.ptr();
|
||||
}
|
||||
|
||||
template<typename CodePointIterator>
|
||||
static bool could_be_emoji(CodePointIterator const& it)
|
||||
{
|
||||
if (it.done())
|
||||
return false;
|
||||
|
||||
static constexpr u32 supplementary_private_use_area_b_first_code_point = 0x100000;
|
||||
if (*it >= supplementary_private_use_area_b_first_code_point) {
|
||||
// We use Supplementary Private Use Area-B for custom Serenity emoji.
|
||||
return true;
|
||||
}
|
||||
|
||||
static auto const emoji_property = Unicode::property_from_string("Emoji"sv);
|
||||
if (!emoji_property.has_value()) {
|
||||
// This means Unicode data generation is disabled. Always check the disk in that case.
|
||||
return true;
|
||||
}
|
||||
|
||||
return Unicode::code_point_has_property(*it, *emoji_property);
|
||||
}
|
||||
|
||||
template<typename CodePointIterator>
|
||||
static Bitmap const* emoji_for_code_point_iterator_impl(CodePointIterator& it)
|
||||
{
|
||||
// NOTE: I'm sure this could be more efficient, e.g. by checking if each code point falls
|
||||
// into a certain range in the loop below (emojis, modifiers, variation selectors, ZWJ),
|
||||
// and bailing out early if not. Current worst case is 10 file lookups for any sequence of
|
||||
// code points (if the first glyph isn't part of the font in regular text rendering).
|
||||
if (!could_be_emoji(it))
|
||||
if (!Unicode::could_be_start_of_emoji_sequence(it))
|
||||
return nullptr;
|
||||
|
||||
constexpr size_t max_emoji_code_point_sequence_length = 10;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue