diff --git a/Telegram/SourceFiles/data/stickers/data_custom_emoji.cpp b/Telegram/SourceFiles/data/stickers/data_custom_emoji.cpp index 0afbecd32..b0101a06f 100644 --- a/Telegram/SourceFiles/data/stickers/data_custom_emoji.cpp +++ b/Telegram/SourceFiles/data/stickers/data_custom_emoji.cpp @@ -41,7 +41,7 @@ using SizeTag = CustomEmojiManager::SizeTag; Unexpected("SizeTag value in CustomEmojiManager-LottieSizeFromTag."); } -[[nodiscard]] int SizeFromTag(SizeTag tag) { +[[nodiscard]] int EmojiSizeFromTag(SizeTag tag) { switch (tag) { case SizeTag::Normal: return Ui::Emoji::GetSizeNormal(); case SizeTag::Large: return Ui::Emoji::GetSizeLarge(); @@ -49,6 +49,12 @@ using SizeTag = CustomEmojiManager::SizeTag; Unexpected("SizeTag value in CustomEmojiManager-SizeFromTag."); } +[[nodiscard]] int SizeFromTag(SizeTag tag) { + const auto emoji = EmojiSizeFromTag(tag); + const auto factor = style::DevicePixelRatio(); + return Ui::Text::AdjustCustomEmojiSize(emoji / factor) * factor; +} + } // namespace class CustomEmojiLoader final @@ -220,9 +226,10 @@ void CustomEmojiLoader::startCacheLookup( lookup->process = std::make_unique(Process{ .loaded = std::move(loaded), }); + const auto size = SizeFromTag(_tag); const auto weak = base::make_weak(&lookup->process->guard); document->owner().cacheBigFile().get(key, [=](QByteArray value) { - auto cache = Ui::CustomEmoji::Cache::FromSerialized(value); + auto cache = Ui::CustomEmoji::Cache::FromSerialized(value, size); crl::on_main(weak, [=, result = std::move(cache)]() mutable { lookupDone(lookup, std::move(result)); }); @@ -297,7 +304,7 @@ void CustomEmojiLoader::check() { .generator = std::move(generator), .put = std::move(put), .loader = std::move(loader), - .size = SizeFromTag(_tag), + .size = size, }); base::take(load->process)->loaded(Caching{ std::move(renderer), diff --git a/Telegram/SourceFiles/ui/text/custom_emoji_instance.cpp b/Telegram/SourceFiles/ui/text/custom_emoji_instance.cpp index 7f34e7b67..02d4555d6 100644 --- a/Telegram/SourceFiles/ui/text/custom_emoji_instance.cpp +++ b/Telegram/SourceFiles/ui/text/custom_emoji_instance.cpp @@ -79,15 +79,17 @@ void Preview::paintPath( Cache::Cache(int size) : _size(size) { } -std::optional Cache::FromSerialized(const QByteArray &serialized) { +std::optional Cache::FromSerialized( + const QByteArray &serialized, + int requestedSize) { + Expects(requestedSize > 0 && requestedSize <= kMaxSize); if (serialized.size() <= sizeof(CacheHeader)) { return {}; } auto header = CacheHeader(); memcpy(&header, serialized.data(), sizeof(header)); const auto size = header.size; - if (size <= 0 - || size > kMaxSize + if (size != requestedSize || header.frames <= 0 || header.frames >= kMaxFrames || header.length <= 0 diff --git a/Telegram/SourceFiles/ui/text/custom_emoji_instance.h b/Telegram/SourceFiles/ui/text/custom_emoji_instance.h index c04c62710..21f448431 100644 --- a/Telegram/SourceFiles/ui/text/custom_emoji_instance.h +++ b/Telegram/SourceFiles/ui/text/custom_emoji_instance.h @@ -66,7 +66,8 @@ public: }; [[nodiscard]] static std::optional FromSerialized( - const QByteArray &serialized); + const QByteArray &serialized, + int requestedSize); [[nodiscard]] QByteArray serialize(); [[nodiscard]] int size() const; diff --git a/Telegram/lib_ui b/Telegram/lib_ui index 2bec77825..d7318d849 160000 --- a/Telegram/lib_ui +++ b/Telegram/lib_ui @@ -1 +1 @@ -Subproject commit 2bec77825150094d248528f40341c6aef16e810a +Subproject commit d7318d849ef89873a1b4f78f23e471555061921b