Show full emoji in fields in all scales.

This commit is contained in:
John Preston 2019-08-27 20:54:19 +03:00
parent bd7cee2252
commit 97a239a8b4
2 changed files with 31 additions and 28 deletions

View File

@ -79,7 +79,7 @@ auto TouchbarEmoji = (Instance*)nullptr;
#endif #endif
auto MainEmojiMap = std::map<int, QPixmap>(); auto MainEmojiMap = std::map<int, QPixmap>();
auto OtherEmojiMap = std::map<int, std::map<int, QPixmap>>(); auto OtherEmojiMap = base::flat_map<int, std::map<int, QPixmap>>();
int RowsCount(int index) { int RowsCount(int index) {
if (index + 1 < SpritesCount) { if (index + 1 < SpritesCount) {
@ -880,14 +880,16 @@ rpl::producer<> UpdatedRecent() {
} }
const QPixmap &SinglePixmap(EmojiPtr emoji, int fontHeight) { const QPixmap &SinglePixmap(EmojiPtr emoji, int fontHeight) {
auto &map = (fontHeight == st::msgFont->height) auto &map = (fontHeight == st::msgFont->height * cIntRetinaFactor())
? MainEmojiMap ? MainEmojiMap
: OtherEmojiMap[fontHeight]; : OtherEmojiMap[fontHeight];
auto i = map.find(emoji->index()); auto i = map.find(emoji->index());
if (i == end(map)) { if (i != end(map)) {
return i->second;
}
auto image = QImage( auto image = QImage(
SizeNormal + st::emojiPadding * cIntRetinaFactor() * 2, SizeNormal + st::emojiPadding * 2,
fontHeight * cIntRetinaFactor(), fontHeight,
QImage::Format_ARGB32_Premultiplied); QImage::Format_ARGB32_Premultiplied);
image.setDevicePixelRatio(cRetinaFactor()); image.setDevicePixelRatio(cRetinaFactor());
image.fill(Qt::transparent); image.fill(Qt::transparent);
@ -899,13 +901,12 @@ const QPixmap &SinglePixmap(EmojiPtr emoji, int fontHeight) {
emoji, emoji,
SizeNormal, SizeNormal,
st::emojiPadding * cIntRetinaFactor(), st::emojiPadding * cIntRetinaFactor(),
(fontHeight * cIntRetinaFactor() - SizeNormal) / 2); (fontHeight - SizeNormal) / 2);
} }
i = map.emplace( return map.emplace(
emoji->index(), emoji->index(),
App::pixmapFromImageInPlace(std::move(image))).first; App::pixmapFromImageInPlace(std::move(image))
} ).first->second;
return i->second;
} }
void Draw(QPainter &p, EmojiPtr emoji, int size, int x, int y) { void Draw(QPainter &p, EmojiPtr emoji, int size, int x, int y) {

View File

@ -82,7 +82,9 @@ QVariant InputDocument::loadResource(int type, const QUrl &name) {
} }
auto result = [&] { auto result = [&] {
if (const auto emoji = Ui::Emoji::FromUrl(name.toDisplayString())) { 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(Ui::Emoji::SinglePixmap(emoji, height));
} }
return QVariant(); return QVariant();
@ -614,9 +616,9 @@ QString AccumulateText(Iterator begin, Iterator end) {
QTextImageFormat PrepareEmojiFormat(EmojiPtr emoji, const QFont &font) { QTextImageFormat PrepareEmojiFormat(EmojiPtr emoji, const QFont &font) {
const auto factor = cIntRetinaFactor(); const auto factor = cIntRetinaFactor();
const auto width = Ui::Emoji::GetSizeNormal() const auto size = Ui::Emoji::GetSizeNormal();
+ st::emojiPadding * factor * 2; const auto width = size + st::emojiPadding * factor * 2;
const auto height = QFontMetrics(font).height() * factor; const auto height = std::max(QFontMetrics(font).height() * factor, size);
auto result = QTextImageFormat(); auto result = QTextImageFormat();
result.setWidth(width / factor); result.setWidth(width / factor);
result.setHeight(height / factor); result.setHeight(height / factor);
@ -641,7 +643,7 @@ void RemoveDocumentTags(
auto cursor = QTextCursor(document->docHandle(), from); auto cursor = QTextCursor(document->docHandle(), from);
cursor.setPosition(end, QTextCursor::KeepAnchor); cursor.setPosition(end, QTextCursor::KeepAnchor);
QTextCharFormat format; auto format = QTextCharFormat();
format.setProperty(kTagProperty, QString()); format.setProperty(kTagProperty, QString());
format.setProperty(kReplaceTagId, QString()); format.setProperty(kReplaceTagId, QString());
format.setForeground(st.textFg); format.setForeground(st.textFg);