From 850d139e3d9e9d2ee96ea44666d676af28df4a8f Mon Sep 17 00:00:00 2001 From: tastytea Date: Mon, 27 Dec 2021 23:16:26 +0100 Subject: [PATCH] Make custom emoticons twice as high as the font. --- src/timeline/TimelineModel.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp index 9696dffb..0bec9505 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp @@ -561,25 +561,28 @@ TimelineModel::data(const mtx::events::collections::TimelineEvents &event, int r } // TODO(Nico): Don't parse html with a regex - const static QRegularExpression matchEmoticonHeight( - "(]*)height=\"([^\"]*)\"([^>]*>)"); - formattedBody_.replace(matchEmoticonHeight, QString("\\1 height=\"%1\"\\3").arg(ascent)); - const static QRegularExpression matchIsImg("]+>"); auto itIsImg = matchIsImg.globalMatch(formattedBody_); while (itIsImg.hasNext()) { + // The current tag. const QString curImg = itIsImg.next().captured(0); + // The replacement for the current . + auto imgReplacement = curImg; // Construct image parameters later used by MxcImageProvider. QString imgParams; if (curImg.contains("height")) { - const static QRegularExpression matchImgHeight("height=[\"\']?(\\d+)[\"\']?"); - const auto height = matchImgHeight.match(curImg).captured(1).toInt(); + const static QRegularExpression matchImgHeight("height=([\"\']?)(\\d+)([\"\']?)"); + // Make emoticons twice as high as the font. + if (curImg.contains("data-mx-emoticon")) { + imgReplacement = + imgReplacement.replace(matchImgHeight, "height=\\1%1\\3").arg(ascent * 2); + } + const auto height = matchImgHeight.match(imgReplacement).captured(2).toInt(); imgParams = QString("?scale&height=%1").arg(height); } // Replace src in current . - auto imgReplacement = curImg; const static QRegularExpression matchImgUri("src=\"mxc://([^\"]*)\""); imgReplacement.replace(matchImgUri, QString("src=\"image://mxcImage/\\1%1\"").arg(imgParams));