diff --git a/ui/emoji_config.cpp b/ui/emoji_config.cpp index 6b43bcf..06f28b9 100644 --- a/ui/emoji_config.cpp +++ b/ui/emoji_config.cpp @@ -490,8 +490,8 @@ void Init() { const auto persprite = kImagesPerRow * kImageRowsPerSprite; SpritesCount = (count / persprite) + ((count % persprite) ? 1 : 0); - SizeNormal = style::ConvertScale(18, style::Scale() * style::DevicePixelRatio()); - SizeLarge = int(style::ConvertScale(18 * 4 / 3., style::Scale() * style::DevicePixelRatio())); + SizeNormal = st::emojiSize * style::DevicePixelRatio(); + SizeLarge = int(style::ConvertScale(18 * 4 / 3., style::Scale())) * style::DevicePixelRatio(); Universal = std::make_shared(ReadCurrentSetId()); CanClearUniversal = false; diff --git a/ui/text/text.cpp b/ui/text/text.cpp index 45e33fc..e56ca5d 100644 --- a/ui/text/text.cpp +++ b/ui/text/text.cpp @@ -1689,7 +1689,17 @@ private: if (!_now) { _now = crl::now(); } - custom->paint(*_p, x, y, _now, _textPalette->spoilerActiveBg->c, _p->inactive()); + if (!_customEmojiSize) { + _customEmojiSize = AdjustCustomEmojiSize(st::emojiSize); + _customEmojiSkip = (st::emojiSize - _customEmojiSize) / 2; + } + custom->paint( + *_p, + x + _customEmojiSkip, + y + _customEmojiSkip, + _now, + _textPalette->spoilerActiveBg->c, + _p->inactive()); } } if (hasSpoiler) { @@ -2871,6 +2881,8 @@ private: const QChar *_str = nullptr; crl::time _now = 0; + int _customEmojiSize = 0; + int _customEmojiSkip = 0; int _indexOfElidedBlock = -1; // For spoilers. // current paragraph data diff --git a/ui/text/text_block.cpp b/ui/text/text_block.cpp index f3d2275..7c6c617 100644 --- a/ui/text/text_block.cpp +++ b/ui/text/text_block.cpp @@ -498,6 +498,10 @@ CustomEmojiBlock::CustomEmojiBlock( } } +int AdjustCustomEmojiSize(int emojiSize) { + return base::SafeRound(emojiSize * 1.12); +} + NewlineBlock::NewlineBlock( const style::font &font, const QString &str, diff --git a/ui/text/text_block.h b/ui/text/text_block.h index 4da5ec9..da10ab2 100644 --- a/ui/text/text_block.h +++ b/ui/text/text_block.h @@ -202,6 +202,8 @@ private: }; +[[nodiscard]] int AdjustCustomEmojiSize(int emojiSize); + class SkipBlock final : public AbstractBlock { public: SkipBlock( diff --git a/ui/widgets/input_fields.cpp b/ui/widgets/input_fields.cpp index 6e103b7..b02a15d 100644 --- a/ui/widgets/input_fields.cpp +++ b/ui/widgets/input_fields.cpp @@ -815,7 +815,11 @@ void RemoveCustomEmojiTag( } void ApplyTagFormat(QTextCharFormat &to, const QTextCharFormat &from) { - to.setProperty(kTagProperty, from.property(kTagProperty)); + if (from.hasProperty(kTagProperty)) { + to.setProperty( + kTagProperty, + TagWithoutCustomEmoji(from.property(kTagProperty).toString())); + } to.setProperty(kReplaceTagId, from.property(kReplaceTagId)); to.setFont(from.font()); to.setForeground(from.foreground()); @@ -1000,19 +1004,19 @@ void InsertCustomEmojiAtCursor( const QString &text, const QString &link) { const auto currentFormat = cursor.charFormat(); + const auto unique = MakeUniqueCustomEmojiLink(link); auto format = QTextCharFormat(); format.setObjectType(kCustomEmojiFormat); format.setProperty(kCustomEmojiText, text); - format.setProperty(kCustomEmojiLink, MakeUniqueCustomEmojiLink(link)); + format.setProperty(kCustomEmojiLink, unique); format.setProperty(kCustomEmojiId, CustomEmojiIdFromLink(link)); format.setVerticalAlignment(QTextCharFormat::AlignBottom); ApplyTagFormat(format, currentFormat); - auto existingTag = TagWithoutCustomEmoji( - format.property(kTagProperty).toString()); + auto existingTag = format.property(kTagProperty).toString(); auto existingTags = existingTag.isEmpty() ? QList() : TextUtilities::SplitTags(existingTag); - existingTags.push_back(link); + existingTags.push_back(unique); format.setProperty(kTagProperty, TextUtilities::JoinTag(existingTags)); cursor.insertText(kObjectReplacement, format); } @@ -1391,10 +1395,14 @@ QSizeF CustomEmojiObject::intrinsicSize( int posInDocument, const QTextFormat &format) { const auto factor = style::DevicePixelRatio() * 1.; - const auto size = Emoji::GetSizeNormal() / factor; + const auto size = st::emojiSize * 1.; const auto width = size + st::emojiPadding * 2.; const auto font = format.toCharFormat().font(); const auto height = std::min(QFontMetrics(font).height() * 1., size); + if (!_skip) { + const auto emoji = Ui::Text::AdjustCustomEmojiSize(st::emojiSize); + _skip = (st::emojiSize - emoji) / 2; + } return { width, height }; } @@ -1421,8 +1429,8 @@ void CustomEmojiObject::drawObject( } i->second->paint( *painter, - int(base::SafeRound(rect.x())) + st::emojiPadding, - int(base::SafeRound(rect.y())), + int(base::SafeRound(rect.x())) + st::emojiPadding + _skip, + int(base::SafeRound(rect.y())) + _skip, _now, st::defaultTextPalette.spoilerActiveBg->c, _paused && _paused()); @@ -1614,7 +1622,8 @@ void InputField::updatePalette() { auto format = cursor.charFormat(); format.merge(PrepareTagFormat( _st, - format.property(kTagProperty).toString())); + TagWithoutCustomEmoji( + format.property(kTagProperty).toString()))); cursor.setCharFormat(format); setTextCursor(cursor); } diff --git a/ui/widgets/input_fields.h b/ui/widgets/input_fields.h index a80e24c..c69defd 100644 --- a/ui/widgets/input_fields.h +++ b/ui/widgets/input_fields.h @@ -185,6 +185,7 @@ private: Fn _paused; base::flat_map> _emoji; crl::time _now = 0; + int _skip = 0; };