1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Android: Attempt to load legacy emoji font if fallback selects incompatible font

This commit is contained in:
reuk 2024-03-13 15:45:24 +00:00
parent b42fd71c9e
commit 9c1c61a06e
No known key found for this signature in database
GPG key ID: FCB43929F012EE5C

View file

@ -316,18 +316,36 @@ private:
if (cache == nullptr)
return {}; // Perhaps we're shutting down
return cache->get ({ matchedFile, (int) matchedIndex }, [] (const TypefaceFileAndIndex& info) -> Typeface::Ptr
{
FileInputStream stream { info.file };
return cache->get ({ matchedFile, (int) matchedIndex }, &loadCompatibleFont);
}
if (! stream.openedOk())
return {};
static Typeface::Ptr loadCompatibleFont (const TypefaceFileAndIndex& info)
{
FileInputStream stream { info.file };
MemoryBlock mb;
stream.readIntoMemoryBlock (mb);
if (! stream.openedOk())
return {};
return fromMemory (DoCache::no, { static_cast<const std::byte*> (mb.getData()), mb.getSize() }, (unsigned int) info.index);
});
MemoryBlock mb;
stream.readIntoMemoryBlock (mb);
auto result = fromMemory (DoCache::no,
{ static_cast<const std::byte*> (mb.getData()), mb.getSize() },
(unsigned int) info.index);
if (result == nullptr)
return {};
const auto tech = result->getColourGlyphFormats();
const auto hasSupportedColours = (tech & (colourGlyphFormatCOLRv0 | colourGlyphFormatBitmap)) != 0;
// If the font only uses unsupported colour technologies, assume it's the system emoji font
// and try to return a compatible version of the font
if (tech != 0 && ! hasSupportedColours)
if (auto fallback = from ({ "NotoColorEmojiLegacy", FontValues::defaultFontHeight, Font::plain }); fallback != nullptr)
return fallback;
return result;
}
static Typeface::Ptr fromMemory (DoCache cache, Span<const std::byte> blob, unsigned int index = 0)