[SCM] ktp-text-ui packaging branch, master, updated. debian/15.12.1-1-1918-gdf4b0ec
Maximiliano Curia
maxy at moszumanska.debian.org
Sat May 28 00:23:45 UTC 2016
Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-text-ui.git;a=commitdiff;h=8843326
The following commit has been merged in the master branch:
commit 8843326b6286f551b9d2af96fe1f207454580f7b
Author: Andrea Scarpino <andrea at archlinux.org>
Date: Fri Apr 5 19:17:43 2013 +0200
Latex filter:
- Do not show the raw text;
- Use base64 to display the image (do not require the Image Preview
plugin);
- Simplify logic.
---
filters/latex/latex-filter.cpp | 64 +++++++++++++++++-------------------------
filters/latex/latex-filter.h | 4 +--
2 files changed, 27 insertions(+), 41 deletions(-)
diff --git a/filters/latex/latex-filter.cpp b/filters/latex/latex-filter.cpp
index a9bcb3f..49a7db0 100644
--- a/filters/latex/latex-filter.cpp
+++ b/filters/latex/latex-filter.cpp
@@ -42,7 +42,7 @@ void LatexFilter::filterMessage(KTp::Message &message, const KTp::MessageContext
{
Q_UNUSED(context);
- const QString messageText = message.mainMessagePart();
+ QString messageText = message.mainMessagePart();
if (!messageText.contains(QLatin1String("$$"))) {
return;
}
@@ -50,48 +50,31 @@ void LatexFilter::filterMessage(KTp::Message &message, const KTp::MessageContext
QRegExp rg(QLatin1String("\$\$.+\$\$"));
rg.setMinimal(true);
- QMap<QString, QString> replaceMap;
int pos = 0;
- while (pos >= 0 && pos < messageText.length()) {
- pos = rg.indexIn(messageText, pos);
-
- if (pos >= 0) {
- const QString match = rg.cap(0);
- pos += rg.matchedLength();
-
- QString formul = match;
- // first remove the $$ delimiters on start and end
- formul.remove(QLatin1String("$$"));
- // then trim the result, so we can skip totally empty/whitespace-only formulas
- formul = formul.trimmed();
- if (formul.isEmpty() || !securityCheck(formul)) {
- continue;
- }
-
- // get the image and encode it with base64
- replaceMap[match] = handleLatex(formul);
- }
- }
+ while ((pos = rg.indexIn(messageText, pos)) != -1) {
+ QString formula = rg.cap();
+ // remove the $$ delimiters on start/end
+ formula.remove(QLatin1String("$$"));
- if (replaceMap.isEmpty()) {
- // we haven't found any LaTeX strings
- return;
- }
+ // we can skip totally empty/whitespace-only formulas
+ formula = formula.trimmed();
- for (QMap<QString, QString>::ConstIterator it = replaceMap.constBegin(); it != replaceMap.constEnd(); ++it) {
- QImage theImage(*it);
- if (theImage.isNull()) {
+ if (formula.isEmpty() || !isSafe(formula)) {
continue;
}
- message.appendMessagePart(
- QLatin1Literal("<br/>") %
- QLatin1Literal("<img src=\"") %
- (*it) %
- QLatin1Literal("\" style=\"max-width:100%;margin-top:3px\" alt=\"") %
- QLatin1Literal("\" />")
- );
+ QString image(QLatin1Literal("<img src=\"data:image/png;base64,") %
+ handleLatex(formula) %
+ QLatin1Literal("\" style=\"max-width:100%;margin-top:3px\" alt=\"") %
+ QLatin1Literal("\" />"));
+
+ int length = rg.matchedLength();
+ messageText.replace(pos, length, image);
+
+ pos += length;
}
+
+ message.setMainMessagePart(messageText);
}
QString LatexFilter::handleLatex(const QString &latexFormula)
@@ -168,10 +151,15 @@ QString LatexFilter::handleLatex(const QString &latexFormula)
return QString();
}
- return imageFile;
+ // Encode the image to base64
+ QFile file(imageFile);
+ file.open(QIODevice::ReadOnly);
+ QByteArray image = file.readAll();
+
+ return QString::fromAscii(image.toBase64());
}
-bool LatexFilter::securityCheck(const QString &latexFormula)
+bool LatexFilter::isSafe(const QString &latexFormula)
{
return !latexFormula.contains(QRegExp(QLatin1String(
"\\(def|let|futurelet|newcommand|renewcomment|else|fi|write|input|include"
diff --git a/filters/latex/latex-filter.h b/filters/latex/latex-filter.h
index d2c3dde..cd4ca08 100644
--- a/filters/latex/latex-filter.h
+++ b/filters/latex/latex-filter.h
@@ -19,8 +19,6 @@
#ifndef LATEX_FILTER_H
#define LATEX_FILTER_H
-#include <QColor>
-
#include <KTemporaryFile>
#include <KTp/abstract-message-filter.h>
@@ -35,7 +33,7 @@ public:
virtual void filterMessage(KTp::Message &message, const KTp::MessageContext &context);
private:
- bool securityCheck(const QString &latexFormula);
+ bool isSafe(const QString &latexFormula);
QString handleLatex(const QString &latexFormula);
QList<KTemporaryFile *> m_tempFiles;
--
ktp-text-ui packaging
More information about the pkg-kde-commits
mailing list