File indexing completed on 2024-10-06 09:25:09
0001 /* 0002 SPDX-License-Identifier: GPL-2.0-or-later 0003 SPDX-FileCopyrightText: 2019 Sirgienko Nikita <warquark@gmail.com> 0004 */ 0005 #ifndef MATHRENDER_H 0006 #define MATHRENDER_H 0007 0008 #include <QObject> 0009 #include <QTextImageFormat> 0010 #include <QMutex> 0011 0012 #include "lib/latexrenderer.h" 0013 0014 /** 0015 * Special class for rendering embedded math in MarkdownEntry and TextEntry 0016 * Instead of LatexRenderer+EpsRenderer provide all needed functianality in one class 0017 * Even if we add some speed optimization in future, API of the class probably won't change 0018 */ 0019 class MathRenderer : public QObject { 0020 Q_OBJECT 0021 public: 0022 0023 MathRenderer(); 0024 ~MathRenderer(); 0025 0026 static bool mathRenderAvailable(); 0027 0028 // Resulution contol 0029 void setScale(qreal scale); 0030 qreal scale(); 0031 void useHighResolution(bool b); 0032 0033 /** 0034 * This function will run render task in Qt thread pool and 0035 * call resultHandler SLOT with MathRenderResult* argument on finish 0036 * receiver will be managed about pointer, task only create it 0037 */ 0038 void renderExpression( 0039 int jobId, 0040 const QString& mathExpression, 0041 Cantor::LatexRenderer::EquationType type, 0042 const QObject *receiver, 0043 const char *resultHandler); 0044 0045 0046 /** 0047 * Rerender renderer math expression in document 0048 * Unlike MathRender::renderExpression this method isn't async, because 0049 * rerender already rendered math is not long operation 0050 */ 0051 void rerender(QTextDocument* document, const QTextImageFormat& math); 0052 0053 /** 0054 * Render math expression from existing .pdf 0055 * Like MathRenderer::rerender is blocking 0056 */ 0057 std::pair<QTextImageFormat, QImage> renderExpressionFromPdf( 0058 const QString& filename, const QString& uuid, const QString& code, Cantor::LatexRenderer::EquationType type, bool* success 0059 ); 0060 0061 private: 0062 double m_scale; 0063 bool m_useHighRes; 0064 }; 0065 0066 #endif /* MATHRENDER_H */