Allow unloading custom emoji data.
This commit is contained in:
parent
e217611d50
commit
187110f438
3 changed files with 27 additions and 2 deletions
|
|
@ -838,7 +838,11 @@ void Parser::finalize(const TextParseOptions &options) {
|
||||||
currentIndex++;
|
currentIndex++;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
_t->_hasCustomEmoji = false;
|
||||||
for (auto &block : _t->_blocks) {
|
for (auto &block : _t->_blocks) {
|
||||||
|
if (block->type() == TextBlockTCustomEmoji) {
|
||||||
|
_t->_hasCustomEmoji = true;
|
||||||
|
}
|
||||||
const auto spoilerIndex = block->spoilerIndex();
|
const auto spoilerIndex = block->spoilerIndex();
|
||||||
if (spoilerIndex && (_t->_spoilers.size() < spoilerIndex)) {
|
if (spoilerIndex && (_t->_spoilers.size() < spoilerIndex)) {
|
||||||
_t->_spoilers.resize(spoilerIndex);
|
_t->_spoilers.resize(spoilerIndex);
|
||||||
|
|
@ -1682,7 +1686,7 @@ private:
|
||||||
x,
|
x,
|
||||||
y);
|
y);
|
||||||
} else if (const auto custom = static_cast<const CustomEmojiBlock*>(currentBlock)->_custom.get()) {
|
} 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) {
|
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 {
|
QString String::toString(TextSelection selection) const {
|
||||||
return toText(selection, false, false).rich.text;
|
return toText(selection, false, false).rich.text;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -161,6 +161,9 @@ public:
|
||||||
return _text.size();
|
return _text.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] bool hasCustomEmoji() const;
|
||||||
|
void unloadCustomEmoji();
|
||||||
|
|
||||||
QString toString(TextSelection selection = AllTextSelection) const;
|
QString toString(TextSelection selection = AllTextSelection) const;
|
||||||
TextWithEntities toTextWithEntities(
|
TextWithEntities toTextWithEntities(
|
||||||
TextSelection selection = AllTextSelection) const;
|
TextSelection selection = AllTextSelection) const;
|
||||||
|
|
@ -207,6 +210,7 @@ private:
|
||||||
QFixed _minResizeWidth;
|
QFixed _minResizeWidth;
|
||||||
QFixed _maxWidth = 0;
|
QFixed _maxWidth = 0;
|
||||||
int32 _minHeight = 0;
|
int32 _minHeight = 0;
|
||||||
|
bool _hasCustomEmoji = false;
|
||||||
|
|
||||||
QString _text;
|
QString _text;
|
||||||
const style::TextStyle *_st = nullptr;
|
const style::TextStyle *_st = nullptr;
|
||||||
|
|
|
||||||
|
|
@ -168,7 +168,8 @@ class CustomEmoji {
|
||||||
public:
|
public:
|
||||||
virtual ~CustomEmoji() = default;
|
virtual ~CustomEmoji() = default;
|
||||||
[[nodiscard]] virtual QString entityData() = 0;
|
[[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;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue