Allow unloading custom emoji data.

This commit is contained in:
John Preston 2022-06-24 20:33:46 +04:00
parent e217611d50
commit 187110f438
3 changed files with 27 additions and 2 deletions

View file

@ -838,7 +838,11 @@ void Parser::finalize(const TextParseOptions &options) {
currentIndex++;
}
};
_t->_hasCustomEmoji = false;
for (auto &block : _t->_blocks) {
if (block->type() == TextBlockTCustomEmoji) {
_t->_hasCustomEmoji = true;
}
const auto spoilerIndex = block->spoilerIndex();
if (spoilerIndex && (_t->_spoilers.size() < spoilerIndex)) {
_t->_spoilers.resize(spoilerIndex);
@ -1682,7 +1686,7 @@ private:
x,
y);
} else if (const auto custom = static_cast<const CustomEmojiBlock*>(currentBlock)->_custom.get()) {
custom->paint(*_p, x, y);
custom->paint(*_p, x, y, _textPalette->spoilerActiveBg->c);
}
}
if (hasSpoiler) {
@ -3515,6 +3519,22 @@ void String::enumerateText(
}
}
bool String::hasCustomEmoji() const {
return _hasCustomEmoji;
}
void String::unloadCustomEmoji() {
if (!_hasCustomEmoji) {
return;
}
for (const auto &block : _blocks) {
const auto raw = block.get();
if (raw->type() == TextBlockTCustomEmoji) {
static_cast<const CustomEmojiBlock*>(raw)->_custom->unload();
}
}
}
QString String::toString(TextSelection selection) const {
return toText(selection, false, false).rich.text;
}

View file

@ -161,6 +161,9 @@ public:
return _text.size();
}
[[nodiscard]] bool hasCustomEmoji() const;
void unloadCustomEmoji();
QString toString(TextSelection selection = AllTextSelection) const;
TextWithEntities toTextWithEntities(
TextSelection selection = AllTextSelection) const;
@ -207,6 +210,7 @@ private:
QFixed _minResizeWidth;
QFixed _maxWidth = 0;
int32 _minHeight = 0;
bool _hasCustomEmoji = false;
QString _text;
const style::TextStyle *_st = nullptr;

View file

@ -168,7 +168,8 @@ class CustomEmoji {
public:
virtual ~CustomEmoji() = default;
[[nodiscard]] virtual QString entityData() = 0;
virtual void paint(QPainter &p, int x, int y) = 0;
virtual void paint(QPainter &p, int x, int y, const QColor &preview) = 0;
virtual void unload() = 0;
};