File indexing completed on 2024-04-28 11:20:59

0001 /*
0002     SPDX-License-Identifier: GPL-2.0-or-later
0003     SPDX-FileCopyrightText: 2019 Sirgienko Nikita <warquark@gmail.com>
0004 */
0005 #ifndef MATHRENDERTASK_H
0006 #define MATHRENDERTASK_H
0007 
0008 #include <QObject>
0009 #include <QString>
0010 #include <QTextImageFormat>
0011 #include <QUrl>
0012 #include <QImage>
0013 #include <QRunnable>
0014 #include <QSharedPointer>
0015 
0016 #include "lib/latexrenderer.h"
0017 
0018 class QMutex;
0019 
0020 struct MathRenderResult
0021 {
0022     int jobId;
0023     bool successful;
0024     QString errorMessage;
0025     QTextImageFormat renderedMath;
0026     QUrl uniqueUrl;
0027     QImage image;
0028 };
0029 Q_DECLARE_METATYPE(MathRenderResult)
0030 Q_DECLARE_METATYPE(QSharedPointer<MathRenderResult>)
0031 
0032 class MathRenderTask : public QObject, public QRunnable
0033 {
0034   Q_OBJECT
0035   public:
0036     MathRenderTask(
0037         int jobId,
0038         const QString& code,
0039         Cantor::LatexRenderer::EquationType type,
0040         double scale,
0041         bool highResolution
0042     );
0043 
0044     void setHandler(const QObject *receiver, const char *resultHandler);
0045 
0046     void run() override;
0047 
0048     static std::pair<QTextImageFormat, QImage> renderPdfToFormat(
0049         const QString& filename,
0050         const QString& code,
0051         const QString uuid,
0052         Cantor::LatexRenderer::EquationType type,
0053         double scale,
0054         bool highResulution,
0055         bool* success = nullptr,
0056         QString* errorReason = nullptr
0057     );
0058 
0059     static QString genUuid();
0060 
0061   Q_SIGNALS:
0062     void finish(QSharedPointer<MathRenderResult> result);
0063 
0064   private:
0065     void finalize(QSharedPointer<MathRenderResult> result);
0066 
0067   private:
0068     int m_jobId;
0069     QString m_code;
0070     Cantor::LatexRenderer::EquationType m_type;
0071     double m_scale;
0072     bool m_highResolution;
0073     QColor m_backgroundColor;
0074     QColor m_foregroundColor;
0075 
0076 };
0077 
0078 #endif /* MATHRENDERTASK_H */