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
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) {
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) {

View File

@ -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);