diff --git a/Telegram/SourceFiles/ui/emoji_config.cpp b/Telegram/SourceFiles/ui/emoji_config.cpp index e1e105b81..1840be6f1 100644 --- a/Telegram/SourceFiles/ui/emoji_config.cpp +++ b/Telegram/SourceFiles/ui/emoji_config.cpp @@ -79,7 +79,7 @@ auto TouchbarEmoji = (Instance*)nullptr; #endif auto MainEmojiMap = std::map(); -auto OtherEmojiMap = std::map>(); +auto OtherEmojiMap = base::flat_map>(); int RowsCount(int index) { if (index + 1 < SpritesCount) { @@ -880,32 +880,33 @@ rpl::producer<> UpdatedRecent() { } const QPixmap &SinglePixmap(EmojiPtr emoji, int fontHeight) { - auto &map = (fontHeight == st::msgFont->height) + auto &map = (fontHeight == st::msgFont->height * cIntRetinaFactor()) ? MainEmojiMap : OtherEmojiMap[fontHeight]; auto i = map.find(emoji->index()); - if (i == end(map)) { - auto image = QImage( - SizeNormal + st::emojiPadding * cIntRetinaFactor() * 2, - fontHeight * cIntRetinaFactor(), - QImage::Format_ARGB32_Premultiplied); - image.setDevicePixelRatio(cRetinaFactor()); - image.fill(Qt::transparent); - { - QPainter p(&image); - PainterHighQualityEnabler hq(p); - Draw( - p, - emoji, - SizeNormal, - st::emojiPadding * cIntRetinaFactor(), - (fontHeight * cIntRetinaFactor() - SizeNormal) / 2); - } - i = map.emplace( - emoji->index(), - App::pixmapFromImageInPlace(std::move(image))).first; + if (i != end(map)) { + return i->second; } - return i->second; + auto image = QImage( + SizeNormal + st::emojiPadding * 2, + fontHeight, + QImage::Format_ARGB32_Premultiplied); + image.setDevicePixelRatio(cRetinaFactor()); + image.fill(Qt::transparent); + { + QPainter p(&image); + PainterHighQualityEnabler hq(p); + Draw( + p, + emoji, + SizeNormal, + st::emojiPadding * cIntRetinaFactor(), + (fontHeight - SizeNormal) / 2); + } + return map.emplace( + emoji->index(), + App::pixmapFromImageInPlace(std::move(image)) + ).first->second; } void Draw(QPainter &p, EmojiPtr emoji, int size, int x, int y) { diff --git a/Telegram/SourceFiles/ui/widgets/input_fields.cpp b/Telegram/SourceFiles/ui/widgets/input_fields.cpp index c35a1309f..ccf68576e 100644 --- a/Telegram/SourceFiles/ui/widgets/input_fields.cpp +++ b/Telegram/SourceFiles/ui/widgets/input_fields.cpp @@ -82,7 +82,9 @@ QVariant InputDocument::loadResource(int type, const QUrl &name) { } auto result = [&] { if (const auto emoji = Ui::Emoji::FromUrl(name.toDisplayString())) { - const auto height = _st.font->height; + const auto height = std::max( + _st.font->height * cIntRetinaFactor(), + Ui::Emoji::GetSizeNormal()); return QVariant(Ui::Emoji::SinglePixmap(emoji, height)); } return QVariant(); @@ -614,9 +616,9 @@ QString AccumulateText(Iterator begin, Iterator end) { QTextImageFormat PrepareEmojiFormat(EmojiPtr emoji, const QFont &font) { const auto factor = cIntRetinaFactor(); - const auto width = Ui::Emoji::GetSizeNormal() - + st::emojiPadding * factor * 2; - const auto height = QFontMetrics(font).height() * factor; + const auto size = Ui::Emoji::GetSizeNormal(); + const auto width = size + st::emojiPadding * factor * 2; + const auto height = std::max(QFontMetrics(font).height() * factor, size); auto result = QTextImageFormat(); result.setWidth(width / factor); result.setHeight(height / factor); @@ -641,7 +643,7 @@ void RemoveDocumentTags( auto cursor = QTextCursor(document->docHandle(), from); cursor.setPosition(end, QTextCursor::KeepAnchor); - QTextCharFormat format; + auto format = QTextCharFormat(); format.setProperty(kTagProperty, QString()); format.setProperty(kReplaceTagId, QString()); format.setForeground(st.textFg);