Make custom emoji size 12% larger.
This commit is contained in:
parent
2bec778251
commit
d7318d849e
6 changed files with 40 additions and 12 deletions
|
|
@ -490,8 +490,8 @@ void Init() {
|
||||||
const auto persprite = kImagesPerRow * kImageRowsPerSprite;
|
const auto persprite = kImagesPerRow * kImageRowsPerSprite;
|
||||||
SpritesCount = (count / persprite) + ((count % persprite) ? 1 : 0);
|
SpritesCount = (count / persprite) + ((count % persprite) ? 1 : 0);
|
||||||
|
|
||||||
SizeNormal = style::ConvertScale(18, style::Scale() * style::DevicePixelRatio());
|
SizeNormal = st::emojiSize * style::DevicePixelRatio();
|
||||||
SizeLarge = int(style::ConvertScale(18 * 4 / 3., style::Scale() * style::DevicePixelRatio()));
|
SizeLarge = int(style::ConvertScale(18 * 4 / 3., style::Scale())) * style::DevicePixelRatio();
|
||||||
Universal = std::make_shared<UniversalImages>(ReadCurrentSetId());
|
Universal = std::make_shared<UniversalImages>(ReadCurrentSetId());
|
||||||
CanClearUniversal = false;
|
CanClearUniversal = false;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1689,7 +1689,17 @@ private:
|
||||||
if (!_now) {
|
if (!_now) {
|
||||||
_now = crl::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) {
|
if (hasSpoiler) {
|
||||||
|
|
@ -2871,6 +2881,8 @@ private:
|
||||||
const QChar *_str = nullptr;
|
const QChar *_str = nullptr;
|
||||||
crl::time _now = 0;
|
crl::time _now = 0;
|
||||||
|
|
||||||
|
int _customEmojiSize = 0;
|
||||||
|
int _customEmojiSkip = 0;
|
||||||
int _indexOfElidedBlock = -1; // For spoilers.
|
int _indexOfElidedBlock = -1; // For spoilers.
|
||||||
|
|
||||||
// current paragraph data
|
// current paragraph data
|
||||||
|
|
|
||||||
|
|
@ -498,6 +498,10 @@ CustomEmojiBlock::CustomEmojiBlock(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int AdjustCustomEmojiSize(int emojiSize) {
|
||||||
|
return base::SafeRound(emojiSize * 1.12);
|
||||||
|
}
|
||||||
|
|
||||||
NewlineBlock::NewlineBlock(
|
NewlineBlock::NewlineBlock(
|
||||||
const style::font &font,
|
const style::font &font,
|
||||||
const QString &str,
|
const QString &str,
|
||||||
|
|
|
||||||
|
|
@ -202,6 +202,8 @@ private:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
[[nodiscard]] int AdjustCustomEmojiSize(int emojiSize);
|
||||||
|
|
||||||
class SkipBlock final : public AbstractBlock {
|
class SkipBlock final : public AbstractBlock {
|
||||||
public:
|
public:
|
||||||
SkipBlock(
|
SkipBlock(
|
||||||
|
|
|
||||||
|
|
@ -815,7 +815,11 @@ void RemoveCustomEmojiTag(
|
||||||
}
|
}
|
||||||
|
|
||||||
void ApplyTagFormat(QTextCharFormat &to, const QTextCharFormat &from) {
|
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.setProperty(kReplaceTagId, from.property(kReplaceTagId));
|
||||||
to.setFont(from.font());
|
to.setFont(from.font());
|
||||||
to.setForeground(from.foreground());
|
to.setForeground(from.foreground());
|
||||||
|
|
@ -1000,19 +1004,19 @@ void InsertCustomEmojiAtCursor(
|
||||||
const QString &text,
|
const QString &text,
|
||||||
const QString &link) {
|
const QString &link) {
|
||||||
const auto currentFormat = cursor.charFormat();
|
const auto currentFormat = cursor.charFormat();
|
||||||
|
const auto unique = MakeUniqueCustomEmojiLink(link);
|
||||||
auto format = QTextCharFormat();
|
auto format = QTextCharFormat();
|
||||||
format.setObjectType(kCustomEmojiFormat);
|
format.setObjectType(kCustomEmojiFormat);
|
||||||
format.setProperty(kCustomEmojiText, text);
|
format.setProperty(kCustomEmojiText, text);
|
||||||
format.setProperty(kCustomEmojiLink, MakeUniqueCustomEmojiLink(link));
|
format.setProperty(kCustomEmojiLink, unique);
|
||||||
format.setProperty(kCustomEmojiId, CustomEmojiIdFromLink(link));
|
format.setProperty(kCustomEmojiId, CustomEmojiIdFromLink(link));
|
||||||
format.setVerticalAlignment(QTextCharFormat::AlignBottom);
|
format.setVerticalAlignment(QTextCharFormat::AlignBottom);
|
||||||
ApplyTagFormat(format, currentFormat);
|
ApplyTagFormat(format, currentFormat);
|
||||||
auto existingTag = TagWithoutCustomEmoji(
|
auto existingTag = format.property(kTagProperty).toString();
|
||||||
format.property(kTagProperty).toString());
|
|
||||||
auto existingTags = existingTag.isEmpty()
|
auto existingTags = existingTag.isEmpty()
|
||||||
? QList<QStringView>()
|
? QList<QStringView>()
|
||||||
: TextUtilities::SplitTags(existingTag);
|
: TextUtilities::SplitTags(existingTag);
|
||||||
existingTags.push_back(link);
|
existingTags.push_back(unique);
|
||||||
format.setProperty(kTagProperty, TextUtilities::JoinTag(existingTags));
|
format.setProperty(kTagProperty, TextUtilities::JoinTag(existingTags));
|
||||||
cursor.insertText(kObjectReplacement, format);
|
cursor.insertText(kObjectReplacement, format);
|
||||||
}
|
}
|
||||||
|
|
@ -1391,10 +1395,14 @@ QSizeF CustomEmojiObject::intrinsicSize(
|
||||||
int posInDocument,
|
int posInDocument,
|
||||||
const QTextFormat &format) {
|
const QTextFormat &format) {
|
||||||
const auto factor = style::DevicePixelRatio() * 1.;
|
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 width = size + st::emojiPadding * 2.;
|
||||||
const auto font = format.toCharFormat().font();
|
const auto font = format.toCharFormat().font();
|
||||||
const auto height = std::min(QFontMetrics(font).height() * 1., size);
|
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 };
|
return { width, height };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1421,8 +1429,8 @@ void CustomEmojiObject::drawObject(
|
||||||
}
|
}
|
||||||
i->second->paint(
|
i->second->paint(
|
||||||
*painter,
|
*painter,
|
||||||
int(base::SafeRound(rect.x())) + st::emojiPadding,
|
int(base::SafeRound(rect.x())) + st::emojiPadding + _skip,
|
||||||
int(base::SafeRound(rect.y())),
|
int(base::SafeRound(rect.y())) + _skip,
|
||||||
_now,
|
_now,
|
||||||
st::defaultTextPalette.spoilerActiveBg->c,
|
st::defaultTextPalette.spoilerActiveBg->c,
|
||||||
_paused && _paused());
|
_paused && _paused());
|
||||||
|
|
@ -1614,7 +1622,8 @@ void InputField::updatePalette() {
|
||||||
auto format = cursor.charFormat();
|
auto format = cursor.charFormat();
|
||||||
format.merge(PrepareTagFormat(
|
format.merge(PrepareTagFormat(
|
||||||
_st,
|
_st,
|
||||||
format.property(kTagProperty).toString()));
|
TagWithoutCustomEmoji(
|
||||||
|
format.property(kTagProperty).toString())));
|
||||||
cursor.setCharFormat(format);
|
cursor.setCharFormat(format);
|
||||||
setTextCursor(cursor);
|
setTextCursor(cursor);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -185,6 +185,7 @@ private:
|
||||||
Fn<bool()> _paused;
|
Fn<bool()> _paused;
|
||||||
base::flat_map<uint64, std::unique_ptr<Text::CustomEmoji>> _emoji;
|
base::flat_map<uint64, std::unique_ptr<Text::CustomEmoji>> _emoji;
|
||||||
crl::time _now = 0;
|
crl::time _now = 0;
|
||||||
|
int _skip = 0;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue