async parsing + tex caching
This commit is contained in:
@@ -7,6 +7,8 @@
|
||||
#include <QUrl>
|
||||
#include <QtQml>
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <jkqtmathtext/jkqtmathtext.h>
|
||||
|
||||
namespace ZShell::llm {
|
||||
@@ -14,7 +16,9 @@ namespace ZShell::llm {
|
||||
// QML wrapper around JKQTMathText (JKQtPlotter's LaTeX renderer).
|
||||
//
|
||||
// Parses a display-math string and renders it into a transparent
|
||||
// QImage at the given device pixel ratio. QML displays the image
|
||||
// QImage at the given device pixel ratio, off the GUI thread (with a
|
||||
// process-wide cache keyed on the full render state, so re-opening a
|
||||
// chat does not re-render the same equations). QML displays the image
|
||||
// (scaling it to the bubble width when needed) and falls back to the
|
||||
// raw LaTeX when parsing fails.
|
||||
class LlmMathText : public QObject {
|
||||
@@ -57,7 +61,9 @@ class LlmMathText : public QObject {
|
||||
private:
|
||||
void reRender();
|
||||
|
||||
JKQTMathText m_renderer;
|
||||
// Shared so an in-flight worker render keeps the renderer alive if
|
||||
// this object (and its QML item) is destroyed mid-render.
|
||||
std::shared_ptr<JKQTMathText> m_renderer;
|
||||
QString m_latex;
|
||||
QColor m_color;
|
||||
double m_fontPointSize = 12.0;
|
||||
@@ -67,6 +73,10 @@ class LlmMathText : public QObject {
|
||||
qreal m_width = 0;
|
||||
qreal m_height = 0;
|
||||
bool m_ok = false;
|
||||
// Bumps on every reRender; a delivery carrying an older id was
|
||||
// superseded and is dropped.
|
||||
int m_requestId = 0;
|
||||
bool m_inFlight = false;
|
||||
};
|
||||
|
||||
} // namespace ZShell::llm
|
||||
|
||||
Reference in New Issue
Block a user